summaryrefslogtreecommitdiff
path: root/lib/lzss.cpp
diff options
context:
space:
mode:
authorPixel <Pixel>2002-08-17 01:48:34 +0000
committerPixel <Pixel>2002-08-17 01:48:34 +0000
commit11bf45f50739afb923829b3cc32efb9c8c009613 (patch)
tree1a9a691cdd3a466d55259aa31fff1bfc0fcd8e7a /lib/lzss.cpp
parent08ecf5aae1c7276bb1e78a288cba3a731604758e (diff)
Working with Baltisot now....
Diffstat (limited to 'lib/lzss.cpp')
-rw-r--r--lib/lzss.cpp38
1 files changed, 19 insertions, 19 deletions
diff --git a/lib/lzss.cpp b/lib/lzss.cpp
index 4f9e424..b57f325 100644
--- a/lib/lzss.cpp
+++ b/lib/lzss.cpp
@@ -22,9 +22,9 @@
#include <string.h>
#include <getopt.h>
#include <iostream>
-#include "fileutils.h"
#include "generic.h"
#include "lzss.h"
+#include "Handle.h"
int lzss_maxsize = 18;
int lzss_maxptr = 0x0fff;
@@ -95,7 +95,7 @@ void compute_limits(void) {
printm(M_INFO, "Computed values: maxsize = %i, maxptr = 0x%06x\n", lzss_maxsize, lzss_maxptr);
}
-unsigned long lzss_decomp(FILE * f_source, FILE * f_cible, long true_length)
+unsigned long lzss_decomp(Handle * f_source, Handle * f_cible, long true_length)
{
unsigned char bitmap, fbitmap;
unsigned char valeur;
@@ -115,7 +115,7 @@ unsigned long lzss_decomp(FILE * f_source, FILE * f_cible, long true_length)
compute_limits();
- fread(&length, 1, 4, f_source);
+ f_source->read(&length, 4);
if (true_length >= 0) {
length = true_length;
}
@@ -126,9 +126,9 @@ unsigned long lzss_decomp(FILE * f_source, FILE * f_cible, long true_length)
text_buf = (unsigned char *) malloc(length + 8);
do {
- fread(&bitmap, 1, 1, f_source);
+ f_source->read(&bitmap, 1);
if (scheme.sixteen_bits) {
- fread(&fbitmap, 1, 1, f_source);
+ f_source->read(&fbitmap, 1);
printm(M_INFO, "16bits behavior, false bitmap = %02x\n", fbitmap);
}
if (scheme.bitmap_inversed) {
@@ -136,25 +136,25 @@ unsigned long lzss_decomp(FILE * f_source, FILE * f_cible, long true_length)
}
printm(M_INFO, "Begin of block, bitmap = %02x\n", bitmap);
for (i = 0; i < 8; i++) {
- printm(M_INFO, " - Chunk %i (offset cible = %li = 0x%04x, offset source = %li = 0x%04x)\n", i, ftell(f_cible), ftell(f_cible), ftell(f_source), ftell(f_source));
+ printm(M_INFO, " - Chunk %i (offset cible = %li = 0x%04x, offset source = %li = 0x%04x)\n", i, f_cible->tell(), f_cible->tell(), f_source->tell(), f_source->tell());
if (whole_count >= length)
break;
if ((bitmap & 1) ^ scheme.one_is_compressed) {
for (j = 0; j < (scheme.sixteen_bits ? 2 : 1); j++) {
- reads = fread(&valeur, 1, 1, f_source);
+ reads = f_source->read(&valeur, 1);
if (!reads) {
printm(M_WARNING, " WARNING! PADDING!\n");
free(text_buf);
return length;
}
printm(M_INFO, " Copying 0x%02x\n", valeur);
- fwrite(&valeur, 1, 1, f_cible);
+ f_cible->write(&valeur, 1);
text_buf[r++] = valeur;
whole_count++;
}
} else {
- fread(&val1, 1, 1, f_source);
- fread(&val2, 1, 1, f_source);
+ f_source->read(&val1, 1);
+ f_source->read(&val2, 1);
decomp_length = shift(val1 & scheme.l_mask_1, scheme.l_shft_1) |
shift(val2 & scheme.l_mask_2, scheme.l_shft_2);
decomp_fill = shift(val1 & scheme.f_mask_1, scheme.f_shft_1) |
@@ -169,7 +169,7 @@ unsigned long lzss_decomp(FILE * f_source, FILE * f_cible, long true_length)
decomp_fill = decomp_fill + 3 + scheme.sixteen_bits;
if ((decomp_length == lzss_maxsize) && (scheme.filling)) {
if ((decomp_fill == 3) && (scheme.filling == 2)) {
- fread(&val3, 1, 1, f_source);
+ f_source->read(&val3, 1);
printm(M_INFO, " Found an extended needle (val1 = 0x%02x, val2 = 0x%02x, val3 = 0x%02x)\n", val1, val2, val3);
decomp_fill = val1 + 19;
valeur = val3;
@@ -177,7 +177,7 @@ unsigned long lzss_decomp(FILE * f_source, FILE * f_cible, long true_length)
printm(M_INFO, " Found a 0x%02x-filling needle of %li bytes (val1 = 0x%02x, val2 = 0x%02x)\n", valeur, decomp_fill, val1, val2);
}
for (decomp_count = 0; decomp_count < decomp_fill; decomp_count++) {
- fwrite(&valeur, 1, 1, f_cible);
+ f_cible->write(&valeur, 1);
text_buf[r++] = valeur;
if (!blockb)
whole_count++;
@@ -211,7 +211,7 @@ unsigned long lzss_decomp(FILE * f_source, FILE * f_cible, long true_length)
whole_count++;
if (decomp_count < 0) {
valeur = 0;
- fwrite(&valeur, 1, 1, f_cible);
+ f_cible->write(&valeur, 1);
text_buf[r++] = 0;
if (!negative_error) {
if (!tolerate) {
@@ -223,7 +223,7 @@ unsigned long lzss_decomp(FILE * f_source, FILE * f_cible, long true_length)
}
printm(M_INFO, "Filling with 0\n");
} else {
- fwrite(&text_buf[decomp_count], 1, 1, f_cible);
+ f_cible->write(&text_buf[decomp_count], 1);
printm(M_INFO, "@0x%04x: 0x%02x\n", decomp_count, text_buf[decomp_count]);
text_buf[r++] = text_buf[decomp_count];
}
@@ -418,21 +418,21 @@ unsigned char * lzss_memcomp(unsigned char * r, long * l, long * delta) {
return comp;
}
-void lzss_comp(FILE * f_source, FILE * f_cible, long * delta) {
- long length = filesize(f_source), l;
+void lzss_comp(Handle * f_source, Handle * f_cible, long * delta) {
+ long length = f_source->GetSize(), l;
unsigned char * r = (unsigned char *) malloc(length), * c;
- fread(r, 1, length, f_source);
+ f_source->read(r, length);
l = length;
c = lzss_memcomp(r, &l, delta);
if (delta) {
length += *delta;
}
- fwrite(&length, 1, 4, f_cible);
+ f_cible->write(&length, 4);
if (delta) {
length -= *delta;
}
- fwrite(c, 1, l, f_cible);
+ f_cible->write(c, l);
free(c);
free(r);
}