X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tools%2Fmkdef_ord.c;h=3873c3a4f3f5be007a81c4385491f7e459223888;hb=3084511901606db82741bffafc8582ab9b7591cc;hp=4f6b50bb457f782a42f42511d669388bdacecce8;hpb=1f906263984019d6804c760d7ca6f8c162c5b78d;p=ia32rtools.git diff --git a/tools/mkdef_ord.c b/tools/mkdef_ord.c index 4f6b50b..3873c3a 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" @@ -19,13 +24,22 @@ int main(int argc, char *argv[]) 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 + break; + } + + if (argc != arg + 2) { + printf("usage:\n%s [-n] <.h> <.def>\n", argv[0]); return 1; } @@ -38,9 +52,12 @@ int main(int argc, char *argv[]) p = strrchr(hdrfn, '.'); my_assert_not(p, NULL); - l = p - hdrfn; - my_assert(l < 256, 1); - memcpy(basename, hdrfn, l); + 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 +71,7 @@ int main(int argc, char *argv[]) if (*p == 0) continue; - if (IS(p, "//")) + if (IS_START(p, "//")) continue; ret = 0; @@ -79,7 +96,10 @@ int main(int argc, char *argv[]) fprintf(fout, "@%-2d", pp->argc_stack * 4); else fprintf(fout, " "); - fprintf(fout, " @%d\n", ord); + fprintf(fout, " @%d", ord); + if (noname) + fprintf(fout, " NONAME"); + fprintf(fout, "\n"); } fclose(fhdr);