kernel/{hammer2,tmpfs}: Fix ENOTDIR/EISDIR logic.
[dragonfly.git] / usr.bin / getconf / fake-gperf.awk
blobb58427ded637b6ce82f1beea2a8c9eca27112895
1 #!/usr/bin/awk -f
2 # $FreeBSD: head/usr.bin/getconf/fake-gperf.awk 119312 2003-08-22 17:32:07Z markm $
3 BEGIN {
4 state = 0;
5 struct_seen = "";
7 /^%{$/ && state == 0 {
8 state = 1;
9 next;
11 /^%}$/ && state == 1 {
12 state = 0;
13 next;
15 state == 1 { print; next; }
16 /^struct/ && state == 0 {
17 print;
18 struct_seen = $2;
19 next;
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";
33 next;
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;
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;
63 state == 3 { print; next; }
65 # eat anything not matched.