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