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
|
#!/usr/bin/awk -f
# $FreeBSD$
BEGIN {
state = 0;
struct_seen = "";
}
/^%{$/ && state == 0 {
state = 1;
next;
}
/^%}$/ && state == 1 {
state = 0;
next;
}
state == 1 { print; next; }
/^struct/ && state == 0 {
print;
struct_seen = $2;
next;
}
/^%%$/ && state == 0 {
state = 2;
if (struct_seen !~ /^$/) {
print "static const struct", struct_seen, "wordlist[] = {";
} else {
print "static const struct map {";
print "\tconst char *name;";
print "\tint key;";
print "\tint valid;";
print "} wordlist[] = {";
struct_seen = "map";
}
next;
}
/^%%$/ && state == 2 {
state = 3;
print "\t{ NULL, 0, 0 }";
print "};";
print "#define\tNWORDS\t(sizeof(wordlist)/sizeof(wordlist[0]) - 1)";
print "static const struct map *";
print "in_word_set(const char *word)";
print "{";
print "\tconst struct", struct_seen, "*mp;";
print "";
print "\tfor (mp = wordlist; mp < &wordlist[NWORDS]; mp++) {";
print "\t\tif (strcmp(word, mp->name) == 0)";
print "\t\t\treturn (mp);";
print "\t}";
print "\treturn (NULL);";
print "}";
print "";
next;
}
state == 2 && NF == 2 {
name = substr($1, 1, length($1) - 1);
printf "#ifdef %s\n", $2;
printf "\t{ \"%s\", %s, 1 },\n", name, $2;
print "#else";
printf "\t{ \"%s\", 0, 0 },\n", name, $2;
print "#endif"
next;
}
state == 3 { print; next; }
{
# eat anything not matched.
}
|