From: notaz Date: Thu, 19 Mar 2015 21:00:37 +0000 (+0200) Subject: translate: stop data parse on imports X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ea60b8d585086fa64f7a8cd298ec1cd698ad56d;p=ia32rtools.git translate: stop data parse on imports --- diff --git a/tools/common.h b/tools/common.h new file mode 100644 index 0000000..4ca8e12 --- /dev/null +++ b/tools/common.h @@ -0,0 +1,24 @@ +// read a line, truncating it if it doesn't fit +static char *my_fgets(char *s, size_t size, FILE *stream) +{ + char *ret, *ret2; + char buf[64]; + int p; + + p = size - 2; + if (p >= 0) + s[p] = 0; + + ret = fgets(s, size, stream); + if (ret != NULL && p >= 0 && s[p] != 0 && s[p] != '\n') { + p = sizeof(buf) - 2; + do { + buf[p] = 0; + ret2 = fgets(buf, sizeof(buf), stream); + } + while (ret2 != NULL && buf[p] != 0 && buf[p] != '\n'); + } + + return ret; +} + diff --git a/tools/cvt_data.c b/tools/cvt_data.c index 8f999a3..bc9b2da 100644 --- a/tools/cvt_data.c +++ b/tools/cvt_data.c @@ -13,6 +13,7 @@ #include "my_assert.h" #include "my_str.h" +#include "common.h" #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) #define IS(w, y) !strcmp(w, y) @@ -87,7 +88,7 @@ static void next_section(FILE *fasm, char *name) name[0] = 0; - while (fgets(line, sizeof(line), fasm)) + while (my_fgets(line, sizeof(line), fasm)) { wordc = 0; asmln++; @@ -96,14 +97,8 @@ static void next_section(FILE *fasm, char *name) if (*p == 0) continue; - if (*p == ';') { - while (strlen(line) == sizeof(line) - 1) { - // one of those long comment lines.. - if (!fgets(line, sizeof(line), fasm)) - break; - } + if (*p == ';') continue; - } for (wordc = 0; wordc < ARRAY_SIZE(words); wordc++) { p = sskip(next_word(words[wordc], sizeof(words[0]), p)); @@ -462,7 +457,7 @@ int main(int argc, char *argv[]) frlist = fopen(argv[arg], "r"); my_assert_not(frlist, NULL); - while (fgets(line, sizeof(line), frlist)) { + while (my_fgets(line, sizeof(line), frlist)) { p = sskip(line); if (*p == 0 || *p == ';') continue; @@ -514,7 +509,7 @@ int main(int argc, char *argv[]) if (!header_mode) fprintf(fout, ".align %d\n", align_value(4)); - while (fgets(line, sizeof(line), fasm)) + while (my_fgets(line, sizeof(line), fasm)) { sym = NULL; asmln++; diff --git a/tools/translate.c b/tools/translate.c index cc6795a..1fa3d95 100644 --- a/tools/translate.c +++ b/tools/translate.c @@ -13,6 +13,7 @@ #include "my_assert.h" #include "my_str.h" +#include "common.h" #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) #define IS(w, y) !strcmp(w, y) @@ -6350,30 +6351,6 @@ static void output_hdr(FILE *fout) fwrite(line, 1, strlen(line), fout); } -// read a line, truncating it if it doesn't fit -static char *my_fgets(char *s, size_t size, FILE *stream) -{ - char *ret, *ret2; - char buf[64]; - int p; - - p = size - 2; - if (p >= 0) - s[p] = 0; - - ret = fgets(s, size, stream); - if (ret != NULL && p >= 0 && s[p] != 0 && s[p] != '\n') { - p = sizeof(buf) - 2; - do { - buf[p] = 0; - ret2 = fgets(buf, sizeof(buf), stream); - } - while (ret2 != NULL && buf[p] != 0 && buf[p] != '\n'); - } - - return ret; -} - // '=' needs special treatment // also ' quote static char *next_word_s(char *w, size_t wsize, char *s) @@ -6473,6 +6450,11 @@ static void scan_variables(FILE *fasm) if (wordc < 2) continue; + if (IS_START(words[0], "__IMPORT_DESCRIPTOR_")) { + // when this starts, we don't need anything from this section + break; + } + if ((hg_var_cnt & 0xff) == 0) { hg_vars = realloc(hg_vars, sizeof(hg_vars[0]) * (hg_var_cnt + 0x100));