X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=configpm;h=fcf4e3d0fa074b6d5858b6d6caaacd54c369c463;hb=8d0ff1118aaee510902477e928a660803304346c;hp=eab7f5bea4a0e24ea061c8fba376140e6694426c;hpb=1fef88e72b0b21420614d87ecab0aaedf3725271;p=p5sagit%2Fp5-mst-13.2.git diff --git a/configpm b/configpm index eab7f5b..fcf4e3d 100755 --- a/configpm +++ b/configpm @@ -6,7 +6,7 @@ $config_pm = $ARGV[0] || 'lib/Config.pm'; # list names to put first (and hence lookup fastest) @fast = qw(archname osname osvers prefix libs libpth dynamic_ext static_ext extensions dlsrc so - sig_name cc ccflags cppflags + sig_name sig_num cc ccflags cppflags privlibexp archlibexp installprivlib installarchlib sharpbang startsh shsharp ); @@ -39,19 +39,23 @@ ENDOFBEG @non_v=(); @v_fast=(); @v_others=(); +$in_v = 0; while (<>) { next if m:^#!/bin/sh:; # Catch CONFIG=true and PATCHLEVEL=n line from Configure. s/^(\w+)=(true|\d+)\s*$/$1='$2'\n/; - unless (m/^(\w+)='(.*)'\s*$/){ + unless ($in_v or m/^(\w+)='(.*\n)/){ push(@non_v, "#$_"); # not a name='value' line next; } - $name = $1; + if ($in_v) { $val .= $_; } + else { ($name,$val) = ($1,$2); } + $in_v = $val !~ /'\n/; + next if $in_v; if ($extensions{$name}) { s,/,::,g } - if (!$fast{$name}){ push(@v_others, $_); next; } - push(@v_fast,$_); + if (!$fast{$name}){ push(@v_others, "$name='$val"); next; } + push(@v_fast,"$name='$val"); } foreach(@non_v){ print CONFIG $_ } @@ -66,8 +70,8 @@ print CONFIG "\n", print CONFIG "my \$summary = <<'!END!';\n"; open(MYCONFIG,") !~ /^Summary of/); -do { print CONFIG $_ } until ($_ = ) =~ /^\s*$/; +1 while defined($_ = ) && !/^Summary of/; +do { print CONFIG $_ } until !defined($_ = ) || /^\s*$/; close(MYCONFIG); print CONFIG "\n!END!\n", <<'EOT'; @@ -86,11 +90,20 @@ EOT print CONFIG <<'ENDOFEND'; sub FETCH { - # check for cached value (which maybe undef so we use exists not defined) + # check for cached value (which may be undef so we use exists not defined) return $_[0]->{$_[1]} if (exists $_[0]->{$_[1]}); - - my($value); # search for the item in the big $config_sh string - return undef unless (($value) = $config_sh =~ m/^$_[1]='(.*)'\s*$/m); + + # Search for it in the big string + my($value, $start, $marker); + $marker = "$_[1]='"; + # return undef unless (($value) = $config_sh =~ m/^$_[1]='(.*)'\s*$/m); + $start = index($config_sh, "\n$marker"); + return undef if ( ($start == -1) && # in case it's first + (substr($config_sh, 0, length($marker)) ne $marker) ); + if ($start == -1) { $start = length($marker) } + else { $start += length($marker) + 1 } + $value = substr($config_sh, $start, + index($config_sh, qq('\n), $start) - $start); $value = undef if $value eq 'undef'; # So we can say "if $Config{'foo'}". $_[0]->{$_[1]} = $value; # cache it @@ -101,19 +114,23 @@ my $prevpos = 0; sub FIRSTKEY { $prevpos = 0; - my($key) = $config_sh =~ m/^(.*?)=/; - $key; + # my($key) = $config_sh =~ m/^(.*?)=/; + substr($config_sh, 0, index($config_sh, '=') ); + # $key; } sub NEXTKEY { - my $pos = index($config_sh, "\n", $prevpos) + 1; + my $pos = index($config_sh, qq('\n), $prevpos) + 2; my $len = index($config_sh, "=", $pos) - $pos; $prevpos = $pos; $len > 0 ? substr($config_sh, $pos, $len) : undef; } sub EXISTS { - exists($_[0]->{$_[1]}) or $config_sh =~ m/^$_[1]=/m; + # exists($_[0]->{$_[1]}) or $config_sh =~ m/^$_[1]=/m; + exists($_[0]->{$_[1]}) or + index($config_sh, "\n$_[1]='") != -1 or + substr($config_sh, 0, length($_[1])+2) eq "$_[1]='"; } sub STORE { die "\%Config::Config is read-only\n" } @@ -228,17 +245,23 @@ See also C<-V:name> in L. Here's a more sophisticated example of using %Config: use Config; + use strict; + + my %sig_num; + my @sig_name; + unless($Config{sig_name} && $Config{sig_num}) { + die "No sigs?"; + } else { + my @names = split ' ', $Config{sig_name}; + @sig_num{@names} = split ' ', $Config{sig_num}; + foreach (@names) { + $sig_name[$sig_num{$_}] ||= $_; + } + } - defined $Config{sig_name} || die "No sigs?"; - foreach $name (split(' ', $Config{sig_name})) { - $signo{$name} = $i; - $signame[$i] = $name; - $i++; - } - - print "signal #17 = $signame[17]\n"; - if ($signo{ALRM}) { - print "SIGALRM is $signo{ALRM}\n"; + print "signal #17 = $sig_name[17]\n"; + if ($sig_num{ALRM}) { + print "SIGALRM is $sig_num{ALRM}\n"; } =head1 WARNING