summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xXenogears/Makefile13
-rw-r--r--Xenogears/reinsert.cpp121
-rw-r--r--generic/Handle.cpp8
-rwxr-xr-xgeneric/Makefile5
-rw-r--r--generic/Output.cpp4
-rw-r--r--generic/String.cpp25
-rw-r--r--includes/Handle.h2
-rw-r--r--includes/Input.h1
-rw-r--r--includes/Output.h3
-rw-r--r--includes/String.h4
-rw-r--r--includes/cdutils.h62
-rw-r--r--includes/generic.h23
-rw-r--r--includes/lzss.h5
-rwxr-xr-xlib/Makefile2
-rw-r--r--lib/cdutils.cpp436
-rw-r--r--lib/dteutils.cpp42
-rw-r--r--lib/lzss.cpp38
17 files changed, 253 insertions, 541 deletions
diff --git a/Xenogears/Makefile b/Xenogears/Makefile
index 4fec754..50cc0f4 100755
--- a/Xenogears/Makefile
+++ b/Xenogears/Makefile
@@ -4,23 +4,26 @@ CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -I../includes
CXX=g++
CC=gcc
+LIBS=-lz
+LDFLAGS=${LIBS}
+
TARGET = reinsert main_dump Decrypt script-comp script-dec XenoCD1.sqr XenoCD2.sqr compil compil-2
all: ${TARGET}
-main_dump: main_dump.o ../includes/cdutils.h ../includes/fileutils.h ../includes/generic.h ../includes/yazedc.h ../lib/lib.a ../generic/generic.a Makefile
+main_dump: main_dump.o ../includes/cdutils.h ../includes/generic.h ../includes/yazedc.h ../lib/lib.a ../generic/generic.a Makefile
${CXX} ${LDFLAGS} main_dump.o ../lib/lib.a ../generic/generic.a -o main_dump
-reinsert: reinsert.o ../includes/cdutils.h ../includes/fileutils.h ../includes/generic.h ../includes/yazedc.h ../lib/lib.a ../generic/generic.a Makefile
+reinsert: reinsert.o ../includes/cdutils.h ../includes/generic.h ../includes/yazedc.h ../lib/lib.a ../generic/generic.a Makefile
${CXX} ${LDFLAGS} reinsert.o ../lib/lib.a ../generic/generic.a -o reinsert
-Decrypt: Decrypt.o ../includes/fileutils.h ../includes/generic.h ../generic/generic.a Makefile
+Decrypt: Decrypt.o ../includes/generic.h ../generic/generic.a Makefile
${CXX} ${LDFLAGS} Decrypt.o ../generic/generic.a -o Decrypt
-script-comp: script-comp.o ../includes/fileutils.h ../includes/generic.h ../includes/lzss.h ../lib/lib.a ../generic/generic.a Makefile
+script-comp: script-comp.o ../includes/generic.h ../includes/lzss.h ../lib/lib.a ../generic/generic.a Makefile
${CXX} ${LDFLAGS} script-comp.o ../lib/lib.a ../generic/generic.a -o script-comp
-script-dec: script-dec.o ../includes/fileutils.h ../includes/generic.h ../includes/lzss.h ../lib/lib.a ../generic/generic.a Makefile
+script-dec: script-dec.o ../includes/generic.h ../includes/lzss.h ../lib/lib.a ../generic/generic.a Makefile
${CXX} ${LDFLAGS} script-dec.o ../lib/lib.a ../generic/generic.a -o script-dec
compil: compil.o
diff --git a/Xenogears/reinsert.cpp b/Xenogears/reinsert.cpp
index d6e0a4c..1227fcc 100644
--- a/Xenogears/reinsert.cpp
+++ b/Xenogears/reinsert.cpp
@@ -2,9 +2,10 @@
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
-#include "fileutils.h"
#include "cdutils.h"
#include "generic.h"
+#include "Input.h"
+#include "Output.h"
unsigned int tourne = 0;
@@ -18,38 +19,38 @@ struct t_index_tab {
struct t_sequence {
unsigned int n;
unsigned int sum;
- char *prefix;
- char *name;
+ String prefix;
+ String name;
int type;
};
-char *title, *iso_filename, *prefix, *in_filename;
+String title, iso_filename, prefix, in_filename;
unsigned long iso_size;
unsigned int nb_records, nb_seqs = 0;
struct t_sequence sequences[1000];
int slus_index = -1, force = 0;
-long check_iso(int f_iso);
-void write_files(int f_iso_r, int f_iso_w, int f_in, int fileindex);
-int process_def_file(int f_def);
+long check_iso(Handle * f_iso);
+void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileindex);
+int process_def_file(Handle * f_def);
unsigned char user_data[2352];
void usage(char ** argv) {
- fprintf(stderr, "Usage: %s <definition_file.sqr> <iso_file_name> <file_index> <filename> [-f]\nSee readme.txt for details\n",
+ printm(M_BARE, "Usage: %s <definition_file.sqr> <iso_file_name> <file_index> <filename> [-f]\nSee readme.txt for details\n",
argv[0]);
exit(-1);
}
int main(int argc, char **argv)
{
- int f_def, f_iso_r, f_iso_w, f_in;
+ Handle * f_def, * f_iso_r, * f_iso_w, * f_in;
int fileindex;
verbosity = 1;
- fprintf(stderr, "Xenogears File Insertor by Nicolas \"Pixel\" Noble\n\n");
+ printm(M_BARE, "Xenogears File Insertor by Nicolas \"Pixel\" Noble\n\n");
if ((argc != 5) && (argc != 6)) {
usage(argv);
@@ -65,13 +66,10 @@ int main(int argc, char **argv)
printm(M_STATUS, "Processing file %s...\n", argv[1]);
- if ((f_def = open(argv[1], O_RDONLY)) < 0) {
- printm(M_ERROR, "Unable to open the definition file \"%s\"...\n", argv[1]);
- exit(-1);
- }
+ f_def = new Input(argv[1]);
if (process_def_file(f_def)) {
- close(f_def);
+ delete f_def;
printm(M_ERROR, "Unable to process the definition file \"%s\"...\n", argv[1]);
exit(-1);
}
@@ -79,74 +77,58 @@ int main(int argc, char **argv)
iso_filename = argv[2];
printm(M_STATUS, "Begin processing iso file.\n");
- if ((f_iso_r = open(iso_filename, O_RDONLY)) < 0) {
- printm(M_ERROR, "Unable to open the iso file \"%s\"...\n", iso_filename);
- exit(-1);
- }
-
- if ((f_iso_w = open(iso_filename, O_WRONLY)) < 0) {
- printm(M_ERROR, "Unable to open the iso file \"%s\"...\n", iso_filename);
- exit(-1);
- }
-
- if (lseek(f_iso_w, 0, SEEK_SET)) {
- printm(M_ERROR, "Can't rewind the file\n");
- exit(-1);
- }
+ f_iso_r = new Input(iso_filename);
+ f_iso_w = new Output(iso_filename, 0, 0);
+ f_iso_w->seek(0, SEEK_SET);
if (check_iso(f_iso_r)) {
- printm(M_ERROR, "Invalid iso file for %s\n", title);
+ printm(M_ERROR, "Invalid iso file for " + title + "\n");
printm(M_ERROR, "===> Make sure you are using a Genuine iso file.\n");
exit(-1);
} else {
- printm(M_INFO, "Genuine %s iso detected.\n", title);
+ printm(M_INFO, "Genuine " + title + " iso detected.\n");
}
fileindex = atoi(argv[3]);
in_filename = argv[4];
- if ((f_in = open(in_filename, O_RDONLY)) < 0) {
- printm(M_ERROR, "Unable to open the file \"%s\"...\n", in_filename);
- exit(-1);
- }
+ f_in = new Input(in_filename);
printm(M_STATUS, "Entering files write sequence\n");
write_files(f_iso_r, f_iso_w, f_in, fileindex);
- close(f_iso_r);
- close(f_iso_w);
+ delete f_iso_r;
+ delete f_iso_w;
exit(0);
}
/*
* Ugly but working... for now
*/
-int process_def_file(int ff_def)
+int process_def_file(Handle * f_def)
{
- char t[1024], *p;
- FILE * f_def = fdopen(ff_def, "r");
unsigned int n, sum = 0;
+ String t;
- if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL)
- return 1;
- *p = 0;
- printm(M_INFO, "Read title: %s\n", t);
- title = strdup(t);
+ *f_def >> t;
+ printm(M_INFO, "Read title: " + t + "\n");
+ title = t;
- if (fscanf(f_def, "%lu\n", &iso_size) != 1)
+ *f_def >> t;
+ if (sscanf(t.to_charp(), "%lu\n", &iso_size) != 1)
return 1;
printm(M_INFO, "Read iso size: %lu bytes\n", iso_size);
- if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL)
- return 1;
- *p = 0;
- printm(M_INFO, "Read global directory prefix: %s\n", t);
- prefix = strdup(t);
+ *f_def >> t;
+ printm(M_INFO, "Read global directory prefix: " + t + "\n");
+ prefix = t;
- if (fscanf(f_def, "%u\n", &nb_records) != 1)
+ *f_def >> t;
+ if (sscanf(t.to_charp(), "%u\n", &nb_records) != 1)
return 1;
printm(M_INFO, "Read total of records: %u\n", nb_records);
while (1) {
- if (fscanf(f_def, "%u\n", &n) != 1)
+ *f_def >> t;
+ if (sscanf(t.to_charp(), "%u\n", &n) != 1)
return 1;
if (!n) {
if (sum == nb_records) {
@@ -160,29 +142,26 @@ int process_def_file(int ff_def)
sum += n;
sequences[nb_seqs].n = n;
sequences[nb_seqs].sum = sum;
- if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL)
- return 1;
- *p = 0;
- sequences[nb_seqs].prefix = strdup(t);
- if (fscanf(f_def, "%u\n", &n) != 1)
+ *f_def >> t;
+ sequences[nb_seqs].prefix = t;
+ *f_def >> t;
+ if (sscanf(t.to_charp(), "%u\n", &n) != 1)
return 1;
sequences[nb_seqs].type = n;
- if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL)
- return 1;
- *p = 0;
- sequences[nb_seqs].name = strdup(t);
- printm(M_INFO, "Read definition of sequence %i:\n===> %5i (sum = %5i) chunks of %s (%s)\n",
- nb_seqs, n, sum, t, sequences[nb_seqs].prefix);
+ *f_def >> t;
+ sequences[nb_seqs].name = t;
+ printm(M_INFO, "Read definition of sequence %i:\n===> %5i (sum = %5i) chunks of " + t +
+ " (" + sequences[nb_seqs].prefix + ")\n", nb_seqs, n, sum);
nb_seqs++;
}
}
-long check_iso(int f_iso)
+long check_iso(Handle * f_iso)
{
unsigned long length;
- length = filesize(f_iso);
- printm(M_INFO, "Filesize of iso file %s is %ld bytes\n", iso_filename, length);
+ length = f_iso->GetSize();
+ printm(M_INFO, "Filesize of iso file " + iso_filename + " is %ld bytes\n", length);
if (length != iso_size) {
return 1;
}
@@ -191,7 +170,7 @@ long check_iso(int f_iso)
#define INDEXPOS 24
-void rewrite_fat(int f_iso_r, int f_iso_w, unsigned char * new_fat) {
+void rewrite_fat(Handle * f_iso_r, Handle * f_iso_w, Byte * new_fat) {
unsigned char old_fat[34816];
int i;
@@ -215,7 +194,7 @@ void rewrite_fat(int f_iso_r, int f_iso_w, unsigned char * new_fat) {
}
}
-void write_files(int f_iso_r, int f_iso_w, int f_in, int fileindex)
+void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileindex)
{
t_index_tab index_tab[10000];
unsigned char t[8];
@@ -258,7 +237,7 @@ void write_files(int f_iso_r, int f_iso_w, int f_in, int fileindex)
if (sequences[seq].sum == i)
seq++;
index_tab[i].type = sequences[seq].type;
- if (!strcmp(sequences[seq].prefix, "SLUS")) {
+ if (sequences[seq].prefix == "SLUS") {
if (slus_index >= 0) {
printm(M_ERROR, "Two SLUS files defined\n");
exit(-1);
@@ -274,7 +253,7 @@ void write_files(int f_iso_r, int f_iso_w, int f_in, int fileindex)
printm(M_INFO, "SLUS file found at sector %6i\n", slus_index);
- new_file_size = filesize(f_in);
+ new_file_size = f_in->GetSize();
old_file_size = index_tab[fileindex].size;
new_nb_sects = new_file_size / sec_sizes[index_tab[fileindex].type];
diff --git a/generic/Handle.cpp b/generic/Handle.cpp
index 6d02381..44b01de 100644
--- a/generic/Handle.cpp
+++ b/generic/Handle.cpp
@@ -289,3 +289,11 @@ ssize_t Handle::uread(void * buf, size_t count) {
off_t Handle::tell() {
return itell;
}
+
+bool Handle::CanSeek() {
+ return 0;
+}
+
+off_t Handle::seek(off_t, int) throw(GeneralException) {
+ throw IOGeneral("Handle " + GetName() + " can't seek");
+}
diff --git a/generic/Makefile b/generic/Makefile
index 99a9631..4ca5e32 100755
--- a/generic/Makefile
+++ b/generic/Makefile
@@ -2,11 +2,12 @@
CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -I../includes -DPARANOID_SEEK -DHAVE_ZLIB
CXX=g++
+CC=gcc
-OBJECTS = Buffer.o Exceptions.o Handle.o Image.o Input.o Output.o generic.o String.o
+OBJECTS = Buffer.o Exceptions.o Handle.o Image.o Input.o Output.o generic.o String.o checkargs.o datecalc.o
TARGET = generic.a
-all: ${TARGET}
+all: ${TARGET} Makefile
generic.a: ${OBJECTS}
ar -r generic.a ${OBJECTS}
diff --git a/generic/Output.cpp b/generic/Output.cpp
index 72d00cf..e136524 100644
--- a/generic/Output.cpp
+++ b/generic/Output.cpp
@@ -13,8 +13,8 @@
#define _(x) x
#endif
-Output::Output(String no, int trunc) throw (GeneralException) :
- Handle(no.strlen() ? open(no.to_charp(), O_WRONLY | O_CREAT | (trunc ? O_TRUNC : O_APPEND), 00666) : dup(1)),
+Output::Output(String no, int create, int trunc) throw (GeneralException) :
+ Handle(no.strlen() ? open(no.to_charp(), O_WRONLY | (O_CREAT * (create ? 1 : 0)) | (trunc ? O_TRUNC : O_APPEND), 00666) : dup(1)),
n(no) {
if (GetHandle() < 0) {
throw IOGeneral(String(_("Error opening file ")) + no + _(" for writing: ") + strerror(errno));
diff --git a/generic/String.cpp b/generic/String.cpp
index 49b4e4d..0f4da24 100644
--- a/generic/String.cpp
+++ b/generic/String.cpp
@@ -23,7 +23,19 @@ String::String(char c) : siz(1) {
str = t;
}
-String::String(const char * s) : str(s ? Base::strdup(s) : Base::strdup("")) {
+String::String(const char * s, ...) : str(s ? Base::strdup(s) : Base::strdup("")) {
+ va_list ap;
+
+ if (!s)
+ return;
+
+/* This causes a warning: cannot pass objects of type `const String' through `...'
+ but it is not really a problem. */
+ va_start(ap, s);
+ vsnprintf(t, BUFSIZ, s, ap);
+ free(str);
+ str = Base::strdup(t);
+ va_end(ap);
siz = ::strlen(str);
}
@@ -78,6 +90,13 @@ String::~String() {
const char * String::set(const char * s, ...) {
va_list ap;
+ if (!s) {
+ free(str);
+ str = Base::strdup("");
+ t[0] = 0;
+ return t;
+ }
+
/* This causes a warning: cannot pass objects of type `const String' through `...'
but it is not really a problem. */
va_start(ap, s);
@@ -354,3 +373,7 @@ bool String::is_time(void) const {
return (extract(p + 1).to_int() < 60) ? true : false;
}
+
+String operator+(const char * a, const String & b) {
+ return String(a) + b;
+}
diff --git a/includes/Handle.h b/includes/Handle.h
index 3836f3e..368ec40 100644
--- a/includes/Handle.h
+++ b/includes/Handle.h
@@ -25,7 +25,7 @@ class Handle : public Base {
virtual bool CanRead();
virtual bool CanWrite();
virtual bool CanSeek();
- virtual off_t seek(off_t, int) throw (GeneralException);
+ virtual off_t seek(off_t, int = SEEK_SET) throw (GeneralException);
virtual off_t tell();
virtual String GetName();
virtual ssize_t GetSize();
diff --git a/includes/Input.h b/includes/Input.h
index 8741ebc..8e3e84e 100644
--- a/includes/Input.h
+++ b/includes/Input.h
@@ -16,7 +16,6 @@ class Input : public Handle {
virtual bool CanRead();
virtual bool CanSeek();
virtual off_t seek(off_t, int) throw (GeneralException);
- virtual off_t tell();
virtual String GetName();
virtual ssize_t GetSize();
virtual time_t GetModif();
diff --git a/includes/Output.h b/includes/Output.h
index b7c8fb8..bce4160 100644
--- a/includes/Output.h
+++ b/includes/Output.h
@@ -9,14 +9,13 @@
class Output : public Handle {
public:
- Output(String = "", int trunc = 1) throw (GeneralException);
+ Output(String = "", int create = 1, int trunc = 1) throw (GeneralException);
Output(const Output &);
virtual ~Output() {}
virtual bool CanWrite();
virtual bool CanRead();
virtual bool CanSeek();
virtual off_t seek(off_t, int) throw (GeneralException);
- virtual off_t tell();
virtual String GetName();
protected:
diff --git a/includes/String.h b/includes/String.h
index 1fd6183..7b5fdc4 100644
--- a/includes/String.h
+++ b/includes/String.h
@@ -9,7 +9,7 @@
class String : public Base {
public:
String(const String &);
- String(const char * = "");
+ String(const char * = "", ...);
String(char);
String(int);
String(unsigned int);
@@ -61,6 +61,8 @@ class String : public Base {
std::ostream & operator<<(std::ostream &, const String &);
std::istream & operator>>(std::istream &, String &);
+String operator+(const char *, const String &);
+
#else
#error This only works with a C++ compiler
#endif
diff --git a/includes/cdutils.h b/includes/cdutils.h
index 3dcf7ac..fa44ca6 100644
--- a/includes/cdutils.h
+++ b/includes/cdutils.h
@@ -23,6 +23,8 @@
#include "yazedc.h"
#include "generic.h"
+#include "Handle.h"
+
#define GUESS 5
struct DirEntry {
@@ -40,8 +42,8 @@ struct DirEntry {
unsigned char Second;
unsigned char Offset;
unsigned char Flags;
- unsigned char FileUnit;
- unsigned char FileGap;
+ unsigned char HandleUnit;
+ unsigned char HandleGap;
unsigned short VolSeq;
unsigned short BEVolSeq;
unsigned char N;
@@ -52,48 +54,30 @@ extern struct DirEntry rootDir;
extern long sec_sizes[];
extern long sec_offsts[];
-extern char * sec_modes[];
+extern String sec_modes[];
-FILE * open_ppf(char * ppf, FILE * iso, char * comment);
-FILE * open_ppf(char * ppf, int iso, char * comment);
+Handle * open_ppf(String ppf, Handle * iso, char * comment);
unsigned short int swap_word(unsigned short int i);
unsigned long int swap_dword(unsigned long int i);
-int guess_type(FILE * f_iso, int number);
-int guess_type(int f_iso, int number);
-void sector_seek(FILE * f_iso, long sector);
-void sector_seek(int f_iso, long sector);
-long read_sector(FILE * f_iso, unsigned char * buffer, char type, int number = -1);
-long read_sector(int f_iso, unsigned char * buffer, char type, int number = -1);
-void read_datas(FILE * f_iso, unsigned char * buffer, int type, int number, long size);
-void read_datas(int f_iso, unsigned char * buffer, int type, int number, long size);
-void read_file(FILE * f_iso, FILE * file, char type, int number, long size);
-void read_file(int f_iso, int file, char type, int number, long size);
-void write_sector(FILE * f_iso_r, FILE * f_iso_w, unsigned char * buffer, char type, int number = -1);
-void write_sector(int f_iso_r, int f_iso_w, unsigned char * buffer, char type, int number = -1);
-void write_datas(FILE * f_iso_r, FILE * f_iso_w, unsigned char * buffer, char type, int number, long size);
-void write_datas(int f_iso_r, int f_iso_w, unsigned char * buffer, char type, int number, long size);
-void write_file(FILE * f_iso_r, FILE * f_iso_w, FILE * file, char type, int number = -1);
-void write_file(int f_iso_r, int f_iso_w, int file, char type, int number = -1);
-int get_iso_infos(FILE * h);
-int get_iso_infos(int h);
-int show_iso_infos(FILE * h);
-int show_iso_infos(int h);
-int get_pt_infos(FILE * h);
-int get_pt_infos(int h);
-int show_pt_infos(FILE * h);
-int show_pt_infos(int h);
-struct DirEntry find_path(FILE * h, char * path);
-struct DirEntry find_path(int h, char * path);
-struct DirEntry find_parent(FILE * h, char * path);
-struct DirEntry find_parent(int h, char * path);
+int guess_type(Handle * f_iso, int number);
+void sector_seek(Handle * f_iso, long sector);
+long read_sector(Handle * f_iso, Byte * buffer, int type, int number = -1);
+void read_datas(Handle * f_iso, Byte * buffer, int type, int number, long size);
+void read_Handle(Handle * f_iso, Handle * Handle, int type, int number, long size);
+void write_sector(Handle * f_iso_r, Handle * f_iso_w, Byte * buffer, int type, int number = -1);
+void write_datas(Handle * f_iso_r, Handle * f_iso_w, Byte * buffer, int type, int number, long size);
+void write_file(Handle * f_iso_r, Handle * f_iso_w, Handle * Handle, int type, int number = -1);
+int get_iso_infos(Handle * h);
+int show_iso_infos(Handle * h);
+int get_pt_infos(Handle * h);
+int show_pt_infos(Handle * h);
+struct DirEntry find_path(Handle * h, String path);
+struct DirEntry find_parent(Handle * h, String path);
void show_head_entry(void);
int show_entry(struct DirEntry * dir);
-int show_dir(FILE * h, struct DirEntry * dir);
-int show_dir(int h, struct DirEntry * dir);
-struct DirEntry find_dir_entry(FILE * h, struct DirEntry * dir, char * name);
-struct DirEntry find_dir_entry(int h, struct DirEntry * dir, char * name);
-struct DirEntry * find_dir_entry(FILE * h, unsigned char ** buffer, struct DirEntry * dir, char * name);
-struct DirEntry * find_dir_entry(int h, unsigned char ** buffer, struct DirEntry * dir, char * name);
+int show_dir(Handle * h, struct DirEntry * dir);
+struct DirEntry find_dir_entry(Handle * h, struct DirEntry * dir, String name);
+struct DirEntry * find_dir_entry(Handle * h, Byte ** buffer, struct DirEntry * dir, String name);
unsigned char from_BCD(unsigned char x);
unsigned char to_BCD(unsigned char x);
int is_valid_BCD(unsigned char x);
diff --git a/includes/generic.h b/includes/generic.h
index 5abb92b..41f3a5f 100644
--- a/includes/generic.h
+++ b/includes/generic.h
@@ -74,9 +74,28 @@ typedef Uint32 DWord;
#endif
extern char verbosity;
-void printm(int level, char * fmt, ...);
char ** split(char * s, char t);
+#ifdef __cplusplus
+class String;
+void printm(int level, String fmt, ...);
+#include "String.h"
+
+#ifndef MAX
+template<class T>
+inline T MAX(T a, T b) {
+ return a < b ? b : a;
+}
+#endif
+
+#ifndef MIN
+template<class T>
+inline T MIN(T a, T b) {
+ return a > b ? b : a;
+}
+#endif
+
+#else
#ifndef MAX
#define MAX(__a,__b) ((__a)<(__b)?(__b):(__a))
#endif
@@ -86,3 +105,5 @@ char ** split(char * s, char t);
#endif
#endif
+
+#endif
diff --git a/includes/lzss.h b/includes/lzss.h
index 127a494..5bfa68a 100644
--- a/includes/lzss.h
+++ b/includes/lzss.h
@@ -22,6 +22,7 @@
#include <stdio.h>
#include "generic.h"
+#include "Handle.h"
#define LZSS_VERSION "3.0.0-pre1"
#define LZSS_NAME "lzss"
@@ -55,8 +56,8 @@ extern scheme_t scheme, schemes[];
extern int tolerate, blockb;
extern long blk, bitmap_count;
-unsigned long lzss_decomp(FILE * f_source, FILE * f_cible, long true_length = -1);
-void lzss_comp(FILE * f_source, FILE * f_cible, long * delta = NULL);
+unsigned long lzss_decomp(Handle * f_source, Handle * f_cible, long true_length = -1);
+void lzss_comp(Handle * f_source, Handle * f_cible, long * delta = NULL);
char swap_bits(char);
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);
}