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