summaryrefslogtreecommitdiff
path: root/lib/dteutils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dteutils.cpp')
-rw-r--r--lib/dteutils.cpp79
1 files changed, 28 insertions, 51 deletions
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]++;
}
}