From a154758122ce8ee7761e87d36f15ae50b2eb0d31 Mon Sep 17 00:00:00 2001 From: Hunter Kvalevog Date: Thu, 1 Oct 2026 18:12:17 -0500 Subject: huffman: read input from file --- huffman/build.sh | 0 huffman/huffman.c | 17 ++++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) mode change 100644 => 100755 huffman/build.sh diff --git a/huffman/build.sh b/huffman/build.sh old mode 100644 new mode 100755 diff --git a/huffman/huffman.c b/huffman/huffman.c index b20c164..b982aee 100644 --- a/huffman/huffman.c +++ b/huffman/huffman.c @@ -24,7 +24,7 @@ #include #include -#define DEBUG +//#define DEBUG #ifdef __GNUC__ # define ATTR_NORETURN __attribute__((noreturn)) @@ -191,11 +191,18 @@ void decompress(const uint8_t *bbuf, size_t blen); int main(int argc, char **argv) { if (argc < 2) - die("supply an input string\n"); + die("supply a file\n"); - printf("inp: %s\n", argv[1]); - const uint8_t *ibuf = (const uint8_t *)argv[1]; - const size_t ilen = strlen(argv[1]); + FILE *f = fopen(argv[1], "rb"); + if (!f) + die("failed to open file\n"); + + fseek(f, 0, SEEK_END); + const size_t ilen = ftell(f); + fseek(f, 0, SEEK_SET); + + uint8_t *ibuf = malloc(ilen); + fread(ibuf, 1, ilen, f); // Set of all possible symbols Node syms[MAX_SYMBOLS] = { 0 }; -- cgit v1.2.3