4 # gtk-doc - GTK DocBook documentation generator.
5 # Copyright (C) 1998 Damon Chaplin
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #############################################################################
23 # Script : gtkdoc-mkdb
24 # Description : This creates the DocBook files from the edited templates.
26 # NOTE: When creating SGML IDS, we append ":CAPS" to all
27 # all-caps identifiers to prevent name clashes. (It basically
28 # never is the case that mixed-case identifiers would collide.)
29 # See the CreateValidSGMLID function.
30 #############################################################################
35 unshift @INC, '@PACKAGE_DATA_DIR@';
36 require "gtkdoc-common.pl";
40 # name of documentation module
45 my $SOURCE_SUFFIXES = "";
46 my $IGNORE_FILES = "";
49 my $OUTPUT_ALL_SYMBOLS;
51 my $EXPAND_CONTENT_FILES = "";
53 my $DEFAULT_STABILITY;
57 my %optctl = ('module' => \$MODULE,
58 'source-dir' => \@SOURCE_DIRS,
59 'source-suffixes' => \$SOURCE_SUFFIXES,
60 'ignore-files' => \$IGNORE_FILES,
61 'output-dir' => \$SGML_OUTPUT_DIR,
62 'tmpl-dir' => \$TMPL_DIR,
63 'version' => \$PRINT_VERSION,
64 'help' => \$PRINT_HELP,
65 'main-sgml-file' => \$MAIN_SGML_FILE,
66 'expand-content-files' => \$EXPAND_CONTENT_FILES,
67 'outputallsymbols' => \$OUTPUT_ALL_SYMBOLS,
68 'sgml-mode' => \$SGML_MODE,
69 'default-stability' => \$DEFAULT_STABILITY,
70 'default-includes' => \$DEFAULT_INCLUDES,
71 'output-format' => \$OUTPUT_FORMAT);
72 GetOptions(\%optctl, "module=s", "source-dir:s", "source-suffixes:s", "ignore-files:s", "output-dir:s", "tmpl-dir:s", "version", "outputallsymbols", "expand-content-files:s", "main-sgml-file:s", "extra-db-files:s", "help", "sgml-mode", "default-stability:s", "default-includes:s", "output-format:s");
83 if ($DEFAULT_STABILITY && $DEFAULT_STABILITY ne "Stable"
84 && $DEFAULT_STABILITY ne "Private" && $DEFAULT_STABILITY ne "Unstable") {
90 gtkdoc-mkdb version @VERSION@
92 --module=MODULE_NAME Name of the doc module being parsed
93 --source-dir=DIRNAME Directories which contain inline reference material
94 --source-suffixes=SUFFIXES Suffixes of source files to scan, comma-separated
95 --ignore-files=FILES Files or directories which should not be scanned
96 May be used more than once for multiple directories
97 --output-dir=DIRNAME Directory to put the generated DocBook files in
98 --tmpl-dir=DIRNAME Directory in which template files may be found
99 --main-sgml-file=FILE File containing the toplevel DocBook file.
100 --expand-content-files=FILES Extra DocBook files to expand abbreviations in.
101 --output-format=FORMAT Format to use for the generated docbook, XML or SGML.
102 --sgml-mode Allow DocBook markup in inline documentation.
103 --default-stability=LEVEL Specify default stability Level. Valid values are
104 Stable, Unstable, or Private.
105 --default-includes=FILENAMES Specify default includes for section Synopsis
106 --version Print the version of this program
107 --help Print this help
112 my ($empty_element_end, $doctype_header);
114 if (lc($OUTPUT_FORMAT) eq "xml") {
115 if (!$MAIN_SGML_FILE) {
116 # backwards compatibility
117 if (-e "${MODULE}-docs.sgml") {
118 $MAIN_SGML_FILE="${MODULE}-docs.sgml";
120 $MAIN_SGML_FILE="${MODULE}-docs.xml";
123 $OUTPUT_FORMAT = "xml";
124 $empty_element_end = "/>";
126 if (-e $MAIN_SGML_FILE) {
127 open(INPUT, "<$MAIN_SGML_FILE") || die "Can't open $MAIN_SGML_FILE";
128 $doctype_header = "";
130 if (/^\s*<(book|chapter|article)/) {
131 if ($_ !~ m/http:\/\/www.w3.org\/200[13]\/XInclude/) {
132 $doctype_header = "";
136 $doctype_header .= $_;
141 "<?xml version=\"1.0\"?>\n" .
142 "<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook XML V4.1.2//EN\"\n" .
143 " \"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd\">\n";
145 $doctype_header =~ s/<!DOCTYPE \w+/<!DOCTYPE refentry/;
147 if (!$MAIN_SGML_FILE) {
148 $MAIN_SGML_FILE="${MODULE}-docs.sgml";
150 $OUTPUT_FORMAT = "sgml";
151 $doctype_header = "";
152 $empty_element_end = ">";
157 # All the files are written in subdirectories beneath here.
158 $TMPL_DIR = $TMPL_DIR ? $TMPL_DIR : "$ROOT_DIR/tmpl";
160 # This is where we put all the DocBook output.
161 $SGML_OUTPUT_DIR = $SGML_OUTPUT_DIR ? $SGML_OUTPUT_DIR : "$ROOT_DIR/$OUTPUT_FORMAT";
163 # This file contains the object hierarchy.
164 my $OBJECT_TREE_FILE = "$ROOT_DIR/$MODULE.hierarchy";
166 # This file contains the interfaces.
167 my $INTERFACES_FILE = "$ROOT_DIR/$MODULE.interfaces";
169 # This file contains the prerequisites.
170 my $PREREQUISITES_FILE = "$ROOT_DIR/$MODULE.prerequisites";
172 # This file contains signal arguments and names.
173 my $SIGNALS_FILE = "$ROOT_DIR/$MODULE.signals";
175 # The file containing Arg information.
176 my $ARGS_FILE = "$ROOT_DIR/$MODULE.args";
178 # These global arrays store information on signals. Each signal has an entry
179 # in each of these arrays at the same index, like a multi-dimensional array.
180 my @SignalObjects; # The GtkObject which emits the signal.
181 my @SignalNames; # The signal name.
182 my @SignalReturns; # The return type.
183 my @SignalFlags; # Flags for the signal
184 my @SignalPrototypes; # The rest of the prototype of the signal handler.
186 # These global arrays store information on Args. Each Arg has an entry
187 # in each of these arrays at the same index, like a multi-dimensional array.
188 my @ArgObjects; # The GtkObject which has the Arg.
189 my @ArgNames; # The Arg name.
190 my @ArgTypes; # The Arg type - gint, GtkArrowType etc.
191 my @ArgFlags; # How the Arg can be used - readable/writable etc.
192 my @ArgNicks; # The nickname of the Arg.
193 my @ArgBlurbs; # Docstring of the Arg.
194 my @ArgDefaults; # Default value of the Arg.
195 my @ArgRanges; # The range of the Arg type
196 # These global hashes store declaration info keyed on a symbol name.
198 my %DeclarationTypes;
199 my %DeclarationConditional;
200 my %DeclarationOutput;
204 my %StructHasTypedef;
206 # These global hashes store the existing documentation.
210 my %SymbolSourceFile;
211 my %SymbolSourceLine;
213 # These global hashes store documentation scanned from the source files.
214 my %SourceSymbolDocs;
215 my %SourceSymbolParams;
216 my %SourceSymbolSourceFile;
217 my %SourceSymbolSourceLine;
219 # all documentation goes in here, so we can do coverage analysis
221 my %AllIncompleteSymbols;
222 my %AllDocumentedSymbols;
224 # Undeclared yet documented symbols
225 my %UndeclaredSymbols;
227 # These global arrays store GtkObject and subclasses and the hierarchy.
234 # holds the symbols which are mentioned in $MODULE-sections.txt
237 # Standard C preprocessor directives, which we ignore for '#' abbreviations.
238 my %PreProcessorDirectives;
239 $PreProcessorDirectives{"assert"} = 1;
240 $PreProcessorDirectives{"define"} = 1;
241 $PreProcessorDirectives{"elif"} = 1;
242 $PreProcessorDirectives{"else"} = 1;
243 $PreProcessorDirectives{"endif"} = 1;
244 $PreProcessorDirectives{"error"} = 1;
245 $PreProcessorDirectives{"if"} = 1;
246 $PreProcessorDirectives{"ifdef"} = 1;
247 $PreProcessorDirectives{"ifndef"} = 1;
248 $PreProcessorDirectives{"include"} = 1;
249 $PreProcessorDirectives{"line"} = 1;
250 $PreProcessorDirectives{"pragma"} = 1;
251 $PreProcessorDirectives{"unassert"} = 1;
252 $PreProcessorDirectives{"undef"} = 1;
253 $PreProcessorDirectives{"warning"} = 1;
255 # Create the root DocBook output directory if it doens't exist.
256 if (! -e $SGML_OUTPUT_DIR) {
257 mkdir ("$SGML_OUTPUT_DIR", 0777)
258 || die "Can't create directory: $SGML_OUTPUT_DIR";
261 # Function and other declaration output settings.
262 my $RETURN_TYPE_FIELD_WIDTH = 20;
263 my $SYMBOL_FIELD_WIDTH = 36;
264 my $SIGNAL_FIELD_WIDTH = 16;
266 &ReadKnownSymbols ("$ROOT_DIR/$MODULE-sections.txt");
267 &ReadSignalsFile ($SIGNALS_FILE);
268 &ReadArgsFile ($ARGS_FILE);
269 &ReadObjectHierarchy;
273 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-decl.txt", 0);
274 if (-f "$ROOT_DIR/$MODULE-overrides.txt") {
275 &ReadDeclarationsFile ("$ROOT_DIR/$MODULE-overrides.txt", 1);
278 for my $dir (@SOURCE_DIRS) {
279 &ReadSourceDocumentation ($dir);
282 my $changed = &OutputSGML ("$ROOT_DIR/$MODULE-sections.txt");
284 # If any of the DocBook SGML files have changed, update the timestamp file (so
285 # it can be used for Makefile dependencies).
286 if ($changed || ! -e "$ROOT_DIR/sgml.stamp") {
287 open (TIMESTAMP, ">$ROOT_DIR/sgml.stamp")
288 || die "Can't create $ROOT_DIR/sgml.stamp: $!";
289 print (TIMESTAMP "timestamp");
293 #############################################################################
294 # Function : OutputObjectList
295 # Description : This outputs the alphabetical list of objects, in a columned
296 # table. FIXME: Currently this also outputs ancestor objects
297 # which may not actually be in this module.
299 #############################################################################
301 sub OutputObjectList {
303 my $old_object_index = "$SGML_OUTPUT_DIR/object_index.sgml";
304 my $new_object_index = "$SGML_OUTPUT_DIR/object_index.new";
306 open (OUTPUT, ">$new_object_index")
307 || die "Can't create $new_object_index: $!";
308 print (OUTPUT <<EOF);
309 <informaltable pgwide="1" frame="none">
310 <tgroup cols="$cols">
311 <colspec colwidth="1*"${empty_element_end}
312 <colspec colwidth="1*"${empty_element_end}
313 <colspec colwidth="1*"${empty_element_end}
319 foreach $object (sort(@Objects)) {
320 my $xref = &MakeXRef ($object);
321 if ($count % $cols == 0) { print (OUTPUT "<row>\n"); }
322 print (OUTPUT "<entry>$xref</entry>\n");
323 if ($count % $cols == ($cols - 1)) { print (OUTPUT "</row>\n"); }
327 # emit an empty row, since empty tables are invalid
328 print (OUTPUT "<row><entry> </entry></row>\n");
331 print (OUTPUT <<EOF);
332 </tbody></tgroup></informaltable>
336 &UpdateFileIfChanged ($old_object_index, $new_object_index, 0);
340 #############################################################################
341 # Function : OutputSGML
342 # Description : This collects the output for each section of the docs, and
343 # outputs each file when the end of the section is found.
344 # Arguments : $file - the $MODULE-sections.txt file which contains all of
345 # the functions/macros/structs etc. being documented, organised
346 # into sections and subsections.
347 #############################################################################
352 #print "Reading: $file\n";
354 || die "Can't open $file: $!";
357 my $book_bottom = "";
358 my $includes = (defined $DEFAULT_INCLUDES) ? $DEFAULT_INCLUDES : "";
359 my $section_includes = "";
367 my $signals_synop = "";
368 my $signals_desc = "";
370 my $child_args_synop = "";
371 my $style_args_synop = "";
373 my $child_args_desc = "";
374 my $style_args_desc = "";
377 my $implementations = "";
378 my $prerequisites = "";
380 my @file_objects = ();
384 # merge the source docs, in case there are no templates
385 &MergeSourceDocumentation;
391 } elsif (m/^<SECTION>/) {
399 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
403 } elsif (m/^<SUBSECTION>/) {
405 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
407 #print "Section: $title\n";
409 # We don't want warnings if object & class structs aren't used.
410 $DeclarationOutput{$title} = 1;
411 $DeclarationOutput{"${title}Class"} = 1;
413 } elsif (m/^<FILE>(.*)<\/FILE>/) {
415 if (! defined $templates{$filename}) {
416 if (&ReadTemplateFile ("$TMPL_DIR/$filename", 1)) {
417 &MergeSourceDocumentation;
418 $templates{$filename}=$.;
421 &LogWarning ($file, $., "Double <FILE>$filename</FILE> entry. ".
422 "Previous occurrence on line ".$templates{$filename}.".");
425 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
427 $section_includes = $1;
429 if (defined $DEFAULT_INCLUDES) {
430 &LogWarning ($file, $., "Default <INCLUDE> being overridden by command line option.");
437 } elsif (m/^<\/SECTION>/) {
438 if($title eq "" && $filename eq "") {
439 &LogWarning ($file, $., "Section has no title and no file.");
441 # FIXME: one of those would be enough
445 if ($filename eq "") {
448 #print "End of section: $title\n";
450 $filename =~ s/\s/_/g;
452 my $section_id = $SourceSymbolDocs{"$TMPL_DIR/$filename:Section_Id"};
453 if (defined ($section_id) && $section_id !~ m/^\s*$/) {
454 # Do nothing. Use section_id as it is.
455 } elsif (&CheckIsObject ($title)) {
456 # GtkObjects use their class name as the ID.
457 $section_id = &CreateValidSGMLID ($title);
459 $section_id = &CreateValidSGMLID ("$MODULE-$title");
462 if ($num_symbols > 0) {
463 if (lc($OUTPUT_FORMAT) eq "xml") {
464 $book_bottom .= " <xi:include href=\"xml/$filename.xml\"/>\n";
466 $book_top.="<!ENTITY $section_id SYSTEM \"sgml/$filename.sgml\">\n";
467 $book_bottom .= " &$section_id;\n";
470 if (defined ($SourceSymbolDocs{"$TMPL_DIR/$filename:Include"})) {
471 if ($section_includes) {
472 &LogWarning ($file, $., "Section <INCLUDE> being overridden by inline comments.");
474 $section_includes = $SourceSymbolDocs{"$TMPL_DIR/$filename:Include"};
476 if ($section_includes eq "") {
477 $section_includes = $includes;
480 $signals_synop =~ s/^\n*//g;
481 $signals_synop =~ s/\n+$/\n/g;
482 if ($signals_synop ne '') {
483 $signals_synop = <<EOF;
484 <refsect1 id="$section_id.signals" role="signal_proto">
485 <title role="signal_proto.title">Signals</title>
487 ${signals_synop}</synopsis>
490 $signals_desc =~ s/^\n*//g;
491 $signals_desc =~ s/\n+$/\n/g;
492 $signals_desc = <<EOF;
493 <refsect1 id="$section_id.signal-details" role="signals">
494 <title role="signals.title">Signal Details</title>
500 $args_synop =~ s/^\n*//g;
501 $args_synop =~ s/\n+$/\n/g;
502 if ($args_synop ne '') {
504 <refsect1 id="$section_id.properties" role="properties">
505 <title role="properties.title">Properties</title>
507 ${args_synop}</synopsis>
510 $args_desc =~ s/^\n*//g;
511 $args_desc =~ s/\n+$/\n/g;
513 <refsect1 id="$section_id.property-details" role="property_details">
514 <title role="property_details.title">Property Details</title>
520 $child_args_synop =~ s/^\n*//g;
521 $child_args_synop =~ s/\n+$/\n/g;
522 if ($child_args_synop ne '') {
523 $args_synop .= <<EOF;
524 <refsect1 id="$section_id.child-properties" role="child_properties">
525 <title role="child_properties.title">Child Properties</title>
527 ${child_args_synop}</synopsis>
530 $args_desc =~ s/^\n*//g;
531 $args_desc =~ s/\n+$/\n/g;
533 <refsect1 id="$section_id.child-property-details" role="child_property_details">
534 <title role="child_property_details.title">Child Property Details</title>
540 $style_args_synop =~ s/^\n*//g;
541 $style_args_synop =~ s/\n+$/\n/g;
542 if ($style_args_synop ne '') {
543 $args_synop .= <<EOF;
544 <refsect1 id="$section_id.style-properties" role="style_properties">
545 <title role="style_properties.title">Style Properties</title>
547 ${style_args_synop}</synopsis>
550 $args_desc =~ s/^\n*//g;
551 $args_desc =~ s/\n+$/\n/g;
553 <refsect1 id="$section_id.style-property-details" role="style_properties_details">
554 <title role="style_properties_details.title">Style Property Details</title>
560 $hierarchy =~ s/^\n*//g;
561 $hierarchy =~ s/\n+$/\n/g;
562 if ($hierarchy ne "") {
564 <refsect1 id="$section_id.object-hierarchy" role="object_hierarchy">
565 <title role="object_hierarchy.title">Object Hierarchy</title>
571 $interfaces =~ s/^\n*//g;
572 $interfaces =~ s/\n+$/\n/g;
573 if ($interfaces ne "") {
575 <refsect1 id="$section_id.implemented-interfaces" role="impl_interfaces">
576 <title role="impl_interfaces.title">Implemented Interfaces</title>
582 $implementations =~ s/^\n*//g;
583 $implementations =~ s/\n+$/\n/g;
584 if ($implementations ne "") {
585 $implementations = <<EOF;
586 <refsect1 id="$section_id.implementations" role="implementations">
587 <title role="implementations.title">Known Implementations</title>
593 $prerequisites =~ s/^\n*//g;
594 $prerequisites =~ s/\n+$/\n/g;
595 if ($prerequisites ne "") {
596 $prerequisites = <<EOF;
597 <refsect1 id="$section_id.prerequisites" role="prerequisites">
598 <title role="prerequisites.title">Prerequisites</title>
604 $derived =~ s/^\n*//g;
605 $derived =~ s/\n+$/\n/g;
606 if ($derived ne "") {
608 <refsect1 id="$section_id.derived-interfaces" role="derived_interfaces">
609 <title role="derived_interfaces.title">Known Derived Interfaces</title>
615 $synopsis =~ s/^\n*//g;
616 $synopsis =~ s/\n+$/\n/g;
617 my $file_changed = &OutputSGMLFile ($filename, $title, $section_id,
619 \$synopsis, \$details,
620 \$signals_synop, \$signals_desc,
621 \$args_synop, \$args_desc,
622 \$hierarchy, \$interfaces,
624 \$prerequisites, \$derived,
633 $section_includes = "";
637 $child_args_synop = "";
638 $style_args_synop = "";
640 $child_args_desc = "";
641 $style_args_desc = "";
644 $implementations = "";
648 } elsif (m/^(\S+)/) {
650 #print " Symbol: $symbol\n";
652 # FIXME: check for duplicate entries
653 if (! defined $symbols{$symbol}) {
654 my $declaration = $Declarations{$symbol};
655 if (defined ($declaration)) {
656 # We don't want standard macros/functions of GtkObjects,
657 # or private declarations.
658 if ($subsection ne "Standard" && $subsection ne "Private") {
659 if (&CheckIsObject ($symbol)) {
660 push @file_objects, $symbol;
662 my ($synop, $desc) = &OutputDeclaration ($symbol,
664 my ($sig_synop, $sig_desc) = &GetSignals ($symbol);
665 my ($arg_synop, $child_arg_synop, $style_arg_synop,
666 $arg_desc, $child_arg_desc, $style_arg_desc) = &GetArgs ($symbol);
667 my $hier = &GetHierarchy ($symbol);
668 my $ifaces = &GetInterfaces ($symbol);
669 my $impls = &GetImplementations ($symbol);
670 my $prereqs = &GetPrerequisites ($symbol);
671 my $der = &GetDerived ($symbol);
674 $signals_synop .= $sig_synop;
675 $signals_desc .= $sig_desc;
676 $args_synop .= $arg_synop;
677 $child_args_synop .= $child_arg_synop;
678 $style_args_synop .= $style_arg_synop;
679 $args_desc .= $arg_desc;
680 $child_args_desc .= $child_arg_desc;
681 $style_args_desc .= $style_arg_desc;
683 $interfaces .= $ifaces;
684 $implementations .= $impls;
685 $prerequisites .= $prereqs;
689 # Note that the declaration has been output.
690 $DeclarationOutput{$symbol} = 1;
691 } elsif ($subsection ne "Standard" && $subsection ne "Private") {
692 $UndeclaredSymbols{$symbol} = 1;
693 &LogWarning ($file, $., "No declaration found for $symbol.");
696 $symbols{$symbol}=$.;
699 &LogWarning ($file, $., "Double symbol entry for $symbol. ".
700 "Previous occurrence on line ".$symbols{$symbol}.".");
706 &OutputMissingDocumentation;
707 &OutputUndeclaredSymbols;
709 if ($OUTPUT_ALL_SYMBOLS) {
713 for $filename (split (' ', $EXPAND_CONTENT_FILES)) {
714 my $file_changed = &OutputExtraFile ($filename);
720 &OutputBook ($book_top, $book_bottom);
726 #############################################################################
727 # Function : ReadKnownSymbols
728 # Description : This collects the names of non-private symbols from the
729 # $MODULE-sections.txt file.
730 # Arguments : $file - the $MODULE-sections.txt file which contains all of
731 # the functions/macros/structs etc. being documented, organised
732 # into sections and subsections.
733 #############################################################################
735 sub ReadKnownSymbols {
740 #print "Reading: $file\n";
742 || die "Can't open $file: $!";
748 } elsif (m/^<SECTION>/) {
751 } elsif (m/^<SUBSECTION\s*(.*)>/i) {
754 } elsif (m/^<SUBSECTION>/) {
757 } elsif (m/^<TITLE>(.*)<\/TITLE>/) {
760 } elsif (m/^<FILE>(.*)<\/FILE>/) {
763 } elsif (m/^<INCLUDE>(.*)<\/INCLUDE>/) {
766 } elsif (m/^<\/SECTION>/) {
769 } elsif (m/^(\S+)/) {
772 if ($subsection ne "Standard" && $subsection ne "Private") {
773 $KnownSymbols{$symbol} = 1;
776 $KnownSymbols{$symbol} = 0;
784 #############################################################################
785 # Function : OutputDeclaration
786 # Description : Returns the synopsis and detailed description DocBook
787 # describing one function/macro etc.
788 # Arguments : $symbol - the name of the function/macro begin described.
789 # $declaration - the declaration of the function/macro.
790 #############################################################################
792 sub OutputDeclaration {
793 my ($symbol, $declaration) = @_;
795 my $type = $DeclarationTypes {$symbol};
796 if ($type eq 'MACRO') {
797 return &OutputMacro ($symbol, $declaration);
798 } elsif ($type eq 'TYPEDEF') {
799 return &OutputTypedef ($symbol, $declaration);
800 } elsif ($type eq 'STRUCT') {
801 return &OutputStruct ($symbol, $declaration);
802 } elsif ($type eq 'ENUM') {
803 return &OutputEnum ($symbol, $declaration);
804 } elsif ($type eq 'UNION') {
805 return &OutputUnion ($symbol, $declaration);
806 } elsif ($type eq 'VARIABLE') {
807 return &OutputVariable ($symbol, $declaration);
809 } elsif ($type eq 'FUNCTION') {
810 return &OutputFunction ($symbol, $declaration, $type);
811 } elsif ($type eq 'USER_FUNCTION') {
812 return &OutputFunction ($symbol, $declaration, $type);
814 die "Unknown symbol type";
819 #############################################################################
820 # Function : OutputSymbolTraits
821 # Description : Returns the Since and StabilityLevel paragraphs for a symbol.
822 # Arguments : $symbol - the name of the function/macro begin described.
823 #############################################################################
825 sub OutputSymbolTraits {
829 if (exists $Since{$symbol}) {
830 $desc .= "<para role=\"since\">Since $Since{$symbol}</para>";
832 if (exists $StabilityLevel{$symbol}) {
833 $desc .= "<para role=\"stability\">Stability Level: $StabilityLevel{$symbol}</para>";
839 #############################################################################
840 # Function : OutputMacro
841 # Description : Returns the synopsis and detailed description of a macro.
842 # Arguments : $symbol - the macro.
843 # $declaration - the declaration of the macro.
844 #############################################################################
847 my ($symbol, $declaration) = @_;
848 my $id = &CreateValidSGMLID ($symbol);
849 my $condition = &MakeConditionDescription ($symbol);
850 my $synop = &MakeReturnField("#define") . "<link linkend=\"$id\">$symbol</link>";
856 if ($declaration =~ m/^\s*#\s*define(\s+)\w+(\([^\)]*\))/) {
860 if (length ($symbol) < $SYMBOL_FIELD_WIDTH) {
861 $synop .= (' ' x ($SYMBOL_FIELD_WIDTH - length ($symbol)));
864 # Try to align all the lines of args correctly.
865 $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH + $SYMBOL_FIELD_WIDTH + 1);
866 my $args_padded = $args;
867 $args_padded =~ s/ *\\\n */\n$pad/gm;
868 $synop .= &CreateValidSGML ($args_padded);
872 my $title = $symbol . ($args ? "()" : "");
873 $desc = "<refsect2 id=\"$id\" role=\"macro\"$condition>\n<title>$title</title>\n";
874 $desc .= MakeIndexterms($symbol, $id);
876 # Don't output the macro definition if is is a conditional macro or it
877 # looks like a function, i.e. starts with "g_" or "_?gnome_", or it is
878 # longer than 2 lines, otherwise we get lots of complicated macros like
880 if (!defined ($DeclarationConditional{$symbol}) && ($symbol !~ m/^g_/)
881 && ($symbol !~ m/^_?gnome_/) && (($declaration =~ tr/\n//) < 2)) {
882 $declaration = &CreateValidSGML ($declaration);
883 $desc .= "<programlisting>$declaration</programlisting>\n";
885 $desc .= "<programlisting>" . &MakeReturnField("#define") . "$symbol";
886 # Align each line so that if should all line up OK.
887 $pad = ' ' x ($RETURN_TYPE_FIELD_WIDTH - length ("#define "));
888 $args =~ s/\n/\n$pad/gm;
889 $desc .= &CreateValidSGML ($args);
890 $desc .= "</programlisting>\n";
893 $desc .= &MakeDeprecationNote($symbol);
895 my $parameters = &OutputParamDescriptions ("MACRO", $symbol);
896 my $parameters_output = 0;
898 if (defined ($SymbolDocs{$symbol})) {
899 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
901 # Try to insert the parameter table at the author's desired position.
902 # Otherwise we need to tag it onto the end.
903 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
904 $parameters_output = 1;
906 $desc .= $symbol_docs;
909 if ($parameters_output == 0) {
910 $desc .= $parameters;
913 $desc .= OutputSymbolTraits ($symbol);
914 $desc .= "</refsect2>\n";
915 return ($synop, $desc);
919 #############################################################################
920 # Function : OutputTypedef
921 # Description : Returns the synopsis and detailed description of a typedef.
922 # Arguments : $symbol - the typedef.
923 # $declaration - the declaration of the typedef,
924 # e.g. 'typedef unsigned int guint;'
925 #############################################################################
928 my ($symbol, $declaration) = @_;
929 my $id = &CreateValidSGMLID ($symbol);
930 my $condition = &MakeConditionDescription ($symbol);
931 my $synop = &MakeReturnField("typedef") . "<link linkend=\"$id\">$symbol</link>;\n";
932 my $desc = "<refsect2 id=\"$id\" role=\"typedef\"$condition>\n<title>$symbol</title>\n";
934 $desc .= MakeIndexterms($symbol, $id);
936 if (!defined ($DeclarationConditional{$symbol})) {
937 $declaration = &CreateValidSGML ($declaration);
938 $desc .= "<programlisting>$declaration</programlisting>\n";
941 $desc .= &MakeDeprecationNote($symbol);
943 if (defined ($SymbolDocs{$symbol})) {
944 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
946 $desc .= OutputSymbolTraits ($symbol);
947 $desc .= "</refsect2>\n";
948 return ($synop, $desc);
952 #############################################################################
953 # Function : OutputStruct
954 # Description : Returns the synopsis and detailed description of a struct.
955 # We check if it is a widget struct, and if so we only output
956 # parts of it that are noted as public fields.
957 # We also use a different SGML ID for widget structs, since the
958 # original ID is used for the entire RefEntry.
959 # Arguments : $symbol - the struct.
960 # $declaration - the declaration of the struct.
961 #############################################################################
964 my ($symbol, $declaration) = @_;
966 my $is_widget_struct = 0;
967 my $default_to_public = 1;
968 if (&CheckIsObject ($symbol)) {
969 #print "Found widget struct: $symbol\n";
970 $is_widget_struct = 1;
971 $default_to_public = 0;
976 if ($is_widget_struct) {
977 $id = &CreateValidSGMLID ($symbol . "_struct");
978 $condition = &MakeConditionDescription ($symbol . "_struct");
980 $id = &CreateValidSGMLID ($symbol);
981 $condition = &MakeConditionDescription ($symbol);
984 # Determine if it is a simple struct or it also has a typedef.
986 if ($StructHasTypedef{$symbol} || $declaration =~ m/^\s*typedef\s+/) {
993 # For structs with typedefs we just output the struct name.
994 $synop = &MakeReturnField("") . "<link linkend=\"$id\">$symbol</link>;\n";
995 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>$symbol</title>\n";
997 $synop = &MakeReturnField("struct") . "<link linkend=\"$id\">$symbol</link>;\n";
998 $desc = "<refsect2 id=\"$id\" role=\"struct\"$condition>\n<title>struct $symbol</title>\n";
1001 $desc .= MakeIndexterms($symbol, $id);
1003 # Form a pretty-printed, private-data-removed form of the declaration
1006 if ($declaration =~ m/^\s*$/) {
1007 #print "Found opaque struct: $symbol\n";
1008 $decl_out = "typedef struct _$symbol $symbol;";
1009 } elsif ($declaration =~ m/^\s*struct\s+\w+\s*;\s*$/) {
1010 #print "Found opaque struct: $symbol\n";
1011 $decl_out = "struct $symbol;";
1013 my $public = $default_to_public;
1014 my $new_declaration = "";
1016 my $decl = $declaration;
1018 if ($decl =~ m/^\s*(typedef\s+)?struct\s*\w*\s*(?:\/\*.*\*\/)?\s*{(.*)}\s*\w*\s*;\s*$/s) {
1019 my $struct_contents = $2;
1021 foreach $decl_line (split (/\n/, $struct_contents)) {
1022 #print "Struct line: $decl_line\n";
1023 if ($decl_line =~ m%/\*\s*<\s*public\s*>\s*\*/%) {
1025 } elsif ($decl_line =~ m%/\*\s*<\s*(private|protected)\s*>\s*\*/%) {
1028 $new_declaration .= $decl_line . "\n";
1032 if ($new_declaration) {
1033 # Strip any blank lines off the ends.
1034 $new_declaration =~ s/^\s*\n//;
1035 $new_declaration =~ s/\n\s*$/\n/;
1038 $decl_out = "typedef struct {\n" . $new_declaration
1041 $decl_out = "struct $symbol {\n" . $new_declaration
1046 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1047 "Couldn't parse struct:\n$declaration");
1050 # If we couldn't parse the struct or it was all private, output an
1051 # empty struct declaration.
1052 if ($decl_out eq "") {
1054 $decl_out = "typedef struct _$symbol $symbol;";
1056 $decl_out = "struct $symbol;";
1061 $decl_out = &CreateValidSGML ($decl_out);
1062 $desc .= "<programlisting>$decl_out</programlisting>\n";
1064 $desc .= &MakeDeprecationNote($symbol);
1066 if (defined ($SymbolDocs{$symbol})) {
1067 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1070 # Create a table of fields and descriptions
1072 # FIXME: Inserting  's into the produced type declarations here would
1073 # improve the output in most situations ... except for function
1074 # members of structs!
1075 my @fields = ParseStructDeclaration($declaration, !$default_to_public,
1078 "<structfield>$_[0]</structfield>";
1080 my $params = $SymbolParams{$symbol};
1082 # If no parameters are filled in, we don't generate the description
1083 # table, for backwards compatibility
1086 if (defined $params) {
1087 for (my $i = 1; $i <= $#$params; $i += 2) {
1088 if ($params->[$i] =~ /\S/) {
1096 my %field_descrs = @$params;
1099 <variablelist role="struct">
1102 my $field_name = shift @fields;
1103 my $text = shift @fields;
1104 my $field_descr = $field_descrs{$field_name};
1106 $desc .= "<varlistentry>\n<term>$text</term>\n";
1107 if (defined $field_descr) {
1108 $desc .= "<listitem><simpara>".&ExpandAbbreviations($symbol, $field_descr)."</simpara></listitem>\n";
1110 $desc .= "<listitem></listitem>\n";
1112 $desc .= "</varlistentry>\n";
1115 $desc .= "</variablelist>";
1117 $desc .= OutputSymbolTraits ($symbol);
1118 $desc .= "</refsect2>\n";
1119 return ($synop, $desc);
1123 #############################################################################
1124 # Function : OutputEnum
1125 # Description : Returns the synopsis and detailed description of a enum.
1126 # Arguments : $symbol - the enum.
1127 # $declaration - the declaration of the enum.
1128 #############################################################################
1131 my ($symbol, $declaration) = @_;
1132 my $id = &CreateValidSGMLID ($symbol);
1133 my $condition = &MakeConditionDescription ($symbol);
1134 my $synop = &MakeReturnField("enum") . "<link linkend=\"$id\">$symbol</link>;\n";
1135 my $desc = "<refsect2 id=\"$id\" role=\"enum\"$condition>\n<title>enum $symbol</title>\n";
1137 $desc .= MakeIndexterms($symbol, $id);
1139 $declaration = &CreateValidSGML ($declaration);
1140 $desc .= "<programlisting>$declaration</programlisting>\n";
1142 $desc .= &MakeDeprecationNote($symbol);
1144 if (defined ($SymbolDocs{$symbol})) {
1145 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1148 # Create a table of fields and descriptions
1150 my @members = ParseEnumDeclaration($declaration);
1151 my $params = $SymbolParams{$symbol};
1153 # If no parameters are filled in, we don't generate the description
1154 # table, for backwards compatibility
1157 if (defined $params) {
1158 for (my $i = 1; $i <= $#$params; $i += 2) {
1159 if ($params->[$i] =~ /\S/) {
1167 my %member_descrs = @$params;
1170 <variablelist role="enum">
1172 for my $member_name (@members) {
1173 my $member_descr = $member_descrs{$member_name};
1175 $id = &CreateValidSGMLID ($member_name);
1176 $condition = &MakeConditionDescription ($member_name);
1177 $desc .= "<varlistentry id=\"$id\" role=\"constant\"$condition>\n<term><literal>$member_name</literal></term>\n";
1178 if (defined $member_descr) {
1179 $desc .= "<listitem><simpara>".&ExpandAbbreviations($symbol, $member_descr)."</simpara></listitem>\n";
1181 $desc .= "<listitem></listitem>\n";
1183 $desc .= "</varlistentry>\n";
1186 $desc .= "</variablelist>";
1189 $desc .= OutputSymbolTraits ($symbol);
1190 $desc .= "</refsect2>\n";
1191 return ($synop, $desc);
1195 #############################################################################
1196 # Function : OutputUnion
1197 # Description : Returns the synopsis and detailed description of a union.
1198 # Arguments : $symbol - the union.
1199 # $declaration - the declaration of the union.
1200 #############################################################################
1203 my ($symbol, $declaration) = @_;
1204 my $id = &CreateValidSGMLID ($symbol);
1205 my $condition = &MakeConditionDescription ($symbol);
1206 my $synop = &MakeReturnField("union") . "<link linkend=\"$id\">$symbol</link>;\n";
1207 my $desc = "<refsect2 id=\"$id\" role=\"union\"$condition>\n<title>union $symbol</title>\n";
1209 $desc .= MakeIndexterms($symbol, $id);
1211 $declaration = &CreateValidSGML ($declaration);
1212 $desc .= "<programlisting>$declaration</programlisting>\n";
1214 $desc .= &MakeDeprecationNote($symbol);
1216 if (defined ($SymbolDocs{$symbol})) {
1217 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1219 $desc .= OutputSymbolTraits ($symbol);
1220 $desc .= "</refsect2>\n";
1221 return ($synop, $desc);
1225 #############################################################################
1226 # Function : OutputVariable
1227 # Description : Returns the synopsis and detailed description of a variable.
1228 # Arguments : $symbol - the extern'ed variable.
1229 # $declaration - the declaration of the variable.
1230 #############################################################################
1232 sub OutputVariable {
1233 my ($symbol, $declaration) = @_;
1234 my $id = &CreateValidSGMLID ($symbol);
1235 my $condition = &MakeConditionDescription ($symbol);
1238 if ($declaration =~ m/^\s*extern\s+((const\s+|unsigned\s+)*\w+)(\s+\*+|\*+|\s)(\s*)([A-Za-z]\w*)\s*;/) {
1239 my $mod = defined ($1) ? $1 : "";
1240 my $ptr = defined ($3) ? $3 : "";
1241 my $space = defined ($4) ? $4 : "";
1242 $synop = &MakeReturnField("extern") . "$mod$ptr$space<link linkend=\"$id\">$symbol</link>;\n";
1245 $synop = &MakeReturnField("extern") . "<link linkend=\"$id\">$symbol</link>;\n";
1248 my $desc = "<refsect2 id=\"$id\" role=\"variable\"$condition>\n<title>$symbol</title>\n";
1250 $desc .= MakeIndexterms($symbol, $id);
1252 $declaration = &CreateValidSGML ($declaration);
1253 $desc .= "<programlisting>$declaration</programlisting>\n";
1255 $desc .= &MakeDeprecationNote($symbol);
1257 if (defined ($SymbolDocs{$symbol})) {
1258 $desc .= &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1260 $desc .= OutputSymbolTraits ($symbol);
1261 $desc .= "</refsect2>\n";
1262 return ($synop, $desc);
1266 #############################################################################
1267 # Function : OutputFunction
1268 # Description : Returns the synopsis and detailed description of a function.
1269 # Arguments : $symbol - the function.
1270 # $declaration - the declaration of the function.
1271 #############################################################################
1273 sub OutputFunction {
1274 my ($symbol, $declaration, $symbol_type) = @_;
1275 my $id = &CreateValidSGMLID ($symbol);
1276 my $condition = &MakeConditionDescription ($symbol);
1278 # Take out the return type $1 $3 $4
1279 $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//;
1280 my $type_modifier = defined($1) ? $1 : "";
1283 #print "$symbol pointer is $pointer\n";
1284 my $xref = &MakeXRef ($type);
1286 #if ($symbol_type eq 'USER_FUNCTION') {
1287 # $start = "typedef ";
1290 # We output const rather than G_CONST_RETURN.
1291 $type_modifier =~ s/G_CONST_RETURN/const/g;
1292 $pointer =~ s/G_CONST_RETURN/const/g;
1293 $pointer =~ s/^\s+/ /g;
1295 my $ret_type_len = length ($start) + length ($type_modifier)
1296 + length ($pointer) + length ($type);
1297 my $ret_type_output;
1299 if ($ret_type_len < $RETURN_TYPE_FIELD_WIDTH) {
1300 $ret_type_output = "$start$type_modifier$xref$pointer"
1301 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
1304 # $ret_type_output = "$start$type_modifier$xref$pointer\n"
1305 # . (' ' x $RETURN_TYPE_FIELD_WIDTH);
1307 $ret_type_output = "$start$type_modifier$xref$pointer ";
1308 $symbol_len = $ret_type_len + 1 - $RETURN_TYPE_FIELD_WIDTH;
1311 $symbol_len += length ($symbol);
1312 my $char1 = my $char2 = my $char3 = "";
1313 if ($symbol_type eq 'USER_FUNCTION') {
1320 my ($symbol_output, $symbol_desc_output);
1321 if ($symbol_len < $SYMBOL_FIELD_WIDTH) {
1322 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3"
1323 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1324 $symbol_desc_output = "$char1$char2$symbol$char3"
1325 . (' ' x ($SYMBOL_FIELD_WIDTH - $symbol_len));
1327 $symbol_output = "$char1<link linkend=\"$id\">$char2$symbol</link>$char3\n"
1328 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1329 $symbol_desc_output = "$char1$char2$symbol$char3\n"
1330 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
1333 my $synop = $ret_type_output . $symbol_output . '(';
1334 my $desc = "<refsect2 id=\"$id\" role=\"function\"$condition>\n<title>${symbol} ()</title>\n";
1336 $desc .= MakeIndexterms($symbol, $id);
1338 $desc .= "<programlisting>${ret_type_output}$symbol_desc_output(";
1341 while ($declaration ne "") {
1342 #print "$declaration";
1344 if ($declaration =~ s/^[\s,]+//) {
1345 # skip whitespace and commas
1348 } elsif ($declaration =~ s/^void\s*[,\n]//) {
1352 } elsif ($declaration =~ s/^...\s*[,\n]//) {
1353 if ($param_num == 0) {
1358 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1361 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1365 # allow alphanumerics, '_', '[' & ']' in param names
1366 # Try to match a standard parameter (keep in sync with gtkdoc-mktmpl)
1368 } 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]//) {
1369 my $pre = defined($1) ? $1 : "";
1371 my $ptr = defined($3) ? $3 : "";
1372 my $name = defined($4) ? $4 : "";
1373 my $array = defined($5) ? $5 : "";
1379 if ($ptr && $ptr !~ m/\*$/) { $ptr .= " "; }
1381 #print "$symbol: '$pre' '$type' '$ptr' '$name' '$array'\n";
1383 if (($name eq "") && $pre =~ m/^((un)?signed .*)\s?/ ) {
1389 my $xref = &MakeXRef ($type);
1390 my $label = "$pre$xref $ptr$name$array";
1392 #print "$symbol: '$pre' '$type' '$ptr' '$name' '$array'\n";
1394 if ($param_num == 0) {
1399 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1402 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1406 # Try to match parameters which are functions (keep in sync with gtkdoc-mktmpl)
1407 # $1 $2 $3 $4 $5 $7 $8
1408 } 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]//) {
1409 my $mod1 = defined($1) ? $1 : "";
1410 if (defined($2)) { $mod1 .= $2; }
1413 my $mod2 = defined($5) ? $5 : "";
1416 my $func_params = defined($8) ? $8 : "";
1418 #if (!defined($type)) { print "## no type\n"; };
1419 #if (!defined($ptr1)) { print "## no ptr1\n"; };
1420 #if (!defined($func_ptr)) { print "## no func_ptr\n"; };
1421 #if (!defined($name)) { print "## no name\n"; };
1423 if ($ptr1 && $ptr1 !~ m/\*$/) { $ptr1 .= " "; }
1424 $func_ptr =~ s/\s+//g;
1425 my $xref = &MakeXRef ($type);
1426 my $label = "$mod1$xref$ptr1$mod2 ($func_ptr$name) ($func_params)";
1428 #print "Type: [$mod1][$xref][$ptr1][$mod2] ([$func_ptr][$name]) ($func_params)\n";
1429 if ($param_num == 0) {
1434 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1437 . (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH))
1442 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
1443 "Can't parse args for function $symbol: $declaration");
1449 $desc .= ");</programlisting>\n";
1451 $desc .= &MakeDeprecationNote($symbol);
1453 my $parameters = &OutputParamDescriptions ("FUNCTION", $symbol);
1454 my $parameters_output = 0;
1456 if (defined ($SymbolDocs{$symbol})) {
1457 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
1459 # Try to insert the parameter table at the author's desired position.
1460 # Otherwise we need to tag it onto the end.
1461 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
1462 $parameters_output = 1;
1464 $desc .= $symbol_docs;
1467 if ($parameters_output == 0) {
1468 $desc .= $parameters;
1471 $desc .= OutputSymbolTraits ($symbol);
1472 $desc .= "</refsect2>\n";
1473 return ($synop, $desc);
1477 #############################################################################
1478 # Function : OutputParamDescriptions
1479 # Description : Returns the DocBook output describing the parameters of a
1480 # function, macro or signal handler.
1481 # Arguments : $symbol_type - 'FUNCTION', 'MACRO' or 'SIGNAL'. Signal
1482 # handlers have an implicit user_data parameter last.
1483 # $symbol - the name of the function/macro being described.
1484 #############################################################################
1486 sub OutputParamDescriptions {
1487 my ($symbol_type, $symbol) = @_;
1489 if (defined ($SymbolParams{$symbol})) {
1491 my $params = $SymbolParams{$symbol};
1492 my $params_desc = "";
1494 for ($j = 0; $j <= $#$params; $j += 2) {
1495 my $param_name = $$params[$j];
1496 my $param = $$params[$j + 1];
1497 if ($param_name eq "Returns") {
1498 $returns = &ExpandAbbreviations($symbol, $param);
1500 if ($param_name eq "Varargs") {
1501 $param_name = "...";
1503 $param = &ExpandAbbreviations($symbol, $param);
1504 $params_desc .= "<varlistentry><term><parameter>$param_name</parameter> :</term>\n<listitem><simpara>$param</simpara></listitem></varlistentry>\n";
1508 # Signals have an implicit user_data parameter which we describe.
1509 if ($symbol_type eq "SIGNAL") {
1510 $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";
1513 # Start a table if we need one.
1514 if ($params_desc || $returns) {
1516 <variablelist role="params">
1519 if ($params_desc ne "") {
1520 # $output .= "<varlistentry><term>Parameters:</term><listitem></listitem></varlistentry>\n";
1521 $output .= $params_desc;
1524 # Output the returns info last.
1526 $output .= "<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>$returns</simpara></listitem></varlistentry>\n";
1530 $output .= "</variablelist>";
1537 #############################################################################
1538 # Function : ParseStabilityLevel
1539 # Description : Parses a stability level and outputs a warning if it isn't
1541 # Arguments : $stability - the stability text.
1542 # $file, $line - context for error message
1543 # $message - description of where the level is from, to use in
1544 # any error message.
1545 # Returns : The parsed stability level string.
1546 #############################################################################
1548 sub ParseStabilityLevel {
1549 my ($stability, $file, $line, $message) = @_;
1551 $stability =~ s/^\s*//;
1552 $stability =~ s/\s*$//;
1553 if ($stability =~ m/^stable$/i) {
1554 $stability = "Stable";
1555 } elsif ($stability =~ m/^unstable$/i) {
1556 $stability = "Unstable";
1557 } elsif ($stability =~ m/^private$/i) {
1558 $stability = "Private";
1560 &LogWarning ($file, $line, "$message is $stability.".
1561 "It should be one of these: Stable, Unstable, or Private.");
1567 #############################################################################
1568 # Function : OutputSGMLFile
1569 # Description : Outputs the final DocBook file for one section.
1570 # Arguments : $file - the name of the file.
1571 # $title - the title from the $MODULE-sections.txt file, which
1572 # will be overridden by the title in the template file.
1573 # $section_id - the SGML id to use for the toplevel tag.
1574 # $includes - comma-separates list of include files added at top
1575 # of synopsis, with '<' '>' around them (if not already enclosed in "").
1576 # $synopsis - reference to the DocBook for the Synopsis part.
1577 # $details - reference to the DocBook for the Details part.
1578 # $signal_synop - reference to the DocBook for the Signal Synopsis part
1579 # $signal_desc - reference to the DocBook for the Signal Description part
1580 # $args_synop - reference to the DocBook for the Arg Synopsis part
1581 # $args_desc - reference to the DocBook for the Arg Description part
1582 # $hierarchy - reference to the DocBook for the Object Hierarchy part
1583 # $interfaces - reference to the DocBook for the Interfaces part
1584 # $implementations - reference to the DocBook for the Known Implementations part
1585 # $prerequisites - reference to the DocBook for the Prerequisites part
1586 # $derived - reference to the DocBook for the Derived Interfaces part
1587 # $file_objects - reference to an array of objects in this file
1588 #############################################################################
1590 sub OutputSGMLFile {
1591 my ($file, $title, $section_id, $includes, $synopsis, $details, $signals_synop, $signals_desc, $args_synop, $args_desc, $hierarchy, $interfaces, $implementations, $prerequisites, $derived, $file_objects) = @_;
1593 #print "Output sgml for file $file with title '$title'\n";
1595 # The edited title overrides the one from the sections file.
1596 my $new_title = $SymbolDocs{"$TMPL_DIR/$file:Title"};
1597 if (defined ($new_title) && $new_title !~ m/^\s*$/) {
1598 $title = $new_title;
1599 #print "Found title: $title\n";
1601 my $short_desc = $SymbolDocs{"$TMPL_DIR/$file:Short_Description"};
1602 if (!defined ($short_desc) || $short_desc =~ m/^\s*$/) {
1605 $short_desc = &ExpandAbbreviations("$title:Short_description",
1607 #print "Found short_desc: $short_desc";
1609 my $long_desc = $SymbolDocs{"$TMPL_DIR/$file:Long_Description"};
1610 if (!defined ($long_desc) || $long_desc =~ m/^\s*$/) {
1613 $long_desc = &ExpandAbbreviations("$title:Long_description",
1615 #print "Found long_desc: $long_desc";
1617 my $see_also = $SymbolDocs{"$TMPL_DIR/$file:See_Also"};
1618 if (!defined ($see_also) || $see_also =~ m%^\s*(<para>)?\s*(</para>)?\s*$%) {
1621 $see_also = &ExpandAbbreviations("$title:See_Also", $see_also);
1622 #print "Found see_also: $see_also";
1625 $see_also = "<refsect1 id=\"$section_id.see-also\">\n<title>See Also</title>\n$see_also\n</refsect1>\n";
1627 my $stability = $SymbolDocs{"$TMPL_DIR/$file:Stability_Level"};
1628 if (!defined ($stability) || $stability =~ m/^\s*$/) {
1631 $stability = &ParseStabilityLevel($stability, $file, $., "Section stability level");
1632 #print "Found stability: $stability";
1635 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$stability, unless otherwise indicated\n</refsect1>\n";
1636 } elsif ($DEFAULT_STABILITY) {
1637 $stability = "<refsect1 id=\"$section_id.stability-level\">\n<title>Stability Level</title>\n$DEFAULT_STABILITY, unless otherwise indicated\n</refsect1>\n";
1640 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
1642 my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
1645 my $include_output = "";
1647 foreach $include (split (/,/, $includes)) {
1648 if ($include =~ m/^\".+\"$/) {
1649 $include_output .= "#include ${include}\n";
1652 $include =~ s/^\s+|\s+$//gs;
1653 $include_output .= "#include <${include}>\n";
1656 if ($include_output ne '') {
1657 $include_output = "\n$include_output\n";
1660 my $old_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT";
1661 my $new_sgml_file = "$SGML_OUTPUT_DIR/$file.$OUTPUT_FORMAT.new";
1663 open (OUTPUT, ">$new_sgml_file")
1664 || die "Can't create $new_sgml_file: $!";
1666 my $object_anchors = "";
1667 foreach my $object (@$file_objects) {
1668 next if ($object eq $section_id);
1669 my $id = CreateValidSGMLID($object);
1670 #print "Debug: Adding anchor for $object\n";
1671 $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
1674 # We used to output this, but is messes up our UpdateFileIfChanged code
1675 # since it changes every day (and it is only used in the man pages):
1676 # "<refentry id="$section_id" revision="$mday $month $year">"
1678 if (lc($OUTPUT_FORMAT) eq "xml") {
1679 print OUTPUT $doctype_header;
1683 <refentry id="$section_id">
1685 <refentrytitle role="top_of_page" id="$section_id.top_of_page">$title</refentrytitle>
1686 <manvolnum>3</manvolnum>
1687 <refmiscinfo>\U$MODULE\E Library</refmiscinfo>
1691 <refname>$title</refname>
1692 <refpurpose>$short_desc</refpurpose>
1693 <!--[<xref linkend="desc" endterm="desc.title"/>]-->
1696 <refsynopsisdiv id="$section_id.synopsis" role="synopsis">
1697 <title role="synopsis.title">Synopsis</title>
1700 $include_output$${synopsis}</synopsis>
1711 <refsect1 id="$section_id.description" role="desc">
1712 <title role="desc.title">Description</title>
1716 <refsect1 id="$section_id.details" role="details">
1717 <title role="details.title">Details</title>
1728 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
1732 #############################################################################
1733 # Function : OutputExtraFile
1734 # Description : Copies an "extra" DocBook file into the output directory,
1735 # expanding abbreviations
1736 # Arguments : $file - the source file.
1737 #############################################################################
1738 sub OutputExtraFile {
1743 ($basename = $file) =~ s!^.*/!!;
1745 my $old_sgml_file = "$SGML_OUTPUT_DIR/$basename";
1746 my $new_sgml_file = "$SGML_OUTPUT_DIR/$basename.new";
1750 open(EXTRA_FILE, "<$file") || die "Can't open $file";
1754 $contents = <EXTRA_FILE>;
1757 open (OUTPUT, ">$new_sgml_file")
1758 || die "Can't create $new_sgml_file: $!";
1760 print OUTPUT &ExpandAbbreviations ("$basename file", $contents);
1763 return &UpdateFileIfChanged ($old_sgml_file, $new_sgml_file, 0);
1765 #############################################################################
1766 # Function : OutputBook
1767 # Description : Outputs the SGML entities that need to be included into the
1768 # main SGML file for the module.
1769 # Arguments : $book_top - the declarations of the entities, which are added
1770 # at the top of the main SGML file.
1771 # $book_bottom - the references to the entities, which are
1772 # added in the main SGML file at the desired position.
1773 #############################################################################
1776 my ($book_top, $book_bottom) = @_;
1778 my $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top";
1779 my $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.top.new";
1781 open (OUTPUT, ">$new_file")
1782 || die "Can't create $new_file: $!";
1783 print OUTPUT $book_top;
1786 &UpdateFileIfChanged ($old_file, $new_file, 0);
1789 $old_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom";
1790 $new_file = "$SGML_OUTPUT_DIR/$MODULE-doc.bottom.new";
1792 open (OUTPUT, ">$new_file")
1793 || die "Can't create $new_file: $!";
1794 print OUTPUT $book_bottom;
1797 &UpdateFileIfChanged ($old_file, $new_file, 0);
1800 # If the main SGML file hasn't been created yet, we create it here.
1801 # The user can tweak it later.
1802 if ($MAIN_SGML_FILE && ! -e $MAIN_SGML_FILE) {
1803 open (OUTPUT, ">$MAIN_SGML_FILE")
1804 || die "Can't create $MAIN_SGML_FILE: $!";
1806 if (lc($OUTPUT_FORMAT) eq "xml") {
1808 <?xml version="1.0"?>
1809 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
1810 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
1811 <book id="index" xmlns:xi="http://www.w3.org/2003/XInclude">
1815 <!doctype book PUBLIC "-//Davenport//DTD DocBook V3.0//EN" [
1817 print OUTPUT $book_top;
1826 <title>$MODULE Reference Manual</title>
1828 for $MODULE [VERSION]
1829 The latest version of this documentation can be found on-line at
1830 <ulink role="online-location" url="http://[SERVER]/$MODULE/index.html">http://[SERVER]/$MODULE/</ulink>.
1835 <title>[Insert title here]</title>
1837 print OUTPUT $book_bottom;
1849 #############################################################################
1850 # Function : CreateValidSGMLID
1851 # Description : Creates a valid SGML 'id' from the given string.
1852 # NOTE: SGML ids are case-insensitive, so we have a few special
1853 # cases to avoid clashes of ids.
1854 # Arguments : $id - the string to be converted into a valid SGML id.
1855 #############################################################################
1857 sub CreateValidSGMLID {
1860 # Append ":CAPS" to all all-caps identifiers
1862 # Special case, '_' would end up as '' so we use 'gettext-macro' instead.
1863 if ($id eq "_") { return "gettext-macro"; }
1865 if ($id !~ /[a-z]/) { $id .= ":CAPS" };
1876 #############################################################################
1877 # Function : CreateValidSGML
1878 # Description : This turns any chars which are used in SGML into entities,
1879 # e.g. '<' into '<'
1880 # Arguments : $text - the text to turn into proper SGML.
1881 #############################################################################
1883 sub CreateValidSGML {
1885 $text =~ s/&/&/g; # Do this first, or the others get messed up.
1886 $text =~ s/</</g;
1887 $text =~ s/>/>/g;
1891 #############################################################################
1892 # Function : ConvertSGMLChars
1893 # Description : This is used for text in source code comment blocks, to turn
1894 # chars which are used in SGML into entities, e.g. '<' into
1895 # '<'. Depending on $SGML_MODE, this is done
1896 # unconditionally or only if the character doesn't seem to be
1897 # part of an SGML construct (tag or entity reference).
1898 # Arguments : $text - the text to turn into proper SGML.
1899 #############################################################################
1901 sub ConvertSGMLChars {
1902 my ($symbol, $text) = @_;
1905 # For the SGML mode only convert to entities outside CDATA sections.
1906 return &ModifyXMLElements ($text, $symbol,
1907 "<!\\[CDATA\\[|<programlisting[^>]*>",
1908 \&ConvertSGMLCharsEndTag,
1909 \&ConvertSGMLCharsCallback);
1911 # For the simple non-sgml mode, convert to entities everywhere.
1912 $text =~ s/&/&/g; # Do this first, or the others get messed up.
1913 $text =~ s/</</g;
1914 $text =~ s/>/>/g;
1920 sub ConvertSGMLCharsEndTag {
1921 if ($_[0] eq "<!\[CDATA\[") {
1924 return "</programlisting>";
1928 sub ConvertSGMLCharsCallback {
1929 my ($text, $symbol, $tag) = @_;
1931 if ($tag =~ m/^<programlisting/) {
1932 # We can handle <programlisting> specially here.
1933 return &ModifyXMLElements ($text, $symbol,
1935 \&ConvertSGMLCharsEndTag,
1936 \&ConvertSGMLCharsCallback2);
1937 } elsif ($tag eq "") {
1938 # If we're not in CDATA convert to entities.
1939 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
1940 $text =~ s/<(?![a-zA-Z\/!])/</g;
1941 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
1943 # Handle "#include <xxxxx>"
1944 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
1950 sub ConvertSGMLCharsCallback2 {
1951 my ($text, $symbol, $tag) = @_;
1953 # If we're not in CDATA convert to entities.
1954 # We could handle <programlisting> differently, though I'm not sure it helps.
1956 # replace only if its not a tag
1957 $text =~ s/&(?![a-zA-Z#]+;)/&/g; # Do this first, or the others get messed up.
1958 $text =~ s/<(?![a-zA-Z\/!])/</g;
1959 $text =~ s/(?<![a-zA-Z0-9"'\/-])>/>/g;
1961 # Handle "#include <xxxxx>"
1962 $text =~ s/#include(\s+)<([^>]+)>/#include$1<$2>/g;
1969 #############################################################################
1970 # Function : ExpandAbbreviations
1971 # Description : This turns the abbreviations function(), macro(), @param,
1972 # %constant, and #symbol into appropriate DocBook markup.
1973 # CDATA sections and <programlisting> parts are skipped.
1974 # Arguments : $symbol - the symbol being documented, for error messages.
1975 # $text - the text to expand.
1976 #############################################################################
1978 sub ExpandAbbreviations {
1979 my ($symbol, $text) = @_;
1981 # Convert "|[" and "]|" into the start and end of program listing examples.
1982 $text =~ s%\|\[%<informalexample><programlisting>%g;
1983 $text =~ s%\]\|%</programlisting></informalexample>%g;
1985 # keep CDATA unmodified, preserve ulink tags (ideally we preseve all tags
1987 return &ModifyXMLElements ($text, $symbol,
1988 "<!\\[CDATA\\[|<ulink[^>]*>|<programlisting[^>]*>",
1989 \&ExpandAbbreviationsEndTag,
1990 \&ExpandAbbreviationsCallback);
1994 # Returns the end tag corresponding to the given start tag.
1995 sub ExpandAbbreviationsEndTag {
1996 my ($start_tag) = @_;
1998 if ($start_tag eq "<!\[CDATA\[") {
2000 } elsif ($start_tag =~ m/<(\w+)/) {
2005 # Called inside or outside each CDATA or <programlisting> section.
2006 sub ExpandAbbreviationsCallback {
2007 my ($text, $symbol, $tag) = @_;
2009 if ($tag =~ m/^<programlisting/) {
2010 # Handle any embedded CDATA sections.
2011 return &ModifyXMLElements ($text, $symbol,
2013 \&ExpandAbbreviationsEndTag,
2014 \&ExpandAbbreviationsCallback2);
2015 } elsif ($tag eq "") {
2016 # We are outside any CDATA or <programlisting> sections, so we expand
2017 # any gtk-doc abbreviations.
2019 # Convert 'function()' or 'macro()'.
2020 $text =~ s/(\w+)\s*\(\)/&MakeXRef($1, &tagify($1 . "()", "function"));/eg;
2022 # Convert '@param', but not '\@param'.
2023 #$text =~ s/\@(\w+((\.|->)\w+)*)/<parameter>$1<\/parameter>/g;
2024 $text =~ s/([^\\])\@(\w+((\.|->)\w+)*)/$1<parameter>$2<\/parameter>/g;
2025 $text =~ s/\\\@/\@/g;
2027 # Convert '%constant', but not '\%constant'.
2028 # Also allow negative numbers, e.g. %-1.
2029 #$text =~ s/\%(-?\w+)/&MakeXRef($1, &tagify($1, "literal"));/eg;
2030 $text =~ s/([^\\])\%(-?\w+)/$1.&MakeXRef($2, &tagify($2, "literal"));/eg;
2031 $text =~ s/\\\%/\%/g;
2033 # Convert '#symbol', but not '\#symbol'.
2034 #$text =~ s/#([\w\-:]+)/&MakeHashXRef($1, "type");/eg;
2035 $text =~ s/([^\\])#([\w\-:]+)/$1.&MakeHashXRef($2, "type");/eg;
2042 # This is called inside a <programlisting>
2043 sub ExpandAbbreviationsCallback2 {
2044 my ($text, $symbol, $tag) = @_;
2047 # We are inside a <programlisting> but outside any CDATA sections,
2048 # so we expand any gtk-doc abbreviations.
2049 # FIXME: why is this different from &ExpandAbbreviationsCallback(),
2050 # why not just call it
2051 $text =~ s/#(\w+)/&MakeHashXRef($1, "");/eg;
2058 my ($symbol, $tag) = @_;;
2061 # Check for things like '#include', '#define', and skip them.
2062 if ($PreProcessorDirectives{$symbol}) {
2066 # Get rid of any special '-struct' suffix.
2067 $text =~ s/-struct$//;
2069 # If the symbol is in the form "Object::signal", then change the symbol to
2070 # "Object-signal" and use "signal" as the text.
2071 if ($symbol =~ s/::/-/) {
2075 # If the symbol is in the form "Object:property", then change the symbol to
2076 # "Object--property" and use "property" as the text.
2077 if ($symbol =~ s/:/--/) {
2082 $text = tagify ($text, $tag);
2085 return &MakeXRef($symbol, $text);
2089 #############################################################################
2090 # Function : ModifyXMLElements
2091 # Description : Looks for given XML element tags within the text, and calls
2092 # the callback on pieces of text inside & outside those elements.
2093 # Used for special handling of text inside things like CDATA
2094 # and <programlisting>.
2095 # Arguments : $text - the text.
2096 # $symbol - the symbol currently being documented (only used for
2098 # $start_tag_regexp - the regular expression to match start tags.
2099 # e.g. "<!\\[CDATA\\[|<programlisting[^>]*>" to match
2100 # CDATA sections or programlisting elements.
2101 # $end_tag_func - function which is passed the matched start tag
2102 # and should return the appropriate end tag string.
2103 # $callback - callback called with each part of the text. It is
2104 # called with a piece of text, the symbol being
2105 # documented, and the matched start tag or "" if the text
2106 # is outside the XML elements being matched.
2107 #############################################################################
2108 sub ModifyXMLElements {
2109 my ($text, $symbol, $start_tag_regexp, $end_tag_func, $callback) = @_;
2110 my ($before_tag, $start_tag, $end_tag_regexp, $end_tag);
2113 while ($text =~ m/$start_tag_regexp/s) {
2114 $before_tag = $`; # Prematch for last successful match string
2115 $start_tag = $&; # Last successful match
2116 $text = $'; # Postmatch for last successful match string
2118 $result .= &$callback ($before_tag, $symbol, "");
2119 $result .= $start_tag;
2121 # get the mathing end-tag for current tag
2122 $end_tag_regexp = &$end_tag_func ($start_tag);
2124 if ($text =~ m/$end_tag_regexp/s) {
2129 $result .= &$callback ($before_tag, $symbol, $start_tag);
2130 $result .= $end_tag;
2132 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2133 "Can't find tag end: $end_tag_regexp in docs for: $symbol.");
2134 # Just assume it is all inside the tag.
2135 $result .= &$callback ($text, $symbol, $start_tag);
2140 # Handle any remaining text outside the tags.
2141 $result .= &$callback ($text, $symbol, "");
2150 # Adds a tag around some text.
2151 # e.g tagify("Text", "literal") => "<literal>Text</literal>".
2153 my ($text, $elem) = @_;
2154 return "<" . $elem . ">" . $text . "</" . $elem . ">";
2158 #############################################################################
2159 # Function : MakeXRef
2160 # Description : This returns a cross-reference link to the given symbol.
2161 # Though it doesn't try to do this for a few standard C types
2162 # that it knows won't be in the documentation.
2163 # Arguments : $symbol - the symbol to try to create a XRef to.
2164 # $text - text text to put inside the XRef, defaults to $symbol
2165 #############################################################################
2168 my ($symbol, $text) = ($_[0], $_[1]);
2169 if (!defined($text)) {
2172 # Get rid of special '-struct' suffix.
2173 $text =~ s/-struct$//;
2176 #print "Getting type link for $symbol -> $text\n";
2178 my $symbol_id = &CreateValidSGMLID ($symbol);
2179 return "<link linkend=\"$symbol_id\">$text</link>";
2183 #############################################################################
2184 # Function : MakeIndexterms
2185 # Description : This returns a indexterm elements for the given symbol
2186 # Arguments : $symbol - the symbol to create indexterms for
2187 #############################################################################
2189 sub MakeIndexterms {
2190 my ($symbol, $id) = @_;
2193 if (exists $Deprecated{$symbol}) {
2194 $terms .= "<indexterm zone=\"$id\" role=\"deprecated\"><primary>$symbol</primary></indexterm>"
2196 if (exists $Since{$symbol}) {
2197 my $since = $Since{$symbol};
2201 $terms .= "<indexterm zone=\"$id\" role=\"$since\"><primary>$symbol</primary></indexterm>";
2205 $terms .= "<indexterm zone=\"$id\"><primary>$symbol</primary></indexterm>";
2211 #############################################################################
2212 # Function : MakeDeprecationNote
2213 # Description : This returns a deprecation warning for the given symbol.
2214 # Arguments : $symbol - the symbol to try to create a warning for.
2215 #############################################################################
2217 sub MakeDeprecationNote {
2218 my ($symbol) = $_[0];
2221 if (exists $Deprecated{$symbol}) {
2222 $desc .= "<warning>";
2224 if ($Deprecated{$symbol} =~ /^\s*([0-9\.]+)\s*:/) {
2225 $desc .= "<para><literal>$symbol</literal> has been deprecated since version $1 and should not be used in newly-written code.";
2227 $desc .= "<para><literal>$symbol</literal> is deprecated and should not be used in newly-written code.";
2229 if ($Deprecated{$symbol} ne "") {
2230 $note = &ExpandAbbreviations($symbol, $Deprecated{$symbol});
2231 $note =~ s/^\s*([0-9\.]+)\s*:\s*//;
2234 $note =~ s%\n{2,}%\n</para>\n<para>\n%g;
2235 $desc .= " " . $note;
2237 $desc .= "</para></warning>\n";
2242 #############################################################################
2243 # Function : MakeConditionDescription
2244 # Description : This returns a sumary of conditions for the given symbol.
2245 # Arguments : $symbol - the symbol to try to create the sumary.
2246 #############################################################################
2248 sub MakeConditionDescription {
2249 my ($symbol) = $_[0];
2252 if (exists $Deprecated{$symbol}) {
2257 if ($Deprecated{$symbol} =~ /^\s*(.*?)\s*$/) {
2258 $desc .= "deprecated:$1";
2260 $desc .= "deprecated";
2264 if (exists $Since{$symbol}) {
2269 if ($Since{$symbol} =~ /^\s*(.*?)\s*$/) {
2270 $desc .= "since:$1";
2276 if (exists $StabilityLevel{$symbol}) {
2280 $desc .= "stability:".$StabilityLevel{$symbol};
2284 $desc=" condition=\"".$desc."\"";
2285 #print "condition for '$symbol' = '$desc'\n";
2290 #############################################################################
2291 # Function : GetHierarchy
2292 # Description : Returns the DocBook output describing the ancestors and
2293 # immediate children of a GObject subclass. It uses the
2294 # global @Objects and @ObjectLevels arrays to walk the tree.
2295 # Arguments : $object - the GtkObject subclass.
2296 #############################################################################
2301 # Find object in the objects array.
2307 for ($i = 0; $i < @Objects; $i++) {
2309 if ($ObjectLevels[$i] <= $level) {
2312 elsif ($ObjectLevels[$i] == $level + 1) {
2313 push (@children, $Objects[$i]);
2316 elsif ($Objects[$i] eq $object) {
2319 $level = $ObjectLevels[$i];
2326 # Walk up the hierarchy, pushing ancestors onto the ancestors array.
2328 push (@ancestors, $object);
2329 #print "Level: $level\n";
2330 while ($level > 1) {
2332 if ($ObjectLevels[$j] < $level) {
2333 push (@ancestors, $Objects[$j]);
2334 $level = $ObjectLevels[$j];
2335 #print "Level: $level\n";
2339 # Output the ancestors list, indented and with links.
2340 my $hierarchy = "<synopsis>\n";
2342 for ($i = $#ancestors; $i >= 0; $i--) {
2344 # Don't add a link to the current widget, i.e. when i == 0.
2346 my $ancestor_id = &CreateValidSGMLID ($ancestors[$i]);
2347 $link_text = "<link linkend=\"$ancestor_id\">$ancestors[$i]</link>";
2349 $link_text = "$ancestors[$i]";
2352 $hierarchy .= " $link_text\n";
2354 # $hierarchy .= ' ' x ($level * 6 - 3) . "|\n";
2355 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2359 for ($i = 0; $i <= $#children; $i++) {
2360 my $id = &CreateValidSGMLID ($children[$i]);
2361 my $link_text = "<link linkend=\"$id\">$children[$i]</link>";
2362 $hierarchy .= ' ' x ($level * 6 - 3) . "+----$link_text\n";
2364 $hierarchy .= "</synopsis>\n";
2370 #############################################################################
2371 # Function : GetInterfaces
2372 # Description : Returns the DocBook output describing the interfaces
2373 # implemented by a class. It uses the global %Interfaces hash.
2374 # Arguments : $object - the GtkObject subclass.
2375 #############################################################################
2382 # Find object in the objects array.
2383 if (exists($Interfaces{$object})) {
2384 my @ifaces = split(' ', $Interfaces{$object});
2389 for ($i = 0; $i <= $#ifaces; $i++) {
2390 my $id = &CreateValidSGMLID ($ifaces[$i]);
2391 $text .= " <link linkend=\"$id\">$ifaces[$i]</link>";
2392 if ($i < $#ifaces - 1) {
2395 elsif ($i < $#ifaces) {
2410 #############################################################################
2411 # Function : GetImplementations
2412 # Description : Returns the DocBook output describing the implementations
2413 # of an interface. It uses the global %Interfaces hash.
2414 # Arguments : $object - the GtkObject subclass.
2415 #############################################################################
2417 sub GetImplementations {
2422 foreach my $key (keys %Interfaces) {
2423 if ($Interfaces{$key} =~ /\b$object\b/) {
2424 push (@impls, $key);
2430 $object is implemented by
2432 for ($i = 0; $i <= $#impls; $i++) {
2433 my $id = &CreateValidSGMLID ($impls[$i]);
2434 $text .= " <link linkend=\"$id\">$impls[$i]</link>";
2435 if ($i < $#impls - 1) {
2438 elsif ($i < $#impls) {
2453 #############################################################################
2454 # Function : GetPrerequisites
2455 # Description : Returns the DocBook output describing the prerequisites
2456 # of an interface. It uses the global %Prerequisites hash.
2457 # Arguments : $iface - the interface.
2458 #############################################################################
2460 sub GetPrerequisites {
2465 if (exists($Prerequisites{$iface})) {
2470 my @prereqs = split(' ', $Prerequisites{$iface});
2471 for ($i = 0; $i <= $#prereqs; $i++) {
2472 my $id = &CreateValidSGMLID ($prereqs[$i]);
2473 $text .= " <link linkend=\"$id\">$prereqs[$i]</link>";
2474 if ($i < $#prereqs - 1) {
2477 elsif ($i < $#prereqs) {
2491 #############################################################################
2492 # Function : GetDerived
2493 # Description : Returns the DocBook output describing the derived interfaces
2494 # of an interface. It uses the global %Prerequisites hash.
2495 # Arguments : $iface - the interface.
2496 #############################################################################
2504 foreach my $key (keys %Prerequisites) {
2505 if ($Prerequisites{$key} =~ /\b$iface\b/) {
2506 push (@derived, $key);
2509 if ($#derived >= 0) {
2512 $iface is required by
2514 for ($i = 0; $i <= $#derived; $i++) {
2515 my $id = &CreateValidSGMLID ($derived[$i]);
2516 $text .= " <link linkend=\"$id\">$derived[$i]</link>";
2517 if ($i < $#derived - 1) {
2520 elsif ($i < $#derived) {
2535 #############################################################################
2536 # Function : GetSignals
2537 # Description : Returns the synopsis and detailed description DocBook output
2538 # for the signal handlers of a given GtkObject subclass.
2539 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
2540 #############################################################################
2548 for ($i = 0; $i <= $#SignalObjects; $i++) {
2549 if ($SignalObjects[$i] eq $object) {
2550 #print "Found signal: $SignalNames[$i]\n";
2551 my $name = $SignalNames[$i];
2552 my $symbol = "${object}::${name}";
2553 my $id = &CreateValidSGMLID ("$object-$name");
2555 my $pad = ' ' x (46 - length($name));
2556 $synop .= " "<link linkend=\"$id\">$name</link>"$pad ";
2558 $desc .= "<refsect2 id=\"$id\"><title>The <literal>"$name"</literal> signal</title>\n";
2559 $desc .= MakeIndexterms($symbol, $id);
2560 $desc .= "<programlisting>";
2562 $SignalReturns[$i] =~ m/\s*(const\s+)?(\w+)\s*(\**)/;
2563 my $type_modifier = defined($1) ? $1 : "";
2566 my $xref = &MakeXRef ($type);
2568 my $ret_type_len = length ($type_modifier) + length ($pointer)
2570 my $ret_type_output = "$type_modifier$xref$pointer"
2571 . (' ' x ($RETURN_TYPE_FIELD_WIDTH - $ret_type_len));
2573 $desc .= "${ret_type_output}user_function " . &MakeReturnField("") . " (";
2575 my $sourceparams = $SourceSymbolParams{$symbol};
2576 my @params = split ("\n", $SignalPrototypes[$i]);
2579 my $type_len = length("gpointer");
2580 my $name_len = length("user_data");
2581 # do two passes, the first one is to calculate padding
2582 for ($l = 0; $l < 2; $l++) {
2583 for ($j = 0; $j <= $#params; $j++) {
2584 # allow alphanumerics, '_', '[' & ']' in param names
2585 if ($params[$j] =~ m/^\s*(\w+)\s*(\**)\s*([\w\[\]]+)\s*$/) {
2588 if (defined($sourceparams)) {
2589 $name = $$sourceparams[2 * $j];
2594 if (!defined($name)) {
2598 if (length($type) + length($pointer) > $type_len) {
2599 $type_len = length($type) + length($pointer);
2601 if (length($name) > $name_len) {
2602 $name_len = length($name);
2606 $xref = &MakeXRef ($type);
2607 $pad = ' ' x ($type_len - length($type) - length($pointer));
2608 $desc .= "$xref$pad $pointer$name,\n";
2609 $desc .= (' ' x ($SYMBOL_FIELD_WIDTH + $RETURN_TYPE_FIELD_WIDTH));
2612 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
2613 "Can't parse arg: $params[$j]\nArgs:$SignalPrototypes[$i]");
2617 $xref = &MakeXRef ("gpointer");
2618 $pad = ' ' x ($type_len - length("gpointer"));
2619 $desc .= "$xref$pad user_data)";
2621 my $flags = $SignalFlags[$i];
2622 my $flags_string = "";
2624 if (defined ($flags)) {
2625 if ($flags =~ m/f/) {
2626 $flags_string = "Run First";
2628 elsif ($flags =~ m/l/) {
2629 $flags_string = "Run Last";
2631 elsif ($flags =~ m/c/) {
2632 $flags_string = "Cleanup";
2634 if ($flags =~ m/r/) {
2635 if ($flags_string) { $flags_string .= " / "; }
2636 $flags_string .= "No Recursion";
2638 if ($flags =~ m/d/) {
2639 if ($flags_string) { $flags_string .= " / "; }
2640 $flags_string .= "Has Details";
2642 if ($flags =~ m/a/) {
2643 if ($flags_string) { $flags_string .= " / "; }
2644 $flags_string .= "Action";
2646 if ($flags =~ m/h/) {
2647 if ($flags_string) { $flags_string .= " / "; }
2648 $flags_string .= "No Hooks";
2654 $synop .= ": $flags_string\n";
2656 $pad = ' ' x (5 + $name_len - length("user_data"));
2657 $desc .= "$pad : $flags_string</programlisting>\n";
2662 $desc .= "</programlisting>\n";
2665 my $parameters = &OutputParamDescriptions ("SIGNAL", $symbol);
2666 my $parameters_output = 0;
2668 $AllSymbols{$symbol} = 1;
2669 if (defined ($SymbolDocs{$symbol})) {
2670 my $symbol_docs = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2672 # Try to insert the parameter table at the author's desired
2673 # position. Otherwise we need to tag it onto the end.
2674 if ($symbol_docs =~ s/<!--PARAMETERS-->/$parameters/) {
2675 $parameters_output = 1;
2677 $desc .= $symbol_docs;
2679 if (!IsEmptyDoc($SymbolDocs{$symbol})) {
2680 $AllDocumentedSymbols{$symbol} = 1;
2684 if ($parameters_output == 0) {
2685 $desc .= $parameters;
2688 if (exists $Since{$symbol}) {
2689 $desc .= "<para>Since $Since{$symbol}</para>";
2691 if (exists $StabilityLevel{$symbol}) {
2692 $desc .= "<para>Stability Level: $StabilityLevel{$symbol}</para>";
2694 $desc .= "</refsect2>";
2697 return ($synop, $desc);
2701 #############################################################################
2702 # Function : GetArgs
2703 # Description : Returns the synopsis and detailed description DocBook output
2704 # for the Args of a given GtkObject subclass.
2705 # Arguments : $object - the GtkObject subclass, e.g. 'GtkButton'.
2706 #############################################################################
2712 my $child_synop = "";
2713 my $child_desc = "";
2714 my $style_synop = "";
2715 my $style_desc = "";
2718 for ($i = 0; $i <= $#ArgObjects; $i++) {
2719 if ($ArgObjects[$i] eq $object) {
2720 #print "Found arg: $ArgNames[$i]\n";
2721 my $name = $ArgNames[$i];
2722 # Remember only one colon so we don't clash with signals.
2723 my $symbol = "${object}:${name}";
2724 # I've used two dashes here for the same reason.
2725 my $id = &CreateValidSGMLID ("$object--$name");
2727 my $type = $ArgTypes[$i];
2729 my $range = $ArgRanges[$i];
2730 my $range_output = CreateValidSGML($range);
2731 my $default = $ArgDefaults[$i];
2732 my $default_output = CreateValidSGML($default);
2734 if ($type eq "GtkString") {
2737 if ($type eq "GtkSignal") {
2738 $type = "GtkSignalFunc, gpointer";
2739 $type_output = &MakeXRef ("GtkSignalFunc") . ", "
2740 . &MakeXRef ("gpointer");
2741 } elsif ($type =~ m/^(\w+)\*$/) {
2742 $type_output = &MakeXRef ($1) . "*";
2744 $type_output = &MakeXRef ($type);
2747 my $flags = $ArgFlags[$i];
2748 my $flags_string = "";
2750 if ($flags =~ m/r/) {
2751 $flags_string = "Read";
2753 if ($flags =~ m/w/) {
2754 if ($flags_string) { $flags_string .= " / "; }
2755 $flags_string .= "Write";
2757 if ($flags =~ m/x/) {
2758 if ($flags_string) { $flags_string .= " / "; }
2759 $flags_string .= "Construct";
2761 if ($flags =~ m/X/) {
2762 if ($flags_string) { $flags_string .= " / "; }
2763 $flags_string .= "Construct Only";
2766 $AllSymbols{$symbol} = 1;
2768 if (defined($SymbolDocs{$symbol}) &&
2769 !IsEmptyDoc($SymbolDocs{$symbol})) {
2770 $blurb = &ExpandAbbreviations($symbol, $SymbolDocs{$symbol});
2771 $AllDocumentedSymbols{$symbol} = 1;
2774 if (!($ArgBlurbs[$i] eq "")) {
2775 $AllDocumentedSymbols{$symbol} = 1;
2777 $blurb = "<para>" . &CreateValidSGML ($ArgBlurbs[$i]) . "</para>";
2780 my $pad1 = " " x (24 - length ($name));
2781 my $pad2 = " " x (20 - length ($type));
2784 if ($flags =~ m/c/) {
2785 $kind = "child property";
2787 elsif ($flags =~ m/s/) {
2788 $kind = "style property";
2794 my $arg_synop = " "<link linkend=\"$id\">$name</link>"$pad1 $type_output $pad2 : $flags_string\n";
2795 my $arg_desc = "<refsect2 id=\"$id\"><title>The <literal>"$name"</literal> $kind</title>\n";
2796 $arg_desc .= MakeIndexterms($symbol, $id);
2797 $arg_desc .= "<programlisting> "$name"$pad1 $type_output $pad2 : $flags_string</programlisting>\n";
2798 $arg_desc .= $blurb;
2800 $arg_desc .= "<para>Allowed values: $range_output</para>\n";
2802 if ($default ne "") {
2803 $arg_desc .= "<para>Default value: $default_output</para>\n";
2805 if (exists $Since{$symbol}) {
2806 $arg_desc .= "<para>Since $Since{$symbol}</para>\n";
2808 if (exists $StabilityLevel{$symbol}) {
2809 $arg_desc .= "<para>Stability Level $StabilityLevel{$symbol}</para>\n";
2811 $arg_desc .= "</refsect2>\n";
2813 if ($flags =~ m/c/) {
2814 $child_synop .= $arg_synop;
2815 $child_desc .= $arg_desc;
2817 elsif ($flags =~ m/s/) {
2818 $style_synop .= $arg_synop;
2819 $style_desc .= $arg_desc;
2822 $synop .= $arg_synop;
2827 return ($synop, $child_synop, $style_synop, $desc, $child_desc, $style_desc);
2831 #############################################################################
2832 # Function : ReadSourceDocumentation
2833 # Description : This reads in the documentation embedded in comment blocks
2834 # in the source code (for Gnome).
2836 # Parameter descriptions override any in the template files.
2837 # Function descriptions are placed before any description from
2838 # the template files.
2840 # It recursively descends the source directory looking for .c
2841 # files and scans them looking for specially-formatted comment
2844 # Arguments : $source_dir - the directory to scan.
2845 #############m###############################################################
2847 sub ReadSourceDocumentation {
2848 my ($source_dir) = @_;
2849 my ($file, $dir, @suffix_list, $suffix);
2850 #print "Scanning source directory: $source_dir\n";
2852 # This array holds any subdirectories found.
2855 @suffix_list = split (/,/, $SOURCE_SUFFIXES);
2857 opendir (SRCDIR, $source_dir)
2858 || die "Can't open source directory $source_dir: $!";
2860 foreach $file (readdir (SRCDIR)) {
2861 if ($file =~ /^\./) {
2863 } elsif (-d "$source_dir/$file") {
2864 push (@subdirs, $file);
2865 } elsif (@suffix_list) {
2866 foreach $suffix (@suffix_list) {
2867 if ($file =~ m/\.\Q${suffix}\E$/) {
2868 &ScanSourceFile ("$source_dir/$file");
2871 } elsif ($file =~ m/\.[ch]$/) {
2872 &ScanSourceFile ("$source_dir/$file");
2877 # Now recursively scan the subdirectories.
2878 foreach $dir (@subdirs) {
2879 next if ($IGNORE_FILES =~ m/(\s|^)\Q${dir}\E(\s|$)/);
2880 &ReadSourceDocumentation ("$source_dir/$dir");
2885 #############################################################################
2886 # Function : ScanSourceFile
2887 # Description : Scans one source file looking for specially-formatted comment
2888 # blocks. Later &MergeSourceDocumentation is used to merge any
2889 # documentation found with the documentation already read in
2890 # from the template files.
2892 # Arguments : $file - the file to scan.
2893 #############################################################################
2895 sub ScanSourceFile {
2899 if ($file =~ m/^.*[\/\\]([^\/\\]*)$/) {
2902 &LogWarning ($file, 1, "Can't find basename for this filename.");
2906 # Check if the basename is in the list of files to ignore.
2907 if ($IGNORE_FILES =~ m/(\s|^)\Q${basename}\E(\s|$)/) {
2911 #print "DEBUG: Scanning $file\n";
2913 open (SRCFILE, $file)
2914 || die "Can't open $file: $!";
2915 my $in_comment_block = 0;
2917 my ($in_description, $in_return, $in_since, $in_stability, $in_deprecated);
2918 my ($description, $return_desc, $return_start, $return_style);
2919 my ($since_desc, $stability_desc, $deprecated_desc);
2921 my $ignore_broken_returns;
2924 # Look for the start of a comment block.
2925 if (!$in_comment_block) {
2926 if (m%^\s*/\*.*\*/%) {
2927 #one-line comment - not gtkdoc
2928 } elsif (m%^\s*/\*\*\s%) {
2929 #print "Found comment block start\n";
2931 $in_comment_block = 1;
2933 # Reset all the symbol data.
2935 $in_description = 0;
2944 $deprecated_desc = "";
2945 $stability_desc = "";
2946 $current_param = -1;
2947 $ignore_broken_returns = 0;
2953 # We're in a comment block. Check if we've found the end of it.
2956 &LogWarning ($file, $., "Symbol name not found at the start of the comment block.");
2958 # Add the return value description onto the end of the params.
2960 push (@params, "Returns");
2961 push (@params, $return_desc);
2962 if ($return_style eq 'broken') {
2963 &LogWarning ($file, $., "Free-form return value description in $symbol. Use `Returns:' to avoid ambiguities.");
2966 # Convert special SGML characters
2967 $description = &ConvertSGMLChars ($symbol, $description);
2969 for ($k = 1; $k <= $#params; $k += 2) {
2970 $params[$k] = &ConvertSGMLChars ($symbol, $params[$k]);
2973 # Handle Section docs
2974 if ($symbol =~ m/SECTION:\s*(.*)/) {
2978 #print "SECTION DOCS found in source for : '$real_symbol'\n";
2979 $ignore_broken_returns = 1;
2980 for ($k = 0; $k <= $#params; $k += 2) {
2981 #print " '".$params[$k]."'\n";
2982 $params[$k] = "\L$params[$k]";
2984 if ($params[$k] eq "short_description") {
2985 $key = "$TMPL_DIR/$real_symbol:Short_Description";
2986 } elsif ($params[$k] eq "see_also") {
2987 $key = "$TMPL_DIR/$real_symbol:See_Also";
2988 } elsif ($params[$k] eq "title") {
2989 $key = "$TMPL_DIR/$real_symbol:Title";
2990 } elsif ($params[$k] eq "stability") {
2991 $key = "$TMPL_DIR/$real_symbol:Stability_Level";
2992 } elsif ($params[$k] eq "section_id") {
2993 $key = "$TMPL_DIR/$real_symbol:Section_Id";
2994 } elsif ($params[$k] eq "include") {
2995 $key = "$TMPL_DIR/$real_symbol:Include";
2997 if (defined($key)) {
2998 $SourceSymbolDocs{$key}=$params[$k+1];
2999 $SourceSymbolSourceFile{$key} = $file;
3000 $SourceSymbolSourceLine{$key} = $.;
3003 $SourceSymbolDocs{"$TMPL_DIR/$real_symbol:Long_Description"}=$description;
3004 $SourceSymbolSourceFile{"$TMPL_DIR/$real_symbol:Long_Description"} = $file;
3005 $SourceSymbolSourceLine{"$TMPL_DIR/$real_symbol:Long_Description"} = $.;
3006 #$SourceSymbolTypes{$symbol} = "SECTION";
3008 #print "SYMBOL DOCS found in source for : '$symbol' ",length($description), "\n";
3009 $SourceSymbolDocs{$symbol} = $description;
3010 $SourceSymbolParams{$symbol} = [ @params ];
3011 # FIXME $SourceSymbolTypes{$symbol} = "STRUCT,SIGNAL,ARG,FUNCTION,MACRO";
3012 #if (defined $DeclarationTypes{$symbol}) {
3013 # $SourceSymbolTypes{$symbol} = $DeclarationTypes{$symbol}
3015 $SourceSymbolSourceFile{$symbol} = $file;
3016 $SourceSymbolSourceLine{$symbol} = $.;
3020 $Since{$symbol} = &ConvertSGMLChars ($symbol, $since_desc);
3023 if ($stability_desc) {
3024 $stability_desc = &ParseStabilityLevel($stability_desc, $file, $., "Stability level for $symbol");
3025 $StabilityLevel{$symbol} = &ConvertSGMLChars ($symbol, $stability_desc);
3028 if ($deprecated_desc) {
3029 if (exists $Deprecated{$symbol}) {
3032 # don't warn for signals and properties
3033 #if ($symbol !~ m/::?(.*)/) {
3034 if (defined $DeclarationTypes{$symbol}) {
3035 &LogWarning ($file, $.,
3036 "$symbol is deprecated in the inline comments, but no deprecation guards were found around the declaration.".
3037 " (See the --deprecated-guards option for gtkdoc-scan.)");
3040 $Deprecated{$symbol} = &ConvertSGMLChars ($symbol, $deprecated_desc);
3044 $in_comment_block = 0;
3048 # Get rid of ' * ' at start of every line in the comment block.
3050 # But make sure we don't get rid of the newline at the end.
3054 #print "DEBUG: scanning :$_";
3056 # If we haven't found the symbol name yet, look for it.
3058 if (m%^\s*(SECTION:\s*\S+)%) {
3060 #print "SECTION DOCS found in source for : '$symbol'\n";
3061 $ignore_broken_returns = 1;
3062 } elsif (m%^\s*([\w:-]*\w)\s*:?%) {
3064 #print "SYMBOL DOCS found in source for : '$symbol'\n";
3069 # If we're in the return value description, add it to the end.
3071 # If we find another valid returns line, we assume that the first
3072 # one was really part of the description.
3073 if (m/^\s*(returns:|return\s+value:)/i) {
3074 if ($return_style eq 'broken') {
3075 $description .= $return_start . $return_desc;
3078 if ($return_style eq 'sane') {
3079 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3081 $return_style = 'sane';
3082 $ignore_broken_returns = 1;
3084 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3085 $description .= $return_start . $return_desc;
3087 $return_style = 'broken';
3089 } elsif (m%^\s*since:%i) {
3093 } elsif (m%^\s*stability:%i) {
3094 $stability_desc = $';
3097 } elsif (m%^\s*deprecated:%i) {
3098 $deprecated_desc = $';
3108 if (m/^\s*(returns:|return\s+value:)/i) {
3109 if ($return_style eq 'broken') {
3110 $description .= $return_start . $return_desc;
3113 if ($return_style eq 'sane') {
3114 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3116 $return_style = 'sane';
3117 $ignore_broken_returns = 1;
3121 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3123 $return_style = 'broken';
3127 } elsif (m%^\s*deprecated:%i) {
3128 $deprecated_desc = $';
3131 } elsif (m%^\s*stability:%i) {
3132 $stability_desc = $';
3141 if ($in_stability) {
3142 if (m/^\s*(returns:|return\s+value:)/i) {
3143 if ($return_style eq 'broken') {
3144 $description .= $return_start . $return_desc;
3147 if ($return_style eq 'sane') {
3148 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3150 $return_style = 'sane';
3151 $ignore_broken_returns = 1;
3155 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3157 $return_style = 'broken';
3161 } elsif (m%^\s*deprecated:%i) {
3162 $deprecated_desc = $';
3165 } elsif (m%^\s*since:%i) {
3170 $stability_desc .= $_;
3175 if ($in_deprecated) {
3176 if (m/^\s*(returns:|return\s+value:)/i) {
3177 if ($return_style eq 'broken') {
3178 $description .= $return_start . $return_desc;
3181 if ($return_style eq 'sane') {
3182 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3184 $return_style = 'sane';
3185 $ignore_broken_returns = 1;
3189 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3191 $return_style = 'broken';
3195 } elsif (m%^\s*since:%i) {
3199 } elsif (m%^\s*stability:%i) {
3200 $stability_desc = $';
3204 $deprecated_desc .= $_;
3209 # If we're in the description part, check for the 'Returns:' line.
3210 # If that isn't found, add the text to the end.
3211 if ($in_description) {
3212 # Get rid of 'Description:'
3213 s%^\s*Description:%%;
3215 if (m/^\s*(returns:|return\s+value:)/i) {
3216 if ($return_style eq 'broken') {
3217 $description .= $return_start . $return_desc;
3220 if ($return_style eq 'sane') {
3221 &LogWarning ($file, $., "Multiple Returns for $symbol.");
3223 $return_style = 'sane';
3224 $ignore_broken_returns = 1;
3228 } elsif (!$ignore_broken_returns && m/^\s*(returns\b\s*)/i) {
3230 $return_style = 'broken';
3234 } elsif (m%^\s*since:%i) {
3238 } elsif (m%^\s*deprecated:%i) {
3239 $deprecated_desc = $';
3242 } elsif (m%^\s*stability:%i) {
3243 $stability_desc = $';
3252 # We must be in the parameters. Check for the empty line below them.
3254 $in_description = 1;
3258 # Look for a parameter name.
3259 if (m%^\s*@(\S+)\s*:%) {
3260 my $param_name = $1;
3261 #print "Found parameter: $param_name\n";
3262 # Allow '...' as the Varargs parameter.
3263 if ($param_name eq "...") {
3264 $param_name = "Varargs";
3266 if ("\L$param_name" eq "returns") {
3267 $return_style = 'sane';
3268 $ignore_broken_returns = 1;
3270 push (@params, $param_name);
3272 $current_param += 2;
3276 # We must be in the middle of a parameter description, so add it on
3277 # to the last element in @params.
3278 if ($current_param == -1) {
3279 &LogWarning ($file, $., "Parsing comment block file : parameter expected.");
3281 $params[$#params] .= $_;
3287 #############################################################################
3288 # Function : OutputMissingDocumentation
3289 # Description : Outputs report of documentation coverage to a file
3292 #############################################################################
3294 sub OutputMissingDocumentation {
3295 my $n_documented = 0;
3296 my $n_incomplete = 0;
3302 my $buffer_deprecated = "";
3303 my $buffer_descriptions = "";
3305 open (UNDOCUMENTED, ">$ROOT_DIR/$MODULE-undocumented.txt")
3306 || die "Can't create $ROOT_DIR/$MODULE-undocumented.txt: $!";
3308 foreach $symbol (sort (keys (%AllSymbols))) {
3309 if ($symbol !~ /:(Title|Long_Description|Short_Description|See_Also|Stability_Level|Include)/) {
3311 if (exists ($AllDocumentedSymbols{$symbol})) {
3313 if (exists ($AllIncompleteSymbols{$symbol})) {
3315 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3317 } elsif (exists $Deprecated{$symbol}) {
3318 if (exists ($AllIncompleteSymbols{$symbol})) {
3320 $buffer_deprecated .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3322 $buffer_deprecated .= $symbol . "\n";
3325 if (exists ($AllIncompleteSymbols{$symbol})) {
3327 $buffer .= $symbol . " (" . $AllIncompleteSymbols{$symbol} . ")\n";
3329 $buffer .= $symbol . "\n";
3332 } elsif ($symbol =~ /:(Long_Description|Short_Description)/) {
3334 #my $len1=(exists($SymbolDocs{$symbol}))?length($SymbolDocs{$symbol}):-1;
3335 #my $len2=(exists($AllDocumentedSymbols{$symbol}))?length($AllDocumentedSymbols{$symbol}):-1;
3336 #print "%%%% $symbol : $len1,$len2\n";
3337 if (((exists ($SymbolDocs{$symbol})) && (length ($SymbolDocs{$symbol}) > 0))
3338 || ((exists ($AllDocumentedSymbols{$symbol})) && (length ($AllDocumentedSymbols{$symbol}) > 0))) {
3341 $symbol =~ m/^.*\/(.*)$/;
3342 $buffer_descriptions .= $1 . "\n";
3347 $buffer .= "\n" . $buffer_deprecated . "\n" . $buffer_descriptions;
3352 $percent = ($n_documented / $total) * 100.0;
3355 printf UNDOCUMENTED "%.0f%% symbol docs coverage.\n", $percent;
3356 print UNDOCUMENTED "$n_documented symbols documented.\n";
3357 print UNDOCUMENTED "$n_incomplete symbols incomplete.\n";
3358 print UNDOCUMENTED ($total - $n_documented) . " not documented.\n\n\n";
3360 print UNDOCUMENTED $buffer;
3362 close (UNDOCUMENTED);
3364 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);
3368 #############################################################################
3369 # Function : OutputUndeclaredSymbols
3370 # Description : Outputs symbols that are undeclared yet documented to a file
3373 #############################################################################
3375 sub OutputUndeclaredSymbols {
3376 open(UNDECLARED, ">$ROOT_DIR/$MODULE-undeclared.txt")
3377 || die "Can't create $ROOT_DIR/$MODULE-undeclared.txt";
3379 if (%UndeclaredSymbols) {
3380 print UNDECLARED (join("\n", sort keys %UndeclaredSymbols));
3381 print UNDECLARED "\n";
3382 print "See $MODULE-undeclared.txt for the list of undeclared symbols.\n"
3388 #############################################################################
3389 # Function : OutputAllSymbols
3390 # Description : Outputs list of all symbols to a file
3393 #############################################################################
3395 sub OutputAllSymbols {
3396 my $n_documented = 0;
3402 open (SYMBOLS, ">$ROOT_DIR/$MODULE-symbols.txt")
3403 || die "Can't create $ROOT_DIR/$MODULE-symbols.txt: $!";
3405 foreach $symbol (sort (keys (%AllSymbols))) {
3406 print SYMBOLS $symbol . "\n"
3413 #############################################################################
3414 # Function : MergeSourceDocumentation
3415 # Description : This merges documentation read from a source file into the
3416 # documentation read in from a template file.
3418 # Parameter descriptions override any in the template files.
3419 # Function descriptions are placed before any description from
3420 # the template files.
3423 #############################################################################
3425 sub MergeSourceDocumentation {
3429 if (scalar %SymbolDocs) {
3430 @Symbols=keys (%SymbolDocs);
3431 #print "num existing entries: ".(scalar @Symbols)."\n";
3432 #print " ",$Symbols[0], " ",$Symbols[1],"\n";
3435 # filter scanned declarations, with what we suppress from -sections.txt
3437 foreach $symbol (keys (%Declarations)) {
3438 if ($KnownSymbols{$symbol}) {
3442 # and add whats found in the source
3443 foreach $symbol (keys (%SourceSymbolDocs)) {
3446 @Symbols = keys (%tmp);
3447 #print "num source entries: ".(scalar @Symbols)."\n";
3449 foreach $symbol (@Symbols) {
3450 $AllSymbols{$symbol} = 1;
3452 my $have_tmpl_docs = 0;
3454 ## See if the symbol is documented in template
3455 my $tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
3456 my $check_tmpl_doc =$tmpl_doc;
3457 # remove all xml-tags and whitespaces
3458 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
3459 $check_tmpl_doc =~ s/<.*?>//g;
3460 $check_tmpl_doc =~ s/\s//g;
3462 if ($check_tmpl_doc ne "") {
3463 $have_tmpl_docs = 1;
3464 #print "## [$check_tmpl_doc]\n";
3467 if (exists ($SourceSymbolDocs{$symbol})) {
3468 my $type = $DeclarationTypes {$symbol};
3470 #print "merging [$symbol] from source\n";
3472 my $item = "Parameter";
3473 if (defined ($type)) {
3474 if ($type eq 'STRUCT') {
3476 } elsif ($type eq 'ENUM') {
3478 } elsif ($type eq 'UNION') {
3485 my $src_doc = $SourceSymbolDocs{$symbol};
3486 # remove leading and training whitespaces
3487 $src_doc =~ s/^\s+//;
3488 $src_doc =~ s/\s+$//;
3490 # Don't output warnings for overridden titles as titles are
3491 # automatically generated in the -sections.txt file, and thus they
3492 # are often overridden.
3493 if ($have_tmpl_docs && $symbol !~ m/:Title$/) {
3494 # check if content is different
3495 if ($tmpl_doc ne $src_doc) {
3496 #print "[$tmpl_doc] [$src_doc]\n";
3497 &LogWarning ($SourceSymbolSourceFile{$symbol}, $SourceSymbolSourceLine{$symbol},
3498 "Documentation in template ".$SymbolSourceFile{$symbol}.":".$SymbolSourceLine{$symbol}." for $symbol being overridden by inline comments.");
3502 if ($src_doc ne "") {
3503 $AllDocumentedSymbols{$symbol} = 1;
3506 # Convert <!--PARAMETERS--> with any blank lines around it to
3507 # a </para> followed by <!--PARAMETERS--> followed by <para>.
3508 $src_doc =~ s%\n+\s*<!--PARAMETERS-->\s*\n+%\n</para>\n<!--PARAMETERS-->\n<para>\n%g;
3510 # If there is a blank line, finish the paragraph and start another.
3511 $src_doc = &ConvertBlankLines ($src_doc, $symbol);
3513 if ($symbol =~ m/$TMPL_DIR\/.+:Long_Description/) {
3514 $SymbolDocs{$symbol} = "<para>\n$src_doc</para>\n$tmpl_doc";
3515 } elsif ($symbol =~ m/$TMPL_DIR\/.+:.+/) {
3516 # For the title/summary/see also section docs we don't want to
3517 # add any <para> tags.
3518 $SymbolDocs{$symbol} = "$src_doc"
3520 $SymbolDocs{$symbol} = "<para>\n$src_doc</para>\n$tmpl_doc";
3524 if ($symbol =~ m/.*::.*/) {
3525 # For signals we prefer the param names from the source docs,
3526 # since the ones from the templates are likely to contain the
3527 # artificial argn names which are generated by gtkdoc-scangobj.
3528 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
3529 # FIXME: we need to check for empty docs here as well!
3531 # The templates contain the definitive parameter names and order,
3532 # so we will not change that. We only override the actual text.
3533 my $tmpl_params = $SymbolParams{$symbol};
3534 if (!defined ($tmpl_params)) {
3535 #print "No merge needed for $symbol\n";
3536 $SymbolParams{$symbol} = $SourceSymbolParams{$symbol};
3538 my $params = $SourceSymbolParams{$symbol};
3540 #print "Merge needed for $symbol, tmpl_params: ",$#$tmpl_params,", source_params: ",$#$params," \n";
3541 for ($j = 0; $j <= $#$tmpl_params; $j += 2) {
3542 my $tmpl_param_name = $$tmpl_params[$j];
3544 # Allow '...' as the Varargs parameter.
3545 if ($tmpl_param_name eq "...") {
3546 $tmpl_param_name = "Varargs";
3549 # Try to find the param in the source comment documentation.
3552 for ($k = 0; $k <= $#$params; $k += 2) {
3553 my $param_name = $$params[$k];
3554 my $param_desc = $$params[$k + 1];
3556 # We accept changes in case, since the Gnome source docs
3557 # contain a lot of these.
3558 if ("\L$param_name" eq "\L$tmpl_param_name") {
3561 # Override the description.
3562 $$tmpl_params[$j + 1] = $param_desc;
3564 # Set the name to "" to mark it as used.
3570 # If it looks like the parameters are there, but not
3571 # in the right place, try to explain a bit better.
3572 if ((!$found) && ($src_doc =~ m/\@$tmpl_param_name:/)) {
3573 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3574 "Parameters for $symbol must start on the line immediately after the function or macro name.");
3578 # Now we output a warning if parameters have been described which
3580 for ($j = 0; $j <= $#$params; $j += 2) {
3581 my $param_name = $$params[$j];
3583 # the template builder cannot detect if a macro returns
3585 if(($type eq "MACRO") && ($param_name eq "Returns")) {
3588 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3589 "$item described in source code comment block but does not exist. $type: $symbol $item: $param_name.");
3595 if ($have_tmpl_docs) {
3596 $AllDocumentedSymbols{$symbol} = 1;
3597 #print "merging [$symbol] from template\n";
3600 #print "[$symbol] undocumented\n";
3604 # if this symbol is documented, check if docs are complete
3605 $check_tmpl_doc = defined ($SymbolDocs{$symbol}) ? $SymbolDocs{$symbol} : "";
3606 # remove all xml-tags and whitespaces
3607 #$check_tmpl_doc =~ s/<\/?[a-z]+>//g;
3608 $check_tmpl_doc =~ s/<.*?>//g;
3609 $check_tmpl_doc =~ s/\s//g;
3610 if ($check_tmpl_doc ne "") {
3611 my $tmpl_params = $SymbolParams{$symbol};
3612 if (defined ($tmpl_params)) {
3613 my $type = $DeclarationTypes {$symbol};
3615 my $item = "Parameter";
3616 if (defined ($type)) {
3617 if ($type eq 'STRUCT') {
3619 } elsif ($type eq 'ENUM') {
3621 } elsif ($type eq 'UNION') {
3628 #print "Check param docs for $symbol, tmpl_params: ",$#$tmpl_params,"\n";
3631 for ($j = 0; $j <= $#$tmpl_params; $j += 2) {
3632 # Output a warning if the parameter is empty and
3633 # remember for stats.
3634 my $tmpl_param_name = $$tmpl_params[$j];
3635 my $tmpl_param_desc = $$tmpl_params[$j + 1];
3636 if ($tmpl_param_desc !~ m/\S/) {
3637 if (exists ($AllIncompleteSymbols{$symbol})) {
3638 $AllIncompleteSymbols{$symbol}.=", ".$tmpl_param_name;
3640 $AllIncompleteSymbols{$symbol}=$tmpl_param_name;
3642 &LogWarning (&GetSymbolSourceFile ($symbol), &GetSymbolSourceLine($symbol),
3643 "$item description for $tmpl_param_name is missing in source code comment block.");
3649 #print "num doc entries: ".(scalar %SymbolDocs)."\n";
3655 if ($doc =~ /^\s*<para>\s*(FIXME)?\s*<\/para>\s*$/) {
3663 # This converts blank lines to "</para><para>", but only outside CDATA and
3664 # <programlisting> tags.
3665 sub ConvertBlankLines {
3666 return &ModifyXMLElements ($_[0], $_[1],
3667 "<!\\[CDATA\\[|<programlisting[^>]*>|\\|\\[",
3668 \&ConvertBlankLinesEndTag,
3669 \&ConvertBlankLinesCallback);
3673 sub ConvertBlankLinesEndTag {
3674 if ($_[0] eq "<!\[CDATA\[") {
3676 } elsif ($_[0] eq "|[") {
3679 return "</programlisting>";
3683 sub ConvertBlankLinesCallback {
3684 my ($text, $symbol, $tag) = @_;
3686 # If we're not in CDATA or a <programlisting> we convert blank lines so
3687 # they start a new <para>.
3689 $text =~ s%\n{2,}%\n</para>\n<para>\n%g;
3696 #############################################################################
3697 # LIBRARY FUNCTIONS - These functions are used in both gtkdoc-mkdb and
3698 # gtkdoc-mktmpl and should eventually be moved to a
3700 #############################################################################
3702 #############################################################################
3703 # Function : ReadDeclarationsFile
3704 # Description : This reads in a file containing the function/macro/enum etc.
3707 # Note that in some cases there are several declarations with
3708 # the same name, e.g. for conditional macros. In this case we
3709 # set a flag in the %DeclarationConditional hash so the
3710 # declaration is not shown in the docs.
3712 # If a macro and a function have the same name, e.g. for
3713 # gtk_object_ref, the function declaration takes precedence.
3715 # Some opaque structs are just declared with 'typedef struct
3716 # _name name;' in which case the declaration may be empty.
3717 # The structure may have been found later in the header, so
3718 # that overrides the empty declaration.
3720 # Arguments : $file - the declarations file to read
3721 # $override - if declarations in this file should override
3722 # any current declaration.
3723 #############################################################################
3725 sub ReadDeclarationsFile {
3726 my ($file, $override) = @_;
3728 if ($override == 0) {
3730 %DeclarationTypes = ();
3731 %DeclarationConditional = ();
3732 %DeclarationOutput = ();
3736 || die "Can't open $file: $!";
3737 my $declaration_type = "";
3738 my $declaration_name;
3740 my $is_deprecated = 0;
3742 if (!$declaration_type) {
3743 if (m/^<([^>]+)>/) {
3744 $declaration_type = $1;
3745 $declaration_name = "";
3746 #print "Found declaration: $declaration_type\n";
3750 if (m%^<NAME>(.*)</NAME>%) {
3751 $declaration_name = $1;
3752 } elsif (m%^<DEPRECATED/>%) {
3754 } elsif (m%^</$declaration_type>%) {
3755 #print "Found end of declaration: $declaration_name\n";
3756 # Check that the declaration has a name
3757 if ($declaration_name eq "") {
3758 print "ERROR: $declaration_type has no name $file:$.\n";
3761 # If the declaration is an empty typedef struct _XXX XXX
3762 # set the flag to indicate the struct has a typedef.
3763 if ($declaration_type eq 'STRUCT'
3764 && $declaration =~ m/^\s*$/) {
3765 #print "Struct has typedef: $declaration_name\n";
3766 $StructHasTypedef{$declaration_name} = 1;
3769 # Check if the symbol is already defined.
3770 if (defined ($Declarations{$declaration_name})
3771 && $override == 0) {
3772 # Function declarations take precedence.
3773 if ($DeclarationTypes{$declaration_name} eq 'FUNCTION') {
3775 } elsif ($declaration_type eq 'FUNCTION') {
3776 if ($is_deprecated) {
3777 $Deprecated{$declaration_name} = "";
3779 $Declarations{$declaration_name} = $declaration;
3780 $DeclarationTypes{$declaration_name} = $declaration_type;
3781 } elsif ($DeclarationTypes{$declaration_name}
3782 eq $declaration_type) {
3783 # If the existing declaration is empty, or is just a
3784 # forward declaration of a struct, override it.
3785 if ($declaration_type eq 'STRUCT') {
3786 if ($Declarations{$declaration_name} =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
3787 if ($is_deprecated) {
3788 $Deprecated{$declaration_name} = "";
3790 $Declarations{$declaration_name} = $declaration;
3791 } elsif ($declaration =~ m/^\s*(struct\s+\w+\s*;)?\s*$/) {
3792 # Ignore an empty or forward declaration.
3794 &LogWarning ($file, $., "Structure $declaration_name has multiple definitions.");
3797 # set flag in %DeclarationConditional hash for
3798 # multiply defined macros/typedefs.
3799 $DeclarationConditional{$declaration_name} = 1;
3802 &LogWarning ($file, $., "$declaration_name has multiple definitions.");
3805 if ($is_deprecated) {
3806 $Deprecated{$declaration_name} = "";
3808 $Declarations{$declaration_name} = $declaration;
3809 $DeclarationTypes{$declaration_name} = $declaration_type;
3812 $declaration_type = "";
3823 #############################################################################
3824 # Function : ReadSignalsFile
3825 # Description : This reads in an existing file which contains information on
3826 # all GTK signals. It creates the arrays @SignalNames and
3827 # @SignalPrototypes containing info on the signals. The first
3828 # line of the SignalPrototype is the return type of the signal
3829 # handler. The remaining lines are the parameters passed to it.
3830 # The last parameter, "gpointer user_data" is always the same
3831 # so is not included.
3832 # Arguments : $file - the file containing the signal handler prototype
3834 #############################################################################
3836 sub ReadSignalsFile {
3844 my $signal_prototype;
3846 # Reset the signal info.
3847 @SignalObjects = ();
3849 @SignalReturns = ();
3851 @SignalPrototypes = ();
3856 if (!open (INPUT, $file)) {
3857 warn "Can't open $file - skipping signals\n";
3864 $signal_object = "";
3866 $signal_returns = "";
3867 $signal_prototype = "";
3870 if (m/^<NAME>(.*)<\/NAME>/) {
3872 if ($signal_name =~ m/^(.*)::(.*)$/) {
3873 $signal_object = $1;
3874 ($signal_name = $2) =~ s/_/-/g;
3875 #print "Found signal: $signal_name\n";
3877 &LogWarning ($file, $., "Invalid signal name: $signal_name.");
3879 } elsif (m/^<RETURNS>(.*)<\/RETURNS>/) {
3880 $signal_returns = $1;
3881 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
3883 } elsif (m%^</SIGNAL>%) {
3884 #print "Found end of signal: ${signal_object}::${signal_name}\nReturns: ${signal_returns}\n${signal_prototype}";
3885 push (@SignalObjects, $signal_object);
3886 push (@SignalNames, $signal_name);
3887 push (@SignalReturns, $signal_returns);
3888 push (@SignalFlags, $signal_flags);
3889 push (@SignalPrototypes, $signal_prototype);
3892 $signal_prototype .= $_;
3900 #############################################################################
3901 # Function : ReadTemplateFile
3902 # Description : This reads in the manually-edited documentation file
3903 # corresponding to the file currently being created, so we can
3904 # insert the documentation at the appropriate places.
3905 # It outputs %SymbolTypes, %SymbolDocs and %SymbolParams, which
3906 # is a hash of arrays.
3907 # NOTE: This function is duplicated in gtkdoc-mktmpl (but
3908 # slightly different).
3909 # Arguments : $docsfile - the template file to read in.
3910 # $skip_unused_params - 1 if the unused parameters should be
3912 #############################################################################
3914 sub ReadTemplateFile {
3915 my ($docsfile, $skip_unused_params) = @_;
3917 my $template = "$docsfile.sgml";
3918 if (! -f $template) {
3919 #print "File doesn't exist: $template\n";
3922 #print "Reading $template\n";
3924 # start with empty hashes, we merge the source comment for each file
3930 my $current_type = ""; # Type of symbol being read.
3931 my $current_symbol = ""; # Name of symbol being read.
3932 my $symbol_doc = ""; # Description of symbol being read.
3933 my @params; # Parameter names and descriptions of current
3934 # function/macro/function typedef.
3935 my $current_param = -1; # Index of parameter currently being read.
3936 # Note that the param array contains pairs
3937 # of param name & description.
3938 my $in_unused_params = 0; # True if we are reading in the unused params.
3939 my $in_deprecated = 0;
3941 my $in_stability = 0;
3943 open (DOCS, "$template")
3944 || die "Can't open $template: $!";
3946 if (m/^<!-- ##### ([A-Z_]+) (\S+) ##### -->/) {
3949 if ($symbol eq "Title"
3950 || $symbol eq "Short_Description"
3951 || $symbol eq "Long_Description"
3952 || $symbol eq "See_Also"
3953 || $symbol eq "Stability_Level"
3954 || $symbol eq "Include") {
3956 $symbol = $docsfile . ":" . $symbol;
3959 #print "Found symbol: $symbol\n";
3960 # Remember file and line for the symbol
3961 $SymbolSourceFile{$symbol} = $template;
3962 $SymbolSourceLine{$symbol} = $.;
3964 # Store previous symbol, but remove any trailing blank lines.
3965 if ($current_symbol ne "") {
3966 $symbol_doc =~ s/\s+$//;
3967 $SymbolTypes{$current_symbol} = $current_type;
3968 $SymbolDocs{$current_symbol} = $symbol_doc;
3970 # Check that the stability level is valid.
3971 if ($StabilityLevel{$current_symbol}) {
3972 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
3975 if ($current_param >= 0) {
3976 $SymbolParams{$current_symbol} = [ @params ];
3978 # Delete any existing params in case we are overriding a
3979 # previously read template.
3980 delete $SymbolParams{$current_symbol};
3983 $current_type = $type;
3984 $current_symbol = $symbol;
3985 $current_param = -1;
3986 $in_unused_params = 0;
3993 } elsif (m/^<!-- # Unused Parameters # -->/) {
3994 #print "DEBUG: Found unused parameters\n";
3995 $in_unused_params = 1;
3998 } elsif ($in_unused_params && $skip_unused_params) {
3999 # When outputting the DocBook we skip unused parameters.
4000 #print "DEBUG: Skipping unused param: $_";
4004 # Check if param found. Need to handle "..." and "format...".
4005 if (s/^\@([\w\.]+):\040?//) {
4006 my $param_name = $1;
4007 # Allow variations of 'Returns'
4008 if ($param_name =~ m/^[Rr]eturns?$/) {
4009 $param_name = "Returns";
4011 #print "Found param for symbol $current_symbol : '$param_name'= '$_'\n";
4013 if ($param_name eq "Deprecated") {
4015 $Deprecated{$current_symbol} = $_;
4016 } elsif ($param_name eq "Since") {
4018 $Since{$current_symbol} = $_;
4019 } elsif ($param_name eq "Stability") {
4021 $StabilityLevel{$current_symbol} = $_;
4023 push (@params, $param_name);
4025 $current_param += 2;
4028 if ($in_deprecated) {
4029 $Deprecated{$current_symbol} .= $_;
4030 } elsif ($in_since) {
4031 $Since{$current_symbol} .= $_;
4032 } elsif ($in_stability) {
4033 $StabilityLevel{$current_symbol} .= $_;
4034 } elsif ($current_param >= 0) {
4035 $params[$current_param] .= $_;
4043 # Remember to finish the current symbol doccs.
4044 if ($current_symbol ne "") {
4046 $symbol_doc =~ s/\s+$//;
4047 $SymbolTypes{$current_symbol} = $current_type;
4048 $SymbolDocs{$current_symbol} = $symbol_doc;
4050 # Check that the stability level is valid.
4051 if ($StabilityLevel{$current_symbol}) {
4052 $StabilityLevel{$current_symbol} = &ParseStabilityLevel($StabilityLevel{$current_symbol}, $template, $., "Stability level for $current_symbol");
4055 if ($current_param >= 0) {
4056 $SymbolParams{$current_symbol} = [ @params ];
4058 # Delete any existing params in case we are overriding a
4059 # previously read template.
4060 delete $SymbolParams{$current_symbol};
4069 #############################################################################
4070 # Function : ReadObjectHierarchy
4071 # Description : This reads in the $MODULE-hierarchy.txt file containing all
4072 # the GtkObject subclasses described in this module (and their
4074 # It places them in the @Objects array, and places their level
4075 # in the widget hierarchy in the @ObjectLevels array, at the
4076 # same index. GtkObject, the root object, has a level of 1.
4078 # FIXME: the version in gtkdoc-mkdb also generates tree_index.sgml
4079 # as it goes along, this should be split out into a separate
4083 #############################################################################
4085 sub ReadObjectHierarchy {
4089 if (! -f $OBJECT_TREE_FILE) {
4092 if (!open (INPUT, $OBJECT_TREE_FILE)) {
4093 warn "Can't open $OBJECT_TREE_FILE - skipping object tree\n";
4097 my $old_tree_index = "$SGML_OUTPUT_DIR/tree_index.sgml";
4098 my $new_tree_index = "$SGML_OUTPUT_DIR/tree_index.new";
4099 my $tree_header = $doctype_header;
4100 $tree_header =~ s/<!DOCTYPE \w+/<!DOCTYPE screen/;
4102 open (OUTPUT, ">$new_tree_index")
4103 || die "Can't create $new_tree_index: $!";
4104 print (OUTPUT "$tree_header<screen>\n");
4106 # Only emit objects if they are supposed to be documented, or if
4107 # they have documented children. To implement this, we maintain a
4108 # stack of pending objects which will be emitted if a documented
4110 my @pending_objects = ();
4111 my @pending_levels = ();
4115 my $level = (length($`)) / 2 + 1;
4118 while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
4119 my $pobject = pop(@pending_objects);
4120 my $plevel = pop(@pending_levels);
4123 push (@pending_objects, $object);
4124 push (@pending_levels, $level);
4126 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
4127 while ($#pending_levels >= 0) {
4128 $object = shift @pending_objects;
4129 $level = shift @pending_levels;
4130 $xref = &MakeXRef ($object);
4132 print (OUTPUT ' ' x ($level * 4), "$xref\n");
4133 push (@Objects, $object);
4134 push (@ObjectLevels, $level);
4139 print (OUTPUT "</screen>\n");
4144 &UpdateFileIfChanged ($old_tree_index, $new_tree_index, 0);
4149 #############################################################################
4150 # Function : ReadInterfaces
4151 # Description : This reads in the $MODULE.interfaces file.
4154 #############################################################################
4156 sub ReadInterfaces {
4159 if (! -f $INTERFACES_FILE) {
4162 if (!open (INPUT, $INTERFACES_FILE)) {
4163 warn "Can't open $INTERFACES_FILE - skipping interfaces\n";
4169 my ($object, @ifaces) = split;
4170 if (exists($KnownSymbols{$object}) && $KnownSymbols{$object} == 1) {
4171 my @knownIfaces = ();
4173 # filter out private interfaces, but leave foreign interfaces
4174 foreach my $iface (@ifaces) {
4175 if (!exists($KnownSymbols{$iface}) || $KnownSymbols{$iface} == 1) {
4176 push (@knownIfaces, $iface);
4180 $Interfaces{$object} = join(' ', @knownIfaces);
4186 #############################################################################
4187 # Function : ReadPrerequisites
4188 # Description : This reads in the $MODULE.prerequisites file.
4191 #############################################################################
4193 sub ReadPrerequisites {
4194 %Prerequisites = ();
4196 if (! -f $PREREQUISITES_FILE) {
4199 if (!open (INPUT, $PREREQUISITES_FILE)) {
4200 warn "Can't open $PREREQUISITES_FILE - skipping prerequisites\n";
4206 my ($iface, @prereqs) = split;
4207 if (exists($KnownSymbols{$iface}) && $KnownSymbols{$iface} == 1) {
4208 my @knownPrereqs = ();
4210 # filter out private prerequisites, but leave foreign prerequisites
4211 foreach my $prereq (@prereqs) {
4212 if (!exists($KnownSymbols{$prereq}) || $KnownSymbols{$prereq} == 1) {
4213 push (@knownPrereqs, $prereq);
4217 $Prerequisites{$iface} = join(' ', @knownPrereqs);
4223 #############################################################################
4224 # Function : ReadArgsFile
4225 # Description : This reads in an existing file which contains information on
4226 # all GTK args. It creates the arrays @ArgObjects, @ArgNames,
4227 # @ArgTypes, @ArgFlags, @ArgNicks and @ArgBlurbs containing info
4229 # Arguments : $file - the file containing the arg information.
4230 #############################################################################
4245 # Reset the args info.
4258 if (!open (INPUT, $file)) {
4259 warn "Can't open $file - skipping args\n";
4276 if (m/^<NAME>(.*)<\/NAME>/) {
4278 if ($arg_name =~ m/^(.*)::(.*)$/) {
4280 ($arg_name = $2) =~ s/_/-/g;
4281 #print "Found arg: $arg_name\n";
4283 &LogWarning ($file, $., "Invalid argument name: $arg_name");
4285 } elsif (m/^<TYPE>(.*)<\/TYPE>/) {
4287 } elsif (m/^<RANGE>(.*)<\/RANGE>/) {
4289 } elsif (m/^<FLAGS>(.*)<\/FLAGS>/) {
4291 } elsif (m/^<NICK>(.*)<\/NICK>/) {
4293 } elsif (m/^<BLURB>(.*)<\/BLURB>/) {
4295 if ($arg_blurb eq "(null)") {
4297 &LogWarning ($file, $., "Property ${arg_object}:${arg_name} has no documentation.");
4299 } elsif (m/^<DEFAULT>(.*)<\/DEFAULT>/) {
4301 } elsif (m%^</ARG>%) {
4302 #print "Found end of arg: ${arg_object}::${arg_name}\n${arg_type} : ${arg_flags}\n";
4303 push (@ArgObjects, $arg_object);
4304 push (@ArgNames, $arg_name);
4305 push (@ArgTypes, $arg_type);
4306 push (@ArgRanges, $arg_range);
4307 push (@ArgFlags, $arg_flags);
4308 push (@ArgNicks, $arg_nick);
4309 push (@ArgBlurbs, $arg_blurb);
4310 push (@ArgDefaults, $arg_default);
4319 #############################################################################
4320 # Function : CheckIsObject
4321 # Description : Returns 1 if the given name is a GtkObject or a subclass.
4322 # It uses the global @Objects array.
4323 # Note that the @Objects array only contains classes in the
4324 # current module and their ancestors - not all GTK classes.
4325 # Arguments : $name - the name to check.
4326 #############################################################################
4332 foreach $object (@Objects) {
4333 if ($object eq $name) {
4341 #############################################################################
4342 # Function : MakeReturnField
4343 # Description : Pads a string to $RETURN_TYPE_FIELD_WIDTH.
4344 # Arguments : $str - the string to pad.
4345 #############################################################################
4347 sub MakeReturnField {
4350 return $str . (' ' x ($RETURN_TYPE_FIELD_WIDTH - length ($str)));
4353 #############################################################################
4354 # Function : GetSymbolSourceFile
4355 # Description : Get the filename where the symbol docs where taken from.
4356 # Arguments : $symbol - the symbol name
4357 #############################################################################
4359 sub GetSymbolSourceFile {
4362 if (defined($SourceSymbolSourceFile{$symbol})) {
4363 return $SourceSymbolSourceFile{$symbol};
4364 } elsif (defined($SymbolSourceFile{$symbol})) {
4365 return $SymbolSourceFile{$symbol};
4371 #############################################################################
4372 # Function : GetSymbolSourceLine
4373 # Description : Get the file line where the symbol docs where taken from.
4374 # Arguments : $symbol - the symbol name
4375 #############################################################################
4377 sub GetSymbolSourceLine {
4380 if (defined($SourceSymbolSourceLine{$symbol})) {
4381 return $SourceSymbolSourceLine{$symbol};
4382 } elsif (defined($SymbolSourceLine{$symbol})) {
4383 return $SymbolSourceLine{$symbol};