158
158
# unlooked at
159
159
my %protos ;
160
160
161
+ # For outputting an index of the API elements. Each key is an element; its
162
+ # value is the section the element is in.
163
+ my %index ;
164
+
161
165
my $described_in = " Described in" ;
162
166
163
167
my $description_indent = 4;
231
235
232
236
# Kept separate at end
233
237
my $undocumented_scn = ' Undocumented elements' ;
238
+ my $index_scn = ' INDEX' ;
234
239
235
240
my %valid_sections = (
236
241
$AV_scn => {},
@@ -479,10 +484,11 @@ ($file, $line_num = 0)
479
484
return " at $file , line $line_num " ;
480
485
}
481
486
482
- sub check_and_add_proto_defn {
483
- my ($element , $file , $line_num , $raw_flags , $ret_type , $args_ref ,
484
- $definition_type
485
- ) = @_ ;
487
+ sub check_and_add_proto_defn ($element , $file , $line_num , $destpod , $section ,
488
+ $raw_flags , $ret_type , $args_ref ,
489
+ $definition_type )
490
+ {
491
+
486
492
487
493
# This function constructs a hash describing what we know so far about the
488
494
# API element '$element', as determined by 'apidoc'-type lines scattered
@@ -620,6 +626,16 @@ sub check_and_add_proto_defn {
620
626
else {
621
627
$elements {$element }{docs_found }{file } = $file ;
622
628
$elements {$element }{docs_found }{line_num } = $line_num // 0;
629
+ $elements {$element }{docs_found }{section } = $section ;
630
+
631
+ if (! $destpod ) {
632
+ my $this_flags = $elements {$element }{flags }
633
+ || $flags_sans_d ;
634
+ $destpod = destination_pod($this_flags );
635
+ }
636
+
637
+ $elements {$element }{destpod } = $destpod ;
638
+ $index {$destpod }{$element } = $section ;
623
639
}
624
640
625
641
if ($definition_type == PLAIN_APIDOC) {
@@ -758,7 +774,7 @@ ($file, $line_num, $input, $is_file_C)
758
774
EOS
759
775
}
760
776
761
- sub handle_apidoc_line ($file , $line_num , $type , $arg ) {
777
+ sub handle_apidoc_line ($file , $line_num , $destpod , $section , $ type , $arg ) {
762
778
763
779
# This just does a couple of checks that would otherwise have to be
764
780
# duplicated in the calling code, and calls check_and_add_proto_defn() to
@@ -792,10 +808,12 @@ ($file, $line_num, $type, $arg)
792
808
# this definition (which has the side effect of cleaning up any NN or
793
809
# NULLOK in @args)
794
810
my $updated = check_and_add_proto_defn($name , $file , $line_num ,
811
+ $destpod , $section ,
795
812
796
813
# The fact that we have this line somewhere in the source
797
814
# code means we implicitly have the 'd' flag
798
815
$flags . " d" ,
816
+
799
817
$ret_type , \@args ,
800
818
$type );
801
819
@@ -899,7 +917,8 @@ ($fh, $file)
899
917
. " '$arg ' " . where_from_string($file , $line_num );
900
918
}
901
919
elsif ($outer_line_type == APIDOC_DEFN) {
902
- handle_apidoc_line($file , $line_num , $outer_line_type , $arg );
920
+ handle_apidoc_line($file , $line_num , $destpod , $section ,
921
+ $outer_line_type , $arg );
903
922
next ; # 'handle_apidoc_line' handled everything for this type
904
923
}
905
924
elsif ($outer_line_type == APIDOC_SECTION) {
@@ -920,9 +939,10 @@ ($fh, $file)
920
939
# Drop down to accumulate the heading text for this section.
921
940
}
922
941
elsif ($outer_line_type == PLAIN_APIDOC) {
923
- my $leader_ref =
924
- handle_apidoc_line($file , $line_num , $outer_line_type , $arg );
925
- $destpod = destination_pod($$leader_ref -> {flags });
942
+ my $leader_ref = handle_apidoc_line($file , $line_num ,
943
+ undef , $section ,
944
+ $outer_line_type , $arg );
945
+ $destpod = $$leader_ref -> {destpod };
926
946
927
947
push @items , $leader_ref ;
928
948
@@ -944,8 +964,9 @@ ($fh, $file)
944
964
# separating 'apidoc_item' lines
945
965
$text = " " ;
946
966
947
- my $item_ref =
948
- handle_apidoc_line($file , $line_num , $item_line_type , $arg );
967
+ my $item_ref = handle_apidoc_line($file , $line_num ,
968
+ $destpod , $section ,
969
+ $item_line_type , $arg );
949
970
950
971
push @items , $item_ref ;
951
972
}
@@ -1563,6 +1584,7 @@ sub parse_config_h {
1563
1584
$flags .= ' U' unless defined $configs {$name }{usage };
1564
1585
my $data = check_and_add_proto_defn($name , $config_h ,
1565
1586
$configs {$name }{defn_line_num },
1587
+ $api , $section ,
1566
1588
$flags ,
1567
1589
" void" , # No return type
1568
1590
[],
@@ -2336,6 +2358,65 @@ ($destpod)
2336
2358
print $fh construct_missings_section($hdr , $ref );
2337
2359
}
2338
2360
2361
+ print $fh <<~EOT ;
2362
+
2363
+ =head1 $index_scn
2364
+
2365
+ Below is an alphabetical list of all API elements in this file,
2366
+ cross referenced to the section in which they are documented.
2367
+
2368
+ EOT
2369
+
2370
+ # Find the longest element name
2371
+ my %this_index = $index {$podname }-> %*;
2372
+ my $max_element_width = 0;
2373
+
2374
+ foreach my $element (keys %this_index ) {
2375
+ $max_element_width = length $element
2376
+ if length $element > $max_element_width ;
2377
+ }
2378
+
2379
+ my $space = " " ;
2380
+ my $column2_indent = $max_element_width + 1 + 1; # 1 space between; +1
2381
+ # verbatim indent
2382
+ my $column2_width = $max_width - $column2_indent ;
2383
+
2384
+ my %column2_text ; # Maps section names to their formatted texts, so only
2385
+ # have to calculate once
2386
+
2387
+ foreach my $element (sort dictionary_order keys %this_index ) {
2388
+ print $fh " " , $element , " " x ($column2_indent - length ($element ) - 1);
2389
+ my $section_name = $this_index {$element };
2390
+
2391
+ # Calculate the formatted 2nd column if haven't already done so.
2392
+ if (! $column2_text {$section_name }) {
2393
+ my $remaining = $section_name ;
2394
+
2395
+ # Split into as many rows as necessary so each fits in the
2396
+ # available space
2397
+ while (length $remaining > $column2_width ) {
2398
+
2399
+ # Find the rightmost space in the portion that fits
2400
+ my $split_pos = rindex $remaining , " " , $column2_width ;
2401
+
2402
+ # And split off a row there.
2403
+ my $this_row = substr $remaining , 0, $split_pos ;
2404
+ $remaining = substr $remaining , $split_pos + 1;
2405
+
2406
+ # Add this row to the formatted text, and prepare for
2407
+ # indenting the next line
2408
+ $column2_text {$section_name } .= $this_row
2409
+ . " \n "
2410
+ . " " x $column2_indent ;
2411
+ }
2412
+
2413
+ # The remaining fits in the final row.
2414
+ $column2_text {$section_name } .= $remaining . " \n " ;
2415
+ }
2416
+
2417
+ print $fh $column2_text {$section_name };
2418
+ }
2419
+
2339
2420
print $fh " \n $destpod ->{footer}\n =cut\n " ;
2340
2421
2341
2422
read_only_bottom_close_and_rename($fh );
@@ -2350,7 +2431,10 @@ ($destpod)
2350
2431
@{$embed }{qw( flags return_type name args) };
2351
2432
check_and_add_proto_defn($func , $file ,
2352
2433
# embed.fnc data doesn't currently furnish the
2353
- # line number
2434
+ # line number; and we have no section in the
2435
+ # documente yet
2436
+ undef ,
2437
+ undef ,
2354
2438
undef ,
2355
2439
2356
2440
$flags , $ret_type , $args ,
@@ -2593,7 +2677,8 @@ ($destpod)
2593
2677
2594
2678
my $section_list = join " \n\n " , map { " =item L</$_ >" }
2595
2679
sort (dictionary_order keys %valid_sections ),
2596
- $undocumented_scn ; # Keep last
2680
+ $undocumented_scn , # Keep next-to-last
2681
+ $index_scn ; # Keep last
2597
2682
2598
2683
# Leading '|' is to hide these lines from pod checkers. khw is unsure if this
2599
2684
# is still needed.
@@ -2613,9 +2698,9 @@ ($destpod)
2613
2698
|L<perlintern> and F<$config_h >, some items are listed here as being actually
2614
2699
|documented in another pod.
2615
2700
|
2616
- |L<At the end |/$undocumented_scn > is a list of functions which have yet
2617
- |to be documented. Patches welcome! The interfaces of these are subject to
2618
- |change without notice.
2701
+ |L<Just before the index |/$undocumented_scn > is a list of functions which have
2702
+ |yet to be documented. Patches welcome! The interfaces of these are subject
2703
+ |to change without notice.
2619
2704
|
2620
2705
|Some of the functions documented here are consolidated so that a single entry
2621
2706
|serves for multiple functions which all do basically the same thing, but have
0 commit comments