1 /* expand.c -- Byte Pair Encoding decompression */
2 /* Copyright 1996 Philip Gage */
4 /* Byte Pair Compression appeared in the September 1997
5 * issue of C/C++ Users Journal. The original source code
6 * may still be found at the web site of the magazine
9 * The decompressor has been modified by me (Thiadmer
10 * Riemersma) to accept a string as input, instead of a
19 SC_FUNC int strexpand(char *dest, unsigned char *source, int maxlen, unsigned char pairtable[128][2])
21 unsigned char stack[STACKSIZE];
26 len = 1; /* already 1 byte for '\0' */
29 /* Pop byte from stack or read byte from the input string */
32 else if ((c = *(unsigned char *)source++) == '\0')
35 /* Push pair on stack or output byte to the output string */
37 assert(top+2 <= STACKSIZE);
38 stack[top++] = pairtable[c-128][1];
39 stack[top++] = pairtable[c-128][0];
43 if (maxlen > 1) { /* reserve one byte for the '\0' */
50 return len; /* return number of bytes decoded */
56 int main (int argc, char **argv)
61 for (i=0; i<58; i++) {
62 strexpand(str, errmsg[i], sizeof str, SCPACK_TABLE);