summaryrefslogtreecommitdiff
path: root/huffman
diff options
context:
space:
mode:
authorHunter Kvalevog <hunter@kvog.sh>2026-10-01 18:12:17 -0500
committerHunter Kvalevog <hunter@kvog.sh>2026-10-01 18:12:17 -0500
commita154758122ce8ee7761e87d36f15ae50b2eb0d31 (patch)
treeb2a7b79188bd3f36f21208bc7430869ad893bd43 /huffman
parent8522f1241c821319989df603dd11fcad770ae063 (diff)
huffman: read input from file
Diffstat (limited to 'huffman')
-rwxr-xr-x[-rw-r--r--]huffman/build.sh0
-rw-r--r--huffman/huffman.c17
2 files changed, 12 insertions, 5 deletions
diff --git a/huffman/build.sh b/huffman/build.sh
index 2125bc2..2125bc2 100644..100755
--- a/huffman/build.sh
+++ b/huffman/build.sh
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 <stdlib.h>
#include <string.h>
-#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 };