1# Extract initialization tables from actual source code.
2
3# XXX: Associated variable aliasing:
4#
5# Some parameters bind to different variables in different contexts,
6# And other parameters map to associated variables in a many-to-1
7# fashion. This is mostly the result of the SMTP+LMTP integration
8# and the overloading of parameters that have identical semantics,
9# for the corresponding context.
10#
11# The "++table[...]" below ignores the associated variable name
12# when doing duplicate elimination. Differences in the default value
13# or lower/upper bounds still result in "postconf -d" duplicates,
14# which are a sign of an error somewhere...
15#
16# XXX Work around ancient AWK implementations with a 10 file limit
17# and no working close() operator (e.g. Solaris). Some systems
18# have a more modern implementation that is XPG4-compatible, but it
19# is too much bother to find out where each system keeps these.
20
21/^(static| )*(const +)?CONFIG_INT_TABLE .*\{/,/\};/ {
22    if ($1 ~ /VAR/) {
23	int_vars["int " substr($3,2,length($3)-2) ";"] = 1
24	if (++itab[$1 $2 $4 $5 $6 $7 $8 $9] == 1) {
25	    int_table[$0] = 1
26	}
27    }
28}
29/^(static| )*(const +)?CONFIG_STR_TABLE .*\{/,/\};/ {
30    if ($1 ~ /^VAR/) {
31	str_vars["char *" substr($3,2,length($3)-2) ";"] = 1
32	if (++stab[$1 $2 $4 $5 $6 $7 $8 $9] == 1) {
33	    str_table[$0] = 1
34	}
35    }
36}
37/^(static| )*(const +)?CONFIG_RAW_TABLE .*\{/,/\};/ {
38    if ($1 ~ /^VAR/) {
39	raw_vars["char *" substr($3,2,length($3)-2) ";"] = 1
40	if (++rtab[$1 $2 $4 $5 $6 $7 $8 $9] == 1) {
41	    raw_table[$0] = 1
42	}
43    }
44}
45/^(static| )*(const +)?CONFIG_BOOL_TABLE .*\{/,/\};/ {
46    if ($1 ~ /^VAR/) {
47	bool_vars["int " substr($3,2,length($3)-2) ";"] = 1
48	if (++btab[$1 $2 $4 $5 $6 $7 $8 $9] == 1) {
49	    bool_table[$0] = 1
50	}
51    }
52}
53/^(static| )*(const +)?CONFIG_TIME_TABLE .*\{/,/\};/ {
54    if ($1 ~ /^VAR/) {
55	time_vars["int " substr($3,2,length($3)-2) ";"] = 1
56	if (++ttab[$1 $2 $4 $5 $6 $7 $8 $9] == 1) {
57	    time_table[$0] = 1
58	}
59    }
60}
61/^(static| )*(const +)?CONFIG_NINT_TABLE .*\{/,/\};/ {
62    if ($1 ~ /VAR/) {
63	nint_vars["int " substr($3,2,length($3)-2) ";"] = 1
64	if (++itab[$1 $2 $4 $5 $6 $7 $8 $9] == 1) {
65	    nint_table[$0] = 1
66	}
67    }
68}
69
70END {
71    # Print parameter declarations without busting old AWK's file limit.
72    print "cat >int_vars.h <<'EOF'"
73    for (key in int_vars)
74	print key
75    print "EOF"
76
77    print "cat >str_vars.h <<'EOF'"
78    for (key in str_vars)
79	print key
80    print "EOF"
81
82    print "cat >raw_vars.h <<'EOF'"
83    for (key in raw_vars)
84	print key
85    print "EOF"
86
87    print "cat >bool_vars.h <<'EOF'"
88    for (key in bool_vars)
89	print key
90    print "EOF"
91
92    print "cat >time_vars.h <<'EOF'"
93    for (key in time_vars)
94	print key
95    print "EOF"
96
97    print "cat >nint_vars.h <<'EOF'"
98    for (key in nint_vars)
99	print key
100    print "EOF"
101
102    # Print parameter initializations without busting old AWK's file limit.
103    print "sed 's/[ 	][ 	]*/ /g' >int_table.h <<'EOF'"
104    for (key in int_table)
105	print key
106    print "EOF"
107
108    print "sed 's/[ 	][ 	]*/ /g' >str_table.h <<'EOF'"
109    for (key in str_table)
110	print key
111    print "EOF"
112
113    print "sed 's/[ 	][ 	]*/ /g' >raw_table.h <<'EOF'"
114    for (key in raw_table)
115	print key
116    print "EOF"
117
118    print "sed 's/[ 	][ 	]*/ /g' >bool_table.h <<'EOF'"
119    for (key in bool_table)
120	print key
121    print "EOF"
122
123    print "sed 's/[ 	][ 	]*/ /g' >time_table.h <<'EOF'"
124    for (key in time_table)
125	print key
126    print "EOF"
127
128    print "sed 's/[ 	][ 	]*/ /g' >nint_table.h <<'EOF'"
129    for (key in nint_table)
130	print key
131    print "EOF"
132
133    # Flush output nicely.
134    exit(0);
135}
136