source: trunk/third/perl/vos/config.pl @ 14545

Revision 14545, 1.7 KB checked in by ghudson, 24 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r14544, which included commits to RCS files with non-trunk default branches.
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
7#
8# Read in the definitions file
9#
10
11if (open(CONFIG_DEF, "config.def")) {
12    while (<CONFIG_DEF>) {
13        if (/^([^=]+)='(.*)'$/) {
14            my ($var, $val) = ($1, $2);
15            $define{$var} = $val;
16        } else {
17            warn "config.def: $.: illegal line: $_";
18        }
19    }
20} else {
21    die "$0: Cannot open config.def: $!";
22}
23
24close (CONFIG_DEF);
25
26#
27# Open the template input file.
28#
29
30unless (open(CONFIG_SH, "config_h.SH_orig")) {
31    die "$0: Cannot open config_h.SH_orig: $!";
32}
33
34#
35# Open the output file.
36#
37
38unless (open(CONFIG_H, ">config.h.new")) {
39    die "$0: Cannot open config.h.new for output: $!";
40}
41
42#
43#   Skip lines before the first !GROK!THIS!
44#
45
46while (<CONFIG_SH>) {
47    last if /^sed <<!GROK!THIS!/;
48}
49
50#
51#   Process the rest of the file, a line at a time.
52#   Stop when the next !GROK!THIS! is found.
53#
54
55while (<CONFIG_SH>) {
56    last if /^!GROK!THIS!/;
57#
58#   The case of #$d_foo at the BOL has to be handled carefully.
59#   If $d_foo is "undef", then we must first comment out the entire line.
60#
61    if (/^#\$\w+/) {
62        s@^#(\$\w+)@("$define{$1}" eq "undef")?"/*#define":"#$define{$1}"@e;
63    }
64#
65#   There could be multiple $variables on this line.
66#   Find and replace all of them.
67#
68    if (/(\$\w+)/) {
69        s/(\$\w+)/(exists $define{$1}) ? $define{$1} : $1/ge;
70        print CONFIG_H;
71    }
72#
73#   There are no variables, just print the line out.
74#
75    else {
76        print CONFIG_H;
77    }
78}
79
80unless (close (CONFIG_H)) {
81    die "$0: Cannot close config.h.new: $!";
82    }
83
84close (CONFIG_SH);
Note: See TracBrowser for help on using the repository browser.