// CSE 373 // University of Washington, Spring 2000 // Assignment 7, Adaptive Huffman encoding // Instructor: Pete Morcos #include #include #include "huff.h" // global flags: // output in binary? or "0" "1"? int binary = 1; // if "01", break after each unit? or every 4 bits? int hexoutput = 0; // decode input? or encode it? int decode = 0; FILE *fin = stdin; FILE *fout = stdout; void dumpTree(PHuff h, NodeIndex n, int indent) { if (n == NONE) return; dumpTree(h, h->nodes[n].c1, indent+2); for (int i=0; inodes[n].value; if (s < 0) s = '-'; if (s == UNKNOWN) s = '?'; if (s == ENDOFFILE) s = '`'; fprintf(fout, "%c: %d [%d]\n", (unsigned char)s, h->nodes[n].weight, h->nodes[n].self); dumpTree(h, h->nodes[n].c0, indent+2); } // Encode entire input sequence. // General idea: for each character: // encode // update tree void EncodeInput(PHuff h) { // TODO: encode everything // (obey the -b flag) } void DecodeInput(PHuff h) { // TODO: decode everything } void main(int argc, char **argv) { // general setup stuff int i; // read the program flags // A flag of -b means output bits as "0" or "1" characters // (useful for debugging) // A flag of -d means to decode the input instead of encoding it for (i=1; i