diff options
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/Makefile | 4 | ||||
-rw-r--r-- | lib/cdutils.cpp | 15 | ||||
-rw-r--r-- | lib/dteutils.cpp | 79 |
3 files changed, 43 insertions, 55 deletions
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]++; } } |