#include extern char **argvec; static const unsigned char table[][2] = { "e ", " t", "th", "he", "s ", " a", "ou", "in", "t ", " s", "er", "d ", "re", "an", "n ", " i", " o", "es", "st", "to", "or", "nd", "o ", "ar", "r ", ", ", "on", " b", "ea", "it", "u ", " w", "ng", "le", "is", "te", "en", "at", " c", "y ", "ro", " f", "oo", "al", ". ", "a ", " d", "ut", " h", "se", "nt", "ll", "g ", "yo", " l", " y", " p", "ve", "f ", "as", "om", "of", "ha", "ed", "h ", "hi", " r", "lo", "Yo", " m", "ne", "l ", "li", "de", "el", "ta", "wa", "ri", "ee", "ti", "no", "do", "Th", " e", "ck", "ur", "ow", "la", "ac", "et", "me", "il", " g", "ra", "co", "ch", "ma", "un", "so", "rt", "ai", "ce", "ic", "be", " n", "k ", "ge", "ot", "si", "pe", "tr", "wi", "e.", "ca", "rs", "ly", "ad", "we", "bo", "ho", "ir", "fo", "ke", "us", "m ", " T", "di", ".." }; static unsigned char bigram[256][256]; static void usage(void) { fprintf(stderr,"Usage: %s -u to uncompress\n",argvec[0]); fprintf(stderr," %s -c to compress\n",argvec[0]); } static void uncompress(void) { int c; while (1) { c = getchar(); if (c == EOF) break; if (c < 128) { putchar(c); } else { putchar(table[c-128][0]); putchar(table[c-128][1]); } } } static void compress(void) { int c1; int c2; for (c1=0;c1<256;c1++) for (c2=0;c2<256;c2++) bigram[c1][c2] = 0; for (c1=0;c1<(int)(sizeof(table)/sizeof(table[0]));c1++) { bigram[table[c1][0]][table[c1][1]] = c1 + 128; } c2 = -1; while (1) { c1 = c2; c2 = getchar(); if (c2 == EOF) { if (c1 >= 0) putchar(c1); return; } if (c1 >= 0) { if (bigram[c1][c2]) { putchar(bigram[c1][c2]); c2 = -1; } else { putchar(c1); } } } } void main(int, char **); void main(int ac, char **av) { if (ac != 2) { usage(); exit(1); } if (!strcmp(av[1],"-u")) { uncompress(); } else if (!strcmp(av[1],"-c")) { compress(); } else { usage(); exit(1); } exit(0); }