1#!/usr/bin/awk -f
| 1#!/usr/bin/awk -f
|
2# 3# This file is in the public domain. Written by Garrett A. Wollman, 4# 2002-09-17. 5# 6# $FreeBSD: head/usr.bin/getconf/fake-gperf.awk 103516 2002-09-18 03:15:25Z wollman $ 7#
| 2# $FreeBSD: head/usr.bin/getconf/fake-gperf.awk 103591 2002-09-19 03:39:03Z wollman $
|
8BEGIN { 9 state = 0;
| 3BEGIN { 4 state = 0;
|
| 5 struct_seen = "";
|
10} 11/^%{$/ && state == 0 { 12 state = 1; 13 next; 14} 15/^%}$/ && state == 1 { 16 state = 0; 17 next; 18} 19state == 1 { print; next; }
| 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}
|
20/^%%$/ && state == 0 { 21 state = 2; 22 print "#include <stddef.h>"; 23 print "#include <string.h>";
| 21/^%%$/ && state == 0 { 22 state = 2; 23 print "#include <stddef.h>"; 24 print "#include <string.h>";
|
24 print "static const struct map {"; 25 print "\tconst char *name;"; 26 print "\tint key;"; 27 print "} wordlist[] = {";
| 25 if (struct_seen !~ /^$/) { 26 print "static const struct", struct_seen, "wordlist[] = {"; 27 } else { 28 print "static const struct map {"; 29 print "\tconst char *name;"; 30 print "\tint key;"; 31 print "\tint valid;"; 32 print "} wordlist[] = {"; 33 struct_seen = "map"; 34 }
|
28 next; 29} 30/^%%$/ && state == 2 { 31 state = 3; 32 print "\t{ NULL }"; 33 print "};";
| 35 next; 36} 37/^%%$/ && state == 2 { 38 state = 3; 39 print "\t{ NULL }"; 40 print "};";
|
34 print "#define\tNWORDS\t(sizeof(wordlist)/sizeof(wordlist[0]))";
| 41 print "#define\tNWORDS\t(sizeof(wordlist)/sizeof(wordlist[0]) - 1)";
|
35 print "static const struct map *"; 36 print "in_word_set(const char *word, unsigned int len)"; 37 print "{";
| 42 print "static const struct map *"; 43 print "in_word_set(const char *word, unsigned int len)"; 44 print "{";
|
38 print "\tconst struct map *mp;";
| 45 print "\tconst struct", struct_seen, "*mp;";
|
39 print ""; 40 print "\tfor (mp = wordlist; mp < &wordlist[NWORDS]; mp++) {"; 41 print "\t\tif (strcmp(word, mp->name) == 0)"; 42 print "\t\t\treturn (mp);"; 43 print "\t}"; 44 print "\treturn (NULL);"; 45 print "}"; 46 print ""; 47 next; 48} 49state == 2 && NF == 2 { 50 name = substr($1, 1, length($1) - 1);
| 46 print ""; 47 print "\tfor (mp = wordlist; mp < &wordlist[NWORDS]; mp++) {"; 48 print "\t\tif (strcmp(word, mp->name) == 0)"; 49 print "\t\t\treturn (mp);"; 50 print "\t}"; 51 print "\treturn (NULL);"; 52 print "}"; 53 print ""; 54 next; 55} 56state == 2 && NF == 2 { 57 name = substr($1, 1, length($1) - 1);
|
51 printf "\t{ \"%s\", %s },\n", name, $2;
| 58 printf "#ifdef %s\n", $2; 59 printf "\t{ \"%s\", %s, 1 },\n", name, $2; 60 print "#else"; 61 printf "\t{ \"%s\", 0, 0 },\n", name, $2; 62 print "#endif"
|
52 next; 53} 54state == 3 { print; next; } 55{ 56 # eat anything not matched. 57}
| 63 next; 64} 65state == 3 { print; next; } 66{ 67 # eat anything not matched. 68}
|