worley@compass.com (Dale Worley) (03/27/91)
The following patch fixes three problems with the inctree program from
chapter 6 of The Book:
1) It adds a usage message.
2) Lines that found with -m and output are indented with -'s, so you
can tell which file they are from.
3) If the eval of $sub fails, it outputs the error message and stops.
Dale
Dale Worley Compass, Inc. worley@compass.com
--
Artificial intelligence has failed, but natural stupidity is still
going strong. -- John Pates
*** /usr/sysmgr/mcmullan/perl/book-examples/ch6/inctree Tue Jan 8 12:57:24 1991
--- /home/worley/bin/inctree Tue Mar 26 15:37:00 1991
***************
*** 10,15 ****
--- 10,29 ----
$shiftwidth = 4;
+ # Usage message
+
+ if ($#ARGV < $[) {
+ print STDERR <<EOF;
+ Usage: $0 [-Dsymbol] [-Idir] [-m/pat/] file ...
+
+ where: -Dsymbol #defines symbol
+ -Idir searches for #includes in dir
+ -m/pat/ prints lines matching Perl regexp /pat/
+ delimiter must be supplied, trailing i may be added
+ EOF
+ exit 1;
+ }
+
# Process switches.
while ($ARGV[0] =~ /^-/) {
***************
*** 36,45 ****
if (@pats) {
$sub = "sub pats {\n";
foreach $pat (@pats) {
! $sub .= " print '>>>>>>> ',\$_ if m$pat;\n";
}
$sub .= "}\n";
eval $sub;
++$pats;
}
--- 50,60 ----
if (@pats) {
$sub = "sub pats {\n";
foreach $pat (@pats) {
! $sub .= " print '-' x (\$indent - $shiftwidth), '>>>>>>> ', \$_ if m$pat;\n";
}
$sub .= "}\n";
eval $sub;
+ die "Error building search routine: $@" if $@;
++$pats;
}