-
Notifications
You must be signed in to change notification settings - Fork 22
/
genfkntab.c
63 lines (56 loc) · 1.6 KB
/
genfkntab.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int
main(int argc, char **argv)
{
int i = 0, j;
char name[160];
char *func_name;
char *prefix;
char *fname;
FILE *header_file, *data_file;
if (argc < 3)
exit(1);
prefix = argv[1];
fname = argv[2];
for (j = 0; prefix[j]; j++)
prefix[j] = toupper(prefix[j]);
(void)sprintf(name, "%s.h", fname);
header_file = fopen(name, "w");
(void)sprintf(name, "%s.t", fname);
data_file = fopen(name, "w");
(void)fprintf(data_file, "static struct fkntab %s_fkntab[] =\n{\n", fname);
for ((void)fgets(name, sizeof(name), stdin);
!feof(stdin);
(void)fgets(name, sizeof(name), stdin))
{
if ((func_name = strchr(name, '\n')) != NULL)
*func_name = '\0';
if (!*name || *name == '#')
continue;
func_name = name;
for (j = 0; name[j]; j++)
{
if (name[j] == '\t' ||
name[j] == ' ')
{
name[j] = '\0';
j++;
while (name[j] || name[j] == ' ' || name[j] == '\t')
j++;
if (name[j])
func_name = &name[j];
break;
}
}
(void)fprintf(data_file, " {\"%s\", 0, 0},\n", func_name);
for (j = 0; name[j]; j++)
name[j] = toupper(name[j]);
(void)fprintf(header_file, "#define %s_%s %d\n", prefix, name, i++);
}
(void)fputs(" {NULL, 0, 0}\n};\n", data_file);
exit(0);
/* NOTREACHED */
}