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