diff options
author | Pixel <Pixel> | 2002-08-17 01:48:34 +0000 |
---|---|---|
committer | Pixel <Pixel> | 2002-08-17 01:48:34 +0000 |
commit | 11bf45f50739afb923829b3cc32efb9c8c009613 (patch) | |
tree | 1a9a691cdd3a466d55259aa31fff1bfc0fcd8e7a /lib | |
parent | 08ecf5aae1c7276bb1e78a288cba3a731604758e (diff) |
Working with Baltisot now....
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/Makefile | 2 | ||||
-rw-r--r-- | lib/cdutils.cpp | 436 | ||||
-rw-r--r-- | lib/dteutils.cpp | 42 | ||||
-rw-r--r-- | lib/lzss.cpp | 38 |
4 files changed, 105 insertions, 413 deletions
diff --git a/lib/Makefile b/lib/Makefile index 9fbb4b3..e5a1b85 100755 --- a/lib/Makefile +++ b/lib/Makefile @@ -3,7 +3,7 @@ CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -Werror -I../includes CXX=g++ -OBJECTS = cdutils.o dteutils.o lzss.o yazedc.o +OBJECTS = cdutils.o lzss.o yazedc.o TARGET = lib.a all: ${TARGET} diff --git a/lib/cdutils.cpp b/lib/cdutils.cpp index 57c1068..e4d7749 100644 --- a/lib/cdutils.cpp +++ b/lib/cdutils.cpp @@ -24,14 +24,14 @@ #include <unistd.h> #include "generic.h" #include "cdutils.h" -#include "Input.h" +#include "Output.h" Output * ppf_file = 0; int pt1 = -1, pt2 = -1, snum = 0, ptl = 0, root = 0; long sec_sizes[5] = {0, 2048, 2336, 2048, 2324}; long sec_offsts[5] = {0, 16, 16, 24, 24}; -char * sec_modes[5] = {"MODE 0 (no mode)", "MODE 1", "MODE 2", "MODE 2 FORM 1", "MODE 2 FORM 2"}; +String sec_modes[5] = {"MODE 0 (no mode)", "MODE 1", "MODE 2", "MODE 2 FORM 1", "MODE 2 FORM 2"}; struct DirEntry rootDir; @@ -60,7 +60,7 @@ unsigned long from_MSF(unsigned long msf, unsigned long start) { return from_MSF(m, s, f, start); } -Input * open_ppf(String ppf, Handle * iso, String comment) { +Output * open_ppf(String ppf, Handle * iso, String comment) { int i, l; Byte buffer[1024]; @@ -69,10 +69,10 @@ Input * open_ppf(String ppf, Handle * iso, String comment) { l = comment.strlen(); if (l >= 50) { - ppf_file->write(comment.to_char(), 50); + ppf_file->write(comment.to_charp(), 50); } else { char * t = " "; - ppf_file->write(comment, l); + ppf_file->write(comment.to_charp(), l); for (i = l; i < 50; i++) { ppf_file->write(t, 1); } @@ -122,7 +122,7 @@ String format_date(String input) { output += input.extract(10, 11) + ':'; output += input.extract(12, 13) + '.'; output += input.extract(14, 15); - output += String("").set("%+3.1f", ((float) (*(((char *)input) + 16))) / 4); + output += String("").set("%+3.1f", ((float) (*((input.to_charp()) + 16))) / 4); return output; } @@ -161,6 +161,10 @@ int guess_type(Handle * f_iso, int number) { return MODE_0; } +void sector_seek(Handle * f_iso, long sector) { + f_iso->seek(2336 * sector); +} + long read_sector(Handle * f_iso, Byte * buffer, int type, int number) { if (number >= 0) { sector_seek(f_iso, number); @@ -171,7 +175,7 @@ long read_sector(Handle * f_iso, Byte * buffer, int type, int number) { } f_iso->seek(sec_offsts[type], SEEK_CUR); - f_iso->read(buffer, sec_sizes[type], f_iso); + f_iso->read(buffer, sec_sizes[type]); f_iso->seek(2352 - sec_offsts[type] - sec_sizes[type], SEEK_CUR); return sec_sizes[type]; } @@ -221,7 +225,7 @@ void read_file(Handle * f_iso, Handle * file, int type, int number, long size) { } } -void write_sector(Handle * f_iso_r, Handle * f_iso_w, Buffer * buffer, int type, int number) { +void write_sector(Handle * f_iso_r, Handle * f_iso_w, Byte * buffer, int type, int number) { Byte old_sector[2352], new_sector[2352]; if (type == GUESS) { @@ -276,33 +280,7 @@ void write_datas(Handle * f_iso_r, Handle * f_iso_w, Byte * buffer, int type, in } } -void write_datas(int f_iso_r, int f_iso_w, unsigned char * buffer, char type, int number, long size) { - long nbsectors, i; - unsigned char sector[2352]; - - if (type == GUESS) { - type = guess_type(f_iso_r, number); - } - - if (number >= 0) { - sector_seek(f_iso_r, number); - sector_seek(f_iso_w, number); - } - - nbsectors = size / sec_sizes[type]; - - for (i = 0; i < nbsectors; i++) { - write_sector(f_iso_r, f_iso_w, buffer + i * sec_sizes[type], type, number + i); - } - - if (size % sec_sizes[type]) { - memset(sector, 0, 2352); - bcopy((char *) (buffer + i * sec_sizes[type]), (char *) sector, size % sec_sizes[type]); - write_sector(f_iso_r, f_iso_w, sector, type, number + i); - } -} - -void write_file(FILE * f_iso_r, FILE * f_iso_w, FILE * file, char type, int number) { +void write_file(Handle * f_iso_r, Handle * f_iso_w, Handle * file, int type, int number) { long size, nbsectors, i; unsigned char buffer[2352]; @@ -315,7 +293,7 @@ void write_file(FILE * f_iso_r, FILE * f_iso_w, FILE * file, char type, int numb sector_seek(f_iso_w, number); } - size = filesize(file); + size = file->GetSize(); nbsectors = size / sec_sizes[type]; if (size % sec_sizes[type]) { @@ -324,34 +302,7 @@ void write_file(FILE * f_iso_r, FILE * f_iso_w, FILE * file, char type, int numb for (i = 0; i < nbsectors; i++) { memset(buffer, 0, 2352); - fread(buffer, 1, sec_sizes[type], file); - write_sector(f_iso_r, f_iso_w, buffer, type); - } -} - -void write_file(int f_iso_r, int f_iso_w, int file, char type, int number) { - long size, nbsectors, i; - unsigned char buffer[2352]; - - if (type == GUESS) { - type = guess_type(f_iso_r, number); - } - - if (number >= 0) { - sector_seek(f_iso_r, number); - sector_seek(f_iso_w, number); - } - - size = filesize(file); - nbsectors = size / sec_sizes[type]; - - if (size % sec_sizes[type]) { - nbsectors++; - } - - for (i = 0; i < nbsectors; i++) { - memset(buffer, 0, 2352); - read(file, buffer, sec_sizes[type]); + file->read(buffer, sec_sizes[type]); write_sector(f_iso_r, f_iso_w, buffer, type); } } @@ -376,15 +327,15 @@ int show_entry(struct DirEntry * dir) { return dir->R; } -int show_dir(FILE * f_iso, struct DirEntry * dir) { +int show_dir(Handle * f_iso, struct DirEntry * dir) { unsigned int ptr; - unsigned char * buffer; + Byte * buffer; if (!(dir->Flags & 2)) { return 0; } - buffer = (unsigned char *) malloc(dir->Size); + buffer = (Byte *) malloc(dir->Size); read_datas(f_iso, buffer, GUESS, dir->Sector, dir->Size); ptr = 0; @@ -396,56 +347,7 @@ int show_dir(FILE * f_iso, struct DirEntry * dir) { return 1; } -int show_dir(int f_iso, struct DirEntry * dir) { - unsigned int ptr; - unsigned char * buffer; - - if (!(dir->Flags & 2)) { - return 0; - } - - buffer = (unsigned char *) malloc(dir->Size); - read_datas(f_iso, buffer, GUESS, dir->Sector, dir->Size); - - ptr = 0; - while(ptr < dir->Size) { - ptr += show_entry((struct DirEntry *) &(buffer[ptr])); - } - - free(buffer); - return 1; -} - -struct DirEntry find_dir_entry(FILE * f_iso, struct DirEntry * dir, char * name) { - unsigned int ptr, size; - unsigned char * buffer; - struct DirEntry r = {0, 0, 0, 0, 0}; - - if (!(dir->Flags & 2)) { - return r; - } - - buffer = (unsigned char *) malloc(size = dir->Size); - read_datas(f_iso, buffer, GUESS, dir->Sector, dir->Size); - - ptr = 0; - while(ptr < size) { - dir = (struct DirEntry *) &(buffer[ptr]); - if (!dir->R) { - ptr++; - } else { - if (!strncmp(name, (char *) &(dir->id), dir->N)) { - r = *dir; - } - ptr += dir->R; - } - } - - free(buffer); - return r; -} - -struct DirEntry find_dir_entry(int f_iso, struct DirEntry * dir, char * name) { +struct DirEntry find_dir_entry(Handle * f_iso, struct DirEntry * dir, String name) { unsigned int ptr, size; unsigned char * buffer; struct DirEntry r = {0, 0, 0, 0, 0}; @@ -463,7 +365,7 @@ struct DirEntry find_dir_entry(int f_iso, struct DirEntry * dir, char * name) { if (!dir->R) { ptr++; } else { - if (!strncmp(name, (char *) &(dir->id), dir->N)) { + if (!strncmp(name.to_charp(), (char *) &(dir->id), dir->N)) { r = *dir; } ptr += dir->R; @@ -474,9 +376,9 @@ struct DirEntry find_dir_entry(int f_iso, struct DirEntry * dir, char * name) { return r; } -struct DirEntry * find_dir_entry(FILE * f_iso, unsigned char ** bufout, struct DirEntry * dir, char * name) { +struct DirEntry * find_dir_entry(Handle * f_iso, Byte ** bufout, struct DirEntry * dir, String name) { unsigned int ptr, size; - unsigned char * buffer; + Byte * buffer; struct DirEntry * rdir = 0; *bufout = 0; @@ -484,7 +386,7 @@ struct DirEntry * find_dir_entry(FILE * f_iso, unsigned char ** bufout, struct D return 0; } - buffer = (unsigned char *) malloc(size = dir->Size); + buffer = (Byte *) malloc(size = dir->Size); read_datas(f_iso, buffer, GUESS, dir->Sector, dir->Size); ptr = 0; @@ -493,7 +395,7 @@ struct DirEntry * find_dir_entry(FILE * f_iso, unsigned char ** bufout, struct D if (!dir->R) { ptr++; } else { - if (!strncmp(name, (char *) &(dir->id), dir->N)) { + if (!strncmp(name.to_charp(), (char *) &(dir->id), dir->N)) { rdir = dir; } ptr += dir->R; @@ -508,48 +410,14 @@ struct DirEntry * find_dir_entry(FILE * f_iso, unsigned char ** bufout, struct D return rdir; } -struct DirEntry * find_dir_entry(int f_iso, unsigned char ** bufout, struct DirEntry * dir, char * name) { - unsigned int ptr, size; - unsigned char * buffer; - struct DirEntry * rdir = 0; - *bufout = 0; - - if (!(dir->Flags & 2)) { - return 0; - } - - buffer = (unsigned char *) malloc(size = dir->Size); - read_datas(f_iso, buffer, GUESS, dir->Sector, dir->Size); - - ptr = 0; - while(ptr < size) { - dir = (struct DirEntry *) &(buffer[ptr]); - if (!dir->R) { - ptr++; - } else { - if (!strncmp(name, (char *) &(dir->id), dir->N)) { - rdir = dir; - } - ptr += dir->R; - } - } - - if (rdir->R) { - *bufout = buffer; - } else { - free(buffer); - } - return rdir; -} - -int show_iso_infos(FILE * f_iso) { - unsigned char buffer[2048]; +int show_iso_infos(Handle * f_iso) { + char buffer[2048]; char pbuff[130]; short int s, nogood = 0; - read_sector(f_iso, buffer, GUESS, 16); + read_sector(f_iso, (Byte *) buffer, GUESS, 16); - printm(M_BARE, "Sector guessed mode : %s\n", sec_modes[guess_type(f_iso, 16)]); + printm(M_BARE, "Sector guessed mode : " + sec_modes[guess_type(f_iso, 16)] + "\n"); printm(M_BARE, "offset-size-info : contents\n"); printm(M_BARE, " 0 - 1- 1 : %i\n", buffer[0]); memcpy(pbuff, buffer + 1, 5); @@ -602,10 +470,10 @@ int show_iso_infos(FILE * f_iso) { memcpy(pbuff, buffer + 776, 37); pbuff[37] = 0; printm(M_BARE, " 776 - 37- BibFile: %s\n", pbuff); - printm(M_BARE, " 813 - 17- DTCreat: %s\n", format_date(&buffer[813])); - printm(M_BARE, " 830 - 17- DTModif: %s\n", format_date(&buffer[830])); - printm(M_BARE, " 847 - 17- DTExpir: %s\n", format_date(&buffer[847])); - printm(M_BARE, " 864 - 17- DTEffec: %s\n", format_date(&buffer[864])); + printm(M_BARE, " 813 - 17- DTCreat: %s\n", format_date(&buffer[813]).to_charp()); + printm(M_BARE, " 830 - 17- DTModif: %s\n", format_date(&buffer[830]).to_charp()); + printm(M_BARE, " 847 - 17- DTExpir: %s\n", format_date(&buffer[847]).to_charp()); + printm(M_BARE, " 864 - 17- DTEffec: %s\n", format_date(&buffer[864]).to_charp()); printm(M_BARE, "Root record:\n"); show_head_entry(); @@ -614,79 +482,7 @@ int show_iso_infos(FILE * f_iso) { return 1; } -int show_iso_infos(int f_iso) { - unsigned char buffer[2048]; - char pbuff[130]; - short int s, nogood = 0; - - read_sector(f_iso, buffer, GUESS, 16); - - printm(M_BARE, "Sector guessed mode : %s\n", sec_modes[guess_type(f_iso, 16)]); - printm(M_BARE, "offset-size-info : contents\n"); - printm(M_BARE, " 0 - 1- 1 : %i\n", buffer[0]); - memcpy(pbuff, buffer + 1, 5); - pbuff[5] = 0; - printm(M_BARE, " 1 - 5-`CD001' : %s\n", pbuff); - printm(M_BARE, " 6 - 2- 1 : %i\n", s = *((short int *) &(buffer[6]))); - printm(M_BARE, "(*this was the signature*)\n"); - if (buffer[0] != 1) nogood = 1; - if (strcmp(pbuff, "CD001")) nogood = 1; - if (s != 1) nogood = 1; - - if (nogood) { - printm(M_BARE, "Not a valid iso9660 file.\n"); - return 0; - } - - memcpy(pbuff, buffer + 8, 32); - pbuff[32] = 0; - printm(M_BARE, " 8 - 32- SYSID : %s\n", pbuff); - memcpy(pbuff, buffer + 40, 32); - pbuff[32] = 0; - printm(M_BARE, " 40 - 32- VOLID : %s\n", pbuff); - printm(M_BARE, " 80 - 8- SNum : %li\n", *((long int *) &(buffer[80]))); - printm(M_BARE, " 120 - 4- VOLSiz : %i\n", *((short int *) &(buffer[120]))); - printm(M_BARE, " 124 - 4- VOLNum : %i\n", *((short int *) &(buffer[124]))); - printm(M_BARE, " 128 - 4- SSize : %i\n", *((short int *) &(buffer[128]))); - printm(M_BARE, " 132 - 8- PSize : %li\n", *((long int *) &(buffer[132]))); - printm(M_BARE, " 140 - 4- 1SLPath: %i\n", *((short int *) &(buffer[140]))); - printm(M_BARE, " 144 - 4- 2SLPath: %i\n", *((short int *) &(buffer[144]))); - printm(M_BARE, " 148 - 4- 1SBPath: %i\n", swap_dword(*((short int *) &(buffer[148])))); - printm(M_BARE, " 152 - 4- 2SBPath: %i\n", swap_dword(*((short int *) &(buffer[152])))); - memcpy(pbuff, buffer + 190, 128); - pbuff[128] = 0; - printm(M_BARE, " 190 - 128- VStId : %s\n", pbuff); - memcpy(pbuff, buffer + 318, 128); - pbuff[128] = 0; - printm(M_BARE, " 318 - 128- PubId : %s\n", pbuff); - memcpy(pbuff, buffer + 446, 128); - pbuff[128] = 0; - printm(M_BARE, " 446 - 128- DPrId : %s\n", pbuff); - memcpy(pbuff, buffer + 574, 128); - pbuff[128] = 0; - printm(M_BARE, " 574 - 128- AppId : %s\n", pbuff); - memcpy(pbuff, buffer + 702, 37); - pbuff[37] = 0; - printm(M_BARE, " 702 - 37- CpyFile: %s\n", pbuff); - memcpy(pbuff, buffer + 739, 37); - pbuff[37] = 0; - printm(M_BARE, " 739 - 37- AbsFile: %s\n", pbuff); - memcpy(pbuff, buffer + 776, 37); - pbuff[37] = 0; - printm(M_BARE, " 776 - 37- BibFile: %s\n", pbuff); - printm(M_BARE, " 813 - 17- DTCreat: %s\n", format_date(&buffer[813])); - printm(M_BARE, " 830 - 17- DTModif: %s\n", format_date(&buffer[830])); - printm(M_BARE, " 847 - 17- DTExpir: %s\n", format_date(&buffer[847])); - printm(M_BARE, " 864 - 17- DTEffec: %s\n", format_date(&buffer[864])); - - printm(M_BARE, "Root record:\n"); - show_head_entry(); - show_entry((DirEntry *) &(buffer[156])); - - return 1; -} - -int get_iso_infos(FILE * f_iso) { +int get_iso_infos(Handle * f_iso) { unsigned char buffer[2048]; char pbuff[130]; short int s, nogood = 0; @@ -714,36 +510,8 @@ int get_iso_infos(FILE * f_iso) { return 1; } -int get_iso_infos(int f_iso) { - unsigned char buffer[2048]; - char pbuff[130]; - short int s, nogood = 0; - - read_sector(f_iso, buffer, GUESS, 16); - - memcpy(pbuff, buffer + 1, 5); - pbuff[5] = 0; - - s = *((short int *) &(buffer[6])); - if (buffer[0] != 1) nogood = 1; - if (strcmp(pbuff, "CD001")) nogood = 1; - if (s != 1) nogood = 1; - - if (nogood) { - printm(M_ERROR, "Not a valid iso9660 file.\n"); - return 0; - } - - pt1 = *((short int *) &(buffer[140])); - pt2 = *((short int *) &(buffer[144])); - snum = *((int *) &(buffer[80])); - ptl = *((long int *) &(buffer[132])); - rootDir = *((struct DirEntry *) &(buffer[156])); - return 1; -} - -int get_pt_infos(FILE * f_iso) { - unsigned char * buffer; +int get_pt_infos(Handle * f_iso) { + Byte * buffer; if ((pt1 <= 0) && (pt2 <= 0)) if (!get_iso_infos(f_iso)) @@ -754,7 +522,7 @@ int get_pt_infos(FILE * f_iso) { return 0; } - buffer = (unsigned char *) malloc(ptl); + buffer = (Byte *) malloc(ptl); read_datas(f_iso, buffer, GUESS, !pt1 ? pt2 : pt1, ptl); if (buffer[0] == 1) @@ -769,8 +537,8 @@ int get_pt_infos(FILE * f_iso) { return root ? 1 : 0; } -int show_pt_infos(FILE * f_iso) { - unsigned char * buffer; +int show_pt_infos(Handle * f_iso) { + Byte * buffer; char pbuf[100]; int i, ptr; @@ -783,7 +551,7 @@ int show_pt_infos(FILE * f_iso) { return 0; } - buffer = (unsigned char *) malloc(ptl); + buffer = (Byte *) malloc(ptl); read_datas(f_iso, buffer, GUESS, !pt1 ? pt2 : pt1, ptl); printm(M_BARE, "node^paren@sector : name\n"); @@ -798,107 +566,20 @@ int show_pt_infos(FILE * f_iso) { return 1; } -int show_pt_infos(int f_iso) { - unsigned char * buffer; - char pbuf[100]; - int i, ptr; - - if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos(f_iso)) - return 0; - - if ((!pt1) & (!pt2)) { - printm(M_ERROR, "No path table defined.\n"); - return 0; - } - - buffer = (unsigned char *) malloc(ptl); - read_datas(f_iso, buffer, GUESS, !pt1 ? pt2 : pt1, ptl); - - printm(M_BARE, "node^paren@sector : name\n"); - for (ptr = 0, i = 1; buffer[ptr]; ptr += ptr & 1, i++) { - strncpy(pbuf, (char *) &(buffer[8 + ptr]), buffer[ptr]); - pbuf[buffer[ptr]] = 0; - printm(M_BARE, "%3i ^ %3i @ %6i: %s\n", i, *((unsigned short *) &(buffer[6 + ptr])), *((unsigned long *) &(buffer[2 + ptr])), pbuf); - ptr += 8 + buffer[ptr]; - } - - free(buffer); - return 1; -} - -struct DirEntry find_path(FILE * f_iso, char * path) { - char ** pts = split(path, '/'); - struct DirEntry dir = {0, 0, 0, 0, 0}; - - if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos(f_iso)) - return dir; - - if ((!pt1) & (!pt2)) { - printm(M_ERROR, "No path table defined.\n"); - return dir; - } - - if (!**pts) - pts++; - - for (dir = rootDir; *pts; pts++) { - if (!strlen(*pts)) - continue; - dir = find_dir_entry(f_iso, &dir, *pts); - if (!dir.R) - return dir; - } - - return dir; -} - -struct DirEntry find_path(int f_iso, char * path) { - char ** pts = split(path, '/'); +struct DirEntry find_path(Handle * f_iso, String path) { + char * newpath = path.strdup(); + char ** pts = split(newpath, '/'); struct DirEntry dir = {0, 0, 0, 0, 0}; if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos(f_iso)) - return dir; - - if ((!pt1) & (!pt2)) { - printm(M_ERROR, "No path table defined.\n"); - return dir; - } - - if (!**pts) - pts++; - - for (dir = rootDir; *pts; pts++) { - if (!strlen(*pts)) - continue; - dir = find_dir_entry(f_iso, &dir, *pts); - if (!dir.R) - return dir; - } - - return dir; -} - -struct DirEntry find_parent(FILE * f_iso, char * path) { - char ** pts, * p; - struct DirEntry dir = {0, 0, 0, 0, 0}; - - if ((p = strchr(path, '/'))) { - *p = 0; - } - if (!*path) { - return rootDir; - } - pts = split(path, '/'); - - if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos(f_iso)) + if (!get_iso_infos(f_iso)) { + free(newpath); return dir; + } if ((!pt1) & (!pt2)) { printm(M_ERROR, "No path table defined.\n"); + free(newpath); return dir; } @@ -909,31 +590,39 @@ struct DirEntry find_parent(FILE * f_iso, char * path) { if (!strlen(*pts)) continue; dir = find_dir_entry(f_iso, &dir, *pts); - if (!dir.R) + if (!dir.R) { + free(newpath); return dir; + } } + free(newpath); return dir; } -struct DirEntry find_parent(int f_iso, char * path) { +struct DirEntry find_parent(Handle * f_iso, String path) { + char * newpath = path.strdup(); char ** pts, * p; struct DirEntry dir = {0, 0, 0, 0, 0}; - if ((p = strchr(path, '/'))) { + if ((p = strchr(newpath, '/'))) { *p = 0; } - if (!*path) { + if (!*newpath) { + free(newpath); return rootDir; } - pts = split(path, '/'); + pts = split(newpath, '/'); if ((pt1 <= 0) && (pt2 <= 0)) - if (!get_iso_infos(f_iso)) + if (!get_iso_infos(f_iso)) { + free(newpath); return dir; + } if ((!pt1) & (!pt2)) { printm(M_ERROR, "No path table defined.\n"); + free(newpath); return dir; } @@ -944,9 +633,12 @@ struct DirEntry find_parent(int f_iso, char * path) { if (!strlen(*pts)) continue; dir = find_dir_entry(f_iso, &dir, *pts); - if (!dir.R) + if (!dir.R) { + free(newpath); return dir; + } } + free(newpath); return dir; } diff --git a/lib/dteutils.cpp b/lib/dteutils.cpp index 4ae8668..6c8dcc4 100644 --- a/lib/dteutils.cpp +++ b/lib/dteutils.cpp @@ -21,13 +21,13 @@ #include <unistd.h> #include <stdlib.h> #include <string.h> -#include "fileutils.h" #include "generic.h" +#include "Handle.h" class thingtree { public: - static void addstring(const char *, long); - static long look(const char *); + static void addstring(const String, long); + static long look(const String); static void destroy(); private: thingtree(); @@ -57,21 +57,21 @@ thingtree::thingtree(char gchar, bool gterm, thingtree * gfather, long gthingent thingtree::thingtree() : thischar(0), terminal(false), father(0), child(0), brother(0) { } -long thingtree::look(const char * s) { - const char * p; +long thingtree::look(const String s) { long currentthing = -1; thingtree * ptr = root; + int i; if (!ptr) { printm(M_ERROR, "Error: thingtree not initialised\n"); exit(-1); } - for (p = s; *p; p++) { + for (i = 0; s[i]; i++) { // printm(M_INFO, "Looking for '%c'\n", *p); for (ptr = ptr->child; ptr; ptr = ptr->brother) { // printm(M_INFO, "Looking in %p: %c\n", ptr, ptr->thischar); - if (ptr->thischar == *p) { + if (ptr->thischar == s[i]) { if (ptr->terminal) { currentthing = ptr->thingentry; } @@ -85,15 +85,15 @@ long thingtree::look(const char * s) { } if (currentthing == -1) { - printm(M_ERROR, "Error, can't find any entry for string '%s'\n", s); + printm(M_ERROR, "Error, can't find any entry for string '" + s + "'\n"); } return currentthing; } -void thingtree::addstring(const char * s, long thingentry) { - const char * p; +void thingtree::addstring(const String s, long thingentry) { thingtree * ptr, * fptr; + int i; if (!root) { root = new thingtree(); @@ -102,21 +102,21 @@ void thingtree::addstring(const char * s, long thingentry) { // printm(M_INFO, "Creating new thingtree entry: %li='%s'\n", thingentry, s); ptr = root; - for (p = s; *p; p++) { + for (i = 0; s[i]; i++) { fptr = ptr; // printm(M_INFO, "Finding entry for '%c'\n", *p); for (ptr = ptr->child; ptr; ptr = ptr->brother) { // printm(M_INFO, "Browsing childs: %p = %c\n", ptr, ptr->thischar); - if (ptr->thischar == *p) + if (ptr->thischar == s[i]) break; } if (!ptr) { // printm(M_INFO, "Creating new branch for %c\n", *p); - ptr = new thingtree(*p, *(p + 1) == 0, fptr, thingentry); + ptr = new thingtree(s[i], s[i + 1] == 0, fptr, thingentry); // printm(M_INFO, "Created branch %p\n", ptr); } else { - if (*(p + 1) == 0) { + if (s[i + 1] == 0) { ptr->terminal = true; ptr->thingentry = thingentry; } @@ -137,7 +137,7 @@ thingtree::~thingtree() { delete child; } -char * things[256]; +String things[256]; char * dte_text; char dte_flags[256 * 256]; @@ -162,12 +162,12 @@ void dte_reset(void) { void build_dte(void) { int i; - unsigned short t, t2; + Uint16 t, t2; unsigned short p = 0; for (i = 0; i < dte_text_size; i++) { - t = *((unsigned short *) (dte_text + i)); - t2 = *((unsigned short *) (dte_text + i + 1)); + t = *((Uint16 *) (dte_text + i)); + t2 = *((Uint16 *) (dte_text + i + 1)); if (t == p) { p = 0; continue; @@ -208,7 +208,7 @@ void push_entry(long entry) { } } -char * read_line(FILE * f, char * b) { +String read_line(Handle * f, String b) { int r, pos = 0; while (!feof(f)) { @@ -261,7 +261,7 @@ void dte_compress() { printm(M_STATUS, "Estimated gain: %li bytes, new file size = %li\n", gain, dte_text_size - gain); } -void read_thingy(FILE * f) { +void read_thingy(Handle * f) { char line[256], * st, * thing; long code; int i; @@ -296,7 +296,7 @@ void read_thingy(FILE * f) { } } -void read_thingy_file(FILE * f) { +void read_thingy_file(Handle * f) { char line[10240], * p, * c, trans[5]; long code; int ptr = 0, i; 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); } |