4 # gtk-doc - GTK DocBook documentation generator.
5 # Copyright (C) 1998 Damon Chaplin
6 # 2007,2008 Stefan Kost
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #############################################################################
24 # Script : gtkdoc-mkdb
25 # Description : This creates the DocBook files from the edited templates.
27 # NOTE: When creating SGML IDS, we append ":CAPS" to all
28 # all-caps identifiers to prevent name clashes. (It basically
29 # never is the case that mixed-case identifiers would collide.)
30 # See the CreateValidSGMLID function.
31 #############################################################################
36 unshift @INC, '@PACKAGE_DATA_DIR@';
37 require "gtkdoc-common.pl";
41 # name of documentation module
46 my $SOURCE_SUFFIXES = "";
47 my $IGNORE_FILES = "";
50 my $OUTPUT_ALL_SYMBOLS;
52 my $EXPAND_CONTENT_FILES = "";
54 my $DEFAULT_STABILITY;
59 my %optctl = ('module' => \$MODULE,
60 'source-dir' => \@SOURCE_DIRS,
61 'source-suffixes' => \$SOURCE_SUFFIXES,
62 'ignore-files' => \$IGNORE_FILES,
63 'output-dir' => \$SGML_OUTPUT_DIR,
64 'tmpl-dir' => \$TMPL_DIR,
65 'version' => \$PRINT_VERSION,
66 'help' => \$PRINT_HELP,
67 'main-sgml-file' => \$MAIN_SGML_FILE,
68 'expand-content-files' => \$EXPAND_CONTENT_FILES,
69 'outputallsymbols' => \$OUTPUT_ALL_SYMBOLS,
70 'sgml-mode' => \$SGML_MODE,
71 'default-stability' => \$DEFAULT_STABILITY,
72 'default-includes' => \$DEFAULT_INCLUDES,
73 'output-format' => \$OUTPUT_FORMAT,
74 'name-space' => \$NAME_SPACE);
75 GetOptions(\%optctl, "module=s", "source-dir:s", "source-suffixes:s",
76 "ignore-files:s", "output-dir:s", "tmpl-dir:s", "version", "outputallsymbols",
77 "expand-content-files:s", "main-sgml-file:s", "extra-db-files:s", "help",
78 "sgml-mode", "default-stability:s", "default-includes:s", "output-format:s",
90 if ($DEFAULT_STABILITY && $DEFAULT_STABILITY ne "Stable"
91 && $DEFAULT_STABILITY ne "Private" && $DEFAULT_STABILITY ne "Unstable") {
97 gtkdoc-mkdb version @VERSION@
99 --module=MODULE_NAME Name of the doc module being parsed
100 --source-dir=DIRNAME Directories which contain inline reference material
101 --source-suffixes=SUFFIXES Suffixes of source files to scan, comma-separated
102 --ignore-files=FILES Files or directories which should not be scanned
103 May be used more than once for multiple directories
104 --output-dir=DIRNAME Directory to put the generated DocBook files in
105 --tmpl-dir=DIRNAME Directory in which template files may be found
106 --main-sgml-file=FILE File containing the toplevel DocBook file.
107 --expand-content-files=FILES Extra DocBook files to expand abbreviations in.
108 --output-format=FORMAT Format to use for the generated docbook, XML or SGML.
109 --sgml-mode Allow DocBook markup in inline documentation.
110 --default-stability=LEVEL Specify default stability Level. Valid values are
111 Stable, Unstable, or Private.
112 --default-includes=FILENAMES Specify default includes for section Synopsis
113 --name-space=NS Omit namespace in index.
114 --version Print the version of this program
115 --help Print this help
120 my ($empty_element_end, $doctype_header);
122 if (lc($OUTPUT_FORMAT) eq "xml") {
123 if (!$MAIN_SGML_FILE) {
124 # backwards compatibility
125 if (-e "${MODULE}-docs.sgml") {
126 $MAIN_SGML_FILE="${MODULE}-docs.sgml";
128 $MAIN_SGML_FILE="${MODULE}-docs.xml";
131 $OUTPUT_FORMAT = "xml";
132 $empty_element_end = "/>";
134 if (-e $MAIN_SGML_FILE) {
135 open(INPUT, "<$MAIN_SGML_FILE") || die "Can't open $MAIN_SGML_FILE";
136 $doctype_header = "";
138 if (/^\s*<(book|chapter|article)/) {
139 if ($_ !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/) {
140 $doctype_header = "";
144 $doctype_header .= $_;
149 "<?xml version=\"1.0\"?>\n" .
150 "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook XML V4.3//EN\"\n" .
151 " \"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd\">\n";
153 $doctype_header =~ s/<!DOCTYPE \w+/<!DOCTYPE refentry/;
155 if (!$MAIN_SGML_FILE) {
156 $MAIN_SGML_FILE="${MODULE}-docs.sgml";
158 $OUTPUT_FORMAT = "sgml";
159 $doctype_header = "";
160 $empty_element_end = ">";
165 # All the files are written in subdirectories beneath here.
166 $TMPL_DIR = $TMPL_DIR ? $TMPL_DIR : "$ROOT_DIR/tmpl";
168 # This is where we put all the DocBook output.
169 $SGML_OUTPUT_DIR = $SGML_OUTPUT_DIR ? $SGML_OUTPUT_DIR : "$ROOT_DIR/$OUTPUT_FORMAT";
171 # This file contains the object hierarchy.
172 my $OBJECT_TREE_FILE = "$ROOT_DIR/$MODULE.hierarchy";
174 # This file contains the interfaces.
175 my $INTERFACES_FILE = "$ROOT_DIR/$MODULE.interfaces";
177 # This file contains the prerequisites.
178 my $PREREQUISITES_FILE = "$ROOT_DIR/$MODULE.prerequisites";
180 # This file contains signal arguments and names.
181 my $SIGNALS_FILE = "$ROOT_DIR/$MODULE.signals";
183 # The file containing Arg information.
184 my $ARGS_FILE = "$ROOT_DIR/$MODULE.args";
186 # These global arrays store information on signals. Each signal has an entry
187 # in each of these arrays at the same index, like a multi-dimensional array.
188 my @SignalObjects; # The GtkObject which emits the signal.
189 my @SignalNames; # The signal name.
190 my @SignalReturns; # The return type.
191 my @SignalFlags; # Flags for the signal
192 my @SignalPrototypes; # The rest of the prototype of the signal handler.
194 # These global arrays store information on Args. Each Arg has an entry
195 # in each of these arrays at the same index, like a multi-dimensional array.
196 my @ArgObjects; # The GtkObject which has the Arg.
197 my @ArgNames; # The Arg name.
198 my @ArgTypes; # The Arg type - gint, GtkArrowType etc.
199 my @ArgFlags; # How the Arg can be used - readable/writable etc.
200 my @ArgNicks; # The nickname of the Arg.
201 my @ArgBlurbs; # Docstring of the Arg.
202 my @ArgDefaults; # Default value of the Arg.
203 my @ArgRanges; # The range of the Arg type
204 # These global hashes store declaration info keyed on a symbol name.
206 my %DeclarationTypes;
207 my %DeclarationConditional;
208 my %DeclarationOutput;
212 my %StructHasTypedef;
214 # These global hashes store the existing documentation.
218 my %SymbolSourceFile;
219 my %SymbolSourceLine;
221 # These global hashes store documentation scanned from the source files.
222 my %SourceSymbolDocs;
223 my %SourceSymbolParams;
224 my %SourceSymbolSourceFile;
225 my %SourceSymbolSourceLine;
227 # all documentation goes in here, so we can do coverage analysis
229 my %AllIncompleteSymbols;
230 my %AllDocumentedSymbols;
232 # Undeclared yet documented symbols
233 my %UndeclaredSymbols;
235 # These global arrays store GObject, subclasses and the hierarchy.
242 # holds the symbols which are mentioned in $MODULE-sections.txt
245 # collects index entries
246 my %IndexEntriesFull;
247 my %IndexEntriesSince;
248 my %IndexEntriesDeprecated;
250 # Standard C preprocessor directives, which we ignore for '#' abbreviations.
251 my %PreProcessorDirectives;
252 $PreProcessorDirectives{"assert"} = 1;
253 $PreProcessorDirectives{"define"} = 1;
254 $PreProcessorDirectives{"elif"} = 1;
255 $PreProcessorDirectives{"else"} = 1;
256 $PreProcessorDirectives{"endif"} = 1;
257 $PreProcessorDirectives{"error"} = 1;
258 $PreProcessorDirectives{"if"} = 1;
259 $PreProcessorDirectives{"ifdef"} = 1;
260 $PreProcessorDirectives{"ifndef"} = 1;
261 $PreProcessorDirectives{"include"} = 1;
262 $PreProcessorDirectives{"line"} = 1;
263 $PreProcessorDirectives{"pragma"} = 1;
264 $PreProcessorDirectives{"unassert"} = 1;
265 $PreProcessorDirectives{"undef"} = 1;
266 $PreProcessorDirectives{"warning"} = 1;
268 # Create the root DocBook output directory if it doens't exist.
269 if (! -e $SGML_OUTPUT_DIR) {
270 mkdir ("$SGML_OUTPUT_DIR", 0777)
271 || die "Can't create directory: $SGML_OUTPUT_DIR";
274 # Function and other declaration output settings.
275 my $RETURN_TYPE_FIELD_WIDTH = 20;
276 my $SYMBOL_FIELD_WIDTH = 36;
277 my $SIGNAL_FIELD_WIDTH = 16;
279 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
280 &ReadSignalsFile ($SIGNALS_FILE);
281 &ReadArgsFile ($ARGS_FILE);
282 &ReadObjectHierarchy;
286 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
287 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
288 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
291 for my $dir (@SOURCE_DIRS) {
292 &ReadSourceDocumentation ($dir);
295 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
297 # If any of the DocBook SGML files have changed, update the timestamp file (so
298 # it can be used for Makefile dependencies).
299 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
302 &OutputDeprecatedIndex;
305 open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
306 || die "Can't create $ROOT_DIR/sgml.stamp: $!";
307 print (TIMESTAMP "timestamp");
311 #############################################################################
312 # Function : OutputObjectList
313 # Description : This outputs the alphabetical list of objects, in a columned
314 # table. FIXME: Currently this also outputs ancestor objects
315 # which may not actually be in this module.
317 #############################################################################
319 sub OutputObjectList {
322 # FIXME: use $OUTPUT_FORMAT
323 # my $old_object_index = "$SGML_OUTPUT_DIR/object_index.$OUTPUT_FORMAT";
324 my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
325 my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
327 open (OUTPUT, ">$new_object_index")
328 || die "Can't create $new_object_index: $!";
330 if (lc($OUTPUT_FORMAT) eq "xml") {
331 my $header = $doctype_header;
333 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE informaltable/;
334 print (OUTPUT "$header");
337 print (OUTPUT <<EOF);
338 <informaltable pgwide="1" frame="none">
339 <tgroup cols="$cols">
340 <colspec colwidth="1*"${empty_element_end}
341 <colspec colwidth="1*"${empty_element_end}
342 <colspec colwidth="1*"${empty_element_end}
348 foreach $object (sort (@Objects)) {
349 my $xref = &MakeXRef ($object);
350 if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
351 print (OUTPUT "<entry>$xref</entry>\n");
352 if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
356 # emit an empty row, since empty tables are invalid
357 print (OUTPUT "<row><entry> </entry></row>\n");
360 print (OUTPUT "</row>\n");
363 print (OUTPUT <<EOF);
364 </tbody></tgroup></informaltable>
368 &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
372 #############################################################################
373 # Function : OutputSGML
374 # Description : This collects the output for each section of the docs, and
375 # outputs each file when the end of the section is found.
376 # Arguments : $file - the $MODULE-sections.txt file which contains all of
377 # the functions/macros/structs etc. being documented, organised
378 # into sections and subsections.
379 #############################################################################
384 #print "Reading: $file\n";
386 || die "Can't open $file: $!";
389 my $book_bottom = "";
390 my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
391 my $section_includes = "";
399 my $signals_synop = "";
400 my $signals_desc = "";
402 my $child_args_synop = "";
403 my $style_args_synop = "";
405 my $child_args_desc = "";
406 my $style_args_desc = "";
409 my $implementations = "";
410 my $prerequisites = "";
412 my @file_objects = ();
416 # merge the source docs, in case there are no templates
417 &MergeSourceDocumentation;
423 } elsif (m/^<SECTION>/) {
431 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
435 } elsif (m/^<SUBSECTION>/) {
437 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
439 #print "Section: $title\n";
441 # We don't want warnings if object & class structs aren't used.
442 $DeclarationOutput{$title} = 1;
443 $DeclarationOutput{"${title}Class"} = 1;
445 } elsif (m/^<FILE>(.*)<\/FILE>/) {
447 if (! defined $templates{$filename}) {
448 if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
449 &MergeSourceDocumentation;
450 $templates{$filename}=$.;
453 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
454 "Previous occurrence on line ".$templates{$filename}.".");
457 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
459 $section_includes = $1;
461 if (defined $DEFAULT_INCLUDES) {
462 &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
469 } elsif (m/^<\/SECTION>/) {
470 if($title eq "" && $filename eq "") {
471 &LogWarning ($file, $., "Section has no title and no file.");
473 # FIXME: one of those would be enough
477 if ($filename eq "") {
480 #print "End of section: $title\n";
482 $filename =~ s/\s/_/g;
484 my $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
485 if (defined ($section_id) && $section_id !~ m/^\s*$/) {
486 # Do nothing. Use section_id as it is.
487 } elsif (&CheckIsObject ($title)) {
488 # GtkObjects use their class name as the ID.
489 $section_id = &CreateValidSGMLID ($title);
491 $section_id = &CreateValidSGMLID ("$MODULE-$title");
494 if ($num_symbols > 0) {
496 if (lc($OUTPUT_FORMAT) eq "xml") {
497 $book_bottom .= " <xi:include href=\"xml/$filename.xml\"/>\n";
499 $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
500 $book_bottom .= " &$section_id;\n";
503 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
504 if ($section_includes) {
505 &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
507 $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
509 if ($section_includes eq "") {
510 $section_includes = $includes;
513 $signals_synop =~ s/^\n*//g;
514 $signals_synop =~ s/\n+$/\n/g;
515 if ($signals_synop ne '') {
516 $signals_synop = <<EOF;
517 <refsect1 id="$section_id.signals" role="signal_proto">
518 <title role="signal_proto.title">Signals</title>
520 ${signals_synop}</synopsis>
523 $signals_desc =~ s/^\n*//g;
524 $signals_desc =~ s/\n+$/\n/g;
525 $signals_desc =~ s/(\s|\n)+$//ms;
526 $signals_desc = <<EOF;
527 <refsect1 id="$section_id.signal-details" role="signals">
528 <title role="signals.title">Signal Details</title>
534 $args_synop =~ s/^\n*//g;
535 $args_synop =~ s/\n+$/\n/g;
536 if ($args_synop ne '') {
538 <refsect1 id="$section_id.properties" role="properties">
539 <title role="properties.title">Properties</title>
541 ${args_synop}</synopsis>
544 $args_desc =~ s/^\n*//g;
545 $args_desc =~ s/\n+$/\n/g;
546 $args_desc =~ s/(\s|\n)+$//ms;
548 <refsect1 id="$section_id.property-details" role="property_details">
549 <title role="property_details.title">Property Details</title>
555 $child_args_synop =~ s/^\n*//g;
556 $child_args_synop =~ s/\n+$/\n/g;
557 if ($child_args_synop ne '') {
558 $args_synop .= <<EOF;
559 <refsect1 id="$section_id.child-properties" role="child_properties">
560 <title role="child_properties.title">Child Properties</title>
562 ${child_args_synop}</synopsis>
565 $child_args_desc =~ s/^\n*//g;
566 $child_args_desc =~ s/\n+$/\n/g;
567 $child_args_desc =~ s/(\s|\n)+$//ms;
569 <refsect1 id="$section_id.child-property-details" role="child_property_details">
570 <title role="child_property_details.title">Child Property Details</title>
576 $style_args_synop =~ s/^\n*//g;
577 $style_args_synop =~ s/\n+$/\n/g;
578 if ($style_args_synop ne '') {
579 $args_synop .= <<EOF;
580 <refsect1 id="$section_id.style-properties" role="style_properties">
581 <title role="style_properties.title">Style Properties</title>
583 ${style_args_synop}</synopsis>
586 $style_args_desc =~ s/^\n*//g;
587 $style_args_desc =~ s/\n+$/\n/g;
588 $style_args_desc =~ s/(\s|\n)+$//ms;
590 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
591 <title role="style_properties_details.title">Style Property Details</title>
597 $hierarchy =~ s/^\n*//g;
598 $hierarchy =~ s/\n+$/\n/g;
599 $hierarchy =~ s/(\s|\n)+$//ms;
600 if ($hierarchy ne "") {
602 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
603 <title role="object_hierarchy.title">Object Hierarchy</title>
609 $interfaces =~ s/^\n*//g;
610 $interfaces =~ s/\n+$/\n/g;
611 $interfaces =~ s/(\s|\n)+$//ms;
612 if ($interfaces ne "") {
614 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
615 <title role="impl_interfaces.title">Implemented Interfaces</title>
621 $implementations =~ s/^\n*//g;
622 $implementations =~ s/\n+$/\n/g;
623 $implementations =~ s/(\s|\n)+$//ms;
624 if ($implementations ne "") {
625 $implementations = <<EOF;
626 <refsect1 id="$section_id.implementations" role="implementations">
627 <title role="implementations.title">Known Implementations</title>
633 $prerequisites =~ s/^\n*//g;
634 $prerequisites =~ s/\n+$/\n/g;
635 $prerequisites =~ s/(\s|\n)+$//ms;
636 if ($prerequisites ne "") {
637 $prerequisites = <<EOF;
638 <refsect1 id="$section_id.prerequisites" role="prerequisites">
639 <title role="prerequisites.title">Prerequisites</title>
645 $derived =~ s/^\n*//g;
646 $derived =~ s/\n+$/\n/g;
647 $derived =~ s/(\s|\n)+$//ms;
648 if ($derived ne "") {
650 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
651 <title role="derived_interfaces.title">Known Derived Interfaces</title>
657 $synopsis =~ s/^\n*//g;
658 $synopsis =~ s/\n+$/\n/g;
659 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
661 \$synopsis, \$details,
662 \$signals_synop, \$signals_desc,
663 \$args_synop, \$args_desc,
664 \$hierarchy, \$interfaces,
666 \$prerequisites, \$derived,
675 $section_includes = "";
679 $child_args_synop = "";
680 $style_args_synop = "";
682 $child_args_desc = "";
683 $style_args_desc = "";
686 $implementations = "";
690 } elsif (m/^(\S+)/) {
692 #print " Symbol: $symbol\n";
694 # FIXME: check for duplicate entries
695 if (! defined $symbols{$symbol}) {
696 my $declaration = $Declarations{$symbol};
697 if (defined ($declaration)) {
698 # We don't want standard macros/functions of GtkObjects,
699 # or private declarations.
700 if ($subsection ne "Standard" && $subsection ne "Private") {
701 if (&CheckIsObject ($symbol)) {
702 push @file_objects, $symbol;
704 my ($synop, $desc) = &OutputDeclaration ($symbol,
706 my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
707 my ($arg_synop, $child_arg_synop, $style_arg_synop,
708 $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
709 my $hier = &GetHierarchy ($symbol);
710 my $ifaces = &GetInterfaces ($symbol);
711 my $impls = &GetImplementations ($symbol);
712 my $prereqs = &GetPrerequisites ($symbol);
713 my $der = &GetDerived ($symbol);
716 $signals_synop .= $sig_synop;
717 $signals_desc .= $sig_desc;
718 $args_synop .= $arg_synop;
719 $child_args_synop .= $child_arg_synop;
720 $style_args_synop .= $style_arg_synop;
721 $args_desc .= $arg_desc;
722 $child_args_desc .= $child_arg_desc;
723 $style_args_desc .= $style_arg_desc;
725 $interfaces .= $ifaces;
726 $implementations .= $impls;
727 $prerequisites .= $prereqs;
731 # Note that the declaration has been output.
732 $DeclarationOutput{$symbol} = 1;
733 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
734 $UndeclaredSymbols{$symbol} = 1;
735 &LogWarning ($file, $., "No declaration found for $symbol.");
738 $symbols{$symbol}=$.;
741 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
742 "Previous occurrence on line ".$symbols{$symbol}.".");
748 &OutputMissingDocumentation;
749 &OutputUndeclaredSymbols;
751 if ($OUTPUT_ALL_SYMBOLS) {
755 for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
756 my $file_changed = &OutputExtraFile ($filename);
762 &OutputBook ($book_top, $book_bottom);
767 #############################################################################
768 # Function : OutputIndex
769 # Description : This writes an indexlist that can be included into the main-
770 # document into an <index> tag.
771 #############################################################################
774 my ($basename, $apiindexref ) = @_;
775 my %apiindex = %{$apiindexref};
776 my $old_index = "$SGML_OUTPUT_DIR/$basename.xml";
777 my $new_index = "$SGML_OUTPUT_DIR/$basename.new";
778 my $lastletter = " ";
783 open (OUTPUT, ">$new_index")
784 || die "Can't create $new_index";
786 my $header = $doctype_header;
787 $header =~ s/<!DOCTYPE \w+/<!DOCTYPE indexdiv/;
789 print (OUTPUT "$header<indexdiv>\n");
791 #print "generate $basename index (".%apiindex." entries)\n";
793 # do a case insensitive sort while chopping off the prefix
795 sort { $$a{kriterium} cmp $$b{kriterium} }
796 map { my $x = uc($_); $x =~ s/^$NAME_SPACE\_?(.*)/$1/i; { kriterium => $x, original => $_, short => $1 } }
799 $symbol = $$hash{original};
800 $short_symbol = $$hash{short};
802 my $xref = &MakeXRef ($symbol);
803 my $curletter = uc(substr($short_symbol,0,1));
804 my $id = $apiindex{$symbol};
806 #print " add symbol $symbol with $id to index\n";
808 if ($curletter ne $lastletter) {
809 $lastletter = $curletter;
812 print (OUTPUT "</indexdiv>\n");
814 print (OUTPUT "<indexdiv><title>$curletter</title>\n");
818 print (OUTPUT <<EOF);
819 <indexentry><primaryie linkends="$id">$xref</primaryie></indexentry>
824 print (OUTPUT "</indexdiv>\n");
826 print (OUTPUT "</indexdiv>\n");
829 &UpdateFileIfChanged ($old_index, $new_index, 0);
833 #############################################################################
834 # Function : OutputIndexFull
835 # Description : This writes the full api indexlist that can be included into the
836 # main document into an <index> tag.
837 #############################################################################
839 sub OutputIndexFull {
840 &OutputIndex ("api-index-full", \%IndexEntriesFull);
844 #############################################################################
845 # Function : OutputDeprecatedIndex
846 # Description : This writes the deprecated api indexlist that can be included
847 # into the main document into an <index> tag.
848 #############################################################################
850 sub OutputDeprecatedIndex {
851 &OutputIndex ("api-index-deprecated", \%IndexEntriesDeprecated);
855 #############################################################################
856 # Function : OutputSinceIndexes
857 # Description : This writes the 'since' api indexlists that can be included into
858 # the main document into an <index> tag.
859 #############################################################################
861 sub OutputSinceIndexes {
862 my @sinces = keys %{{ map { $_ => 1 } values %Since }};
864 foreach my $version (@sinces) {
865 #print "Since : [$version]\n";
866 # todo make filtered hash
867 #my %index = grep { $Since{$_} eq $version } %IndexEntriesSince;
868 my %index = map { $_ => $IndexEntriesSince{$_} } grep { $Since{$_} eq $version } keys %IndexEntriesSince;
870 &OutputIndex ("api-index-$version", \%index);
875 #############################################################################
876 # Function : ReadKnownSymbols
877 # Description : This collects the names of non-private symbols from the
878 # $MODULE-sections.txt file.
879 # Arguments : $file - the $MODULE-sections.txt file which contains all of
880 # the functions/macros/structs etc. being documented, organised
881 # into sections and subsections.
882 #############################################################################
884 sub ReadKnownSymbols {
889 #print "Reading: $file\n";
891 || die "Can't open $file: $!";
897 } elsif (m/^<SECTION>/) {
900 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
903 } elsif (m/^<SUBSECTION>/) {
906 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
909 } elsif (m/^<FILE>(.*)<\/FILE>/) {
912 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
915 } elsif (m/^<\/SECTION>/) {
918 } elsif (m/^(\S+)/) {
921 if ($subsection ne "Standard" && $subsection ne "Private") {
922 $KnownSymbols{$symbol} = 1;
925 $KnownSymbols{$symbol} = 0;
933 #############################################################################
934 # Function : OutputDeclaration
935 # Description : Returns the synopsis and detailed description DocBook
936 # describing one function/macro etc.
937 # Arguments : $symbol - the name of the function/macro begin described.
938 # $declaration - the declaration of the function/macro.
939 #############################################################################
941 sub OutputDeclaration {
942 my ($symbol, $declaration) = @_;
944 my $type = $DeclarationTypes {$symbol};
945 if ($type eq 'MACRO') {
946 return &OutputMacro ($symbol, $declaration);
947 } elsif ($type eq 'TYPEDEF') {
948 return &OutputTypedef ($symbol, $declaration);
949 } elsif ($type eq 'STRUCT') {
950 return &OutputStruct ($symbol, $declaration);
951 } elsif ($type eq 'ENUM') {
952 return &OutputEnum ($symbol, $declaration);
953 } elsif ($type eq 'UNION') {
954 return &OutputUnion ($symbol, $declaration);
955 } elsif ($type eq 'VARIABLE') {
956 return &OutputVariable ($symbol, $declaration);
958 } elsif ($type eq 'FUNCTION') {
959 return &OutputFunction ($symbol, $declaration, $type);
960 } elsif ($type eq 'USER_FUNCTION') {
961 return &OutputFunction ($symbol, $declaration, $type);
963 die "Unknown symbol type";
968 #############################################################################
969 # Function : OutputSymbolTraits
970 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
971 # Arguments : $symbol - the name of the function/macro begin described.
972 #############################################################################
974 sub OutputSymbolTraits {
978 if (exists $Since{$symbol}) {
979 $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
981 if (exists $StabilityLevel{$symbol}) {
982 $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
988 #############################################################################
989 # Function : OutputMacro
990 # Description : Returns the synopsis and detailed description of a macro.
991 # Arguments : $symbol - the macro.
992 # $declaration - the declaration of the macro.
993 #############################################################################
996 my ($symbol, $declaration) = @_;
997 my $id = &CreateValidSGMLID ($symbol);
998 my $condition = &MakeConditionDescription ($symbol);
999 my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
1005 if ($declaration =~ m/^\s*#\s*define(\s+)\w+(\([^\)]*\))/) {
1009 if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
1010 $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
1013 # Try to align all the lines of args correctly.
1014 $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH + $SYMBOL_FIELD_WIDTH + 1);
1015 my $args_padded = $args;
1016 $args_padded =~ s/ *\\\n */\n$pad/gm;
1017 $synop .= &CreateValidSGML ($args_padded);
1021 my $title = $symbol . ($args ? "()" : "");
1022 $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
1023 $desc .= MakeIndexterms($symbol, $id);
1025 # Don't output the macro definition if is is a conditional macro or it
1026 # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
1027 # longer than 2 lines, otherwise we get lots of complicated macros like
1029 if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
1030 && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
1031 $declaration = &CreateValidSGML ($declaration);
1032 $desc .= "<programlisting>$declaration</programlisting>\n";
1034 $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
1035 # Align each line so that if should all line up OK.
1036 $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
1037 $args =~ s/\n/\n$pad/gm;
1038 $desc .= &CreateValidSGML ($args);
1039 $desc .= "</programlisting>\n";
1042 $desc .= &MakeDeprecationNote($symbol);
1044 my $parameters = &OutputParamDescriptions ("MACRO", $symbol);
1045 my $parameters_output = 0;
1047 if (defined ($SymbolDocs{$symbol})) {
1048 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1050 # Try to insert the parameter table at the author's desired position.
1051 # Otherwise we need to tag it onto the end.
1052 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1053 $parameters_output = 1;
1055 $desc .= $symbol_docs;
1058 if ($parameters_output == 0) {
1059 $desc .= $parameters;
1062 $desc .= OutputSymbolTraits ($symbol);
1063 $desc .= "</refsect2>\n";
1064 return ($synop, $desc);
1068 #############################################################################
1069 # Function : OutputTypedef
1070 # Description : Returns the synopsis and detailed description of a typedef.
1071 # Arguments : $symbol - the typedef.
1072 # $declaration - the declaration of the typedef,
1073 # e.g. 'typedef unsigned int guint;'
1074 #############################################################################
1077 my ($symbol, $declaration) = @_;
1078 my $id = &CreateValidSGMLID ($symbol);
1079 my $condition = &MakeConditionDescription ($symbol);
1080 my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
1081 my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
1083 $desc .= MakeIndexterms($symbol, $id);
1085 if (!defined ($DeclarationConditional{$symbol})) {
1086 $declaration = &CreateValidSGML ($declaration);
1087 $desc .= "<programlisting>$declaration</programlisting>\n";
1090 $desc .= &MakeDeprecationNote($symbol);
1092 if (defined ($SymbolDocs{$symbol})) {
1093 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1095 $desc .= OutputSymbolTraits ($symbol);
1096 $desc .= "</refsect2>\n";
1097 return ($synop, $desc);
1101 #############################################################################
1102 # Function : OutputStruct
1103 # Description : Returns the synopsis and detailed description of a struct.
1104 # We check if it is a widget struct, and if so we only output
1105 # parts of it that are noted as public fields.
1106 # We also use a different SGML ID for widget structs, since the
1107 # original ID is used for the entire RefEntry.
1108 # Arguments : $symbol - the struct.
1109 # $declaration - the declaration of the struct.
1110 #############################################################################
1113 my ($symbol, $declaration) = @_;
1115 my $is_widget_struct = 0;
1116 my $default_to_public = 1;
1117 if (&CheckIsObject ($symbol)) {
1118 #print "Found widget struct: $symbol\n";
1119 $is_widget_struct = 1;
1120 $default_to_public = 0;
1125 if ($is_widget_struct) {
1126 $id = &CreateValidSGMLID ($symbol . "_struct");
1127 $condition = &MakeConditionDescription ($symbol . "_struct");
1129 $id = &CreateValidSGMLID ($symbol);
1130 $condition = &MakeConditionDescription ($symbol);
1133 # Determine if it is a simple struct or it also has a typedef.
1134 my $has_typedef = 0;
1135 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
1142 # For structs with typedefs we just output the struct name.
1143 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
1144 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
1146 $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
1147 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1150 $desc .= MakeIndexterms($symbol, $id);
1152 # Form a pretty-printed, private-data-removed form of the declaration
1155 if ($declaration =~ m/^\s*$/) {
1156 #print "Found opaque struct: $symbol\n";
1157 $decl_out = "typedef struct _$symbol $symbol;";
1158 } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1159 #print "Found opaque struct: $symbol\n";
1160 $decl_out = "struct $symbol;";
1162 my $public = $default_to_public;
1163 my $new_declaration = "";
1165 my $decl = $declaration;
1167 if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1168 my $struct_contents = $2;
1170 foreach $decl_line (split (/\n/, $struct_contents)) {
1171 #print "Struct line: $decl_line\n";
1172 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1174 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1177 $new_declaration .= $decl_line . "\n";
1181 if ($new_declaration) {
1182 # Strip any blank lines off the ends.
1183 $new_declaration =~ s/^\s*\n//;
1184 $new_declaration =~ s/\n\s*$/\n/;
1187 $decl_out = "typedef struct {\n" . $new_declaration
1190 $decl_out = "struct $symbol {\n" . $new_declaration
1195 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1196 "Couldn't parse struct:\n$declaration");
1199 # If we couldn't parse the struct or it was all private, output an
1200 # empty struct declaration.
1201 if ($decl_out eq "") {
1203 $decl_out = "typedef struct _$symbol $symbol;";
1205 $decl_out = "struct $symbol;";
1210 $decl_out = &CreateValidSGML ($decl_out);
1211 $desc .= "<programlisting>$decl_out</programlisting>\n";
1213 $desc .= &MakeDeprecationNote($symbol);
1215 if (defined ($SymbolDocs{$symbol})) {
1216 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1219 # Create a table of fields and descriptions
1221 # FIXME: Inserting  's into the produced type declarations here would
1222 # improve the output in most situations ... except for function
1223 # members of structs!
1224 my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1227 "<structfield>$_[0]</structfield>";
1229 my $params = $SymbolParams{$symbol};
1231 # If no parameters are filled in, we don't generate the description
1232 # table, for backwards compatibility
1235 if (defined $params) {
1236 for (my $i = 1; $i <= $#$params; $i += 2) {
1237 if ($params->[$i] =~ /\S/) {
1245 my %field_descrs = @$params;
1248 <variablelist role="struct">
1251 my $field_name = shift @fields;
1252 my $text = shift @fields;
1253 my $field_descr = $field_descrs{$field_name};
1255 $desc .= "<varlistentry>\n<term>$text</term>\n";
1256 if (defined $field_descr) {
1257 $desc .= "<listitem><simpara>".&ExpandAbbreviations($symbol, $field_descr)."</simpara></listitem>\n";
1259 $desc .= "<listitem><simpara /></listitem>\n";
1261 $desc .= "</varlistentry>\n";
1264 $desc .= "</variablelist>";
1266 $desc .= OutputSymbolTraits ($symbol);
1267 $desc .= "</refsect2>\n";
1268 return ($synop, $desc);
1272 #############################################################################
1273 # Function : OutputEnum
1274 # Description : Returns the synopsis and detailed description of a enum.
1275 # Arguments : $symbol - the enum.
1276 # $declaration - the declaration of the enum.
1277 #############################################################################
1280 my ($symbol, $declaration) = @_;
1281 my $id = &CreateValidSGMLID ($symbol);
1282 my $condition = &MakeConditionDescription ($symbol);
1283 my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1284 my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1286 $desc .= MakeIndexterms($symbol, $id);
1288 $declaration = &CreateValidSGML ($declaration);
1289 $desc .= "<programlisting>$declaration</programlisting>\n";
1291 $desc .= &MakeDeprecationNote($symbol);
1293 if (defined ($SymbolDocs{$symbol})) {
1294 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1297 # Create a table of fields and descriptions
1299 my @members = ParseEnumDeclaration($declaration);
1300 my $params = $SymbolParams{$symbol};
1302 # If no parameters are filled in, we don't generate the description
1303 # table, for backwards compatibility
1306 if (defined $params) {
1307 for (my $i = 1; $i <= $#$params; $i += 2) {
1308 if ($params->[$i] =~ /\S/) {
1316 my %member_descrs = @$params;
1319 <variablelist role="enum">
1321 for my $member_name (@members) {
1322 my $member_descr = $member_descrs{$member_name};
1324 $id = &CreateValidSGMLID ($member_name);
1325 $condition = &MakeConditionDescription ($member_name);
1326 $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$member_name</literal></term>\n";
1327 if (defined $member_descr) {
1328 $desc .= "<listitem><simpara>".&ExpandAbbreviations($symbol, $member_descr)."</simpara></listitem>\n";
1330 $desc .= "<listitem></listitem>\n";
1332 $desc .= "</varlistentry>\n";
1335 $desc .= "</variablelist>";
1338 $desc .= OutputSymbolTraits ($symbol);
1339 $desc .= "</refsect2>\n";
1340 return ($synop, $desc);
1344 #############################################################################
1345 # Function : OutputUnion
1346 # Description : Returns the synopsis and detailed description of a union.
1347 # Arguments : $symbol - the union.
1348 # $declaration - the declaration of the union.
1349 #############################################################################
1352 my ($symbol, $declaration) = @_;
1353 my $id = &CreateValidSGMLID ($symbol);
1354 my $condition = &MakeConditionDescription ($symbol);
1355 my $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1356 my $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1358 $desc .= MakeIndexterms($symbol, $id);
1360 $declaration = &CreateValidSGML ($declaration);
1361 $desc .= "<programlisting>$declaration</programlisting>\n";
1363 $desc .= &MakeDeprecationNote($symbol);
1365 if (defined ($SymbolDocs{$symbol})) {
1366 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1368 $desc .= OutputSymbolTraits ($symbol);
1369 $desc .= "</refsect2>\n";
1370 return ($synop, $desc);
1374 #############################################################################
1375 # Function : OutputVariable
1376 # Description : Returns the synopsis and detailed description of a variable.
1377 # Arguments : $symbol - the extern'ed variable.
1378 # $declaration - the declaration of the variable.
1379 #############################################################################
1381 sub OutputVariable {
1382 my ($symbol, $declaration) = @_;
1383 my $id = &CreateValidSGMLID ($symbol);
1384 my $condition = &MakeConditionDescription ($symbol);
1387 if ($declaration =~ m/^\s*extern\s+((const\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1388 my $mod = defined ($1) ? $1 : "";
1389 my $ptr = defined ($3) ? $3 : "";
1390 my $space = defined ($4) ? $4 : "";
1391 $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1394 $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1397 my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1399 $desc .= MakeIndexterms($symbol, $id);
1401 $declaration = &CreateValidSGML ($declaration);
1402 $desc .= "<programlisting>$declaration</programlisting>\n";
1404 $desc .= &MakeDeprecationNote($symbol);
1406 if (defined ($SymbolDocs{$symbol})) {
1407 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1409 $desc .= OutputSymbolTraits ($symbol);
1410 $desc .= "</refsect2>\n";
1411 return ($synop, $desc);
1415 #############################################################################
1416 # Function : OutputFunction
1417 # Description : Returns the synopsis and detailed description of a function.
1418 # Arguments : $symbol - the function.
1419 # $declaration - the declaration of the function.
1420 #############################################################################
1422 sub OutputFunction {
1423 my ($symbol, $declaration, $symbol_type) = @_;
1424 my $id = &CreateValidSGMLID ($symbol);
1425 my $condition = &MakeConditionDescription ($symbol);
1427 # Take out the return type $1 $3 $4
1428 $declaration =~ s/<RETURNS>\s*((const\s+|G_CONST_RETURN\s+|unsigned\s+|struct\s+|enum\s+)*)(\w+)(\s*\**\s*(const|G_CONST_RETURN)?\s*\**\s*(restrict)?\s*)<\/RETURNS>\n//;
1429 my $type_modifier = defined($1) ? $1 : "";
1432 #print "$symbol pointer is $pointer\n";
1433 my $xref = &MakeXRef ($type);
1435 #if ($symbol_type eq 'USER_FUNCTION') {
1436 # $start = "typedef ";
1439 # We output const rather than G_CONST_RETURN.
1440 $type_modifier =~ s/G_CONST_RETURN/const/g;
1441 $pointer =~ s/G_CONST_RETURN/const/g;
1442 $pointer =~ s/^\s+/ /g;
1444 my $ret_type_len = length ($start) + length ($type_modifier)
1445 + length ($pointer) + length ($type);
1446 my $ret_type_output;
1448 if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1449 $ret_type_output = "$start$type_modifier$xref$pointer"
1450 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1453 # $ret_type_output = "$start$type_modifier$xref$pointer\n"
1454 # . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1456 $ret_type_output = "$start$type_modifier$xref$pointer ";
1457 $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1460 $symbol_len += length ($symbol);
1461 my $char1 = my $char2 = my $char3 = "";
1462 if ($symbol_type eq 'USER_FUNCTION') {
1469 my ($symbol_output, $symbol_desc_output);
1470 if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1471 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1472 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1473 $symbol_desc_output = "$char1$char2$symbol$char3"
1474 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1476 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1477 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1478 $symbol_desc_output = "$char1$char2$symbol$char3\n"
1479 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1482 my $synop = $ret_type_output . $symbol_output . '(';
1483 my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
1485 $desc .= MakeIndexterms($symbol, $id);
1487 $desc .= "<programlisting>${ret_type_output}$symbol_desc_output(";
1490 while ($declaration ne "") {
1491 #print "$declaration";
1493 if ($declaration =~ s/^[\s,]+//) {
1494 # skip whitespace and commas
1497 } elsif ($declaration =~ s/^void\s*[,\n]//) {
1501 } elsif ($declaration =~ s/^...\s*[,\n]//) {
1502 if ($param_num == 0) {
1507 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1510 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1514 # allow alphanumerics, '_', '[' & ']' in param names
1515 # Try to match a standard parameter (keep in sync with gtkdoc-mktmpl)
1517 } elsif ($declaration =~ s/^\s*((?:G_CONST_RETURN|G_GNUC_UNUSED|unsigned long|unsigned short|signed long|signed short|unsigned|signed|long|short|volatile|const)\s+)*((?:struct\b|enum\b)?\s*\w+)\s*((?:(?:const\b|restrict\b)?\s*\*?\s*(?:const\b|restrict\b)?\s*)*)(\w+)?\s*((?:\[\S*\])*)\s*[,\n]//) {
1518 my $pre = defined($1) ? $1 : "";
1520 my $ptr = defined($3) ? $3 : "";
1521 my $name = defined($4) ? $4 : "";
1522 my $array = defined($5) ? $5 : "";
1528 if ($ptr && $ptr !~ m/\*$/) { $ptr .= " "; }
1530 #print "$symbol: '$pre' '$type' '$ptr' '$name' '$array'\n";
1532 if (($name eq "") && $pre =~ m/^((un)?signed .*)\s?/ ) {
1538 my $xref = &MakeXRef ($type);
1539 my $label = "$pre$xref $ptr$name$array";
1541 #print "$symbol: '$pre' '$type' '$ptr' '$name' '$array'\n";
1543 if ($param_num == 0) {
1548 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1551 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1555 # Try to match parameters which are functions (keep in sync with gtkdoc-mktmpl)
1556 # $1 $2 $3 $4 $5 $7 $8
1557 } elsif ($declaration =~ s/^(const\s+|G_CONST_RETURN\s+|unsigned\s+)*(struct\s+)?(\w+)\s*(\**)\s*(?:restrict\b)?\s*(const\s+)?\(\s*\*+\s*(\w+)\s*\)\s*\(([^)]*)\)\s*[,\n]//) {
1558 my $mod1 = defined($1) ? $1 : "";
1559 if (defined($2)) { $mod1 .= $2; }
1562 my $mod2 = defined($5) ? $5 : "";
1565 my $func_params = defined($8) ? $8 : "";
1567 #if (!defined($type)) { print "## no type\n"; };
1568 #if (!defined($ptr1)) { print "## no ptr1\n"; };
1569 #if (!defined($func_ptr)) { print "## no func_ptr\n"; };
1570 #if (!defined($name)) { print "## no name\n"; };
1572 if ($ptr1 && $ptr1 !~ m/\*$/) { $ptr1 .= " "; }
1573 $func_ptr =~ s/\s+//g;
1574 my $xref = &MakeXRef ($type);
1575 my $label = "$mod1$xref$ptr1$mod2 ($func_ptr$name) ($func_params)";
1577 #print "Type: [$mod1][$xref][$ptr1][$mod2] ([$func_ptr][$name]) ($func_params)\n";
1578 if ($param_num == 0) {
1583 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1586 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1591 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1592 "Can't parse args for function $symbol: $declaration");
1598 $desc .= ");</programlisting>\n";
1600 $desc .= &MakeDeprecationNote($symbol);
1602 my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol);
1603 my $parameters_output = 0;
1605 if (defined ($SymbolDocs{$symbol})) {
1606 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1608 # Try to insert the parameter table at the author's desired position.
1609 # Otherwise we need to tag it onto the end.
1610 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1611 $parameters_output = 1;
1613 $desc .= $symbol_docs;
1616 if ($parameters_output == 0) {
1617 $desc .= $parameters;
1620 $desc .= OutputSymbolTraits ($symbol);
1621 $desc .= "</refsect2>\n";
1622 return ($synop, $desc);
1626 #############################################################################
1627 # Function : OutputParamDescriptions
1628 # Description : Returns the DocBook output describing the parameters of a
1629 # function, macro or signal handler.
1630 # Arguments : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
1631 # handlers have an implicit user_data parameter last.
1632 # $symbol - the name of the function/macro being described.
1633 #############################################################################
1635 sub OutputParamDescriptions {
1636 my ($symbol_type, $symbol) = @_;
1638 if (defined ($SymbolParams{$symbol})) {
1640 my $params = $SymbolParams{$symbol};
1641 my $params_desc = "";
1643 for ($j = 0; $j <= $#$params; $j += 2) {
1644 my $param_name = $$params[$j];
1645 my $param = $$params[$j + 1];
1646 if ($param_name eq "Returns") {
1647 $returns = &ExpandAbbreviations($symbol, $param);
1649 if ($param_name eq "Varargs") {
1650 $param_name = "...";
1652 $param = &ExpandAbbreviations($symbol, $param);
1653 $params_desc .= "<varlistentry><term><parameter>$param_name</parameter> :</term>\n<listitem><simpara>$param</simpara></listitem></varlistentry>\n";
1657 # Signals have an implicit user_data parameter which we describe.
1658 if ($symbol_type eq "SIGNAL") {
1659 $params_desc .= "<varlistentry><term><parameter>user_data</parameter> :</term>\n<listitem><simpara>user data set when the signal handler was connected.</simpara></listitem></varlistentry>\n";
1662 # Start a table if we need one.
1663 if ($params_desc || $returns) {
1665 <variablelist role="params">
1668 if ($params_desc ne "") {
1669 # $output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
1670 $output .= $params_desc;
1673 # Output the returns info last.
1675 $output .= "<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
1679 $output .= "</variablelist>";
1686 #############################################################################
1687 # Function : ParseStabilityLevel
1688 # Description : Parses a stability level and outputs a warning if it isn't
1690 # Arguments : $stability - the stability text.
1691 # $file, $line - context for error message
1692 # $message - description of where the level is from, to use in
1693 # any error message.
1694 # Returns : The parsed stability level string.
1695 #############################################################################
1697 sub ParseStabilityLevel {
1698 my ($stability, $file, $line, $message) = @_;
1700 $stability =~ s/^\s*//;
1701 $stability =~ s/\s*$//;
1702 if ($stability =~ m/^stable$/i) {
1703 $stability = "Stable";
1704 } elsif ($stability =~ m/^unstable$/i) {
1705 $stability = "Unstable";
1706 } elsif ($stability =~ m/^private$/i) {
1707 $stability = "Private";
1709 &LogWarning ($file, $line, "$message is $stability.".
1710 "It should be one of these: Stable, Unstable, or Private.");
1716 #############################################################################
1717 # Function : OutputSGMLFile
1718 # Description : Outputs the final DocBook file for one section.
1719 # Arguments : $file - the name of the file.
1720 # $title - the title from the $MODULE-sections.txt file, which
1721 # will be overridden by the title in the template file.
1722 # $section_id - the SGML id to use for the toplevel tag.
1723 # $includes - comma-separates list of include files added at top
1724 # of synopsis, with '<' '>' around them (if not already enclosed in "").
1725 # $synopsis - reference to the DocBook for the Synopsis part.
1726 # $details - reference to the DocBook for the Details part.
1727 # $signal_synop - reference to the DocBook for the Signal Synopsis part
1728 # $signal_desc - reference to the DocBook for the Signal Description part
1729 # $args_synop - reference to the DocBook for the Arg Synopsis part
1730 # $args_desc - reference to the DocBook for the Arg Description part
1731 # $hierarchy - reference to the DocBook for the Object Hierarchy part
1732 # $interfaces - reference to the DocBook for the Interfaces part
1733 # $implementations - reference to the DocBook for the Known Implementations part
1734 # $prerequisites - reference to the DocBook for the Prerequisites part
1735 # $derived - reference to the DocBook for the Derived Interfaces part
1736 # $file_objects - reference to an array of objects in this file
1737 #############################################################################
1739 sub OutputSGMLFile {
1740 my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
1742 #print "Output sgml for file $file with title '$title'\n";
1744 # The edited title overrides the one from the sections file.
1745 my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
1746 if (defined ($new_title) && $new_title !~ m/^\s*$/) {
1747 $title = $new_title;
1748 #print "Found title: $title\n";
1750 my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
1751 if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
1754 $short_desc = &ExpandAbbreviations("$title:Short_description",
1756 #print "Found short_desc: $short_desc";
1758 my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
1759 if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
1762 $long_desc = &ExpandAbbreviations("$title:Long_description",
1764 #print "Found long_desc: $long_desc";
1766 my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
1767 if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
1770 $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
1771 #print "Found see_also: $see_also";
1774 $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
1776 my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
1777 if (!defined ($stability) || $stability =~ m/^\s*$/) {
1780 $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
1781 #print "Found stability: $stability";
1784 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
1785 } elsif ($DEFAULT_STABILITY) {
1786 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
1789 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
1791 my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
1794 my $include_output = "";
1796 foreach $include (split (/,/, $includes)) {
1797 if ($include =~ m/^\".+\"$/) {
1798 $include_output .= "#include ${include}\n";
1801 $include =~ s/^\s+|\s+$//gs;
1802 $include_output .= "#include <${include}>\n";
1805 if ($include_output ne '') {
1806 $include_output = "\n$include_output\n";
1809 my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
1810 my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
1812 open (OUTPUT, ">$new_sgml_file")
1813 || die "Can't create $new_sgml_file: $!";
1815 my $object_anchors = "";
1816 foreach my $object (@$file_objects) {
1817 next if ($object eq $section_id);
1818 my $id = CreateValidSGMLID($object);
1819 #print "Debug: Adding anchor for $object\n";
1820 $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
1823 # We used to output this, but is messes up our UpdateFileIfChanged code
1824 # since it changes every day (and it is only used in the man pages):
1825 # "<refentry id="$section_id" revision="$mday $month $year">"
1827 if (lc($OUTPUT_FORMAT) eq "xml") {
1828 print OUTPUT $doctype_header;
1832 <refentry id="$section_id">
1834 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
1835 <manvolnum>3</manvolnum>
1836 <refmiscinfo>\U$MODULE\E Library</refmiscinfo>
1840 <refname>$title</refname>
1841 <refpurpose>$short_desc</refpurpose>
1844 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
1845 <title role="synopsis.title">Synopsis</title>
1848 $include_output$${synopsis}</synopsis>
1859 <refsect1 id="$section_id.description" role="desc">
1860 <title role="desc.title">Description</title>
1864 <refsect1 id="$section_id.details" role="details">
1865 <title role="details.title">Details</title>
1876 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
1880 #############################################################################
1881 # Function : OutputExtraFile
1882 # Description : Copies an "extra" DocBook file into the output directory,
1883 # expanding abbreviations
1884 # Arguments : $file - the source file.
1885 #############################################################################
1886 sub OutputExtraFile {
1891 ($basename = $file) =~ s!^.*/!!;
1893 my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
1894 my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
1898 open(EXTRA_FILE, "<$file") || die "Can't open $file";
1902 $contents = <EXTRA_FILE>;
1905 open (OUTPUT, ">$new_sgml_file")
1906 || die "Can't create $new_sgml_file: $!";
1908 print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
1911 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
1913 #############################################################################
1914 # Function : OutputBook
1915 # Description : Outputs the SGML entities that need to be included into the
1916 # main SGML file for the module.
1917 # Arguments : $book_top - the declarations of the entities, which are added
1918 # at the top of the main SGML file.
1919 # $book_bottom - the references to the entities, which are
1920 # added in the main SGML file at the desired position.
1921 #############################################################################
1924 my ($book_top, $book_bottom) = @_;
1926 my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
1927 my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
1929 open (OUTPUT, ">$new_file")
1930 || die "Can't create $new_file: $!";
1931 print OUTPUT $book_top;
1934 &UpdateFileIfChanged ($old_file, $new_file, 0);
1937 $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
1938 $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
1940 open (OUTPUT, ">$new_file")
1941 || die "Can't create $new_file: $!";
1942 print OUTPUT $book_bottom;
1945 &UpdateFileIfChanged ($old_file, $new_file, 0);
1948 # If the main SGML file hasn't been created yet, we create it here.
1949 # The user can tweak it later.
1950 if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
1951 open (OUTPUT, ">$MAIN_SGML_FILE")
1952 || die "Can't create $MAIN_SGML_FILE: $!";
1954 if (lc($OUTPUT_FORMAT) eq "xml") {
1956 <?xml version="1.0"?>
1957 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
1958 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
1960 <!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'">
1966 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
1968 print OUTPUT $book_top;
1977 <title>$MODULE Reference Manual</title>
1979 for $MODULE [VERSION]
1980 The latest version of this documentation can be found on-line at
1981 <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
1986 <title>[Insert title here]</title>
1988 print OUTPUT $book_bottom;
2000 #############################################################################
2001 # Function : CreateValidSGMLID
2002 # Description : Creates a valid SGML 'id' from the given string.
2003 # NOTE: SGML ids are case-insensitive, so we have a few special
2004 # cases to avoid clashes of ids.
2005 # Arguments : $id - the string to be converted into a valid SGML id.
2006 #############################################################################
2008 sub CreateValidSGMLID {
2011 # Append ":CAPS" to all all-caps identifiers
2013 # Special case, '_' would end up as '' so we use 'gettext-macro' instead.
2014 if ($id eq "_") { return "gettext-macro"; }
2016 if ($id !~ /[a-z]/) { $id .= ":CAPS" };
2028 #############################################################################
2029 # Function : CreateValidSGML
2030 # Description : This turns any chars which are used in SGML into entities,
2031 # e.g. '<' into '<'
2032 # Arguments : $text - the text to turn into proper SGML.
2033 #############################################################################
2035 sub CreateValidSGML {
2037 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2038 $text =~ s/</</g;
2039 $text =~ s/>/>/g;
2043 #############################################################################
2044 # Function : ConvertSGMLChars
2045 # Description : This is used for text in source code comment blocks, to turn
2046 # chars which are used in SGML into entities, e.g. '<' into
2047 # '<'. Depending on $SGML_MODE, this is done
2048 # unconditionally or only if the character doesn't seem to be
2049 # part of an SGML construct (tag or entity reference).
2050 # Arguments : $text - the text to turn into proper SGML.
2051 #############################################################################
2053 sub ConvertSGMLChars {
2054 my ($symbol, $text) = @_;
2057 # For the SGML mode only convert to entities outside CDATA sections.
2058 return &ModifyXMLElements ($text, $symbol,
2059 "<!\\[CDATA\\[|<programlisting[^>]*>",
2060 \&ConvertSGMLCharsEndTag,
2061 \&ConvertSGMLCharsCallback);
2063 # For the simple non-sgml mode, convert to entities everywhere.
2064 $text =~ s/&/&/g; # Do this first, or the others get messed up.
2065 $text =~ s/</</g;
2066 $text =~ s/>/>/g;
2072 sub ConvertSGMLCharsEndTag {
2073 if ($_[0] eq "<!\[CDATA\[") {
2076 return "</programlisting>";
2080 sub ConvertSGMLCharsCallback {
2081 my ($text, $symbol, $tag) = @_;
2083 if ($tag =~ m/^<programlisting/) {
2084 # We can handle <programlisting> specially here.
2085 return &ModifyXMLElements ($text, $symbol,
2087 \&ConvertSGMLCharsEndTag,
2088 \&ConvertSGMLCharsCallback2);
2089 } elsif ($tag eq "") {
2090 # If we're not in CDATA convert to entities.
2091 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2092 $text =~ s/<(?![a-zA-Z\/!])/</g;
2093 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2095 # Handle "#include <xxxxx>"
2096 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2102 sub ConvertSGMLCharsCallback2 {
2103 my ($text, $symbol, $tag) = @_;
2105 # If we're not in CDATA convert to entities.
2106 # We could handle <programlisting> differently, though I'm not sure it helps.
2108 # replace only if its not a tag
2109 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
2110 $text =~ s/<(?![a-zA-Z\/!])/</g;
2111 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
2113 # Handle "#include <xxxxx>"
2114 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
2121 #############################################################################
2122 # Function : ExpandAbbreviations
2123 # Description : This turns the abbreviations function(), macro(), @param,
2124 # %constant, and #symbol into appropriate DocBook markup.
2125 # CDATA sections and <programlisting> parts are skipped.
2126 # Arguments : $symbol - the symbol being documented, for error messages.
2127 # $text - the text to expand.
2128 #############################################################################
2130 sub ExpandAbbreviations {
2131 my ($symbol, $text) = @_;
2133 # Convert "|[" and "]|" into the start and end of program listing examples.
2134 $text =~ s%\|\[%<informalexample><programlisting>%g;
2135 $text =~ s%\]\|%</programlisting></informalexample>%g;
2137 # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
2139 return &ModifyXMLElements ($text, $symbol,
2140 "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>",
2141 \&ExpandAbbreviationsEndTag,
2142 \&ExpandAbbreviationsCallback);
2146 # Returns the end tag corresponding to the given start tag.
2147 sub ExpandAbbreviationsEndTag {
2148 my ($start_tag) = @_;
2150 if ($start_tag eq "<!\[CDATA\[") {
2152 } elsif ($start_tag =~ m/<(\w+)/) {
2157 # Called inside or outside each CDATA or <programlisting> section.
2158 sub ExpandAbbreviationsCallback {
2159 my ($text, $symbol, $tag) = @_;
2161 if ($tag =~ m/^<programlisting/) {
2162 # Handle any embedded CDATA sections.
2163 return &ModifyXMLElements ($text, $symbol,
2165 \&ExpandAbbreviationsEndTag,
2166 \&ExpandAbbreviationsCallback2);
2167 } elsif ($tag eq "") {
2168 # We are outside any CDATA or <programlisting> sections, so we expand
2169 # any gtk-doc abbreviations.
2171 # Convert 'function()' or 'macro()'.
2172 $text =~ s/(\w+)\s*\(\)/&MakeXRef($1, &tagify($1 . "()", "function"));/eg;
2174 # Convert '@param', but not '\@param'.
2175 #$text =~ s/\@(\w+((\.|->)\w+)*)/<parameter>$1<\/parameter>/g;
2176 $text =~ s/([^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2177 $text =~ s/\\\@/\@/g;
2179 # Convert '%constant', but not '\%constant'.
2180 # Also allow negative numbers, e.g. %-1.
2181 #$text =~ s/\%(-?\w+)/&MakeXRef($1, &tagify($1, "literal"));/eg;
2182 $text =~ s/([^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2183 $text =~ s/\\\%/\%/g;
2185 # Convert '#symbol', but not '\#symbol'.
2186 #$text =~ s/#([\w\-:]+)/&MakeHashXRef($1, "type");/eg;
2187 $text =~ s/([^\\])#([\w\-:]+)/$1.&MakeHashXRef($2, "type");/eg;
2194 # This is called inside a <programlisting>
2195 sub ExpandAbbreviationsCallback2 {
2196 my ($text, $symbol, $tag) = @_;
2199 # We are inside a <programlisting> but outside any CDATA sections,
2200 # so we expand any gtk-doc abbreviations.
2201 # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2202 # why not just call it
2203 $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2210 my ($symbol, $tag) = @_;;
2213 # Check for things like '#include', '#define', and skip them.
2214 if ($PreProcessorDirectives{$symbol}) {
2218 # Get rid of any special '-struct' suffix.
2219 $text =~ s/-struct$//;
2221 # If the symbol is in the form "Object::signal", then change the symbol to
2222 # "Object-signal" and use "signal" as the text.
2223 if ($symbol =~ s/::/-/) {
2227 # If the symbol is in the form "Object:property", then change the symbol to
2228 # "Object--property" and use "property" as the text.
2229 if ($symbol =~ s/:/--/) {
2234 $text = tagify ($text, $tag);
2237 return &MakeXRef($symbol, $text);
2241 #############################################################################
2242 # Function : ModifyXMLElements
2243 # Description : Looks for given XML element tags within the text, and calls
2244 # the callback on pieces of text inside & outside those elements.
2245 # Used for special handling of text inside things like CDATA
2246 # and <programlisting>.
2247 # Arguments : $text - the text.
2248 # $symbol - the symbol currently being documented (only used for
2250 # $start_tag_regexp - the regular expression to match start tags.
2251 # e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2252 # CDATA sections or programlisting elements.
2253 # $end_tag_func - function which is passed the matched start tag
2254 # and should return the appropriate end tag string.
2255 # $callback - callback called with each part of the text. It is
2256 # called with a piece of text, the symbol being
2257 # documented, and the matched start tag or "" if the text
2258 # is outside the XML elements being matched.
2259 #############################################################################
2260 sub ModifyXMLElements {
2261 my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2262 my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2265 while ($text =~ m/$start_tag_regexp/s) {
2266 $before_tag = $`; # Prematch for last successful match string
2267 $start_tag = $&; # Last successful match
2268 $text = $'; # Postmatch for last successful match string
2270 $result .= &$callback ($before_tag, $symbol, "");
2271 $result .= $start_tag;
2273 # get the mathing end-tag for current tag
2274 $end_tag_regexp = &$end_tag_func ($start_tag);
2276 if ($text =~ m/$end_tag_regexp/s) {
2281 $result .= &$callback ($before_tag, $symbol, $start_tag);
2282 $result .= $end_tag;
2284 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2285 "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2286 # Just assume it is all inside the tag.
2287 $result .= &$callback ($text, $symbol, $start_tag);
2292 # Handle any remaining text outside the tags.
2293 $result .= &$callback ($text, $symbol, "");
2302 # Adds a tag around some text.
2303 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2305 my ($text, $elem) = @_;
2306 return "<" . $elem . ">" . $text . "</" . $elem . ">";
2310 #############################################################################
2311 # Function : MakeXRef
2312 # Description : This returns a cross-reference link to the given symbol.
2313 # Though it doesn't try to do this for a few standard C types
2314 # that it knows won't be in the documentation.
2315 # Arguments : $symbol - the symbol to try to create a XRef to.
2316 # $text - text text to put inside the XRef, defaults to $symbol
2317 #############################################################################
2320 my ($symbol, $text) = ($_[0], $_[1]);
2321 if (!defined($text)) {
2324 # Get rid of special '-struct' suffix.
2325 $text =~ s/-struct$//;
2328 #print "Getting type link for $symbol -> $text\n";
2330 my $symbol_id = &CreateValidSGMLID ($symbol);
2331 return "<link linkend=\"$symbol_id\">$text</link>";
2335 #############################################################################
2336 # Function : MakeIndexterms
2337 # Description : This returns a indexterm elements for the given symbol
2338 # Arguments : $symbol - the symbol to create indexterms for
2339 #############################################################################
2341 sub MakeIndexterms {
2342 my ($symbol, $id) = @_;
2346 # make the index useful, by ommiting the namespace when sorting
2347 if (defined($NAME_SPACE)) {
2348 if ($symbol =~ m/^$NAME_SPACE\_?(.*)/i) {
2349 $sortas=" sortas=\"$1\"";
2353 if (exists $Deprecated{$symbol}) {
2354 $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary$sortas>$symbol</primary></indexterm>";
2355 $IndexEntriesDeprecated{$symbol}=$id;
2356 $IndexEntriesFull{$symbol}=$id;
2358 if (exists $Since{$symbol}) {
2359 my $since = $Since{$symbol};
2363 $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary$sortas>$symbol</primary></indexterm>";
2365 $IndexEntriesSince{$symbol}=$id;
2366 $IndexEntriesFull{$symbol}=$id;
2369 $terms .= "<indexterm zone=\"$id\"><primary$sortas>$symbol</primary></indexterm>";
2370 $IndexEntriesFull{$symbol}=$id;
2376 #############################################################################
2377 # Function : MakeDeprecationNote
2378 # Description : This returns a deprecation warning for the given symbol.
2379 # Arguments : $symbol - the symbol to try to create a warning for.
2380 #############################################################################
2382 sub MakeDeprecationNote {
2383 my ($symbol) = $_[0];
2386 if (exists $Deprecated{$symbol}) {
2387 $desc .= "<warning>";
2389 if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2390 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2392 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2394 if ($Deprecated{$symbol} ne "") {
2395 $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2396 $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2399 $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2400 $desc .= " " . $note;
2402 $desc .= "</para></warning>\n";
2407 #############################################################################
2408 # Function : MakeConditionDescription
2409 # Description : This returns a sumary of conditions for the given symbol.
2410 # Arguments : $symbol - the symbol to try to create the sumary.
2411 #############################################################################
2413 sub MakeConditionDescription {
2414 my ($symbol) = $_[0];
2417 if (exists $Deprecated{$symbol}) {
2422 if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
2423 $desc .= "deprecated:$1";
2425 $desc .= "deprecated";
2429 if (exists $Since{$symbol}) {
2434 if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
2435 $desc .= "since:$1";
2441 if (exists $StabilityLevel{$symbol}) {
2445 $desc .= "stability:".$StabilityLevel{$symbol};
2449 $desc=" condition=\"".$desc."\"";
2450 #print "condition for '$symbol' = '$desc'\n";
2455 #############################################################################
2456 # Function : GetHierarchy
2457 # Description : Returns the DocBook output describing the ancestors and
2458 # immediate children of a GObject subclass. It uses the
2459 # global @Objects and @ObjectLevels arrays to walk the tree.
2460 # Arguments : $object - the GtkObject subclass.
2461 #############################################################################
2466 # Find object in the objects array.
2472 for ($i = 0; $i < @Objects; $i++) {
2474 if ($ObjectLevels[$i] <= $level) {
2477 elsif ($ObjectLevels[$i] == $level + 1) {
2478 push (@children, $Objects[$i]);
2481 elsif ($Objects[$i] eq $object) {
2484 $level = $ObjectLevels[$i];
2491 # Walk up the hierarchy, pushing ancestors onto the ancestors array.
2493 push (@ancestors, $object);
2494 #print "Level: $level\n";
2495 while ($level > 1) {
2497 if ($ObjectLevels[$j] < $level) {
2498 push (@ancestors, $Objects[$j]);
2499 $level = $ObjectLevels[$j];
2500 #print "Level: $level\n";
2504 # Output the ancestors list, indented and with links.
2505 my $hierarchy = "<synopsis>\n";
2507 for ($i = $#ancestors; $i >= 0; $i--) {
2509 # Don't add a link to the current widget, i.e. when i == 0.
2511 my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
2512 $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
2514 $link_text = "$ancestors[$i]";
2517 $hierarchy .= " $link_text\n";
2519 # $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
2520 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2524 for ($i = 0; $i <= $#children; $i++) {
2525 my $id = &CreateValidSGMLID ($children[$i]);
2526 my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
2527 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2529 $hierarchy .= "</synopsis>\n";
2535 #############################################################################
2536 # Function : GetInterfaces
2537 # Description : Returns the DocBook output describing the interfaces
2538 # implemented by a class. It uses the global %Interfaces hash.
2539 # Arguments : $object - the GtkObject subclass.
2540 #############################################################################
2547 # Find object in the objects array.
2548 if (exists($Interfaces{$object})) {
2549 my @ifaces = split(' ', $Interfaces{$object});
2554 for ($i = 0; $i <= $#ifaces; $i++) {
2555 my $id = &CreateValidSGMLID ($ifaces[$i]);
2556 $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
2557 if ($i < $#ifaces - 1) {
2560 elsif ($i < $#ifaces) {
2575 #############################################################################
2576 # Function : GetImplementations
2577 # Description : Returns the DocBook output describing the implementations
2578 # of an interface. It uses the global %Interfaces hash.
2579 # Arguments : $object - the GtkObject subclass.
2580 #############################################################################
2582 sub GetImplementations {
2587 foreach my $key (keys %Interfaces) {
2588 if ($Interfaces{$key} =~ /\b$object\b/) {
2589 push (@impls, $key);
2595 $object is implemented by
2597 for ($i = 0; $i <= $#impls; $i++) {
2598 my $id = &CreateValidSGMLID ($impls[$i]);
2599 $text .= " <link linkend=\"$id\">$impls[$i]</link>";
2600 if ($i < $#impls - 1) {
2603 elsif ($i < $#impls) {
2618 #############################################################################
2619 # Function : GetPrerequisites
2620 # Description : Returns the DocBook output describing the prerequisites
2621 # of an interface. It uses the global %Prerequisites hash.
2622 # Arguments : $iface - the interface.
2623 #############################################################################
2625 sub GetPrerequisites {
2630 if (exists($Prerequisites{$iface})) {
2635 my @prereqs = split(' ', $Prerequisites{$iface});
2636 for ($i = 0; $i <= $#prereqs; $i++) {
2637 my $id = &CreateValidSGMLID ($prereqs[$i]);
2638 $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
2639 if ($i < $#prereqs - 1) {
2642 elsif ($i < $#prereqs) {
2656 #############################################################################
2657 # Function : GetDerived
2658 # Description : Returns the DocBook output describing the derived interfaces
2659 # of an interface. It uses the global %Prerequisites hash.
2660 # Arguments : $iface - the interface.
2661 #############################################################################
2669 foreach my $key (keys %Prerequisites) {
2670 if ($Prerequisites{$key} =~ /\b$iface\b/) {
2671 push (@derived, $key);
2674 if ($#derived >= 0) {
2677 $iface is required by
2679 for ($i = 0; $i <= $#derived; $i++) {
2680 my $id = &CreateValidSGMLID ($derived[$i]);
2681 $text .= " <link linkend=\"$id\">$derived[$i]</link>";
2682 if ($i < $#derived - 1) {
2685 elsif ($i < $#derived) {
2700 #############################################################################
2701 # Function : GetSignals
2702 # Description : Returns the synopsis and detailed description DocBook output
2703 # for the signal handlers of a given GtkObject subclass.
2704 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
2705 #############################################################################
2713 for ($i = 0; $i <= $#SignalObjects; $i++) {
2714 if ($SignalObjects[$i] eq $object) {
2715 #print "Found signal: $SignalNames[$i]\n";
2716 my $name = $SignalNames[$i];
2717 my $symbol = "${object}::${name}";
2718 my $id = &CreateValidSGMLID ("$object-$name");
2720 my $pad = ' ' x (46 - length($name));
2721 $synop .= " "<link linkend=\"$id\">$name</link>"$pad ";
2723 $desc .= "<refsect2 id=\"$id\"><title>The <literal>"$name"</literal> signal</title>\n";
2724 $desc .= MakeIndexterms($symbol, $id);
2725 $desc .= "<programlisting>";
2727 $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
2728 my $type_modifier = defined($1) ? $1 : "";
2731 my $xref = &MakeXRef ($type);
2733 my $ret_type_len = length ($type_modifier) + length ($pointer)
2735 my $ret_type_output = "$type_modifier$xref$pointer"
2736 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
2738 $desc .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
2740 my $sourceparams = $SourceSymbolParams{$symbol};
2741 my @params = split ("\n", $SignalPrototypes[$i]);
2744 my $type_len = length("gpointer");
2745 my $name_len = length("user_data");
2746 # do two passes, the first one is to calculate padding
2747 for ($l = 0; $l < 2; $l++) {
2748 for ($j = 0; $j <= $#params; $j++) {
2749 # allow alphanumerics, '_', '[' & ']' in param names
2750 if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
2753 if (defined($sourceparams)) {
2754 $name = $$sourceparams[2 * $j];
2759 if (!defined($name)) {
2763 if (length($type) + length($pointer) > $type_len) {
2764 $type_len = length($type) + length($pointer);
2766 if (length($name) > $name_len) {
2767 $name_len = length($name);
2771 $xref = &MakeXRef ($type);
2772 $pad = ' ' x ($type_len - length($type) - length($pointer));
2773 $desc .= "$xref$pad $pointer$name,\n";
2774 $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
2777 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2778 "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
2782 $xref = &MakeXRef ("gpointer");
2783 $pad = ' ' x ($type_len - length("gpointer"));
2784 $desc .= "$xref$pad user_data)";
2786 my $flags = $SignalFlags[$i];
2787 my $flags_string = "";
2789 if (defined ($flags)) {
2790 if ($flags =~ m/f/) {
2791 $flags_string = "Run First";
2793 elsif ($flags =~ m/l/) {
2794 $flags_string = "Run Last";
2796 elsif ($flags =~ m/c/) {
2797 $flags_string = "Cleanup";
2799 if ($flags =~ m/r/) {
2800 if ($flags_string) { $flags_string .= " / "; }
2801 $flags_string .= "No Recursion";
2803 if ($flags =~ m/d/) {
2804 if ($flags_string) { $flags_string .= " / "; }
2805 $flags_string .= "Has Details";
2807 if ($flags =~ m/a/) {
2808 if ($flags_string) { $flags_string .= " / "; }
2809 $flags_string .= "Action";
2811 if ($flags =~ m/h/) {
2812 if ($flags_string) { $flags_string .= " / "; }
2813 $flags_string .= "No Hooks";
2819 $synop .= ": $flags_string\n";
2821 $pad = ' ' x (5 + $name_len - length("user_data"));
2822 $desc .= "$pad : $flags_string</programlisting>\n";
2827 $desc .= "</programlisting>\n";
2830 my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
2831 my $parameters_output = 0;
2833 $AllSymbols{$symbol} = 1;
2834 if (defined ($SymbolDocs{$symbol})) {
2835 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2837 # Try to insert the parameter table at the author's desired
2838 # position. Otherwise we need to tag it onto the end.
2839 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2840 $parameters_output = 1;
2842 $desc .= $symbol_docs;
2844 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
2845 $AllDocumentedSymbols{$symbol} = 1;
2849 if ($parameters_output == 0) {
2850 $desc .= $parameters;
2853 if (exists $Since{$symbol}) {
2854 $desc .= "<para>Since $Since{$symbol}</para>";
2856 if (exists $StabilityLevel{$symbol}) {
2857 $desc .= "<para>Stability Level: $StabilityLevel{$symbol}</para>";
2859 $desc .= "</refsect2>";
2862 return ($synop, $desc);
2866 #############################################################################
2867 # Function : GetArgs
2868 # Description : Returns the synopsis and detailed description DocBook output
2869 # for the Args of a given GtkObject subclass.
2870 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
2871 #############################################################################
2877 my $child_synop = "";
2878 my $child_desc = "";
2879 my $style_synop = "";
2880 my $style_desc = "";
2883 for ($i = 0; $i <= $#ArgObjects; $i++) {
2884 if ($ArgObjects[$i] eq $object) {
2885 #print "Found arg: $ArgNames[$i]\n";
2886 my $name = $ArgNames[$i];
2887 my $flags = $ArgFlags[$i];
2888 my $flags_string = "";
2892 if ($flags =~ m/c/) {
2893 $kind = "child property";
2896 elsif ($flags =~ m/s/) {
2897 $kind = "style property";
2904 # Remember only one colon so we don't clash with signals.
2905 my $symbol = "${object}:${name}";
2906 # use two dashes and ev. an extra separator here for the same reason.
2907 my $id = &CreateValidSGMLID ("$object--$id_sep$name");
2909 my $type = $ArgTypes[$i];
2911 my $range = $ArgRanges[$i];
2912 my $range_output = CreateValidSGML($range);
2913 my $default = $ArgDefaults[$i];
2914 my $default_output = CreateValidSGML($default);
2916 if ($type eq "GtkString") {
2919 if ($type eq "GtkSignal") {
2920 $type = "GtkSignalFunc, gpointer";
2921 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
2922 . &MakeXRef ("gpointer");
2923 } elsif ($type =~ m/^(\w+)\*$/) {
2924 $type_output = &MakeXRef ($1) . "*";
2926 $type_output = &MakeXRef ($type);
2929 if ($flags =~ m/r/) {
2930 $flags_string = "Read";
2932 if ($flags =~ m/w/) {
2933 if ($flags_string) { $flags_string .= " / "; }
2934 $flags_string .= "Write";
2936 if ($flags =~ m/x/) {
2937 if ($flags_string) { $flags_string .= " / "; }
2938 $flags_string .= "Construct";
2940 if ($flags =~ m/X/) {
2941 if ($flags_string) { $flags_string .= " / "; }
2942 $flags_string .= "Construct Only";
2945 $AllSymbols{$symbol} = 1;
2947 if (defined($SymbolDocs{$symbol}) &&
2948 !IsEmptyDoc($SymbolDocs{$symbol})) {
2949 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2950 $AllDocumentedSymbols{$symbol} = 1;
2953 if (!($ArgBlurbs[$i] eq "")) {
2954 $AllDocumentedSymbols{$symbol} = 1;
2956 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
2959 my $pad1 = " " x (24 - length ($name));
2960 my $pad2 = " " x (20 - length ($type));
2962 my $arg_synop = " "<link linkend=\"$id\">$name</link>"$pad1 $type_output $pad2 : $flags_string\n";
2963 my $arg_desc = "<refsect2 id=\"$id\"><title>The <literal>"$name"</literal> $kind</title>\n";
2964 $arg_desc .= MakeIndexterms($symbol, $id);
2965 $arg_desc .= "<programlisting> "$name"$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
2966 $arg_desc .= $blurb;
2968 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
2970 if ($default ne "") {
2971 $arg_desc .= "<para>Default value: $default_output</para>\n";
2973 if (exists $Since{$symbol}) {
2974 $arg_desc .= "<para>Since $Since{$symbol}</para>\n";
2976 if (exists $StabilityLevel{$symbol}) {
2977 $arg_desc .= "<para>Stability Level $StabilityLevel{$symbol}</para>\n";
2979 $arg_desc .= "</refsect2>\n";
2981 if ($flags =~ m/c/) {
2982 $child_synop .= $arg_synop;
2983 $child_desc .= $arg_desc;
2985 elsif ($flags =~ m/s/) {
2986 $style_synop .= $arg_synop;
2987 $style_desc .= $arg_desc;
2990 $synop .= $arg_synop;
2995 return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
2999 #############################################################################
3000 # Function : ReadSourceDocumentation
3001 # Description : This reads in the documentation embedded in comment blocks
3002 # in the source code (for Gnome).
3004 # Parameter descriptions override any in the template files.
3005 # Function descriptions are placed before any description from
3006 # the template files.
3008 # It recursively descends the source directory looking for .c
3009 # files and scans them looking for specially-formatted comment
3012 # Arguments : $source_dir - the directory to scan.
3013 #############m###############################################################
3015 sub ReadSourceDocumentation {
3016 my ($source_dir) = @_;
3017 my ($file, $dir, @suffix_list, $suffix);
3018 #print "Scanning source directory: $source_dir\n";
3020 # This array holds any subdirectories found.
3023 @suffix_list = split (/,/, $SOURCE_SUFFIXES);
3025 opendir (SRCDIR, $source_dir)
3026 || die "Can't open source directory $source_dir: $!";
3028 foreach $file (readdir (SRCDIR)) {
3029 if ($file =~ /^\./) {
3031 } elsif (-d "$source_dir/$file") {
3032 push (@subdirs, $file);
3033 } elsif (@suffix_list) {
3034 foreach $suffix (@suffix_list) {
3035 if ($file =~ m/\.\Q${suffix}\E$/) {
3036 &ScanSourceFile ("$source_dir/$file");
3039 } elsif ($file =~ m/\.[ch]$/) {
3040 &ScanSourceFile ("$source_dir/$file");
3045 # Now recursively scan the subdirectories.
3046 foreach $dir (@subdirs) {
3047 next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
3048 &ReadSourceDocumentation ("$source_dir/$dir");
3053 #############################################################################
3054 # Function : ScanSourceFile
3055 # Description : Scans one source file looking for specially-formatted comment
3056 # blocks. Later &MergeSourceDocumentation is used to merge any
3057 # documentation found with the documentation already read in
3058 # from the template files.
3060 # Arguments : $file - the file to scan.
3061 #############################################################################
3063 sub ScanSourceFile {
3067 if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
3070 &LogWarning ($file, 1, "Can't find basename for this filename.");
3074 # Check if the basename is in the list of files to ignore.
3075 if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
3079 #print "DEBUG: Scanning $file\n";
3081 open (SRCFILE, $file)
3082 || die "Can't open $file: $!";
3083 my $in_comment_block = 0;
3085 my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
3086 my ($description, $return_desc, $return_start, $return_style);
3087 my ($since_desc, $stability_desc, $deprecated_desc);
3089 my $ignore_broken_returns;
3092 # Look for the start of a comment block.
3093 if (!$in_comment_block) {
3094 if (m%^\s*/\*.*\*/%) {
3095 #one-line comment - not gtkdoc
3096 } elsif (m%^\s*/\*\*\s%) {
3097 #print "Found comment block start\n";
3099 $in_comment_block = 1;
3101 # Reset all the symbol data.
3103 $in_description = 0;
3112 $deprecated_desc = "";
3113 $stability_desc = "";
3114 $current_param = -1;
3115 $ignore_broken_returns = 0;
3121 # We're in a comment block. Check if we've found the end of it.
3124 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
3126 # Add the return value description onto the end of the params.
3128 push (@params, "Returns");
3129 push (@params, $return_desc);
3130 if ($return_style eq 'broken') {
3131 &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
3134 # Convert special SGML characters
3135 $description = &ConvertSGMLChars ($symbol, $description);
3137 for ($k = 1; $k <= $#params; $k += 2) {
3138 $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
3141 # Handle Section docs
3142 if ($symbol =~ m/SECTION:\s*(.*)/) {
3146 #print "SECTION DOCS found in source for : '$real_symbol'\n";
3147 $ignore_broken_returns = 1;
3148 for ($k = 0; $k <= $#params; $k += 2) {
3149 #print " '".$params[$k]."'\n";
3150 $params[$k] = "\L$params[$k]";
3152 if ($params[$k] eq "short_description") {
3153 $key = "$TMPL_DIR/$real_symbol:Short_Description";
3154 } elsif ($params[$k] eq "see_also") {
3155 $key = "$TMPL_DIR/$real_symbol:See_Also";
3156 } elsif ($params[$k] eq "title") {
3157 $key = "$TMPL_DIR/$real_symbol:Title";
3158 } elsif ($params[$k] eq "stability") {
3159 $key = "$TMPL_DIR/$real_symbol:Stability_Level";
3160 } elsif ($params[$k] eq "section_id") {
3161 $key = "$TMPL_DIR/$real_symbol:Section_Id";
3162 } elsif ($params[$k] eq "include") {
3163 $key = "$TMPL_DIR/$real_symbol:Include";
3165 if (defined($key)) {
3166 $SourceSymbolDocs{$key}=$params[$k+1];
3167 $SourceSymbolSourceFile{$key} = $file;
3168 $SourceSymbolSourceLine{$key} = $.;
3171 $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3172 $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3173 $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3174 #$SourceSymbolTypes{$symbol} = "SECTION";
3176 #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3177 $SourceSymbolDocs{$symbol} = $description;
3178 $SourceSymbolParams{$symbol} = [ @params ];
3179 # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3180 #if (defined $DeclarationTypes{$symbol}) {
3181 # $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3183 $SourceSymbolSourceFile{$symbol} = $file;
3184 $SourceSymbolSourceLine{$symbol} = $.;
3188 ($since_desc, my @extra_lines) = split ("\n", $since_desc);
3189 $since_desc =~ s/^\s+//;
3190 $since_desc =~ s/\s+$//;
3191 #print "Since($symbol) : [$since_desc]\n";
3192 $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3193 if(scalar @extra_lines) {
3194 &LogWarning ($file, $., "multi-line since docs found");
3198 if ($stability_desc) {
3199 $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3200 $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3203 if ($deprecated_desc) {
3204 if (exists $Deprecated{$symbol}) {
3207 # don't warn for signals and properties
3208 #if ($symbol !~ m/::?(.*)/) {
3209 if (defined $DeclarationTypes{$symbol}) {
3210 &LogWarning ($file, $.,
3211 "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3212 " (See the --deprecated-guards option for gtkdoc-scan.)");
3215 $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3219 $in_comment_block = 0;
3223 # Get rid of ' * ' at start of every line in the comment block.
3225 # But make sure we don't get rid of the newline at the end.
3229 #print "DEBUG: scanning :$_";
3231 # If we haven't found the symbol name yet, look for it.
3233 if (m%^\s*(SECTION:\s*\S+)%) {
3235 #print "SECTION DOCS found in source for : '$symbol'\n";
3236 $ignore_broken_returns = 1;
3237 } elsif (m%^\s*([\w:-]*\w)\s*:?%) {
3239 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3244 # If we're in the return value description, add it to the end.
3246 # If we find another valid returns line, we assume that the first
3247 # one was really part of the description.
3248 if (m/^\s*(returns:|return\s+value:)/i) {
3249 if ($return_style eq 'broken') {
3250 $description .= $return_start . $return_desc;
3253 if ($return_style eq 'sane') {
3254 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3256 $return_style = 'sane';
3257 $ignore_broken_returns = 1;
3259 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3260 $description .= $return_start . $return_desc;
3262 $return_style = 'broken';
3264 } elsif (m%^\s*since:%i) {
3268 } elsif (m%^\s*stability:%i) {
3269 $stability_desc = $';
3272 } elsif (m%^\s*deprecated:%i) {
3273 $deprecated_desc = $';
3283 if (m/^\s*(returns:|return\s+value:)/i) {
3284 if ($return_style eq 'broken') {
3285 $description .= $return_start . $return_desc;
3288 if ($return_style eq 'sane') {
3289 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3291 $return_style = 'sane';
3292 $ignore_broken_returns = 1;
3296 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3298 $return_style = 'broken';
3302 } elsif (m%^\s*deprecated:%i) {
3303 $deprecated_desc = $';
3306 } elsif (m%^\s*stability:%i) {
3307 $stability_desc = $';
3316 if ($in_stability) {
3317 if (m/^\s*(returns:|return\s+value:)/i) {
3318 if ($return_style eq 'broken') {
3319 $description .= $return_start . $return_desc;
3322 if ($return_style eq 'sane') {
3323 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3325 $return_style = 'sane';
3326 $ignore_broken_returns = 1;
3330 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3332 $return_style = 'broken';
3336 } elsif (m%^\s*deprecated:%i) {
3337 $deprecated_desc = $';
3340 } elsif (m%^\s*since:%i) {
3345 $stability_desc .= $_;
3350 if ($in_deprecated) {
3351 if (m/^\s*(returns:|return\s+value:)/i) {
3352 if ($return_style eq 'broken') {
3353 $description .= $return_start . $return_desc;
3356 if ($return_style eq 'sane') {
3357 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3359 $return_style = 'sane';
3360 $ignore_broken_returns = 1;
3364 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3366 $return_style = 'broken';
3370 } elsif (m%^\s*since:%i) {
3374 } elsif (m%^\s*stability:%i) {
3375 $stability_desc = $';
3379 $deprecated_desc .= $_;
3384 # If we're in the description part, check for the 'Returns:' line.
3385 # If that isn't found, add the text to the end.
3386 if ($in_description) {
3387 # Get rid of 'Description:'
3388 s%^\s*Description:%%;
3390 if (m/^\s*(returns:|return\s+value:)/i) {
3391 if ($return_style eq 'broken') {
3392 $description .= $return_start . $return_desc;
3395 if ($return_style eq 'sane') {
3396 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3398 $return_style = 'sane';
3399 $ignore_broken_returns = 1;
3403 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3405 $return_style = 'broken';
3409 } elsif (m%^\s*since:%i) {
3413 } elsif (m%^\s*deprecated:%i) {
3414 $deprecated_desc = $';
3417 } elsif (m%^\s*stability:%i) {
3418 $stability_desc = $';
3427 # We must be in the parameters. Check for the empty line below them.
3429 $in_description = 1;
3433 # Look for a parameter name.
3434 if (m%^\s*@(\S+)\s*:%) {
3435 my $param_name = $1;
3436 #print "Found parameter: $param_name\n";
3437 # Allow '...' as the Varargs parameter.
3438 if ($param_name eq "...") {
3439 $param_name = "Varargs";
3441 if ("\L$param_name" eq "returns") {
3442 $return_style = 'sane';
3443 $ignore_broken_returns = 1;
3445 push (@params, $param_name);
3447 $current_param += 2;
3451 # We must be in the middle of a parameter description, so add it on
3452 # to the last element in @params.
3453 if ($current_param == -1) {
3454 &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
3456 $params[$#params] .= $_;
3462 #############################################################################
3463 # Function : OutputMissingDocumentation
3464 # Description : Outputs report of documentation coverage to a file
3467 #############################################################################
3469 sub OutputMissingDocumentation {
3470 my $n_documented = 0;
3471 my $n_incomplete = 0;
3477 my $buffer_deprecated = "";
3478 my $buffer_descriptions = "";
3480 open (UNDOCUMENTED, ">$ROOT_DIR/$MODULE-undocumented.txt")
3481 || die "Can't create $ROOT_DIR/$MODULE-undocumented.txt: $!";
3483 foreach $symbol (sort (keys (%AllSymbols))) {
3484 if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include)/) {
3486 if (exists ($AllDocumentedSymbols{$symbol})) {
3488 if (exists ($AllIncompleteSymbols{$symbol})) {
3490 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3492 } elsif (exists $Deprecated{$symbol}) {
3493 if (exists ($AllIncompleteSymbols{$symbol})) {
3495 $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3497 $buffer_deprecated .= $symbol . "\n";
3500 if (exists ($AllIncompleteSymbols{$symbol})) {
3502 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3504 $buffer .= $symbol . "\n";
3507 } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
3509 #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
3510 #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
3511 #print "%%%% $symbol : $len1,$len2\n";
3512 if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
3513 || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
3516 $symbol =~ m/^.*\/(.*)$/;
3517 $buffer_descriptions .= $1 . "\n";
3522 $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
3527 $percent = ($n_documented / $total) * 100.0;
3530 printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
3531 print UNDOCUMENTED "$n_documented symbols documented.\n";
3532 print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
3533 print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
3535 print UNDOCUMENTED $buffer;
3537 close (UNDOCUMENTED);
3539 printf (("%.0f%% symbol docs coverage ($n_documented symbols documented, $n_incomplete symbols incomplete, " . ($total - $n_documented) . " not documented)\nSee $MODULE-undocumented.txt for a list of missing docs.\nThe doc coverage percentage doesn't include intro sections.\n"), $percent);
3543 #############################################################################
3544 # Function : OutputUndeclaredSymbols
3545 # Description : Outputs symbols that are undeclared yet documented to a file
3548 #############################################################################
3550 sub OutputUndeclaredSymbols {
3551 open(UNDECLARED, ">$ROOT_DIR/$MODULE-undeclared.txt")
3552 || die "Can't create $ROOT_DIR/$MODULE-undeclared.txt";
3554 if (%UndeclaredSymbols) {
3555 print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
3556 print UNDECLARED "\n";
3557 print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
3563 #############################################################################
3564 # Function : OutputAllSymbols
3565 # Description : Outputs list of all symbols to a file
3568 #############################################################################
3570 sub OutputAllSymbols {
3571 my $n_documented = 0;
3577 open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
3578 || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
3580 foreach $symbol (sort (keys (%AllSymbols))) {
3581 print SYMBOLS $symbol . "\n"
3588 #############################################################################
3589 # Function : MergeSourceDocumentation
3590 # Description : This merges documentation read from a source file into the
3591 # documentation read in from a template file.
3593 # Parameter descriptions override any in the template files.
3594 # Function descriptions are placed before any description from
3595 # the template files.
3598 #############################################################################
3600 sub MergeSourceDocumentation {
3604 if (scalar %SymbolDocs) {
3605 @Symbols=keys (%SymbolDocs);
3606 #print "num existing entries: ".(scalar @Symbols)."\n";
3607 #print " ",$Symbols[0], " ",$Symbols[1],"\n";
3610 # filter scanned declarations, with what we suppress from -sections.txt
3612 foreach $symbol (keys (%Declarations)) {
3613 if ($KnownSymbols{$symbol}) {
3617 # and add whats found in the source
3618 foreach $symbol (keys (%SourceSymbolDocs)) {
3621 @Symbols = keys (%tmp);
3622 #print "num source entries: ".(scalar @Symbols)."\n";
3624 foreach $symbol (@Symbols) {
3625 $AllSymbols{$symbol} = 1;
3627 my $have_tmpl_docs = 0;
3629 ## See if the symbol is documented in template
3630 my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
3631 my $check_tmpl_doc =$tmpl_doc;
3632 # remove all xml-tags and whitespaces
3633 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
3634 $check_tmpl_doc =~ s/<.*?>//g;
3635 $check_tmpl_doc =~ s/\s//g;
3637 if ($check_tmpl_doc ne "") {
3638 $have_tmpl_docs = 1;
3639 #print "## [$check_tmpl_doc]\n";
3642 if (exists ($SourceSymbolDocs{$symbol})) {
3643 my $type = $DeclarationTypes {$symbol};
3645 #print "merging [$symbol] from source\n";
3647 my $item = "Parameter";
3648 if (defined ($type)) {
3649 if ($type eq 'STRUCT') {
3651 } elsif ($type eq 'ENUM') {
3653 } elsif ($type eq 'UNION') {
3660 my $src_doc = $SourceSymbolDocs{$symbol};
3661 # remove leading and training whitespaces
3662 $src_doc =~ s/^\s+//;
3663 $src_doc =~ s/\s+$//;
3665 # Don't output warnings for overridden titles as titles are
3666 # automatically generated in the -sections.txt file, and thus they
3667 # are often overridden.
3668 if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
3669 # check if content is different
3670 if ($tmpl_doc ne $src_doc) {
3671 #print "[$tmpl_doc] [$src_doc]\n";
3672 &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
3673 "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
3677 if ($src_doc ne "") {
3678 $AllDocumentedSymbols{$symbol} = 1;
3681 # Convert <!--PARAMETERS--> with any blank lines around it to
3682 # a </para> followed by <!--PARAMETERS--> followed by <para>.
3683 $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
3685 # If there is a blank line, finish the paragraph and start another.
3686 $src_doc = &ConvertBlankLines ($src_doc, $symbol);
3688 if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
3689 $SymbolDocs{$symbol} = "<para>\n$src_doc</para>\n$tmpl_doc";
3690 } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
3691 # For the title/summary/see also section docs we don't want to
3692 # add any <para> tags.
3693 $SymbolDocs{$symbol} = "$src_doc"
3695 $SymbolDocs{$symbol} = "<para>\n$src_doc</para>\n$tmpl_doc";
3699 if ($symbol =~ m/.*::.*/) {
3700 # For signals we prefer the param names from the source docs,
3701 # since the ones from the templates are likely to contain the
3702 # artificial argn names which are generated by gtkdoc-scangobj.
3703 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
3704 # FIXME: we need to check for empty docs here as well!
3706 # The templates contain the definitive parameter names and order,
3707 # so we will not change that. We only override the actual text.
3708 my $tmpl_params = $SymbolParams{$symbol};
3709 if (!defined ($tmpl_params)) {
3710 #print "No merge needed for $symbol\n";
3711 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
3713 my $params = $SourceSymbolParams{$symbol};
3715 #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
3716 for ($j = 0; $j <= $#$tmpl_params; $j += 2) {
3717 my $tmpl_param_name = $$tmpl_params[$j];
3719 # Allow '...' as the Varargs parameter.
3720 if ($tmpl_param_name eq "...") {
3721 $tmpl_param_name = "Varargs";
3724 # Try to find the param in the source comment documentation.
3727 for ($k = 0; $k <= $#$params; $k += 2) {
3728 my $param_name = $$params[$k];
3729 my $param_desc = $$params[$k + 1];
3731 # We accept changes in case, since the Gnome source docs
3732 # contain a lot of these.
3733 if ("\L$param_name" eq "\L$tmpl_param_name") {
3736 # Override the description.
3737 $$tmpl_params[$j + 1] = $param_desc;
3739 # Set the name to "" to mark it as used.
3745 # If it looks like the parameters are there, but not
3746 # in the right place, try to explain a bit better.
3747 if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
3748 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3749 "Parameters for $symbol must start on the line immediately after the function or macro name.");
3753 # Now we output a warning if parameters have been described which
3755 for ($j = 0; $j <= $#$params; $j += 2) {
3756 my $param_name = $$params[$j];
3758 # the template builder cannot detect if a macro returns
3760 if(($type eq "MACRO") && ($param_name eq "Returns")) {
3763 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3764 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
3770 if ($have_tmpl_docs) {
3771 $AllDocumentedSymbols{$symbol} = 1;
3772 #print "merging [$symbol] from template\n";
3775 #print "[$symbol] undocumented\n";
3779 # if this symbol is documented, check if docs are complete
3780 $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
3781 # remove all xml-tags and whitespaces
3782 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
3783 $check_tmpl_doc =~ s/<.*?>//g;
3784 $check_tmpl_doc =~ s/\s//g;
3785 if ($check_tmpl_doc ne "") {
3786 my $tmpl_params = $SymbolParams{$symbol};
3787 if (defined ($tmpl_params)) {
3788 my $type = $DeclarationTypes {$symbol};
3790 my $item = "Parameter";
3791 if (defined ($type)) {
3792 if ($type eq 'STRUCT') {
3794 } elsif ($type eq 'ENUM') {
3796 } elsif ($type eq 'UNION') {
3803 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params,"\n";
3806 for ($j = 0; $j <= $#$tmpl_params; $j += 2) {
3807 # Output a warning if the parameter is empty and
3808 # remember for stats.
3809 my $tmpl_param_name = $$tmpl_params[$j];
3810 my $tmpl_param_desc = $$tmpl_params[$j + 1];
3811 if ($tmpl_param_desc !~ m/\S/) {
3812 if (exists ($AllIncompleteSymbols{$symbol})) {
3813 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
3815 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
3817 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3818 "$item description for $tmpl_param_name is missing in source code comment block.");
3824 #print "num doc entries: ".(scalar %SymbolDocs)."\n";
3830 if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
3838 # This converts blank lines to "</para><para>", but only outside CDATA and
3839 # <programlisting> tags.
3840 sub ConvertBlankLines {
3841 return &ModifyXMLElements ($_[0], $_[1],
3842 "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
3843 \&ConvertBlankLinesEndTag,
3844 \&ConvertBlankLinesCallback);
3848 sub ConvertBlankLinesEndTag {
3849 if ($_[0] eq "<!\[CDATA\[") {
3851 } elsif ($_[0] eq "|[") {
3854 return "</programlisting>";
3858 sub ConvertBlankLinesCallback {
3859 my ($text, $symbol, $tag) = @_;
3861 # If we're not in CDATA or a <programlisting> we convert blank lines so
3862 # they start a new <para>.
3864 $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
3871 #############################################################################
3872 # LIBRARY FUNCTIONS - These functions are used in both gtkdoc-mkdb and
3873 # gtkdoc-mktmpl and should eventually be moved to a
3875 #############################################################################
3877 #############################################################################
3878 # Function : ReadDeclarationsFile
3879 # Description : This reads in a file containing the function/macro/enum etc.
3882 # Note that in some cases there are several declarations with
3883 # the same name, e.g. for conditional macros. In this case we
3884 # set a flag in the %DeclarationConditional hash so the
3885 # declaration is not shown in the docs.
3887 # If a macro and a function have the same name, e.g. for
3888 # gtk_object_ref, the function declaration takes precedence.
3890 # Some opaque structs are just declared with 'typedef struct
3891 # _name name;' in which case the declaration may be empty.
3892 # The structure may have been found later in the header, so
3893 # that overrides the empty declaration.
3895 # Arguments : $file - the declarations file to read
3896 # $override - if declarations in this file should override
3897 # any current declaration.
3898 #############################################################################
3900 sub ReadDeclarationsFile {
3901 my ($file, $override) = @_;
3903 if ($override == 0) {
3905 %DeclarationTypes = ();
3906 %DeclarationConditional = ();
3907 %DeclarationOutput = ();
3911 || die "Can't open $file: $!";
3912 my $declaration_type = "";
3913 my $declaration_name;
3915 my $is_deprecated = 0;
3917 if (!$declaration_type) {
3918 if (m/^<([^>]+)>/) {
3919 $declaration_type = $1;
3920 $declaration_name = "";
3921 #print "Found declaration: $declaration_type\n";
3925 if (m%^<NAME>(.*)</NAME>%) {
3926 $declaration_name = $1;
3927 } elsif (m%^<DEPRECATED/>%) {
3929 } elsif (m%^</$declaration_type>%) {
3930 #print "Found end of declaration: $declaration_name\n";
3931 # Check that the declaration has a name
3932 if ($declaration_name eq "") {
3933 print "ERROR: $declaration_type has no name $file:$.\n";
3936 # If the declaration is an empty typedef struct _XXX XXX
3937 # set the flag to indicate the struct has a typedef.
3938 if ($declaration_type eq 'STRUCT'
3939 && $declaration =~ m/^\s*$/) {
3940 #print "Struct has typedef: $declaration_name\n";
3941 $StructHasTypedef{$declaration_name} = 1;
3944 # Check if the symbol is already defined.
3945 if (defined ($Declarations{$declaration_name})
3946 && $override == 0) {
3947 # Function declarations take precedence.
3948 if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
3950 } elsif ($declaration_type eq 'FUNCTION') {
3951 if ($is_deprecated) {
3952 $Deprecated{$declaration_name} = "";
3954 $Declarations{$declaration_name} = $declaration;
3955 $DeclarationTypes{$declaration_name} = $declaration_type;
3956 } elsif ($DeclarationTypes{$declaration_name}
3957 eq $declaration_type) {
3958 # If the existing declaration is empty, or is just a
3959 # forward declaration of a struct, override it.
3960 if ($declaration_type eq 'STRUCT') {
3961 if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
3962 if ($is_deprecated) {
3963 $Deprecated{$declaration_name} = "";
3965 $Declarations{$declaration_name} = $declaration;
3966 } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
3967 # Ignore an empty or forward declaration.
3969 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
3972 # set flag in %DeclarationConditional hash for
3973 # multiply defined macros/typedefs.
3974 $DeclarationConditional{$declaration_name} = 1;
3977 &LogWarning ($file, $., "$declaration_name has multiple definitions.");
3980 if ($is_deprecated) {
3981 $Deprecated{$declaration_name} = "";
3983 $Declarations{$declaration_name} = $declaration;
3984 $DeclarationTypes{$declaration_name} = $declaration_type;
3987 $declaration_type = "";
3998 #############################################################################
3999 # Function : ReadSignalsFile
4000 # Description : This reads in an existing file which contains information on
4001 # all GTK signals. It creates the arrays @SignalNames and
4002 # @SignalPrototypes containing info on the signals. The first
4003 # line of the SignalPrototype is the return type of the signal
4004 # handler. The remaining lines are the parameters passed to it.
4005 # The last parameter, "gpointer user_data" is always the same
4006 # so is not included.
4007 # Arguments : $file - the file containing the signal handler prototype
4009 #############################################################################
4011 sub ReadSignalsFile {
4019 my $signal_prototype;
4021 # Reset the signal info.
4022 @SignalObjects = ();
4024 @SignalReturns = ();
4026 @SignalPrototypes = ();
4031 if (!open (INPUT, $file)) {
4032 warn "Can't open $file - skipping signals\n";
4039 $signal_object = "";
4041 $signal_returns = "";
4042 $signal_prototype = "";
4045 if (m/^<NAME>(.*)<\/NAME>/) {
4047 if ($signal_name =~ m/^(.*)::(.*)$/) {
4048 $signal_object = $1;
4049 ($signal_name = $2) =~ s/_/-/g;
4050 #print "Found signal: $signal_name\n";
4052 &LogWarning ($file, $., "Invalid signal name: $signal_name.");
4054 } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
4055 $signal_returns = $1;
4056 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4058 } elsif (m%^</SIGNAL>%) {
4059 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
4060 push (@SignalObjects, $signal_object);
4061 push (@SignalNames, $signal_name);
4062 push (@SignalReturns, $signal_returns);
4063 push (@SignalFlags, $signal_flags);
4064 push (@SignalPrototypes, $signal_prototype);
4067 $signal_prototype .= $_;
4075 #############################################################################
4076 # Function : ReadTemplateFile
4077 # Description : This reads in the manually-edited documentation file
4078 # corresponding to the file currently being created, so we can
4079 # insert the documentation at the appropriate places.
4080 # It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
4081 # is a hash of arrays.
4082 # NOTE: This function is duplicated in gtkdoc-mktmpl (but
4083 # slightly different).
4084 # Arguments : $docsfile - the template file to read in.
4085 # $skip_unused_params - 1 if the unused parameters should be
4087 #############################################################################
4089 sub ReadTemplateFile {
4090 my ($docsfile, $skip_unused_params) = @_;
4092 my $template = "$docsfile.sgml";
4093 if (! -f $template) {
4094 #print "File doesn't exist: $template\n";
4097 #print "Reading $template\n";
4099 # start with empty hashes, we merge the source comment for each file
4105 my $current_type = ""; # Type of symbol being read.
4106 my $current_symbol = ""; # Name of symbol being read.
4107 my $symbol_doc = ""; # Description of symbol being read.
4108 my @params; # Parameter names and descriptions of current
4109 # function/macro/function typedef.
4110 my $current_param = -1; # Index of parameter currently being read.
4111 # Note that the param array contains pairs
4112 # of param name & description.
4113 my $in_unused_params = 0; # True if we are reading in the unused params.
4114 my $in_deprecated = 0;
4116 my $in_stability = 0;
4118 open (DOCS, "$template")
4119 || die "Can't open $template: $!";
4121 if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
4124 if ($symbol eq "Title"
4125 || $symbol eq "Short_Description"
4126 || $symbol eq "Long_Description"
4127 || $symbol eq "See_Also"
4128 || $symbol eq "Stability_Level"
4129 || $symbol eq "Include") {
4131 $symbol = $docsfile . ":" . $symbol;
4134 #print "Found symbol: $symbol\n";
4135 # Remember file and line for the symbol
4136 $SymbolSourceFile{$symbol} = $template;
4137 $SymbolSourceLine{$symbol} = $.;
4139 # Store previous symbol, but remove any trailing blank lines.
4140 if ($current_symbol ne "") {
4141 $symbol_doc =~ s/\s+$//;
4142 $SymbolTypes{$current_symbol} = $current_type;
4143 $SymbolDocs{$current_symbol} = $symbol_doc;
4145 # Check that the stability level is valid.
4146 if ($StabilityLevel{$current_symbol}) {
4147 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4150 if ($current_param >= 0) {
4151 $SymbolParams{$current_symbol} = [ @params ];
4153 # Delete any existing params in case we are overriding a
4154 # previously read template.
4155 delete $SymbolParams{$current_symbol};
4158 $current_type = $type;
4159 $current_symbol = $symbol;
4160 $current_param = -1;
4161 $in_unused_params = 0;
4168 } elsif (m/^<!-- # Unused Parameters # -->/) {
4169 #print "DEBUG: Found unused parameters\n";
4170 $in_unused_params = 1;
4173 } elsif ($in_unused_params && $skip_unused_params) {
4174 # When outputting the DocBook we skip unused parameters.
4175 #print "DEBUG: Skipping unused param: $_";
4179 # Check if param found. Need to handle "..." and "format...".
4180 if (s/^\@([\w\.]+):\040?//) {
4181 my $param_name = $1;
4182 # Allow variations of 'Returns'
4183 if ($param_name =~ m/^[Rr]eturns?$/) {
4184 $param_name = "Returns";
4187 # strip trailing whitespaces and blank lines
4190 #print "Found param for symbol $current_symbol : '$param_name'= '$_'";
4192 if ($param_name eq "Deprecated") {
4194 $Deprecated{$current_symbol} = $_;
4195 } elsif ($param_name eq "Since") {
4198 $Since{$current_symbol} = $_;
4199 } elsif ($param_name eq "Stability") {
4201 $StabilityLevel{$current_symbol} = $_;
4203 push (@params, $param_name);
4205 $current_param += 2;
4208 # strip trailing whitespaces and blank lines
4213 if ($in_deprecated) {
4214 $Deprecated{$current_symbol} .= $_;
4215 } elsif ($in_since) {
4216 &LogWarning ($template, $., "multi-line since docs found");
4217 #$Since{$current_symbol} .= $_;
4218 } elsif ($in_stability) {
4219 $StabilityLevel{$current_symbol} .= $_;
4220 } elsif ($current_param >= 0) {
4221 $params[$current_param] .= $_;
4230 # Remember to finish the current symbol doccs.
4231 if ($current_symbol ne "") {
4233 $symbol_doc =~ s/\s+$//;
4234 $SymbolTypes{$current_symbol} = $current_type;
4235 $SymbolDocs{$current_symbol} = $symbol_doc;
4237 # Check that the stability level is valid.
4238 if ($StabilityLevel{$current_symbol}) {
4239 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4242 if ($current_param >= 0) {
4243 $SymbolParams{$current_symbol} = [ @params ];
4245 # Delete any existing params in case we are overriding a
4246 # previously read template.
4247 delete $SymbolParams{$current_symbol};
4256 #############################################################################
4257 # Function : ReadObjectHierarchy
4258 # Description : This reads in the $MODULE-hierarchy.txt file containing all
4259 # the GtkObject subclasses described in this module (and their
4261 # It places them in the @Objects array, and places their level
4262 # in the widget hierarchy in the @ObjectLevels array, at the
4263 # same index. GtkObject, the root object, has a level of 1.
4265 # FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
4266 # as it goes along, this should be split out into a separate
4270 #############################################################################
4272 sub ReadObjectHierarchy {
4276 if (! -f $OBJECT_TREE_FILE) {
4279 if (!open (INPUT, $OBJECT_TREE_FILE)) {
4280 warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
4284 # FIXME: use $OUTPUT_FORMAT
4285 # my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.$OUTPUT_FORMAT";
4286 my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
4287 my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
4289 open (OUTPUT, ">$new_tree_index")
4290 || die "Can't create $new_tree_index: $!";
4292 if (lc($OUTPUT_FORMAT) eq "xml") {
4293 my $tree_header = $doctype_header;
4295 $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
4296 print (OUTPUT "$tree_header");
4298 print (OUTPUT "<screen>\n");
4300 # Only emit objects if they are supposed to be documented, or if
4301 # they have documented children. To implement this, we maintain a
4302 # stack of pending objects which will be emitted if a documented
4304 my @pending_objects = ();
4305 my @pending_levels = ();
4309 my $level = (length($`)) / 2 + 1;
4312 while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
4313 my $pobject = pop(@pending_objects);
4314 my $plevel = pop(@pending_levels);
4317 push (@pending_objects, $object);
4318 push (@pending_levels, $level);
4320 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
4321 while ($#pending_levels >= 0) {
4322 $object = shift @pending_objects;
4323 $level = shift @pending_levels;
4324 $xref = &MakeXRef ($object);
4326 print (OUTPUT ' ' x ($level * 4), "$xref\n");
4327 push (@Objects, $object);
4328 push (@ObjectLevels, $level);
4333 print (OUTPUT "</screen>\n");
4338 &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
4343 #############################################################################
4344 # Function : ReadInterfaces
4345 # Description : This reads in the $MODULE.interfaces file.
4348 #############################################################################
4350 sub ReadInterfaces {
4353 if (! -f $INTERFACES_FILE) {
4356 if (!open (INPUT, $INTERFACES_FILE)) {
4357 warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
4363 my ($object, @ifaces) = split;
4364 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
4365 my @knownIfaces = ();
4367 # filter out private interfaces, but leave foreign interfaces
4368 foreach my $iface (@ifaces) {
4369 if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
4370 push (@knownIfaces, $iface);
4374 $Interfaces{$object} = join(' ', @knownIfaces);
4380 #############################################################################
4381 # Function : ReadPrerequisites
4382 # Description : This reads in the $MODULE.prerequisites file.
4385 #############################################################################
4387 sub ReadPrerequisites {
4388 %Prerequisites = ();
4390 if (! -f $PREREQUISITES_FILE) {
4393 if (!open (INPUT, $PREREQUISITES_FILE)) {
4394 warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
4400 my ($iface, @prereqs) = split;
4401 if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
4402 my @knownPrereqs = ();
4404 # filter out private prerequisites, but leave foreign prerequisites
4405 foreach my $prereq (@prereqs) {
4406 if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
4407 push (@knownPrereqs, $prereq);
4411 $Prerequisites{$iface} = join(' ', @knownPrereqs);
4417 #############################################################################
4418 # Function : ReadArgsFile
4419 # Description : This reads in an existing file which contains information on
4420 # all GTK args. It creates the arrays @ArgObjects, @ArgNames,
4421 # @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
4423 # Arguments : $file - the file containing the arg information.
4424 #############################################################################
4439 # Reset the args info.
4452 if (!open (INPUT, $file)) {
4453 warn "Can't open $file - skipping args\n";
4470 if (m/^<NAME>(.*)<\/NAME>/) {
4472 if ($arg_name =~ m/^(.*)::(.*)$/) {
4474 ($arg_name = $2) =~ s/_/-/g;
4475 #print "Found arg: $arg_name\n";
4477 &LogWarning ($file, $., "Invalid argument name: $arg_name");
4479 } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
4481 } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
4483 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4485 } elsif (m/^<NICK>(.*)<\/NICK>/) {
4487 } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
4489 if ($arg_blurb eq "(null)") {
4491 &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
4493 } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
4495 } elsif (m%^</ARG>%) {
4496 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
4497 push (@ArgObjects, $arg_object);
4498 push (@ArgNames, $arg_name);
4499 push (@ArgTypes, $arg_type);
4500 push (@ArgRanges, $arg_range);
4501 push (@ArgFlags, $arg_flags);
4502 push (@ArgNicks, $arg_nick);
4503 push (@ArgBlurbs, $arg_blurb);
4504 push (@ArgDefaults, $arg_default);
4513 #############################################################################
4514 # Function : CheckIsObject
4515 # Description : Returns 1 if the given name is a GtkObject or a subclass.
4516 # It uses the global @Objects array.
4517 # Note that the @Objects array only contains classes in the
4518 # current module and their ancestors - not all GTK classes.
4519 # Arguments : $name - the name to check.
4520 #############################################################################
4526 foreach $object (@Objects) {
4527 if ($object eq $name) {
4535 #############################################################################
4536 # Function : MakeReturnField
4537 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
4538 # Arguments : $str - the string to pad.
4539 #############################################################################
4541 sub MakeReturnField {
4544 return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
4547 #############################################################################
4548 # Function : GetSymbolSourceFile
4549 # Description : Get the filename where the symbol docs where taken from.
4550 # Arguments : $symbol - the symbol name
4551 #############################################################################
4553 sub GetSymbolSourceFile {
4556 if (defined($SourceSymbolSourceFile{$symbol})) {
4557 return $SourceSymbolSourceFile{$symbol};
4558 } elsif (defined($SymbolSourceFile{$symbol})) {
4559 return $SymbolSourceFile{$symbol};
4565 #############################################################################
4566 # Function : GetSymbolSourceLine
4567 # Description : Get the file line where the symbol docs where taken from.
4568 # Arguments : $symbol - the symbol name
4569 #############################################################################
4571 sub GetSymbolSourceLine {
4574 if (defined($SourceSymbolSourceLine{$symbol})) {
4575 return $SourceSymbolSourceLine{$symbol};
4576 } elsif (defined($SymbolSourceLine{$symbol})) {
4577 return $SymbolSourceLine{$symbol};