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{ owned_by_library = (FILENAME ~ /\/(global|tls)\//) }
22
23/^(static| )*(const +)?CONFIG_INT_TABLE .*\{/,/\};/ { 
24    if ($1 ~ /VAR/) {
25	if (!owned_by_library)
26	    int_vars["int " substr($3,2,length($3)-2) ";"] = 1
27	if (++itab[$1 $2 $4 $5 $6 $7 $8 $9] == 1) {
28	    int_table[$0] = 1
29	}
30    }
31}
32/^(static| )*(const +)?CONFIG_STR_TABLE .*\{/,/\};/ { 
33    if ($1 ~ /^VAR/) {
34	if (!owned_by_library)
35	    str_vars["char *" substr($3,2,length($3)-2) ";"] = 1
36	if (++stab[$1 $2 $4 $5 $6 $7 $8 $9] == 1) {
37	    str_table[$0] = 1
38	}
39    }
40}
41/^(static| )*(const +)?CONFIG_STR_FN_TABLE .*\{/,/\};/ { 
42    if ($1 ~ /^VAR/) {
43	if (!owned_by_library)
44	    str_fn_vars["char *" substr($3,2,length($3)-2) ";"] = 1
45	$2 = "pcf_" $2
46	if (++stab[$1 $2 $4 $5 $6 $7 $8 $9] == 1) {
47	    str_fn_table[$0] = 1
48	}
49    }
50}
51/^(static| )*(const +)?CONFIG_RAW_TABLE .*\{/,/\};/ { 
52    if ($1 ~ /^VAR/) {
53	if (!owned_by_library)
54	    raw_vars["char *" substr($3,2,length($3)-2) ";"] = 1
55	if (++rtab[$1 $2 $4 $5 $6 $7 $8 $9] == 1) {
56	    raw_table[$0] = 1
57	}
58    }
59}
60/^(static| )*(const +)?CONFIG_BOOL_TABLE .*\{/,/\};/ { 
61    if ($1 ~ /^VAR/) {
62	if (!owned_by_library)
63	    bool_vars["int " substr($3,2,length($3)-2) ";"] = 1
64	if (++btab[$1 $2 $4 $5 $6 $7 $8 $9] == 1) {
65	    bool_table[$0] = 1
66	}
67    }
68}
69/^(static| )*(const +)?CONFIG_TIME_TABLE .*\{/,/\};/ { 
70    if ($1 ~ /^VAR/) {
71	if (!owned_by_library)
72	    time_vars["int " substr($3,2,length($3)-2) ";"] = 1
73	if (++ttab[$1 $2 $4 $5 $6 $7 $8 $9] == 1) {
74	    time_table[$0] = 1
75	}
76    }
77}
78/^(static| )*(const +)?CONFIG_NINT_TABLE .*\{/,/\};/ { 
79    if ($1 ~ /VAR/) {
80	if (!owned_by_library)
81	    nint_vars["int " substr($3,2,length($3)-2) ";"] = 1
82	if (++itab[$1 $2 $4 $5 $6 $7 $8 $9] == 1) {
83	    nint_table[$0] = 1
84	}
85    }
86}
87/^(static| )*(const +)?CONFIG_NBOOL_TABLE .*\{/,/\};/ { 
88    if ($1 ~ /^VAR/) {
89	if (!owned_by_library)
90	    nbool_vars["int " substr($3,2,length($3)-2) ";"] = 1
91	if (++btab[$1 $2 $4 $5 $6 $7 $8 $9] == 1) {
92	    nbool_table[$0] = 1
93	}
94    }
95}
96/^(static| )*(const +)?CONFIG_LONG_TABLE .*\{/,/\};/ { 
97    if ($1 ~ /VAR/) {
98	if (!owned_by_library)
99	    long_vars["long " substr($3,2,length($3)-2) ";"] = 1
100	if (++itab[$1 $2 $4 $5 $6 $7 $8 $9] == 1) {
101	    long_table[$0] = 1
102	}
103    }
104}
105
106END { 
107    # Print parameter declarations without busting old AWK's file limit.
108    print "cat >int_vars.h <<'EOF'"
109    for (key in int_vars)
110	print key
111    print "EOF"
112
113    print "cat >str_vars.h <<'EOF'"
114    for (key in str_vars)
115	print key
116    print "EOF"
117
118    print "cat >str_fn_vars.h <<'EOF'"
119    for (key in str_fn_vars)
120	print key
121    print "EOF"
122
123    print "cat >raw_vars.h <<'EOF'"
124    for (key in raw_vars)
125	print key
126    print "EOF"
127
128    print "cat >bool_vars.h <<'EOF'"
129    for (key in bool_vars)
130	print key
131    print "EOF"
132
133    print "cat >time_vars.h <<'EOF'"
134    for (key in time_vars)
135	print key
136    print "EOF"
137
138    print "cat >nint_vars.h <<'EOF'"
139    for (key in nint_vars)
140	print key
141    print "EOF"
142
143    print "cat >nbool_vars.h <<'EOF'"
144    for (key in nbool_vars)
145	print key
146    print "EOF"
147
148    print "cat >long_vars.h <<'EOF'"
149    for (key in long_vars)
150	print key
151    print "EOF"
152
153    # Print parameter initializations without busting old AWK's file limit.
154    print "sed 's/[ 	][ 	]*/ /g' >int_table.h <<'EOF'"
155    for (key in int_table)
156	print key
157    print "EOF"
158
159    print "sed 's/[ 	][ 	]*/ /g' >str_table.h <<'EOF'"
160    for (key in str_table)
161	print key
162    print "EOF"
163
164    print "sed 's/[ 	][ 	]*/ /g' >str_fn_table.h <<'EOF'"
165    for (key in str_fn_table)
166	print key
167    print "EOF"
168
169    print "sed 's/[ 	][ 	]*/ /g' >raw_table.h <<'EOF'"
170    for (key in raw_table)
171	print key
172    print "EOF"
173
174    print "sed 's/[ 	][ 	]*/ /g' >bool_table.h <<'EOF'"
175    for (key in bool_table)
176	print key
177    print "EOF"
178
179    print "sed 's/[ 	][ 	]*/ /g' >time_table.h <<'EOF'"
180    for (key in time_table)
181	print key
182    print "EOF"
183
184    print "sed 's/[ 	][ 	]*/ /g' >nint_table.h <<'EOF'"
185    for (key in nint_table)
186	print key
187    print "EOF"
188
189    print "sed 's/[ 	][ 	]*/ /g' >nbool_table.h <<'EOF'"
190    for (key in nbool_table)
191	print key
192    print "EOF"
193
194    print "sed 's/[ 	][ 	]*/ /g' >long_table.h <<'EOF'"
195    for (key in long_table)
196	print key
197    print "EOF"
198
199    # Flush output nicely.
200    exit(0);
201}
202