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/^(static| )*(const +)?CONFIG_NBOOL_TABLE .*\{/,/\};/ { 
70    if ($1 ~ /^VAR/) {
71	nbool_vars["int " substr($3,2,length($3)-2) ";"] = 1
72	if (++btab[$1 $2 $4 $5 $6 $7 $8 $9] == 1) {
73	    nbool_table[$0] = 1
74	}
75    }
76}
77
78END { 
79    # Print parameter declarations without busting old AWK's file limit.
80    print "cat >int_vars.h <<'EOF'"
81    for (key in int_vars)
82	print key
83    print "EOF"
84
85    print "cat >str_vars.h <<'EOF'"
86    for (key in str_vars)
87	print key
88    print "EOF"
89
90    print "cat >raw_vars.h <<'EOF'"
91    for (key in raw_vars)
92	print key
93    print "EOF"
94
95    print "cat >bool_vars.h <<'EOF'"
96    for (key in bool_vars)
97	print key
98    print "EOF"
99
100    print "cat >time_vars.h <<'EOF'"
101    for (key in time_vars)
102	print key
103    print "EOF"
104
105    print "cat >nint_vars.h <<'EOF'"
106    for (key in nint_vars)
107	print key
108    print "EOF"
109
110    print "cat >nbool_vars.h <<'EOF'"
111    for (key in nbool_vars)
112	print key
113    print "EOF"
114
115    # Print parameter initializations without busting old AWK's file limit.
116    print "sed 's/[ 	][ 	]*/ /g' >int_table.h <<'EOF'"
117    for (key in int_table)
118	print key
119    print "EOF"
120
121    print "sed 's/[ 	][ 	]*/ /g' >str_table.h <<'EOF'"
122    for (key in str_table)
123	print key
124    print "EOF"
125
126    print "sed 's/[ 	][ 	]*/ /g' >raw_table.h <<'EOF'"
127    for (key in raw_table)
128	print key
129    print "EOF"
130
131    print "sed 's/[ 	][ 	]*/ /g' >bool_table.h <<'EOF'"
132    for (key in bool_table)
133	print key
134    print "EOF"
135
136    print "sed 's/[ 	][ 	]*/ /g' >time_table.h <<'EOF'"
137    for (key in time_table)
138	print key
139    print "EOF"
140
141    print "sed 's/[ 	][ 	]*/ /g' >nint_table.h <<'EOF'"
142    for (key in nint_table)
143	print key
144    print "EOF"
145
146    print "sed 's/[ 	][ 	]*/ /g' >nbool_table.h <<'EOF'"
147    for (key in nbool_table)
148	print key
149    print "EOF"
150
151    # Flush output nicely.
152    exit(0);
153}
154