Commit | Line | Data |
---|---|---|
c287c78d | 1 | # This file fills in a config_h.SH template based on the data |
24e8e380 GS |
2 | # of the file config.def and outputs a config.h. |
3 | # | |
4 | # Written January 24, 2000 by Jarkko Hietaniemi [jhi@iki.fi] | |
5 | # Modified February 2, 2000 by Paul Green [Paul_Green@stratus.com] | |
5b8c1387 | 6 | # Modified October 23, 2000 by Paul Green [Paul_Green@stratus.com] |
24e8e380 GS |
7 | |
8 | # | |
9 | # Read in the definitions file | |
10 | # | |
c287c78d JH |
11 | |
12 | if (open(CONFIG_DEF, "config.def")) { | |
13 | while (<CONFIG_DEF>) { | |
24e8e380 GS |
14 | if (/^([^=]+)='(.*)'$/) { |
15 | my ($var, $val) = ($1, $2); | |
16 | $define{$var} = $val; | |
5b8c1387 | 17 | $used{$var} = 0; |
24e8e380 GS |
18 | } else { |
19 | warn "config.def: $.: illegal line: $_"; | |
20 | } | |
c287c78d JH |
21 | } |
22 | } else { | |
23 | die "$0: Cannot open config.def: $!"; | |
24 | } | |
25 | ||
24e8e380 GS |
26 | close (CONFIG_DEF); |
27 | ||
28 | # | |
29 | # Open the template input file. | |
30 | # | |
31 | ||
5b8c1387 JH |
32 | $lineno = 0; |
33 | unless (open(CONFIG_SH, "../config_h.SH")) { | |
34 | die "$0: Cannot open ../config_h.SH: $!"; | |
24e8e380 GS |
35 | } |
36 | ||
37 | # | |
38 | # Open the output file. | |
39 | # | |
40 | ||
41 | unless (open(CONFIG_H, ">config.h.new")) { | |
42 | die "$0: Cannot open config.h.new for output: $!"; | |
43 | } | |
44 | ||
45 | # | |
46 | # Skip lines before the first !GROK!THIS! | |
47 | # | |
48 | ||
49 | while (<CONFIG_SH>) { | |
5b8c1387 | 50 | $lineno = $lineno + 1; |
24e8e380 GS |
51 | last if /^sed <<!GROK!THIS!/; |
52 | } | |
53 | ||
54 | # | |
55 | # Process the rest of the file, a line at a time. | |
56 | # Stop when the next !GROK!THIS! is found. | |
57 | # | |
58 | ||
59 | while (<CONFIG_SH>) { | |
5b8c1387 | 60 | $lineno = $lineno + 1; |
24e8e380 GS |
61 | last if /^!GROK!THIS!/; |
62 | # | |
5b8c1387 JH |
63 | # The definition of SITEARCH and SITEARCH_EXP has to be commented-out. |
64 | # The easiest way to do this is to special-case it here. | |
65 | # | |
66 | if (/^#define SITEARCH*/) { | |
67 | s@(^.*$)@/*$1@; | |
68 | } | |
69 | # | |
24e8e380 GS |
70 | # The case of #$d_foo at the BOL has to be handled carefully. |
71 | # If $d_foo is "undef", then we must first comment out the entire line. | |
72 | # | |
5b8c1387 JH |
73 | if (/^#(\$\w+)/) { |
74 | if (exists $define{$1}) { | |
75 | $used{$1}=1; | |
76 | s@^#(\$\w+)@("$define{$1}" eq "undef") ? | |
77 | "/*#define":"#$define{$1}"@e; | |
78 | } | |
c287c78d | 79 | } |
24e8e380 GS |
80 | # |
81 | # There could be multiple $variables on this line. | |
82 | # Find and replace all of them. | |
83 | # | |
84 | if (/(\$\w+)/) { | |
5b8c1387 JH |
85 | s/(\$\w+)/(exists $define{$1}) ? |
86 | (($used{$1}=1),$define{$1}) : | |
87 | ((print "Undefined keyword $1 on line $lineno\n"),$1)/ge; | |
24e8e380 GS |
88 | print CONFIG_H; |
89 | } | |
90 | # | |
91 | # There are no variables, just print the line out. | |
92 | # | |
93 | else { | |
94 | print CONFIG_H; | |
c287c78d | 95 | } |
c287c78d | 96 | } |
24e8e380 GS |
97 | |
98 | unless (close (CONFIG_H)) { | |
99 | die "$0: Cannot close config.h.new: $!"; | |
100 | } | |
101 | ||
102 | close (CONFIG_SH); | |
5b8c1387 JH |
103 | |
104 | while (($key,$value) = each %used) { | |
105 | if ($value == 0) { | |
106 | print "Unused keyword definition: $key\n"; | |
107 | } | |
108 | } | |
109 |