summaryrefslogtreecommitdiff
path: root/src/main.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cc')
-rw-r--r--src/main.cc54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/main.cc b/src/main.cc
new file mode 100644
index 0000000..520f6ec
--- /dev/null
+++ b/src/main.cc
@@ -0,0 +1,54 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "config.h"
+#include "BHeap.h"
+#include "FHeap.h"
+#include "BinHeap.h"
+#include "PLList.h"
+#include "Huffman.h"
+
+void exception(int e, char *msg)
+{
+ fprintf(stderr, "%s\n", msg);
+ exit(-1);
+}
+
+PriorityList *newlist(void)
+{
+ return new BinHeap;
+}
+
+void Count(FILE * strm, PriorityList * P)
+{
+ int tab[256], i;
+ char *t;
+
+ for (i = 0; i < 256; i++) {
+ tab[i] = 0;
+ }
+
+ while ((i = getc(strm)) != EOF) {
+ tab[i]++;
+ }
+
+ for (i = 0; i < 256; i++) {
+ if (tab[i]) {
+ t = (char *) malloc(2);
+ t[0] = i;
+ t[1] = 0;
+ HInsert(P, tab[i], t);
+ }
+ }
+}
+
+int main(int argc, char **argv)
+{
+ PriorityList *P = newlist();
+ HTree *H;
+
+ Count(stdin, P);
+
+ H = Coder(P);
+ H->Trace(cout);
+ return 0;
+}