This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perlapi: Rename COP section
[perl5.git] / autodoc.pl
CommitLineData
94bdecf9 1#!/usr/bin/perl -w
00d68f0d
KW
2
3use Text::Tabs;
a9a7c81e 4#
6294c161
DM
5# Unconditionally regenerate:
6#
7# pod/perlintern.pod
8# pod/perlapi.pod
9#
10# from information stored in
11#
12# embed.fnc
9b983db7 13# plus all the core .c, .h, and .pod files listed in MANIFEST
e10306bf
KW
14# plus %extra_input_pods
15
16my %extra_input_pods = ( 'dist/ExtUtils-ParseXS/lib/perlxs.pod' => 1 );
17
6294c161 18# Has an optional arg, which is the directory to chdir to before reading
9b983db7 19# MANIFEST and the files
6294c161 20#
52a9d53b 21# This script is invoked as part of 'make all'
151c3fe5 22#
9b983db7
KW
23# The generated pod consists of sections of related elements, functions,
24# macros, and variables. The keys of %valid_sections give the current legal
25# ones. Just add a new key to add a section.
26#
27# Throughout the files read by this script are lines like
28#
29# =for apidoc_section Section Name
3f620621 30# =for apidoc_section $section_name_variable
9b983db7
KW
31#
32# "Section Name" (after having been stripped of leading space) must be one of
3f620621
KW
33# the legal section names, or an error is thrown. $section_name_variable must
34# be one of the legal section name variables defined below; these expand to
35# legal section names. This form is used so that minor wording changes in
36# these titles can be confied to this file. All the names of the variables
37# end in '_scn'; this suffix is optional in the apidoc_section lines.
38#
39# All API elements defined between this line and the next 'apidoc_section'
40# line will go into the section "Section Name" (or $section_name_variable),
41# sorted by dictionary order within it. perlintern and perlapi are parallel
42# documents, each potentially with a section "Section Name". Each element is
43# marked as to which document it goes into. If there are none for a
44# particular section in perlapi, that section is omitted.
9b983db7
KW
45#
46# Also, in .[ch] files, there may be
47#
48# =head1 Section Name
49#
50# lines in comments. These are also used by this program to switch to section
51# "Section Name". The difference is that if there are any lines after the
52# =head1, inside the same comment, and before any =for apidoc-ish lines, they
53# are used as a heading for section "Section Name" (in both perlintern and
54# perlapi). This includes any =head[2-5]. If more than one '=head1 Section
55# Name' line has content, they appear in the generated pod in an undefined
3f620621 56# order. Note that you can't use a $section_name_variable in =head1 lines
9b983db7
KW
57#
58# The next =head1, =for apidoc_section, or file end terminates what goes into
59# the current section
60#
61# The %valid_sections hash below also can have header content, which will
62# appear before any =head1 content. The hash can also have footer content
63# content, which will appear at the end of the section, after all the
64# elements.
65#
66# The lines that define the actual functions, etc are documented in embed.fnc,
67# because they have flags which must be kept in sync with that file.
1fcde0e9 68
56a0c332 69use strict;
04adaf08 70use warnings;
a64c954a 71
3dc8ec40
KW
72# 80 column terminal - 2 for pager adding 2 columns; -4 for indent for
73# non-heading lines;
74my $max_width = 80 - 2 - 4;
e4f5ddf4 75
7882b24a
NC
76if (@ARGV) {
77 my $workdir = shift;
78 chdir $workdir
79 or die "Couldn't chdir to '$workdir': $!";
80}
3d7c117d
MB
81require './regen/regen_lib.pl';
82require './regen/embed_lib.pl';
7882b24a 83
a026e430 84my %described_elsewhere;
b87d9527 85
94bdecf9 86#
346f75ff 87# See database of global and static function prototypes in embed.fnc
94bdecf9
JH
88# This is used to generate prototype headers under various configurations,
89# export symbols lists for different platforms, and macros to provide an
90# implicit interpreter context argument.
91#
92
6a235718 93my %docs;
df6bd76f 94my %seen;
5ce57792 95my %funcflags;
5ce57792 96my %missing;
00d68f0d
KW
97my %missing_macros;
98
99my $link_text = "Described in";
100
783469eb
KW
101my $description_indent = 4;
102my $usage_indent = 3; # + initial blank yields 4 total
103
3e294c2f 104my $AV_scn = 'AV Handling';
3951f999
KW
105my $callback_scn = 'Callback Functions';
106my $casting_scn = 'Casting';
107my $casing_scn = 'Character case changing';
108my $classification_scn = 'Character classification';
109my $names_scn = 'Character names';
110my $scope_scn = 'Compile-time scope hooks';
111my $compiler_scn = 'Compiler and Preprocessor information';
112my $directives_scn = 'Compiler directives';
113my $concurrency_scn = 'Concurrency';
240d081e 114my $COP_scn = 'COPs and Hint Hashes';
3951f999
KW
115my $CV_scn = 'CV Handling';
116my $custom_scn = 'Custom Operators';
d1b9805e
KW
117my $debugging_scn = 'Debugging';
118my $display_scn = 'Display functions';
3951f999
KW
119my $embedding_scn = 'Embedding and Interpreter Cloning';
120my $errno_scn = 'Errno';
121my $exceptions_scn = 'Exception Handling (simple) Macros';
122my $filesystem_scn = 'Filesystem configuration values';
b6f27e58 123my $filters_scn = 'Source Filters';
3951f999
KW
124my $floating_scn = 'Floating point configuration values';
125my $formats_scn = 'Formats';
126my $genconfig_scn = 'General Configuration';
127my $globals_scn = 'Global Variables';
128my $GV_scn = 'GV Handling';
129my $hook_scn = 'Hook manipulation';
130my $HV_scn = 'HV Handling';
131my $io_scn = 'Input/Output';
132my $integer_scn = 'Integer configuration values';
133my $lexer_scn = 'Lexer interface';
3e294c2f 134my $locale_scn = 'Locales';
3951f999
KW
135my $magic_scn = 'Magic';
136my $memory_scn = 'Memory Management';
3e294c2f 137my $MRO_scn = 'MRO';
3951f999
KW
138my $multicall_scn = 'Multicall Functions';
139my $numeric_scn = 'Numeric Functions';
72957953
KW
140
141# Now combined, as unclear which functions go where, but separate names kept
142# to avoid 1) other code changes; 2) in case it seems better to split again
143my $optrees_scn = 'Optrees';
144my $optree_construction_scn = $optrees_scn; # Was 'Optree construction';
145my $optree_manipulation_scn = $optrees_scn; # Was 'Optree Manipulation Functions'
3951f999
KW
146my $pack_scn = 'Pack and Unpack';
147my $pad_scn = 'Pad Data Structures';
148my $password_scn = 'Password and Group access';
149my $paths_scn = 'Paths to system commands';
3951f999
KW
150my $prototypes_scn = 'Prototype information';
151my $regexp_scn = 'REGEXP Functions';
152my $signals_scn = 'Signals';
153my $site_scn = 'Site configuration';
154my $sockets_scn = 'Sockets configuration values';
3951f999
KW
155my $stack_scn = 'Stack Manipulation Macros';
156my $string_scn = 'String Handling';
157my $SV_flags_scn = 'SV Flags';
158my $SV_scn = 'SV Handling';
d8e799d8 159my $tainting_scn = 'Tainting';
3951f999
KW
160my $time_scn = 'Time';
161my $typedefs_scn = 'Typedef names';
162my $unicode_scn = 'Unicode Support';
163my $utility_scn = 'Utility Functions';
164my $versioning_scn = 'Versioning';
165my $warning_scn = 'Warning and Dieing';
3e294c2f 166my $XS_scn = 'XS';
3951f999 167
55d5a9fe
KW
168# Kept separate at end
169my $undocumented_scn = 'Undocumented elements';
170
00d68f0d 171my %valid_sections = (
3e294c2f 172 $AV_scn => {},
3951f999
KW
173 $callback_scn => {},
174 $casting_scn => {},
175 $casing_scn => {},
176 $classification_scn => {},
177 $scope_scn => {},
178 $compiler_scn => {},
179 $directives_scn => {},
180 $concurrency_scn => {},
181 $COP_scn => {},
89222628
KW
182 $CV_scn => {
183 header => <<~'EOT',
184 This section documents functions to manipulate CVs which are
185 code-values, meaning subroutines. For more information, see
186 L<perlguts>.
187 EOT
188 },
189
3951f999 190 $custom_scn => {},
d1b9805e
KW
191 $debugging_scn => {},
192 $display_scn => {},
3951f999
KW
193 $embedding_scn => {},
194 $errno_scn => {},
195 $exceptions_scn => {},
196 $filesystem_scn => {
6927cd44
KW
197 header => <<~'EOT',
198 Also see L</List of capability HAS_foo symbols>.
199 EOT
200 },
b6f27e58 201 $filters_scn => {},
3951f999 202 $floating_scn => {
00d68f0d 203 header => <<~'EOT',
6927cd44
KW
204 Also L</List of capability HAS_foo symbols> lists capabilities
205 that arent in this section. For example C<HAS_ASINH>, for the
206 hyperbolic sine function.
207 EOT
208 },
3951f999 209 $formats_scn => {
6927cd44
KW
210 header => <<~'EOT',
211 These are used for formatting the corresponding type For example,
212 instead of saying
213
214 Perl_newSVpvf(pTHX_ "Create an SV with a %d in it\n", iv);
215
216 use
217
218 Perl_newSVpvf(pTHX_ "Create an SV with a " IVdf " in it\n", iv);
219
220 This keeps you from having to know if, say an IV, needs to be
221 printed as C<%d>, C<%ld>, or something else.
00d68f0d
KW
222 EOT
223 },
3951f999 224 $genconfig_scn => {
00d68f0d
KW
225 header => <<~'EOT',
226 This section contains configuration information not otherwise
227 found in the more specialized sections of this document. At the
228 end is a list of C<#defines> whose name should be enough to tell
229 you what they do, and a list of #defines which tell you if you
230 need to C<#include> files to get the corresponding functionality.
231 EOT
232
233 footer => <<~'EOT',
234
235 =head2 List of capability C<HAS_I<foo>> symbols
236
6927cd44
KW
237 This is a list of those symbols that dont appear elsewhere in ths
238 document that indicate if the current platform has a certain
239 capability. Their names all begin with C<HAS_>. Only those
240 symbols whose capability is directly derived from the name are
241 listed here. All others have their meaning expanded out elsewhere
242 in this document. This (relatively) compact list is because we
243 think that the expansion would add little or no value and take up
244 a lot of space (because there are so many). If you think certain
245 ones should be expanded, send email to
246 L<perl5-porters@perl.org|mailto:perl5-porters@perl.org>.
00d68f0d
KW
247
248 Each symbol here will be C<#define>d if and only if the platform
249 has the capability. If you need more detail, see the
6927cd44
KW
250 corresponding entry in F<config.h>. For convenience, the list is
251 split so that the ones that indicate there is a reentrant version
252 of a capability are listed separately
00d68f0d
KW
253
254 __HAS_LIST__
255
6927cd44
KW
256 And, the reentrant capabilities:
257
258 __HAS_R_LIST__
259
00d68f0d
KW
260 Example usage:
261
262 =over
263
264 #ifdef HAS_STRNLEN
265 use strnlen()
266 #else
267 use an alternative implementation
268 #endif
269
270 =back
271
272 =head2 List of C<#include> needed symbols
273
274 This list contains symbols that indicate if certain C<#include>
275 files are present on the platform. If your code accesses the
276 functionality that one of these is for, you will need to
277 C<#include> it if the symbol on this list is C<#define>d. For
278 more detail, see the corresponding entry in F<config.h>.
279
280 __INCLUDE_LIST__
281
282 Example usage:
283
284 =over
285
286 #ifdef I_WCHAR
287 #include <wchar.h>
288 #endif
289
290 =back
291 EOT
292 },
3951f999
KW
293 $globals_scn => {},
294 $GV_scn => {},
295 $hook_scn => {},
296 $HV_scn => {},
297 $io_scn => {},
298 $integer_scn => {},
299 $lexer_scn => {},
3e294c2f 300 $locale_scn => {},
3951f999
KW
301 $magic_scn => {},
302 $memory_scn => {},
3e294c2f 303 $MRO_scn => {},
3951f999
KW
304 $multicall_scn => {},
305 $numeric_scn => {},
72957953 306 $optrees_scn => {},
3951f999
KW
307 $optree_construction_scn => {},
308 $optree_manipulation_scn => {},
309 $pack_scn => {},
310 $pad_scn => {},
311 $password_scn => {},
312 $paths_scn => {},
3951f999
KW
313 $prototypes_scn => {},
314 $regexp_scn => {},
315 $signals_scn => {},
316 $site_scn => {
6927cd44
KW
317 header => <<~'EOT',
318 These variables give details as to where various libraries,
319 installation destinations, I<etc.>, go, as well as what various
320 installation options were selected
321 EOT
322 },
3951f999 323 $sockets_scn => {},
3951f999
KW
324 $stack_scn => {},
325 $string_scn => {
89222628
KW
326 header => <<~EOT,
327 See also C<L</$unicode_scn>>.
6927cd44
KW
328 EOT
329 },
3951f999
KW
330 $SV_flags_scn => {},
331 $SV_scn => {},
d8e799d8 332 $tainting_scn => {},
3951f999
KW
333 $time_scn => {},
334 $typedefs_scn => {},
89222628
KW
335 $unicode_scn => {
336 header => <<~EOT,
337 L<perlguts/Unicode Support> has an introduction to this API.
338
339 See also C<L</$classification_scn>>,
340 C<L</$casing_scn>>,
341 and C<L</$string_scn>>.
342 Various functions outside this section also work specially with
343 Unicode. Search for the string "utf8" in this document.
344 EOT
345 },
3951f999
KW
346 $utility_scn => {},
347 $versioning_scn => {},
348 $warning_scn => {},
3e294c2f 349 $XS_scn => {},
00d68f0d 350);
94bdecf9 351
9e019b59
KW
352# Somewhat loose match for an apidoc line so we can catch minor typos.
353# Parentheses are used to capture portions so that below we verify
354# that things are the actual correct syntax.
355my $apidoc_re = qr/ ^ (\s*) # $1
356 (=?) # $2
357 (\s*) # $3
358 for (\s*) # $4
359 apidoc (_item)? # $5
360 (\s*) # $6
361 (.*?) # $7
362 \s* \n /x;
183f6e59 363# Only certain flags, dealing with display, are acceptable for apidoc_item
b8324975 364my $display_flags = "fFnDopsTx";
9e019b59
KW
365
366sub check_api_doc_line ($$) {
367 my ($file, $in) = @_;
368
369 return unless $in =~ $apidoc_re;
370
371 my $is_item = defined $5;
372 my $is_in_proper_form = length $1 == 0
373 && length $2 > 0
374 && length $3 == 0
375 && length $4 > 0
6e93196a
KW
376 && length $7 > 0
377 && ( length $6 > 0
378 || ($is_item && substr($7, 0, 1) eq '|'));
9e019b59
KW
379 my $proto_in_file = $7;
380 my $proto = $proto_in_file;
381 $proto = "||$proto" if $proto !~ /\|/;
382 my ($flags, $ret_type, $name, @args) = split /\s*\|\s*/, $proto;
383
384 $name && $is_in_proper_form or die <<EOS;
385Bad apidoc at $file line $.:
386 $in
387Expected:
388 =for apidoc flags|returntype|name|arg|arg|...
389 =for apidoc flags|returntype|name
390 =for apidoc name
391(or 'apidoc_item')
392EOS
393
56aac0d0 394 die "Only [$display_flags] allowed in apidoc_item:\n$in"
783469eb
KW
395 if $is_item && $flags =~ /[^$display_flags]/;
396
9e019b59
KW
397 return ($name, $flags, $ret_type, $is_item, $proto_in_file, @args);
398}
94bdecf9 399
4be3b9ca
KW
400sub embed_override($) {
401 my ($element_name) = shift;
402
403 # If the entry is also in embed.fnc, it should be defined
404 # completely there, but not here
405 my $embed_docref = delete $funcflags{$element_name};
406
407 return unless $embed_docref and %$embed_docref;
408
409 my $flags = $embed_docref->{'flags'};
410 warn "embed.fnc entry '$element_name' missing 'd' flag"
411 unless $flags =~ /d/;
412
413 return ($flags, $embed_docref->{'ret_type'}, $embed_docref->{args}->@*);
414}
415
89222628
KW
416# The section that is in effect at the beginning of the given file. If not
417# listed here, an apidoc_section line must precede any apidoc lines.
418# This allows the files listed here that generally are single-purpose, to not
419# have to worry about the autodoc section
420my %initial_file_section = (
421 'av.c' => $AV_scn,
422 'av.h' => $AV_scn,
423 'cv.h' => $CV_scn,
189b9288 424 'dist/ExtUtils-ParseXS/lib/perlxs.pod' => $XS_scn,
89222628
KW
425 'doio.c' => $io_scn,
426 'gv.c' => $GV_scn,
427 'gv.h' => $GV_scn,
428 'hv.h' => $HV_scn,
429 'locale.c' => $locale_scn,
430 'malloc.c' => $memory_scn,
431 'numeric.c' => $numeric_scn,
432 'opnames.h' => $optree_construction_scn,
433 'pad.h'=> $pad_scn,
434 'patchlevel.h' => $versioning_scn,
435 'perlio.h' => $io_scn,
436 'pod/perlapio.pod' => $io_scn,
437 'pod/perlcall.pod' => $callback_scn,
438 'pod/perlembed.pod' => $embedding_scn,
439 'pod/perlfilter.pod' => $filters_scn,
440 'pod/perliol.pod' => $io_scn,
441 'pod/perlmroapi.pod' => $MRO_scn,
442 'pod/perlreguts.pod' => $regexp_scn,
443 'pp_pack.c' => $pack_scn,
444 'pp_sort.c' => $SV_scn,
445 'regcomp.c' => $regexp_scn,
446 'regexp.h' => $regexp_scn,
d63f0f68
KW
447 'sv.h' => $SV_scn,
448 'sv.c' => $SV_scn,
072be79c 449 'sv_inline.h' => $SV_scn,
d8e799d8 450 'taint.c' => $tainting_scn,
89222628
KW
451 'unicode_constants.h' => $unicode_scn,
452 'utf8.c' => $unicode_scn,
453 'utf8.h' => $unicode_scn,
454 'vutil.c' => $versioning_scn,
455 );
456
94bdecf9
JH
457sub autodoc ($$) { # parse a file and extract documentation info
458 my($fh,$file) = @_;
63da8140 459 my($in, $line_num, $header, $section);
f554dfc5 460
89222628
KW
461 $section = $initial_file_section{$file}
462 if defined $initial_file_section{$file};
463
3cfa66c4
KW
464 my $file_is_C = $file =~ / \. [ch] $ /x;
465
f554dfc5 466 # Count lines easier
b1cb8a49 467 my $get_next_line = sub { $line_num++; return <$fh> };
f554dfc5 468
63da8140
KW
469 # Read the file
470 while ($in = $get_next_line->()) {
471 last unless defined $in;
3cfa66c4 472
63da8140
KW
473 next unless ( $in =~ / ^ =for [ ]+ apidoc /x
474 # =head1 lines only have effect in C files
475 || ($file_is_C && $in =~ /^=head1/));
476
477 # Here, the line introduces a portion of the input that we care about.
478 # Either it is for an API element, or heading text which we expect
479 # will be used for elements later in the file
480
481 my ($text, $element_name, $flags, $ret_type, $is_item, $proto_in_file);
183f6e59 482 my (@args, @items);
63da8140
KW
483
484 # If the line starts a new section ...
485 if ($in=~ /^ = (?: for [ ]+ apidoc_section | head1 ) [ ]+ (.*) /x) {
183f6e59 486
b1cb8a49 487 $section = $1;
3f620621
KW
488 if ($section =~ / ^ \$ /x) {
489 $section .= '_scn' unless $section =~ / _scn $ /;
490 $section = eval "$section";
491 die "Unknown \$section variable '$section' in $file: $@" if $@;
492 }
6927cd44
KW
493 die "Unknown section name '$section' in $file near line $.\n"
494 unless defined $valid_sections{$section};
495
3cfa66c4 496 }
63da8140
KW
497 elsif ($in=~ /^ =for [ ]+ apidoc \B /x) { # Otherwise better be a
498 # plain apidoc line
183f6e59
KW
499 die "Unkown apidoc-type line '$in'" unless $in=~ /^=for apidoc_item/;
500 die "apidoc_item doesn't immediately follow an apidoc entry: '$in'";
63da8140
KW
501 }
502 else { # Plain apidoc
503
504 ($element_name, $flags, $ret_type, $is_item, $proto_in_file, @args)
505 = check_api_doc_line($file, $in);
4be3b9ca
KW
506 # Override this line with any info in embed.fnc
507 my ($embed_flags, $embed_ret_type, @embed_args)
508 = embed_override($element_name);
509 if ($embed_ret_type) {
63da8140 510 warn "embed.fnc entry overrides redundant information in"
4be3b9ca
KW
511 . " '$proto_in_file' in $file"
512 if $flags || $ret_type || @args;
513 $flags = $embed_flags;
514 $ret_type = $embed_ret_type;
515 @args = @embed_args;
516 }
9e728159
KW
517 elsif ($flags !~ /[my]/) { # Not in embed.fnc, is missing if not
518 # a macro or typedef
63da8140
KW
519 $missing{$element_name} = $file;
520 }
3cfa66c4 521
56aac0d0 522 die "flag '$1' is not legal (for function $element_name (from $file))"
ed18bf14 523 if $flags =~ / ( [^AabCDdEeFfGhiIMmNnTOoPpRrSsUuWXxy] ) /x;
151c3fe5 524
9e728159
KW
525 die "'u' flag must also have 'm' or 'y' flags' for $element_name"
526 if $flags =~ /u/ && $flags !~ /[my]/;
63da8140
KW
527 warn ("'$element_name' not \\w+ in '$proto_in_file' in $file")
528 if $flags !~ /N/ && $element_name !~ / ^ [_[:alpha:]] \w* $ /x;
f554dfc5 529
63da8140
KW
530 if (exists $seen{$element_name} && $flags !~ /h/) {
531 die ("'$element_name' in $file was already documented in $seen{$element_name}");
532 }
533 else {
534 $seen{$element_name} = $file;
151c3fe5 535 }
94bdecf9 536 }
df6bd76f 537
63da8140
KW
538 # Here we have processed the initial line in the heading text or API
539 # element, and have saved the important information from it into the
540 # corresponding variables. Now accumulate the text that applies to it
541 # up to a terminating line, which is one of:
542 # 1) =cut
543 # 2) =head (in a C file only =head1)
544 # 3) an end comment line in a C file: m:^\s*\*/:
183f6e59 545 # 4) =for apidoc... (except apidoc_item lines)
63da8140
KW
546 $text = "";
547 my $head_ender_num = ($file_is_C) ? 1 : "";
548 while (defined($in = $get_next_line->())) {
549
550 last if $in =~ /^=cut/x;
551 last if $in =~ /^=head$head_ender_num/;
552
553 if ($file_is_C && $in =~ m: ^ \s* \* / $ :x) {
554
555 # End of comment line in C files is a fall-back terminator,
556 # but warn only if there actually is some accumulated text
557 warn "=cut missing? $file:$line_num:$in" if $text =~ /\S/;
558 last;
df6bd76f 559 }
df6bd76f 560
63da8140
KW
561 if ($in !~ / ^ =for [ ]+ apidoc /x) {
562 $text .= $in;
563 next;
564 }
565
183f6e59 566 # Here, the line is an apidoc line. All but apidoc_item terminate
63da8140 567 # the text being accumulated.
183f6e59
KW
568 last if $in =~ / ^ =for [ ]+ apidoc_section /x;
569
570 my ($item_name, $item_flags, $item_ret_type, $is_item,
4be3b9ca 571 $item_proto, @item_args) = check_api_doc_line($file, $in);
183f6e59
KW
572 last unless $is_item;
573
574 # Here, is an apidoc_item_line; They can only come within apidoc
575 # paragraphs.
4be3b9ca
KW
576 die "Unexpected api_doc_item line '$item_proto'"
577 unless $element_name;
183f6e59
KW
578
579 # We accept blank lines between these, but nothing else;
56aac0d0
KW
580 die "apidoc_item lines must immediately follow apidoc lines for "
581 . " '$element_name' in $file"
183f6e59 582 if $text =~ /\S/;
4be3b9ca
KW
583 # Override this line with any info in embed.fnc
584 my ($embed_flags, $embed_ret_type, @embed_args)
585 = embed_override($item_name);
586 if ($embed_ret_type) {
587 warn "embed.fnc entry overrides redundant information in"
588 . " '$item_proto' in $file"
589 if $item_flags || $item_ret_type || @item_args;
590
591 $item_flags = $embed_flags;
592 $item_ret_type = $embed_ret_type;
593 @item_args = @embed_args;
594 }
183f6e59
KW
595
596 # Use the base entry flags if none for this item; otherwise add in
597 # any non-display base entry flags.
598 if ($item_flags) {
599 $item_flags .= $flags =~ s/[$display_flags]//rg;
600 }
601 else {
602 $item_flags = $flags;
603 }
604 $item_ret_type = $ret_type unless $item_ret_type;
605 @item_args = @args unless @item_args;
606 push @items, { name => $item_name,
607 ret_type => $item_ret_type,
608 flags => $item_flags,
609 args => [ @item_args ],
610 };
611
612 # This line shows that this element is documented.
613 delete $funcflags{$item_name};
a9a7c81e 614 }
3cfa66c4 615
63da8140
KW
616 # Here, are done accumulating the text for this item. Trim it
617 $text =~ s/ ^ \s* //x;
618 $text =~ s/ \s* $ //x;
619 $text .= "\n" if $text ne "";
6523e108 620
63da8140
KW
621 # And treat all-spaces as nothing at all
622 undef $text unless $text =~ /\S/;
df6bd76f 623
63da8140 624 if ($element_name) {
df6bd76f 625
63da8140
KW
626 # Here, we have accumulated into $text, the pod for $element_name
627 my $where = $flags =~ /A/ ? 'api' : 'guts';
5ce57792 628
63da8140
KW
629 die "No =for apidoc_section nor =head1 in $file for '$element_name'\n"
630 unless defined $section;
631 if (exists $docs{$where}{$section}{$element_name}) {
632 warn "$0: duplicate API entry for '$element_name' in"
633 . " $where/$section\n";
634 next;
20046047 635 }
5ce57792 636
63da8140
KW
637 # Override the text with just a link if the flags call for that
638 my $is_link_only = ($flags =~ /h/);
639 if ($is_link_only) {
640 if ($file_is_C) {
56aac0d0 641 die "Can't currently handle link with items to it:\n$in" if @items;
63da8140
KW
642 redo; # Don't put anything if C source
643 }
644
645 # Here, is an 'h' flag in pod. We add a reference to the pod (and
646 # nothing else) to perlapi/intern. (It would be better to add a
647 # reference to the correct =item,=header, but something that makes
648 # it harder is that it that might be a duplicate, like '=item *';
649 # so that is a future enhancement XXX. Another complication is
650 # there might be more than one deserving candidates.)
651 my $podname = $file =~ s!.*/!!r; # Rmv directory name(s)
652 $podname =~ s/\.pod//;
653 $text = "Described in L<$podname>.\n";
654
655 # Don't output a usage example for linked to documentation if
656 # it is trivial (has no arguments) and we aren't to add a
657 # semicolon
658 $flags .= 'U' if $flags =~ /n/ && $flags !~ /[Us]/;
659
660 # Keep track of all the pod files that we refer to.
661 push $described_elsewhere{$podname}->@*, $podname;
662 }
5ce57792 663
5bf02caf
KW
664 $docs{$where}{$section}{$element_name}{flags} = $flags;
665 $docs{$where}{$section}{$element_name}{pod} = $text;
666 $docs{$where}{$section}{$element_name}{file} = $file;
667 $docs{$where}{$section}{$element_name}{ret_type} = $ret_type;
668 push $docs{$where}{$section}{$element_name}{args}->@*, @args;
183f6e59 669 push $docs{$where}{$section}{$element_name}{items}->@*, @items;
a9a7c81e 670 }
63da8140
KW
671 elsif ($text) {
672 $valid_sections{$section}{header} = "" unless
673 defined $valid_sections{$section}{header};
674 $valid_sections{$section}{header} .= "\n$text";
a9a7c81e 675 }
63da8140
KW
676
677 # We already have the first line of what's to come in $in
678 redo;
679
680 } # End of loop through input
94bdecf9
JH
681}
682
00d68f0d
KW
683my %configs;
684my @has_defs;
685my @has_r_defs; # Reentrant symbols
686my @include_defs;
63447426 687
00d68f0d
KW
688sub parse_config_h {
689 use re '/aa'; # Everthing is ASCII in this file
690
691 # Process config.h
d3871820
KW
692 my $config_h = 'config.h';
693 $config_h = 'win32/config.h' unless -e $config_h;
694 die "Can't find $config_h" unless -e $config_h;
695 open my $fh, '<', $config_h or die "Can't open $config_h: $!";
00d68f0d
KW
696 while (<$fh>) {
697
698 # Look for lines like /* FOO_BAR:
699 # By convention all config.h descriptions begin like that
700 if (m[ ^ /\* [ ] ( [[:alpha:]] \w+ ) : \s* $ ]ax) {
701 my $name = $1;
702
703 # Here we are starting the description for $name in config.h. We
704 # accumulate the entire description for it into @description.
705 # Flowing text from one input line to another is appended into the
706 # same array element to make a single flowing line element, but
707 # verbatim lines are kept as separate elements in @description.
708 # This will facilitate later doing pattern matching without regard
709 # to line boundaries on non-verbatim text.
710
711 die "Multiple config.h entries for '$name'"
712 if defined $configs{$name}{description};
713
714 # Get first line of description
715 $_ = <$fh>;
716
717 # Each line in the description begins with blanks followed by '/*'
718 # and some spaces.
719 die "Unexpected config.h initial line for $name: '$_'"
720 unless s/ ^ ( \s* \* \s* ) //x;
721 my $initial_text = $1;
722
723 # Initialize the description with this first line (after having
724 # stripped the prefix text)
725 my @description = $_;
726
727 # The first line is used as a template for how much indentation
728 # each normal succeeding line has. Lines indented further
729 # will be considered as intended to be verbatim. But, empty lines
730 # likely won't have trailing blanks, so just strip the whole thing
731 # for them.
732 my $strip_initial_qr = qr! \s* \* \s* $
733 | \Q$initial_text\E
734 !x;
735 $configs{$name}{verbatim} = 0;
736
737 # Read in the remainder of the description
738 while (<$fh>) {
739 last if s| ^ \s* \* / ||x; # A '*/' ends it
740
741 die "Unexpected config.h description line for $name: '$_'"
742 unless s/$strip_initial_qr//;
743
744 # Fix up the few flawed lines in config.h wherein a new
745 # sentence begins with a tab (and maybe a space after that).
746 # Although none of them currently do, let it recognize
747 # something like
748 #
749 # "... text"). The next sentence ...
750 #
751 s/ ( \w "? \)? \. ) \t \s* ( [[:alpha:]] ) /$1 $2/xg;
752
753 # If this line has extra indentation or looks to have columns,
754 # it should be treated as verbatim. Columns are indicated by
755 # use of interior: tabs, 3 spaces in a row, or even 2 spaces
756 # not preceded by punctuation.
757 if ($_ !~ m/ ^ \s
758 | \S (?: \t
759 | \s{3}
760 | (*nlb:[[:punct:]]) \s{2}
761 )
762 /x)
763 {
764 # But here, is not a verbatim line. Add an empty line if
765 # this is the first non-verbatim after a run of verbatims
766 if ($description[-1] =~ /^\s/) {
767 push @description, "\n", $_;
768 }
769 else { # Otherwise, append this flowing line to the
770 # current flowing line
771 $description[-1] .= $_;
772 }
773 }
774 else {
775 $configs{$name}{verbatim} = 1;
776
777 # The first verbatim line in a run of them is separated by an
778 # empty line from the flowing lines above it
779 push @description, "\n" if $description[-1] =~ /^\S/;
780
781 $_ = Text::Tabs::expand($_);
782
783 # Only a single space so less likely to wrap
784 s/ ^ \s* / /x;
785
786 push @description, $_;
787 }
788 }
789
790 push $configs{$name}{description}->@*, @description
791
792 } # Not a description; see if it is a macro definition.
793 elsif (m! ^
794 (?: / \* )? # Optional commented-out
795 # indication
796 \# \s* define \s+ ( \w+ ) # $1 is the name
797 ( \s* ) # $2 indicates if args or not
798 ( .*? ) # $3 is any definition
799 (?: / \s* \* \* / )? # Optional trailing /**/ or / **/
800 $
801 !x)
802 {
803 my $name = $1;
804
805 # There can be multiple definitions for a name. We want to know
806 # if any of them has arguments, and if any has a body.
807 $configs{$name}{has_args} //= $2 eq "";
808 $configs{$name}{has_args} ||= $2 eq "";
809 $configs{$name}{has_defn} //= $3 ne "";
810 $configs{$name}{has_defn} ||= $3 ne "";
811 }
812 }
813
814 # We now have stored the description and information about every #define
815 # in the file. The description is in a form convenient to operate on to
816 # convert to pod. Do that now.
817 foreach my $name (keys %configs) {
818 next unless defined $configs{$name}{description};
819
820 # All adjacent non-verbatim lines of the description are appended
821 # together in a single element in the array. This allows the patterns
822 # to work across input line boundaries.
823
824 my $pod = "";
825 while (defined ($_ = shift $configs{$name}{description}->@*)) {
826 chomp;
827
828 if (/ ^ \S /x) { # Don't edit verbatim lines
829
830 # Enclose known file/path names not already so enclosed
831 # with <...>. (Some entries in config.h are already
832 # '<path/to/file>')
833 my $file_name_qr = qr! [ \w / ]+ \.
834 (?: c | h | xs | p [lm] | pmc | PL
835 | sh | SH | exe ) \b
836 !xx;
837 my $path_name_qr = qr! (?: / \w+ )+ !x;
838 for my $re ($file_name_qr, $path_name_qr) {
839 s! (*nlb:[ < \w / ]) ( $re ) !<$1>!gxx;
840 }
841
842 # Enclose <... file/path names with F<...> (but no double
843 # angle brackets)
844 for my $re ($file_name_qr, $path_name_qr) {
845 s! < ( $re ) > !F<$1>!gxx;
846 }
847
848 # Explain metaconfig units
849 s/ ( \w+ \. U \b ) /$1 (part of metaconfig)/gx;
850
851 # Convert "See foo" to "See C<L</foo>>" if foo is described in
852 # this file. Also create a link to the known file INSTALL.
853 # And, to be more general, handle "See also foo and bar", and
854 # "See also foo, bar, and baz"
855 while (m/ \b [Ss]ee \s+
856 (?: also \s+ )? ( \w+ )
857 (?: , \s+ ( \w+ ) )?
858 (?: ,? \s+ and \s+ ( \w+ ) )? /xg) {
859 my @links = $1;
860 push @links, $2 if defined $2;
861 push @links, $3 if defined $3;
862 foreach my $link (@links) {
863 if ($link eq 'INSTALL') {
864 s/ \b INSTALL \b /C<L<INSTALL>>/xg;
865 }
866 elsif (grep { $link =~ / \b $_ \b /x } keys %configs) {
867 s| \b $link \b |C<L</$link>>|xg;
868 $configs{$link}{linked} = 1;
869 $configs{$name}{linked} = 1;
870 }
871 }
872 }
873
874 # Enclose what we think are symbols with C<...>.
875 no warnings 'experimental::vlb';
876 s/ (*nlb:<)
877 (
878 # Any word followed immediately with parens or
879 # brackets
880 \b \w+ (?: \( [^)]* \) # parameter list
881 | \[ [^]]* \] # or array reference
882 )
883 | (*plb: ^ | \s ) -D \w+ # Also -Dsymbols.
884 | \b (?: struct | union ) \s \w+
885
886 # Words that contain underscores (which are
887 # definitely not text) or three uppercase letters in
888 # a row. Length two ones, like IV, aren't enclosed,
889 # because they often don't look as nice.
890 | \b \w* (?: _ | [[:upper:]]{3,} ) \w* \b
891 )
892 (*nla:>)
893 /C<$1>/xg;
894
895 # These include foo when the name is HAS_foo. This is a
896 # heuristic which works in most cases.
897 if ($name =~ / ^ HAS_ (.*) /x) {
898 my $symbol = lc $1;
899
900 # Don't include path components, nor things already in
901 # <>, or with trailing '(', '['
902 s! \b (*nlb:[/<]) $symbol (*nla:[[/>(]) \b !C<$symbol>!xg;
903 }
904 }
905
906 $pod .= "$_\n";
907 }
908 delete $configs{$name}{description};
909
910 $configs{$name}{pod} = $pod;
911 }
912
913 # Now have converted the description to pod. We also now have enough
914 # information that we can do cross checking to find definitions without
915 # corresponding pod, and see if they are mentioned in some description;
916 # otherwise they aren't documented.
917 NAME:
918 foreach my $name (keys %configs) {
919
920 # A definition without pod
921 if (! defined $configs{$name}{pod}) {
922
923 # Leading/trailing underscore means internal to config.h, e.g.,
924 # _GNU_SOURCE
925 next if $name =~ / ^ _ /x;
926 next if $name =~ / _ $ /x;
927
928 # MiXeD case names are internal to config.h; the first 4
929 # characters are sufficient to determine this
930 next if $name =~ / ^ [[:upper:]] [[:lower:]]
931 [[:upper:]] [[:lower:]]
932 /x;
933
934 # Here, not internal to config.h. Look to see if this symbol is
935 # mentioned in the pod of some other. If so, assume it is
936 # documented.
937 foreach my $check_name (keys %configs) {
938 my $this_element = $configs{$check_name};
939 my $this_pod = $this_element->{pod};
940 if (defined $this_pod) {
941 next NAME if $this_pod =~ / \b $name \b /x;
942 }
943 }
944
945 warn "$name has no documentation\n";
946 $missing_macros{$name} = 'config.h';
947
948 next;
949 }
950
951 my $has_defn = $configs{$name}{has_defn};
952 my $has_args = $configs{$name}{has_args};
953
954 # Check if any section already has an entry for this element.
955 # If so, it better be a placeholder, in which case we replace it
956 # with this entry.
957 foreach my $section (keys $docs{'api'}->%*) {
958 if (exists $docs{'api'}{$section}{$name}) {
959 my $was = $docs{'api'}{$section}{$name}->{pod};
960 $was = "" unless $was;
961 chomp $was;
962 if ($was ne "" && $was !~ m/$link_text/) {
963 die "Multiple descriptions for $name\n"
964 . "$section contained '$was'";
965 }
966 $docs{'api'}{$section}{$name}->{pod} = $configs{$name}{pod};
967 $configs{$name}{section} = $section;
968 last;
969 }
970 }
971
972 my $handled = 0; # Haven't handled this yet
973
974 if (defined $configs{$name}{'section'}) {
975 # This has been taken care of elsewhere.
976 $handled = 1;
977 }
978 else {
9e728159 979 my $flags = "";
00d68f0d
KW
980 if ($has_defn && ! $has_args) {
981 $configs{$name}{args} = 1;
982 }
983
984 # Symbols of the form I_FOO are for #include files. They have
985 # special usage information
986 if ($name =~ / ^ I_ ( .* ) /x) {
987 my $file = lc $1 . '.h';
988 $configs{$name}{usage} = <<~"EOT";
989 #ifdef $name
990 #include <$file>
991 #endif
992 EOT
993 }
994
995 # Compute what section this variable should go into. This
996 # heuristic was determined by manually inspecting the current
997 # things in config.h, and should be adjusted as necessary as
998 # deficiencies are found.
999 #
1000 # This is the default section for macros with a definiton but
1001 # no arguments, meaning it is replaced unconditionally
1002 #
1003 my $sb = qr/ _ | \b /x; # segment boundary
1004 my $dash_or_spaces = qr/ - | \s+ /x;
1005 my $pod = $configs{$name}{pod};
1006 if ($name =~ / ^ USE_ /x) {
3951f999 1007 $configs{$name}{'section'} = $site_scn;
00d68f0d
KW
1008 }
1009 elsif ($name =~ / SLEEP | (*nlb:SYS_) TIME | TZ | $sb TM $sb /x)
1010 {
3951f999 1011 $configs{$name}{'section'} = $time_scn;
00d68f0d 1012 }
c86b25ed
KW
1013 elsif ( $name =~ / ^ [[:alpha:]]+ f $ /x
1014 && $configs{$name}{pod} =~ m/ \b format \b /ix)
1015 {
1016 $configs{$name}{'section'} = $formats_scn;
1017 }
00d68f0d
KW
1018 elsif ($name =~ / DOUBLE | FLOAT | LONGDBL | LDBL | ^ NV
1019 | $sb CASTFLAGS $sb
1020 | QUADMATH
1021 | $sb (?: IS )? NAN
1022 | $sb (?: IS )? FINITE
1023 /x)
1024 {
1025 $configs{$name}{'section'} =
3951f999 1026 $floating_scn;
00d68f0d
KW
1027 }
1028 elsif ($name =~ / (?: POS | OFF | DIR ) 64 /x) {
3951f999 1029 $configs{$name}{'section'} = $filesystem_scn;
00d68f0d
KW
1030 }
1031 elsif ( $name =~ / $sb (?: BUILTIN | CPP ) $sb | ^ CPP /x
1032 || $configs{$name}{pod} =~ m/ \b align /x)
1033 {
3951f999 1034 $configs{$name}{'section'} = $compiler_scn;
00d68f0d
KW
1035 }
1036 elsif ($name =~ / ^ [IU] [ \d V ]
1037 | ^ INT | SHORT | LONG | QUAD | 64 | 32 /xx)
1038 {
3951f999 1039 $configs{$name}{'section'} = $integer_scn;
00d68f0d
KW
1040 }
1041 elsif ($name =~ / $sb t $sb /x) {
3951f999 1042 $configs{$name}{'section'} = $typedefs_scn;
9e728159 1043 $flags .= 'y';
00d68f0d
KW
1044 }
1045 elsif ( $name =~ / ^ PERL_ ( PRI | SCN ) | $sb FORMAT $sb /x
1046 && $configs{$name}{pod} =~ m/ \b format \b /ix)
1047 {
3951f999 1048 $configs{$name}{'section'} = $formats_scn;
00d68f0d
KW
1049 }
1050 elsif ($name =~ / BACKTRACE /x) {
d1b9805e 1051 $configs{$name}{'section'} = $debugging_scn;
00d68f0d
KW
1052 }
1053 elsif ($name =~ / ALLOC $sb /x) {
3951f999 1054 $configs{$name}{'section'} = $memory_scn;
00d68f0d
KW
1055 }
1056 elsif ( $name =~ / STDIO | FCNTL | EOF | FFLUSH
1057 | $sb FILE $sb
1058 | $sb DIR $sb
1059 | $sb LSEEK
1060 | $sb INO $sb
1061 | $sb OPEN
1062 | $sb CLOSE
1063 | ^ DIR
1064 | ^ INO $sb
1065 | DIR $
1066 | FILENAMES
1067 /x
1068 || $configs{$name}{pod} =~ m! I/O | stdio
1069 | file \s+ descriptor
1070 | file \s* system
1071 | statfs
1072 !x)
1073 {
3951f999 1074 $configs{$name}{'section'} = $filesystem_scn;
00d68f0d
KW
1075 }
1076 elsif ($name =~ / ^ SIG | SIGINFO | signal /ix) {
3951f999 1077 $configs{$name}{'section'} = $signals_scn;
00d68f0d
KW
1078 }
1079 elsif ($name =~ / $sb ( PROTO (?: TYPE)? S? ) $sb /x) {
3951f999 1080 $configs{$name}{'section'} = $prototypes_scn;
00d68f0d
KW
1081 }
1082 elsif ( $name =~ / ^ LOC_ /x
1083 || $configs{$name}{pod} =~ /full path/i)
1084 {
3951f999 1085 $configs{$name}{'section'} = $paths_scn;
00d68f0d
KW
1086 }
1087 elsif ($name =~ / $sb LC_ | LOCALE | langinfo /xi) {
3e294c2f 1088 $configs{$name}{'section'} = $locale_scn;
00d68f0d
KW
1089 }
1090 elsif ($configs{$name}{pod} =~ / GCC | C99 | C\+\+ /xi) {
3951f999 1091 $configs{$name}{'section'} = $compiler_scn;
00d68f0d
KW
1092 }
1093 elsif ($name =~ / PASSW (OR)? D | ^ PW | ( PW | GR ) ENT /x)
1094 {
3951f999 1095 $configs{$name}{'section'} = $password_scn;
00d68f0d
KW
1096 }
1097 elsif ($name =~ / SOCKET | $sb SOCK /x) {
3951f999 1098 $configs{$name}{'section'} = $sockets_scn;
00d68f0d
KW
1099 }
1100 elsif ( $name =~ / THREAD | MULTIPLICITY /x
1101 || $configs{$name}{pod} =~ m/ \b pthread /ix)
1102 {
3951f999 1103 $configs{$name}{'section'} = $concurrency_scn;
00d68f0d
KW
1104 }
1105 elsif ($name =~ / PERL | ^ PRIV | SITE | ARCH | BIN
1106 | VENDOR | ^ USE
1107 /x)
1108 {
3951f999 1109 $configs{$name}{'section'} = $site_scn;
00d68f0d
KW
1110 }
1111 elsif ( $pod =~ / \b floating $dash_or_spaces point \b /ix
63447426
KW
1112 || $pod =~ / \b (double | single) $dash_or_spaces precision \b /ix
1113 || $pod =~ / \b doubles \b /ix
1114 || $pod =~ / \b (?: a | the | long ) \s+ (?: double | NV ) \b /ix)
00d68f0d
KW
1115 {
1116 $configs{$name}{'section'} =
3951f999 1117 $floating_scn;
00d68f0d
KW
1118 }
1119 else {
1120 # Above are the specific sections. The rest go into a
1121 # grab-bag of general configuration values. However, we put
1122 # two classes of them into lists of their names, without their
1123 # descriptions, when we think that the description doesn't add
1124 # any real value. One list contains the #include variables:
1125 # the description is basically boiler plate for each of these.
1126 # The other list contains the very many things that are of the
1127 # form HAS_foo, and \bfoo\b is contained in its description,
1128 # and there is no verbatim text in the pod or links to/from it
1129 # (which would add value). That means that it is likely the
1130 # intent of the variable can be gleaned from just its name,
1131 # and unlikely the description adds signficant value, so just
1132 # listing them suffices. Giving their descriptions would
1133 # expand this pod significantly with little added value.
1134 if ( ! $has_defn
1135 && ! $configs{$name}{verbatim}
1136 && ! $configs{$name}{linked})
1137 {
1138 if ($name =~ / ^ I_ ( .* ) /x) {
1139 push @include_defs, $name;
1140 next;
1141 }
1142 elsif ($name =~ / ^ HAS_ ( .* ) /x) {
1143 my $canonical_name = $1;
1144 $canonical_name =~ s/_//g;
1145
1146 my $canonical_pod = $configs{$name}{pod};
1147 $canonical_pod =~ s/_//g;
1148
1149 if ($canonical_pod =~ / \b $canonical_name \b /xi) {
1150 if ($name =~ / $sb R $sb /x) {
1151 push @has_r_defs, $name;
1152 }
1153 else {
1154 push @has_defs, $name;
1155 }
1156 next;
1157 }
1158 }
1159 }
1160
3951f999 1161 $configs{$name}{'section'} = $genconfig_scn;
00d68f0d
KW
1162 }
1163
1164 my $section = $configs{$name}{'section'};
6927cd44
KW
1165 die "Internal error: '$section' not in \%valid_sections"
1166 unless grep { $_ eq $section } keys %valid_sections;
9e728159 1167 $flags .= 'AdmnT';
00d68f0d 1168 $flags .= 'U' unless defined $configs{$name}{usage};
9e728159 1169
63447426 1170 # All the information has been gathered; save it
00d68f0d
KW
1171 $docs{'api'}{$section}{$name}{flags} = $flags;
1172 $docs{'api'}{$section}{$name}{pod} = $configs{$name}{pod};
1173 $docs{'api'}{$section}{$name}{ret_type} = "";
1174 $docs{'api'}{$section}{$name}{file} = 'config.h';
1175 $docs{'api'}{$section}{$name}{usage}
1176 = $configs{$name}{usage} if defined $configs{$name}{usage};
1177 push $docs{'api'}{$section}{$name}{args}->@*, ();
1178 push $docs{'api'}{$section}{$name}{items}->@*, ();
1179 }
1180 }
1181}
1182
c7a2af98
KW
1183sub format_pod_indexes($) {
1184 my $entries_ref = shift;
1185
1186 # Output the X<> references to the names, packed since they don't get
1187 # displayed, but not too many per line so that when someone is editing the
1188 # file, it doesn't run on
1189
1190 my $text ="";
1191 my $line_length = 0;
1192 for my $name (sort dictionary_order $entries_ref->@*) {
1193 my $entry = "X<$name>";
1194 my $entry_length = length $entry;
1195
1196 # Don't loop forever if we have a verrry long name, and don't go too
1197 # far to the right.
1198 if ($line_length > 0 && $line_length + $entry_length > $max_width) {
1199 $text .= "\n";
1200 $line_length = 0;
1201 }
1202
1203 $text .= $entry;
1204 $line_length += $entry_length;
1205 }
1206
1207 return $text;
1208}
1209
b63f8ed4 1210sub docout ($$$) { # output the docs for one function group
b1cb8a49 1211 my($fh, $element_name, $docref) = @_;
5bf02caf 1212
783469eb
KW
1213 # Trim trailing space
1214 $element_name =~ s/\s*$//;
1215
5bf02caf 1216 my $flags = $docref->{flags};
63da8140 1217 my $pod = $docref->{pod} // "";
5bf02caf 1218 my $file = $docref->{file};
783469eb 1219
183f6e59 1220 my @items = $docref->{items}->@*;
5bf02caf 1221
783469eb
KW
1222 # Make the main element the first of the items. This allows uniform
1223 # treatment below
1224 unshift @items, { name => $element_name,
1225 flags => $flags,
1226 ret_type => $docref->{ret_type},
1227 args => [ $docref->{args}->@* ],
1228 };
94bdecf9 1229
7a997878 1230 warn("Empty pod for $element_name (from $file)") unless $pod =~ /\S/;
9639517b 1231
783469eb
KW
1232 print $fh "\n=over $description_indent\n";
1233 print $fh "\n=item C<$_->{name}>\n" for @items;
63da8140 1234
783469eb
KW
1235 # If we're printing only a link to an element, this isn't the major entry,
1236 # so no X<> here.
1237 if ($flags !~ /h/) {
1238 print $fh "X<$_->{name}>" for @items;
1239 print $fh "\n";
d4e99c76 1240 }
63da8140 1241
d1681de8
KW
1242 my @deprecated;
1243 my @experimental;
783469eb 1244 for my $item (@items) {
d1681de8
KW
1245 push @deprecated, "C<$item->{name}>" if $item->{flags} =~ /D/;
1246 push @experimental, "C<$item->{name}>" if $item->{flags} =~ /x/;
1247 }
54c193ae 1248
d1681de8
KW
1249 for my $which (\@deprecated, \@experimental) {
1250 if ($which->@*) {
1251 my $is;
1252 my $it;
1253 my $list;
1254
1255 if ($which->@* == 1) {
1256 $is = 'is';
1257 $it = 'it';
1258 $list = $which->[0];
1259 }
1260 elsif ($which->@* == @items) {
1261 $is = 'are';
1262 $it = 'them';
1263 $list = (@items == 2)
1264 ? "both forms"
1265 : "all these forms";
1266 }
1267 else {
1268 $is = 'are';
1269 $it = 'them';
1270 my $final = pop $which->@*;
1271 $list = "the " . join ", ", $which->@*;
1272 $list .= "," if $which->@* > 1;
1273 $list .= " and $final forms";
1274 }
54c193ae 1275
d1681de8
KW
1276 if ($which == \@deprecated) {
1277 print $fh <<~"EOT";
1278
1279 C<B<DEPRECATED!>> It is planned to remove $list
1280 from a future release of Perl. Do not use $it for
1281 new code; remove $it from existing code.
1282 EOT
1283 }
1284 else {
1285 print $fh <<~"EOT";
1286
1287 NOTE: $list $is B<experimental> and may change or be
1288 removed without notice.
1289 EOT
1290 }
783469eb 1291 }
54c193ae 1292 }
94bdecf9 1293
783469eb
KW
1294 chomp $pod; # Make sure prints pod with a single trailing \n
1295 print $fh "\n", $pod, "\n";
3cfa66c4 1296
783469eb
KW
1297 for my $item (@items) {
1298 my $item_flags = $item->{flags};
1299 my $item_name = $item->{name};
3cfa66c4 1300
783469eb
KW
1301 print $fh "\nNOTE: the C<perl_$item_name()> form is B<deprecated>.\n"
1302 if $item_flags =~ /O/;
1303 # Is Perl_, but no #define foo # Perl_foo
1304 if (($item_flags =~ /p/ && $item_flags =~ /o/ && $item_flags !~ /M/)
1305
1306 # Can't handle threaded varargs
1307 || ($item_flags =~ /f/ && $item_flags !~ /T/))
1308 {
1309 $item->{name} = "Perl_$item_name";
1310 print $fh <<~"EOT";
1311
1312 NOTE: C<$item_name> must be explicitly called as
1313 C<$item->{name}>
1314 EOT
1315 print $fh "with an C<aTHX_> parameter" if $item_flags !~ /T/;
1316 print $fh ".\n";
1317 }
1318 }
94bdecf9 1319
9e728159
KW
1320 if ($flags =~ /[Uy]/) { # no usage; typedefs are considered simple enough
1321 # to never warrant a usage line
1322 warn("U and s flags are incompatible")
1323 if $flags =~ /U/ && $flags =~ /s/;
20046047 1324 # nothing
05ca4832 1325 } else {
783469eb
KW
1326
1327 print $fh "\n=over $usage_indent\n";
1328
00d68f0d
KW
1329 if (defined $docref->{usage}) { # An override of the usage section
1330 print $fh "\n", ($docref->{usage} =~ s/^/ /mrg), "\n";
1331 }
783469eb
KW
1332 else {
1333
8d1c4423
KW
1334 # Add the thread context formal parameter on expanded-out names
1335 for my $item (@items) {
1336 unshift $item->{args}->@*, (($item->{args}->@*)
1337 ? "pTHX_"
1338 : "pTHX")
1339 if $item->{flags} !~ /T/
1340 && $item->{name} =~ /^Perl_/;
1341 }
1342
783469eb 1343 # Look through all the items in this entry. If all have the same
4be56a7d
KW
1344 # return type and arguments (including thread context), only the
1345 # main entry is displayed.
783469eb
KW
1346 # Also, find the longest return type and longest name so that if
1347 # multiple ones are shown, they can be vertically aligned nicely
783469eb 1348 my $need_individual_usage = 0;
53c9fbf2 1349 my $longest_name_length = length $items[0]->{name};
783469eb 1350 my $base_ret_type = $items[0]->{ret_type};
53c9fbf2 1351 my $longest_ret = length $base_ret_type;
783469eb 1352 my @base_args = $items[0]->{args}->@*;
4be56a7d 1353 my $base_thread_context = $items[0]->{flags} =~ /T/;
53c9fbf2 1354 for (my $i = 1; $i < @items; $i++) {
783469eb 1355 no warnings 'experimental::smartmatch';
53c9fbf2 1356 my $item = $items[$i];
783469eb
KW
1357 $need_individual_usage = 1
1358 if $item->{ret_type} ne $base_ret_type
4be56a7d
KW
1359 || ! ($item->{args}->@* ~~ @base_args)
1360 || ( $item->{flags} =~ /T/
1361 != $base_thread_context);
783469eb
KW
1362 my $ret_length = length $item->{ret_type};
1363 $longest_ret = $ret_length if $ret_length > $longest_ret;
1364 my $name_length = length $item->{name};
1365 $longest_name_length = $name_length
1366 if $name_length > $longest_name_length;
1ded1f42 1367 }
783469eb
KW
1368
1369 # If we're only showing one entry, only its length matters.
1370 $longest_name_length = length($items[0]->{name})
1371 unless $need_individual_usage;
1372 print $fh "\n";
1373
1374 my $indent = 1; # 1 is sufficient for verbatim; =over is used
1375 # for more
1376 my $ret_name_sep_length = 2; # spaces between return type and name
1377 my $name_indent = $indent + $longest_ret;
1378 $name_indent += $ret_name_sep_length if $longest_ret;
1379
ca711307
KW
1380 my $this_max_width =
1381 $max_width - $description_indent - $usage_indent;
1382
783469eb
KW
1383 for my $item (@items) {
1384 my $ret_type = $item->{ret_type};
1385 my @args = $item->{args}->@*;
1386 my $name = $item->{name};
1387 my $item_flags = $item->{flags};
1388
783469eb
KW
1389 # The return type
1390 print $fh (" " x $indent), $ret_type;
1391
1392 print $fh " " x ( $ret_name_sep_length
1393 + $longest_ret - length $ret_type);
1394 print $fh $name;
1395
1396 if ($item_flags =~ /n/) { # no args
1397 warn("$file: $element_name: n flag without m")
1398 unless $item_flags =~ /m/;
1399 warn("$file: $name: n flag but apparently has args")
1400 if @args;
1401 }
1402 else {
1403 # +1 for the '('
1404 my $arg_indent = $name_indent + $longest_name_length + 1;
1405
1406 # Align the argument lists of the items
1407 print $fh " " x ($longest_name_length - length($name));
1408 print $fh "(";
1409
1410 # Display as many of the arguments on the same line as
1411 # will fit.
1412 my $total_length = $arg_indent;
1413 my $first_line = 1;
1414 for (my $i = 0; $i < @args; $i++) {
1415 my $arg = $args[$i];
1416 my $arg_length = length($arg);
1417
1418 # All but the first arg are preceded by a blank
1419 my $use_blank = $i > 0;
1420
1421 # +1 here and below because either the argument has a
1422 # trailing comma or trailing ')'
1423 $total_length += $arg_length + $use_blank + 1;
1424
1425 # We want none of the arguments to be positioned so
1426 # they extend too far to the right. Ideally, they
1427 # should all start in the same column as the arguments
1428 # on the first line of the function display do. But, if
1429 # necessary, outdent them so that they all start in
1430 # another column, with the longest ending at the right
1431 # margin, like so:
1432 # void function_name(pTHX_ short1,
1433 # short2,
1434 # very_long_argument,
1435 # short3)
ca711307 1436 if ($total_length > $this_max_width) {
783469eb
KW
1437
1438 # If this is the first continuation line,
1439 # calculate the longest argument; this will be the
1440 # one we may have to outdent for.
1441 if ($first_line) {
1442 $first_line = 0;
1443
1444 # We will need at least as much as the current
1445 # argument
1446 my $longest_arg_length = $arg_length
1447 + $use_blank + 1;
1448
1449 # Look through the rest of the args to see if
1450 # any are longer than this one.
1451 for (my $j = $i + 1; $j < @args; $j++) {
1452
1453 # Include the trailing ',' or ')' in the
1454 # length. No need to concern ourselves
1455 # with a leading blank, as the argument
1456 # would be positioned first on the next
1457 # line
1458 my $peek_arg_length = length ($args[$j])
1459 + 1;
1460 $longest_arg_length = $peek_arg_length
1461 if $peek_arg_length > $longest_arg_length;
1462 }
1463
1464 # Calculate the new indent if necessary.
ca711307
KW
1465 $arg_indent =
1466 $this_max_width - $longest_arg_length
783469eb 1467 if $arg_indent + $longest_arg_length
ca711307 1468 > $this_max_width;
783469eb
KW
1469 }
1470
1471 print $fh "\n", (" " x $arg_indent);
1472 $total_length = $arg_indent + $arg_length + 1;
1473 $use_blank = 0;
1474 }
1475
1476 # Display this argument
1477 print $fh " " if $use_blank;
1478 print $fh $arg;
1479 print $fh "," if $i < @args - 1 && $args[$i] ne 'pTHX_';
1480
1481 } # End of loop through args
1482
1483 print $fh ")";
1ded1f42 1484 }
783469eb
KW
1485
1486 print $fh ";" if $item_flags =~ /s/; # semicolon: "dTHR;"
1487 print $fh "\n";
1488
1489 # Only the first entry is normally displayed
1490 last unless $need_individual_usage;
1ded1f42 1491 }
1ded1f42 1492 }
783469eb
KW
1493
1494 print $fh "\n=back\n";
94bdecf9 1495 }
783469eb
KW
1496
1497 print $fh "\n=back\n";
63da8140 1498 print $fh "\n=for hackers\nFound in file $file\n";
94bdecf9
JH
1499}
1500
02c5183e
KW
1501sub construct_missings_section {
1502 my ($pod_name, $missings_ref) = @_;
1503 my $text = "";
1504
1505 return $text unless $missings_ref->@*;
1506
1507 $text .= <<~EOT;
d5c04b1e 1508
55d5a9fe 1509 =head1 $undocumented_scn
02c5183e
KW
1510
1511 EOT
1512 if ($pod_name eq 'perlapi') {
1513 $text .= <<~'EOT';
1514 The following functions have been flagged as part of the public
1515 API, but are currently undocumented. Use them at your own risk,
1516 as the interfaces are subject to change. Functions that are not
1517 listed in this document are not intended for public use, and
1518 should NOT be used under any circumstances.
1519
1520 If you feel you need to use one of these functions, first send
1521 email to L<perl5-porters@perl.org|mailto:perl5-porters@perl.org>.
1522 It may be that there is a good reason for the function not being
1523 documented, and it should be removed from this list; or it may
1524 just be that no one has gotten around to documenting it. In the
1525 latter case, you will be asked to submit a patch to document the
1526 function. Once your patch is accepted, it will indicate that the
1527 interface is stable (unless it is explicitly marked otherwise) and
1528 usable by you.
1529 EOT
1530 }
1531 else {
1532 $text .= <<~'EOT';
1533 The following functions are currently undocumented. If you use
1534 one of them, you may wish to consider creating and submitting
1535 documentation for it.
1536 EOT
1537 }
1538
c7a2af98 1539 $text .= "\n" . format_pod_indexes($missings_ref);
e4f5ddf4
KW
1540
1541 # Sort the elements.
1542 my @missings = sort dictionary_order $missings_ref->@*;
1543
e4f5ddf4 1544
c7a2af98 1545 $text .= "\n";
e4f5ddf4
KW
1546
1547 use integer;
1548
1549 # Look through all the elements in the list and see how many columns we
1550 # could place them in the output what will fit in the available width.
1551 my $min_spacer = 2; # Need this much space between columns
1552 my $columns;
1553 my $rows;
1554 my @col_widths;
1555
1556 COLUMN:
1557 # We start with more columns, and work down until we find a number that
1558 # can accommodate all the data. This algorithm doesn't require the
1559 # resulting columns to all have the same width. This can allow for
1560 # as tight of packing as the data will possibly allow.
1561 for ($columns = 7; $columns > 1; $columns--) {
1562
1563 # For this many columns, we will need this many rows (final row might
1564 # not be completely filled)
1565 $rows = (@missings + $columns - 1) / $columns;
1566
1567 my $row_width = 0;
1568 my $i = 0; # Which missing element
1569
1570 # For each column ...
1571 for my $col (0 .. $columns - 1) {
1572
1573 # Calculate how wide the column needs to be, which is based on the
1574 # widest element in it
1575 $col_widths[$col] = 0;
1576
1577 # Look through all the rows to find the widest element
1578 for my $row (0 .. $rows - 1) {
1579
1580 # Skip if this row doesn't have an entry for this column
1581 last if $i >= @missings;
1582
1583 # This entry occupies this many bytes.
1584 my $this_width = length $missings[$i];
1585
1586 # All but the final column need a spacer between it and the
1587 # next column over.
1588 $this_width += $min_spacer if $col < $columns - 1;
1589
1590
1591 # This column will need to have enough width to accommodate
1592 # this element
1593 if ($this_width > $col_widths[$col]) {
1594
1595 # We can't have this many columns if the total width
1596 # exceeds the available; bail now and try fewer columns
1597 next COLUMN if $row_width + $this_width > $max_width;
1598
1599 $col_widths[$col] = $this_width;
1600 }
1601
1602 $i++; # The next row will contain the next item
1603 }
1604
1605 $row_width += $col_widths[$col];
1606 next COLUMN if $row_width > $max_width;
1607 }
1608
1609 # If we get this far, this many columns works
1610 last;
1611 }
1612
1613 # Here, have calculated the number of rows ($rows) and columns ($columns)
1614 # required to list the elements. @col_widths contains the width of each
1615 # column.
1616
1617 $text .= "\n\n=over $description_indent\n\n";
1618
1619 # Assemble the output
1620 for my $row (0 .. $rows - 1) {
1621 for my $col (0 .. $columns - 1) {
1622 $text .= " " if $col == 0; # Indent one to mark as verbatim
1623
1624 my $index = $row + $rows * $col; # Convert 2 dimensions to 1
1625
1626 # Skip if this row doesn't have an entry for this column
1627 next if $index >= @missings;
1628
1629 my $element = $missings[$index];
1630 $text .= $element;
1631
1632 # Add alignment spaces for all but final column
1633 $text .= " " x ($col_widths[$col] - length $element)
1634 if $col < $columns - 1;
1635 }
02c5183e 1636
e4f5ddf4 1637 $text .= "\n"; # End of row
02c5183e
KW
1638 }
1639
1640 $text .= "\n=back\n";
1641
1642 return $text;
1643}
1644
1645sub dictionary_order {
f83c6033
KW
1646 # Do a case-insensitive dictionary sort, with only alphabetics
1647 # significant, falling back to using everything for determinancy
1354d57e 1648 return (uc($a =~ s/[[:^alpha:]]//r) cmp uc($b =~ s/[[:^alpha:]]//r))
f83c6033
KW
1649 || uc($a) cmp uc($b)
1650 || $a cmp $b;
1651}
1652
7b73ff98 1653sub output {
d5c04b1e 1654 my ($podname, $header, $dochash, $missings_ref, $footer) = @_;
6a4c4cd4
DM
1655 #
1656 # strip leading '|' from each line which had been used to hide
1657 # pod from pod checkers.
1658 s/^\|//gm for $header, $footer;
1659
7882b24a 1660 my $fh = open_new("pod/$podname.pod", undef,
20046047 1661 {by => "$0 extracting documentation",
f1f44974 1662 from => 'the C source files'}, 1);
e0492643 1663
63da8140 1664 print $fh $header, "\n";
e0492643 1665
02c5183e 1666 for my $section_name (sort dictionary_order keys %valid_sections) {
7a997878 1667 my $section_info = $dochash->{$section_name};
36ea2d2f 1668
5781dcac
KW
1669 # We allow empty sections in perlintern.
1670 if (! $section_info && $podname eq 'perlapi') {
36ea2d2f 1671 warn "Empty section '$section_name'; skipped";
36ea2d2f
KW
1672 next;
1673 }
1674
63da8140
KW
1675 print $fh "\n=head1 $section_name\n";
1676
5781dcac
KW
1677 if ($podname eq 'perlapi') {
1678 print $fh "\n", $valid_sections{$section_name}{header}, "\n"
1679 if defined $valid_sections{$section_name}{header};
151c3fe5 1680
5781dcac
KW
1681 # Output any heading-level documentation and delete so won't get in
1682 # the way later
1683 if (exists $section_info->{""}) {
1684 print $fh "\n", $section_info->{""}, "\n";
1685 delete $section_info->{""};
1686 }
151c3fe5 1687 }
151c3fe5 1688
74ab7b79 1689 if ($section_info && keys $section_info->%*) {
02c5183e 1690 for my $function_name (sort dictionary_order keys %$section_info) {
5781dcac
KW
1691 docout($fh, $function_name, $section_info->{$function_name});
1692 }
1693 }
1694 else {
1695 print $fh "\nThere are only public API items currently in $section_name\n";
20046047 1696 }
00b0fb83
KW
1697
1698 print $fh "\n", $valid_sections{$section_name}{footer}, "\n"
5781dcac
KW
1699 if $podname eq 'perlapi'
1700 && defined $valid_sections{$section_name}{footer};
7b73ff98
NC
1701 }
1702
d5c04b1e 1703 print $fh construct_missings_section($podname, $missings_ref);
63da8140
KW
1704
1705 print $fh "\n$footer\n=cut\n";
5a0155e6 1706
7882b24a 1707 read_only_bottom_close_and_rename($fh);
cd093254
MM
1708}
1709
e8e591c9
NC
1710foreach (@{(setup_embed())[0]}) {
1711 next if @$_ < 2;
b1cb8a49 1712 my ($flags, $ret_type, $func, @args) = @$_;
e8e591c9 1713 s/\b(?:NN|NULLOK)\b\s+//g for @args;
bc350081 1714
5ce57792 1715 $funcflags{$func} = {
20046047 1716 flags => $flags,
b1cb8a49 1717 ret_type => $ret_type,
20046047
KE
1718 args => \@args,
1719 };
5ce57792
NC
1720}
1721
5ce57792
NC
1722# glob() picks up docs from extra .c or .h files that may be in unclean
1723# development trees.
741c0772
NC
1724open my $fh, '<', 'MANIFEST'
1725 or die "Can't open MANIFEST: $!";
1726while (my $line = <$fh>) {
b87d9527 1727 next unless my ($file) = $line =~ /^(\S+\.(?:[ch]|pod))\t/;
5ce57792 1728
e10306bf
KW
1729 # Don't pick up pods from these.
1730 next if $file =~ m! ^ ( cpan | dist | ext ) / !x
1731 && ! defined $extra_input_pods{$file};
7cb0b6c4 1732
1ae6ead9 1733 open F, '<', $file or die "Cannot open $file for docs: $!\n";
5ce57792
NC
1734 autodoc(\*F,$file);
1735 close F or die "Error closing $file: $!\n";
1736}
741c0772 1737close $fh or die "Error whilst reading MANIFEST: $!";
5ce57792 1738
00d68f0d
KW
1739parse_config_h();
1740
5ce57792
NC
1741for (sort keys %funcflags) {
1742 next unless $funcflags{$_}{flags} =~ /d/;
6523e108 1743 next if $funcflags{$_}{flags} =~ /h/;
573cf2be 1744 warn "no docs for $_\n";
bc350081 1745}
94bdecf9 1746
5ce57792 1747foreach (sort keys %missing) {
5ce57792 1748 warn "Function '$_', documented in $missing{$_}, not listed in embed.fnc";
94bdecf9
JH
1749}
1750
ff5af78d
KW
1751# List of funcs in the public API that aren't also marked as core-only,
1752# experimental nor deprecated.
b87d9527
KW
1753my @missing_api = grep $funcflags{$_}{flags} =~ /A/
1754 && $funcflags{$_}{flags} !~ /[xD]/
1755 && !$docs{api}{$_}, keys %funcflags;
00d68f0d 1756push @missing_api, keys %missing_macros;
a026e430 1757
e10306bf 1758my @other_places = ( qw(perlclib ), keys %described_elsewhere );
ea7c1d7a
KW
1759my $places_other_than_intern = join ", ",
1760 map { "L<$_>" } sort dictionary_order 'perlapi', @other_places;
1761my $places_other_than_api = join ", ",
1762 map { "L<$_>" } sort dictionary_order 'perlintern', @other_places;
a026e430 1763
00d68f0d 1764# The S< > makes things less densely packed, hence more readable
02c5183e
KW
1765my $has_defs_text .= join ",S< > ", map { "C<$_>" } sort dictionary_order @has_defs;
1766my $has_r_defs_text .= join ",S< > ", map { "C<$_>" } sort dictionary_order @has_r_defs;
3951f999
KW
1767$valid_sections{$genconfig_scn}{footer} =~ s/__HAS_LIST__/$has_defs_text/;
1768$valid_sections{$genconfig_scn}{footer} =~ s/__HAS_R_LIST__/$has_r_defs_text/;
00d68f0d 1769
02c5183e 1770my $include_defs_text .= join ",S< > ", map { "C<$_>" } sort dictionary_order @include_defs;
3951f999 1771$valid_sections{$genconfig_scn}{footer} =~ s/__INCLUDE_LIST__/$include_defs_text/;
00d68f0d 1772
55d5a9fe
KW
1773my $section_list = join "\n\n", map { "=item L</$_>" }
1774 sort(dictionary_order keys %valid_sections),
1775 $undocumented_scn; # Keep last
7260d4ba 1776
b87d9527 1777output('perlapi', <<"_EOB_", $docs{api}, \@missing_api, <<"_EOE_");
6a4c4cd4
DM
1778|=encoding UTF-8
1779|
1780|=head1 NAME
1781|
1782|perlapi - autogenerated documentation for the perl public API
1783|
1784|=head1 DESCRIPTION
1785|X<Perl API> X<API> X<api>
1786|
b87d9527
KW
1787|This file contains most of the documentation of the perl public API, as
1788|generated by F<embed.pl>. Specifically, it is a listing of functions,
a026e430
KW
1789|macros, flags, and variables that may be used by extension writers. Besides
1790|L<perlintern> and F<config.h>, some items are listed here as being actually
1791|documented in another pod.
b87d9527 1792|
55d5a9fe 1793|L<At the end|/$undocumented_scn> is a list of functions which have yet
b87d9527
KW
1794|to be documented. Patches welcome! The interfaces of these are subject to
1795|change without notice.
1796|
6927cd44
KW
1797|Some of the functions documented here are consolidated so that a single entry
1798|serves for multiple functions which all do basically the same thing, but have
1799|some slight differences. For example, one form might process magic, while
1800|another doesn't. The name of each variation is listed at the top of the
1801|single entry. But if all have the same signature (arguments and return type)
1802|except for their names, only the usage for the base form is shown. If any
1803|one of the forms has a different signature (such as returning C<const> or
1804|not) every function's signature is explicitly displayed.
7260d4ba 1805|
a026e430
KW
1806|Anything not listed here or in the other mentioned pods is not part of the
1807|public API, and should not be used by extension writers at all. For these
1808|reasons, blindly using functions listed in F<proto.h> is to be avoided when
1809|writing extensions.
6a4c4cd4
DM
1810|
1811|In Perl, unlike C, a string of characters may generally contain embedded
1812|C<NUL> characters. Sometimes in the documentation a Perl string is referred
1813|to as a "buffer" to distinguish it from a C string, but sometimes they are
1814|both just referred to as strings.
1815|
1816|Note that all Perl API global variables must be referenced with the C<PL_>
1817|prefix. Again, those not listed here are not to be used by extension writers,
1818|and can be changed or removed without notice; same with macros.
1819|Some macros are provided for compatibility with the older,
1820|unadorned names, but this support may be disabled in a future release.
1821|
1822|Perl was originally written to handle US-ASCII only (that is characters
1823|whose ordinal numbers are in the range 0 - 127).
1824|And documentation and comments may still use the term ASCII, when
1825|sometimes in fact the entire range from 0 - 255 is meant.
1826|
1827|The non-ASCII characters below 256 can have various meanings, depending on
1828|various things. (See, most notably, L<perllocale>.) But usually the whole
1829|range can be referred to as ISO-8859-1. Often, the term "Latin-1" (or
1830|"Latin1") is used as an equivalent for ISO-8859-1. But some people treat
1831|"Latin1" as referring just to the characters in the range 128 through 255, or
2de859ce 1832|sometimes from 160 through 255.
6a4c4cd4
DM
1833|This documentation uses "Latin1" and "Latin-1" to refer to all 256 characters.
1834|
1835|Note that Perl can be compiled and run under either ASCII or EBCDIC (See
1836|L<perlebcdic>). Most of the documentation (and even comments in the code)
1837|ignore the EBCDIC possibility.
1838|For almost all purposes the differences are transparent.
1839|As an example, under EBCDIC,
1840|instead of UTF-8, UTF-EBCDIC is used to encode Unicode strings, and so
1841|whenever this documentation refers to C<utf8>
1842|(and variants of that name, including in function names),
1843|it also (essentially transparently) means C<UTF-EBCDIC>.
1844|But the ordinals of characters differ between ASCII, EBCDIC, and
1845|the UTF- encodings, and a string encoded in UTF-EBCDIC may occupy a different
1846|number of bytes than in UTF-8.
1847|
6927cd44
KW
1848|The organization of this document is tentative and subject to change.
1849|Suggestions and patches welcome
1850|L<perl5-porters\@perl.org|mailto:perl5-porters\@perl.org>.
1851|
1852|The sections in this document currently are
1853|
1854|=over
1855
1856|$section_list
1857|
1858|=back
1859|
6a4c4cd4 1860|The listing below is alphabetical, case insensitive.
94bdecf9 1861_EOB_
6a4c4cd4
DM
1862|=head1 AUTHORS
1863|
1864|Until May 1997, this document was maintained by Jeff Okamoto
7b1f0a98 1865|<okamoto\@corp.hp.com>. It is now maintained as part of Perl itself.
6a4c4cd4
DM
1866|
1867|With lots of help and suggestions from Dean Roehrich, Malcolm Beattie,
1868|Andreas Koenig, Paul Hudson, Ilya Zakharevich, Paul Marquess, Neil
1869|Bowers, Matthew Green, Tim Bunce, Spider Boardman, Ulrich Pfeifer,
1870|Stephen McCamant, and Gurusamy Sarathy.
1871|
7b1f0a98 1872|API Listing originally by Dean Roehrich <roehrich\@cray.com>.
6a4c4cd4
DM
1873|
1874|Updated to be autogenerated from comments in the source by Benjamin Stuhl.
1875|
1876|=head1 SEE ALSO
1877|
ea7c1d7a 1878|F<config.h>, $places_other_than_api
94bdecf9
JH
1879_EOE_
1880
79fc8511
FC
1881# List of non-static internal functions
1882my @missing_guts =
9f589e47 1883 grep $funcflags{$_}{flags} !~ /[AS]/ && !$docs{guts}{$_}, keys %funcflags;
5a0155e6 1884
7b1f0a98 1885output('perlintern', <<'_EOB_', $docs{guts}, \@missing_guts, <<"_EOE_");
6a4c4cd4
DM
1886|=head1 NAME
1887|
1888|perlintern - autogenerated documentation of purely B<internal>
20046047 1889|Perl functions
6a4c4cd4
DM
1890|
1891|=head1 DESCRIPTION
1892|X<internal Perl functions> X<interpreter functions>
1893|
1894|This file is the autogenerated documentation of functions in the
1895|Perl interpreter that are documented using Perl's internal documentation
1896|format but are not marked as part of the Perl API. In other words,
1897|B<they are not for use in extensions>!
5781dcac
KW
1898
1899|It has the same sections as L<perlapi>, though some may be empty.
6a4c4cd4 1900|
7b1f0a98 1901_EOB_
6a4c4cd4
DM
1902|
1903|=head1 AUTHORS
1904|
1905|The autodocumentation system was originally added to the Perl core by
1906|Benjamin Stuhl. Documentation is by whoever was kind enough to
1907|document their functions.
1908|
1909|=head1 SEE ALSO
1910|
ea7c1d7a 1911|F<config.h>, $places_other_than_intern
7b1f0a98 1912_EOE_