Remove the last regnode<==>char*
[p5sagit/p5-mst-13.2.git] / win32 / config_sh.PL
1 # take a semicolon separated path list and turn it into a quoted
2 # list of paths that Text::Parsewords will grok
3 sub mungepath {
4     my $p = shift;
5     # remove leading/trailing semis/spaces
6     $p =~ s/^[ ;]+//;
7     $p =~ s/[ ;]+$//;
8     $p =~ s/'/"/g;
9     my @p = map { $_ = "\"$_\"" if /\s/ and !/^".*"$/; $_ } split /;/, $p;
10     return join(' ', @p);
11 }
12
13 my %opt;
14 while (@ARGV && $ARGV[0] =~ /^([\w_]+)=(.*)$/)
15  {
16   $opt{$1}=$2;
17   shift(@ARGV);
18  }
19
20 $opt{VERSION} = $];
21 $opt{INST_VER} =~ s|~VERSION~|$]|g;
22 if ($] =~ /^(\d+)\.(\d\d\d)?(\d\d)?$/) { # should always be true
23   $opt{PERL_REVISION} = $1;
24   $opt{PERL_VERSION} = int($2 || 0);
25   $opt{PERL_SUBVERSION} = $3 || '00';
26 }
27 else {
28   die "Can't parse perl version ($])";
29 }
30
31 $opt{'cf_by'} = $ENV{USERNAME} unless $opt{'cf_by'};
32 $opt{'cf_email'} = $opt{'cf_by'} . '@' . (gethostbyname('localhost'))[0]
33         unless $opt{'cf_email'};
34 $opt{'usemymalloc'} = 'y' if $opt{'d_mymalloc'} eq 'define';
35
36 $opt{libpth} = mungepath($opt{libpth}) if exists $opt{libpth};
37 $opt{incpath} = mungepath($opt{incpath}) if exists $opt{incpath};
38
39 while (<>)
40  {
41   s/~([\w_]+)~/$opt{$1}/g;
42   if (/^([\w_]+)=(.*)$/) {
43     my($k,$v) = ($1,$2);
44     # this depends on cf_time being empty in the template (or we'll get a loop)
45     if ($k eq 'cf_time') {
46       $_ = "$k='" . localtime(time) . "'\n" if $v =~ /^\s*'\s*'/;
47     }
48     elsif (exists $opt{$k}) {
49       $_ = "$k='$opt{$k}'\n";
50     }
51   }
52   print;
53  }
54