1
2
3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6#include <ctype.h>
7
8int main(int argc, char *argv[])
9{
10 char *tag = 0;
11 int idx = 0;
12
13 for (;;) {
14 char *line = 0, *s;
15 ssize_t len;
16
17 len = getline(&line, (void *)&len, stdin);
18 if (len<0) break;
19 while (len && isspace(line[len-1])) line[--len]=0;
20
21
22
23
24
25
26 if (!tag) {
27 if (!isalpha(*line)) {
28 fprintf(stderr, "bad tag %s\n", line);
29 exit(1);
30 }
31 tag = strdup(line);
32 idx = 0;
33
34 continue;
35 }
36
37 for (s = line; isspace(*s); s++);
38 if (*s == ')') tag = 0;
39 else for (;;) {
40 char *start;
41
42 while (*s && *s != '{') s++;
43 while (*s && *s != '"') s++;
44 if (!*s) break;
45
46 start = ++s;
47 while (*s && *s != '"') {
48 if (!isalpha(*s) && !isdigit(*s)) *s = '_';
49 s++;
50 }
51 printf("#define %s_%*.*s %d\n", tag, -40, (int)(s-start), start, idx);
52 printf("#define _%s_%*.*s (1%s<<%d)\n", tag, -39, (int)(s-start), start,
53 idx>31 ? "LL": "", idx);
54 idx++;
55 }
56 free(line);
57 }
58}
59