aboutsummaryrefslogtreecommitdiff
path: root/engines/glk/alan2/decode.cpp
diff options
context:
space:
mode:
authordreammaster2019-06-22 03:43:17 +0100
committerPaul Gilbert2019-06-22 14:40:50 -0700
commit2450df501c152249fe1002a7dee70642563d40a3 (patch)
tree226adf311a755ca71d2c18317199a74b2c130864 /engines/glk/alan2/decode.cpp
parenta3fa9d12a94494f86134f56df6c064d7e48e8580 (diff)
downloadscummvm-rg350-2450df501c152249fe1002a7dee70642563d40a3.tar.gz
scummvm-rg350-2450df501c152249fe1002a7dee70642563d40a3.tar.bz2
scummvm-rg350-2450df501c152249fe1002a7dee70642563d40a3.zip
GLK: ALAN2: astyle formatting
Diffstat (limited to 'engines/glk/alan2/decode.cpp')
-rw-r--r--engines/glk/alan2/decode.cpp172
1 files changed, 86 insertions, 86 deletions
diff --git a/engines/glk/alan2/decode.cpp b/engines/glk/alan2/decode.cpp
index f1ec3db89c..2955c37745 100644
--- a/engines/glk/alan2/decode.cpp
+++ b/engines/glk/alan2/decode.cpp
@@ -28,94 +28,94 @@ namespace Glk {
namespace Alan2 {
/* Bit output */
-static int decodeBuffer; /* Bits to be input */
-static int bitsToGo; /* Bits still in buffer */
-static int garbageBits; /* Bits past EOF */
+static int decodeBuffer; /* Bits to be input */
+static int bitsToGo; /* Bits still in buffer */
+static int garbageBits; /* Bits past EOF */
static int inputBit() {
- int bit;
-
- if (!bitsToGo) { /* More bits available ? */
- decodeBuffer = txtfil->readByte(); /* No, so get more */
- if (decodeBuffer == EOF) {
- 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;
+ int bit;
+
+ if (!bitsToGo) { /* More bits available ? */
+ decodeBuffer = txtfil->readByte(); /* No, so get more */
+ if (decodeBuffer == EOF) {
+ 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() {
- int i;
+ 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() {
- 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;
+ 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 */
typedef 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;
} DecodeInfo;
@@ -128,16 +128,16 @@ typedef struct DecodeInfo {
*/
void *pushDecode() {
- DecodeInfo *info;
-
- info = (DecodeInfo *) allocate(sizeof(DecodeInfo));
- info->fpos = txtfil->pos();
- info->buffer = decodeBuffer;
- info->bits = bitsToGo;
- info->value = value;
- info->high = high;
- info->low = low;
- return(info);
+ DecodeInfo *info;
+
+ info = (DecodeInfo *) allocate(sizeof(DecodeInfo));
+ info->fpos = txtfil->pos();
+ info->buffer = decodeBuffer;
+ info->bits = bitsToGo;
+ info->value = value;
+ info->high = high;
+ info->low = low;
+ return (info);
}
@@ -150,15 +150,15 @@ void *pushDecode() {
*/
void popDecode(void *i) {
- DecodeInfo *info = (DecodeInfo *) i;
- fseek(txtfil, info->fpos, 0);
- decodeBuffer = info->buffer;
- bitsToGo = info->bits;
- value = info->value;
- high = info->high;
- low = info->low;
-
- free(info);
+ DecodeInfo *info = (DecodeInfo *) i;
+ fseek(txtfil, info->fpos, 0);
+ decodeBuffer = info->buffer;
+ bitsToGo = info->bits;
+ value = info->value;
+ high = info->high;
+ low = info->low;
+
+ free(info);
}
} // End of namespace Alan2