Print result in ulzdec.c

This commit is contained in:
neauoire 2023-11-15 16:18:03 -08:00
parent dc119c1026
commit 47a1e91a74
1 changed files with 7 additions and 6 deletions

View File

@ -12,12 +12,12 @@ error(const char *name, const char *msg)
char *mem, *ptr; char *mem, *ptr;
void int
decode_ulz(FILE *src) decode_ulz(FILE *src)
{ {
char c, *copy; char c, *copy;
short i, length; short i, length;
mem = malloc(0x10000), ptr = mem; ptr = mem = malloc(0x10000);
while((c = getc(src)) != EOF) { while((c = getc(src)) != EOF) {
if(c & 0x80) { /* DICT */ if(c & 0x80) { /* DICT */
if(c & 0x40) if(c & 0x40)
@ -31,12 +31,13 @@ decode_ulz(FILE *src)
for(i = 0; i < c + 1; i++) for(i = 0; i < c + 1; i++)
*(ptr++) = getc(src); *(ptr++) = getc(src);
} }
return ptr - mem;
} }
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
char *res; int res;
FILE *src, *dst; FILE *src, *dst;
if(argv[1][0] == '-' && argv[1][1] == 'v') if(argv[1][0] == '-' && argv[1][1] == 'v')
return !fprintf(stdout, "Ulzdec - ULZ Decoder, 15 Nov 2023.\n"); return !fprintf(stdout, "Ulzdec - ULZ Decoder, 15 Nov 2023.\n");
@ -44,10 +45,10 @@ main(int argc, char *argv[])
return error("usage", "ulzdec [-v] a.ulz b.bin"); return error("usage", "ulzdec [-v] a.ulz b.bin");
if(!(src = fopen(argv[1], "rb"))) if(!(src = fopen(argv[1], "rb")))
return !error("Invalid input file", argv[1]); return !error("Invalid input file", argv[1]);
decode_ulz(src); res = decode_ulz(src);
if(!(dst = fopen(argv[2], "wb"))) if(!(dst = fopen(argv[2], "wb")))
return !error("Invalid output file", argv[1]); return !error("Invalid output file", argv[1]);
fwrite(mem, ptr - mem, 1, dst); fwrite(mem, res, 1, dst);
printf("Decompressed %s -> %s(%d bytes).\n", argv[1], argv[2], ptr - mem); printf("Decompressed %s -> %s(%d bytes).\n", argv[1], argv[2], res);
return 0; return 0;
} }