aboutsummaryrefslogtreecommitdiff
path: root/engines/glk/alan3/decode.cpp
diff options
context:
space:
mode:
authordreammaster2019-06-27 04:02:48 +0100
committerPaul Gilbert2019-07-06 15:27:08 -0700
commitdc40211ec5e54d01f7cb822940714ed6e6da36d5 (patch)
treededda7f6ce1ab7f581941d9f002ad1926fa3e367 /engines/glk/alan3/decode.cpp
parentaebf25661076eaa382b3025f0123f6ceb7cf920b (diff)
downloadscummvm-rg350-dc40211ec5e54d01f7cb822940714ed6e6da36d5.tar.gz
scummvm-rg350-dc40211ec5e54d01f7cb822940714ed6e6da36d5.tar.bz2
scummvm-rg350-dc40211ec5e54d01f7cb822940714ed6e6da36d5.zip
GLK: ALAN3: Proper indentation & formatting
Diffstat (limited to 'engines/glk/alan3/decode.cpp')
-rw-r--r--engines/glk/alan3/decode.cpp197
1 files changed, 96 insertions, 101 deletions
diff --git a/engines/glk/alan3/decode.cpp b/engines/glk/alan3/decode.cpp
index 41afbddca6..286223ced0 100644
--- a/engines/glk/alan3/decode.cpp
+++ b/engines/glk/alan3/decode.cpp
@@ -35,101 +35,98 @@ Aword *freq; /* Cumulative character frequencies */
/* PRIVATE DATA */
/* Bit output */
-static int decodeBuffer; /* Bits to be input */
-static int bitsToGo; /* Bits still in buffer */
-static int garbageBits; /* Bits past EOD */
-
-
-static int inputBit(void)
-{
- int bit;
-
- /* More bits available ? */
- if (!bitsToGo) {
- /* No, so get more */
- decodeBuffer = (textFile->pos() >= textFile->size()) ? EOD : textFile->readByte();
- if (decodeBuffer == (int)EOD) {
- garbageBits++;
- if (garbageBits > VALUEBITS-2)
- syserr("Error in encoded data file.");
- } else
- bitsToGo = 8; /* Another Char, 8 new bits */
- }
- bit = decodeBuffer&1; /* Get next bit */
- decodeBuffer = decodeBuffer>>1; /* and remove it */
- bitsToGo--;
- return bit;
+static int decodeBuffer; /* Bits to be input */
+static int bitsToGo; /* Bits still in buffer */
+static int garbageBits; /* Bits past EOD */
+
+
+static int inputBit(void) {
+ int bit;
+
+ /* More bits available ? */
+ if (!bitsToGo) {
+ /* No, so get more */
+ decodeBuffer = (textFile->pos() >= textFile->size()) ? EOD : textFile->readByte();
+ if (decodeBuffer == (int)EOD) {
+ garbageBits++;
+ if (garbageBits > VALUEBITS - 2)
+ syserr("Error in encoded data file.");
+ } else
+ bitsToGo = 8; /* Another Char, 8 new bits */
+ }
+ bit = decodeBuffer & 1; /* Get next bit */
+ decodeBuffer = decodeBuffer >> 1; /* and remove it */
+ bitsToGo--;
+ return bit;
}
/* Current state of decoding */
-static CodeValue value; /* Currently seen code value */
-static CodeValue low, high; /* Current code region */
+static CodeValue value; /* Currently seen code value */
+static CodeValue low, high; /* Current code region */
-void startDecoding(void)
-{
- int i;
+void startDecoding(void) {
+ int i;
- bitsToGo = 0;
- garbageBits = 0;
+ bitsToGo = 0;
+ garbageBits = 0;
- value = 0;
- for (i = 0; i < VALUEBITS; i++)
- value = 2*value + inputBit();
- low = 0;
- high = TOPVALUE;
+ value = 0;
+ for (i = 0; i < VALUEBITS; i++)
+ value = 2 * value + inputBit();
+ low = 0;
+ high = TOPVALUE;
}
-int decodeChar(void)
-{
- long range;
- int f;
- int symbol;
-
- range = (long)(high-low) + 1;
- f = (((long)(value-low)+1)*freq[0]-1)/range;
-
- /* Find the symbol */
- for (symbol = 1; (int)freq[symbol] > f; ++symbol) {}
-
- high = low + range*freq[symbol-1]/freq[0]-1;
- low = low + range*freq[symbol]/freq[0];
-
- for (;;) {
- if (high < HALF)
- ;
- else if (low >= HALF) {
- value = value - HALF;
- low = low - HALF;
- high = high - HALF;
- } else if (low >= ONEQUARTER && high < THREEQUARTER) {
- value = value - ONEQUARTER;
- low = low - ONEQUARTER;
- high = high - ONEQUARTER;
- } else
- break;
-
- /* Scale up the range */
- low = 2*low;
- high = 2*high+1;
- value = 2*value + inputBit();
- }
- return symbol-1;
+int decodeChar(void) {
+ long range;
+ int f;
+ int symbol;
+
+ range = (long)(high - low) + 1;
+ f = (((long)(value - low) + 1) * freq[0] - 1) / range;
+
+ /* Find the symbol */
+ for (symbol = 1; (int)freq[symbol] > f; ++symbol) {}
+
+ high = low + range * freq[symbol - 1] / freq[0] - 1;
+ low = low + range * freq[symbol] / freq[0];
+
+ for (;;) {
+ if (high < HALF)
+ ;
+ else if (low >= HALF) {
+ value = value - HALF;
+ low = low - HALF;
+ high = high - HALF;
+ } else if (low >= ONEQUARTER && high < THREEQUARTER) {
+ value = value - ONEQUARTER;
+ low = low - ONEQUARTER;
+ high = high - ONEQUARTER;
+ } else
+ break;
+
+ /* Scale up the range */
+ low = 2 * low;
+ high = 2 * high + 1;
+ value = 2 * value + inputBit();
+ }
+ return symbol - 1;
}
/* Structure for saved decode info */
struct DecodeInfo {
- long fpos;
- int buffer;
- int bits;
- CodeValue value;
- CodeValue high;
- CodeValue low;
+ long fpos;
+ int buffer;
+ int bits;
+ CodeValue value;
+ CodeValue high;
+ CodeValue low;
};
@@ -141,18 +138,17 @@ struct DecodeInfo {
restore and continue later.
*/
-void *pushDecode(void)
-{
- DecodeInfo *info;
-
- info = (DecodeInfo *)allocate(sizeof(DecodeInfo));
- info->fpos = textFile->pos();
- info->buffer = decodeBuffer;
- info->bits = bitsToGo;
- info->value = value;
- info->high = high;
- info->low = low;
- return(info);
+void *pushDecode(void) {
+ DecodeInfo *info;
+
+ info = (DecodeInfo *)allocate(sizeof(DecodeInfo));
+ info->fpos = textFile->pos();
+ info->buffer = decodeBuffer;
+ info->bits = bitsToGo;
+ info->value = value;
+ info->high = high;
+ info->low = low;
+ return (info);
}
@@ -164,18 +160,17 @@ void *pushDecode(void)
continue after having decoded something else.
*/
-void popDecode(void *i)
-{
- DecodeInfo *info = (DecodeInfo *) i;
-
- textFile->seek(info->fpos);
- decodeBuffer = info->buffer;
- bitsToGo = info->bits;
- value = info->value;
- high = info->high;
- low = info->low;
-
- free(info);
+void popDecode(void *i) {
+ DecodeInfo *info = (DecodeInfo *) i;
+
+ textFile->seek(info->fpos);
+ decodeBuffer = info->buffer;
+ bitsToGo = info->bits;
+ value = info->value;
+ high = info->high;
+ low = info->low;
+
+ free(info);
}
} // End of namespace Alan3