diff --git a/cli/lz/explanation.md b/cli/lz/README.md similarity index 100% rename from cli/lz/explanation.md rename to cli/lz/README.md diff --git a/cli/lz/build.sh b/cli/lz/build.sh index e798f99..d0bccfe 100755 --- a/cli/lz/build.sh +++ b/cli/lz/build.sh @@ -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 diff --git a/cli/lz/ulzenc.c b/cli/lz/ulzenc.c new file mode 100644 index 0000000..fb11072 --- /dev/null +++ b/cli/lz/ulzenc.c @@ -0,0 +1,39 @@ +#include +#include + +/* 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; +} \ No newline at end of file