This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
This is my patch patch.1j for perl5.001.
[perl5.git] / perldoc.SH
CommitLineData
16d20bd9
AD
1case $CONFIG in
2'')
3 if test -f config.sh; then TOP=.;
4 elif test -f ../config.sh; then TOP=..;
5 elif test -f ../../config.sh; then TOP=../..;
6 elif test -f ../../../config.sh; then TOP=../../..;
7 elif test -f ../../../../config.sh; then TOP=../../../..;
8 else
9 echo "Can't find config.sh."; exit 1
10 fi
11 . $TOP/config.sh
12 ;;
13esac
14: This forces SH files to create target in same directory as SH file.
15: This is so that make depend always knows where to find SH derivatives.
16case "$0" in
17*/*) cd `expr X$0 : 'X\(.*\)/'` ;;
18esac
19echo "Extracting perldoc (with variable substitutions)"
20$spitshell >perldoc <<!GROK!THIS!
c2960299 21#!$binexp/perl
16d20bd9
AD
22!GROK!THIS!
23
24$spitshell >>perldoc <<'!NO!SUBS!'
25
26#
27# Perldoc revision #1 -- look up a piece of documentation in .pod format that
28# is embedded in the perl installation tree.
29#
30# This is not to be confused with Tom Christianson's perlman, which is a
31# man replacement, written in perl. This perldoc is strictly for reading
32# the perl manuals, though it too is written in perl.
33#
34# Version 1.01: Tue May 30 14:47:34 EDT 1995
35# Andy Dougherty <doughera@lafcol.lafayette.edu>
36# -added pod documentation.
37# -added PATH searching.
38# -added searching pod/ subdirectory (mainly to pick up perlfunc.pod
39# and friends.
40
41=head1 NAME
42
43perldoc - Look up Perl documentation in pod format.
44
45=head1 SYNOPSIS
46
47B<perldoc> [B<-h>] PageName|ModuleName
48
49=head1 DESCRIPTION
50
51I<perldoc> looks up a piece of documentation in .pod format that is
52embedded in the perl installation tree or in a perl script, and displays
53it via pod2man | nroff -man | $PAGER. This is primarily used for the
54documentation for the perl library modules.
55
56Your system may also have man pages installed for those modules, in
57which case you can probably just use the man(1) command.
58
59=head1 OPTIONS
60
61=over 5
62
63=item B<-h> help
64
65Prints out a brief help message.
66
67=item B<PageName|ModuleName>
68
69The item you want to look up. Nested modules (such as C<File::Basename>)
70are specified either as C<File::Basename> or C<File/Basename>. You
71may also give a descriptive name of a page, such as C<perlfunc>.
72
73=back
74
75=head1 ENVIRONMENT
76
77Any switches in the C<PERLDOC> environment variable will be used before the
78command line arguments. C<perldoc> also searches directories
79specified by the C<PERL5LIB> (or C<PERLLIB> if C<PERL5LIB> is not
80defined) and C<PATH> environment variables.
81(The latter is so that embedded pods for executables, such as
82C<perldoc> itself, are available.)
83
84=head1 AUTHOR
85
86Kenneth Albanowski <kjahds@kjahds.com>
87
88Minor updates by Andy Dougherty <doughera@lafcol.lafayette.edu>
89
90=head1 SEE ALSO
91
92=head1 DIAGNOSTICS
93
94=cut
95
96if(@ARGV<1) {
97 die <<EOF;
98Usage: $0 [-h] PageName|ModuleName
99
100We suggest you use C<perldoc perldoc> to get aquainted
101with the system.
102EOF
103}
104
105use Getopt::Std;
106
107sub usage{
108 warn "@_\n" if @_;
109 die <<EOF;
110perlman [-h] PageName|ModuleName...
111 -h Display this help message.
112PageName|ModuleName...
113 is the name of a piece of documentation that you want to look at. You
114 may either give a descriptive name of the page (as in the case of
115 `perlfunc') or the name of a module, either like `Term::Info',
116 `Term/Info'.
117
118Any switches in the PERLDOC environment variable will be used before the
119command line arguments.
120
121EOF
122}
123
124use Text::ParseWords;
125
126unshift(@ARGV,shellwords($ENV{"PERLDOC"}));
127
128getopts("h") || usage;
129
130usage if $opt_h;
131
132$index = $opt_i;
133@pages = @ARGV;
134
135sub containspod {
136 my($file) = @_;
137 local($_);
138 open(TEST,"<$file");
139 while(<TEST>) {
140 if(/^=head/) {
141 close(TEST);
142 return 1;
143 }
144 }
145 close(TEST);
146 return 0;
147}
148
149sub searchfor {
150 my($s,@dirs) = @_;
151 $s =~ s!::!/!g;
c2960299 152 # printf STDERR "looking for $s in @dirs\n";
16d20bd9
AD
153
154 foreach $dir (@dirs) {
155 if( -f "$dir/$s.pod") { return "$dir/$s.pod" }
156 elsif( -f "$dir/$s.pm" and containspod("$dir/$s.pm"))
157 { return "$dir/$s.pm" }
158 elsif( -f "$dir/$s" and containspod("$dir/$s"))
159 { return "$dir/$s" }
160 elsif( -f "$dir/pod/$s.pod") { return "$dir/pod/$s.pod" }
161 elsif( -f "$dir/pod/$s" and containspod("$dir/pod/$s"))
162 { return "$dir/pod/$s" }
163 }
164 return ();
165}
166
167
168$ENV{PAGER} ||= "more";
169
170foreach (@pages) {
171 print STDERR "Searching for $_\n";
172 # We must look both in @INC for library modules and in PATH
173 # for executables, like h2xs or perldoc itself.
174 @searchdirs = @INC;
175 push(@searchdirs, split(':', $ENV{'PATH'}) );
176 @files= searchfor($_,@searchdirs);
177 if( @files ) {
178 print STDERR "Found as @files\n";
179 } else {
180 print STDERR "No documentation found for $_\n";
181 }
182 push(@found,@files);
183}
184
185$cmd=$filter="";
186
187if( ! -t STDOUT ) { $opt_f = 1 }
188
189$cmd = "pod2man - | nroff -man";
190if( ! $opt_f ) { $filter = "|$ENV{PAGER}" };
191
192open(OUT,"|$cmd$filter");
193foreach (@found) {
194 open(IN,"<$_");
195 print OUT while <IN>;
196 close(IN);
197}
198close(OUT);
199!NO!SUBS!
200chmod 755 perldoc
201$eunicefix perldoc