ref: c8ff8d599f84e0209ed0c37e92b6e05f1d06995f
parent: c6421a8f496a920c9c2e28659ac893e84dda3695
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sat Mar 8 13:36:25 EST 2025
lzpack: work with any input size, add level option
--- a/mkfile
+++ b/mkfile
@@ -88,7 +88,7 @@
$LD $LDFLAGS -o tools/$O.lzpack $OFILES_lzpack
src/plan9/sl.boot.s:D: boot/sl.boot tools/$cpuobjtype.lzpack
- tools/$cpuobjtype.lzpack < boot/sl.boot | aux/data2s boot >$target
+ tools/$cpuobjtype.lzpack -10 < boot/sl.boot | aux/data2s boot >$target
%.$O: %.c
$CC $CFLAGS -o $target $stem.c
--- a/tools/boot2h.sh
+++ b/tools/boot2h.sh
@@ -1,4 +1,4 @@
#!/bin/sh
set -e
sed 's/^ */ /g' < "$2" | tr -d '
-' | "$1" | od -t x1 -v -A n | sed -E 's/^[^ ]*[ ]+/ /g;s/[ ]+([^ ]+)/0x\1,/g'
+' | "$1" -10 | od -t x1 -v -A n | sed -E 's/^[^ ]*[ ]+/ /g;s/[ ]+([^ ]+)/0x\1,/g'
--- a/tools/lzpack.c
+++ b/tools/lzpack.c
@@ -1,17 +1,29 @@
#include "platform.h"
#include "brieflz.h"
-static u8int in[256*1024];
-
int
main(int argc, char **argv)
{
unsigned long sz;
- int n;
+ int n, level;
- USED(argc); USED(argv);
+ level = 9;
+ if(argc == 2 && argv[1][0] == '-' && isdigit(argv[1][1])){
+ level = atoi(argv[1]+1);
+ argc--;
+ }
+ if(argc != 1)
+ abort();
+
+ u8int *in = nil;
+ unsigned long max = 32768;
for(sz = 0;; sz += n){
- if((n = read(0, in+sz, sizeof(in)-sz)) < 0)
+ if(max < sz+65536){
+ max *= 2;
+ if((in = realloc(in, max)) == nil)
+ abort();
+ }
+ if((n = read(0, in+sz, max-sz)) < 0)
abort();
if(n == 0)
break;
@@ -21,10 +33,10 @@
u8int *out = malloc(1+4+blz_max_packed_size(sz));
if(out == nil)
abort();
- u8int *w = malloc(blz_workmem_size_level(sz, 10));
+ u8int *w = malloc(blz_workmem_size_level(sz, level));
if(w == nil)
abort();
- unsigned long osz = blz_pack_level(in, out+1+4, sz, w, 10);
+ unsigned long osz = blz_pack_level(in, out+1+4, sz, w, level);
if(osz == BLZ_ERROR)
abort();
out[0] = 0;