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