5 * This work is licensed under the terms of 3-clause BSD license.
6 * See COPYING file in the top-level directory.
13 #include "my_assert.h"
16 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
17 #define IS(w, y) !strcmp(w, y)
18 #define IS_START(w, y) !strncmp(w, y, strlen(y))
20 #include "protoparse.h"
22 int main(int argc, char *argv[])
24 const struct parsed_proto *pp;
37 for (arg = 1; arg < argc; arg++) {
38 if (IS(argv[arg], "-n"))
44 if (argc != arg + 2) {
45 printf("usage:\n%s [-n] <.h> <.def>\n", argv[0]);
50 fhdr = fopen(hdrfn, "r");
51 my_assert_not(fhdr, NULL);
53 fout = fopen(argv[arg++], "w");
54 my_assert_not(fout, NULL);
56 p = strrchr(hdrfn, '.');
57 my_assert_not(p, NULL);
58 p2 = strrchr(hdrfn, '/');
62 my_assert((unsigned int)l < 256, 1);
63 memcpy(basename, p2, l);
66 snprintf(fmt, sizeof(fmt), "%s_%%d", basename);
68 fprintf(fout, "LIBRARY %s\n", basename);
69 fprintf(fout, "EXPORTS\n");
71 while (fgets(line, sizeof(line), fhdr))
77 if (IS_START(p, "//"))
81 while (p != NULL && *p != 0) {
82 p = next_word(word, sizeof(word), p);
83 ret = sscanf(word, fmt, &ord);
88 printf("scan for '%s' failed for '%s'\n", fmt, line);
92 snprintf(word, sizeof(word), fmt, ord);
93 pp = proto_parse(fhdr, word, 0);
97 fprintf(fout, " %s", word);
99 fprintf(fout, "@%-2d", pp->argc_stack * 4);
102 fprintf(fout, " @%d", ord);
104 fprintf(fout, " NONAME");
113 // vim:ts=2:shiftwidth=2:expandtab