Commit | Line | Data |
---|---|---|
16d20bd9 AD |
1 | case $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 | ;; | |
13 | esac | |
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. | |
16 | case "$0" in | |
17 | */*) cd `expr X$0 : 'X\(.*\)/'` ;; | |
18 | esac | |
19 | echo "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 | ||
43 | perldoc - Look up Perl documentation in pod format. | |
44 | ||
45 | =head1 SYNOPSIS | |
46 | ||
47 | B<perldoc> [B<-h>] PageName|ModuleName | |
48 | ||
49 | =head1 DESCRIPTION | |
50 | ||
51 | I<perldoc> looks up a piece of documentation in .pod format that is | |
52 | embedded in the perl installation tree or in a perl script, and displays | |
53 | it via pod2man | nroff -man | $PAGER. This is primarily used for the | |
54 | documentation for the perl library modules. | |
55 | ||
56 | Your system may also have man pages installed for those modules, in | |
57 | which 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 | ||
65 | Prints out a brief help message. | |
66 | ||
67 | =item B<PageName|ModuleName> | |
68 | ||
69 | The item you want to look up. Nested modules (such as C<File::Basename>) | |
70 | are specified either as C<File::Basename> or C<File/Basename>. You | |
71 | may also give a descriptive name of a page, such as C<perlfunc>. | |
72 | ||
73 | =back | |
74 | ||
75 | =head1 ENVIRONMENT | |
76 | ||
77 | Any switches in the C<PERLDOC> environment variable will be used before the | |
78 | command line arguments. C<perldoc> also searches directories | |
79 | specified by the C<PERL5LIB> (or C<PERLLIB> if C<PERL5LIB> is not | |
80 | defined) and C<PATH> environment variables. | |
81 | (The latter is so that embedded pods for executables, such as | |
82 | C<perldoc> itself, are available.) | |
83 | ||
84 | =head1 AUTHOR | |
85 | ||
86 | Kenneth Albanowski <kjahds@kjahds.com> | |
87 | ||
88 | Minor updates by Andy Dougherty <doughera@lafcol.lafayette.edu> | |
89 | ||
90 | =head1 SEE ALSO | |
91 | ||
92 | =head1 DIAGNOSTICS | |
93 | ||
94 | =cut | |
95 | ||
96 | if(@ARGV<1) { | |
97 | die <<EOF; | |
98 | Usage: $0 [-h] PageName|ModuleName | |
99 | ||
100 | We suggest you use C<perldoc perldoc> to get aquainted | |
101 | with the system. | |
102 | EOF | |
103 | } | |
104 | ||
105 | use Getopt::Std; | |
106 | ||
107 | sub usage{ | |
108 | warn "@_\n" if @_; | |
109 | die <<EOF; | |
110 | perlman [-h] PageName|ModuleName... | |
111 | -h Display this help message. | |
112 | PageName|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 | ||
118 | Any switches in the PERLDOC environment variable will be used before the | |
119 | command line arguments. | |
120 | ||
121 | EOF | |
122 | } | |
123 | ||
124 | use Text::ParseWords; | |
125 | ||
126 | unshift(@ARGV,shellwords($ENV{"PERLDOC"})); | |
127 | ||
128 | getopts("h") || usage; | |
129 | ||
130 | usage if $opt_h; | |
131 | ||
132 | $index = $opt_i; | |
133 | @pages = @ARGV; | |
134 | ||
135 | sub 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 | ||
149 | sub 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 | ||
170 | foreach (@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 | ||
187 | if( ! -t STDOUT ) { $opt_f = 1 } | |
188 | ||
189 | $cmd = "pod2man - | nroff -man"; | |
190 | if( ! $opt_f ) { $filter = "|$ENV{PAGER}" }; | |
191 | ||
192 | open(OUT,"|$cmd$filter"); | |
193 | foreach (@found) { | |
194 | open(IN,"<$_"); | |
195 | print OUT while <IN>; | |
196 | close(IN); | |
197 | } | |
198 | close(OUT); | |
199 | !NO!SUBS! | |
200 | chmod 755 perldoc | |
201 | $eunicefix perldoc |