summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <Pixel>2002-08-25 14:39:48 +0000
committerPixel <Pixel>2002-08-25 14:39:48 +0000
commit38d60726082b04e79edae1c8c797c6dcb8314504 (patch)
tree4a056a158c6fc21c29dd8d8ed94c010a25cee19a
parent1b0a5db816b7610c83615e93095155b1709f55da (diff)
Workiiiiiiiiiiiiiiiiiing!!!!
-rwxr-xr-xMakefile32
-rwxr-xr-xXenogears/Makefile8
-rw-r--r--Xenogears/main_dump.cpp12
-rw-r--r--bgrep.cpp10
-rw-r--r--cd-tool.cpp104
-rw-r--r--crypto-search.cpp17
-rw-r--r--dtemain.cpp20
-rw-r--r--generic/Exceptions.cpp49
-rw-r--r--generic/Input.cpp19
-rwxr-xr-xgeneric/Makefile2
-rw-r--r--generic/Output.cpp6
-rw-r--r--generic/String.cpp18
-rw-r--r--includes/String.h3
-rw-r--r--includes/cdutils.h5
-rw-r--r--includes/dte.h6
-rw-r--r--includes/generic.h5
-rwxr-xr-xlib/Makefile4
-rw-r--r--lib/cdutils.cpp15
-rw-r--r--lib/dteutils.cpp79
-rw-r--r--lzss-main.cpp36
-rw-r--r--str-player.cpp16
21 files changed, 254 insertions, 212 deletions
diff --git a/Makefile b/Makefile
index 04aaecb..46dad1d 100755
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,10 @@
#!/usr/bin/make -f
-CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -Werror -Iincludes `sdl-config --cflags`
-LDFLAGS=`sdl-config --libs`
+CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -Werror -Iincludes `sdl-config --cflags` -DHAVE_ZLIB
+LDFLAGS=`sdl-config --libs` -lz -lefence
CXX=g++
-SUBDIRS = psxdev generic lib Xenogears VP MegamanX5
+SUBDIRS = psxdev generic lib Xenogears
TARGET = lzss dlzss cd-tool str-player crypto-search bgrep dte-tool
all: subdirs ${TARGET}
@@ -12,29 +12,29 @@ all: subdirs ${TARGET}
subdirs:
for d in ${SUBDIRS} ; do make -C $$d || exit -1 ; done
-lzss: includes/lzss.h includes/generic.h includes/fileutils.h lzss-main.o generic/generic.a lib/lib.a Makefile
- ${CXX} ${LDFLAGS} -DLZSS_MAIN lzss-main.o lib/lib.a generic/generic.a -o lzss
+lzss: includes/lzss.h includes/generic.h lzss-main.o generic/generic.a lib/lib.a Makefile
+ ${CXX} -DLZSS_MAIN lzss-main.o lib/lib.a generic/generic.a -o lzss ${LDFLAGS}
dlzss: lzss Makefile
ln -fs lzss dlzss
yazedc: yazedc-main.o lib/lib.a Makefile
- ${CXX} ${LDFLAGS} yazedc-main.o lib/lib.a -DMAIN -o yazedc
+ ${CXX} yazedc-main.o lib/lib.a -DMAIN -o yazedc ${LDFLAGS}
-cd-tool: includes/cdutils.h includes/fileutils.h includes/generic.h includes/yazedc.h cd-tool.o Makefile
- ${CXX} ${LDFLAGAS} cd-tool.o lib/lib.a generic/generic.a -o cd-tool
+cd-tool: includes/cdutils.h includes/generic.h includes/yazedc.h cd-tool.o Makefile
+ ${CXX} cd-tool.o lib/lib.a generic/generic.a -o cd-tool ${LDFLAGS}
-dte-tool: includes/generic.h includes/fileutils.h includes/dte.h dtemain.o lib/lib.a generic/generic.a Makefile
- ${CXX} ${LDFLAGS} dtemain.o lib/lib.a generic/generic.a -o dte-tool
+dte-tool: includes/generic.h includes/dte.h dtemain.o lib/lib.a generic/generic.a Makefile
+ ${CXX} dtemain.o lib/lib.a generic/generic.a -o dte-tool ${LDFLAGS}
-str-player: str-player.o includes/generic.h includes/fileutils.h includes/cdutils.h includes/yazedc.h lib/lib.a generic/generic.a psxdev/psxdev.a Makefile
- ${CXX} ${LDFLAGS} str-player.o psxdev/psxdev.a lib/lib.a generic/generic.a -o str-player
+str-player: str-player.o includes/generic.h includes/cdutils.h includes/yazedc.h lib/lib.a generic/generic.a psxdev/psxdev.a Makefile
+ ${CXX} str-player.o psxdev/psxdev.a lib/lib.a generic/generic.a -o str-player ${LDFLAGS}
-crypto-search: crypto-search.o includes/generic.h includes/fileutils.h lib/lib.a generic/generic.a Makefile
- ${CXX} ${LDFLAGS} crypto-search.o lib/lib.a generic/generic.a -o crypto-search
+crypto-search: crypto-search.o includes/generic.h lib/lib.a generic/generic.a Makefile
+ ${CXX} crypto-search.o lib/lib.a generic/generic.a -o crypto-search ${LDFLAGS}
-bgrep: bgrep.o includes/generic.h includes/fileutils.h generic/generic.a Makefile
- ${CXX} ${LDFLAGS} bgrep.o generic/generic.a -o bgrep
+bgrep: bgrep.o includes/generic.h generic/generic.a Makefile
+ ${CXX} bgrep.o generic/generic.a -o bgrep ${LDFLAGS}
clean:
for d in ${SUBDIRS} ; do make -C $$d clean || exit -1 ; done
diff --git a/Xenogears/Makefile b/Xenogears/Makefile
index 50cc0f4..0f4a0bc 100755
--- a/Xenogears/Makefile
+++ b/Xenogears/Makefile
@@ -1,18 +1,18 @@
#!/usr/bin/make -f
-CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -I../includes
+CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -I../includes -DHAVE_ZLIB
CXX=g++
CC=gcc
-LIBS=-lz
-LDFLAGS=${LIBS}
+LIBS=-lz -lefence
+LDFLAGS=${LIBS} `pkg-config --libs glib-2.0`
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/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
+ ${CXX} main_dump.o ../lib/lib.a ../generic/generic.a -o main_dump ${LDFLAGS}
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
diff --git a/Xenogears/main_dump.cpp b/Xenogears/main_dump.cpp
index 60c15df..e380f7a 100644
--- a/Xenogears/main_dump.cpp
+++ b/Xenogears/main_dump.cpp
@@ -53,7 +53,7 @@ struct t_sequence {
String title, iso_filename, prefix;
unsigned long iso_size;
unsigned int nb_records, nb_seqs = 0;
-struct t_sequence sequences[1000];
+struct t_sequence sequences[100];
long check_iso(Handle * f_iso);
void read_files(Handle * f_iso);
@@ -62,7 +62,7 @@ int process_def_file(Handle * f_def);
Byte user_data[2352];
-int main(int argc, char **argv)
+int Main(int argc, char **argv)
{
Handle * f_def, * f_iso;
@@ -266,3 +266,11 @@ void file_dump(Handle * f_iso, unsigned long debut, unsigned long taille, long n
delete f_out;
printm(M_BARE, " (*) Dumped file number %4ld - type \"" + sequences[seq].name + "\" \r", num);
}
+
+int main(int argc, char ** argv) {
+ try {
+ Main(argc, argv);
+ } catch (GeneralException e) {
+ fprintf(stderr, "Main got an unexpected exception: %s\n", e.GetMsg());
+ }
+}
diff --git a/bgrep.cpp b/bgrep.cpp
index 30be341..8759907 100644
--- a/bgrep.cpp
+++ b/bgrep.cpp
@@ -1,22 +1,22 @@
#include <stdio.h>
#include <stdlib.h>
-#include "fileutils.h"
+#include "Input.h"
#define THRESHOLD 20480
int main(int argc, char ** argv) {
unsigned int p = strtol(argv[1], 0, 0);
char * fn = argv[2];
- FILE * f = fopen(fn, "r+");
+ Handle * f = new Input(fn);
if (!f) {
printf("Bleeh.\n");
exit(-1);
}
- int l = filesize(f), i;
+ int l = f->GetSize(), i;
char * b = (char *) malloc(l);
- fread(b, 1, l, f);
+ f->read(b, l);
for (i = 0; i < l - 3; i++) {
unsigned int r = *((unsigned int *) &(b[i]));
@@ -25,5 +25,5 @@ int main(int argc, char ** argv) {
}
}
- fclose(f);
+ delete f;
}
diff --git a/cd-tool.cpp b/cd-tool.cpp
index 4b601ba..9f10eaa 100644
--- a/cd-tool.cpp
+++ b/cd-tool.cpp
@@ -25,9 +25,10 @@
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
+#include "Input.h"
+#include "Output.h"
#include "cdutils.h"
#include "generic.h"
-#include "fileutils.h"
int lga = 0;
struct option long_options[] = {
@@ -58,7 +59,7 @@ void showhelp(void) {
int main(int argc, char ** argv) {
int type = GUESS, c, size, force = 0, sector;
- int iso_r, iso_w;
+ Handle * iso_r, * iso_w = 0;
char * ppf = 0, * iso_name = 0, * arg1 = 0, * arg2 = 0, * f;
verbosity = M_WARNING;
@@ -90,17 +91,14 @@ int main(int argc, char ** argv) {
iso_name = argv[optind++];
- if ((iso_r = open(iso_name, O_RDONLY)) < 0) {
- printm(M_ERROR, "Failed to open %s for reading.\n", iso_name);
- exit(-1);
- }
-
if (argc == optind) {
showhelp();
printm(M_ERROR, "Need a command to execute.\n");
exit(-1);
}
+ iso_r = new Input(iso_name);
+
get_iso_infos(iso_r);
if (!strcmp(argv[optind], "infos")) {
@@ -113,6 +111,7 @@ int main(int argc, char ** argv) {
if ((argc - 1) != optind) {
showhelp();
printm(M_ERROR, "printdir needs one argument.\n");
+ delete iso_r;
exit(-1);
}
arg1 = argv[optind];
@@ -120,85 +119,87 @@ int main(int argc, char ** argv) {
free(f);
if (!dir.R) {
printm(M_ERROR, "Path %s was not found on iso.\n", arg1);
+ delete iso_r;
exit(-1);
}
if (!(dir.Flags & 2)) {
printm(M_ERROR, "Path %s design a file and not a directory.\n", arg1);
+ delete iso_r;
exit(-1);
}
show_head_entry();
show_dir(iso_r, &dir);
} else if (!strcmp(argv[optind], "extract-file")) {
struct DirEntry dir;
- int file;
+ Handle * file;
optind++;
if ((argc - 2) != optind) {
showhelp();
printm(M_ERROR, "extract-file needs two arguments.\n");
+ delete iso_r;
exit(-1);
}
arg1 = argv[optind++];
arg2 = argv[optind++];
- if ((file = open(arg1, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
- printm(M_ERROR, "Failed to open file %s for writing.\n", arg1);
- exit(-1);
- }
+ file = new Output(arg1);
dir = find_path(iso_r, f = strdup(arg2));
free(f);
if (!dir.R) {
printm(M_ERROR, "Path %s was not found on iso.\n", arg2);
+ delete iso_r;
+ delete file;
exit(-1);
}
printm(M_STATUS, "Reading path %s to file %s.\n", arg2, arg1);
read_file(iso_r, file, type, dir.Sector, dir.Size);
+ delete file;
} else if (!strcmp(argv[optind], "extract")) {
- int file;
+ Handle * file;
optind++;
if ((argc - 3) != optind) {
showhelp();
printm(M_ERROR, "extract needs three arguments.\n");
+ delete iso_r;
exit(-1);
}
arg1 = argv[optind++];
size = atoi(argv[optind++]);
sector = atoi(argv[optind++]);
- if ((file = open(arg1, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
- printm(M_ERROR, "Failed to open file %s for writing.\n", arg1);
- exit(-1);
- }
+ file = new Output(arg1);
printm(M_STATUS, "Reading %i bytes from sector %i to file %s.\n", size, sector, arg1);
read_file(iso_r, file, type, sector, size);
+ delete file;
} else if (!strcmp(argv[optind], "insert-file")) {
struct DirEntry dir, * d;
unsigned char * buffer;
- int file;
+ Handle * file;
int old_type;
- if ((iso_w = open(iso_name, O_WRONLY)) < 0) {
- printm(M_ERROR, "Failed to open %s for writing.\n", iso_name);
- exit(-1);
- }
- lseek(iso_w, 0, SEEK_SET);
if (ppf) {
if (open_ppf(ppf, iso_r, "Created by CD-Tool") < 0) {
printm(M_ERROR, "Failed to open file %s for writing.\n", ppf);
}
+ } else {
+ iso_w = new Output(iso_name, 0, 0);
}
optind++;
if ((argc - 2) != optind) {
showhelp();
printm(M_ERROR, "insert-file needs two arguments.\n");
+ delete iso_r;
+ if (ppf) {
+ close_ppf();
+ } else {
+ delete iso_w;
+ }
exit(-1);
}
arg1 = argv[optind++];
arg2 = argv[optind++];
- if ((file = open(arg1, O_RDONLY)) < 0) {
- printm(M_ERROR, "Failed to open file %s for reading.\n", arg1);
- exit(-1);
- }
+ file = new Input(arg1);
dir = find_path(iso_r, f = strdup(arg2));
free(f);
if (!dir.R) {
@@ -212,11 +213,18 @@ int main(int argc, char ** argv) {
type = old_type;
}
if (((dir.Size / sec_sizes[old_type]) + ((dir.Size % sec_sizes[old_type]) ? 1 : 0)) <
- ((filesize(file) / sec_sizes[type]) + ((filesize(file) % sec_sizes[type]) ? 1 : 0))) {
+ (((size_t) file->GetSize() / sec_sizes[type]) + (((size_t) file->GetSize() % sec_sizes[type]) ? 1 : 0))) {
if (force) {
- printm(M_WARNING, "New file too big: %i vs %i in %s.\n", dir.Size, filesize(file), sec_modes[type]);
+ printm(M_WARNING, "New file too big: %i vs %i in " + sec_modes[type] + ".\n", dir.Size, file->GetSize());
} else {
- printm(M_ERROR, "New file too big: %i vs %i in %s.\n", dir.Size, filesize(file), sec_modes[type]);
+ printm(M_ERROR, "New file too big: %i vs %i in " + sec_modes[type] + ".\n", dir.Size, file->GetSize());
+ delete iso_r;
+ if (ppf) {
+ close_ppf();
+ } else {
+ delete iso_w;
+ }
+ delete file;
exit(-1);
}
}
@@ -231,43 +239,57 @@ int main(int argc, char ** argv) {
f = arg2;
}
d = find_dir_entry(iso_r, &buffer, &dir, f);
- d->Size = filesize(file);
+ d->Size = file->GetSize();
write_datas(iso_r, iso_w, buffer, GUESS, dir.Sector, dir.Size);
free(buffer);
- } else if (!strcmp(argv[optind], "insert")) {
- int file;
- if ((iso_w = open(iso_name, O_WRONLY)) < 0) {
- printm(M_ERROR, "Failed to open %s for writing.\n", iso_name);
- exit(-1);
+ delete file;
+ if (ppf) {
+ close_ppf();
+ } else {
+ delete iso_w;
}
- lseek(iso_w, 0, SEEK_SET);
+ } else if (!strcmp(argv[optind], "insert")) {
+ Handle * file;
if (ppf) {
if (open_ppf(ppf, iso_r, "Created by CD-Tool") < 0) {
printm(M_ERROR, "Failed to open file %s for writing.\n", ppf);
}
+ } else {
+ iso_w = new Output(iso_name, 0, 0);
}
optind++;
if ((argc - 2) != optind) {
showhelp();
printm(M_ERROR, "insert needs two arguments.\n");
+ if (ppf) {
+ close_ppf();
+ } else {
+ delete iso_w;
+ }
+ delete iso_r;
exit(-1);
}
arg1 = argv[optind++];
sector = atoi(argv[optind++]);
- if ((file = open(arg1, O_RDONLY)) < 0) {
- printm(M_ERROR, "Failed to open file %s for reading.\n", arg1);
- exit(-1);
- }
+ file = new Input(arg1);
printm(M_STATUS, "Writing file %s at sector %i.\n", arg1, sector);
write_file(iso_r, iso_w, file, type, sector);
+ if (ppf) {
+ close_ppf();
+ } else {
+ delete iso_w;
+ }
+ delete file;
} else {
showhelp();
printm(M_ERROR, "Command %s unknow.\n", argv[optind]);
+ delete iso_r;
exit(-1);
}
+ delete iso_r;
exit(0);
}
diff --git a/crypto-search.cpp b/crypto-search.cpp
index 8775095..4ece311 100644
--- a/crypto-search.cpp
+++ b/crypto-search.cpp
@@ -23,11 +23,12 @@
#include <string.h>
#include <unistd.h>
#include "generic.h"
-#include "fileutils.h"
+#include "Input.h"
int main(int argc, char ** argv) {
- int h, size, mind, maxd, delta, len, i, j;
+ int size, mind, maxd, delta, len, i, j;
char * buffer, * str;
+ Handle * h;
if (argc != 3) {
printm(M_BARE, "Usage: %s <inputfile> <needle>\n", argv[0]);
@@ -36,23 +37,21 @@ int main(int argc, char ** argv) {
verbosity = M_INFO;
- if ((h = open(argv[1], O_RDONLY)) < 0) {
- printm(M_ERROR, "Unable to open file %s\n", argv[1]);
- exit(-1);
- }
+ h = new Input(argv[1]);
str = argv[2];
- size = filesize(h);
+ size = h->GetSize();
printm(M_STATUS, "Requesting memory (%i bytes)\n", size);
if (!(buffer = (char *) malloc(size))) {
printm(M_ERROR, "Not enough memory.\n");
+ delete h;
exit(-1);
}
printm(M_STATUS, "Loading file...\n");
- read(h, buffer, size);
+ h->read(buffer, size);
printm(M_STATUS, "Done, initialising the search.\n");
len = strlen(argv[2]);
@@ -88,4 +87,6 @@ int main(int argc, char ** argv) {
}
}
}
+
+ delete h;
}
diff --git a/dtemain.cpp b/dtemain.cpp
index c044c79..ec60509 100644
--- a/dtemain.cpp
+++ b/dtemain.cpp
@@ -21,28 +21,28 @@
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
-#include "fileutils.h"
+#include "Input.h"
#include "generic.h"
#include "dte.h"
int main(int argc, char ** argv) {
- FILE * f, * t;
+ Handle * f, * t;
long old_size;
int i;
verbosity = M_INFO;
printm(M_STATUS, "Reading thingy table\n");
- t = fopen(argv[2], "r");
+ t = new Input(argv[2]);
read_thingy(t);
- fclose(t);
+ delete t;
- f = fopen(argv[1], "r");
- dte_text_size = filesize(f);
+ f = new Input(argv[1]);
+ dte_text_size = f->GetSize();
dte_text = (char *) calloc(dte_text_size + 4, 1);
printm(M_STATUS, "Reading file, size = %li\n", dte_text_size);
read_thingy_file(f);
- fclose(f);
+ delete f;
printm(M_STATUS, "True size = %li\n", old_size = dte_text_size);
@@ -50,11 +50,11 @@ int main(int argc, char ** argv) {
dte_compress();
printm(M_STATUS, "Rereading file.\n");
- f = fopen(argv[1], "r");
- dte_text_size = filesize(f);
+ f = new Input(argv[1]);
+ dte_text_size = f->GetSize();
dte_text = (char *) calloc(dte_text_size + 4, 1);
read_thingy_file(f);
- fclose(f);
+ delete f;
printm(M_STATUS, "True size = %li, real gain = %li\n", dte_text_size, old_size - dte_text_size);
diff --git a/generic/Exceptions.cpp b/generic/Exceptions.cpp
index f24c0fb..b7c00a6 100644
--- a/generic/Exceptions.cpp
+++ b/generic/Exceptions.cpp
@@ -3,6 +3,10 @@
#include <string.h>
#include <errno.h>
#include <stddef.h>
+#include <glib.h>
+#ifdef DEBUG
+#include <iostream>
+#endif
#include "String.h"
#include "Exceptions.h"
#include "generic.h"
@@ -82,36 +86,26 @@ void * xmalloc(size_t s) throw (GeneralException) {
return 0;
}
- if (!(r = (char *) ::malloc(s + 2 * sizeof(size_t)))) {
- throw MemoryException(s + 2 * sizeof(size_t));
+ if (!(r = (char *) ::malloc(s))) {
+ throw MemoryException(s);
}
+#ifdef DEBUG
+ fprintf(stderr, "Allocating %i bytes of memory, got it at %p\n", s, r);
+#endif
- memset(r, 0, s + 2 * sizeof(size_t));
+ memset(r, 0, s);
- *((size_t *)r) = s;
- *(((size_t *)r) + 1) = 0xdeedbeef;
-
- return (void *)(r + 2 * sizeof(size_t));
+ return (void *)(r);
}
void * xrealloc(void * ptr, size_t s) {
- char * r;
- size_t os;
-
- if (!ptr) {
- return xmalloc(s);
- }
-
- os = *(((size_t *) ptr) - 1);
-
- r = (char *) xmalloc(s);
-
- if (s) {
- memcpy(r, ptr, MIN(s, os));
- }
-
- xfree(ptr);
+#ifdef DEBUG
+ void * r = realloc(ptr, s);
+ fprintf(stderr, "Reallocating pointer at %p for %i bytes, now at %p\n", ptr, s, r);
return r;
+#else
+ return realloc(ptr, s);
+#endif
}
#ifdef OVER_FREE
@@ -123,12 +117,11 @@ void xfree(void *& p) {
}
void xfree(char *& p) {
+#ifdef DEBUG
+ fprintf(stderr, "Freeing pointer at %p\n", p);
+#endif
if (p) {
- if (*(((size_t *)p) - 1) != 0xdeedbeef) {
- fprintf(stderr, "Error: trying to xfree() a non xmalloc()ed bloc.\n");
- exit(-1);
- }
- ::free(p - 2 * sizeof(size_t));
+ ::free(p);
p = 0;
}
}
diff --git a/generic/Input.cpp b/generic/Input.cpp
index b7ee99c..d415279 100644
--- a/generic/Input.cpp
+++ b/generic/Input.cpp
@@ -16,18 +16,23 @@
Input::Input(const String & no) throw (GeneralException) :
Handle(no.strlen() ? open(no.to_charp(), O_RDONLY) : dup(0)),
n(no) {
+
+#ifdef DEBUG
+ fprintf(stderr, "Opening file %s, Input at %p\n", no.to_charp(), this);
+#endif
+
if (GetHandle() < 0) {
throw IOGeneral(String(_("Error opening file ")) + no + _(" for reading: ") + strerror(errno));
}
- size = lseek(GetHandle(), 0, SEEK_END);
- lseek(GetHandle(), 0, SEEK_SET);
-
struct stat s;
-
fstat(GetHandle(), &s);
-
date_modif = s.st_mtime;
+
+ if (S_ISREG(s.st_mode)) {
+ size = seek(0, SEEK_END);
+ seek(0, SEEK_SET);
+ }
}
Input::Input(const Input & i) : Handle(i), n(i.n), size(i.size), date_modif(i.date_modif) {
@@ -63,11 +68,11 @@ time_t Input::GetModif() {
off_t Input::seek(off_t offset, int whence) throw (GeneralException) {
if ((itell = lseek(GetHandle(), offset, whence)) < 0) {
- throw IOGeneral(String(_("Error seeking file ")) + n + _(": ") + strerror(errno));
+ throw IOGeneral(String(_("Error seeking file ")) + GetName() + _(": ") + strerror(errno));
}
#ifdef PARANOID_SEEK
if (itell != lseek(GetHandle(), 0, SEEK_CUR)) {
- throw IOGeneral(String(_("Error seeking file ")) + n + _(": the position does not match"));
+ throw IOGeneral(String(_("Error seeking file ")) + GetName() + _(": the position does not match"));
}
#endif
return itell;
diff --git a/generic/Makefile b/generic/Makefile
index 4ca5e32..7107501 100755
--- a/generic/Makefile
+++ b/generic/Makefile
@@ -1,6 +1,6 @@
#!/usr/bin/make -f
-CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -I../includes -DPARANOID_SEEK -DHAVE_ZLIB
+CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -I../includes -DPARANOID_SEEK -DHAVE_ZLIB `pkg-config --cflags glib-2.0`
CXX=g++
CC=gcc
diff --git a/generic/Output.cpp b/generic/Output.cpp
index e136524..1d7981e 100644
--- a/generic/Output.cpp
+++ b/generic/Output.cpp
@@ -14,7 +14,11 @@
#endif
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)),
+ Handle(no.strlen() ? open(no.to_charp(), O_WRONLY | (O_CREAT * (create ? 1 : 0)) | (trunc ? O_TRUNC : O_APPEND)
+#ifdef __linux__
+, 00666
+#endif
+) : 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 c389c13..22d77d6 100644
--- a/generic/String.cpp
+++ b/generic/String.cpp
@@ -14,7 +14,11 @@ extern "C" {
char String::t[BUFSIZ + 1];
-String::String(const String & s) : str(Base::strdup(s.str)), siz(s.siz) { }
+String::String(const String & s) : str(Base::strdup(s.str)), siz(s.siz) {
+#ifdef DEBUG
+ fprintf(stderr, "Duplicating string `%s', from %p to %p\n", str, s.str, str);
+#endif
+}
String::String(char c) : siz(1) {
char * t = (char *) malloc(2);
@@ -23,8 +27,17 @@ String::String(char c) : siz(1) {
str = t;
}
+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
+}
+
+#if 0
String::String(const char * s, ...) {
va_list ap;
+
+ fprintf(stderr, "Creating a String with s = '%s'\n", s);
/* This causes a warning: cannot pass objects of type `const String' through `...'
but it is not really a problem. */
@@ -33,7 +46,8 @@ String::String(const char * s, ...) {
str = Base::strdup(t);
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 7b5fdc4..af97d2b 100644
--- a/includes/String.h
+++ b/includes/String.h
@@ -9,7 +9,10 @@
class String : public Base {
public:
String(const String &);
+ String(const char * = "");
+#if 0
String(const char * = "", ...);
+#endif
String(char);
String(int);
String(unsigned int);
diff --git a/includes/cdutils.h b/includes/cdutils.h
index fa44ca6..e3cf8fb 100644
--- a/includes/cdutils.h
+++ b/includes/cdutils.h
@@ -56,14 +56,15 @@ extern long sec_sizes[];
extern long sec_offsts[];
extern String sec_modes[];
-Handle * open_ppf(String ppf, Handle * iso, char * comment);
+Handle * open_ppf(String ppf, Handle * iso, String comment) throw(GeneralException);
+void close_ppf() throw(GeneralException);
unsigned short int swap_word(unsigned short int i);
unsigned long int swap_dword(unsigned long int i);
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 read_file(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);
diff --git a/includes/dte.h b/includes/dte.h
index 267e9ed..3be7f9c 100644
--- a/includes/dte.h
+++ b/includes/dte.h
@@ -4,10 +4,10 @@
void dte_reset(void);
void build_dte(void);
void push_entry(long entry);
-char * read_line(FILE * f, char * b);
+char * read_line(Handle * f, char * b);
void dte_compress();
-void read_thingy(FILE * f);
-void read_thingy_file(FILE * f);
+void read_thingy(Handle * f);
+void read_thingy_file(Handle * f);
extern char * dte_text;
extern char * things[256];
diff --git a/includes/generic.h b/includes/generic.h
index 9c5b7a4..5586953 100644
--- a/includes/generic.h
+++ b/includes/generic.h
@@ -33,8 +33,13 @@
#define bcopy(x,y,z) memcpy((y),(x),(z))
#endif
+#ifndef MAX
#define MIN(a,b) ((a)<(b)?(a):(b))
+#endif
+
+#ifndef MAX
#define MAX(a,b) ((a)<(b)?(b):(a)
+#endif
#ifndef SDL_VERSIONNUM
typedef unsigned long int Uint32;
diff --git a/lib/Makefile b/lib/Makefile
index e5a1b85..c351a36 100755
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -1,9 +1,9 @@
#!/usr/bin/make -f
-CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -Werror -I../includes
+CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -Werror -I../includes -DHAVE_ZLIB
CXX=g++
-OBJECTS = cdutils.o lzss.o yazedc.o
+OBJECTS = cdutils.o lzss.o yazedc.o dteutils.o
TARGET = lib.a
all: ${TARGET}
diff --git a/lib/cdutils.cpp b/lib/cdutils.cpp
index e4d7749..1049535 100644
--- a/lib/cdutils.cpp
+++ b/lib/cdutils.cpp
@@ -60,10 +60,12 @@ unsigned long from_MSF(unsigned long msf, unsigned long start) {
return from_MSF(m, s, f, start);
}
-Output * open_ppf(String ppf, Handle * iso, String comment) {
+Handle * open_ppf(String ppf, Handle * iso, String comment) throw (GeneralException) {
int i, l;
Byte buffer[1024];
+ if (ppf_file)
+ throw GeneralException("Tried to open_ppf() while already opened.");
ppf_file = new Output(ppf);
ppf_file->write("PPF20\001", 6);
@@ -112,6 +114,15 @@ void write_ppf(Byte * old_sec, Byte * new_sec, int sec_num) {
}
}
+void close_ppf() throw (GeneralException) {
+ if (ppf_file) {
+ delete ppf_file;
+ ppf_file = 0;
+ } else {
+ throw GeneralException("Tried to close_ppf() without previous opening");
+ }
+}
+
String format_date(String input) {
String output;
@@ -162,7 +173,7 @@ int guess_type(Handle * f_iso, int number) {
}
void sector_seek(Handle * f_iso, long sector) {
- f_iso->seek(2336 * sector);
+ f_iso->seek(2352 * sector);
}
long read_sector(Handle * f_iso, Byte * buffer, int type, int number) {
diff --git a/lib/dteutils.cpp b/lib/dteutils.cpp
index 6c8dcc4..0f52667 100644
--- a/lib/dteutils.cpp
+++ b/lib/dteutils.cpp
@@ -208,28 +208,6 @@ void push_entry(long entry) {
}
}
-String read_line(Handle * f, String b) {
- int r, pos = 0;
-
- while (!feof(f)) {
- if ((r = fgetc(f)) == EOF)
- break;
- if (r == 0x0d) {
- if ((r = fgetc(f)) == EOF)
- break;
- }
- if (r == 0x0a) {
- b[pos] = 0;
- return b;
- }
- b[pos++] = r;
- }
-
- b[pos] = 0;
-
- return b;
-}
-
void dte_compress() {
int i, j;
char c1, c2;
@@ -262,26 +240,24 @@ void dte_compress() {
}
void read_thingy(Handle * f) {
- char line[256], * st, * thing;
+ String line, st, thing;
long code;
int i;
- st = line + 2;
- thing = line + 5;
- line[0] = '0';
- line[1] = 'x';
-
dte_size = 0;
for (i = 0; i < 256; i++) {
dte_entries[i] = -1;
}
- while (!feof(f)) {
- if (strlen(read_line(f, st))) {
- line[4] = 0;
- sscanf(line, "%li", &code);
- switch (strlen(thing)) {
+ while (1) {
+ line = "0x";
+ *f >> st;
+ if (st.strlen()) {
+ line += st.extract(0, 1);
+ code = line.to_int();
+ thing = st.extract(3);
+ switch (thing.strlen()) {
case 0:
dte_size++;
dte_entries[code] = 0;
@@ -289,7 +265,7 @@ void read_thingy(Handle * f) {
case 1:
alloweds[code] = 1;
default:
- things[code] = strdup(thing);
+ things[code] = thing;
thingtree::addstring(thing, code);
}
}
@@ -297,40 +273,41 @@ void read_thingy(Handle * f) {
}
void read_thingy_file(Handle * f) {
- char line[10240], * p, * c, trans[5];
+ String line, trans;
long code;
- int ptr = 0, i;
+ int ptr = 0, i, c;
for (i = 0; i < 256; i++) {
dte_usage[i] = 0;
}
- while (!feof(f)) {
- if (!strlen(p = read_line(f, line)))
+ while (1) {
+ *f >> line;
+ if (!line.strlen())
continue;
- while (*p) {
- if (*p == '<') {
- if (!(c = strchr(p, '>'))) {
+ i = 0;
+ while (line[i]) {
+ if (line[i] == '<') {
+ if ((c = line.strchr('>', i)) < 0) {
printm(M_ERROR, "Error in file: '<' not closed.\n");
exit(-1);
}
- p++;
- if ((c - p) == 2) {
- *c = 0;
- sprintf(trans, "0x%s", p);
- sscanf(trans, "%li", &code);
+ i++;
+ if (c == 2) {
+ trans = "0x" + line.extract(i, 2);
+ code = line.to_int();
dte_text[ptr++] = code;
printm(M_BARE, "0x%02x-", code);
} else {
- printm(M_BARE, "Unknow %s-", p);
+ printm(M_BARE, "Unknow " + trans.extract(2) + "-");
}
- p = c + 1;
+ i += c;
} else {
- if ((code = thingtree::look(p)) == -1)
+ if ((code = thingtree::look(line.extract(i))) == -1)
exit(-1);
dte_text[ptr++] = code;
- p += strlen(things[code]);
- printm(M_BARE, "%s-", things[code]);
+ i += things[code].strlen();
+ printm(M_BARE, things[code] + "-");
dte_usage[code]++;
}
}
diff --git a/lzss-main.cpp b/lzss-main.cpp
index 0d08cba..0a4a446 100644
--- a/lzss-main.cpp
+++ b/lzss-main.cpp
@@ -21,15 +21,15 @@
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
-#include <iostream>
-#include "fileutils.h"
+#include "Input.h"
+#include "Output.h"
#include "generic.h"
#include "lzss.h"
char * fn1, * fn2, * pname;
int lga = 0;
-int compress = 1;
+int lzsscompress = 1;
struct option long_options[] = {
{"1iscomp", 1, &lga, 1 },
@@ -96,7 +96,7 @@ void showhelp(void) {
"If you don't know what they are, forget them.\n"
"\n"
"Default behavior is to %scompress.\n"
-"\n", pname, pname, pname, pname, compress ? "" : "de");
+"\n", pname, pname, pname, pname, lzsscompress ? "" : "de");
}
void showscheme(void) {
@@ -146,7 +146,7 @@ void dump(void) {
int main(int argc, char ** argv) {
long length = -1;
- FILE * f1, * f2;
+ Handle * f1, * f2;
int p, show = 0;
int c, s, t;
@@ -156,7 +156,7 @@ int main(int argc, char ** argv) {
verbosity = M_STATUS;
if (!strcasecmp(pname + p, "dlzss")) {
- compress = 0;
+ lzsscompress = 0;
}
printm(M_BARE, /*
@@ -317,10 +317,10 @@ LZSS_MAIN " compressor/decompressor version " LZSS_VERSION ",\n" */
exit(0);
break;
case 'd':
- compress = 0;
+ lzsscompress = 0;
break;
case 'c':
- compress = 1;
+ lzsscompress = 1;
break;
case 'b':
blockb = 1;
@@ -347,21 +347,17 @@ LZSS_MAIN " compressor/decompressor version " LZSS_VERSION ",\n" */
fn1 = argv[optind++];
fn2 = argv[optind++];
- if (!(f1 = fopen(fn1, "r"))) {
- printm(M_ERROR, "Error opening file %s for reading.\n", fn1);
- }
+ f1 = new Input(fn1);
- if (!(f2 = fopen(fn2, "w"))) {
- printm(M_ERROR, "Error opening file %s for writing.\n", fn2);
- }
+ f2 = new Output(fn2);
- if (compress) {
+ if (lzsscompress) {
printm(M_STATUS, "Compressing `%s' to `%s'...\n", fn1, fn2);
} else {
printm(M_STATUS, "Decompressing `%s' to `%s'...\n", fn1, fn2);
}
- if (compress) {
+ if (lzsscompress) {
if (length == -1) {
lzss_comp(f1, f2);
} else {
@@ -371,14 +367,14 @@ LZSS_MAIN " compressor/decompressor version " LZSS_VERSION ",\n" */
length = lzss_decomp(f1, f2, length);
}
- printm(M_STATUS, "Done, filesize changed from %i to %i.\n", filesize(f1), filesize(f2));
+ printm(M_STATUS, "Done, filesize changed from %i to %i.\n", f1->GetSize(), f2->GetSize());
if (!bitmap_count)
bitmap_count = 8;
- if (compress)
+ if (lzsscompress)
printm(M_STATUS, "Compressed %i = 0x%08x blocs, containing %i = 0x%08x chunks.\n", blk + 1, blk + 1, blk * 8 + bitmap_count, blk * 8 + bitmap_count);
- fclose(f1);
- fclose(f2);
+ delete f1;
+ delete f2;
exit(0);
}
diff --git a/str-player.cpp b/str-player.cpp
index 223270c..7d9f47b 100644
--- a/str-player.cpp
+++ b/str-player.cpp
@@ -2,8 +2,8 @@
#include <string.h>
#include <SDL/SDL.h>
#include <SDL/SDL_audio.h>
+#include "Input.h"
#include "psxdev/bs.h"
-#include "fileutils.h"
#include "generic.h"
#include "cdutils.h"
#include "psxdev/xadecode.h"
@@ -64,11 +64,11 @@ void mixaudio(void *unused, Uint8 *stream, int len) {
audio_len -= len;
}
-void process_one_sector(FILE * f) {
+void process_one_sector(Handle * f) {
Byte sector[2336];
STR_Header * h;
- fread(sector, 2336, 1, f);
+ f->read(sector, 2336);
h = (STR_Header *) ((Byte *) sector + 8);
// printm(M_INFO, "SubHeader: FN = %x, CN = %x, SM = %x, CI = %x: ", sector[0], sector[1], sector[2], sector[3]);
/*
@@ -184,6 +184,8 @@ void process_one_sector(FILE * f) {
}
int main(int argc, char ** argv) {
+ Handle * file = 0;
+
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0) {
printm(M_ERROR, "Couldn't initialise SDL: %s\n", SDL_GetError());
exit(-1);
@@ -194,18 +196,18 @@ int main(int argc, char ** argv) {
switch (argc) {
case 1:
+ file = &Stdin;
break;
case 2:
- fclose(stdin);
- stdin = fopen(argv[1], "r");
+ file = new Input(argv[1]);
break;
default:
printm(M_ERROR, "Too much arguments.\n");
exit(-1);
}
- while (!feof(stdin)) {
- process_one_sector(stdin);
+ while (1) {
+ process_one_sector(file);
}
if (!audio)