1#!/usr/bin/awk -f 2# $FreeBSD$ 3BEGIN { 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} 15state == 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 "#include <sys/param.h>"; 40 print "#define\tNWORDS\t(nitems(wordlist) - 1)"; 41 print "static const struct map *"; 42 print "in_word_set(const char *word)"; 43 print "{"; 44 print "\tconst struct", struct_seen, "*mp;"; 45 print ""; 46 print "\tfor (mp = wordlist; mp < &wordlist[NWORDS]; mp++) {"; 47 print "\t\tif (strcmp(word, mp->name) == 0)"; 48 print "\t\t\treturn (mp);"; 49 print "\t}"; 50 print "\treturn (NULL);"; 51 print "}"; 52 print ""; 53 next; 54} 55state == 2 && NF == 2 { 56 name = substr($1, 1, length($1) - 1); 57 printf "#ifdef %s\n", $2; 58 printf "\t{ \"%s\", %s, 1 },\n", name, $2; 59 print "#else"; 60 printf "\t{ \"%s\", 0, 0 },\n", name, $2; 61 print "#endif" 62 next; 63} 64state == 3 { print; next; } 65{ 66 # eat anything not matched. 67} 68