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