4 my $outname = shift || '-';
7 my @funcs = make_func_list();
8 my %funcs = map { $_ => 1 } @funcs;
10 # look for files to parse
12 my @files = grep $_ ne 'Imager.xs', glob '*.c';
14 # scan each file for =item <func>\b
25 for my $file (@files) {
27 or die "Cannot open $file for documentation: $!\n";
29 if (/^=item (\w+)\b/ && $funcs{$1}) {
34 elsif ($func && /^=(cut|head)/) {
35 if ($funcs{$func}) { # only save the API functions
36 $alldocs{$func} = [ @funcdocs ];
37 $from{$func} = "Line $start in $file";
39 $funccats{$func} = $category;
40 push @{$cats{$category}}, $func;
43 $funcsyns{$func} = $synopsis;
51 if (/^=category (.*)/) {
54 elsif (/^=synopsis (.*)/) {
63 die "Documentation for $func not followed by =cut or =head in $file\n";
68 open OUT, "> $outname"
69 or die "Cannot open $outname: $!";
72 Do not edit this file, it is generated automatically by apidocs.perl
73 from Imager's source files.
75 Each function description has a comment listing the source file and
76 line number where you can find the documentation.
80 Imager::APIRef - Imager's C API.
85 color.rgba.red = 255; color.rgba.green = 0; color.rgba.blue = 255;
86 i_fill_t *fill = i_new_fill_...(...);
90 for my $cat (sort { lc $a cmp lc $b } keys %cats) {
91 print OUT "\n # $cat\n";
92 for my $func (grep $funcsyns{$_}, sort @{$cats{$cat}}) {
93 my $syn = $funcsyns{$func};
101 i_fill_destroy(fill);
109 for my $cat (sort { lc $a cmp lc $b } keys %cats) {
110 print OUT "=head2 $cat\n\n=over\n\n";
111 for my $func (sort @{$cats{$cat}}) {
112 print OUT @{$alldocs{$func}}, "\n";
113 print OUT "=for comment\nFrom: $from{$func}\n\n";
114 delete $undoc{$func};
116 print OUT "\n=back\n\n";
119 # see if we have an uncategorized section
120 if (grep $alldocs{$_}, keys %undoc) {
121 print OUT "=head2 Uncategorized functions\n\n=over\n\n";
122 for my $func (sort @funcs) {
123 if ($undoc{$func} && $alldocs{$func}) {
124 print OUT @{$alldocs{$func}}, "\n";
125 print OUT "=for comment\nFrom: $from{$func}\n\n";
126 delete $undoc{$func};
129 print OUT "\n\n=back\n\n";
137 The following API functions are undocumented so far, hopefully this
144 print OUT "=item *\n\nB<$_>\n\n" for sort keys %undoc;
146 print OUT "\n\n=back\n\n";
153 Tony Cook <tony@imager.perl.org>
157 Imager, Imager::ExtUtils, Imager::Inline
167 open FUNCS, "< imexttypes.h"
168 or die "Cannot open imexttypes.h: $!\n";
171 /^typedef struct/ && ++$in_struct;
172 if ($in_struct && /\(\*f_(i_\w+)/) {
175 if (/^\} im_ext_funcs;$/) {
177 or die "Found end of functions structure but not the start";
184 die "Found start of the functions structure but not the end\n";
187 die "Found neither the start nor end of the functions structure\n";