From 759d3185adcd933a5ddadb509e27cc01362f38c2 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 28 Jan 2004 21:21:48 +0000 Subject: [PATCH] Use strict & warnings. Fix several minor bugs uncovered by it. Semantics of assigning to $[ changed in Perl 5, and its use is `highly discouraged'. Programs obviously assumed $[ affects all arrays, but it doesn't in Perl 5. If these programs ever worked, then certainly not with Perl 5. Remove the assignments and shift indexes accordingly. --- info/checklist.pl | 9 ++++++-- info/emp2html.pl | 46 +++++++++++++++++++------------------- info/info.pl | 18 ++++++++++----- info/ls2html.pl | 3 +++ info/subj2html.pl | 56 ++++++++++++++++++++++++----------------------- 5 files changed, 76 insertions(+), 56 deletions(-) diff --git a/info/checklist.pl b/info/checklist.pl index 7a2471dcb..279f17f0e 100644 --- a/info/checklist.pl +++ b/info/checklist.pl @@ -11,6 +11,11 @@ # to check which Empire commands need to be documented. # +use strict; +use warnings; + +my ($com, @list, @obsolete, @Commands); + open(LIST, ") { @@ -60,10 +65,10 @@ while () { close LS; print "In list but not Commands:\n"; -for $l (@list) { +for my $l (@list) { print " $l\n" unless grep (/^$l$/, @Commands); } print "In Commands but not list:\n"; -for $c (@Commands) { +for my $c (@Commands) { print " $c\n" unless grep(/^$c$/, @list) || grep(/^$c$/, @obsolete); } diff --git a/info/emp2html.pl b/info/emp2html.pl index 249c4180f..fa65ab883 100644 --- a/info/emp2html.pl +++ b/info/emp2html.pl @@ -1,7 +1,9 @@ #!/usr/local/bin/perl +use strict; +use warnings; -$[ = 1; # set array base to 1 +my (@Fld, $str, @a); line: while (<>) { chop; # strip record separator @@ -9,17 +11,17 @@ line: while (<>) { procline: if (/^\.TH/) { - $str=$Fld[3]; - for ($i=4;$i <= $#Fld; $i++) { + $str=$Fld[2]; + for (my $i=3; $i <= $#Fld; $i++) { $str .= " " . $Fld[$i]; } $str = &htmlify($str); printf("%s : %s

%s : %s

\n", - $Fld[2],$str,$Fld[2], $str); + $Fld[1], $str, $Fld[1], $str); next line; } - if (/^\.SY/) { + if (/^\.SY../) { # $i = $_ =~ "\"" && ($RLENGTH = length($&), $RSTART = length($`)+1); # $str = substr($_, $i + 1, length($_) - $i - 1); $str = substr($_,5); @@ -28,13 +30,13 @@ procline: next line; } - if (/^\.EX/) { + if (/^\.EX../) { $str = substr($_, 5); printf "
[##:##] %s

\n", &htmlify($str); next line; } - if (/^\.L/) { + if (/^\.L../) { $str = substr($_, 4); printf "

%s

\n", &htmlify($str); next line; @@ -48,8 +50,8 @@ procline: if (/^\.SA/) { @a = split('[: ",.]+'); - printf("See also : %s\n",&anchor($a[3]) ); - for ($i = 4; $i <= $#a ; ($i)++) { + printf("See also : %s\n",&anchor($a[2]) ); + for (my $i = 3; $i <= $#a ; ($i)++) { printf(", %s\n",&anchor($a[$i])); } @@ -58,7 +60,7 @@ procline: @a = split('[: ,.]+'); @Fld = split(' ', $_, 9999); if (/^\./) { goto procline; } - for ($i = 1; $i <= $#a ; ($i)++) { + for (my $i = 0; $i <= $#a ; ($i)++) { printf(", %s\n",&anchor($a[$i])); } } @@ -71,8 +73,8 @@ procline: if (/^(See also|See Also|see also)/) { @a = split('[: ,.]+'); - printf("See also : %s\n",&anchor($a[3]) ); - for ($i = 4; $i <= $#a ; ($i)++) { + printf("See also : %s\n",&anchor($a[2]) ); + for (my $i = 3; $i <= $#a ; ($i)++) { printf(", %s\n",&anchor($a[$i])); } @@ -81,7 +83,7 @@ procline: @a = split('[: ,.]+'); @Fld = split(' ', $_, 9999); if (/^\./) { goto procline; } - for ($i = 1; $i <= $#a ; ($i)++) { + for (my $i = 0; $i <= $#a ; ($i)++) { printf(", %s\n",&anchor($a[$i])); } } @@ -103,8 +105,8 @@ procline: #} sub anchor { - local($_) = @_; - local(@file,$file); + local ($_) = @_; + my (@file,$file); $file = $_ . ".t"; # if (-r $file) { if (1) { @@ -113,9 +115,9 @@ sub anchor { } else { @file = <$_*t>; if (@file) { - warn "Expanding $_ to $file[$[]\n"; - $file[$[] =~ s/.t$/.html/; - return ("$_"); + warn "Expanding $_ to $file[0]\n"; + $file[0] =~ s/.t$/.html/; + return ("$_"); } else { warn "Unable to link $_\n"; return ( "$_"); @@ -126,7 +128,7 @@ sub anchor { # Translate HTML special characters into escape sequences sub htmlify { - local($_) = @_; + local ($_) = @_; s/^\"(.*)\"$/$1/; s/\\&//g; # a nothing character s/\&/&/g; @@ -134,15 +136,15 @@ sub htmlify { s/\>/>/g; while (@a = /(\\\*Q)([A-Za-z0-9\-\.]+)(\\\*U)/) { /(\\\*Q)([A-Za-z\-]+)(\\\*U)/; - $_ = $` . &anchor($a[2]) . $'; + $_ = $` . &anchor($a[1]) . $'; } while (@a = /(\\\*Q)(\"info )([A-Za-z0-9\-\.]+)(\\\*U)/) { /(\\\*Q)(\"info )([\w\-\.]+)(\\\*U)/; - $_ = $` . "\"info " . &anchor($a[3]) . $'; + $_ = $` . "\"info " . &anchor($a[2]) . $'; } while (@a = /(\"info )([A-Za-z0-9\-\.]+)/) { /(\"info )([\w\-\.]+)/; - $_ = $` . "\"info " . &anchor($a[2]) . $'; + $_ = $` . "\"info " . &anchor($a[1]) . $'; } s/\\\*Q//g; s/\\\*U/<\/em>/g; diff --git a/info/info.pl b/info/info.pl index 91610cd80..96e1596bc 100644 --- a/info/info.pl +++ b/info/info.pl @@ -84,6 +84,12 @@ # flush_subj Print a row of Subjects to TOP # error Print an integrity error to STDERR and exit with code 1. +use strict; +use warnings; + +our (@dirs, $dir, $filename, %filedir, @Subjects, $type, %desc, %level); +our (%see_also, %subject, %largest, $subj, @rowsubj, @colsubj, @subj); + eval("require 5"); # Test for perl version 5 die "info.pl requires version 5 of perl.\n" if $@; @@ -208,9 +214,9 @@ sub parse_file { # Create %subject from %see_also sub parse_see_also { - local (@see_also) = split(/, /, $see_also{$filename}); + my (@see_also) = split(/, /, $see_also{$filename}); local ($dir) = $filedir{$filename}; - local ($found); # Does this item belong to any Subject? + my ($found); # Does this item belong to any Subject? for (@see_also) { if (!(defined $filedir{$_})) { # is this entry a subject? @@ -225,6 +231,7 @@ sub parse_see_also { # Add a new entry to %subject and possibly to %largest sub set_subject { $subject{$_}{$dir} .= "$filename\n"; + $largest{$_} = "" unless defined $largest{$_}; $largest{$_} = $filename if length $filename > length $largest{$_}; $largest{$_} = $dir if length $dir > length $largest{$_}; } @@ -283,8 +290,9 @@ EOF $subj eq 'TOP' || grep (/^$subj$/, @rowsubj); } - for $i (0..2) { - for ($j = $i; $j <= $#rowsubj; $j += 3) { + my $k = 0; + for my $i (0..2) { + for (my $j = $i; $j <= $#rowsubj; $j += 3) { $colsubj[$j] = $rowsubj[$k++]; } } @@ -316,7 +324,7 @@ sub flush_subj { # Print an integrity error message and exit with code 1 sub error { - local ($error) = @_; + my ($error) = @_; print STDERR "Error on line $. of $filedir{$filename}/$filename.t:\n"; print STDERR "$_"; diff --git a/info/ls2html.pl b/info/ls2html.pl index 6a5be1b6b..611e44797 100644 --- a/info/ls2html.pl +++ b/info/ls2html.pl @@ -1,5 +1,8 @@ #!/usr/local/bin/perl +use strict; +use warnings; + printf("
\n");
 while (<>) {
     s/([\w\.\-]+)\.html/$1<\/a>/g;
diff --git a/info/subj2html.pl b/info/subj2html.pl
index 034e09ef2..234ecd10a 100644
--- a/info/subj2html.pl
+++ b/info/subj2html.pl
@@ -1,8 +1,10 @@
 #!/usr/local/bin/perl
 
+use strict;
+use warnings;
 
-$[ = 1;			# set array base to 1
-$dome = 0;
+my $dome = 0;
+my (@Fld, $str, @a);
 
 line: while (<>) {
     chop;	# strip record separator
@@ -10,17 +12,17 @@ line: while (<>) {
 
 procline:
     if (/^\.TH/) {
-	$str=$Fld[3];
-	for ($i=4;$i <= $#Fld; $i++) {
+	$str=$Fld[2];
+	for (my $i=3; $i <= $#Fld; $i++) {
 	    $str .= " " . $Fld[$i];
 	}
 	$str = &htmlify($str);
 	printf("%s : %s

%s : %s

\n", - $Fld[2],$str,$Fld[2], $str); + $Fld[1], $str, $Fld[1], $str); next line; } - if (/^\.SY/) { + if (/^\.SY../) { # $i = $_ =~ "\"" && ($RLENGTH = length($&), $RSTART = length($`)+1); # $str = substr($_, $i + 1, length($_) - $i - 1); $str = substr($_,5); @@ -29,7 +31,7 @@ procline: next line; } - if (/^\.EX/) { + if (/^\.EX../) { $str = substr($_, 5); printf "
[##:##] %s

\n", &htmlify($str); next line; @@ -37,8 +39,8 @@ procline: if (/^\.L/) { @a = split('[: ",.]+'); - $str = &anchor($a[3]); - $str = ("$str $a[4]"); + $str = &anchor($a[2]); + $str = ("$str $a[3]") if defined $a[3]; printf("
%s\n", $str); next line; } @@ -53,9 +55,9 @@ procline: if ($dome == 1) { @a = split('[: ",.]+'); - for ($i = 2; $i <= $#a ; ($i)++) { + for (my $i = 1; $i <= $#a ; ($i)++) { printf("%s",&anchor($a[$i])); - for ($j = 0; $j < 20 - length($a[$i]); $j++) { + for (my $j = 0; $j < 20 - length($a[$i]); $j++) { printf(" "); } } @@ -65,9 +67,9 @@ procline: @a = split('[: ,.]+'); @Fld = split(' ', $_, 9999); if (/^\./) { goto procline; } - for ($i = 2; $i <= $#a ; ($i)++) { + for (my $i = 1; $i <= $#a ; ($i)++) { printf("%s",&anchor($a[$i])); - for ($j = 0; $j < 20 - length($a[$i]); $j++) { + for (my $j = 0; $j < 20 - length($a[$i]); $j++) { printf(" "); } } @@ -79,8 +81,8 @@ procline: if (/^\.SA/) { @a = split('[: ",.]+'); - printf("See also : %s\n",&anchor($a[3]) ); - for ($i = 4; $i <= $#a ; ($i)++) { + printf("See also : %s\n",&anchor($a[2]) ); + for (my $i = 3; $i <= $#a ; ($i)++) { printf(", %s\n",&anchor($a[$i])); } @@ -89,7 +91,7 @@ procline: @a = split('[: ,.]+'); @Fld = split(' ', $_, 9999); if (/^\./) { goto procline; } - for ($i = 1; $i <= $#a ; ($i)++) { + for (my $i = 0; $i <= $#a ; ($i)++) { printf(", %s\n",&anchor($a[$i])); } } @@ -102,8 +104,8 @@ procline: if (/^(See also|See Also|see also)/) { @a = split('[: ,.]+'); - printf("See also : %s\n",&anchor($a[3]) ); - for ($i = 4; $i <= $#a ; ($i)++) { + printf("See also : %s\n",&anchor($a[2]) ); + for (my $i = 3; $i <= $#a ; ($i)++) { printf(", %s\n",&anchor($a[$i])); } @@ -112,7 +114,7 @@ procline: @a = split('[: ,.]+'); @Fld = split(' ', $_, 9999); if (/^\./) { goto procline; } - for ($i = 1; $i <= $#a ; ($i)++) { + for (my $i = 0; $i <= $#a ; ($i)++) { printf(", %s\n",&anchor($a[$i])); } } @@ -134,8 +136,8 @@ procline: #} sub anchor { - local($_) = @_; - local(@file,$file); + local ($_) = @_; + my (@file, $file); $file = $_ . ".t"; # if (-r $file) { if (1) { @@ -144,9 +146,9 @@ sub anchor { } else { @file = <$_*t>; if (@file) { - warn "Expanding $_ to $file[$[]\n"; - $file[$[] =~ s/.t$/.html/; - return ("
$_"); + warn "Expanding $_ to $file[0]\n"; + $file[0] =~ s/.t$/.html/; + return ("$_"); } else { warn "Unable to link $_\n"; return ( "$_"); @@ -165,15 +167,15 @@ sub htmlify { s/\>/>/g; while (@a = /(\\\*Q)([A-Za-z0-9\-\.]+)(\\\*U)/) { /(\\\*Q)([A-Za-z\-]+)(\\\*U)/; - $_ = $` . &anchor($a[2]) . $'; + $_ = $` . &anchor($a[1]) . $'; } while (@a = /(\\\*Q)(\"info )([A-Za-z0-9\-\.]+)(\\\*U)/) { /(\\\*Q)(\"info )([\w\-\.]+)(\\\*U)/; - $_ = $` . "\"info " . &anchor($a[3]) . $'; + $_ = $` . "\"info " . &anchor($a[2]) . $'; } while (@a = /(\"info )([A-Za-z0-9\-\.]+)/) { /(\"info )([\w\-\.]+)/; - $_ = $` . "\"info " . &anchor($a[2]) . $'; + $_ = $` . "\"info " . &anchor($a[1]) . $'; } s/\\\*Q//g; s/\\\*U/<\/em>/g; -- 2.43.0