diff options
Diffstat (limited to 'system_cmds/getconf.tproj/fake-gperf.awk')
-rw-r--r-- | system_cmds/getconf.tproj/fake-gperf.awk | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/system_cmds/getconf.tproj/fake-gperf.awk b/system_cmds/getconf.tproj/fake-gperf.awk new file mode 100644 index 0000000..b3107fe --- /dev/null +++ b/system_cmds/getconf.tproj/fake-gperf.awk @@ -0,0 +1,66 @@ +#!/usr/bin/awk -f +# $FreeBSD: src/usr.bin/getconf/fake-gperf.awk,v 1.3 2003/08/22 17:32:07 markm Exp $ +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. +} |