Hide internal __gettextparse function [BZ #18822]
[glibc.git] / scripts / gen-posix-conf-vars.awk
blob9a4c54256af93c79fe292f1f3bcc38b6ecc7578d
1 # Generate posix-conf-vars-def.h with definitions for CONF_DEF{CONF} for each
2 # configuration variable that getconf or sysconf may use. Currently it is
3 # equipped only to generate such macros for specification macros and for
4 # SYSCONF macros in the _POSIX namespace.
6 BEGIN {
7 prefix = ""
10 $1 ~ /^#/ || $0 ~ /^\s*$/ {
11 next
14 # Begin a new prefix.
15 $NF == "{" {
16 type = $1
17 prefix = $2
19 if (NF == 4)
20 sc_prefix = $3
21 else
22 sc_prefix = "_SC"
24 next
27 $1 == "}" {
28 prefix = ""
29 type = ""
30 sc_prefix = ""
31 next
35 if (prefix == "" && type == "" && sc_prefix == "") {
36 printf ("Syntax error at %s:%d\n", FILENAME, FNR) > "/dev/stderr"
37 exit 1
40 # The prefix and variable names are indices and the value indicates what type
41 # of variable it is. The possible options are:
42 # CONFSTR: A configuration string
43 # SYSCONF: A numeric value
44 # SPEC: A specification
45 c = prefix "_" $1
46 sc_prefixes[c] = sc_prefix
47 prefix_conf[c] = type
48 conf[c] = $1
51 END {
52 print "/* AUTOGENERATED by gen-posix-conf-vars.awk. DO NOT EDIT. */\n"
54 # Generate macros that specify if a sysconf macro is defined and/or set.
55 for (c in prefix_conf) {
56 printf "#ifndef _%s\n", c
57 printf "# define CONF_DEF_%s CONF_DEF_UNDEFINED\n", c
58 # CONFSTR have string values and they are not set or unset.
59 if (prefix_conf[c] != "CONFSTR") {
60 printf "#else\n"
61 printf "# if _%s > 0\n", c
62 printf "# define CONF_DEF_%s CONF_DEF_DEFINED_SET\n", c
63 printf "# else\n"
64 printf "# define CONF_DEF_%s CONF_DEF_DEFINED_UNSET\n", c
65 printf "# endif\n"
67 printf "#endif\n\n"
69 # Build a name -> sysconf number associative array to print a C array at
70 # the end.
71 if (prefix_conf[c] == "SPEC")
72 spec[c] = sc_prefixes[c] "_" conf[c]
75 # Print the specification array. Define the macro NEED_SPEC_ARRAY before
76 # including posix-conf-vars.h to make it available in the compilation unit.
77 print "#if NEED_SPEC_ARRAY"
78 print "static const struct { const char *name; int num; } specs[] ="
79 print " {"
80 for (s in spec) {
81 printf " { \"%s\", %s },\n", s, spec[s]
83 print " };"
84 print "static const size_t nspecs = sizeof (specs) / sizeof (specs[0]);"
85 print "#endif"