From 259110b90336240ce6cdde0201d05ce03a1f73fe Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 9 Sep 2002 14:50:25 +0000 Subject: Doh --- Makefile | 2 +- VP/Makefile | 8 +-- VP/main_dump.cpp | 140 +++++++++++++++++++++-------------------------------- cd-tool.cpp | 2 +- generic/String.cpp | 6 ++- includes/String.h | 4 +- 6 files changed, 66 insertions(+), 96 deletions(-) diff --git a/Makefile b/Makefile index 46dad1d..8f4aa5a 100755 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ #!/usr/bin/make -f CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -Werror -Iincludes `sdl-config --cflags` -DHAVE_ZLIB -LDFLAGS=`sdl-config --libs` -lz -lefence +LDFLAGS=-lz CXX=g++ SUBDIRS = psxdev generic lib Xenogears diff --git a/VP/Makefile b/VP/Makefile index 243d11b..27af592 100755 --- a/VP/Makefile +++ b/VP/Makefile @@ -7,16 +7,16 @@ TARGET = main_dump VP-CD1.sqr decomp-slz unarc search-script all: ${TARGET} -main_dump: main_dump.o ../includes/fileutils.h ../includes/cdutils.h ../includes/generic.h ../lib/lib.a ../generic/generic.a Makefile +main_dump: main_dump.o ../includes/cdutils.h ../includes/generic.h ../lib/lib.a ../generic/generic.a Makefile ${CXX} ${LDFLAGS} main_dump.o ../lib/lib.a ../generic/generic.a -o main_dump -decomp-slz: decomp-slz.o ../includes/fileutils.h ../includes/generic.h ../includes/lzss.h Makefile +decomp-slz: decomp-slz.o ../includes/generic.h ../includes/lzss.h Makefile ${CXX} ${LDFLAGS} decomp-slz.o ../lib/lib.a ../generic/generic.a -o decomp-slz -unarc: unarc.o ../includes/fileutils.h ../includes/generic.h Makefile +unarc: unarc.o ../includes/generic.h Makefile ${CXX} ${LDFLAGS} unarc.o ../generic/generic.a -o unarc -search-script: search-script.o ../includes/fileutils.h ../includes/generic.h Makefile +search-script: search-script.o ../includes/generic.h Makefile ${CXX} ${LDFLAGS} search-script.o ../generic/generic.a -o search-script clean: diff --git a/VP/main_dump.cpp b/VP/main_dump.cpp index 21b5201..0845e1a 100644 --- a/VP/main_dump.cpp +++ b/VP/main_dump.cpp @@ -28,9 +28,11 @@ #include #include #include -#include "fileutils.h" #include "cdutils.h" #include "generic.h" +#include "Input.h" +#include "Output.h" +#include "String.h" unsigned int tourne = 0; @@ -44,26 +46,26 @@ 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; +String title, iso_filename, prefix; unsigned long iso_size; unsigned int nb_records, nb_seqs = 0; struct t_sequence sequences[1000]; -long check_iso(FILE * f_iso); -void read_files(FILE * f_iso); -void file_dump(FILE * f_iso, unsigned long debut, unsigned long taille, long num, int seq); -int process_def_file(FILE * f_def); +long check_iso(Handle * f_iso); +void read_files(Handle * f_iso); +void file_dump(Handle * f_iso, unsigned long debut, unsigned long taille, long num, int seq); +int process_def_file(Handle * f_def); unsigned char user_data[2352]; int main(int argc, char **argv) { - FILE * f_def, * f_iso; + Handle * f_def, * f_iso; verbosity = M_STATUS; @@ -79,13 +81,10 @@ int main(int argc, char **argv) printm(M_STATUS, "Processing file %s...\n", argv[1]); - if (!(f_def = fopen(argv[1], "r"))) { - 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)) { - fclose(f_def); + delete f_def; printm(M_ERROR, "Unable to process the definition file \"%s\"...\n", argv[1]); exit(-1); } @@ -93,54 +92,45 @@ int main(int argc, char **argv) iso_filename = argv[2]; printm(M_STATUS, "Begin processing iso file.\n"); - if (!(f_iso = fopen(iso_filename, "r"))) { - printm(M_ERROR, "Unable to open the iso file \"%s\"...\n", iso_filename); - exit(-1); - } + f_iso = new Input(iso_filename); if (check_iso(f_iso)) { - 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"); } else { - printm(M_INFO, "Genuine %s iso detected.\n", title); + printm(M_INFO, "Genuine " + title + " iso detected.\n"); } printm(M_STATUS, "Entering files read sequence\n"); read_files(f_iso); - fclose(f_iso); + delete f_iso; exit(0); } /* * Ugly but working... for now */ -int process_def_file(FILE * f_def) +int process_def_file(Handle * f_def) { - char t[1024], *p; + String t; unsigned int n, sum = 0; - 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 >> title; + printm(M_INFO, "Read title: " + title + "\n"); - if (fscanf(f_def, "%lu\n", &iso_size) != 1) - return 1; + *f_def >> t; + iso_size = t.to_int(); 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 >> prefix; + printm(M_INFO, "Read global directory prefix: " + prefix + "\n"); - if (fscanf(f_def, "%u\n", &nb_records) != 1) - return 1; + *f_def >> t; + nb_records = t.to_int(); printm(M_INFO, "Read total of records: %u\n", nb_records); while (1) { - if (fscanf(f_def, "%u\n", &n) != 1) - return 1; + *f_def >> t; + n = t.to_int(); if (!n) { if (sum == nb_records) { printm(M_INFO, "Definition file seems coherent\n"); @@ -153,36 +143,29 @@ int process_def_file(FILE * f_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) - 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 >> sequences[nb_seqs].prefix; + *f_def >> t; + sequences[nb_seqs].type = t.to_int(); + *f_def >> sequences[nb_seqs].name; + printm(M_INFO, "Read definition of sequence %i:\n===> %5i (sum = %5i) chunks of " + sequences[nb_seqs].name + " (" + sequences[nb_seqs].prefix + ")\n", + nb_seqs, n, sum); nb_seqs++; } } -long check_iso(FILE * 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; } return 0; } -void read_files(FILE * f_iso) +void read_files(Handle * f_iso) { t_index_tab index_tab[10000]; unsigned long i; @@ -228,7 +211,7 @@ void read_files(FILE * f_iso) } } printm(M_STATUS, "Index file generation complete.\n\n"); - index_tab[indexer].address = filesize(f_iso) / 2352; + index_tab[indexer].address = f_iso->GetSize() / 2352; for (i = 0; i < nb_records; i++) { if (sequences[seq].sum == i) @@ -250,39 +233,24 @@ void read_files(FILE * f_iso) fprintf(stderr, "\n"); } -void file_dump(FILE * f_iso, unsigned long debut, unsigned long taille, long num, int seq) +void file_dump(Handle * f_iso, unsigned long debut, unsigned long taille, long num, int seq) { long i; long nbsects; - char nom[1000] = ""; - char *extention = ".out"; - char nom_t[1000] = ""; - int f_out; + String nom; + Handle * f_out; char type = sequences[seq].type; char ptitbidule[] = "-\\|/"; - sprintf(nom_t, "%ld", num); - - strcat(nom, "./"); + nom = "./" + prefix + "/"; + MKDIR(nom.to_charp()); - strcat(nom, prefix); - strcat(nom, "/"); - MKDIR(nom); - - strcat(nom, sequences[seq].prefix); - strcat(nom, "/"); - MKDIR(nom); - - if (num < 10) - strcat(nom, "0"); - if (num < 100) - strcat(nom, "0"); - if (num < 1000) - strcat(nom, "0"); - strcat(nom, nom_t); + nom += sequences[seq].prefix + "/"; + MKDIR(nom.to_charp()); + + nom += String("%04ld.out", num); - strcat(nom, extention); - f_out = open(nom, O_WRONLY | O_CREAT | O_TRUNC, 00644); + f_out = new Output(nom); nbsects = taille / sec_sizes[type]; if (taille % sec_sizes[type]) nbsects++; @@ -292,11 +260,11 @@ void file_dump(FILE * f_iso, unsigned long debut, unsigned long taille, long num fprintf(stderr, " (%c)\010\010\010\010\010", ptitbidule[((tourne++) >> 8) % 4]); read_sector(f_iso, user_data, type); if (i != (nbsects - 1)) { - write(f_out, user_data, sec_sizes[type]); + f_out->write(user_data, sec_sizes[type]); } else { - write(f_out, user_data, taille % sec_sizes[type] ? taille % sec_sizes[type] : sec_sizes[type]); + f_out->write(user_data, taille % sec_sizes[type] ? taille % sec_sizes[type] : sec_sizes[type]); } } - close(f_out); - fprintf(stderr, " (*) Dumped file number %4ld - type \"%s\" \r", num, sequences[seq].name); + delete f_out; + printm(M_BARE, " (*) Dumped file number %4ld - type \"" + sequences[seq].name + "\" \r", num); } diff --git a/cd-tool.cpp b/cd-tool.cpp index 8a6b9c7..35e550f 100644 --- a/cd-tool.cpp +++ b/cd-tool.cpp @@ -98,7 +98,7 @@ int Main(int argc, char ** argv) { exit(-1); } - iso_r = new cdreader(iso_name); + iso_r = new Input(iso_name); get_iso_infos(iso_r); diff --git a/generic/String.cpp b/generic/String.cpp index 22d77d6..24961c5 100644 --- a/generic/String.cpp +++ b/generic/String.cpp @@ -27,17 +27,20 @@ String::String(char c) : siz(1) { str = t; } +#if 0 String::String(const char * s) : str(Base::strdup(s)), siz(::strlen(str)) { #ifdef DEBUG fprintf(stderr, "Creating a string with `%s' at %p\n", str, str); #endif } +#endif -#if 0 String::String(const char * s, ...) { va_list ap; +#ifdef DEBUG fprintf(stderr, "Creating a String with s = '%s'\n", s); +#endif /* This causes a warning: cannot pass objects of type `const String' through `...' but it is not really a problem. */ @@ -47,7 +50,6 @@ String::String(const char * s, ...) { va_end(ap); siz = ::strlen(str); } -#endif String::String(int hs, const char * s) : str(s ? Base::strdup(s) : Base::strdup("")), siz(hs) { } diff --git a/includes/String.h b/includes/String.h index af97d2b..ea501b2 100644 --- a/includes/String.h +++ b/includes/String.h @@ -9,10 +9,10 @@ class String : public Base { public: String(const String &); - String(const char * = ""); #if 0 - String(const char * = "", ...); + String(const char * = ""); #endif + String(const char * = "", ...); String(char); String(int); String(unsigned int); -- cgit v1.2.3