[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Fixing Config.pm (was Re: Welcome to macperl)



Sorry about the previous uninformative title.

Attached is a fixed version of Config.pm for MacPerl.  It incorporates two levels of fixes, defining variables which were not defined

SUBVERSION=''
useshrplib=''
libperl=''
baserev=''
d_sigaction=''
bincompat3=''
useperlio=''
d_sfio=''
ld=''

and altering the test for definition so it will not throw a warning for a 
value which is 'undef'

	$summary =~ s/\$(\w+)/$Config{$1} if defined($Config{$1})/ge;

to replace

	$summary =~ s/\$(\w+)/$Config{$1}/ge;

Hope this helps.


>Sorry if this is a known bug; the archive did not pop it up for me...
>
>Config.pm subroutine myconfig seems to throw warnings as shown below.
>Has anyone fixed this for all 10 warnings?  Would you be so kind as to
>send me the fix?  
>
>Thanks.
>
>Regards, Mike
>
>
>#!perl -w
>#use strict;
>#use Carp ();
>#local $SIG{__WARN__} = \&Carp::cluck;
>#use File::Basename;
>use Config;
>use Config qw(myconfig config_sh config_vars);
>print myconfig();
>#my ($app, $path) = fileparse($0);
>print "$Config{'osname'}",
> "\n\nLibrary paths:\n", join ("\n" , @INC ) ;
>
>__END__
>Output: warnings thrown by "print myconfig();",
>due to absence of definitions in $config_sh for variables such as 
>
>SUBVERSION
>useshrplib
>libperl
>
>and others which are left as an exercise for the reader 
>
>
># Use of uninitialized value.
>File 'scsi:MacPerl 520r4 Ÿ:lib:Config.pm'; Line 469
># Use of uninitialized value.
>File 'scsi:MacPerl 520r4 Ÿ:lib:Config.pm'; Line 469
># Use of uninitialized value.
>File 'scsi:MacPerl 520r4 Ÿ:lib:Config.pm'; Line 469
># Use of uninitialized value.
>File 'scsi:MacPerl 520r4 Ÿ:lib:Config.pm'; Line 469
># Use of uninitialized value.
>File 'scsi:MacPerl 520r4 Ÿ:lib:Config.pm'; Line 469
># Use of uninitialized value.
>File 'scsi:MacPerl 520r4 Ÿ:lib:Config.pm'; Line 469
># Use of uninitialized value.
>File 'scsi:MacPerl 520r4 Ÿ:lib:Config.pm'; Line 469
># Use of uninitialized value.
>File 'scsi:MacPerl 520r4 Ÿ:lib:Config.pm'; Line 469
># Use of uninitialized value.
>File 'scsi:MacPerl 520r4 Ÿ:lib:Config.pm'; Line 469
># Use of uninitialized value.
>File 'scsi:MacPerl 520r4 Ÿ:lib:Config.pm'; Line 469
>Summary of my  ( patchlevel 0 subversion ) configuration:
>  Platform:
>    osname=MacOS, osvers=7.5, archname=
>    uname=''
>    hint=, useposix=true, d_sigaction=
>    bincompat3= useperlio= d_sfio=
>  Compiler:
>    cc='C', optimize='', gccversion=
>    cppflags=''
>    ccflags =''
>    stdchar='', d_stdstdio=define, usevfork=
>    voidflags=, castflags=0, d_casti32=32, d_castneg=define
>    intsize=32, alignbytes=, usemymalloc=, randbits=
>  Linker and Libraries:
>    ld='', ldflags =''
>    libpth=
>    libs=
>    libc=, so=
>    useshrplib=, libperl=
>  Dynamic Linking:
>    dlsrc=, dlext=, d_dlsymun=, ccdlflags=''
>    cccdlflags='', lddlflags=''
>
>MacOS
>
>Library paths:
>scsi:MacPerl 520r4 Ÿ:site_perl:MacPPC:
>scsi:MacPerl 520r4 Ÿ:site_perl:
>scsi:MacPerl 520r4 Ÿ:lib:MacPPC:
>scsi:MacPerl 520r4 Ÿ:lib:
>scsi:MacPerl 520r4 Ÿ:lib:MacPPC:
>scsi:MacPerl 520r4 Ÿ:lib:
>scsi:MacPerl 520r4 Ÿ:site_perl:MacPPC:
>scsi:MacPerl 520r4 Ÿ:site_perl:
>:
>Dev:Pseudo:
>
># ===== Want to unsubscribe from this list?
># ===== Send mail with body "unsubscribe" to macperl-request@macperl.org
package Config;
use Exporter ();
@ISA = (Exporter);
@EXPORT = qw(%Config);
@EXPORT_OK = qw(myconfig config_sh config_vars);

$] == 5.004
  or die "Perl lib version (5.004) doesn't match executable version ($])";

# This file was created by configpm when Perl was built. Any changes
# made to this file will be lost the next time perl is built.

##
## Manually created configuration file for Macintii
## Configuration time:	18Jun97
## Configured by: 	Matthias Neeracher <neeri@iis.ee.ethz.ch>
## Target system: 	Apple Macintosh
#
# patched by Mike West <mwest@nyx.net> 20Jan2000 so that 
# myconfig will not throw warnings when used with -w 
# by adding 9 blank variables and modifying one line to 
# 	$summary =~ s/\$(\w+)/$Config{$1} if defined($Config{$1})/ge;
# to catch a variable set to 'undef'

my $config_sh = <<'!END!';
extensions='DB_File DynaLoader Fcntl NDBM_File POSIX IO Socket Opcode Safe'
static_ext='DynaLoader'
osname='MacOS'
osvers='7.5'
archlibexp=''
archname=''
installarchlib=''
cc='C'
ccflags=''
cppflags=''
dlsrc=''
libpth=''
libs=''
prefix=''
installprivlib=''
privlibexp=''
sig_name=''
so=''
sharpbang=''
shsharp=''
startsh=''
Author='neeri'
CONFIG='true'
Date=''
Header=''
Id=''
Locker=''
Log=''
Mcc='C'
PATCHLEVEL='0'
RCSfile=''
Revision=''
Source=''
State=''
afs=''
alignbytes=''
aphostname=''
archlib=''
awk='gawk'
bash=''
bin=''
binexp=''
bison='bison'
byacc='byacc'
byteorder='4321'
c=''
castflags='0'
cat='Catenate'
cccdlflags=''
ccdlflags=''
cf_by=''
cf_time=''
chgrp=''
chmod=''
chown=''
clocktype='clock_t'
compress='Stuffit'
contains=''
cp='Duplicate'
cpio=''
cpp='C -e'
cpp_stuff=''
cpplast=''
cppminus=''
cpprun=''
cppstdin=''
cryptlib=''
csh=''
d_Gconvert='undef'
d_access='undef'
d_alarm='undef'
d_archlib='undef'
d_attrib='undef'
d_bcmp='define'
d_bcopy='define'
d_bsdpgrp='undef'
d_bzero='define'
d_casti32='32'
d_castneg='define'
d_charsprf='undef'
d_charvspr='undef'
d_chown='undef'
d_chroot='undef'
d_chsize='undef'
d_closedir='define'
d_const='define'
d_crypt='undef'
d_csh='undef'
d_cuserid='undef'
d_dbl_dig='define'
d_difftime='define'
d_dirnamlen='define'
d_dlerror='undef'
d_dlopen='undef'
d_dlsymun='undef'
d_dosuid='undef'
d_drem='undef'
d_dup2='2'
d_eunice='undef'
d_fchmod='define'
d_fchown='undef'
d_fcntl='define'
d_fd_macros='define'
d_fd_set='define'
d_fds_bits='define'
d_fgetpos='define'
d_flexfnam='define'
d_flock='undef'
d_fmod='define'
d_fork='undef'
d_fpathconf='undef'
d_fsetpos='define'
d_getgrps='undef'
d_gethent='undef'
d_gethname='define'
d_getlogin='undef'
d_getpgrp2='undef'
d_getpgrp='undef'
d_getppid='undef'
d_getprior='undef'
d_group='undef'
d_htonl='define'
d_index='undef'
d_isascii='define'
d_killpg='undef'
d_link='undef'
d_linuxstd='undef'
d_locconv='undef'
d_lockf='undef'
d_lstat='define'
d_mblen='undef'
d_mbstowcs='define'
d_mbtowc='define'
d_memcmp='define'
d_memcpy='define'
d_memmove='define'
d_memset='define'
d_mkdir='define'
d_mkfifo='undef'
d_mktime='define'
d_msg='undef'
d_msgctl='undef'
d_msgget='undef'
d_msgrcv='undef'
d_msgsnd='undef'
d_mymalloc='undef'
d_nice='undef'
d_oldsock='undef'
d_open3='3'
d_passwd='undef'
d_pathconf='undef'
d_pause='undef'
d_phostname='undef'
d_pipe='undef'
d_portable='undef'
d_pwage='undef'
d_pwchange='undef'
d_pwclass='undef'
d_pwcomment='undef'
d_pwexpire='undef'
d_pwquota='undef'
d_readdir='define'
d_readlink='define'
d_rename='define'
d_rewinddir='define'
d_rmdir='define'
d_safebcpy='define'
d_safemcpy='undef'
d_seekdir='define'
d_select='define'
d_sem='undef'
d_semctl='undef'
d_semget='undef'
d_semop='undef'
d_setegid='undef'
d_seteuid='undef'
d_setlinebuf='undef'
d_setlocale='undef'
d_setpgid='undef'
d_setpgrp2='2'
d_setpgrp='undef'
d_setprior='undef'
d_setregid='undef'
d_setresgid='undef'
d_setresuid='undef'
d_setreuid='undef'
d_setrgid='undef'
d_setruid='undef'
d_setsid='undef'
d_shm='undef'
d_shmat='undef'
d_shmatprototype='undef'
d_shmctl='undef'
d_shmdt='undef'
d_shmget='undef'
d_socket='define'
d_sockpair='undef'
d_statblks='undef'
d_stdstdio='define'
d_strchr='define'
d_strcoll='undef'
d_strctcpy='undef'
d_strerrm='undef'
d_strerror='define'
d_strtod='define'
d_strtol='define'
d_strtoul='define'
d_strxfrm='define'
d_suidsafe='undef'
d_symlink='define'
d_syscall='undef'
d_sysconf='undef'
d_sysernlst='undef'
d_syserrlst='undef'
d_system='undef'
d_tcgetpgrp='undef'
d_tcsetpgrp='undef'
d_telldir='define'
d_time='define'
d_times='define'
d_truncate='undef'
d_tzname='undef'
d_umask='define'
d_uname='undef'
d_vfork='undef'
d_void_closedir='undef'
d_voidsig='undef'
d_voidtty='undef'
d_volatile='define'
d_vprintf='define'
d_wait4='undef'
d_waitpid='undef'
d_wcstombs='define'
d_wctomb='define'
d_xenix='undef'
date='Date'
defvoidused=''
direntrytype='dirent'
dlext=''
dont_use_nlink='define'
echo='Echo'
egrep='egrep'
emacs='$emacs'
eunicefix=':'
expr='Evaluate'
find=''
flex='flex'
fpostype='fpos_t'
gcc='gcc'
gccversion=''
gidtype=''
glibpth=''
grep='grep'
groupcat=''
groupstype=''
h_fcntl='true'
h_sysfile='false'
hint=''
hostcat=''
huge=''
i_bsdioctl=''
i_db='define'
i_dbm='define'
i_dirent='define'
i_dld=''
i_dlfcn=''
i_fcntl='define'
i_float='define'
i_gdbm='undef'
i_grp='undef'
i_limits='define'
i_malloc='undef'
i_math='define'
i_memory='define'
i_ndbm='define'
i_neterrno='undef'
i_niin='undef'
i_pwd='undef'
i_sgtty=''
i_stdarg='define'
i_stddef='define'
i_stdlib='define'
i_string='define'
i_sysdir='undef'
i_sysfile='undef'
i_sysfilio=''
i_sysin='define'
i_sysioctl='define'
i_sysndir=''
i_sysparam=''
i_sysselct=''
i_syssockio=''
i_systime='define'
i_systimek=''
i_systimes=''
i_termio=''
i_termios=''
i_time='define'
i_unistd='define'
i_utime=''
i_varargs=''
i_varhdr='stdarg.h'
i_vfork=''
incpath=''
inews=''
installbin=''
installmansrc=''
installscript=''
intsize='32'
known_extensions='DB_File DynaLoader Fcntl NDBM_File POSIX IO Socket Opcode Safe'
ksh=''
large=''
lddlflags=''
ldflags=''
less=''
libc=''
libswanted=''
line='line'
lint=''
lkflags=''
ln=''
lns=''
lp=''
lpr='Print'
ls='Directory'
lseektype=''
mail=''
mailx=''
make='BuildProgram'
mallocobj=''
mallocsrc=''
malloctype=''
manext=''
mansrc=''
mansrcexp=''
medium=''
mips=''
mips_type=''
mkdir='NewFolder'
models=''
modetype=''
more=''
mv='Move'
mydomain=''
myhostname=''
myuname=''
n=''
nm_opt=''
nroff=''
optimize=''
orderlib=''
package=''
passcat=''
path_sep=','
perl='Perl'
pg=''
phostname=''
plibpth=''
pmake=''
pr=''
privlib=''
prototype=''
randbits=''
ranlib=''
rm='Delete'
rmail=''
runnm=''
scriptdir=''
scriptdirexp=''
sed='sed'
selecttype=''
sendmail=''
sh=''
shar=''
shmattype=''
signal_t='signal_t'
sizetype=''
sleep=''
smail=''
small=''
sockethdr=''
socketlib=''
sort='Sort'
spackage=''
spitshell=''
split=''
ssizetype=''
startperl='Perl -Sx "{0}" {"Parameters"}; Exit {Status}\n#!perl'
stdchar=''
strings='define'
submit=''
sysman=''
tail=''
tar=''
tbl=''
test=''
timeincl='time.h'
timetype='time_t'
touch='SetFile -m .'
tr=''
troff=''
uidtype=''
uname=''
uniq=''
usedl=''
usemymalloc=''
usenm=''
useposix='true'
usevfork=''
usrinc=''
uuname=''
vi=''
voidflags=''
xlibpth=''
yacc=''
yaccflags=''
zcat=''
SUBVERSION=''
useshrplib=''
libperl=''
baserev=''
d_sigaction=''
bincompat3=''
useperlio=''
d_sfio=''
ld=''
!END!

my $summary = <<'!END!';
Summary of my $package ($baserev patchlevel $PATCHLEVEL subversion $SUBVERSION) configuration:
  Platform:
    osname=$osname, osvers=$osvers, archname=$archname
    uname='$myuname'
    hint=$hint, useposix=$useposix, d_sigaction=$d_sigaction
    bincompat3=$bincompat3 useperlio=$useperlio d_sfio=$d_sfio
  Compiler:
    cc='$cc', optimize='$optimize', gccversion=$gccversion
    cppflags='$cppflags'
    ccflags ='$ccflags'
    stdchar='$stdchar', d_stdstdio=$d_stdstdio, usevfork=$usevfork
    voidflags=$voidflags, castflags=$castflags, d_casti32=$d_casti32, d_castneg=$d_castneg
    intsize=$intsize, alignbytes=$alignbytes, usemymalloc=$usemymalloc, randbits=$randbits
  Linker and Libraries:
    ld='$ld', ldflags ='$ldflags'
    libpth=$libpth
    libs=$libs
    libc=$libc, so=$so
    useshrplib=$useshrplib, libperl=$libperl
  Dynamic Linking:
    dlsrc=$dlsrc, dlext=$dlext, d_dlsymun=$d_dlsymun, ccdlflags='$ccdlflags'
    cccdlflags='$cccdlflags', lddlflags='$lddlflags'

!END!
my $summary_expanded = 0;

sub myconfig {
	return $summary if $summary_expanded;
	$summary =~ s/\$(\w+)/$Config{$1} if defined($Config{$1})/ge;
	$summary_expanded = 1;
	$summary;
}

sub FETCH { 
    # check for cached value (which may be undef so we use exists not defined)
    return $_[0]->{$_[1]} if (exists $_[0]->{$_[1]});

    # 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'}".
    $value =~ s/\\n/\n/g if defined $value;		 # macintosh
    $_[0]->{$_[1]} = $value; # cache it
    return $value;
}
 
my $prevpos = 0;

sub FIRSTKEY {
    $prevpos = 0;
    # my($key) = $config_sh =~ m/^(.*?)=/;
    substr($config_sh, 0, index($config_sh, '=') );
    # $key;
}

sub NEXTKEY {
    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
    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" }
sub DELETE { &STORE }
sub CLEAR  { &STORE }


sub config_sh {
    $config_sh
}

sub config_re {
    my $re = shift;
    my @matches = ($config_sh =~ /^$re=.*\n/mg);
    @matches ? (print @matches) : print "$re: not found\n";
}

sub config_vars {
    foreach(@_){
	config_re($_), next if /\W/;
	my $v=(exists $Config{$_}) ? $Config{$_} : 'UNKNOWN';
	$v='undef' unless defined $v;
	print "$_='$v';\n";
    }
}

sub TIEHASH { bless {} }

tie %Config, 'Config';

1;
__END__

=head1 NAME

Config - access Perl configuration information

=head1 SYNOPSIS

    use Config;
    if ($Config{'cc'} =~ /gcc/) {
	print "built by gcc\n";
    } 

    use Config qw(myconfig config_sh config_vars);

    print myconfig();

    print config_sh();

    config_vars(qw(osname archname));


=head1 DESCRIPTION

The Config module contains all the information that was available to
the C<Configure> program at Perl build time (over 900 values).

Shell variables from the F<config.sh> file (written by Configure) are
stored in the readonly-variable C<%Config>, indexed by their names.

Values stored in config.sh as 'undef' are returned as undefined
values.  The perl C<exists> function can be used to check if a
named variable exists.

=over 4

=item myconfig()

Returns a textual summary of the major perl configuration values.
See also C<-V> in L<perlrun/Switches>.

=item config_sh()

Returns the entire perl configuration information in the form of the
original config.sh shell variable assignment script.

=item config_vars(@names)

Prints to STDOUT the values of the named configuration variable. Each is
printed on a separate line in the form:

  name='value';

Names which are unknown are output as C<name='UNKNOWN';>.
See also C<-V:name> in L<perlrun/Switches>.

=back

=head1 EXAMPLE

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{$_}] ||= $_;
	}   
    }

    print "signal #17 = $sig_name[17]\n";
    if ($sig_num{ALRM}) { 
	print "SIGALRM is $sig_num{ALRM}\n";
    }   

=head1 WARNING

Because this information is not stored within the perl executable
itself it is possible (but unlikely) that the information does not
relate to the actual perl binary which is being used to access it.

The Config module is installed into the architecture and version
specific library directory ($Config{installarchlib}) and it checks the
perl version number when loaded.

=head1 NOTE

This module contains a good example of how to use tie to implement a
cache and an example of how to make a tied variable readonly to those
outside of it.

=cut