source: trunk/essentials/dev-lang/perl/vos/config.pl

Last change on this file was 3181, checked in by bird, 18 years ago

perl 5.8.8

File size: 2.4 KB
Line 
1# This file fills in a config_h.SH template based on the data
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]
6# Modified October 23, 2000 by Paul Green [Paul_Green@stratus.com]
7
8#
9# Read in the definitions file
10#
11
12if (open(CONFIG_DEF, "config.def")) {
13 while (<CONFIG_DEF>) {
14 if (/^([^=]+)='(.*)'$/) {
15 my ($var, $val) = ($1, $2);
16 $define{$var} = $val;
17 $used{$var} = 0;
18 } else {
19 warn "config.def: $.: illegal line: $_";
20 }
21 }
22} else {
23 die "$0: Cannot open config.def: $!";
24}
25
26close (CONFIG_DEF);
27
28#
29# Open the template input file.
30#
31
32$lineno = 0;
33unless (open(CONFIG_SH, "../config_h.SH")) {
34 die "$0: Cannot open ../config_h.SH: $!";
35}
36
37#
38# Open the output file.
39#
40
41unless (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
49while (<CONFIG_SH>) {
50 $lineno = $lineno + 1;
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
59while (<CONFIG_SH>) {
60 $lineno = $lineno + 1;
61 last if /^!GROK!THIS!/;
62#
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#
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#
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 }
79 }
80#
81# There could be multiple $variables on this line.
82# Find and replace all of them.
83#
84 if (/(\$\w+)/) {
85 s/(\$\w+)/(exists $define{$1}) ?
86 (($used{$1}=1),$define{$1}) :
87 ((print "Undefined keyword $1 on line $lineno\n"),$1)/ge;
88 print CONFIG_H;
89 }
90#
91# There are no variables, just print the line out.
92#
93 else {
94 print CONFIG_H;
95 }
96}
97
98unless (close (CONFIG_H)) {
99 die "$0: Cannot close config.h.new: $!";
100 }
101
102close (CONFIG_SH);
103
104while (($key,$value) = each %used) {
105 if ($value == 0 && $key ne '$undef') {
106 print "Unused keyword definition: $key\n";
107 }
108}
109
Note: See TracBrowser for help on using the repository browser.