From dc119c1026870f125547b19af69305aaa4666e0e Mon Sep 17 00:00:00 2001 From: neauoire Date: Wed, 15 Nov 2023 16:14:41 -0800 Subject: [PATCH] Ulzdec is writing output --- cli/lz/build.sh | 11 ++++++----- cli/lz/lz_main.c | 2 +- cli/lz/ulzdec.c | 19 ++++++++++--------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/cli/lz/build.sh b/cli/lz/build.sh index 86c1fc8..e798f99 100755 --- a/cli/lz/build.sh +++ b/cli/lz/build.sh @@ -11,7 +11,7 @@ if [[ "$*" == *"--lint"* ]] then $LIN decoder.tal clang-format -i lz_main.c - clang-format -i ulzcdec.c + clang-format -i ulzdec.c fi # Building @@ -29,17 +29,18 @@ $ASM ulzdec.tal ulzdec.rom echo "" echo "C Decoder" echo "" -./ulzdec compressed.bin +./ulzdec a.ulz b.bin +cat b.bin # Uxn Decoding echo "" echo "Uxn Decoder" echo "" -uxncli ulzdec.rom compressed.bin decompressed.txt && cat decompressed.txt +uxncli ulzdec.rom a.ulz b.bin && cat b.bin rm ./main rm ./ulzdec -rm ./compressed.bin -rm ./decompressed.txt +rm ./a.ulz +rm ./b.bin rm ./ulzdec.rom diff --git a/cli/lz/lz_main.c b/cli/lz/lz_main.c index 70e633b..b8e1b11 100644 --- a/cli/lz/lz_main.c +++ b/cli/lz/lz_main.c @@ -253,7 +253,7 @@ main(int argc, char *argv[]) printf("!!!%d -> %d\n", (int)i, (int)res); FILE *out_file; - out_file = fopen("compressed.bin", "wb"); + out_file = fopen("a.ulz", "wb"); fwrite(my_byte_buffer, 1, res, out_file); fclose(out_file); diff --git a/cli/lz/ulzdec.c b/cli/lz/ulzdec.c index 08638ea..1773bd3 100644 --- a/cli/lz/ulzdec.c +++ b/cli/lz/ulzdec.c @@ -17,6 +17,7 @@ decode_ulz(FILE *src) { char c, *copy; short i, length; + mem = malloc(0x10000), ptr = mem; while((c = getc(src)) != EOF) { if(c & 0x80) { /* DICT */ if(c & 0x40) @@ -36,17 +37,17 @@ int main(int argc, char *argv[]) { char *res; - FILE *src; - if(argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v') + FILE *src, *dst; + if(argv[1][0] == '-' && argv[1][1] == 'v') return !fprintf(stdout, "Ulzdec - ULZ Decoder, 15 Nov 2023.\n"); - if(argc != 2) - return error("usage", "ulzdec [-v] compressed.bin"); + if(argc != 3) + return error("usage", "ulzdec [-v] a.ulz b.bin"); if(!(src = fopen(argv[1], "rb"))) - return !error("Invalid input", argv[1]); - mem = malloc(0x10000); - ptr = mem; + return !error("Invalid input file", argv[1]); decode_ulz(src); - *(ptr) = 0; - printf("%s\n", mem); + if(!(dst = fopen(argv[2], "wb"))) + return !error("Invalid output file", argv[1]); + fwrite(mem, ptr - mem, 1, dst); + printf("Decompressed %s -> %s(%d bytes).\n", argv[1], argv[2], ptr - mem); return 0; } \ No newline at end of file