summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuc Verhaegen <libv@skynet.be>2009-06-16 17:29:08 +0200
committerLuc Verhaegen <libv@skynet.be>2009-06-17 14:47:06 +0200
commita36f41a3f8a4c6a9ed44f04b923e801423fd17a0 (patch)
treefbf2a89bdbf0cb34b9dd796b46682b673d3a924d
parente21b0e10387d320ee330e9edc49527afe4eb41e7 (diff)
Clean up interface struct and pass values to decodeM3 directly.
-rw-r--r--phnxdeco/kernel.c27
-rw-r--r--phnxdeco/phnxdeco.c48
-rw-r--r--phnxdeco/phnxdeco.h2
3 files changed, 30 insertions, 47 deletions
diff --git a/phnxdeco/kernel.c b/phnxdeco/kernel.c
index 9add380..ef527ba 100644
--- a/phnxdeco/kernel.c
+++ b/phnxdeco/kernel.c
@@ -19,27 +19,24 @@
#define CBIT 9
#define USHRT_BIT 16 /* (CHAR_BIT * sizeof(ushort)) */
-#define MAX_DICBIT 13
-#define MAX_DICSIZ (1 << MAX_DICBIT)
+#define DICBIT 13
+#define DICSIZ (1 << DICBIT)
#define MATCHBIT 8
#define MAXMATCH 256
#define THRESHOLD 3
#define NC (UCHAR_MAX + MAXMATCH + 2 - THRESHOLD)
-#define NP (MAX_DICBIT + 1)
+#define NP (DICBIT + 1)
#define NT (USHRT_BIT + 3)
#define PBIT 4
#define TBIT 5
#define NPT 0x80
static unsigned long origsize, compsize;
-static unsigned short dicbit;
static unsigned long count;
static unsigned short loc;
static unsigned char *text;
-static unsigned short dicsiz;
-
static unsigned char subbitbuf, bitcount;
static unsigned short crc, bitbuf;
@@ -340,20 +337,20 @@ void decode(interfacing interface)
infile = interface.infile;
outfile = interface.outfile;
- dicbit = interface.dicbit;
origsize = interface.original;
compsize = interface.packed;
+
crc = 0;
prev_char = -1;
- dicsiz = 1 << dicbit;
- text = (unsigned char *) malloc(dicsiz);
+
+ text = (unsigned char *) malloc(DICSIZ);
if (text == NULL)
exit(1);
- memset(text, ' ', dicsiz);
+ memset(text, ' ', DICSIZ);
decode_start_st1();
- dicsiz1 = dicsiz - 1;
+ dicsiz1 = DICSIZ - 1;
offset = 0x100 - 3;
count = 0;
loc = 0;
@@ -363,8 +360,8 @@ void decode(interfacing interface)
if (c <= UCHAR_MAX) {
text[loc++] = c;
- if (loc == dicsiz) {
- fwrite_crc(text, dicsiz, outfile);
+ if (loc == DICSIZ) {
+ fwrite_crc(text, DICSIZ, outfile);
loc = 0;
}
count++;
@@ -375,8 +372,8 @@ void decode(interfacing interface)
for (k = 0; k < j; k++) {
c = text[(i + k) & dicsiz1];
text[loc++] = c;
- if (loc == dicsiz) {
- fwrite_crc(text, dicsiz, outfile);
+ if (loc == DICSIZ) {
+ fwrite_crc(text, DICSIZ, outfile);
loc = 0;
}
}
diff --git a/phnxdeco/phnxdeco.c b/phnxdeco/phnxdeco.c
index b180f09..568786b 100644
--- a/phnxdeco/phnxdeco.c
+++ b/phnxdeco/phnxdeco.c
@@ -145,16 +145,11 @@ static char *GetCompressionName(unsigned char ID)
}
}
-static void decodeM3(interfacing interface)
+static void decodeM3(FILE *ptx, FILE *bmx, unsigned int RealLen)
{
- FILE *ptx, *bmx;
unsigned short Index, Index2, DX, Loop, XorOp, i;
unsigned char *Buffer, tmp;
- unsigned int RealLen, Now;
-
- ptx = interface.infile;
- bmx = interface.outfile;
- RealLen = interface.original;
+ unsigned int Now;
Buffer = (unsigned char *) calloc(4096, 1);
if (!Buffer)
@@ -301,20 +296,17 @@ static unsigned char TotalSec(FILE * ptx, unsigned char * Buf, unsigned char Act
exit(1);
}
- interface.infile = ptx;
- interface.outfile = pto;
- interface.original = phhead.ExpLen1;
- interface.packed = phhead.Packed1;
-
- interface.dicbit = 13;
- interface.method = 5;
-
/* isPacked == PackedLevel == CompressionName */
- if (phhead.isPacked == 0x5)
+ if (phhead.isPacked == 0x5) {
+ interface.infile = ptx;
+ interface.outfile = pto;
+ interface.original = phhead.ExpLen1;
+ interface.packed = phhead.Packed1;
+
decode(interface);
- else if (phhead.isPacked == 0x3) {
+ } else if (phhead.isPacked == 0x3) {
fseek(ptx, -4L, 1);
- decodeM3(interface);
+ decodeM3(ptx, pto, phhead.ExpLen1);
} else {
fseek(ptx, -4L, 1);
for (i = 0; i < phhead.ExpLen1; i++) {
@@ -418,21 +410,17 @@ static unsigned char TotalSecM(FILE * ptx, unsigned char * Buf, unsigned char Ac
exit(1);
}
-
- interface.infile = ptx;
- interface.outfile = pto;
- interface.original = phhead.ExpLen1;
- interface.packed = phhead.Packed1;
-
- interface.dicbit = 13;
- interface.method = 5;
-
/* Evidently, isPacked == PackedLevel */
- if (phhead.isPacked == 0x5)
+ if (phhead.isPacked == 0x5) {
+ interface.infile = ptx;
+ interface.outfile = pto;
+ interface.original = phhead.ExpLen1;
+ interface.packed = phhead.Packed1;
+
decode(interface);
- else if (phhead.isPacked == 0x3) {
+ } else if (phhead.isPacked == 0x3) {
fseek(ptx, -4L, 1);
- decodeM3(interface);
+ decodeM3(ptx, pto, phhead.ExpLen1);
} else {
fseek(ptx, -4L, 1);
for (i = 0; i < phhead.ExpLen1; i++) {
diff --git a/phnxdeco/phnxdeco.h b/phnxdeco/phnxdeco.h
index 6dd51c6..2453471 100644
--- a/phnxdeco/phnxdeco.h
+++ b/phnxdeco/phnxdeco.h
@@ -3,8 +3,6 @@ typedef struct {
FILE *outfile;
unsigned long original;
unsigned long packed;
- int dicbit;
- int method;
} interfacing;
void decode(interfacing interface);