#include "pm2hist.h"
#include "pm2tree.h"
-static unsigned long nextcount;
-static unsigned short lastupdate;
+static off_t nextcount;
+static unsigned long lastupdate;
/* repeated from slide.c */
-static unsigned short dicsiz1;
+static unsigned int dicsiz1;
#define offset (0x100 - 2)
void
hist_update(dtext[lastupdate]);
lastupdate = (lastupdate + 1) & dicsiz1;
}
- while (decode_count >= nextcount)
+
+ while (decode_count >= nextcount) {
/* Actually it will never loop, because count doesn't grow that fast.
However, this is the way LHA does it.
Probably other encoding methods can have repeats larger than 256 bytes.
Note: LHA puts this code in decode_p...
- */
- {
- if (nextcount == 0x0000) {
+ */
+
+ switch (nextcount) {
+ case 0x0000:
maketree1();
maketree2(5);
nextcount = 0x0400;
- }
- else if (nextcount == 0x0400) {
+ break;
+ case 0x0400:
maketree2(6);
nextcount = 0x0800;
- }
- else if (nextcount == 0x0800) {
+ break;
+ case 0x0800:
maketree2(7);
nextcount = 0x1000;
- }
- else if (nextcount == 0x1000) {
+ break;
+ case 0x1000:
if (getbits(1) != 0)
maketree1();
maketree2(8);
nextcount = 0x2000;
- }
- else { /* 0x2000, 0x3000, 0x4000, ... */
+ break;
+ default: /* 0x2000, 0x3000, 0x4000, ... */
if (getbits(1) != 0) {
maketree1();
maketree2(8);
}
nextcount += 0x1000;
+ break;
}
}
gettree1 = tree_get(&tree1); /* value preserved for decode_p */
maketree1()
{
int i, nbits, x;
+
tree1bound = getbits(5);
mindepth = getbits(3);
if (mindepth == 0) {
unsigned char *parentarr, d;
int i, curr, empty, n;
- parentarr = (unsigned char *)malloc(bound * sizeof(unsigned char));
+ parentarr = (unsigned char *)xmalloc(bound);
t->root = 0;
for (i = 0; i < bound; i++) {
t->leftarr[i] = 0;
empty = mindepth;
for (d = mindepth; TRUE; d++) {
for (i = 0; i < bound; i++) {
- if (table[i] == d) {
- if (t->leftarr[curr] == 0)
- t->leftarr[curr] = i | 128;
- else {
- t->rightarr[curr] = i | 128;
- n = 0;
- while (t->rightarr[curr] != 0) {
- if (curr == 0) { /* root? -> done */
- free(parentarr);
- return;
- }
- curr = parentarr[curr];
- n++;
- }
- t->rightarr[curr] = empty;
- for (;;) {
- parentarr[empty] = curr;
- curr = empty;
- empty++;
-
- n--;
- if (n == 0)
- break;
- t->leftarr[curr] = empty;
- }
+ if (table[i] != d)
+ continue;
+
+ if (t->leftarr[curr] == 0) {
+ t->leftarr[curr] = i | 128;
+ continue;
+ }
+
+ t->rightarr[curr] = i | 128;
+ n = 0;
+ while (t->rightarr[curr] != 0) {
+ if (curr == 0) { /* root? -> done */
+ free(parentarr);
+ return;
}
+ curr = parentarr[curr];
+ n++;
+ }
+
+ t->rightarr[curr] = empty;
+ for (;;) {
+ parentarr[empty] = curr;
+ curr = empty;
+ empty++;
+
+ n--;
+ if (n == 0)
+ break;
+ t->leftarr[curr] = empty;
}
}
+
if (t->leftarr[curr] == 0)
t->leftarr[curr] = empty;
else
t->rightarr[curr] = empty;
+ if (empty >= bound) {
+ error("bad archive");
+ exit(1);
+ }
+
parentarr[empty] = curr;
curr = empty;
empty++;