aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/getconf/fake-gperf.awk
diff options
context:
space:
mode:
authorGarrett Wollman <wollman@FreeBSD.org>2002-09-19 03:39:03 +0000
committerGarrett Wollman <wollman@FreeBSD.org>2002-09-19 03:39:03 +0000
commite9cfb9ae3ade961f80124f3cca73e8e9dae2315b (patch)
treeab1f0dc71db78e794da3665ed9b795e82d90c7aa /usr.bin/getconf/fake-gperf.awk
parenta72f2b1a91a13b655b1f93e8806d2a3a8aa6944b (diff)
downloadsrc-e9cfb9ae3ade961f80124f3cca73e8e9dae2315b.tar.gz
src-e9cfb9ae3ade961f80124f3cca73e8e9dae2315b.zip
Completely revamp the way getconf(1) works, for better adherence to the
intent of the Standard. - Make getconf able to distinguish between configuration variables which are entirely unknown and those which are merely not defined in the compilation environment. The latter now get a more appropriate "undefined\n" result rather than a diagnostic. This may not be exactly right, but it's closer to the intent of the Standard than the previous behavior. - Support ``programming environments'' by validating that the environment requested with the `-v' flag is the one-and-only execution environment. (If more environments are supported for some platforms in the future, multiple getconf(1) executables will be required, but a simple edit in progenv.gperf will enable automatic support for it.) Document POSIX standard programming environments. - Add all of the 1003.1-2001 configuration variables. FreeBSD does not support all of these (including some that are mandatory); getconf will later be fixed to break the world should a required variable not be defined. As a result of all these changes, gperf is no longer adequate. Keep the overall format and names of the files for now, to preserve revision history. Use an awk script to process the .gperf files into C source, which does a few things that gperf, as a more general tool, cannot do. The keyword recognition function is no longer a perfect hash function. This may obviate the need for gperf in the source tree. - Add a small compile-time regression test to break the build if any of the .gperf files declare conflicting token sets. (gperf itself would have done this for the simple case of duplicate tokens in the same input file.)
Notes
Notes: svn path=/head/; revision=103591
Diffstat (limited to 'usr.bin/getconf/fake-gperf.awk')
-rw-r--r--usr.bin/getconf/fake-gperf.awk35
1 files changed, 23 insertions, 12 deletions
diff --git a/usr.bin/getconf/fake-gperf.awk b/usr.bin/getconf/fake-gperf.awk
index bffa5087c1dd..2705d6a03450 100644
--- a/usr.bin/getconf/fake-gperf.awk
+++ b/usr.bin/getconf/fake-gperf.awk
@@ -1,12 +1,8 @@
#!/usr/bin/awk -f
-#
-# This file is in the public domain. Written by Garrett A. Wollman,
-# 2002-09-17.
-#
# $FreeBSD$
-#
BEGIN {
state = 0;
+ struct_seen = "";
}
/^%{$/ && state == 0 {
state = 1;
@@ -17,25 +13,36 @@ BEGIN {
next;
}
state == 1 { print; next; }
+/^struct/ && state == 0 {
+ print;
+ struct_seen = $2;
+ next;
+}
/^%%$/ && state == 0 {
state = 2;
print "#include <stddef.h>";
print "#include <string.h>";
- print "static const struct map {";
- print "\tconst char *name;";
- print "\tint key;";
- print "} wordlist[] = {";
+ 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 }";
print "};";
- print "#define\tNWORDS\t(sizeof(wordlist)/sizeof(wordlist[0]))";
+ print "#define\tNWORDS\t(sizeof(wordlist)/sizeof(wordlist[0]) - 1)";
print "static const struct map *";
print "in_word_set(const char *word, unsigned int len)";
print "{";
- print "\tconst struct map *mp;";
+ print "\tconst struct", struct_seen, "*mp;";
print "";
print "\tfor (mp = wordlist; mp < &wordlist[NWORDS]; mp++) {";
print "\t\tif (strcmp(word, mp->name) == 0)";
@@ -48,7 +55,11 @@ state == 1 { print; next; }
}
state == 2 && NF == 2 {
name = substr($1, 1, length($1) - 1);
- printf "\t{ \"%s\", %s },\n", name, $2;
+ 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; }