forked from cotillion/cd-gamedriver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_table.c
72 lines (69 loc) · 1.86 KB
/
make_table.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
int
main(int argc, char *argv[])
{
void lower(char *);
char buffer[BUFSIZ], *p;
FILE *in, *out;
int first=0x7fffffff, last=0, n;
if (argc != 3) {
(void)fprintf(stderr, "Usage: make_table input.h output.h\n");
exit(1);
/* NOTREACHED */
}
if ((in = fopen(argv[1], "r")) == NULL) {
perror("fopen");
exit(1);
/* NOTREACHED */
}
if ((out = fopen(argv[2], "w")) == NULL) {
perror("fopen");
exit(1);
/* NOTREACHED */
}
(void)fprintf(out, "/*\n");
(void)fprintf(out, " * This file is automatically generated; do not edit.\n");
(void)fprintf(out, " */\n\n");
(void)fprintf(out, "#ifdef EFUN_TABLE\n");
(void)fprintf(out, "static void (*efun_table[])(int) = {\n");
while (fgets(buffer, sizeof(buffer), in)) {
if (buffer[0] != '#')
continue;
p = strtok(buffer+1, " \t\n");
if (strcmp(p, "define"))
continue;
if ((p = strtok(NULL, " \t\n")) == NULL)
continue;
if (p[0] != 'F' || p[1] != '_')
continue;
lower(p);
(void)fprintf(out, "\t%s,\n", p);
if ((p = strtok(NULL, " \t\n")) == NULL)
continue;
n = atoi(p);
if (n < first)
first = n;
if (n > last)
last = n;
}
(void)fprintf(out, "};\n");
(void)fprintf(out, "#else /* EFUN_TABLE */\n");
(void)fprintf(out, "#define EFUN_FIRST %4d\n", first);
(void)fprintf(out, "#define EFUN_LAST %4d\n", last);
(void)fprintf(out, "#endif /* EFUN_TABLE */\n");
(void)fclose(out);
(void)fclose(in);
return 0;
}
void
lower(char *string)
{
while (*string) {
if (isupper(*string))
*string = tolower(*string);
string++;
}
}