X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tools%2Fcvt_data.c;h=7138da040c756acfcc9014d429de03d68353748b;hb=efea2951f8ca2f939ea9297ea4a035e7e99ef714;hp=e21ff96e0b724cfc9b45ab01cd3ba0a0a3e6bb98;hpb=c0050df6e9d6eb81afacb0fa2d1910293dd2165e;p=ia32rtools.git diff --git a/tools/cvt_data.c b/tools/cvt_data.c index e21ff96..7138da0 100644 --- a/tools/cvt_data.c +++ b/tools/cvt_data.c @@ -205,28 +205,6 @@ static char *escape_string(char *s) return strcpy(s, buf); } -static void sprint_pp(const struct parsed_proto *pp, char *buf, - size_t buf_size) -{ - size_t l; - int i; - - snprintf(buf, buf_size, "%s %s(", pp->ret_type.name, pp->name); - l = strlen(buf); - - for (i = 0; i < pp->argc_reg; i++) { - snprintf(buf + l, buf_size - l, "%s%s", - i == 0 ? "" : ", ", pp->arg[i].reg); - l = strlen(buf); - } - if (pp->argc_stack > 0) { - snprintf(buf + l, buf_size - l, "%s{%d stack}", - i == 0 ? "" : ", ", pp->argc_stack); - l = strlen(buf); - } - snprintf(buf + l, buf_size - l, ")"); -} - static void sprint_pp_short(const struct parsed_proto *pp, char *buf, size_t buf_size) { @@ -272,7 +250,7 @@ static const struct parsed_proto *check_var(FILE *fhdr, if (!pp->is_func && !pp->is_fptr) return NULL; - sprint_pp(pp, fp_var, sizeof(fp_var)); + pp_print(fp_var, sizeof(fp_var), pp); if (pp->argc_reg == 0) goto check_sym; @@ -324,7 +302,7 @@ check_sym: } if (bad) { - sprint_pp(pp_sym, fp_sym, sizeof(fp_sym)); + pp_print(fp_sym, sizeof(fp_sym), pp_sym); anote("var: %s\n", fp_var); anote("sym: %s\n", fp_sym); awarn("^ mismatch\n"); @@ -333,6 +311,16 @@ check_sym: return pp; } +static void output_decorated_pp(FILE *fout, + const struct parsed_proto *pp) +{ + if (pp->name[0] != '_') + fprintf(fout, pp->is_fastcall ? "@" : "_"); + fprintf(fout, "%s", pp->name); + if (pp->is_stdcall && pp->argc > 0) + fprintf(fout, "@%d", pp->argc * 4); +} + static int cmpstringp(const void *p1, const void *p2) { return strcmp(*(char * const *)p1, *(char * const *)p2); @@ -342,6 +330,7 @@ int main(int argc, char *argv[]) { FILE *fout, *fasm, *fhdr, *frlist; const struct parsed_proto *pp; + int no_decorations = 0; char words[20][256]; char word[256]; char line[256]; @@ -367,11 +356,19 @@ int main(int argc, char *argv[]) char *p2; if (argc < 4) { - printf("usage:\n%s <.s> <.asm> [rlist]*\n", + // -nd: no symbol decorations + printf("usage:\n%s [-nd] <.s> <.asm> [rlist]*\n", argv[0]); return 1; } + for (arg = 1; arg < argc; arg++) { + if (IS(argv[arg], "-nd")) + no_decorations = 1; + else + break; + } + arg_out = arg++; asmfn = argv[arg++]; @@ -504,7 +501,7 @@ int main(int argc, char *argv[]) g_func_sym_pp = NULL; len = strlen(sym); - fprintf(fout, "_%s:", sym); + fprintf(fout, "%s%s:", no_decorations ? "" : "_", sym); len += 2; if (len < 8) @@ -520,7 +517,10 @@ int main(int argc, char *argv[]) fprintf(fout, "\t\t "); } - if (type == DXT_BYTE && words[w][0] == '\'') { + if (type == DXT_BYTE + && (words[w][0] == '\'' + || (w + 1 < wordc && words[w + 1][0] == '\''))) + { // string; use asciz for most common case if (w == wordc - 2 && IS(words[w + 1], "0")) { fprintf(fout, ".asciz \""); @@ -629,11 +629,16 @@ int main(int argc, char *argv[]) } else { pp = check_var(fhdr, sym, p); - if (p[0] != '_') - fprintf(fout, (pp && pp->is_fastcall) ? "@" : "_"); - fprintf(fout, "%s", p); - if (pp && pp->is_stdcall && pp->argc > 0) - fprintf(fout, "@%d", pp->argc * 4); + if (pp == NULL) { + fprintf(fout, "%s%s", + (no_decorations || p[0] == '_') ? "" : "_", p); + } + else { + if (no_decorations) + fprintf(fout, "%s", pp->name); + else + output_decorated_pp(fout, pp); + } } } else { @@ -660,7 +665,8 @@ fin: // dump public syms for (i = 0; i < pub_sym_cnt; i++) - fprintf(fout, ".global _%s\n", pub_syms[i]); + fprintf(fout, ".global %s%s\n", + no_decorations ? "" : "_", pub_syms[i]); fclose(fout); fclose(fasm);