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,24 @@ ($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
+ my %this_index = $index {$podname }-> %*;
2371
+ my $space = " E<nbsp>" x 4 ;
2372
+
2373
+ print $fh " =over 1\n\n " ;
2374
+ foreach my $element (sort dictionary_order keys %this_index ) {
2375
+ print $fh " =item L</$element >${space} L</$this_index {$element }>\n\n " ;
2376
+ }
2377
+ print $fh " =back\n\n " ;
2378
+
2339
2379
print $fh " \n $destpod ->{footer}\n =cut\n " ;
2340
2380
2341
2381
read_only_bottom_close_and_rename($fh );
@@ -2350,7 +2390,10 @@ ($destpod)
2350
2390
@{$embed }{qw( flags return_type name args) };
2351
2391
check_and_add_proto_defn($func , $file ,
2352
2392
# embed.fnc data doesn't currently furnish the
2353
- # line number
2393
+ # line number; and we have no section in the
2394
+ # documente yet
2395
+ undef ,
2396
+ undef ,
2354
2397
undef ,
2355
2398
2356
2399
$flags , $ret_type , $args ,
@@ -2593,7 +2636,8 @@ ($destpod)
2593
2636
2594
2637
my $section_list = join " \n\n " , map { " =item L</$_ >" }
2595
2638
sort (dictionary_order keys %valid_sections ),
2596
- $undocumented_scn ; # Keep last
2639
+ $undocumented_scn , # Keep next-to-last
2640
+ $index_scn ; # Keep last
2597
2641
2598
2642
# Leading '|' is to hide these lines from pod checkers. khw is unsure if this
2599
2643
# is still needed.
@@ -2613,9 +2657,9 @@ ($destpod)
2613
2657
|L<perlintern> and F<$config_h >, some items are listed here as being actually
2614
2658
|documented in another pod.
2615
2659
|
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.
2660
+ |L<Just before the index |/$undocumented_scn > is a list of functions which have
2661
+ |yet to be documented. Patches welcome! The interfaces of these are subject
2662
+ |to change without notice.
2619
2663
|
2620
2664
|Some of the functions documented here are consolidated so that a single entry
2621
2665
|serves for multiple functions which all do basically the same thing, but have
0 commit comments