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 invoked as part of 'make all'
18 # '=head1' are the only headings looked for. If the next line after the
19 # heading begins with a word character, it is considered to be the first line
20 # of documentation that applies to the heading itself. That is, it is output
21 # immediately after the heading, before the first function, and not indented.
22 # The next input line that is a pod directive terminates this heading-level
30 or die "Couldn't chdir to '$workdir': $!";
32 require 'regen/regen_lib.pl';
33 require 'regen/embed_lib.pl';
36 # See database of global and static function prototypes in embed.fnc
37 # This is used to generate prototype headers under various configurations,
38 # export symbols lists for different platforms, and macros to provide an
39 # implicit interpreter context argument.
52 my $curheader = "Unknown section";
54 sub autodoc ($$) { # parse a file and extract documentation info
56 my($in, $doc, $line, $header_doc);
58 while (defined($in = <$fh>)) {
59 if ($in =~ /^#\s*define\s+([A-Za-z_][A-Za-z_0-9]+)\(/ &&
60 ($file ne 'embed.h' || $file ne 'proto.h')) {
64 if ($in=~ /^=head1 (.*)/) {
67 # If the next line begins with a word char, then is the start of
68 # heading-level documentation.
69 if (defined($doc = <$fh>)) {
77 # Continue getting the heading-level documentation until read
78 # in any pod directive (or as a fail-safe, find a closing
79 # comment to this pod in a C language file
81 while (defined($doc = <$fh>)) {
88 if ($doc =~ m:^\s*\*/$:) {
89 warn "=cut missing? $file:$line:$doc";;
98 if ($in =~ /^=for\s+apidoc\s+(.*?)\s*\n/) {
100 $proto = "||$proto" unless $proto =~ /\|/;
101 my($flags, $ret, $name, @args) = split /\|/, $proto;
104 while (defined($doc = <$fh>)) {
106 last DOC if $doc =~ /^=\w+/;
107 if ($doc =~ m:^\*/$:) {
108 warn "=cut missing? $file:$line:$doc";;
113 $docs = "\n$docs" if $docs and $docs !~ /^\n/;
115 # Check the consistency of the flags
116 my ($embed_where, $inline_where);
117 my ($embed_may_change, $inline_may_change);
119 my $docref = delete $funcflags{$name};
120 if ($docref and %$docref) {
121 $embed_where = $docref->{flags} =~ /A/ ? 'api' : 'guts';
122 $embed_may_change = $docref->{flags} =~ /M/;
123 $flags .= 'D' if $docref->{flags} =~ /D/;
125 $missing{$name} = $file;
128 $inline_where = $flags =~ /A/ ? 'api' : 'guts';
129 $inline_may_change = $flags =~ /x/;
131 if (defined $embed_where && $inline_where ne $embed_where) {
132 warn "Function '$name' inconsistency: embed.fnc says $embed_where, Pod says $inline_where";
135 if (defined $embed_may_change
136 && $inline_may_change ne $embed_may_change) {
137 my $message = "Function '$name' inconsistency: ";
138 if ($embed_may_change) {
139 $message .= "embed.fnc says 'may change', Pod does not";
141 $message .= "Pod says 'may change', embed.fnc does not";
145 } elsif (!defined $embed_where) {
146 warn "Unable to place $name!\n";
149 $inline_where = $embed_where;
150 $flags .= 'x' if $embed_may_change;
151 @args = @{$docref->{args}};
152 $ret = $docref->{retval};
155 $docs{$inline_where}{$curheader}{$name}
156 = [$flags, $docs, $ret, $file, @args];
158 # Create a special entry with an empty-string name for the
159 # heading-level documentation.
160 if (defined $header_doc) {
161 $docs{$inline_where}{$curheader}{""} = $header_doc;
166 if ($doc =~ /^=(?:for|head)/) {
171 warn "$file:$line:$in";
177 sub docout ($$$) { # output the docs for one function
178 my($fh, $name, $docref) = @_;
179 my($flags, $docs, $ret, $file, @args) = @$docref;
183 $docs = "\n\nDEPRECATED! It is planned to remove this function from a
184 future release of Perl. Do not use it for new code; remove it from
185 existing code.\n\n$docs";
188 $docs = "\n\nNOTE: this function is experimental and may change or be
189 removed without notice.\n\n$docs" if $flags =~ /x/;
191 $docs .= "NOTE: the perl_ form of this function is deprecated.\n\n"
193 $docs .= "NOTE: this function must be explicitly called as Perl_$name with an aTHX_ parameter.\n\n"
196 print $fh "=item $name\nX<$name>\n$docs";
198 if ($flags =~ /U/) { # no usage
200 } elsif ($flags =~ /s/) { # semicolon ("dTHR;")
201 print $fh "\t\t$name;\n\n";
202 } elsif ($flags =~ /n/) { # no args
203 print $fh "\t$ret\t$name\n\n";
204 } else { # full usage
205 my $p = $flags =~ /o/; # no #define foo Perl_foo
206 my $n = "Perl_"x$p . $name;
207 my $large_ret = length $ret > 7;
208 my $indent_size = 7+8 # nroff: 7 under =head + 8 under =item
209 +8+($large_ret ? 1 + length $ret : 8)
212 print $fh "\t$ret" . ($large_ret ? ' ' : "\t") . "$n(";
215 if ($indent_size + 2 + length > 79) {
217 $indent_size -= length($n) - 3;
223 $args = @args ? "pTHX_ " : "pTHX";
224 if ($long_args) { print $fh $args; $args = '' }
226 $long_args and print $fh "\n";
227 my $first = !$long_args;
231 && $indent_size + 3 + length($args[0]) + length $args > 79
236 "\t".($large_ret ? " " x (1+length $ret) : "\t")
237 ." "x($long_args ? 4 : 1 + length $n)
239 $args, (","x($args ne 'pTHX_ ') . "\n")x!!@args;
243 $args .= ", "x!!(length $args && $args ne 'pTHX_ ')
246 if ($long_args) { print $fh "\n", substr $indent, 0, -4 }
249 print $fh "=for hackers\nFound in file $file\n\n";
253 # Do a case-insensitive dictionary sort, with only alphabetics
254 # significant, falling back to using everything for determinancy
255 return (uc($a =~ s/[[^:alpha]]//r) cmp uc($b =~ s/[[^:alpha]]//r))
261 my ($podname, $header, $dochash, $missing, $footer) = @_;
262 my $fh = open_new("pod/$podname.pod", undef,
263 {by => "$0 extracting documentation",
264 from => 'the C source files'}, 1);
269 for $key (sort sort_helper keys %$dochash) {
270 my $section = $dochash->{$key};
271 print $fh "\n=head1 $key\n\n";
273 # Output any heading-level documentation and delete so won't get in
275 if (exists $section->{""}) {
276 print $fh $section->{""} . "\n";
277 delete $section->{""};
279 print $fh "=over 8\n\n";
281 for my $key (sort sort_helper keys %$section) {
282 docout($fh, $key, $section->{$key});
284 print $fh "\n=back\n";
288 print $fh "\n=head1 Undocumented functions\n\n";
289 print $fh $podname eq 'perlapi' ? <<'_EOB_' : <<'_EOB_';
290 The following functions have been flagged as part of the public API,
291 but are currently undocumented. Use them at your own risk, as the
292 interfaces are subject to change. Functions that are not listed in this
293 document are not intended for public use, and should NOT be used under any
296 If you use one of the undocumented functions below, you may wish to consider
297 creating and submitting documentation
298 for it. If your patch is accepted, this
299 will indicate that the interface is stable (unless it is explicitly marked
305 The following functions are currently undocumented. If you use one of
306 them, you may wish to consider creating and submitting documentation for
312 for my $missing (sort @$missing) {
313 print $fh "=item $missing\nX<$missing>\n\n";
315 print $fh "=back\n\n";
317 print $fh $footer, "=cut\n";
319 read_only_bottom_close_and_rename($fh);
322 foreach (@{(setup_embed())[0]}) {
324 my ($flags, $retval, $func, @args) = @$_;
325 s/\b(?:NN|NULLOK)\b\s+//g for @args;
327 $funcflags{$func} = {
334 # glob() picks up docs from extra .c or .h files that may be in unclean
336 open my $fh, '<', 'MANIFEST'
337 or die "Can't open MANIFEST: $!";
338 while (my $line = <$fh>) {
339 next unless my ($file) = $line =~ /^(\S+\.[ch])\t/;
341 open F, "< $file" or die "Cannot open $file for docs: $!\n";
342 $curheader = "Functions in file $file\n";
344 close F or die "Error closing $file: $!\n";
346 close $fh or die "Error whilst reading MANIFEST: $!";
348 for (sort keys %funcflags) {
349 next unless $funcflags{$_}{flags} =~ /d/;
350 warn "no docs for $_\n"
353 foreach (sort keys %missing) {
355 # Heuristics for known not-a-function macros:
359 warn "Function '$_', documented in $missing{$_}, not listed in embed.fnc";
362 # walk table providing an array of components in each line to
363 # subroutine, printing the result
365 # List of funcs in the public API that aren't also marked as experimental nor
367 my @missing_api = grep $funcflags{$_}{flags} =~ /A/ && $funcflags{$_}{flags} !~ /[MD]/ && !$docs{api}{$_}, keys %funcflags;
368 output('perlapi', <<'_EOB_', $docs{api}, \@missing_api, <<'_EOE_');
371 perlapi - autogenerated documentation for the perl public API
374 X<Perl API> X<API> X<api>
376 This file contains the documentation of the perl public API generated by
377 F<embed.pl>, specifically a listing of functions, macros, flags, and variables
378 that may be used by extension writers. L<At the end|/Undocumented functions>
379 is a list of functions which have yet to be documented. The interfaces of
380 those are subject to change without notice. Anything not listed here is
381 not part of the public API, and should not be used by extension writers at
382 all. For these reasons, blindly using functions listed in proto.h is to be
383 avoided when writing extensions.
385 Note that all Perl API global variables must be referenced with the C<PL_>
386 prefix. Again, those not listed here are not to be used by extension writers,
387 and can be changed or removed without notice; same with macros.
388 Some macros are provided for compatibility with the older,
389 unadorned names, but this support may be disabled in a future release.
391 Perl was originally written to handle US-ASCII only (that is characters
392 whose ordinal numbers are in the range 0 - 127).
393 And documentation and comments may still use the term ASCII, when
394 sometimes in fact the entire range from 0 - 255 is meant.
396 Note that Perl can be compiled and run under EBCDIC (See L<perlebcdic>)
397 or ASCII. Most of the documentation (and even comments in the code)
398 ignore the EBCDIC possibility.
399 For almost all purposes the differences are transparent.
400 As an example, under EBCDIC,
401 instead of UTF-8, UTF-EBCDIC is used to encode Unicode strings, and so
402 whenever this documentation refers to C<utf8>
403 (and variants of that name, including in function names),
404 it also (essentially transparently) means C<UTF-EBCDIC>.
405 But the ordinals of characters differ between ASCII, EBCDIC, and
406 the UTF- encodings, and a string encoded in UTF-EBCDIC may occupy more bytes
409 The listing below is alphabetical, case insensitive.
415 Until May 1997, this document was maintained by Jeff Okamoto
416 <okamoto@corp.hp.com>. It is now maintained as part of Perl itself.
418 With lots of help and suggestions from Dean Roehrich, Malcolm Beattie,
419 Andreas Koenig, Paul Hudson, Ilya Zakharevich, Paul Marquess, Neil
420 Bowers, Matthew Green, Tim Bunce, Spider Boardman, Ulrich Pfeifer,
421 Stephen McCamant, and Gurusamy Sarathy.
423 API Listing originally by Dean Roehrich <roehrich@cray.com>.
425 Updated to be autogenerated from comments in the source by Benjamin Stuhl.
429 L<perlguts>, L<perlxs>, L<perlxstut>, L<perlintern>
433 # List of non-static internal functions
435 grep $funcflags{$_}{flags} !~ /[As]/ && !$docs{guts}{$_}, keys %funcflags;
437 output('perlintern', <<'END', $docs{guts}, \@missing_guts, <<'END');
440 perlintern - autogenerated documentation of purely B<internal>
444 X<internal Perl functions> X<interpreter functions>
446 This file is the autogenerated documentation of functions in the
447 Perl interpreter that are documented using Perl's internal documentation
448 format but are not marked as part of the Perl API. In other words,
449 B<they are not for use in extensions>!
455 The autodocumentation system was originally added to the Perl core by
456 Benjamin Stuhl. Documentation is by whoever was kind enough to
457 document their functions.
461 L<perlguts>, L<perlapi>