From: Gurusamy Sarathy Date: Mon, 11 Aug 1997 11:01:26 +0000 (+1200) Subject: Win95-proofing pl2bat X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b2dfa14c0b6969b69807f3aadd535d36b8ceb8d3;p=p5sagit%2Fp5-mst-13.2.git Win95-proofing pl2bat This patch+shell script removes all the *.bat files in the distribution. Instead, these files will be created during build time (which will take care of making sure they work on Win95, in that silly only-nine-args way). pl2bat is now a little smarter. p5p-msgid: 199708121733.NAA14888@aatma.engin.umich.edu --- diff --git a/MANIFEST b/MANIFEST index f0865dc..1977114 100644 --- a/MANIFEST +++ b/MANIFEST @@ -819,11 +819,10 @@ win32/Makefile Win32 makefile for NMAKE (Visual C++ build) win32/TEST Win32 port win32/autosplit.pl Win32 port win32/bin/network.pl Win32 port -win32/bin/pl2bat.bat wrap perl scripts into batch files -win32/bin/runperl.bat run perl script via batch file namesake -win32/bin/search.bat Win32 port -win32/bin/test.bat Win32 port -win32/bin/webget.bat Win32 port +win32/bin/pl2bat.pl wrap perl scripts into batch files +win32/bin/runperl.pl run perl script via batch file namesake +win32/bin/search.pl Win32 port +win32/bin/webget.pl Win32 port win32/bin/www.pl Win32 port win32/config.bc Win32 base line config.sh (Borland C++ build) win32/config.vc Win32 base line config.sh (Visual C++ build) diff --git a/win32/Makefile b/win32/Makefile index 880cb88..9e4437f 100644 --- a/win32/Makefile +++ b/win32/Makefile @@ -122,8 +122,8 @@ GLOBEXE=..\perlglob.exe CONFIGPM=..\lib\Config.pm MINIMOD=..\lib\ExtUtils\Miniperl.pm -PL2BAT=bin\PL2BAT.BAT -GLOBBAT = perlglob.bat +PL2BAT=bin\pl2bat.pl +GLOBBAT = bin\perlglob.bat MAKE=nmake -nologo CFGSH_TMPL = config.vc @@ -277,8 +277,8 @@ $(DYNALOADER).obj : $(DYNALOADER).c $(CORE_H) $(EXTDIR)\DynaLoader\dlutils.c $(GLOBEXE): perlglob.obj $(LINK32) $(LINK_FLAGS) -out:$@ -subsystem:$(SUBSYS) perlglob.obj setargv.obj -perlglob.bat : ..\lib\File\DosGlob.pm $(MINIPERL) - $(MINIPERL) $(PL2BAT) - < ..\lib\File\DosGlob.pm > $(*B).bat +$(GLOBBAT) : ..\lib\File\DosGlob.pm $(MINIPERL) + $(MINIPERL) $(PL2BAT) - < ..\lib\File\DosGlob.pm > $(GLOBBAT) perlglob.obj : perlglob.c @@ -416,10 +416,12 @@ doc: $(PERLEXE) utils: $(PERLEXE) cd ..\utils nmake PERL=$(MINIPERL) - $(PERLEXE) ..\win32\$(PL2BAT) h2ph splain perlbug pl2pm c2ph \ - h2xs perldoc pstruct + $(PERLEXE) ..\win32\$(PL2BAT) h2ph splain perlbug pl2pm c2ph + $(PERLEXE) ..\win32\$(PL2BAT) h2xs perldoc pstruct $(XCOPY) *.bat ..\win32\bin\*.* cd ..\win32 + $(PERLEXE) $(PL2BAT) bin\network.pl bin\www.pl bin\runperl.pl \ + bin\pl2bat.pl distclean: clean -del /f $(MINIPERL) $(PERLEXE) $(PERLDLL) $(GLOBEXE) \ @@ -431,6 +433,9 @@ distclean: clean $(DYNALOADER).c -del /f $(PODDIR)\*.html -del /f $(PODDIR)\*.bat + -del /f ..\config.sh ..\splittree.pl perlmain.c dlutils.c \ + config.h.new perl95.c + -del /f bin\*.bat -rmdir /s /q ..\lib\auto -rmdir /s /q ..\lib\CORE cd $(EXTDIR) @@ -443,9 +448,8 @@ install : all doc utils $(XCOPY) $(PERLEXE) $(INST_BIN)\*.* $(XCOPY) $(PERL95EXE) $(INST_BIN)\*.* $(XCOPY) $(GLOBEXE) $(INST_BIN)\*.* - $(XCOPY) $(GLOBBAT) $(INST_BIN)\*.* $(XCOPY) $(PERLDLL) $(INST_BIN)\*.* - $(XCOPY) bin\*.* $(INST_BIN)\*.* + $(XCOPY) bin\*.bat $(INST_BIN)\*.* $(RCOPY) ..\lib $(INST_LIB)\*.* $(XCOPY) ..\pod\*.bat $(INST_BIN)\*.* $(XCOPY) ..\pod\*.pod $(INST_POD)\*.* @@ -486,7 +490,8 @@ clean : -@erase $(CORE_OBJ) -@erase $(WIN32_OBJ) -@erase $(DLL_OBJ) - -@erase ..\*.obj *.obj ..\*.lib ..\*.exp + -@erase ..\*.obj ..\*.lib ..\*.exp *.obj *.lib *.exp + -@erase ..\t\*.exe ..\t\*.dll ..\t\*.bat -@erase *.ilk -@erase *.pdb diff --git a/win32/bin/pl2bat.bat b/win32/bin/pl2bat.bat deleted file mode 100644 index 0b7bf32..0000000 --- a/win32/bin/pl2bat.bat +++ /dev/null @@ -1,103 +0,0 @@ -@rem = '--*-Perl-*-- -@echo off -perl -x -S %0 %* -goto endofperl -@rem '; -#!perl -w -#line 8 -(my $head = <<'--end--') =~ s/^\t//gm; - @rem = '--*-Perl-*-- - @echo off - perl -x -S %0 %* - goto endofperl - @rem '; ---end-- -my $headlines = 2 + ($head =~ tr/\n/\n/); -my $tail = "__END__\n:endofperl\n"; - -@ARGV = ('-') unless @ARGV; - -process(@ARGV); - -sub process { - LOOP: - foreach ( @_ ) { - my $myhead = $head; - my $linedone = 0; - my $linenum = $headlines; - my $line; - open( FILE, $_ ) or die "Can't open $_: $!"; - @file = ; - foreach $line ( @file ) { - $linenum++; - if ( $line =~ /^:endofperl/) { - warn "$_ has already been converted to a batch file!\n"; - next LOOP; - } - if ( not $linedone and $line =~ /^#!.*perl/ ) { - $line .= "#line $linenum\n"; - $linedone++; - } - } - close( FILE ); - s/\.pl$//; - $_ .= '.bat' unless /\.bat$/ or /^-$/; - open( FILE, ">$_" ) or die "Can't open $_: $!"; - print FILE $myhead; - print FILE "#!perl\n#line " . ($headlines+1) . "\n" unless $linedone; - print FILE @file, $tail; - close( FILE ); - } -} -__END__ - -=head1 NAME - -pl2bat.bat - a batch file to wrap perl code into a batch file - -=head1 SYNOPSIS - - C:\> pl2bat foo.pl bar - [..creates foo.bat, bar.bat..] - - C:\> pl2bat < somefile > another.bat - - C:\> pl2bat > another.bat - print scalar reverse "rekcah lrep rehtona tsuj\n"; - ^Z - [..another.bat is now a certified japh application..] - -=head1 DESCRIPTION - -This utility converts a perl script into a batch file that can be -executed on DOS-like operating systems. - -Note that the ".pl" suffix will be stripped before adding a -".bat" suffix to the supplied file names. - -The batch file created makes use of the C<%*> construct to refer -to all the command line arguments that were given to the batch file, -so you'll need to make sure that works on your variant of the -command shell. It is known to work in the cmd.exe shell under -WindowsNT. 4DOS/NT users will want to put a C -line in their initialization file, or execute C in -the shell startup file. - -=head1 BUGS - -C<$0> will contain the full name, including the ".bat" suffix. -If you don't like this, see runperl.bat for an alternative way to -invoke perl scripts. - -Perl is invoked with the -S flag, so it will search the PATH to find -the script. This may have undesirable effects. - -=head1 SEE ALSO - -perl, perlwin32, runperl.bat - -=cut - -__END__ -:endofperl - diff --git a/win32/bin/pl2bat.pl b/win32/bin/pl2bat.pl new file mode 100644 index 0000000..73ae871 --- /dev/null +++ b/win32/bin/pl2bat.pl @@ -0,0 +1,154 @@ +#!perl -w +require 5; +use Getopt::Std; + +$0 =~ s|.*[/\\]||; + +my $usage = <; + foreach $line ( @file ) { + $linenum++; + if ( $line =~ /^:endofperl/) { + warn "$0: $_ has already been converted to a batch file!\n"; + next LOOP; + } + if ( not $linedone and $line =~ /^#!.*perl/ ) { + $line .= "#line $linenum\n"; + $linedone++; + } + } + close( FILE ); + s/$OPT{'s'}$//oi; + $_ .= '.bat' unless /\.bat$/i or /^-$/; + open( FILE, ">$_" ) or die "Can't open $_: $!"; + print FILE $myhead; + print FILE "#!perl\n#line " . ($headlines+1) . "\n" unless $linedone; + print FILE @file, $tail; + close( FILE ); + } +} +__END__ + +=head1 NAME + +pl2bat - wrap perl code into a batch file + +=head1 SYNOPSIS + +B [B<-h>] S<[B<-a> I]> S<[B<-s> I]> [files] + +=head1 DESCRIPTION + +This utility converts a perl script into a batch file that can be +executed on DOS-like operating systems. + +Note that by default, the ".pl" suffix will be stripped before adding +a ".bat" suffix to the supplied file names. This can be controlled +with the C<-s> option. + +The default behavior on WindowsNT is to generate a batch file that +uses the C<%*> construct to refer to all the command line arguments +that were given to it, so you'll need to make sure that works on your +variant of the command shell. It is known to work in the cmd.exe shell +under WindowsNT. 4DOS/NT users will want to put a C +line in their initialization file, or execute C in +the shell startup file. On Windows95 and other platforms a nine +argument limit is imposed on command-line arguments given to the +generated batch file, since they may not support C<%*> in batch files. +This can be overridden using the C<-a> option. + +=head1 OPTIONS + +=over 8 + +=item B<-a> I + +Arguments to invoke perl with in generated batch file. Defaults to +S<"-x -S %0 %*"> on WindowsNT, S<"-x -S %0 %1 %2 %3 %4 %5 %6 %7 %8 %9"> +on other platforms. + +=item B<-s> I + +Strip a suffix string from file name before appending a ".bat" +suffix. The suffix is not case-sensitive. It can be a regex if it +begins with `/' (the trailing '/' being optional. Defaults to ".pl". + +=item B<-h> + +Show command line usage. + +=back + +=head1 EXAMPLES + + C:\> pl2bat foo.pl bar.PM + [..creates foo.bat, bar.PM.bat..] + + C:\> pl2bat -s "/\.pl|\.pm/" foo.pl bar.PM + [..creates foo.bat, bar.bat..] + + C:\> pl2bat < somefile > another.bat + + C:\> pl2bat > another.bat + print scalar reverse "rekcah lrep rehtona tsuj\n"; + ^Z + [..another.bat is now a certified japh application..] + +=head1 BUGS + +C<$0> will contain the full name, including the ".bat" suffix +when the generated batch file runs. If you don't like this, +see runperl.bat for an alternative way to invoke perl scripts. + +Default behavior is to invoke Perl with the -S flag, so Perl will +search the PATH to find the script. This may have undesirable +effects. + +=head1 SEE ALSO + +perl, perlwin32, runperl.bat + +=cut + diff --git a/win32/bin/runperl.bat b/win32/bin/runperl.pl similarity index 92% rename from win32/bin/runperl.bat rename to win32/bin/runperl.pl index cca69e8..95b33f9 100644 --- a/win32/bin/runperl.bat +++ b/win32/bin/runperl.pl @@ -1,10 +1,4 @@ -@rem = '--*-Perl-*-- -@echo off -perl -x -S %0 %* -goto endofperl -@rem '; #!perl -w -#line 8 $0 =~ s|\.bat||i; unless (-f $0) { $0 =~ s|.*[/\\]||; @@ -20,7 +14,7 @@ __END__ =head1 NAME -runperl.bat - an "universal" batch file to run perl scripts +runperl.bat - "universal" batch file to run perl scripts =head1 SYNOPSIS @@ -71,6 +65,3 @@ perl, perlwin32, pl2bat.bat =cut -__END__ -:endofperl - diff --git a/win32/bin/search.bat b/win32/bin/search.pl similarity index 99% rename from win32/bin/search.bat rename to win32/bin/search.pl index 88e83e5..b63f735 100644 --- a/win32/bin/search.bat +++ b/win32/bin/search.pl @@ -1,9 +1,3 @@ -@rem = '--*-Perl-*--'; -@rem = ' -@echo off -perl -S %0.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 -goto endofperl -@rem '; #!/usr/local/bin/perl -w 'di'; 'ig00'; @@ -1869,5 +1863,3 @@ http://www.wg.omron.co.jp/cgi-bin/j-e/jfriedl.html .SH "LATEST SOURCE" See http://www.wg.omron.co.jp/~jfriedl/perl/index.html -__END__ -:endofperl diff --git a/win32/bin/test.bat b/win32/bin/test.bat deleted file mode 100644 index e6b7b38..0000000 --- a/win32/bin/test.bat +++ /dev/null @@ -1,143 +0,0 @@ -@rem = ' -@echo off -if exist perl.exe goto perlhere -echo Cannot run without perl.exe in current directory!! Did you build it? -pause -goto endofperl -:perlhere -if exist perlglob.exe goto perlglobhere -echo Cannot run without perlglob.exe in current directory!! Did you build it? -pause -goto endofperl -:perlglobhere -perl %0.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 -goto endofperl -@rem '; - -#Portions (C) 1995 Microsoft Corporation. All rights reserved. -# Developed by hip communications inc., http://info.hip.com/info/ - - -# This is written in a peculiar style, since we're trying to avoid -# most of the constructs we'll be testing for. - -$| = 1; - -if ($ARGV[0] eq '-v') { - $verbose = 1; - shift; -} - - -# WYT 1995-05-02 -chdir 't' if -f 't/TESTNT'; - - -if ($ARGV[0] eq '') { -# @ARGV = split(/[ \n]/, -# `echo base/*.t comp/*.t cmd/*.t io/*.t; echo op/*.t lib/*.t`); -# `ls base/*.t comp/*.t cmd/*.t io/*.t op/*.t lib/*.t`); - -# WYT 1995-05-02 wildcard expansion, -# `perl -e "print( join( ' ', \@ARGV ) )" base/*.t comp/*.t cmd/*.t io/*.t op/*.t lib/*.t nt/*.t`); - -# WYT 1995-06-01 removed all dependency on perlglob -# WYT 1995-11-28 hacked up to cope with braindead Win95 console. - push( @ARGV, `dir/s/b base` ); - push( @ARGV, `dir/s/b comp` ); - push( @ARGV, `dir/s/b cmd` ); - push( @ARGV, `dir/s/b io` ); - push( @ARGV, `dir/s/b op` ); - push( @ARGV, `dir/s/b lib` ); - push( @ARGV, `dir/s/b nt` ); - - grep( chomp, @ARGV ); - @ARGV = grep( /\.t$/, @ARGV ); - grep( s/.*t\\//, @ARGV ); -} - -$sharpbang = 0; - -$bad = 0; -$good = 0; -$total = @ARGV; -while ($test = shift) { - if ($test =~ /^$/) { - next; - } - $te = $test; -# chop off 't' extension - chop($te); - print "$te" . '.' x (15 - length($te)); - if ($sharpbang) { - open(results,"./$test |") || (print "can't run.\n"); - } else { - $switch = ''; -# open(results,"./perl$switch $test |") || (print "can't run.\n"); - open(results,"perl$switch $test |") || (print "can't run.\n"); - } - $ok = 0; - $next = 0; - while () { - if ($verbose) { - print $_; - } - unless (/^#/||/^$/) { - if (/^1\.\.([0-9]+)/) { - $max = $1; - $totmax += $max; - $files += 1; - $next = 1; - $ok = 1; - } else { - $next = $1, $ok = 0, last if /^not ok ([0-9]*)/; - if (/^ok (.*)/ && $1 == $next) { - $next = $next + 1; - } else { - $ok = 0; - } - } - } - } - $next = $next - 1; - if ($ok && $next == $max) { - print "ok\n"; - $good = $good + 1; - } else { - $next += 1; - print "FAILED on test $next\n"; - $bad = $bad + 1; - $_ = $test; - if (/^base/) { - die "Failed a basic test--cannot continue.\n"; - } - } -} - -if ($bad == 0) { - if ($ok) { - print "All tests successful.\n"; - } else { - die "FAILED--no tests were run for some reason.\n"; - } -} else { - $pct = sprintf("%.2f", $good / $total * 100); - if ($bad == 1) { - warn "Failed 1 test, $pct% okay.\n"; - } else { - die "Failed $bad/$total tests, $pct% okay.\n"; - } -} - - -# WYT 1995-05-03 times not implemented. -#($user,$sys,$cuser,$csys) = times; -#print sprintf("u=%g s=%g cu=%g cs=%g files=%d tests=%d\n", -# $user,$sys,$cuser,$csys,$files,$totmax); - -#`del /f Cmd_while.tmp Comp.try null 2>NULL`; - -unlink 'Cmd_while.tmp', 'Comp.try', 'null'; - -__END__ -:endofperl diff --git a/win32/bin/webget.bat b/win32/bin/webget.pl similarity index 99% rename from win32/bin/webget.bat rename to win32/bin/webget.pl index e77bb88..3d72208 100644 --- a/win32/bin/webget.bat +++ b/win32/bin/webget.pl @@ -1,9 +1,3 @@ -@rem = '--*-Perl-*--'; -@rem = ' -@echo off -perl -S %0.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 -goto endofperl -@rem '; #!/usr/local/bin/perl -w #- @@ -1095,5 +1089,3 @@ sub dummy { } __END__ -__END__ -:endofperl diff --git a/win32/makefile.mk b/win32/makefile.mk index 62b2b11..4696dcb 100644 --- a/win32/makefile.mk +++ b/win32/makefile.mk @@ -176,8 +176,8 @@ GLOBEXE=..\perlglob.exe CONFIGPM=..\lib\Config.pm MINIMOD=..\lib\ExtUtils\Miniperl.pm -PL2BAT=bin\PL2BAT.BAT -GLOBBAT = perlglob.bat +PL2BAT=bin\pl2bat.pl +GLOBBAT = bin\perlglob.bat .IF "$(CCTYPE)" == "BORLAND" @@ -350,8 +350,8 @@ $(GLOBEXE): perlglob.obj $(LINK32) $(LINK_FLAGS) -out:$@ -subsystem:$(SUBSYS) perlglob.obj setargv.obj .ENDIF -perlglob.bat : ..\lib\File\DosGlob.pm $(MINIPERL) - $(MINIPERL) $(PL2BAT) - < ..\lib\File\DosGlob.pm > $(*B).bat +$(GLOBBAT) : ..\lib\File\DosGlob.pm $(MINIPERL) + $(MINIPERL) $(PL2BAT) - < ..\lib\File\DosGlob.pm > $(GLOBBAT) perlglob.obj : perlglob.c @@ -510,7 +510,9 @@ utils: $(PERLEXE) cd ..\utils && $(MAKE) PERL=$(MINIPERL) cd ..\utils && $(PERLEXE) ..\win32\$(PL2BAT) h2ph splain perlbug \ pl2pm c2ph h2xs perldoc pstruct - cd ..\utils && $(XCOPY) *.bat ..\win32\bin\*.* + $(XCOPY) ..\utils\*.bat bin\*.* + $(PERLEXE) $(PL2BAT) bin\network.pl bin\www.pl bin\runperl.pl \ + bin\pl2bat.pl distclean: clean -del /f $(MINIPERL) $(PERLEXE) $(PERLDLL) $(GLOBEXE) \ @@ -522,6 +524,11 @@ distclean: clean $(DYNALOADER).c -del /f $(PODDIR)\*.html -del /f $(PODDIR)\*.bat + -del /f ..\config.sh ..\splittree.pl perlmain.c dlutils.c config.h.new +.IF "$(PERL95EXE)" != "" + -del /f perl95.c +.ENDIF + -del /f bin\*.bat -cd $(EXTDIR) && del /s *.lib *.def *.map *.bs Makefile *.obj pm_to_blib -rmdir /s /q ..\lib\auto -rmdir /s /q ..\lib\CORE @@ -534,9 +541,8 @@ install : all doc utils $(XCOPY) $(PERL95EXE) $(INST_BIN)\*.* .ENDIF $(XCOPY) $(GLOBEXE) $(INST_BIN)\*.* - $(XCOPY) $(GLOBBAT) $(INST_BIN)\*.* $(XCOPY) $(PERLDLL) $(INST_BIN)\*.* - $(XCOPY) bin\*.* $(INST_BIN)\*.* + $(XCOPY) bin\*.bat $(INST_BIN)\*.* $(RCOPY) ..\lib $(INST_LIB)\*.* $(XCOPY) ..\pod\*.bat $(INST_BIN)\*.* $(XCOPY) ..\pod\*.pod $(INST_POD)\*.* @@ -582,7 +588,8 @@ clean : -@erase $(CORE_OBJ) -@erase $(WIN32_OBJ) -@erase $(DLL_OBJ) - -@erase ..\*.obj *.obj ..\*.lib ..\*.exp + -@erase ..\*.obj ..\*.lib ..\*.exp *.obj *.lib *.exp + -@erase ..\t\*.exe ..\t\*.dll ..\t\*.bat -@erase *.ilk -@erase *.pdb