f31bd465cbc75ffd5e17b2066a490301531119dd
[platform/upstream/gst-common.git] / gstdoc-scangobj
1 #!/usr/bin/env perl
2 # -*- cperl -*-
3 #
4 # gtk-doc - GTK DocBook documentation generator.
5 # Copyright (C) 1998  Damon Chaplin
6 #
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.
11 #
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.
16 #
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.
20 #
21
22 #
23 # This gets information about object hierarchies and signals
24 # by compiling a small C program. CFLAGS and LDFLAGS must be
25 # set appropriately before running this script.
26 #
27
28 use Getopt::Long;
29
30 my $GTK_DOC_PREFIX=`pkg-config --variable prefix gtk-doc`;
31 if ($GTK_DOC_PREFIX) {
32   chomp $GTK_DOC_PREFIX;
33   #print "Adding $GTK_DOC_PREFIX/share/gtk-doc/data to \@INC\n";
34   unshift @INC, "$GTK_DOC_PREFIX/share/gtk-doc/data";
35 } else {
36   unshift @INC, '/usr/share/gtk-doc/data';
37 }
38 require "gtkdoc-common.pl";
39
40 # Options
41
42 # name of documentation module
43 my $MODULE;
44 my $OUTPUT_DIR;
45 my $INSPECT_DIR;
46 my $VERBOSE;
47 my $PRINT_VERSION;
48 my $PRINT_HELP;
49 my $TYPE_INIT_FUNC="g_type_init ()";
50
51 # --nogtkinit is deprecated, as it is the default now anyway.
52 %optctl = (module => \$MODULE,
53            source => \$SOURCE,
54            types => \$TYPES_FILE,
55            nogtkinit => \$NO_GTK_INIT,
56            'type-init-func' => \$TYPE_INIT_FUNC,
57            'output-dir' => \$OUTPUT_DIR,
58            'inspect-dir' => \$INSPECT_DIR,
59            'verbose' => \$VERBOSE,
60            'version' => \$PRINT_VERSION,
61            'help' => \$PRINT_HELP);
62
63 GetOptions(\%optctl, "module=s", "source=s", "types:s", "output-dir:s", "inspect-dir:s", "nogtkinit", "type-init-func:s", "verbose", "version", "help");
64
65 if ($NO_GTK_INIT) {
66   # Do nothing. This just avoids a warning.
67   # the option is not used anymore
68 }
69
70 if ($PRINT_VERSION) {
71     print "1.5\n";
72     exit 0;
73 }
74
75 if (!$MODULE) {
76     $PRINT_HELP = 1;
77 }
78
79 if ($PRINT_HELP) {
80     print <<EOF;
81 gstdoc-scangobj version 1.5 - introspect gstreamer-plugins
82
83 --module=MODULE_NAME          Name of the doc module being parsed
84 --source=SOURCE_NAME          Name of the source module for plugins
85 --types=FILE                  The name of the file to store the types in
86 --type-init-func=FUNC         The init function to call instead of g_type_init()
87 --output-dir=DIRNAME          The directory where the results are stored
88 --inspect-dir=DIRNAME         The directory where the plugin inspect data is stored
89 --verbose                     Print extra output while processing
90 --version                     Print the version of this program
91 --help                        Print this help
92 EOF
93     exit 0;
94 }
95
96 $OUTPUT_DIR = $OUTPUT_DIR ? $OUTPUT_DIR : ".";
97
98 $TYPES_FILE = $TYPES_FILE ? $TYPES_FILE : "$OUTPUT_DIR/$MODULE.types";
99
100 open (TYPES, $TYPES_FILE) || die "Cannot open $TYPES_FILE: $!\n";
101 open (OUTPUT, ">$MODULE-scan.c") || die "Cannot open $MODULE-scan.c: $!\n";
102
103 my $old_signals_filename = "$OUTPUT_DIR/$MODULE.signals";
104 my $new_signals_filename = "$OUTPUT_DIR/$MODULE.signals.new";
105 my $old_hierarchy_filename = "$OUTPUT_DIR/$MODULE.hierarchy";
106 my $new_hierarchy_filename = "$OUTPUT_DIR/$MODULE.hierarchy.new";
107 my $old_interfaces_filename = "$OUTPUT_DIR/$MODULE.interfaces";
108 my $new_interfaces_filename = "$OUTPUT_DIR/$MODULE.interfaces.new";
109 my $old_prerequisites_filename = "$OUTPUT_DIR/$MODULE.prerequisites";
110 my $new_prerequisites_filename = "$OUTPUT_DIR/$MODULE.prerequisites.new";
111 my $old_args_filename = "$OUTPUT_DIR/$MODULE.args";
112 my $new_args_filename = "$OUTPUT_DIR/$MODULE.args.new";
113
114 my $debug_log="g_message";
115 if (!defined($VERBOSE) or $VERBOSE eq "0") {
116     $debug_log="//$debug_log";
117 }
118
119 # write a C program to scan the types
120
121 $includes = "";
122 @types = ();
123 @impl_types = ();
124
125 for (<TYPES>) {
126     if (/^#include/) {
127         $includes .= $_;
128     } elsif (/^%/) {
129         next;
130     } elsif (/^\s*$/) {
131         next;
132     } elsif (/^type:(.*)$/) {
133         $t = $1;
134         chomp $t;
135         push @impl_types, $t;
136     } else {
137         chomp;
138         push @types, $_;
139     }
140 }
141
142 $ntypes = @types + @impl_types + 1;
143
144 print OUTPUT <<EOT;
145 #include <string.h>
146 #include <stdlib.h>
147 #include <stdio.h>
148 #include <errno.h>
149
150 $includes
151
152 #ifdef GTK_IS_WIDGET_CLASS
153 #include <gtk/gtkversion.h>
154 #endif
155
156 static GType *object_types = NULL;
157
158 static GString *xmlstr = NULL;
159
160 static const gchar*
161 xmlprint (gint indent, const gchar *tag, const gchar *data)
162 {
163   const gchar indent_str[] = "                                               ";
164
165   /* reset */
166   g_string_truncate (xmlstr, 0);
167   g_string_append_len (xmlstr, indent_str, MIN (indent, strlen (indent_str)));
168   g_string_append_printf (xmlstr, "<%s>", tag);
169
170   if (data) {
171     gchar *s;
172
173     s = g_markup_escape_text (data, -1);
174     g_string_append (xmlstr, s);
175     g_free (s);
176   }
177
178   g_string_append_printf (xmlstr, "</%s>\\n", tag);
179   return xmlstr->str;
180 }
181
182 static gint
183 gst_feature_sort_compare (gconstpointer a, gconstpointer b)
184 {
185   return strcmp (((GstPluginFeature *)a)->name, ((GstPluginFeature *)b)->name);
186 }
187
188 static gint
189 static_pad_template_compare (gconstpointer a, gconstpointer b)
190 {
191   GstStaticPadTemplate *spt_a = (GstStaticPadTemplate *) a;
192   GstStaticPadTemplate *spt_b = (GstStaticPadTemplate *) b;
193
194   /* we want SINK before SRC (enum is UNKNOWN, SRC, SINK) */
195   if (spt_a->direction != spt_b->direction)
196     return spt_b->direction - spt_a->direction;
197
198   /* we want ALWAYS first, SOMETIMES second, REQUEST last
199    * (enum is ALWAYS, SOMETIMES, REQUEST) */
200   if (spt_a->presence != spt_b->presence)
201     return spt_a->presence - spt_b->presence;
202
203   return strcmp (spt_a->name_template, spt_b->name_template);
204 }
205
206 static GType *
207 get_object_types (void)
208 {
209     gpointer g_object_class;
210     GList *plugins = NULL;
211     GList *factories = NULL;
212     GList *l;
213     GstElementFactory *factory = NULL;
214     GType type;
215     gint i = 0;
216     gboolean reinspect;
217
218     /* get a list of features from plugins in our source module */
219     plugins = gst_registry_get_plugin_list (gst_registry_get_default());
220
221     xmlstr = g_string_new ("");
222
223     reinspect = !g_file_test ("scanobj-build.stamp", G_FILE_TEST_EXISTS);
224
225     while (plugins) {
226       GList *features;
227       GstPlugin *plugin;
228       const gchar *source;
229       FILE *inspect = NULL;
230       gchar *inspect_name;
231
232       plugin = (GstPlugin *) (plugins->data);
233       plugins = g_list_next (plugins);
234       source = gst_plugin_get_source (plugin);
235       if (!source || strcmp (source, "$SOURCE") != 0) {
236         continue;
237       }
238
239       /* skip static coreelements plugin with pipeline and bin element factory */
240       if (gst_plugin_get_filename (plugin) == NULL)
241         continue;
242
243       $debug_log ("plugin: %s source: %s", plugin->desc.name, source);
244
245       if (reinspect) {
246         inspect_name = g_strdup_printf ("$INSPECT_DIR" G_DIR_SEPARATOR_S "plugin-%s.xml",
247             plugin->desc.name);
248         inspect = fopen (inspect_name, "w");
249         if (inspect == NULL) {
250           g_error ("Could not open %s for writing: %s\\n", inspect_name,
251               g_strerror (errno));
252         }
253         g_free (inspect_name);
254
255         /* output plugin data */
256         fputs ("<plugin>\\n",inspect);
257         fputs (xmlprint(2, "name", plugin->desc.name),inspect);
258         fputs (xmlprint(2, "description", plugin->desc.description),inspect);
259         fputs (xmlprint(2, "filename", plugin->filename),inspect);
260         fputs (xmlprint(2, "basename", plugin->basename),inspect);
261         fputs (xmlprint(2, "version", plugin->desc.version),inspect);
262         fputs (xmlprint(2, "license", plugin->desc.license),inspect);
263         fputs (xmlprint(2, "source", plugin->desc.source),inspect);
264         fputs (xmlprint(2, "package", plugin->desc.package),inspect);
265         fputs (xmlprint(2, "origin", plugin->desc.origin),inspect);
266         fputs ("  <elements>\\n", inspect);
267       }
268
269       features =
270           gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
271           plugin->desc.name);
272
273       /* sort factories by feature->name */
274       features = g_list_sort (features, gst_feature_sort_compare);
275
276       while (features) {
277         GstPluginFeature *feature;
278         feature = GST_PLUGIN_FEATURE (features->data);
279         feature = gst_plugin_feature_load (feature);
280         if (!feature) {
281           g_warning ("Could not load plugin feature %s",
282                      gst_plugin_feature_get_name (feature));
283         }
284
285         if (GST_IS_ELEMENT_FACTORY (feature)) {
286           const gchar *pad_dir[] = { "unknown","source","sink" };
287           const gchar *pad_pres[] = { "always","sometimes","request" };
288           GList *pads, *pad;
289
290           $debug_log ("  feature: %s", feature->name);
291
292           factory = GST_ELEMENT_FACTORY (feature);
293           factories = g_list_prepend (factories, factory);
294
295           if (reinspect) {
296             /* output element data */
297             fputs ("    <element>\\n", inspect);
298             fputs (xmlprint(6, "name", feature->name),inspect);
299             fputs (xmlprint(6, "longname", gst_element_factory_get_longname (factory)),inspect);
300             fputs (xmlprint(6, "class", gst_element_factory_get_klass (factory)),inspect);
301             fputs (xmlprint(6, "description", gst_element_factory_get_description (factory)),inspect);
302             fputs (xmlprint(6, "author", gst_element_factory_get_author (factory)),inspect);
303             fputs ("      <pads>\\n", inspect);
304
305             /* output pad-template data */
306             pads = g_list_copy ((GList *) gst_element_factory_get_static_pad_templates (factory));
307             pads = g_list_sort (pads, static_pad_template_compare);
308             for (pad = pads; pad != NULL; pad = pad->next) {
309               GstStaticPadTemplate *pt = pad->data;
310
311               fputs ("        <caps>\\n", inspect);
312               fputs (xmlprint(10, "name", pt->name_template),inspect);
313               fputs (xmlprint(10, "direction", pad_dir[pt->direction]),inspect);
314               fputs (xmlprint(10, "presence", pad_pres[pt->presence]),inspect);
315               fputs (xmlprint(10, "details", pt->static_caps.string),inspect);
316               fputs ("        </caps>\\n", inspect);
317             }
318             g_list_free (pads);
319             fputs ("      </pads>\\n    </element>\\n", inspect);
320           }
321         }
322         features = g_list_next (features);
323       }
324
325       if (reinspect) {
326         fputs ("  </elements>\\n</plugin>", inspect);
327         fclose (inspect);
328       }
329     }
330
331     g_string_free (xmlstr, TRUE);
332
333     $debug_log ("number of element factories: %d", g_list_length (factories));
334
335     /* allocate the object_types array to hold them */
336     object_types = g_new0 (GType, g_list_length (factories)+$ntypes+1);
337
338     l = factories;
339     i = 0;
340
341     /* fill it */
342     while (l) {
343       factory = GST_ELEMENT_FACTORY (l->data);
344       type = gst_element_factory_get_element_type (factory);
345       if (type != 0) {
346         $debug_log ("adding type for factory %s", gst_element_factory_get_longname (factory));
347         object_types[i++] = type;
348       } else {
349         g_message ("type info for factory %s not found",
350             gst_element_factory_get_longname (factory));
351       }
352       l = g_list_next (l);
353     }
354
355 EOT
356
357 # get_type functions:
358 for (@types) {
359 print OUTPUT <<EOT;
360     type = $_ ();
361     if (type == 0) {
362       g_message ("$_ () didn't return a valid type");
363     }
364     else {
365       object_types[i++] = type;
366     }
367 EOT
368 }
369
370 # Implicit types retrieved from GLib:
371 for (@impl_types) {
372 print OUTPUT <<EOT;
373     type = g_type_from_name ("$_");
374     if (type == 0) {
375       g_message ("Implicit type $_ not found");
376     }
377     else {
378       object_types[i++] = type;
379     }
380 EOT
381 }
382
383 print OUTPUT <<EOT;
384
385     object_types[i] = 0;
386
387     /* reference the GObjectClass to initialize the param spec pool
388      * potentially needed by interfaces. See http://bugs.gnome.org/571820 */
389     g_object_class = g_type_class_ref (G_TYPE_OBJECT);
390
391     /* Need to make sure all the types are loaded in and initialize
392      * their signals and properties.
393      */
394     for (i=0; object_types[i]; i++)
395       {
396         if (G_TYPE_IS_CLASSED (object_types[i]))
397           g_type_class_ref (object_types[i]);
398         if (G_TYPE_IS_INTERFACE (object_types[i]))
399           g_type_default_interface_ref (object_types[i]);
400       }
401
402     g_type_class_unref (g_object_class);
403
404     return object_types;
405 }
406
407 /*
408  * This uses GObject type functions to output signal prototypes and the object
409  * hierarchy.
410  */
411
412 /* The output files */
413 const gchar *signals_filename = "$new_signals_filename";
414 const gchar *hierarchy_filename = "$new_hierarchy_filename";
415 const gchar *interfaces_filename = "$new_interfaces_filename";
416 const gchar *prerequisites_filename = "$new_prerequisites_filename";
417 const gchar *args_filename = "$new_args_filename";
418
419
420 static void output_signals (void);
421 static void output_object_signals (FILE *fp,
422                                    GType object_type);
423 static void output_object_signal (FILE *fp,
424                                   const gchar *object_class_name,
425                                   guint signal_id);
426 static const gchar * get_type_name (GType type,
427                                     gboolean * is_pointer);
428 static void output_object_hierarchy (void);
429 static void output_hierarchy (FILE *fp,
430                               GType type,
431                               guint level);
432
433 static void output_object_interfaces (void);
434 static void output_interfaces (FILE *fp,
435                                GType type);
436
437 static void output_interface_prerequisites (void);
438 static void output_prerequisites (FILE *fp,
439                                   GType type);
440
441 static void output_args (void);
442 static void output_object_args (FILE *fp, GType object_type);
443
444 int
445 main (int argc, char *argv[])
446 {
447   /* Silence the compiler: */
448   if (argv != argv) argc = argc;
449
450   $TYPE_INIT_FUNC;
451
452   get_object_types ();
453
454   output_signals ();
455   output_object_hierarchy ();
456   output_object_interfaces ();
457   output_interface_prerequisites ();
458   output_args ();
459
460   return 0;
461 }
462
463
464 static void
465 output_signals (void)
466 {
467   FILE *fp;
468   gint i;
469
470   fp = fopen (signals_filename, "w");
471   if (fp == NULL)
472     {
473       g_warning ("Couldn't open output file: %s : %s", signals_filename, g_strerror(errno));
474       return;
475     }
476
477   for (i = 0; object_types[i]; i++)
478     output_object_signals (fp, object_types[i]);
479
480   fclose (fp);
481 }
482
483 static gint
484 compare_signals (const void *a, const void *b)
485 {
486   const guint *signal_a = a;
487   const guint *signal_b = b;
488
489   return strcmp (g_signal_name (*signal_a), g_signal_name (*signal_b));
490 }
491
492 /* This outputs all the signals of one object. */
493 static void
494 output_object_signals (FILE *fp, GType object_type)
495 {
496   const gchar *object_class_name;
497   guint *signals, n_signals;
498   guint sig;
499
500   if (G_TYPE_IS_INSTANTIATABLE (object_type) ||
501       G_TYPE_IS_INTERFACE (object_type))
502     {
503
504       object_class_name = g_type_name (object_type);
505
506       signals = g_signal_list_ids (object_type, &n_signals);
507       qsort (signals, n_signals, sizeof (guint), compare_signals);
508
509       for (sig = 0; sig < n_signals; sig++)
510         {
511            output_object_signal (fp, object_class_name, signals[sig]);
512         }
513       g_free (signals);
514    }
515 }
516
517
518 /* This outputs one signal. */
519 static void
520 output_object_signal (FILE *fp,
521                       const gchar *object_name,
522                       guint signal_id)
523 {
524   GSignalQuery query_info;
525   const gchar *type_name, *ret_type, *object_arg, *arg_name;
526   gchar *pos, *object_arg_lower;
527   gboolean is_pointer;
528   gchar buffer[1024];
529   guint i, param;
530   gint param_num, widget_num, event_num, callback_num;
531   gint *arg_num;
532   gchar signal_name[128];
533   gchar flags[16];
534
535   $debug_log ("Object: %s Signal: %u", object_name, signal_id);
536
537   param_num = 1;
538   widget_num = event_num = callback_num = 0;
539
540   g_signal_query (signal_id, &query_info);
541
542   /* Output the signal object type and the argument name. We assume the
543      type is a pointer - I think that is OK. We remove "Gtk" or "Gnome" and
544      convert to lower case for the argument name. */
545   pos = buffer;
546   sprintf (pos, "%s ", object_name);
547   pos += strlen (pos);
548
549   /* Try to come up with a sensible variable name for the first arg
550    * It chops off 2 know prefixes :/ and makes the name lowercase
551    * It should replace lowercase -> uppercase with '_'
552    * GFileMonitor -> file_monitor
553    * GIOExtensionPoint -> extension_point
554    * GtkTreeView -> tree_view
555    * if 2nd char is upper case too
556    *   search for first lower case and go back one char
557    * else
558    *   search for next upper case
559    */
560   if (!strncmp (object_name, "Gtk", 3))
561       object_arg = object_name + 3;
562   else if (!strncmp (object_name, "Gnome", 5))
563       object_arg = object_name + 5;
564   else
565       object_arg = object_name;
566
567   object_arg_lower = g_ascii_strdown (object_arg, -1);
568   sprintf (pos, "*%s\\n", object_arg_lower);
569   pos += strlen (pos);
570   if (!strncmp (object_arg_lower, "widget", 6))
571     widget_num = 2;
572   g_free(object_arg_lower);
573
574   /* Convert signal name to use underscores rather than dashes '-'. */
575   strncpy (signal_name, query_info.signal_name, 127);
576   signal_name[127] = '\\0';
577   for (i = 0; signal_name[i]; i++)
578     {
579       if (signal_name[i] == '-')
580         signal_name[i] = '_';
581     }
582
583   /* Output the signal parameters. */
584   for (param = 0; param < query_info.n_params; param++)
585     {
586       type_name = get_type_name (query_info.param_types[param] & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
587
588       /* Most arguments to the callback are called "arg1", "arg2", etc.
589          GtkWidgets are called "widget", "widget2", ...
590          GtkCallbacks are called "callback", "callback2", ... */
591       if (!strcmp (type_name, "GtkWidget"))
592         {
593           arg_name = "widget";
594           arg_num = &widget_num;
595         }
596       else if (!strcmp (type_name, "GtkCallback")
597                || !strcmp (type_name, "GtkCCallback"))
598         {
599           arg_name = "callback";
600           arg_num = &callback_num;
601         }
602       else
603         {
604           arg_name = "arg";
605           arg_num = &param_num;
606         }
607       sprintf (pos, "%s ", type_name);
608       pos += strlen (pos);
609
610       if (!arg_num || *arg_num == 0)
611         sprintf (pos, "%s%s\\n", is_pointer ? "*" : " ", arg_name);
612       else
613         sprintf (pos, "%s%s%i\\n", is_pointer ? "*" : " ", arg_name,
614                  *arg_num);
615       pos += strlen (pos);
616
617       if (arg_num)
618         {
619           if (*arg_num == 0)
620             *arg_num = 2;
621           else
622             *arg_num += 1;
623         }
624     }
625
626   pos = flags;
627   /* We use one-character flags for simplicity. */
628   if (query_info.signal_flags & G_SIGNAL_RUN_FIRST)
629     *pos++ = 'f';
630   if (query_info.signal_flags & G_SIGNAL_RUN_LAST)
631     *pos++ = 'l';
632   if (query_info.signal_flags & G_SIGNAL_RUN_CLEANUP)
633     *pos++ = 'c';
634   if (query_info.signal_flags & G_SIGNAL_NO_RECURSE)
635     *pos++ = 'r';
636   if (query_info.signal_flags & G_SIGNAL_DETAILED)
637     *pos++ = 'd';
638   if (query_info.signal_flags & G_SIGNAL_ACTION)
639     *pos++ = 'a';
640   if (query_info.signal_flags & G_SIGNAL_NO_HOOKS)
641     *pos++ = 'h';
642   *pos = 0;
643
644   /* Output the return type and function name. */
645   ret_type = get_type_name (query_info.return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
646
647   fprintf (fp,
648            "<SIGNAL>\\n<NAME>%s::%s</NAME>\\n<RETURNS>%s%s</RETURNS>\\n<FLAGS>%s</FLAGS>\\n%s</SIGNAL>\\n\\n",
649            object_name, query_info.signal_name, ret_type, is_pointer ? "*" : "", flags, buffer);
650 }
651
652
653 /* Returns the type name to use for a signal argument or return value, given
654    the GtkType from the signal info. It also sets is_pointer to TRUE if the
655    argument needs a '*' since it is a pointer. */
656 static const gchar *
657 get_type_name (GType type, gboolean * is_pointer)
658 {
659   const gchar *type_name;
660
661   *is_pointer = FALSE;
662   type_name = g_type_name (type);
663
664   switch (type) {
665   case G_TYPE_NONE:
666   case G_TYPE_CHAR:
667   case G_TYPE_UCHAR:
668   case G_TYPE_BOOLEAN:
669   case G_TYPE_INT:
670   case G_TYPE_UINT:
671   case G_TYPE_LONG:
672   case G_TYPE_ULONG:
673   case G_TYPE_FLOAT:
674   case G_TYPE_DOUBLE:
675   case G_TYPE_POINTER:
676     /* These all have normal C type names so they are OK. */
677     return type_name;
678
679   case G_TYPE_STRING:
680     /* A GtkString is really a gchar*. */
681     *is_pointer = TRUE;
682     return "gchar";
683
684   case G_TYPE_ENUM:
685   case G_TYPE_FLAGS:
686     /* We use a gint for both of these. Hopefully a subtype with a decent
687        name will be registered and used instead, as GTK+ does itself. */
688     return "gint";
689
690   case G_TYPE_BOXED:
691     /* The boxed type shouldn't be used itself, only subtypes. Though we
692        return 'gpointer' just in case. */
693     return "gpointer";
694
695   case G_TYPE_PARAM:
696     /* A GParam is really a GParamSpec*. */
697     *is_pointer = TRUE;
698     return "GParamSpec";
699
700 #if GLIB_CHECK_VERSION (2, 25, 9)
701   case G_TYPE_VARIANT:
702     *is_pointer = TRUE;
703     return "GVariant";
704 #endif
705
706 default:
707     break;
708   }
709
710   /* For all GObject subclasses we can use the class name with a "*",
711      e.g. 'GtkWidget *'. */
712   if (g_type_is_a (type, G_TYPE_OBJECT))
713     *is_pointer = TRUE;
714
715   /* Also catch non GObject root types */
716   if (G_TYPE_IS_CLASSED (type))
717     *is_pointer = TRUE;
718
719   /* All boxed subtypes will be pointers as well. */
720   /* Exception: GStrv */
721   if (g_type_is_a (type, G_TYPE_BOXED) &&
722       !g_type_is_a (type, G_TYPE_STRV))
723     *is_pointer = TRUE;
724
725   /* All pointer subtypes will be pointers as well. */
726   if (g_type_is_a (type, G_TYPE_POINTER))
727     *is_pointer = TRUE;
728
729   /* But enums are not */
730   if (g_type_is_a (type, G_TYPE_ENUM) ||
731       g_type_is_a (type, G_TYPE_FLAGS))
732     *is_pointer = FALSE;
733
734   return type_name;
735 }
736
737
738 /* This outputs the hierarchy of all objects which have been initialized,
739    i.e. by calling their XXX_get_type() initialization function. */
740 static void
741 output_object_hierarchy (void)
742 {
743   FILE *fp;
744   gint i,j;
745   GType root, type;
746   GType root_types[$ntypes] = { G_TYPE_INVALID, };
747
748   fp = fopen (hierarchy_filename, "w");
749   if (fp == NULL)
750     {
751       g_warning ("Couldn't open output file: %s : %s", hierarchy_filename, g_strerror(errno));
752       return;
753     }
754   output_hierarchy (fp, G_TYPE_OBJECT, 0);
755   output_hierarchy (fp, G_TYPE_INTERFACE, 0);
756
757   for (i=0; object_types[i]; i++) {
758     root = object_types[i];
759     while ((type = g_type_parent (root))) {
760       root = type;
761     }
762     if ((root != G_TYPE_OBJECT) && (root != G_TYPE_INTERFACE)) {
763       for (j=0; root_types[j]; j++) {
764         if (root == root_types[j]) {
765           root = G_TYPE_INVALID; break;
766         }
767       }
768       if(root) {
769         root_types[j] = root;
770         output_hierarchy (fp, root, 0);
771       }
772     }
773   }
774
775   fclose (fp);
776 }
777
778 /* This is called recursively to output the hierarchy of a object. */
779 static void
780 output_hierarchy (FILE  *fp,
781                   GType  type,
782                   guint   level)
783 {
784   guint i;
785   GType *children;
786   guint n_children;
787
788   if (!type)
789     return;
790
791   for (i = 0; i < level; i++)
792     fprintf (fp, "  ");
793   fprintf (fp, "%s\\n", g_type_name (type));
794
795   children = g_type_children (type, &n_children);
796
797   for (i=0; i < n_children; i++)
798     output_hierarchy (fp, children[i], level + 1);
799
800   g_free (children);
801 }
802
803 static void output_object_interfaces (void)
804 {
805   guint i;
806   FILE *fp;
807
808   fp = fopen (interfaces_filename, "w");
809   if (fp == NULL)
810     {
811       g_warning ("Couldn't open output file: %s : %s", interfaces_filename, g_strerror(errno));
812       return;
813     }
814   output_interfaces (fp, G_TYPE_OBJECT);
815
816   for (i = 0; object_types[i]; i++)
817     {
818       if (!g_type_parent (object_types[i]) &&
819           (object_types[i] != G_TYPE_OBJECT) &&
820           G_TYPE_IS_INSTANTIATABLE (object_types[i]))
821         {
822           output_interfaces (fp, object_types[i]);
823         }
824     }
825   fclose (fp);
826 }
827
828 static void
829 output_interfaces (FILE  *fp,
830                    GType  type)
831 {
832   guint i;
833   GType *children, *interfaces;
834   guint n_children, n_interfaces;
835
836   if (!type)
837     return;
838
839   interfaces = g_type_interfaces (type, &n_interfaces);
840
841   if (n_interfaces > 0)
842     {
843       fprintf (fp, "%s", g_type_name (type));
844       for (i=0; i < n_interfaces; i++)
845           fprintf (fp, " %s", g_type_name (interfaces[i]));
846       fprintf (fp, "\\n");
847      }
848   g_free (interfaces);
849
850   children = g_type_children (type, &n_children);
851
852   for (i=0; i < n_children; i++)
853     output_interfaces (fp, children[i]);
854
855   g_free (children);
856 }
857
858 static void output_interface_prerequisites (void)
859 {
860   FILE *fp;
861
862   fp = fopen (prerequisites_filename, "w");
863   if (fp == NULL)
864     {
865       g_warning ("Couldn't open output file: %s : %s", prerequisites_filename, g_strerror(errno));
866       return;
867     }
868   output_prerequisites (fp, G_TYPE_INTERFACE);
869   fclose (fp);
870 }
871
872 static void
873 output_prerequisites (FILE  *fp,
874                       GType  type)
875 {
876 #if GLIB_CHECK_VERSION(2,1,0)
877   guint i;
878   GType *children, *prerequisites;
879   guint n_children, n_prerequisites;
880
881   if (!type)
882     return;
883
884   prerequisites = g_type_interface_prerequisites (type, &n_prerequisites);
885
886   if (n_prerequisites > 0)
887     {
888       fprintf (fp, "%s", g_type_name (type));
889       for (i=0; i < n_prerequisites; i++)
890           fprintf (fp, " %s", g_type_name (prerequisites[i]));
891       fprintf (fp, "\\n");
892      }
893   g_free (prerequisites);
894
895   children = g_type_children (type, &n_children);
896
897   for (i=0; i < n_children; i++)
898     output_prerequisites (fp, children[i]);
899
900   g_free (children);
901 #endif
902 }
903
904 static void
905 output_args (void)
906 {
907   FILE *fp;
908   gint i;
909
910   fp = fopen (args_filename, "w");
911   if (fp == NULL)
912     {
913       g_warning ("Couldn't open output file: %s : %s", args_filename, g_strerror(errno));
914       return;
915     }
916
917   for (i = 0; object_types[i]; i++) {
918     output_object_args (fp, object_types[i]);
919   }
920
921   fclose (fp);
922 }
923
924 static gint
925 compare_param_specs (const void *a, const void *b)
926 {
927   GParamSpec *spec_a = *(GParamSpec **)a;
928   GParamSpec *spec_b = *(GParamSpec **)b;
929
930   return strcmp (g_param_spec_get_name (spec_a), g_param_spec_get_name (spec_b));
931 }
932
933 /* Its common to have unsigned properties restricted
934  * to the signed range. Therefore we make this look
935  * a bit nicer by spelling out the max constants.
936  */
937
938 /* Don't use "==" with floats, it might trigger a gcc warning.  */
939 #define GTKDOC_COMPARE_FLOAT(x, y) (x <= y && x >= y)
940
941 static gchar*
942 describe_double_constant (gdouble value)
943 {
944   gchar *desc;
945
946   if (GTKDOC_COMPARE_FLOAT (value, G_MAXDOUBLE))
947     desc = g_strdup ("G_MAXDOUBLE");
948   else if (GTKDOC_COMPARE_FLOAT (value, G_MINDOUBLE))
949     desc = g_strdup ("G_MINDOUBLE");
950   else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXDOUBLE))
951     desc = g_strdup ("-G_MAXDOUBLE");
952   else if (GTKDOC_COMPARE_FLOAT (value, G_MAXFLOAT))
953     desc = g_strdup ("G_MAXFLOAT");
954   else if (GTKDOC_COMPARE_FLOAT (value, G_MINFLOAT))
955     desc = g_strdup ("G_MINFLOAT");
956   else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXFLOAT))
957     desc = g_strdup ("-G_MAXFLOAT");
958   else{
959     /* make sure floats are output with a decimal dot irrespective of
960     * current locale. Use formatd since we want human-readable numbers
961     * and do not need the exact same bit representation when deserialising */
962     desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
963     g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g", value);
964   }
965
966   return desc;
967 }
968
969 static gchar*
970 describe_signed_constant (gsize size, gint64 value)
971 {
972   gchar *desc = NULL;
973
974   switch (size) {
975     case 8:
976       if (value == G_MAXINT64)
977         desc = g_strdup ("G_MAXINT64");
978       else if (value == G_MININT64)
979         desc = g_strdup ("G_MININT64");
980       /* fall through */
981     case 4:
982       if (sizeof (int) == 4) {
983         if (value == G_MAXINT)
984           desc = g_strdup ("G_MAXINT");
985         else if (value == G_MININT)
986           desc = g_strdup ("G_MININT");
987         else if (value == (gint64)G_MAXUINT)
988           desc = g_strdup ("G_MAXUINT");
989       }
990       if (value == G_MAXLONG)
991         desc = g_strdup ("G_MAXLONG");
992       else if (value == G_MINLONG)
993         desc = g_strdup ("G_MINLONG");
994       else if (value == (gint64)G_MAXULONG)
995         desc = g_strdup ("G_MAXULONG");
996       /* fall through */
997     case 2:
998       if (sizeof (int) == 2) {
999         if (value == G_MAXINT)
1000           desc = g_strdup ("G_MAXINT");
1001         else if (value == G_MININT)
1002           desc = g_strdup ("G_MININT");
1003         else if (value == (gint64)G_MAXUINT)
1004           desc = g_strdup ("G_MAXUINT");
1005       }
1006       break;
1007     default:
1008       break;
1009   }
1010   if (!desc)
1011     desc = g_strdup_printf ("%" G_GINT64_FORMAT, value);
1012
1013   return desc;
1014 }
1015
1016 static gchar*
1017 describe_unsigned_constant (gsize size, guint64 value)
1018 {
1019   gchar *desc = NULL;
1020
1021   switch (size) {
1022     case 8:
1023       if (value == G_MAXINT64)
1024         desc = g_strdup ("G_MAXINT64");
1025       else if (value == G_MAXUINT64)
1026         desc = g_strdup ("G_MAXUINT64");
1027       /* fall through */
1028     case 4:
1029       if (sizeof (int) == 4) {
1030         if (value == (guint64)G_MAXINT)
1031           desc = g_strdup ("G_MAXINT");
1032         else if (value == G_MAXUINT)
1033           desc = g_strdup ("G_MAXUINT");
1034       }
1035       if (value == (guint64)G_MAXLONG)
1036         desc = g_strdup ("G_MAXLONG");
1037       else if (value == G_MAXULONG)
1038         desc = g_strdup ("G_MAXULONG");
1039       /* fall through */
1040     case 2:
1041       if (sizeof (int) == 2) {
1042         if (value == (guint64)G_MAXINT)
1043           desc = g_strdup ("G_MAXINT");
1044         else if (value == G_MAXUINT)
1045           desc = g_strdup ("G_MAXUINT");
1046       }
1047       break;
1048     default:
1049       break;
1050   }
1051   if (!desc)
1052     desc = g_strdup_printf ("%" G_GUINT64_FORMAT, value);
1053
1054   return desc;
1055 }
1056
1057 static gchar*
1058 describe_type (GParamSpec *spec)
1059 {
1060   gchar *desc;
1061   gchar *lower;
1062   gchar *upper;
1063
1064   if (G_IS_PARAM_SPEC_CHAR (spec))
1065     {
1066       GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
1067
1068       lower = describe_signed_constant (sizeof(gchar), pspec->minimum);
1069       upper = describe_signed_constant (sizeof(gchar), pspec->maximum);
1070       if (pspec->minimum == G_MININT8 && pspec->maximum == G_MAXINT8)
1071         desc = g_strdup ("");
1072       else if (pspec->minimum == G_MININT8)
1073         desc = g_strdup_printf ("<= %s", upper);
1074       else if (pspec->maximum == G_MAXINT8)
1075         desc = g_strdup_printf (">= %s", lower);
1076       else
1077         desc = g_strdup_printf ("[%s,%s]", lower, upper);
1078       g_free (lower);
1079       g_free (upper);
1080     }
1081   else if (G_IS_PARAM_SPEC_UCHAR (spec))
1082     {
1083       GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
1084
1085       lower = describe_unsigned_constant (sizeof(guchar), pspec->minimum);
1086       upper = describe_unsigned_constant (sizeof(guchar), pspec->maximum);
1087       if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT8)
1088         desc = g_strdup ("");
1089       else if (pspec->minimum == 0)
1090         desc = g_strdup_printf ("<= %s", upper);
1091       else if (pspec->maximum == G_MAXUINT8)
1092         desc = g_strdup_printf (">= %s", lower);
1093       else
1094         desc = g_strdup_printf ("[%s,%s]", lower, upper);
1095       g_free (lower);
1096       g_free (upper);
1097     }
1098   else if (G_IS_PARAM_SPEC_INT (spec))
1099     {
1100       GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
1101
1102       lower = describe_signed_constant (sizeof(gint), pspec->minimum);
1103       upper = describe_signed_constant (sizeof(gint), pspec->maximum);
1104       if (pspec->minimum == G_MININT && pspec->maximum == G_MAXINT)
1105         desc = g_strdup ("");
1106       else if (pspec->minimum == G_MININT)
1107         desc = g_strdup_printf ("<= %s", upper);
1108       else if (pspec->maximum == G_MAXINT)
1109         desc = g_strdup_printf (">= %s", lower);
1110       else
1111         desc = g_strdup_printf ("[%s,%s]", lower, upper);
1112       g_free (lower);
1113       g_free (upper);
1114     }
1115   else if (G_IS_PARAM_SPEC_UINT (spec))
1116     {
1117       GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
1118
1119       lower = describe_unsigned_constant (sizeof(guint), pspec->minimum);
1120       upper = describe_unsigned_constant (sizeof(guint), pspec->maximum);
1121       if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT)
1122         desc = g_strdup ("");
1123       else if (pspec->minimum == 0)
1124         desc = g_strdup_printf ("<= %s", upper);
1125       else if (pspec->maximum == G_MAXUINT)
1126         desc = g_strdup_printf (">= %s", lower);
1127       else
1128         desc = g_strdup_printf ("[%s,%s]", lower, upper);
1129       g_free (lower);
1130       g_free (upper);
1131     }
1132   else if (G_IS_PARAM_SPEC_LONG (spec))
1133     {
1134       GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
1135
1136       lower = describe_signed_constant (sizeof(glong), pspec->minimum);
1137       upper = describe_signed_constant (sizeof(glong), pspec->maximum);
1138       if (pspec->minimum == G_MINLONG && pspec->maximum == G_MAXLONG)
1139         desc = g_strdup ("");
1140       else if (pspec->minimum == G_MINLONG)
1141         desc = g_strdup_printf ("<= %s", upper);
1142       else if (pspec->maximum == G_MAXLONG)
1143         desc = g_strdup_printf (">= %s", lower);
1144       else
1145         desc = g_strdup_printf ("[%s,%s]", lower, upper);
1146       g_free (lower);
1147       g_free (upper);
1148     }
1149   else if (G_IS_PARAM_SPEC_ULONG (spec))
1150     {
1151       GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
1152
1153       lower = describe_unsigned_constant (sizeof(gulong), pspec->minimum);
1154       upper = describe_unsigned_constant (sizeof(gulong), pspec->maximum);
1155       if (pspec->minimum == 0 && pspec->maximum == G_MAXULONG)
1156         desc = g_strdup ("");
1157       else if (pspec->minimum == 0)
1158         desc = g_strdup_printf ("<= %s", upper);
1159       else if (pspec->maximum == G_MAXULONG)
1160         desc = g_strdup_printf (">= %s", lower);
1161       else
1162         desc = g_strdup_printf ("[%s,%s]", lower, upper);
1163       g_free (lower);
1164       g_free (upper);
1165     }
1166   else if (G_IS_PARAM_SPEC_INT64 (spec))
1167     {
1168       GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
1169
1170       lower = describe_signed_constant (sizeof(gint64), pspec->minimum);
1171       upper = describe_signed_constant (sizeof(gint64), pspec->maximum);
1172       if (pspec->minimum == G_MININT64 && pspec->maximum == G_MAXINT64)
1173         desc = g_strdup ("");
1174       else if (pspec->minimum == G_MININT64)
1175         desc = g_strdup_printf ("<= %s", upper);
1176       else if (pspec->maximum == G_MAXINT64)
1177         desc = g_strdup_printf (">= %s", lower);
1178       else
1179         desc = g_strdup_printf ("[%s,%s]", lower, upper);
1180       g_free (lower);
1181       g_free (upper);
1182     }
1183   else if (G_IS_PARAM_SPEC_UINT64 (spec))
1184     {
1185       GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
1186
1187       lower = describe_unsigned_constant (sizeof(guint64), pspec->minimum);
1188       upper = describe_unsigned_constant (sizeof(guint64), pspec->maximum);
1189       if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT64)
1190         desc = g_strdup ("");
1191       else if (pspec->minimum == 0)
1192         desc = g_strdup_printf ("<= %s", upper);
1193       else if (pspec->maximum == G_MAXUINT64)
1194         desc = g_strdup_printf (">= %s", lower);
1195       else
1196         desc = g_strdup_printf ("[%s,%s]", lower, upper);
1197       g_free (lower);
1198       g_free (upper);
1199     }
1200   else if (G_IS_PARAM_SPEC_FLOAT (spec))
1201     {
1202       GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
1203
1204       lower = describe_double_constant (pspec->minimum);
1205       upper = describe_double_constant (pspec->maximum);
1206       if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXFLOAT))
1207         {
1208           if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
1209             desc = g_strdup ("");
1210           else
1211             desc = g_strdup_printf ("<= %s", upper);
1212         }
1213       else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
1214         desc = g_strdup_printf (">= %s", lower);
1215       else
1216         desc = g_strdup_printf ("[%s,%s]", lower, upper);
1217       g_free (lower);
1218       g_free (upper);
1219     }
1220   else if (G_IS_PARAM_SPEC_DOUBLE (spec))
1221     {
1222       GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
1223
1224       lower = describe_double_constant (pspec->minimum);
1225       upper = describe_double_constant (pspec->maximum);
1226       if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXDOUBLE))
1227         {
1228           if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
1229             desc = g_strdup ("");
1230           else
1231             desc = g_strdup_printf ("<= %s", upper);
1232         }
1233       else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
1234         desc = g_strdup_printf (">= %s", lower);
1235       else
1236         desc = g_strdup_printf ("[%s,%s]", lower, upper);
1237       g_free (lower);
1238       g_free (upper);
1239     }
1240 #if GLIB_CHECK_VERSION (2, 12, 0)
1241   else if (G_IS_PARAM_SPEC_GTYPE (spec))
1242     {
1243       GParamSpecGType *pspec = G_PARAM_SPEC_GTYPE (spec);
1244       gboolean is_pointer;
1245
1246       desc = g_strdup (get_type_name (pspec->is_a_type, &is_pointer));
1247     }
1248 #endif
1249 #if GLIB_CHECK_VERSION (2, 25, 9)
1250   else if (G_IS_PARAM_SPEC_VARIANT (spec))
1251     {
1252       GParamSpecVariant *pspec = G_PARAM_SPEC_VARIANT (spec);
1253       gchar *variant_type;
1254
1255       variant_type = g_variant_type_dup_string (pspec->type);
1256       desc = g_strdup_printf ("GVariant<%s>", variant_type);
1257       g_free (variant_type);
1258     }
1259 #endif
1260   else
1261     {
1262       desc = g_strdup ("");
1263     }
1264
1265   return desc;
1266 }
1267
1268 static gchar*
1269 describe_default (GParamSpec *spec)
1270 {
1271   gchar *desc;
1272
1273   if (G_IS_PARAM_SPEC_CHAR (spec))
1274     {
1275       GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
1276
1277       desc = g_strdup_printf ("%d", pspec->default_value);
1278     }
1279   else if (G_IS_PARAM_SPEC_UCHAR (spec))
1280     {
1281       GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
1282
1283       desc = g_strdup_printf ("%u", pspec->default_value);
1284     }
1285   else if (G_IS_PARAM_SPEC_BOOLEAN (spec))
1286     {
1287       GParamSpecBoolean *pspec = G_PARAM_SPEC_BOOLEAN (spec);
1288
1289       desc = g_strdup_printf ("%s", pspec->default_value ? "TRUE" : "FALSE");
1290     }
1291   else if (G_IS_PARAM_SPEC_INT (spec))
1292     {
1293       GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
1294
1295       desc = g_strdup_printf ("%d", pspec->default_value);
1296     }
1297   else if (G_IS_PARAM_SPEC_UINT (spec))
1298     {
1299       GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
1300
1301       desc = g_strdup_printf ("%u", pspec->default_value);
1302     }
1303   else if (G_IS_PARAM_SPEC_LONG (spec))
1304     {
1305       GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
1306
1307       desc = g_strdup_printf ("%ld", pspec->default_value);
1308     }
1309   else if (G_IS_PARAM_SPEC_LONG (spec))
1310     {
1311       GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
1312
1313       desc = g_strdup_printf ("%lu", pspec->default_value);
1314     }
1315   else if (G_IS_PARAM_SPEC_INT64 (spec))
1316     {
1317       GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
1318
1319       desc = g_strdup_printf ("%" G_GINT64_FORMAT, pspec->default_value);
1320     }
1321   else if (G_IS_PARAM_SPEC_UINT64 (spec))
1322     {
1323       GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
1324
1325       desc = g_strdup_printf ("%" G_GUINT64_FORMAT, pspec->default_value);
1326     }
1327   else if (G_IS_PARAM_SPEC_UNICHAR (spec))
1328     {
1329       GParamSpecUnichar *pspec = G_PARAM_SPEC_UNICHAR (spec);
1330
1331       if (g_unichar_isprint (pspec->default_value))
1332         desc = g_strdup_printf ("'%c'", pspec->default_value);
1333       else
1334         desc = g_strdup_printf ("%u", pspec->default_value);
1335     }
1336   else if (G_IS_PARAM_SPEC_ENUM (spec))
1337     {
1338       GParamSpecEnum *pspec = G_PARAM_SPEC_ENUM (spec);
1339
1340       GEnumValue *value = g_enum_get_value (pspec->enum_class, pspec->default_value);
1341       if (value)
1342         desc = g_strdup_printf ("%s", value->value_name);
1343       else
1344         desc = g_strdup_printf ("%d", pspec->default_value);
1345     }
1346   else if (G_IS_PARAM_SPEC_FLAGS (spec))
1347     {
1348       GParamSpecFlags *pspec = G_PARAM_SPEC_FLAGS (spec);
1349       guint default_value;
1350       GString *acc;
1351
1352       default_value = pspec->default_value;
1353       acc = g_string_new ("");
1354
1355       while (default_value)
1356         {
1357           GFlagsValue *value = g_flags_get_first_value (pspec->flags_class, default_value);
1358
1359           if (!value)
1360             break;
1361
1362           if (acc->len > 0)
1363             g_string_append (acc, "|");
1364           g_string_append (acc, value->value_name);
1365
1366           default_value &= ~value->value;
1367         }
1368
1369       if (default_value == 0)
1370         desc = g_string_free (acc, FALSE);
1371       else
1372         {
1373           desc = g_strdup_printf ("%d", pspec->default_value);
1374           g_string_free (acc, TRUE);
1375         }
1376     }
1377   else if (G_IS_PARAM_SPEC_FLOAT (spec))
1378     {
1379       GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
1380
1381       /* make sure floats are output with a decimal dot irrespective of
1382        * current locale. Use formatd since we want human-readable numbers
1383        * and do not need the exact same bit representation when deserialising */
1384       desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
1385       g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
1386           pspec->default_value);
1387     }
1388   else if (G_IS_PARAM_SPEC_DOUBLE (spec))
1389     {
1390       GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
1391
1392       /* make sure floats are output with a decimal dot irrespective of
1393        * current locale. Use formatd since we want human-readable numbers
1394        * and do not need the exact same bit representation when deserialising */
1395       desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
1396       g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
1397           pspec->default_value);
1398     }
1399   else if (G_IS_PARAM_SPEC_STRING (spec))
1400     {
1401       GParamSpecString *pspec = G_PARAM_SPEC_STRING (spec);
1402
1403       if (pspec->default_value)
1404         {
1405           gchar *esc = g_strescape (pspec->default_value, NULL);
1406
1407           desc = g_strdup_printf ("\\"%s\\"", esc);
1408
1409           g_free (esc);
1410         }
1411       else
1412         desc = g_strdup_printf ("NULL");
1413     }
1414   else
1415     {
1416       desc = g_strdup ("");
1417     }
1418
1419   return desc;
1420 }
1421
1422
1423 static void
1424 output_object_args (FILE *fp, GType object_type)
1425 {
1426   gpointer class;
1427   const gchar *object_class_name;
1428   guint arg;
1429   gchar flags[16], *pos;
1430   GParamSpec **properties;
1431   guint n_properties;
1432   gboolean child_prop;
1433   gboolean style_prop;
1434   gboolean is_pointer;
1435   const gchar *type_name;
1436   gchar *type_desc;
1437   gchar *default_value;
1438
1439   if (G_TYPE_IS_OBJECT (object_type))
1440     {
1441       class = g_type_class_peek (object_type);
1442       if (!class)
1443         return;
1444
1445       properties = g_object_class_list_properties (class, &n_properties);
1446     }
1447 #if GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 3)
1448   else if (G_TYPE_IS_INTERFACE (object_type))
1449     {
1450       class = g_type_default_interface_ref (object_type);
1451
1452       if (!class)
1453         return;
1454
1455       properties = g_object_interface_list_properties (class, &n_properties);
1456     }
1457 #endif
1458   else
1459     return;
1460
1461   object_class_name = g_type_name (object_type);
1462
1463   child_prop = FALSE;
1464   style_prop = FALSE;
1465
1466   while (TRUE) {
1467     qsort (properties, n_properties, sizeof (GParamSpec *), compare_param_specs);
1468     for (arg = 0; arg < n_properties; arg++)
1469       {
1470         GParamSpec *spec = properties[arg];
1471         const gchar *nick, *blurb, *dot;
1472
1473         if (spec->owner_type != object_type)
1474           continue;
1475
1476         pos = flags;
1477         /* We use one-character flags for simplicity. */
1478         if (child_prop && !style_prop)
1479           *pos++ = 'c';
1480         if (style_prop)
1481           *pos++ = 's';
1482         if (spec->flags & G_PARAM_READABLE)
1483           *pos++ = 'r';
1484         if (spec->flags & G_PARAM_WRITABLE)
1485           *pos++ = 'w';
1486         if (spec->flags & G_PARAM_CONSTRUCT)
1487           *pos++ = 'x';
1488         if (spec->flags & G_PARAM_CONSTRUCT_ONLY)
1489           *pos++ = 'X';
1490         *pos = 0;
1491
1492         nick = g_param_spec_get_nick (spec);
1493         blurb = g_param_spec_get_blurb (spec);
1494
1495         dot = "";
1496         if (blurb) {
1497           int str_len = strlen (blurb);
1498           if (str_len > 0  && blurb[str_len - 1] != '.')
1499             dot = ".";
1500         }
1501
1502         type_desc = describe_type (spec);
1503         default_value = describe_default (spec);
1504         type_name = get_type_name (spec->value_type, &is_pointer);
1505         fprintf (fp, "<ARG>\\n<NAME>%s::%s</NAME>\\n<TYPE>%s%s</TYPE>\\n<RANGE>%s</RANGE>\\n<FLAGS>%s</FLAGS>\\n<NICK>%s</NICK>\\n<BLURB>%s%s</BLURB>\\n<DEFAULT>%s</DEFAULT>\\n</ARG>\\n\\n",
1506                  object_class_name, g_param_spec_get_name (spec), type_name, is_pointer ? "*" : "", type_desc, flags, nick ? nick : "(null)", blurb ? blurb : "(null)", dot, default_value);
1507         g_free (type_desc);
1508         g_free (default_value);
1509       }
1510
1511     g_free (properties);
1512
1513 #ifdef GTK_IS_CONTAINER_CLASS
1514     if (!child_prop && GTK_IS_CONTAINER_CLASS (class)) {
1515       properties = gtk_container_class_list_child_properties (class, &n_properties);
1516       child_prop = TRUE;
1517       continue;
1518     }
1519 #endif
1520
1521 #ifdef GTK_IS_CELL_AREA_CLASS
1522     if (!child_prop && GTK_IS_CELL_AREA_CLASS (class)) {
1523       properties = gtk_cell_area_class_list_cell_properties (class, &n_properties);
1524       child_prop = TRUE;
1525       continue;
1526     }
1527 #endif
1528
1529 #ifdef GTK_IS_WIDGET_CLASS
1530 #if GTK_CHECK_VERSION(2,1,0)
1531     if (!style_prop && GTK_IS_WIDGET_CLASS (class)) {
1532       properties = gtk_widget_class_list_style_properties (GTK_WIDGET_CLASS (class), &n_properties);
1533       style_prop = TRUE;
1534       continue;
1535     }
1536 #endif
1537 #endif
1538
1539     break;
1540   }
1541 }
1542 EOT
1543
1544 close OUTPUT;
1545
1546 # Compile and run our file
1547
1548 $CC = $ENV{CC} ? $ENV{CC} : "gcc";
1549 $LD = $ENV{LD} ? $ENV{LD} : $CC;
1550 $CFLAGS = $ENV{CFLAGS} ? "$ENV{CFLAGS}" : "";
1551 $LDFLAGS = $ENV{LDFLAGS} ? $ENV{LDFLAGS} : "";
1552
1553 my $o_file;
1554 if ($CC =~ /libtool/) {
1555   $o_file  = "$MODULE-scan.lo"
1556 } else {
1557   $o_file = "$MODULE-scan.o"
1558 }
1559
1560 my $stdout="";
1561 if (!defined($VERBOSE) or $VERBOSE eq "0") {
1562     $stdout=">/dev/null";
1563 }
1564
1565 # Compiling scanner
1566 $command = "$CC $stdout $CFLAGS -c -o $o_file $MODULE-scan.c";
1567 system("($command)") == 0 or die "Compilation of scanner failed: $!\n";
1568
1569 # Linking scanner
1570 $command = "$LD $stdout -o $MODULE-scan $o_file $LDFLAGS";
1571 system($command) == 0 or die "Linking of scanner failed: $!\n";
1572
1573 # Running scanner $MODULE-scan ";
1574 system("sh -c ./$MODULE-scan") == 0 or die "Scan failed: $!\n";
1575
1576 if (!defined($ENV{"GTK_DOC_KEEP_INTERMEDIATE"})) {
1577   unlink "./$MODULE-scan.c", "./$MODULE-scan.o", "./$MODULE-scan.lo", "./$MODULE-scan";
1578 }
1579
1580 &UpdateFileIfChanged ($old_hierarchy_filename, $new_hierarchy_filename, 0);
1581 &UpdateFileIfChanged ($old_interfaces_filename, $new_interfaces_filename, 0);
1582 &UpdateFileIfChanged ($old_prerequisites_filename, $new_prerequisites_filename, 0);
1583 # we will merge these in scangobj-merge.py
1584 #&UpdateFileIfChanged ($old_signals_filename, $new_signals_filename, 0);
1585 #&UpdateFileIfChanged ($old_args_filename, $new_args_filename, 0);
1586