diff --git a/Makefile b/Makefile index d10cfea9314d26160b5630632dac288d0b877077..639061f3537adeb518a611793c54a7ee79a4f6a6 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ huffman : huffman.c cc huffman.c -o huffman inflate : inflate.c - cc inflate.c -o inflate -lm + cc inflate.c -o inflate clean : rm myzip0 myunzip0 huffman inflate diff --git a/inflate.c b/inflate.c index ba911e189f8eabdb89eeb7ae0c1c03c4ebd84998..e8ceaf1d5a096a686d5e39d756271857bd7347ba 100644 --- a/inflate.c +++ b/inflate.c @@ -4,36 +4,16 @@ #include <stdint.h> #include <stdlib.h> #include <stdbool.h> -#include <math.h> + +#include "inflate.h" /* Types of huffman codes */ #define FIXED 1 #define DYNAMIC 2 -/* Maximum length for any Huffman code */ -#define MAX_LENGTH 15 - /* Dummy value for min_codes in huffman_t structs */ #define NO_CODE -1 -typedef struct huffman { - /* bl_counts[i] = number of codes of length i */ - int bl_counts[MAX_LENGTH + 1]; - - /* This stores the alphabet. - * alphabet[i] returns an array of alphabet symbols of length bl_counts[i]. - */ - int *alphabet[MAX_LENGTH + 1]; - - /* Suppose we are reading a code and we want an index into the alphabet array. - * These are basically the numerical offsets for such an index. - * So if the code we are reading has value c and is of length i, - * its alphabet character is indexed by (c - min_codes[i]). - */ - int min_codes[MAX_LENGTH + 1]; - -} huffman_t; - /* * Constants for FIXED code type */ @@ -323,7 +303,6 @@ int *read_lens(char *buf, huffman_t *hf_codes, int num_symbols, int num_codes) { return lens; } -/* Read the block starting at the n-th bit */ void read_block(char *buf, FILE *out) { /* First bit is the BFINAL flag */