3 require 5.003; # keep this compatible, an old perl is all we may have before
8 require 'regen_lib.pl';
14 # See database of global and static function prototypes in embed.fnc
15 # This is used to generate prototype headers under various configurations,
16 # export symbols lists for different platforms, and macros to provide an
17 # implicit interpreter context argument.
20 open IN, "embed.fnc" or die $!;
22 # walk table providing an array of components in each line to
23 # subroutine, printing the result
26 seek IN, 0, 0; # so we may restart
40 @args = split /\s*\|\s*/, $_;
42 s/\b(NN|NULLOK)\b\s+//g for @args;
52 my $curheader = "Unknown section";
54 sub autodoc ($$) { # parse a file and extract documentation info
58 while (defined($in = <$fh>)) {
59 if ($in=~ /^=head1 (.*)/) {
64 if ($in =~ /^=for\s+apidoc\s+(.*?)\s*\n/) {
66 $proto = "||$proto" unless $proto =~ /\|/;
67 my($flags, $ret, $name, @args) = split /\|/, $proto;
70 while (defined($doc = <$fh>)) {
72 last DOC if $doc =~ /^=\w+/;
73 if ($doc =~ m:^\*/$:) {
74 warn "=cut missing? $file:$line:$doc";;
79 $docs = "\n$docs" if $docs and $docs !~ /^\n/;
82 $apidocs{$curheader}{$name} = [$flags, $docs, $ret, $file, @args];
85 $gutsdocs{$curheader}{$name} = [$flags, $docs, $ret, $file, @args];
89 $docfuncs{$name} = [$flags, $docs, $ret, $file, $curheader, @args];
92 if ($doc =~ /^=(?:for|head)/) {
97 warn "$file:$line:$in";
103 sub docout ($$$) { # output the docs for one function
104 my($fh, $name, $docref) = @_;
105 my($flags, $docs, $ret, $file, @args) = @$docref;
108 $docs .= "NOTE: this function is experimental and may change or be
109 removed without notice.\n\n" if $flags =~ /x/;
110 $docs .= "NOTE: the perl_ form of this function is deprecated.\n\n"
113 print $fh "=item $name\nX<$name>\n$docs";
115 if ($flags =~ /U/) { # no usage
117 } elsif ($flags =~ /s/) { # semicolon ("dTHR;")
118 print $fh "\t\t$name;\n\n";
119 } elsif ($flags =~ /n/) { # no args
120 print $fh "\t$ret\t$name\n\n";
121 } else { # full usage
122 print $fh "\t$ret\t$name";
123 print $fh "(" . join(", ", @args) . ")";
126 print $fh "=for hackers\nFound in file $file\n\n";
129 sub readonly_header (*) {
132 -*- buffer-read-only: t -*-
134 !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
135 This file is built by $0 extracting documentation from the C source
141 sub readonly_footer (*) {
151 # glob() picks up docs from extra .c or .h files that may be in unclean
155 open FH, "MANIFEST" or die "Can't open MANIFEST: $!";
159 for $file (($MANIFEST =~ /^(\S+\.c)\t/gm), ($MANIFEST =~ /^(\S+\.h)\t/gm)) {
160 open F, "< $file" or die "Cannot open $file for docs: $!\n";
161 $curheader = "Functions in file $file\n";
163 close F or die "Error closing $file: $!\n";
166 safer_unlink "pod/perlapi.pod";
167 my $doc = safer_open("pod/perlapi.pod");
169 walk_table { # load documented functions into appropriate hash
171 my($flags, $retval, $func, @args) = @_;
172 return "" unless $flags =~ /d/;
173 $func =~ s/\t//g; $flags =~ s/p//; # clean up fields from embed.pl
175 my $docref = delete $docfuncs{$func};
176 $seenfuncs{$func} = 1;
177 if ($docref and @$docref) {
179 $docref->[0].="x" if $flags =~ /M/;
180 $apidocs{$docref->[4]}{$func} =
181 [$docref->[0] . 'A', $docref->[1], $retval, $docref->[3],
184 $gutsdocs{$docref->[4]}{$func} =
185 [$docref->[0], $docref->[1], $retval, $docref->[3], @args];
189 warn "no docs for $func\n" unless $seenfuncs{$func};
194 for (sort keys %docfuncs) {
195 # Have you used a full for apidoc or just a func name?
196 # Have you used Ap instead of Am in the for apidoc?
197 warn "Unable to place $_!\n";
200 readonly_header($doc);
202 print $doc <<'_EOB_';
205 perlapi - autogenerated documentation for the perl public API
208 X<Perl API> X<API> X<api>
210 This file contains the documentation of the perl public API generated by
211 embed.pl, specifically a listing of functions, macros, flags, and variables
212 that may be used by extension writers. The interfaces of any functions that
213 are not listed here are subject to change without notice. For this reason,
214 blindly using functions listed in proto.h is to be avoided when writing
217 Note that all Perl API global variables must be referenced with the C<PL_>
218 prefix. Some macros are provided for compatibility with the older,
219 unadorned names, but this support may be disabled in a future release.
221 Perl was originally written to handle US-ASCII only (that is characters
222 whose ordinal numbers are in the range 0 - 127).
223 And documentation and comments may still use the term ASCII, when
224 sometimes in fact the entire range from 0 - 255 is meant.
226 Note that Perl can be compiled and run under EBCDIC (See L<perlebcdic>)
227 or ASCII. Most of the documentation (and even comments in the code)
228 ignore the EBCDIC possibility.
229 For almost all purposes the differences are transparent.
230 As an example, under EBCDIC,
231 instead of UTF-8, UTF-EBCDIC is used to encode Unicode strings, and so
232 whenever this documentation refers to C<utf8>
233 (and variants of that name, including in function names),
234 it also (essentially transparently) means C<UTF-EBCDIC>.
235 But the ordinals of characters differ between ASCII, EBCDIC, and
236 the UTF- encodings, and a string encoded in UTF-EBCDIC may occupy more bytes
239 Also, on some EBCDIC machines, functions that are documented as operating on
240 US-ASCII (or Basic Latin in Unicode terminology) may in fact operate on all
241 256 characters in the EBCDIC range, not just the subset corresponding to
244 The listing below is alphabetical, case insensitive.
249 # case insensitive sort, with fallback for determinacy
250 for $key (sort { uc($a) cmp uc($b) || $a cmp $b } keys %apidocs) {
251 my $section = $apidocs{$key};
252 print $doc "\n=head1 $key\n\n=over 8\n\n";
253 # Again, fallback for determinacy
254 for my $key (sort { uc($a) cmp uc($b) || $a cmp $b } keys %$section) {
255 docout($doc, $key, $section->{$key});
257 print $doc "\n=back\n";
260 print $doc <<'_EOE_';
264 Until May 1997, this document was maintained by Jeff Okamoto
265 <okamoto@corp.hp.com>. It is now maintained as part of Perl itself.
267 With lots of help and suggestions from Dean Roehrich, Malcolm Beattie,
268 Andreas Koenig, Paul Hudson, Ilya Zakharevich, Paul Marquess, Neil
269 Bowers, Matthew Green, Tim Bunce, Spider Boardman, Ulrich Pfeifer,
270 Stephen McCamant, and Gurusamy Sarathy.
272 API Listing originally by Dean Roehrich <roehrich@cray.com>.
274 Updated to be autogenerated from comments in the source by Benjamin Stuhl.
278 perlguts(1), perlxs(1), perlxstut(1), perlintern(1)
282 readonly_footer($doc);
286 safer_unlink "pod/perlintern.pod";
287 my $guts = safer_open("pod/perlintern.pod");
288 readonly_header($guts);
292 perlintern - autogenerated documentation of purely B<internal>
296 X<internal Perl functions> X<interpreter functions>
298 This file is the autogenerated documentation of functions in the
299 Perl interpreter that are documented using Perl's internal documentation
300 format but are not marked as part of the Perl API. In other words,
301 B<they are not for use in extensions>!
305 for $key (sort { uc($a) cmp uc($b); } keys %gutsdocs) {
306 my $section = $gutsdocs{$key};
307 print $guts "\n=head1 $key\n\n=over 8\n\n";
308 for my $key (sort { uc($a) cmp uc($b); } keys %$section) {
309 docout($guts, $key, $section->{$key});
311 print $guts "\n=back\n";
318 The autodocumentation system was originally added to the Perl core by
319 Benjamin Stuhl. Documentation is by whoever was kind enough to
320 document their functions.
324 perlguts(1), perlapi(1)
327 readonly_footer($guts);