Starting encoding

This commit is contained in:
neauoire 2023-11-15 20:30:28 -08:00
parent ea996c2c3f
commit 32bbb4011e
3 changed files with 48 additions and 0 deletions

View File

@ -18,6 +18,7 @@ fi
cc lz_main.c -o main
cc ulzdec.c -o ulzdec
cc ulzenc.c -o ulzenc
$ASM ulzdec.tal ulzdec.rom
# Make compressed file
@ -39,8 +40,16 @@ echo "Uxn Decoder"
echo ""
uxncli ulzdec.rom a.ulz b.bin && cat b.bin
# C Encoder
echo ""
echo "C Encoder"
echo ""
./ulzenc example.txt a.ulz
rm ./main
rm ./ulzdec
rm ./ulzenc
rm ./a.ulz
rm ./b.bin
rm ./ulzdec.rom

39
cli/lz/ulzenc.c Normal file
View File

@ -0,0 +1,39 @@
#include <stdio.h>
#include <stdlib.h>
/* cc ulzenc.c -o ulzenc && ./ulzenc example.txt */
static int
error(const char *name, const char *msg)
{
fprintf(stderr, "%s: %s\n", name, msg);
return 0;
}
char *mem, *ptr;
int
encode_ulz(FILE *src)
{
return 0;
}
int
main(int argc, char *argv[])
{
int res;
FILE *src, *dst;
if(argv[1][0] == '-' && argv[1][1] == 'v')
return !fprintf(stdout, "Ulzenc - ULZ Encoder, 15 Nov 2023.\n");
if(argc != 3)
return error("usage", "ulzenc [-v] a.bin b.ulz ");
if(!(src = fopen(argv[1], "rb")))
return !error("Invalid input file", argv[1]);
res = encode_ulz(src);
if(!(dst = fopen(argv[2], "wb")))
return !error("Invalid output file", argv[1]);
fwrite(mem, res, 1, dst);
printf("Compressed %s -> %s(%d bytes).\n", argv[1], argv[2], res);
return 0;
}