X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=utils%2Flibnetcfg.PL;h=1f47c24a1773e67f4ee28e6ba255f85921c2574b;hb=3bf55fe9d8000eec3ee2afa7455b435ffc747d7d;hp=3418dd11a34288a91930d67ec6a8829d303493ea;hpb=406c51eefa6c9c4f403ef7f86adb46a627701935;p=p5sagit%2Fp5-mst-13.2.git diff --git a/utils/libnetcfg.PL b/utils/libnetcfg.PL index 3418dd1..1f47c24 100644 --- a/utils/libnetcfg.PL +++ b/utils/libnetcfg.PL @@ -35,14 +35,75 @@ $Config{startperl} print OUT <<'!NO!SUBS!'; +=head1 NAME + +libnetcfg - configure libnet + +=head1 DESCRIPTION + +The libnetcfg utility can be used to configure the libnet. +Starting from perl 5.8 libnet is part of the standard Perl +distribution, but the libnetcfg can be used for any libnet +installation. + +=head1 USAGE + +Without arguments libnetcfg displays the current configuration. + + $ libnetcfg + # old config ./libnet.cfg + daytime_hosts ntp1.none.such + ftp_int_passive 0 + ftp_testhost ftp.funet.fi + inet_domain none.such + nntp_hosts nntp.none.such + ph_hosts + pop3_hosts pop.none.such + smtp_hosts smtp.none.such + snpp_hosts + test_exist 1 + test_hosts 1 + time_hosts ntp.none.such + # libnetcfg -h for help + $ + +It tells where the old configuration file was found (if found). + +The C<-h> option will show a usage message. + +To change the configuration you will need to use either the C<-c> or +the C<-d> options. + +The default name of the old configuration file is by default +"libnet.cfg", unless otherwise specified using the -i option, +C<-i oldfile>, and it is searched first from the current directory, +and then from your module path. + +The default name of the new configuration file is "libnet.cfg", and by +default it is written to the current directory, unless otherwise +specified using the -o option, C<-o newfile>. + +=head1 SEE ALSO + +L, L + +=head1 AUTHORS + +Graham Barr, the original Configure script of libnet. + +Jarkko Hietaniemi, conversion into libnetcfg for inclusion into Perl 5.8. + +=cut + # $Id: Configure,v 1.8 1997/03/04 09:22:32 gbarr Exp $ use strict; use IO::File; use Getopt::Std; use ExtUtils::MakeMaker qw(prompt); +use File::Spec; -use vars qw($opt_d $opt_o); +use vars qw($opt_d $opt_c $opt_h $opt_o $opt_i); ## ## @@ -51,7 +112,7 @@ use vars qw($opt_d $opt_o); my %cfg = (); my @cfg = (); -my($libnet_cfg,$msg,$ans,$def,$have_old); +my($libnet_cfg_in,$libnet_cfg_out,$msg,$ans,$def,$have_old); ## ## @@ -268,17 +329,20 @@ sub default_hostname ## ## -getopts('do:'); +getopts('dcho:i:'); + +$libnet_cfg_in = "libnet.cfg" + unless(defined($libnet_cfg_in = $opt_i)); -$libnet_cfg = "libnet.cfg" - unless(defined($libnet_cfg = $opt_o)); +$libnet_cfg_out = "libnet.cfg" + unless(defined($libnet_cfg_out = $opt_o)); my %oldcfg = (); $Net::Config::CONFIGURE = 1; # Suppress load of user overrides -if( -f $libnet_cfg ) +if( -f $libnet_cfg_in ) { - %oldcfg = ( %{ do $libnet_cfg } ); + %oldcfg = ( %{ do $libnet_cfg_in } ); } elsif (eval { require Net::Config }) { @@ -288,6 +352,60 @@ elsif (eval { require Net::Config }) map { $cfg{lc $_} = $cfg{$_}; delete $cfg{$_} if /[A-Z]/ } keys %cfg; +#--------------------------------------------------------------------------- + +if ($opt_h) { + print <, and it is searched first from the current directory, +and then from your module path. + +The default name of the new configuration file is "libnet.cfg", and by +default it is written to the current directory, unless otherwise +specified using the -o option. + +EOU + exit(0); +} + +#--------------------------------------------------------------------------- + +{ + my $oldcfgfile; + my @inc; + push @inc, $ENV{PERL5LIB} if exists $ENV{PERL5LIB}; + push @inc, $ENV{PERLLIB} if exists $ENV{PERLLIB}; + push @inc, @INC; + for (@inc) { + my $trycfgfile = File::Spec->catfile($_, $libnet_cfg_in); + if (-f $trycfgfile && -r $trycfgfile) { + $oldcfgfile = $trycfgfile; + last; + } + } + print "# old config $oldcfgfile\n" if defined $oldcfgfile; + for (sort keys %oldcfg) { + printf "%-20s %s\n", $_, + ref $oldcfg{$_} ? @{$oldcfg{$_}} : $oldcfg{$_}; + } + unless ($opt_c || $opt_d) { + print "# $0 -h for help\n"; + exit(0); + } +} + +#--------------------------------------------------------------------------- + $oldcfg{'test_exist'} = 1 unless exists $oldcfg{'test_exist'}; $oldcfg{'test_hosts'} = 1 unless exists $oldcfg{'test_hosts'}; @@ -595,10 +713,10 @@ print "\n"; #--------------------------------------------------------------------------- -my $fh = IO::File->new($libnet_cfg, "w") or - die "Cannot create `$libnet_cfg': $!"; +my $fh = IO::File->new($libnet_cfg_out, "w") or + die "Cannot create `$libnet_cfg_out': $!"; -print "Writing $libnet_cfg\n"; +print "Writing $libnet_cfg_out\n"; print $fh "{\n";