]>
Commit | Line | Data |
---|---|---|
83f6dbe8 A |
1 | #!/usr/bin/awk -f |
2 | # $FreeBSD: src/usr.bin/getconf/fake-gperf.awk,v 1.3 2003/08/22 17:32:07 markm Exp $ | |
3 | BEGIN { | |
4 | state = 0; | |
5 | struct_seen = ""; | |
6 | } | |
7 | /^%{$/ && state == 0 { | |
8 | state = 1; | |
9 | next; | |
10 | } | |
11 | /^%}$/ && state == 1 { | |
12 | state = 0; | |
13 | next; | |
14 | } | |
15 | state == 1 { print; next; } | |
16 | /^struct/ && state == 0 { | |
17 | print; | |
18 | struct_seen = $2; | |
19 | next; | |
20 | } | |
21 | /^%%$/ && state == 0 { | |
22 | state = 2; | |
23 | if (struct_seen !~ /^$/) { | |
24 | print "static const struct", struct_seen, "wordlist[] = {"; | |
25 | } else { | |
26 | print "static const struct map {"; | |
27 | print "\tconst char *name;"; | |
28 | print "\tint key;"; | |
29 | print "\tint valid;"; | |
30 | print "} wordlist[] = {"; | |
31 | struct_seen = "map"; | |
32 | } | |
33 | next; | |
34 | } | |
35 | /^%%$/ && state == 2 { | |
36 | state = 3; | |
37 | print "\t{ NULL, 0, 0 }"; | |
38 | print "};"; | |
39 | print "#define\tNWORDS\t(sizeof(wordlist)/sizeof(wordlist[0]) - 1)"; | |
40 | print "static const struct map *"; | |
41 | print "in_word_set(const char *word)"; | |
42 | print "{"; | |
43 | print "\tconst struct", struct_seen, "*mp;"; | |
44 | print ""; | |
45 | print "\tfor (mp = wordlist; mp < &wordlist[NWORDS]; mp++) {"; | |
46 | print "\t\tif (strcmp(word, mp->name) == 0)"; | |
47 | print "\t\t\treturn (mp);"; | |
48 | print "\t}"; | |
49 | print "\treturn (NULL);"; | |
50 | print "}"; | |
51 | print ""; | |
52 | next; | |
53 | } | |
54 | state == 2 && NF == 2 { | |
55 | name = substr($1, 1, length($1) - 1); | |
56 | printf "#ifdef %s\n", $2; | |
57 | printf "\t{ \"%s\", %s, 1 },\n", name, $2; | |
58 | print "#else"; | |
59 | printf "\t{ \"%s\", 0, 0 },\n", name, $2; | |
60 | print "#endif" | |
61 | next; | |
62 | } | |
63 | state == 3 { print; next; } | |
64 | { | |
65 | # eat anything not matched. | |
66 | } |