3 # Unconditionally regenerate:
8 # from information stored in
11 # plus all the .c and .h files listed in MANIFEST
13 # Has an optional arg, which is the directory to chdir to before reading
14 # MANIFEST and *.[ch].
16 # This script is normally invoked as part of 'make all', but is also
17 # called from from regen.pl.
22 # See database of global and static function prototypes in embed.fnc
23 # This is used to generate prototype headers under various configurations,
24 # export symbols lists for different platforms, and macros to provide an
25 # implicit interpreter context argument.
38 my $curheader = "Unknown section";
40 sub autodoc ($$) { # parse a file and extract documentation info
44 while (defined($in = <$fh>)) {
45 if ($in =~ /^#\s*define\s+([A-Za-z_][A-Za-z_0-9]+)\(/ &&
46 ($file ne 'embed.h' || $file ne 'proto.h')) {
50 if ($in=~ /^=head1 (.*)/) {
55 if ($in =~ /^=for\s+apidoc\s+(.*?)\s*\n/) {
57 $proto = "||$proto" unless $proto =~ /\|/;
58 my($flags, $ret, $name, @args) = split /\|/, $proto;
61 while (defined($doc = <$fh>)) {
63 last DOC if $doc =~ /^=\w+/;
64 if ($doc =~ m:^\*/$:) {
65 warn "=cut missing? $file:$line:$doc";;
70 $docs = "\n$docs" if $docs and $docs !~ /^\n/;
72 # Check the consistency of the flags
73 my ($embed_where, $inline_where);
74 my ($embed_may_change, $inline_may_change);
76 my $docref = delete $funcflags{$name};
77 if ($docref and %$docref) {
78 $embed_where = $docref->{flags} =~ /A/ ? 'api' : 'guts';
79 $embed_may_change = $docref->{flags} =~ /M/;
81 $missing{$name} = $file;
84 $inline_where = $flags =~ /A/ ? 'api' : 'guts';
85 $inline_may_change = $flags =~ /x/;
87 if (defined $embed_where && $inline_where ne $embed_where) {
88 warn "Function '$name' inconsistency: embed.fnc says $embed_where, Pod says $inline_where";
91 if (defined $embed_may_change
92 && $inline_may_change ne $embed_may_change) {
93 my $message = "Function '$name' inconsistency: ";
94 if ($embed_may_change) {
95 $message .= "embed.fnc says 'may change', Pod does not";
97 $message .= "Pod says 'may change', embed.fnc does not";
101 } elsif (!defined $embed_where) {
102 warn "Unable to place $name!\n";
105 $inline_where = $embed_where;
106 $flags .= 'x' if $embed_may_change;
107 @args = @{$docref->{args}};
108 $ret = $docref->{retval};
111 $docs{$inline_where}{$curheader}{$name}
112 = [$flags, $docs, $ret, $file, @args];
115 if ($doc =~ /^=(?:for|head)/) {
120 warn "$file:$line:$in";
126 sub docout ($$$) { # output the docs for one function
127 my($fh, $name, $docref) = @_;
128 my($flags, $docs, $ret, $file, @args) = @$docref;
131 $docs .= "NOTE: this function is experimental and may change or be
132 removed without notice.\n\n" if $flags =~ /x/;
133 $docs .= "NOTE: the perl_ form of this function is deprecated.\n\n"
136 print $fh "=item $name\nX<$name>\n$docs";
138 if ($flags =~ /U/) { # no usage
140 } elsif ($flags =~ /s/) { # semicolon ("dTHR;")
141 print $fh "\t\t$name;\n\n";
142 } elsif ($flags =~ /n/) { # no args
143 print $fh "\t$ret\t$name\n\n";
144 } else { # full usage
145 print $fh "\t$ret\t$name";
146 print $fh "(" . join(", ", @args) . ")";
149 print $fh "=for hackers\nFound in file $file\n\n";
153 my ($podname, $header, $dochash, $footer) = @_;
154 my $filename = "pod/$podname.pod";
155 open my $fh, '>', $filename or die "Can't open $filename: $!";
157 print $fh <<"_EOH_", $header;
158 -*- buffer-read-only: t -*-
160 !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
161 This file is built by $0 extracting documentation from the C source
167 # case insensitive sort, with fallback for determinacy
168 for $key (sort { uc($a) cmp uc($b) || $a cmp $b } keys %$dochash) {
169 my $section = $dochash->{$key};
170 print $fh "\n=head1 $key\n\n=over 8\n\n";
171 # Again, fallback for determinacy
172 for my $key (sort { uc($a) cmp uc($b) || $a cmp $b } keys %$section) {
173 docout($fh, $key, $section->{$key});
175 print $fh "\n=back\n";
178 print $fh $footer, <<'_EOF_';
184 close $fh or die "Can't close $filename: $!";
190 or die "Couldn't chdir to '$workdir': $!";
193 open IN, "embed.fnc" or die $!;
205 my ($flags, $retval, $func, @args) = split /\s*\|\s*/, $_;
209 s/\b(NN|NULLOK)\b\s+//g for @args;
210 $func =~ s/\t//g; # clean up fields from embed.pl
213 $funcflags{$func} = {
221 # glob() picks up docs from extra .c or .h files that may be in unclean
225 open FH, "MANIFEST" or die "Can't open MANIFEST: $!";
229 for $file (($MANIFEST =~ /^(\S+\.c)\t/gm), ($MANIFEST =~ /^(\S+\.h)\t/gm)) {
230 open F, "< $file" or die "Cannot open $file for docs: $!\n";
231 $curheader = "Functions in file $file\n";
233 close F or die "Error closing $file: $!\n";
236 for (sort keys %funcflags) {
237 next unless $funcflags{$_}{flags} =~ /d/;
238 warn "no docs for $_\n"
241 foreach (sort keys %missing) {
243 # Heuristics for known not-a-function macros:
247 warn "Function '$_', documented in $missing{$_}, not listed in embed.fnc";
250 # walk table providing an array of components in each line to
251 # subroutine, printing the result
253 output('perlapi', <<'_EOB_', $docs{api}, <<'_EOE_');
256 perlapi - autogenerated documentation for the perl public API
259 X<Perl API> X<API> X<api>
261 This file contains the documentation of the perl public API generated by
262 embed.pl, specifically a listing of functions, macros, flags, and variables
263 that may be used by extension writers. The interfaces of any functions that
264 are not listed here are subject to change without notice. For this reason,
265 blindly using functions listed in proto.h is to be avoided when writing
268 Note that all Perl API global variables must be referenced with the C<PL_>
269 prefix. Some macros are provided for compatibility with the older,
270 unadorned names, but this support may be disabled in a future release.
272 Perl was originally written to handle US-ASCII only (that is characters
273 whose ordinal numbers are in the range 0 - 127).
274 And documentation and comments may still use the term ASCII, when
275 sometimes in fact the entire range from 0 - 255 is meant.
277 Note that Perl can be compiled and run under EBCDIC (See L<perlebcdic>)
278 or ASCII. Most of the documentation (and even comments in the code)
279 ignore the EBCDIC possibility.
280 For almost all purposes the differences are transparent.
281 As an example, under EBCDIC,
282 instead of UTF-8, UTF-EBCDIC is used to encode Unicode strings, and so
283 whenever this documentation refers to C<utf8>
284 (and variants of that name, including in function names),
285 it also (essentially transparently) means C<UTF-EBCDIC>.
286 But the ordinals of characters differ between ASCII, EBCDIC, and
287 the UTF- encodings, and a string encoded in UTF-EBCDIC may occupy more bytes
290 Also, on some EBCDIC machines, functions that are documented as operating on
291 US-ASCII (or Basic Latin in Unicode terminology) may in fact operate on all
292 256 characters in the EBCDIC range, not just the subset corresponding to
295 The listing below is alphabetical, case insensitive.
301 Until May 1997, this document was maintained by Jeff Okamoto
302 <okamoto@corp.hp.com>. It is now maintained as part of Perl itself.
304 With lots of help and suggestions from Dean Roehrich, Malcolm Beattie,
305 Andreas Koenig, Paul Hudson, Ilya Zakharevich, Paul Marquess, Neil
306 Bowers, Matthew Green, Tim Bunce, Spider Boardman, Ulrich Pfeifer,
307 Stephen McCamant, and Gurusamy Sarathy.
309 API Listing originally by Dean Roehrich <roehrich@cray.com>.
311 Updated to be autogenerated from comments in the source by Benjamin Stuhl.
315 perlguts(1), perlxs(1), perlxstut(1), perlintern(1)
319 output('perlintern', <<'END', $docs{guts}, <<'END');
322 perlintern - autogenerated documentation of purely B<internal>
326 X<internal Perl functions> X<interpreter functions>
328 This file is the autogenerated documentation of functions in the
329 Perl interpreter that are documented using Perl's internal documentation
330 format but are not marked as part of the Perl API. In other words,
331 B<they are not for use in extensions>!
337 The autodocumentation system was originally added to the Perl core by
338 Benjamin Stuhl. Documentation is by whoever was kind enough to
339 document their functions.
343 perlguts(1), perlapi(1)