Ulzdec is writing output

This commit is contained in:
neauoire 2023-11-15 16:14:41 -08:00
parent 3813c6b83e
commit dc119c1026
3 changed files with 17 additions and 15 deletions

View File

@ -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

View File

@ -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);

View File

@ -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;
}