X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tools%2Fmkdef_ord.c;h=648e0d4daab0563328b5340a6f388cb1df71e9a3;hb=HEAD;hp=4f6b50bb457f782a42f42511d669388bdacecce8;hpb=1f906263984019d6804c760d7ca6f8c162c5b78d;p=ia32rtools.git diff --git a/tools/mkdef_ord.c b/tools/mkdef_ord.c index 4f6b50b..648e0d4 100644 --- a/tools/mkdef_ord.c +++ b/tools/mkdef_ord.c @@ -1,13 +1,18 @@ +/* + * ia32rtools + * (C) notaz, 2013,2014 + * + * This work is licensed under the terms of 3-clause BSD license. + * See COPYING file in the top-level directory. + */ + #include #include #include #include "my_assert.h" #include "my_str.h" - -#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) -#define IS(w, y) !strcmp(w, y) -#define IS_START(w, y) !strncmp(w, y, strlen(y)) +#include "common.h" #include "protoparse.h" @@ -15,17 +20,28 @@ int main(int argc, char *argv[]) { const struct parsed_proto *pp; FILE *fout, *fhdr; - char basename[256]; + char basename[256] = { 0, }; char line[256]; char fmt[256]; char word[256]; + int noname = 0; + const char *p2; char *p; - int arg = 1; + int arg; int ret, ord; int l; - if (argc != 3) { - printf("usage:\n%s <.h> <.def>\n", argv[0]); + for (arg = 1; arg < argc; arg++) { + if (IS(argv[arg], "-n")) + noname = 1; + else if (IS(argv[arg], "-b") && arg < argc - 1) + snprintf(basename, sizeof(basename), "%s", argv[++arg]); + else + break; + } + + if (argc != arg + 2) { + printf("usage:\n%s [-n] [-b ] <.h> <.def>\n", argv[0]); return 1; } @@ -36,12 +52,17 @@ int main(int argc, char *argv[]) fout = fopen(argv[arg++], "w"); my_assert_not(fout, NULL); - p = strrchr(hdrfn, '.'); - my_assert_not(p, NULL); - l = p - hdrfn; - my_assert(l < 256, 1); - memcpy(basename, hdrfn, l); - basename[l] = 0; + if (basename[0] == 0) { + p = strrchr(hdrfn, '.'); + my_assert_not(p, NULL); + p2 = strrchr(hdrfn, '/'); + if (p2++ == NULL) + p2 = hdrfn; + l = p - p2; + my_assert((unsigned int)l < 256, 1); + memcpy(basename, p2, l); + basename[l] = 0; + } snprintf(fmt, sizeof(fmt), "%s_%%d", basename); @@ -54,7 +75,7 @@ int main(int argc, char *argv[]) if (*p == 0) continue; - if (IS(p, "//")) + if (IS_START(p, "//")) continue; ret = 0; @@ -74,12 +95,17 @@ int main(int argc, char *argv[]) if (pp == NULL) return 1; - fprintf(fout, " %s", word); + fputc(' ', fout); + fputc(pp->is_fastcall ? '@' : ' ', fout); + fprintf(fout, "%s", word); if (pp->is_stdcall) - fprintf(fout, "@%-2d", pp->argc_stack * 4); + fprintf(fout, "@%-2d", pp->argc * 4); else fprintf(fout, " "); - fprintf(fout, " @%d\n", ord); + fprintf(fout, " @%d", ord); + if (noname) + fprintf(fout, " NONAME"); + fprintf(fout, "\n"); } fclose(fhdr);