6 # See database of global and static function prototypes in embed.fnc
7 # This is used to generate prototype headers under various configurations,
8 # export symbols lists for different platforms, and macros to provide an
9 # implicit interpreter context argument.
17 my $curheader = "Unknown section";
19 sub autodoc ($$) { # parse a file and extract documentation info
23 while (defined($in = <$fh>)) {
24 if ($in=~ /^=head1 (.*)/) {
29 if ($in =~ /^=for\s+apidoc\s+(.*?)\s*\n/) {
31 $proto = "||$proto" unless $proto =~ /\|/;
32 my($flags, $ret, $name, @args) = split /\|/, $proto;
35 while (defined($doc = <$fh>)) {
37 last DOC if $doc =~ /^=\w+/;
38 if ($doc =~ m:^\*/$:) {
39 warn "=cut missing? $file:$line:$doc";;
44 $docs = "\n$docs" if $docs and $docs !~ /^\n/;
47 $apidocs{$curheader}{$name} = [$flags, $docs, $ret, $file, @args];
50 $gutsdocs{$curheader}{$name} = [$flags, $docs, $ret, $file, @args];
54 $docfuncs{$name} = [$flags, $docs, $ret, $file, $curheader, @args];
57 if ($doc =~ /^=(?:for|head)/) {
62 warn "$file:$line:$in";
68 sub docout ($$$) { # output the docs for one function
69 my($fh, $name, $docref) = @_;
70 my($flags, $docs, $ret, $file, @args) = @$docref;
73 $docs .= "NOTE: this function is experimental and may change or be
74 removed without notice.\n\n" if $flags =~ /x/;
75 $docs .= "NOTE: the perl_ form of this function is deprecated.\n\n"
78 print $fh "=item $name\nX<$name>\n$docs";
80 if ($flags =~ /U/) { # no usage
82 } elsif ($flags =~ /s/) { # semicolon ("dTHR;")
83 print $fh "\t\t$name;\n\n";
84 } elsif ($flags =~ /n/) { # no args
85 print $fh "\t$ret\t$name\n\n";
87 print $fh "\t$ret\t$name";
88 print $fh "(" . join(", ", @args) . ")";
91 print $fh "=for hackers\nFound in file $file\n\n";
95 my ($podname, $header, $dochash, $footer) = @_;
96 my $filename = "pod/$podname.pod";
97 open my $fh, '>', $filename or die "Can't open $filename: $!";
99 print $fh <<"_EOH_", $header;
100 -*- buffer-read-only: t -*-
102 !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
103 This file is built by $0 extracting documentation from the C source
109 # case insensitive sort, with fallback for determinacy
110 for $key (sort { uc($a) cmp uc($b) || $a cmp $b } keys %$dochash) {
111 my $section = $dochash->{$key};
112 print $fh "\n=head1 $key\n\n=over 8\n\n";
113 # Again, fallback for determinacy
114 for my $key (sort { uc($a) cmp uc($b) || $a cmp $b } keys %$section) {
115 docout($fh, $key, $section->{$key});
117 print $fh "\n=back\n";
120 print $fh $footer, <<'_EOF_';
126 close $fh or die "Can't close $filename: $!";
132 or die "Couldn't chdir to '$workdir': $!";
136 # glob() picks up docs from extra .c or .h files that may be in unclean
140 open FH, "MANIFEST" or die "Can't open MANIFEST: $!";
144 for $file (($MANIFEST =~ /^(\S+\.c)\t/gm), ($MANIFEST =~ /^(\S+\.h)\t/gm)) {
145 open F, "< $file" or die "Cannot open $file for docs: $!\n";
146 $curheader = "Functions in file $file\n";
148 close F or die "Error closing $file: $!\n";
151 open IN, "embed.fnc" or die $!;
153 # walk table providing an array of components in each line to
154 # subroutine, printing the result
166 my ($flags, $retval, $func, @args) = split /\s*\|\s*/, $_;
168 next unless $flags =~ /d/;
171 s/\b(NN|NULLOK)\b\s+//g for @args;
172 $func =~ s/\t//g; # 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};
193 for (sort keys %docfuncs) {
194 # Have you used a full for apidoc or just a func name?
195 # Have you used Ap instead of Am in the for apidoc?
196 warn "Unable to place $_!\n";
199 output('perlapi', <<'_EOB_', \%apidocs, <<'_EOE_');
202 perlapi - autogenerated documentation for the perl public API
205 X<Perl API> X<API> X<api>
207 This file contains the documentation of the perl public API generated by
208 embed.pl, specifically a listing of functions, macros, flags, and variables
209 that may be used by extension writers. The interfaces of any functions that
210 are not listed here are subject to change without notice. For this reason,
211 blindly using functions listed in proto.h is to be avoided when writing
214 Note that all Perl API global variables must be referenced with the C<PL_>
215 prefix. Some macros are provided for compatibility with the older,
216 unadorned names, but this support may be disabled in a future release.
218 Perl was originally written to handle US-ASCII only (that is characters
219 whose ordinal numbers are in the range 0 - 127).
220 And documentation and comments may still use the term ASCII, when
221 sometimes in fact the entire range from 0 - 255 is meant.
223 Note that Perl can be compiled and run under EBCDIC (See L<perlebcdic>)
224 or ASCII. Most of the documentation (and even comments in the code)
225 ignore the EBCDIC possibility.
226 For almost all purposes the differences are transparent.
227 As an example, under EBCDIC,
228 instead of UTF-8, UTF-EBCDIC is used to encode Unicode strings, and so
229 whenever this documentation refers to C<utf8>
230 (and variants of that name, including in function names),
231 it also (essentially transparently) means C<UTF-EBCDIC>.
232 But the ordinals of characters differ between ASCII, EBCDIC, and
233 the UTF- encodings, and a string encoded in UTF-EBCDIC may occupy more bytes
236 Also, on some EBCDIC machines, functions that are documented as operating on
237 US-ASCII (or Basic Latin in Unicode terminology) may in fact operate on all
238 256 characters in the EBCDIC range, not just the subset corresponding to
241 The listing below is alphabetical, case insensitive.
247 Until May 1997, this document was maintained by Jeff Okamoto
248 <okamoto@corp.hp.com>. It is now maintained as part of Perl itself.
250 With lots of help and suggestions from Dean Roehrich, Malcolm Beattie,
251 Andreas Koenig, Paul Hudson, Ilya Zakharevich, Paul Marquess, Neil
252 Bowers, Matthew Green, Tim Bunce, Spider Boardman, Ulrich Pfeifer,
253 Stephen McCamant, and Gurusamy Sarathy.
255 API Listing originally by Dean Roehrich <roehrich@cray.com>.
257 Updated to be autogenerated from comments in the source by Benjamin Stuhl.
261 perlguts(1), perlxs(1), perlxstut(1), perlintern(1)
265 output('perlintern', <<'END', \%gutsdocs, <<'END');
268 perlintern - autogenerated documentation of purely B<internal>
272 X<internal Perl functions> X<interpreter functions>
274 This file is the autogenerated documentation of functions in the
275 Perl interpreter that are documented using Perl's internal documentation
276 format but are not marked as part of the Perl API. In other words,
277 B<they are not for use in extensions>!
283 The autodocumentation system was originally added to the Perl core by
284 Benjamin Stuhl. Documentation is by whoever was kind enough to
285 document their functions.
289 perlguts(1), perlapi(1)