*.mak: more spaces/tabs clean-ups
[platform/upstream/gst-common.git] / gstdoc-scangobj
index d6e1560..b344e56 100755 (executable)
@@ -38,27 +38,30 @@ require "gtkdoc-common.pl";
 # name of documentation module
 my $MODULE;
 my $OUTPUT_DIR;
+my $INSPECT_DIR;
 my $PRINT_VERSION;
 my $PRINT_HELP;
 my $TYPE_INIT_FUNC="g_type_init ()";
 
 # --nogtkinit is deprecated, as it is the default now anyway.
 %optctl = (module => \$MODULE,
+           source => \$SOURCE,
           types => \$TYPES_FILE,
           nogtkinit => \$NO_GTK_INIT,
           'type-init-func' => \$TYPE_INIT_FUNC,
           'output-dir' => \$OUTPUT_DIR,
+          'inspect-dir' => \$INSPECT_DIR,
           'version' => \$PRINT_VERSION,
           'help' => \$PRINT_HELP);
-          
-GetOptions(\%optctl, "module=s", "types:s", "output-dir:s", "nogtkinit", "type-init-func:s", "version", "help");
+
+GetOptions(\%optctl, "module=s", "source=s", "types:s", "output-dir:s", "inspect-dir:s", "nogtkinit", "type-init-func:s", "version", "help");
 
 if ($NO_GTK_INIT) {
   # Do nothing. This just avoids a warning.
 }
 
 if ($PRINT_VERSION) {
-    print "1.3\n";
+    print "1.5\n";
     exit 0;
 }
 
@@ -67,11 +70,13 @@ if (!$MODULE) {
 }
 
 if ($PRINT_HELP) {
-    print "gtkdoc-scangobj version 1.3\n";
+    print "gstdoc-scangobj version 1.5\n";
     print "\n--module=MODULE_NAME  Name of the doc module being parsed";
+    print "\n--source=SOURCE_NAME  Name of the source module for plugins";
     print "\n--types=FILE          The name of the file to store the types in";
     print "\n--type-init-func=FUNC The init function to call instead of g_type_init ()";
     print "\n--output-dir=DIRNAME  The directory where the results are stored";
+    print "\n--inspect-dir=DIRNAME  The directory where the plugin inspect data is stored";
     print "\n--version             Print the version of this program";
     print "\n--help                Print this help\n";
     exit 0;
@@ -79,11 +84,10 @@ if ($PRINT_HELP) {
 
 $OUTPUT_DIR = $OUTPUT_DIR ? $OUTPUT_DIR : ".";
 
-# THOMAS: dynamic types; only use types file for headers
- $TYPES_FILE = $TYPES_FILE ? $TYPES_FILE : "$OUTPUT_DIR/$MODULE.types";
+$TYPES_FILE = $TYPES_FILE ? $TYPES_FILE : "$OUTPUT_DIR/$MODULE.types";
 
-open TYPES, $TYPES_FILE || die "Cannot open $TYPES_FILE: $!\n";
-open OUTPUT, ">$MODULE-scan.c" || die "Cannot open $MODULE-scan.c: $!\n";
+open (TYPES, $TYPES_FILE) || die "Cannot open $TYPES_FILE: $!\n";
+open (OUTPUT, ">$MODULE-scan.c") || die "Cannot open $MODULE-scan.c: $!\n";
 
 my $old_signals_filename = "$OUTPUT_DIR/$MODULE.signals";
 my $new_signals_filename = "$OUTPUT_DIR/$MODULE.signals.new";
@@ -99,34 +103,89 @@ my $new_args_filename = "$OUTPUT_DIR/$MODULE.args.new";
 # write a C program to scan the types
 
 $includes = "";
-#@types = ();
+@types = ();
+@impl_types = ();
 
 for (<TYPES>) {
     if (/^#include/) {
        $includes .= $_;
-#    } elsif (/^%/) {
-#      next;
-#    } elsif (/^\s*$/) {
-#      next;
-#    } else {
-#      chomp;
-#      push @types, $_;
+    } elsif (/^%/) {
+       next;
+    } elsif (/^\s*$/) {
+       next;
+    } elsif (/^type:(.*)$/) {
+       $t = $1;
+        chomp $t;
+       push @impl_types, $t;
+    } else {
+       chomp;
+       push @types, $_;
     }
 }
 
-#$ntypes = @types + 1;
+$ntypes = @types + @impl_types;
 
 print OUTPUT <<EOT;
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <errno.h>
 
 $includes
+
 #ifdef GTK_IS_WIDGET_CLASS
 #include <gtk/gtkversion.h>
 #endif
-gint num_object_types = 0;
-GType *object_types = NULL;
+
+static GType *object_types = NULL;
+
+static GString *xmlstr = NULL;
+
+static const gchar*
+xmlprint (gint indent, const gchar *tag, const gchar *data)
+{
+  const gchar indent_str[] = "                                               ";
+
+  /* reset */
+  g_string_truncate (xmlstr, 0);
+  g_string_append_len (xmlstr, indent_str, MIN (indent, strlen (indent_str)));
+  g_string_append_printf (xmlstr, "<%s>", tag);
+
+  if (data) {
+    gchar *s;
+
+    s = g_markup_escape_text (data, -1);
+    g_string_append (xmlstr, s);
+    g_free (s);
+  }
+  
+  g_string_append_printf (xmlstr, "</%s>\\n", tag);
+  return xmlstr->str;
+}
+
+static gint
+gst_feature_sort_compare (gconstpointer a, gconstpointer b)
+{
+  return strcmp (((GstPluginFeature *)a)->name, ((GstPluginFeature *)b)->name); 
+}
+
+static gint
+static_pad_template_compare (gconstpointer a, gconstpointer b)
+{
+  GstStaticPadTemplate *spt_a = (GstStaticPadTemplate *) a;
+  GstStaticPadTemplate *spt_b = (GstStaticPadTemplate *) b;
+
+  /* we want SINK before SRC (enum is UNKNOWN, SRC, SINK) */
+  if (spt_a->direction != spt_b->direction)
+    return spt_b->direction - spt_a->direction;
+
+  /* we want ALWAYS first, SOMETIMES second, REQUEST last
+   * (enum is ALWAYS, SOMETIMES, REQUEST) */
+  if (spt_a->presence != spt_b->presence)
+    return spt_a->presence - spt_b->presence;
+
+  return strcmp (spt_a->name_template, spt_b->name_template);
+}
 
 static GType *
 get_object_types (void)
@@ -135,105 +194,225 @@ get_object_types (void)
     GList *factories = NULL;
     GList *l;
     GstElementFactory *factory = NULL;
-
+    GType type;
     gint i = 0;
-
-    /* get the number of types from the registry */
-    plugins = gst_registry_pool_plugin_list ();
-
+    gboolean reinspect;
+    
+    /* get a list of features from plugins in our source module */
+    plugins = gst_registry_get_plugin_list (gst_registry_get_default());
+
+    xmlstr = g_string_new ("");
+    
+    reinspect = !g_file_test ("scanobj-build.stamp", G_FILE_TEST_EXISTS);
+    
     while (plugins) {
       GList *features;
       GstPlugin *plugin;
+      const gchar *source;
+      FILE *inspect = NULL;
+      gchar *inspect_name;
 
       plugin = (GstPlugin *) (plugins->data);
       plugins = g_list_next (plugins);
+      source = gst_plugin_get_source (plugin);
+      /*g_print ("plugin: %s source: %s\\n", plugin->desc.name, source);*/
+      if (!source || strcmp (source, "$SOURCE") != 0) {
+        continue;
+      }
+
+      /* skip static coreelements plugin with pipeline and bin element factory */
+      if (gst_plugin_get_filename (plugin) == NULL)
+        continue;
+
+      g_print ("plugin: %s source: %s\\n", plugin->desc.name, source);
+
+      if (reinspect) {
+        inspect_name = g_strdup_printf ("$INSPECT_DIR" G_DIR_SEPARATOR_S "plugin-%s.xml",
+            plugin->desc.name);
+        inspect = fopen (inspect_name, "w");
+        if (inspect == NULL) {
+          g_error ("Could not open %s for writing: %s\\n", inspect_name,
+              g_strerror (errno));
+        }
+        g_free (inspect_name);
+        
+        /* output plugin data */
+        fputs ("<plugin>\\n",inspect);
+        fputs (xmlprint(2, "name", plugin->desc.name),inspect);
+        fputs (xmlprint(2, "description", plugin->desc.description),inspect);
+        fputs (xmlprint(2, "filename", plugin->filename),inspect);
+        fputs (xmlprint(2, "basename", plugin->basename),inspect);
+        fputs (xmlprint(2, "version", plugin->desc.version),inspect);
+        fputs (xmlprint(2, "license", plugin->desc.license),inspect);
+        fputs (xmlprint(2, "source", plugin->desc.source),inspect);
+        fputs (xmlprint(2, "package", plugin->desc.package),inspect);
+        fputs (xmlprint(2, "origin", plugin->desc.origin),inspect);
+        fputs ("  <elements>\\n", inspect);
+      }
 
-      features = gst_plugin_get_feature_list (plugin);
+      features =
+          gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
+          plugin->desc.name);
+
+      /* sort factories by feature->name */
+      features = g_list_sort (features, gst_feature_sort_compare);
+          
       while (features) {
         GstPluginFeature *feature;
         feature = GST_PLUGIN_FEATURE (features->data);
-        if (!gst_plugin_feature_ensure_loaded (feature)) {
+        feature = gst_plugin_feature_load (feature);
+        if (!feature) {
           g_warning ("Could not load plugin feature %s",
                      gst_plugin_feature_get_name (feature));
         }
 
         if (GST_IS_ELEMENT_FACTORY (feature)) {
+          const gchar *pad_dir[] = { "unknown","source","sink" };
+          const gchar *pad_pres[] = { "always","sometimes","request" };
+          GList *pads, *pad;
+
+          /*g_print ("  feature: %s\\n", feature->name);*/
+          
           factory = GST_ELEMENT_FACTORY (feature);
-          factories = g_list_append (factories, factory);
+          factories = g_list_prepend (factories, factory);
+          
+          if (reinspect) {
+            /* output element data */
+            fputs ("    <element>\\n", inspect);
+            fputs (xmlprint(6, "name", feature->name),inspect);
+            fputs (xmlprint(6, "longname", factory->details.longname),inspect);
+            fputs (xmlprint(6, "class", factory->details.klass),inspect);
+            fputs (xmlprint(6, "description", factory->details.description),inspect);
+            fputs (xmlprint(6, "author", factory->details.author),inspect);
+            fputs ("      <pads>\\n", inspect);
+            
+            /* output pad-template data */
+            pads = g_list_copy ((GList *) gst_element_factory_get_static_pad_templates (factory));
+            pads = g_list_sort (pads, static_pad_template_compare);
+            for (pad = pads; pad != NULL; pad = pad->next) {
+              GstStaticPadTemplate *pt = pad->data;
+            
+              fputs ("        <caps>\\n", inspect);
+              fputs (xmlprint(10, "name", pt->name_template),inspect);
+              fputs (xmlprint(10, "direction", pad_dir[pt->direction]),inspect);
+              fputs (xmlprint(10, "presence", pad_pres[pt->presence]),inspect);
+              fputs (xmlprint(10, "details", pt->static_caps.string),inspect);
+              fputs ("        </caps>\\n", inspect);
+            }
+            g_list_free (pads);
+            fputs ("      </pads>\\n    </element>\\n", inspect);
+          }
         }
         features = g_list_next (features);
       }
+      
+      if (reinspect) {
+        fputs ("  </elements>\\n</plugin>", inspect);
+        fclose (inspect);
+      }
     }
+    
+    g_string_free (xmlstr, TRUE);
 
-    num_object_types = g_list_length (factories);
     g_message ("number of element factories: %d", g_list_length (factories));
 
     /* allocate the object_types array to hold them */
-    object_types = g_new0 (GType, g_list_length (factories));
+    object_types = g_new0 (GType, g_list_length (factories)+$ntypes+1);
 
     l = factories;
     i = 0;
 
     /* fill it */
     while (l) {
-      GType type;
       factory = GST_ELEMENT_FACTORY (l->data);
-      g_message ("adding type for factory %s", gst_element_factory_get_longname (factory));
       type = gst_element_factory_get_element_type (factory);
-      g_message ("adding type %p", (void *) type);
-      object_types[i] = type;
-      i++;
+      if (type != 0) {
+        g_message ("adding type %p for factory %s", (void *) type, gst_element_factory_get_longname (factory));
+        object_types[i++] = type;
+      } else {
+        g_message ("type info for factory %s not found",
+            gst_element_factory_get_longname (factory));
+      }
       l = g_list_next (l);
     }
+
+EOT
+
+# get_type functions:
+for (@types) {
+print OUTPUT <<EOT;
+    type = $_ ();
+    if (type == 0) {
+      g_message ("$_ () didn't return a valid type");
+    }
+    else {
+      object_types[i++] = type;
+    }
+EOT
+}
+
+# Implicit types retrieved from GLib:
+for (@impl_types) {
+print OUTPUT <<EOT;
+    type = g_type_from_name ("$_");
+    if (type == 0) {
+      g_message ("Implicit type $_ not found");
+    }
+    else {
+      object_types[i++] = type;
+    }
 EOT
+}
 
 print OUTPUT <<EOT;
 
+    object_types[i] = 0;
+
     /* Need to make sure all the types are loaded in and initialize
      * their signals and properties.
      */
-    g_message ("class reffing");
-
-    for (i=0; i < num_object_types; i++) {
+    for (i=0; object_types[i]; i++) {
       if (G_TYPE_IS_CLASSED (object_types[i]))
         g_type_class_ref (object_types[i]);
+        else {
+          g_warning ("not reffing type: %s", g_type_name (object_types[i]));
+        }
     }
 
     return object_types;
 }
 
 /*
- * This uses GTK type functions to output signal prototypes and the widget
+ * This uses GObject type functions to output signal prototypes and the object
  * hierarchy.
  */
 
 /* The output files */
-gchar *signals_filename = "$new_signals_filename";
-gchar *hierarchy_filename = "$new_hierarchy_filename";
-gchar *interfaces_filename = "$new_interfaces_filename";
-gchar *prerequisites_filename = "$new_prerequisites_filename";
-gchar *args_filename = "$new_args_filename";
+const gchar *signals_filename = "$new_signals_filename";
+const gchar *hierarchy_filename = "$new_hierarchy_filename";
+const gchar *interfaces_filename = "$new_interfaces_filename";
+const gchar *prerequisites_filename = "$new_prerequisites_filename";
+const gchar *args_filename = "$new_args_filename";
 
 
 static void output_signals (void);
-static void output_widget_signals (FILE *fp,
+static void output_object_signals (FILE *fp,
                                   GType object_type);
-static void output_widget_signal (FILE *fp,
-                                 GType object_type,
+static void output_object_signal (FILE *fp,
                                  const gchar *object_class_name,
                                  guint signal_id);
 static const gchar * get_type_name (GType type,
                                    gboolean * is_pointer);
-static gchar * get_gdk_event (const gchar * signal_name);
-static gchar ** lookup_signal_arg_names (const gchar * type,
-                                        const gchar * signal_name);
+static const gchar * get_gdk_event (const gchar * signal_name);
+static const gchar ** lookup_signal_arg_names (const gchar * type,
+                                              const gchar * signal_name);
 
-static void output_widget_hierarchy (void);
+static void output_object_hierarchy (void);
 static void output_hierarchy (FILE *fp,
                              GType type,
                              guint level);
 
-static void output_widget_interfaces (void);
+static void output_object_interfaces (void);
 static void output_interfaces (FILE *fp,
                               GType type);
 
@@ -242,22 +421,22 @@ static void output_prerequisites (FILE *fp,
                                  GType type);
 
 static void output_args (void);
-static void output_widget_args (FILE *fp, GType object_type);
+static void output_object_args (FILE *fp, GType object_type);
 
 int
 main (int argc, char *argv[])
 {
+  /* Silence the compiler: */
+  if (argv != argv) argc = argc;
+
   $TYPE_INIT_FUNC;
 
   get_object_types ();
 
-  g_message ("output signals");
   output_signals ();
-  g_message ("output widget hierarchy");
-  output_widget_hierarchy ();
-  output_widget_interfaces ();
+  output_object_hierarchy ();
+  output_object_interfaces ();
   output_interface_prerequisites ();
-  g_message ("output args");
   output_args ();
 
   return 0;
@@ -273,12 +452,12 @@ output_signals (void)
   fp = fopen (signals_filename, "w");
   if (fp == NULL)
     {
-      g_warning ("Couldn't open output file: %s", signals_filename);
+      g_warning ("Couldn't open output file: %s : %s", signals_filename, strerror(errno));
       return;
     }
 
-  for (i = 0; i < num_object_types; i++)
-    output_widget_signals (fp, object_types[i]);
+  for (i = 0; object_types[i]; i++)
+    output_object_signals (fp, object_types[i]);
 
   fclose (fp);
 }
@@ -292,9 +471,9 @@ compare_signals (const void *a, const void *b)
   return strcmp (g_signal_name (*signal_a), g_signal_name (*signal_b));
 }
 
-/* This outputs all the signals of one widget. */
+/* This outputs all the signals of one object. */
 static void
-output_widget_signals (FILE *fp, GType object_type)
+output_object_signals (FILE *fp, GType object_type)
 {
   const gchar *object_class_name;
   guint *signals, n_signals;
@@ -311,8 +490,7 @@ output_widget_signals (FILE *fp, GType object_type)
 
       for (sig = 0; sig < n_signals; sig++)
         {
-           output_widget_signal (fp, object_type, object_class_name,
-                                signals[sig]);
+           output_object_signal (fp, object_class_name, signals[sig]);
         }
       g_free (signals);
    }
@@ -321,25 +499,23 @@ output_widget_signals (FILE *fp, GType object_type)
 
 /* This outputs one signal. */
 static void
-output_widget_signal (FILE *fp,
-                     GType object_type,
+output_object_signal (FILE *fp,
                      const gchar *object_name,
                      guint signal_id)
 {
   GSignalQuery query_info;
-  const gchar *type_name, *ret_type, *object_arg;
-  gchar *pos, *arg_name, *object_arg_lower;
+  const gchar *type_name, *ret_type, *object_arg, *arg_name;
+  gchar *pos, *object_arg_lower;
   gboolean is_pointer;
   gchar ret_type_buffer[1024], buffer[1024];
   guint i, param;
-  gchar **arg_names;
+  const gchar **arg_names;
   gint param_num, widget_num, event_num, callback_num;
   gint *arg_num;
   gchar signal_name[128];
+  gchar flags[16];
 
-
-  /*  g_print ("Object: %s Type: %i Signal: %u\\n", object_name, object_type,
-      signal_id);*/
+  /*  g_print ("Object: %s Signal: %u\\n", object_name, signal_id);*/
 
   param_num = 1;
   widget_num = event_num = callback_num = 0;
@@ -440,9 +616,27 @@ output_widget_signal (FILE *fp,
        }
     }
 
+  pos = flags;
+  /* We use one-character flags for simplicity. */
+  if (query_info.signal_flags & G_SIGNAL_RUN_FIRST)
+    *pos++ = 'f';
+  if (query_info.signal_flags & G_SIGNAL_RUN_LAST)
+    *pos++ = 'l';
+  if (query_info.signal_flags & G_SIGNAL_RUN_CLEANUP)
+    *pos++ = 'c';
+  if (query_info.signal_flags & G_SIGNAL_NO_RECURSE)
+    *pos++ = 'r';
+  if (query_info.signal_flags & G_SIGNAL_DETAILED)
+    *pos++ = 'd';
+  if (query_info.signal_flags & G_SIGNAL_ACTION)
+    *pos++ = 'a';
+  if (query_info.signal_flags & G_SIGNAL_NO_HOOKS)
+    *pos++ = 'h';
+  *pos = 0;
+
   fprintf (fp,
-          "<SIGNAL>\\n<NAME>%s::%s</NAME>\\n<RETURNS>%s</RETURNS>\\n%s</SIGNAL>\\n\\n",
-          object_name, query_info.signal_name, ret_type_buffer, buffer);
+          "<SIGNAL>\\n<NAME>%s::%s</NAME>\\n<RETURNS>%s</RETURNS>\\n<FLAGS>%s</FLAGS>\\n%s</SIGNAL>\\n\\n",
+          object_name, query_info.signal_name, ret_type_buffer, flags, buffer);
 }
 
 
@@ -497,11 +691,14 @@ get_type_name (GType type, gboolean * is_pointer)
     break;
   }
 
-  /* For all GtkObject subclasses we can use the class name with a "*",
+  /* For all GObject subclasses we can use the class name with a "*",
      e.g. 'GtkWidget *'. */
   if (g_type_is_a (type, G_TYPE_OBJECT))
     *is_pointer = TRUE;
 
+  if (G_TYPE_IS_CLASSED (type))
+    *is_pointer = TRUE;
+
   /* All boxed subtypes will be pointers as well. */
   if (g_type_is_a (type, G_TYPE_BOXED))
     *is_pointer = TRUE;
@@ -510,14 +707,19 @@ get_type_name (GType type, gboolean * is_pointer)
   if (g_type_is_a (type, G_TYPE_POINTER))
     *is_pointer = TRUE;
 
+  /* But enums are not */
+  if (g_type_is_a (type, G_TYPE_ENUM) ||
+      g_type_is_a (type, G_TYPE_FLAGS))
+    *is_pointer = FALSE;
+
   return type_name;
 }
 
 
-static gchar *
+static const gchar *
 get_gdk_event (const gchar * signal_name)
 {
-  static gchar *GbGDKEvents[] =
+  static const gchar *GbGDKEvents[] =
   {
     "button_press_event", "GdkEventButton",
     "button_release_event", "GdkEventButton",
@@ -570,12 +772,12 @@ get_gdk_event (const gchar * signal_name)
     It is passed a widget name, e.g. 'GtkCList' and a signal name, e.g.
     'select_row' and it returns a pointer to an array of argument types and
     names. */
-static gchar **
+static const gchar **
 lookup_signal_arg_names (const gchar * type, const gchar * signal_name)
 {
   /* Each arg array starts with the object type name and the signal name,
      and then signal arguments follow. */
-  static gchar *GbArgTable[][16] =
+  static const gchar *GbArgTable[][16] =
   {
     {"GtkCList", "select_row",
      "gint             row",
@@ -790,24 +992,52 @@ lookup_signal_arg_names (const gchar * type, const gchar * signal_name)
   return NULL;
 }
 
-/* This outputs the hierarchy of all widgets which have been initialized,
+/* This outputs the hierarchy of all objects which have been initialized,
    i.e. by calling their XXX_get_type() initialization function. */
 static void
-output_widget_hierarchy (void)
+output_object_hierarchy (void)
 {
   FILE *fp;
+  gint i;
 
   fp = fopen (hierarchy_filename, "w");
   if (fp == NULL)
     {
-      g_warning ("Couldn't open output file: %s", hierarchy_filename);
+      g_warning ("Couldn't open output file: %s : %s", hierarchy_filename, strerror(errno));
       return;
     }
   output_hierarchy (fp, G_TYPE_OBJECT, 0);
   output_hierarchy (fp, G_TYPE_INTERFACE, 0);
+
+  for (i=0; object_types[i]; i++) {
+    if (!g_type_parent (object_types[i]) &&
+      (object_types[i] != G_TYPE_NONE) &&
+      (object_types[i] != G_TYPE_OBJECT) &&
+      (object_types[i] != G_TYPE_INTERFACE)
+    ) {
+      g_warning ("printing hierarchy for root type: %s",
+          g_type_name (object_types[i]));
+      output_hierarchy (fp, object_types[i], 0);
+    }
+  }
+  /* for debugging
+  for (i=0; object_types[i]; i++) {
+    if(object_types[i] != G_TYPE_NONE) {
+      g_print ("type has not been added to hierarchy: %s\\n",
+        g_type_name (object_types[i]));
+    }
+  }
+  for debugging */
+
   fclose (fp);
 }
 
+static int
+type_cmp (const void * p1, const void * p2)
+{
+  return strcmp (g_type_name (*((GType *) p1)), g_type_name (*((GType *) p2)));
+}
+
 /* This is called recursively to output the hierarchy of a widget. */
 static void
 output_hierarchy (FILE  *fp,
@@ -821,30 +1051,55 @@ output_hierarchy (FILE  *fp,
   if (!type)
     return;
 
+  /* for debugging
+  for (i=0; object_types[i]; i++) {
+    if(object_types[i] == type) {
+      g_print ("added type to hierarchy (level %d): %s\\n",
+        level, g_type_name (type));
+      object_types[i] = G_TYPE_NONE;
+      break;
+    }
+  }
+  for debugging */
+
   for (i = 0; i < level; i++)
     fprintf (fp, "  ");
-  fprintf (fp, g_type_name (type));
+  fprintf (fp, "%s", g_type_name (type));
   fprintf (fp, "\\n");
 
   children = g_type_children (type, &n_children);
 
-  for (i=0; i < n_children; i++)
+  qsort (&children[0], n_children, sizeof (GType), type_cmp);
+
+  for (i=0; i < n_children; i++) {
     output_hierarchy (fp, children[i], level + 1);
+  }
 
   g_free (children);
 }
 
-static void output_widget_interfaces (void)
+static void output_object_interfaces (void)
 {
+  guint i;
   FILE *fp;
 
   fp = fopen (interfaces_filename, "w");
   if (fp == NULL)
     {
-      g_warning ("Couldn't open output file: %s", interfaces_filename);
+      g_warning ("Couldn't open output file: %s : %s", interfaces_filename, strerror(errno));
       return;
     }
   output_interfaces (fp, G_TYPE_OBJECT);
+
+  for (i = 0; object_types[i]; i++)
+    {
+      if (!g_type_parent (object_types[i]) &&
+          (object_types[i] != G_TYPE_OBJECT) &&
+          G_TYPE_IS_INSTANTIATABLE (object_types[i]))
+        {
+          output_interfaces (fp, object_types[i]);
+        }
+    }
   fclose (fp);
 }
 
@@ -863,7 +1118,7 @@ output_interfaces (FILE  *fp,
 
   if (n_interfaces > 0)
     {
-      fprintf (fp, g_type_name (type));
+      fprintf (fp, "%s", g_type_name (type));
       for (i=0; i < n_interfaces; i++)
           fprintf (fp, " %s", g_type_name (interfaces[i]));
       fprintf (fp, "\\n");
@@ -885,7 +1140,7 @@ static void output_interface_prerequisites (void)
   fp = fopen (prerequisites_filename, "w");
   if (fp == NULL)
     {
-      g_warning ("Couldn't open output file: %s", prerequisites_filename);
+      g_warning ("Couldn't open output file: %s : %s", prerequisites_filename, strerror(errno));
       return;
     }
   output_prerequisites (fp, G_TYPE_INTERFACE);
@@ -908,7 +1163,7 @@ output_prerequisites (FILE  *fp,
 
   if (n_prerequisites > 0)
     {
-      fprintf (fp, g_type_name (type));
+      fprintf (fp, "%s", g_type_name (type));
       for (i=0; i < n_prerequisites; i++)
           fprintf (fp, " %s", g_type_name (prerequisites[i]));
       fprintf (fp, "\\n");
@@ -933,12 +1188,13 @@ output_args (void)
   fp = fopen (args_filename, "w");
   if (fp == NULL)
     {
-      g_warning ("Couldn't open output file: %s", args_filename);
+      g_warning ("Couldn't open output file: %s : %s", args_filename, strerror(errno));
       return;
     }
 
-  for (i = 0; i < num_object_types; i++)
-    output_widget_args (fp, object_types[i]);
+  for (i = 0; object_types[i]; i++) {
+    output_object_args (fp, object_types[i]);
+  }
 
   fclose (fp);
 }
@@ -957,25 +1213,33 @@ compare_param_specs (const void *a, const void *b)
  * a bit nicer by spelling out the max constants.
  */
 
+/* Don't use "==" with floats, it might trigger a gcc warning.  */
+#define GTKDOC_COMPARE_FLOAT(x, y) (x <= y && x >= y)
+
 static gchar*
 describe_double_constant (gdouble value)
 {
   gchar *desc;
 
-  if (value == G_MAXDOUBLE)
+  if (GTKDOC_COMPARE_FLOAT (value, G_MAXDOUBLE))
     desc = g_strdup ("G_MAXDOUBLE");
-  else if (value == G_MINDOUBLE)
+  else if (GTKDOC_COMPARE_FLOAT (value, G_MINDOUBLE))
     desc = g_strdup ("G_MINDOUBLE");
-  else if (value == -G_MAXDOUBLE)
+  else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXDOUBLE))
     desc = g_strdup ("-G_MAXDOUBLE");
-  else if (value == G_MAXFLOAT)
+  else if (GTKDOC_COMPARE_FLOAT (value, G_MAXFLOAT))
     desc = g_strdup ("G_MAXFLOAT");
-  else if (value == G_MINFLOAT)
+  else if (GTKDOC_COMPARE_FLOAT (value, G_MINFLOAT))
     desc = g_strdup ("G_MINFLOAT");
-  else if (value == -G_MAXFLOAT)
+  else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXFLOAT))
     desc = g_strdup ("-G_MAXFLOAT");
-  else
-    desc = g_strdup_printf ("%lg", value);
+  else {
+    /* make sure floats are output with a decimal dot irrespective of
+     * current locale. Use formatd since we want human-readable numbers
+     * and do not need the exact same bit representation when deserialising */
+    desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
+    g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g", value);
+  }
 
   return desc;
 }
@@ -1186,11 +1450,14 @@ describe_type (GParamSpec *spec)
 
       lower = describe_double_constant (pspec->minimum);
       upper = describe_double_constant (pspec->maximum);
-      if (pspec->minimum == -G_MAXFLOAT && pspec->maximum == G_MAXFLOAT)
-       desc = g_strdup ("");
-      else if (pspec->minimum == -G_MAXFLOAT)
-       desc = g_strdup_printf ("<= %s", upper);
-      else if (pspec->maximum == G_MAXFLOAT)
+      if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXFLOAT))
+       {
+         if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
+           desc = g_strdup ("");
+         else
+           desc = g_strdup_printf ("<= %s", upper);
+       }
+      else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
        desc = g_strdup_printf (">= %s", lower);
       else
        desc = g_strdup_printf ("[%s,%s]", lower, upper);
@@ -1203,11 +1470,14 @@ describe_type (GParamSpec *spec)
 
       lower = describe_double_constant (pspec->minimum);
       upper = describe_double_constant (pspec->maximum);
-      if (pspec->minimum == -G_MAXDOUBLE && pspec->maximum == G_MAXDOUBLE)
-       desc = g_strdup ("");
-      else if (pspec->minimum == -G_MAXDOUBLE)
-       desc = g_strdup_printf ("<= %s", upper);
-      else if (pspec->maximum == G_MAXDOUBLE)
+      if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXDOUBLE))
+       {
+         if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
+           desc = g_strdup ("");
+         else
+           desc = g_strdup_printf ("<= %s", upper);
+       }
+      else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
        desc = g_strdup_printf (">= %s", lower);
       else
        desc = g_strdup_printf ("[%s,%s]", lower, upper);
@@ -1335,13 +1605,23 @@ describe_default (GParamSpec *spec)
     {
       GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
 
-      desc = g_strdup_printf ("%g", pspec->default_value);
+      /* make sure floats are output with a decimal dot irrespective of
+       * current locale. Use formatd since we want human-readable numbers
+       * and do not need the exact same bit representation when deserialising */
+      desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
+      g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
+          pspec->default_value);
     }
   else if (G_IS_PARAM_SPEC_DOUBLE (spec))
     {
       GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
 
-      desc = g_strdup_printf ("%lg", pspec->default_value);
+      /* make sure floats are output with a decimal dot irrespective of
+       * current locale. Use formatd since we want human-readable numbers
+       * and do not need the exact same bit representation when deserialising */
+      desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
+      g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
+          pspec->default_value);
     }
   else if (G_IS_PARAM_SPEC_STRING (spec))
     {
@@ -1368,7 +1648,7 @@ describe_default (GParamSpec *spec)
 
 
 static void
-output_widget_args (FILE *fp, GType object_type)
+output_object_args (FILE *fp, GType object_type)
 {
   gpointer class;
   const gchar *object_class_name;
@@ -1378,10 +1658,12 @@ output_widget_args (FILE *fp, GType object_type)
   guint n_properties;
   gboolean child_prop;
   gboolean style_prop;
+  gboolean is_pointer;
+  const gchar *type_name;
   gchar *type_desc;
   gchar *default_value;
 
-  if (G_TYPE_IS_CLASSED (object_type))
+  if (G_TYPE_IS_OBJECT (object_type))
     {
       class = g_type_class_peek (object_type);
       if (!class)
@@ -1446,8 +1728,9 @@ output_widget_args (FILE *fp, GType object_type)
 
        type_desc = describe_type (spec);
        default_value = describe_default (spec);
-        fprintf (fp, "<ARG>\\n<NAME>%s::%s</NAME>\\n<TYPE>%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",
-                object_class_name, g_param_spec_get_name (spec), g_type_name (spec->value_type), type_desc, flags, nick ? nick : "(null)", blurb ? blurb : "(null)", dot, default_value);
+       type_name = get_type_name (spec->value_type, &is_pointer);
+        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",
+                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);
        g_free (type_desc);
        g_free (default_value);
       }
@@ -1483,7 +1766,7 @@ close OUTPUT;
 
 $CC = $ENV{CC} ? $ENV{CC} : "gcc";
 $LD = $ENV{LD} ? $ENV{LD} : $CC;
-$CFLAGS = $ENV{CFLAGS} ? $ENV{CFLAGS} : "";
+$CFLAGS = $ENV{CFLAGS} ? "$ENV{CFLAGS}" : "";
 $LDFLAGS = $ENV{LDFLAGS} ? $ENV{LDFLAGS} : "";
 
 my $o_file;
@@ -1493,18 +1776,25 @@ if ($CC =~ /libtool/) {
   $o_file = "$MODULE-scan.o"
 }
 
-$command = "$CC $CFLAGS -c -o $o_file $MODULE-scan.c && $LD -o $MODULE-scan $o_file $LDFLAGS";
+print "gtk-doc: Compiling scanner\n";
+$command = "$CC $CFLAGS -c -o $o_file $MODULE-scan.c";
+system($command) == 0 or die "Compilation of scanner failed: $!\n";
 
-system($command) == 0 or die "Compilation of scanner failed\n";
+print "gtk-doc: Linking scanner\n";
+$command = "$LD -o $MODULE-scan $o_file $LDFLAGS";
+system($command) == 0 or die "Linking of scanner failed: $!\n";
 
-system("./$MODULE-scan") == 0 or die "Scan failed\n";
+print "gtk-doc: Running scanner $MODULE-scan\n";
+system("sh -c ./$MODULE-scan") == 0 or die "Scan failed: $!\n";
 
-unlink "./$MODULE-scan.c", "./$MODULE-scan.o", "./$MODULE-scan.lo", "./$MODULE-scan";
+if (!defined($ENV{"GTK_DOC_KEEP_INTERMEDIATE"})) {
+  unlink "./$MODULE-scan.c", "./$MODULE-scan.o", "./$MODULE-scan.lo", "./$MODULE-scan";
+}
 
 #&UpdateFileIfChanged ($old_signals_filename, $new_signals_filename, 0);
-#&UpdateFileIfChanged ($old_hierarchy_filename, $new_hierarchy_filename, 0);
-#&UpdateFileIfChanged ($old_interfaces_filename, $new_interfaces_filename, 0);
-#&UpdateFileIfChanged ($old_prerequisites_filename, $new_prerequisites_filename, 0);
+&UpdateFileIfChanged ($old_hierarchy_filename, $new_hierarchy_filename, 0);
+&UpdateFileIfChanged ($old_interfaces_filename, $new_interfaces_filename, 0);
+&UpdateFileIfChanged ($old_prerequisites_filename, $new_prerequisites_filename, 0);
 #&UpdateFileIfChanged ($old_args_filename, $new_args_filename, 0);