diff options
author | Vincent Torri <vincent.torri@gmail.com> | 2012-10-26 09:01:52 +0000 |
---|---|---|
committer | Vincent Torri <vincent.torri@gmail.com> | 2012-10-26 09:01:52 +0000 |
commit | 5bdb5d376373dab8bf624388cac520094be95b63 (patch) | |
tree | e494c3a000eeb506e63cd55a77f310767633e0d8 /src/bin/embryo/embryo_cc_scexpand.c | |
parent | 124e0d4afdff0937d8be8014f4dea5f78aa9f76f (diff) | |
download | efl-5bdb5d376373dab8bf624388cac520094be95b63.tar.gz efl-5bdb5d376373dab8bf624388cac520094be95b63.tar.xz efl-5bdb5d376373dab8bf624388cac520094be95b63.zip |
merge: add embryo
please check and report problems (not cosmetic ones)
someone should update the efl.spec.in file, i don't know that stuff
SVN revision: 78512
Diffstat (limited to 'src/bin/embryo/embryo_cc_scexpand.c')
-rw-r--r-- | src/bin/embryo/embryo_cc_scexpand.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/bin/embryo/embryo_cc_scexpand.c b/src/bin/embryo/embryo_cc_scexpand.c new file mode 100644 index 000000000..6ab34a17a --- /dev/null +++ b/src/bin/embryo/embryo_cc_scexpand.c @@ -0,0 +1,53 @@ +/* expand.c -- Byte Pair Encoding decompression */ +/* Copyright 1996 Philip Gage */ + +/* Byte Pair Compression appeared in the September 1997 + * issue of C/C++ Users Journal. The original source code + * may still be found at the web site of the magazine + * (www.cuj.com). + * + * The decompressor has been modified by me (Thiadmer + * Riemersma) to accept a string as input, instead of a + * complete file. + */ + + +#include "embryo_cc_sc.h" + +#define STACKSIZE 16 + +int +strexpand(char *dest, unsigned char *source, int maxlen, unsigned char pairtable[128][2]) +{ + unsigned char stack[STACKSIZE]; + short c, top = 0; + int len; + + len = 1; /* already 1 byte for '\0' */ + for (;;) + { + /* Pop byte from stack or read byte from the input string */ + if (top) + c = stack[--top]; + else if ((c = *(unsigned char *)source++) == '\0') + break; + + /* Push pair on stack or output byte to the output string */ + if (c > 127) + { + stack[top++] = pairtable[c - 128][1]; + stack[top++] = pairtable[c - 128][0]; + } + else + { + len++; + if (maxlen > 1) + { + *dest++ = (char)c; + maxlen--; + } + } + } + *dest = '\0'; + return len; +} |