4 # gtk-doc - GTK DocBook documentation generator.
5 # Copyright (C) 1998 Damon Chaplin
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.
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.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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.
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";
36 unshift @INC, '/usr/share/gtk-doc/data';
38 require "gtkdoc-common.pl";
42 # name of documentation module
49 my $TYPE_INIT_FUNC="g_type_init ()";
51 # --nogtkinit is deprecated, as it is the default now anyway.
52 %optctl = (module => \$MODULE,
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);
63 GetOptions(\%optctl, "module=s", "source=s", "types:s", "output-dir:s", "inspect-dir:s", "nogtkinit", "type-init-func:s", "verbose", "version", "help");
66 # Do nothing. This just avoids a warning.
67 # the option is not used anymore
81 gstdoc-scangobj version 1.5 - introspect gstreamer-plugins
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
96 $OUTPUT_DIR = $OUTPUT_DIR ? $OUTPUT_DIR : ".";
98 $TYPES_FILE = $TYPES_FILE ? $TYPES_FILE : "$OUTPUT_DIR/$MODULE.types";
100 open (TYPES, $TYPES_FILE) || die "Cannot open $TYPES_FILE: $!\n";
101 open (OUTPUT, ">$MODULE-scan.c") || die "Cannot open $MODULE-scan.c: $!\n";
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";
114 my $debug_log="g_message";
115 if (!defined($VERBOSE) or $VERBOSE eq "0") {
116 $debug_log="//$debug_log";
119 # write a C program to scan the types
132 } elsif (/^type:(.*)$/) {
135 push @impl_types, $t;
142 $ntypes = @types + @impl_types + 1;
152 #ifdef GTK_IS_WIDGET_CLASS
153 #include <gtk/gtkversion.h>
156 static GType *object_types = NULL;
158 static GString *xmlstr = NULL;
161 xmlprint (gint indent, const gchar *tag, const gchar *data)
163 const gchar indent_str[] = " ";
166 g_string_truncate (xmlstr, 0);
167 g_string_append_len (xmlstr, indent_str, MIN (indent, strlen (indent_str)));
168 g_string_append_printf (xmlstr, "<%s>", tag);
173 s = g_markup_escape_text (data, -1);
174 g_string_append (xmlstr, s);
178 g_string_append_printf (xmlstr, "</%s>\\n", tag);
183 gst_feature_sort_compare (gconstpointer a, gconstpointer b)
185 const gchar *name_a = gst_plugin_feature_get_name ((GstPluginFeature *) a);
186 const gchar *name_b = gst_plugin_feature_get_name ((GstPluginFeature *) b);
187 return strcmp (name_a, name_b);
191 static_pad_template_compare (gconstpointer a, gconstpointer b)
193 GstStaticPadTemplate *spt_a = (GstStaticPadTemplate *) a;
194 GstStaticPadTemplate *spt_b = (GstStaticPadTemplate *) b;
196 /* we want SINK before SRC (enum is UNKNOWN, SRC, SINK) */
197 if (spt_a->direction != spt_b->direction)
198 return spt_b->direction - spt_a->direction;
200 /* we want ALWAYS first, SOMETIMES second, REQUEST last
201 * (enum is ALWAYS, SOMETIMES, REQUEST) */
202 if (spt_a->presence != spt_b->presence)
203 return spt_a->presence - spt_b->presence;
205 return strcmp (spt_a->name_template, spt_b->name_template);
209 get_object_types (void)
211 gpointer g_object_class;
212 GList *plugins = NULL;
213 GList *factories = NULL;
215 GstElementFactory *factory = NULL;
220 /* get a list of features from plugins in our source module */
221 plugins = gst_registry_get_plugin_list (gst_registry_get_default());
223 xmlstr = g_string_new ("");
225 reinspect = !g_file_test ("scanobj-build.stamp", G_FILE_TEST_EXISTS);
231 FILE *inspect = NULL;
234 plugin = (GstPlugin *) (plugins->data);
235 plugins = g_list_next (plugins);
236 source = gst_plugin_get_source (plugin);
237 if (!source || strcmp (source, "$SOURCE") != 0) {
241 /* skip static coreelements plugin with pipeline and bin element factory */
242 if (gst_plugin_get_filename (plugin) == NULL)
245 $debug_log ("plugin: %s source: %s", plugin->desc.name, source);
248 inspect_name = g_strdup_printf ("$INSPECT_DIR" G_DIR_SEPARATOR_S "plugin-%s.xml",
250 inspect = fopen (inspect_name, "w");
251 if (inspect == NULL) {
252 g_error ("Could not open %s for writing: %s\\n", inspect_name,
255 g_free (inspect_name);
257 /* output plugin data */
258 fputs ("<plugin>\\n",inspect);
259 fputs (xmlprint(2, "name", plugin->desc.name),inspect);
260 fputs (xmlprint(2, "description", plugin->desc.description),inspect);
261 fputs (xmlprint(2, "filename", plugin->filename),inspect);
262 fputs (xmlprint(2, "basename", plugin->basename),inspect);
263 fputs (xmlprint(2, "version", plugin->desc.version),inspect);
264 fputs (xmlprint(2, "license", plugin->desc.license),inspect);
265 fputs (xmlprint(2, "source", plugin->desc.source),inspect);
266 fputs (xmlprint(2, "package", plugin->desc.package),inspect);
267 fputs (xmlprint(2, "origin", plugin->desc.origin),inspect);
268 fputs (" <elements>\\n", inspect);
272 gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
275 /* sort factories by feature->name */
276 features = g_list_sort (features, gst_feature_sort_compare);
279 GstPluginFeature *feature;
280 feature = GST_PLUGIN_FEATURE (features->data);
281 feature = gst_plugin_feature_load (feature);
283 g_warning ("Could not load plugin feature %s",
284 gst_plugin_feature_get_name (feature));
287 if (GST_IS_ELEMENT_FACTORY (feature)) {
288 const gchar *pad_dir[] = { "unknown","source","sink" };
289 const gchar *pad_pres[] = { "always","sometimes","request" };
292 $debug_log (" feature: %s", gst_plugin_feature_get_name (feature));
294 factory = GST_ELEMENT_FACTORY (feature);
295 factories = g_list_prepend (factories, factory);
298 /* output element data */
299 fputs (" <element>\\n", inspect);
300 fputs (xmlprint(6, "name", gst_plugin_feature_get_name (feature)),inspect);
301 fputs (xmlprint(6, "longname", gst_element_factory_get_longname (factory)),inspect);
302 fputs (xmlprint(6, "class", gst_element_factory_get_klass (factory)),inspect);
303 fputs (xmlprint(6, "description", gst_element_factory_get_description (factory)),inspect);
304 fputs (xmlprint(6, "author", gst_element_factory_get_author (factory)),inspect);
305 fputs (" <pads>\\n", inspect);
307 /* output pad-template data */
308 pads = g_list_copy ((GList *) gst_element_factory_get_static_pad_templates (factory));
309 pads = g_list_sort (pads, static_pad_template_compare);
310 for (pad = pads; pad != NULL; pad = pad->next) {
311 GstStaticPadTemplate *pt = pad->data;
313 fputs (" <caps>\\n", inspect);
314 fputs (xmlprint(10, "name", pt->name_template),inspect);
315 fputs (xmlprint(10, "direction", pad_dir[pt->direction]),inspect);
316 fputs (xmlprint(10, "presence", pad_pres[pt->presence]),inspect);
317 fputs (xmlprint(10, "details", pt->static_caps.string),inspect);
318 fputs (" </caps>\\n", inspect);
321 fputs (" </pads>\\n </element>\\n", inspect);
324 features = g_list_next (features);
328 fputs (" </elements>\\n</plugin>", inspect);
333 g_string_free (xmlstr, TRUE);
335 $debug_log ("number of element factories: %d", g_list_length (factories));
337 /* allocate the object_types array to hold them */
338 object_types = g_new0 (GType, g_list_length (factories)+$ntypes+1);
345 factory = GST_ELEMENT_FACTORY (l->data);
346 type = gst_element_factory_get_element_type (factory);
348 $debug_log ("adding type for factory %s", gst_element_factory_get_longname (factory));
349 object_types[i++] = type;
351 g_message ("type info for factory %s not found",
352 gst_element_factory_get_longname (factory));
359 # get_type functions:
364 g_message ("$_ () didn't return a valid type");
367 object_types[i++] = type;
372 # Implicit types retrieved from GLib:
375 type = g_type_from_name ("$_");
377 g_message ("Implicit type $_ not found");
380 object_types[i++] = type;
389 /* reference the GObjectClass to initialize the param spec pool
390 * potentially needed by interfaces. See http://bugs.gnome.org/571820 */
391 g_object_class = g_type_class_ref (G_TYPE_OBJECT);
393 /* Need to make sure all the types are loaded in and initialize
394 * their signals and properties.
396 for (i=0; object_types[i]; i++)
398 if (G_TYPE_IS_CLASSED (object_types[i]))
399 g_type_class_ref (object_types[i]);
400 if (G_TYPE_IS_INTERFACE (object_types[i]))
401 g_type_default_interface_ref (object_types[i]);
404 g_type_class_unref (g_object_class);
410 * This uses GObject type functions to output signal prototypes and the object
414 /* The output files */
415 const gchar *signals_filename = "$new_signals_filename";
416 const gchar *hierarchy_filename = "$new_hierarchy_filename";
417 const gchar *interfaces_filename = "$new_interfaces_filename";
418 const gchar *prerequisites_filename = "$new_prerequisites_filename";
419 const gchar *args_filename = "$new_args_filename";
422 static void output_signals (void);
423 static void output_object_signals (FILE *fp,
425 static void output_object_signal (FILE *fp,
426 const gchar *object_class_name,
428 static const gchar * get_type_name (GType type,
429 gboolean * is_pointer);
430 static void output_object_hierarchy (void);
431 static void output_hierarchy (FILE *fp,
435 static void output_object_interfaces (void);
436 static void output_interfaces (FILE *fp,
439 static void output_interface_prerequisites (void);
440 static void output_prerequisites (FILE *fp,
443 static void output_args (void);
444 static void output_object_args (FILE *fp, GType object_type);
447 main (int argc, char *argv[])
449 /* Silence the compiler: */
450 if (argv != argv) argc = argc;
457 output_object_hierarchy ();
458 output_object_interfaces ();
459 output_interface_prerequisites ();
467 output_signals (void)
472 fp = fopen (signals_filename, "w");
475 g_warning ("Couldn't open output file: %s : %s", signals_filename, g_strerror(errno));
479 for (i = 0; object_types[i]; i++)
480 output_object_signals (fp, object_types[i]);
486 compare_signals (const void *a, const void *b)
488 const guint *signal_a = a;
489 const guint *signal_b = b;
491 return strcmp (g_signal_name (*signal_a), g_signal_name (*signal_b));
494 /* This outputs all the signals of one object. */
496 output_object_signals (FILE *fp, GType object_type)
498 const gchar *object_class_name;
499 guint *signals, n_signals;
502 if (G_TYPE_IS_INSTANTIATABLE (object_type) ||
503 G_TYPE_IS_INTERFACE (object_type))
506 object_class_name = g_type_name (object_type);
508 signals = g_signal_list_ids (object_type, &n_signals);
509 qsort (signals, n_signals, sizeof (guint), compare_signals);
511 for (sig = 0; sig < n_signals; sig++)
513 output_object_signal (fp, object_class_name, signals[sig]);
520 /* This outputs one signal. */
522 output_object_signal (FILE *fp,
523 const gchar *object_name,
526 GSignalQuery query_info;
527 const gchar *type_name, *ret_type, *object_arg, *arg_name;
528 gchar *pos, *object_arg_lower;
532 gint param_num, widget_num, event_num, callback_num;
534 gchar signal_name[128];
537 $debug_log ("Object: %s Signal: %u", object_name, signal_id);
540 widget_num = event_num = callback_num = 0;
542 g_signal_query (signal_id, &query_info);
544 /* Output the signal object type and the argument name. We assume the
545 type is a pointer - I think that is OK. We remove "Gtk" or "Gnome" and
546 convert to lower case for the argument name. */
548 sprintf (pos, "%s ", object_name);
551 /* Try to come up with a sensible variable name for the first arg
552 * It chops off 2 know prefixes :/ and makes the name lowercase
553 * It should replace lowercase -> uppercase with '_'
554 * GFileMonitor -> file_monitor
555 * GIOExtensionPoint -> extension_point
556 * GtkTreeView -> tree_view
557 * if 2nd char is upper case too
558 * search for first lower case and go back one char
560 * search for next upper case
562 if (!strncmp (object_name, "Gtk", 3))
563 object_arg = object_name + 3;
564 else if (!strncmp (object_name, "Gnome", 5))
565 object_arg = object_name + 5;
567 object_arg = object_name;
569 object_arg_lower = g_ascii_strdown (object_arg, -1);
570 sprintf (pos, "*%s\\n", object_arg_lower);
572 if (!strncmp (object_arg_lower, "widget", 6))
574 g_free(object_arg_lower);
576 /* Convert signal name to use underscores rather than dashes '-'. */
577 strncpy (signal_name, query_info.signal_name, 127);
578 signal_name[127] = '\\0';
579 for (i = 0; signal_name[i]; i++)
581 if (signal_name[i] == '-')
582 signal_name[i] = '_';
585 /* Output the signal parameters. */
586 for (param = 0; param < query_info.n_params; param++)
588 type_name = get_type_name (query_info.param_types[param] & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
590 /* Most arguments to the callback are called "arg1", "arg2", etc.
591 GtkWidgets are called "widget", "widget2", ...
592 GtkCallbacks are called "callback", "callback2", ... */
593 if (!strcmp (type_name, "GtkWidget"))
596 arg_num = &widget_num;
598 else if (!strcmp (type_name, "GtkCallback")
599 || !strcmp (type_name, "GtkCCallback"))
601 arg_name = "callback";
602 arg_num = &callback_num;
607 arg_num = ¶m_num;
609 sprintf (pos, "%s ", type_name);
612 if (!arg_num || *arg_num == 0)
613 sprintf (pos, "%s%s\\n", is_pointer ? "*" : " ", arg_name);
615 sprintf (pos, "%s%s%i\\n", is_pointer ? "*" : " ", arg_name,
629 /* We use one-character flags for simplicity. */
630 if (query_info.signal_flags & G_SIGNAL_RUN_FIRST)
632 if (query_info.signal_flags & G_SIGNAL_RUN_LAST)
634 if (query_info.signal_flags & G_SIGNAL_RUN_CLEANUP)
636 if (query_info.signal_flags & G_SIGNAL_NO_RECURSE)
638 if (query_info.signal_flags & G_SIGNAL_DETAILED)
640 if (query_info.signal_flags & G_SIGNAL_ACTION)
642 if (query_info.signal_flags & G_SIGNAL_NO_HOOKS)
646 /* Output the return type and function name. */
647 ret_type = get_type_name (query_info.return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
650 "<SIGNAL>\\n<NAME>%s::%s</NAME>\\n<RETURNS>%s%s</RETURNS>\\n<FLAGS>%s</FLAGS>\\n%s</SIGNAL>\\n\\n",
651 object_name, query_info.signal_name, ret_type, is_pointer ? "*" : "", flags, buffer);
655 /* Returns the type name to use for a signal argument or return value, given
656 the GtkType from the signal info. It also sets is_pointer to TRUE if the
657 argument needs a '*' since it is a pointer. */
659 get_type_name (GType type, gboolean * is_pointer)
661 const gchar *type_name;
664 type_name = g_type_name (type);
678 /* These all have normal C type names so they are OK. */
682 /* A GtkString is really a gchar*. */
688 /* We use a gint for both of these. Hopefully a subtype with a decent
689 name will be registered and used instead, as GTK+ does itself. */
693 /* The boxed type shouldn't be used itself, only subtypes. Though we
694 return 'gpointer' just in case. */
698 /* A GParam is really a GParamSpec*. */
702 #if GLIB_CHECK_VERSION (2, 25, 9)
712 /* For all GObject subclasses we can use the class name with a "*",
713 e.g. 'GtkWidget *'. */
714 if (g_type_is_a (type, G_TYPE_OBJECT))
717 /* Also catch non GObject root types */
718 if (G_TYPE_IS_CLASSED (type))
721 /* All boxed subtypes will be pointers as well. */
722 /* Exception: GStrv */
723 if (g_type_is_a (type, G_TYPE_BOXED) &&
724 !g_type_is_a (type, G_TYPE_STRV))
727 /* All pointer subtypes will be pointers as well. */
728 if (g_type_is_a (type, G_TYPE_POINTER))
731 /* But enums are not */
732 if (g_type_is_a (type, G_TYPE_ENUM) ||
733 g_type_is_a (type, G_TYPE_FLAGS))
740 /* This outputs the hierarchy of all objects which have been initialized,
741 i.e. by calling their XXX_get_type() initialization function. */
743 output_object_hierarchy (void)
748 GType root_types[$ntypes] = { G_TYPE_INVALID, };
750 fp = fopen (hierarchy_filename, "w");
753 g_warning ("Couldn't open output file: %s : %s", hierarchy_filename, g_strerror(errno));
756 output_hierarchy (fp, G_TYPE_OBJECT, 0);
757 output_hierarchy (fp, G_TYPE_INTERFACE, 0);
759 for (i=0; object_types[i]; i++) {
760 root = object_types[i];
761 while ((type = g_type_parent (root))) {
764 if ((root != G_TYPE_OBJECT) && (root != G_TYPE_INTERFACE)) {
765 for (j=0; root_types[j]; j++) {
766 if (root == root_types[j]) {
767 root = G_TYPE_INVALID; break;
771 root_types[j] = root;
772 output_hierarchy (fp, root, 0);
781 compare_types (const void *a, const void *b)
783 const char *na = g_type_name (*((GType *)a));
784 const char *nb = g_type_name (*((GType *)b));
786 return g_strcmp0 (na, nb);
790 /* This is called recursively to output the hierarchy of a object. */
792 output_hierarchy (FILE *fp,
803 for (i = 0; i < level; i++)
805 fprintf (fp, "%s\\n", g_type_name (type));
807 children = g_type_children (type, &n_children);
808 qsort (children, n_children, sizeof (GType), compare_types);
811 for (i=0; i < n_children; i++)
812 output_hierarchy (fp, children[i], level + 1);
817 static void output_object_interfaces (void)
822 fp = fopen (interfaces_filename, "w");
825 g_warning ("Couldn't open output file: %s : %s", interfaces_filename, g_strerror(errno));
828 output_interfaces (fp, G_TYPE_OBJECT);
830 for (i = 0; object_types[i]; i++)
832 if (!g_type_parent (object_types[i]) &&
833 (object_types[i] != G_TYPE_OBJECT) &&
834 G_TYPE_IS_INSTANTIATABLE (object_types[i]))
836 output_interfaces (fp, object_types[i]);
843 output_interfaces (FILE *fp,
847 GType *children, *interfaces;
848 guint n_children, n_interfaces;
853 interfaces = g_type_interfaces (type, &n_interfaces);
855 if (n_interfaces > 0)
857 fprintf (fp, "%s", g_type_name (type));
858 for (i=0; i < n_interfaces; i++)
859 fprintf (fp, " %s", g_type_name (interfaces[i]));
864 children = g_type_children (type, &n_children);
866 for (i=0; i < n_children; i++)
867 output_interfaces (fp, children[i]);
872 static void output_interface_prerequisites (void)
876 fp = fopen (prerequisites_filename, "w");
879 g_warning ("Couldn't open output file: %s : %s", prerequisites_filename, g_strerror(errno));
882 output_prerequisites (fp, G_TYPE_INTERFACE);
887 output_prerequisites (FILE *fp,
890 #if GLIB_CHECK_VERSION(2,1,0)
892 GType *children, *prerequisites;
893 guint n_children, n_prerequisites;
898 prerequisites = g_type_interface_prerequisites (type, &n_prerequisites);
900 if (n_prerequisites > 0)
902 fprintf (fp, "%s", g_type_name (type));
903 for (i=0; i < n_prerequisites; i++)
904 fprintf (fp, " %s", g_type_name (prerequisites[i]));
907 g_free (prerequisites);
909 children = g_type_children (type, &n_children);
911 for (i=0; i < n_children; i++)
912 output_prerequisites (fp, children[i]);
924 fp = fopen (args_filename, "w");
927 g_warning ("Couldn't open output file: %s : %s", args_filename, g_strerror(errno));
931 for (i = 0; object_types[i]; i++) {
932 output_object_args (fp, object_types[i]);
939 compare_param_specs (const void *a, const void *b)
941 GParamSpec *spec_a = *(GParamSpec **)a;
942 GParamSpec *spec_b = *(GParamSpec **)b;
944 return strcmp (g_param_spec_get_name (spec_a), g_param_spec_get_name (spec_b));
947 /* Its common to have unsigned properties restricted
948 * to the signed range. Therefore we make this look
949 * a bit nicer by spelling out the max constants.
952 /* Don't use "==" with floats, it might trigger a gcc warning. */
953 #define GTKDOC_COMPARE_FLOAT(x, y) (x <= y && x >= y)
956 describe_double_constant (gdouble value)
960 if (GTKDOC_COMPARE_FLOAT (value, G_MAXDOUBLE))
961 desc = g_strdup ("G_MAXDOUBLE");
962 else if (GTKDOC_COMPARE_FLOAT (value, G_MINDOUBLE))
963 desc = g_strdup ("G_MINDOUBLE");
964 else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXDOUBLE))
965 desc = g_strdup ("-G_MAXDOUBLE");
966 else if (GTKDOC_COMPARE_FLOAT (value, G_MAXFLOAT))
967 desc = g_strdup ("G_MAXFLOAT");
968 else if (GTKDOC_COMPARE_FLOAT (value, G_MINFLOAT))
969 desc = g_strdup ("G_MINFLOAT");
970 else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXFLOAT))
971 desc = g_strdup ("-G_MAXFLOAT");
973 /* make sure floats are output with a decimal dot irrespective of
974 * current locale. Use formatd since we want human-readable numbers
975 * and do not need the exact same bit representation when deserialising */
976 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
977 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g", value);
984 describe_signed_constant (gsize size, gint64 value)
990 if (value == G_MAXINT64)
991 desc = g_strdup ("G_MAXINT64");
992 else if (value == G_MININT64)
993 desc = g_strdup ("G_MININT64");
996 if (sizeof (int) == 4) {
997 if (value == G_MAXINT)
998 desc = g_strdup ("G_MAXINT");
999 else if (value == G_MININT)
1000 desc = g_strdup ("G_MININT");
1001 else if (value == (gint64)G_MAXUINT)
1002 desc = g_strdup ("G_MAXUINT");
1004 if (value == G_MAXLONG)
1005 desc = g_strdup ("G_MAXLONG");
1006 else if (value == G_MINLONG)
1007 desc = g_strdup ("G_MINLONG");
1008 else if (value == (gint64)G_MAXULONG)
1009 desc = g_strdup ("G_MAXULONG");
1012 if (sizeof (int) == 2) {
1013 if (value == G_MAXINT)
1014 desc = g_strdup ("G_MAXINT");
1015 else if (value == G_MININT)
1016 desc = g_strdup ("G_MININT");
1017 else if (value == (gint64)G_MAXUINT)
1018 desc = g_strdup ("G_MAXUINT");
1025 desc = g_strdup_printf ("%" G_GINT64_FORMAT, value);
1031 describe_unsigned_constant (gsize size, guint64 value)
1037 if (value == G_MAXINT64)
1038 desc = g_strdup ("G_MAXINT64");
1039 else if (value == G_MAXUINT64)
1040 desc = g_strdup ("G_MAXUINT64");
1043 if (sizeof (int) == 4) {
1044 if (value == (guint64)G_MAXINT)
1045 desc = g_strdup ("G_MAXINT");
1046 else if (value == G_MAXUINT)
1047 desc = g_strdup ("G_MAXUINT");
1049 if (value == (guint64)G_MAXLONG)
1050 desc = g_strdup ("G_MAXLONG");
1051 else if (value == G_MAXULONG)
1052 desc = g_strdup ("G_MAXULONG");
1055 if (sizeof (int) == 2) {
1056 if (value == (guint64)G_MAXINT)
1057 desc = g_strdup ("G_MAXINT");
1058 else if (value == G_MAXUINT)
1059 desc = g_strdup ("G_MAXUINT");
1066 desc = g_strdup_printf ("%" G_GUINT64_FORMAT, value);
1072 describe_type (GParamSpec *spec)
1078 if (G_IS_PARAM_SPEC_CHAR (spec))
1080 GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
1082 lower = describe_signed_constant (sizeof(gchar), pspec->minimum);
1083 upper = describe_signed_constant (sizeof(gchar), pspec->maximum);
1084 if (pspec->minimum == G_MININT8 && pspec->maximum == G_MAXINT8)
1085 desc = g_strdup ("");
1086 else if (pspec->minimum == G_MININT8)
1087 desc = g_strdup_printf ("<= %s", upper);
1088 else if (pspec->maximum == G_MAXINT8)
1089 desc = g_strdup_printf (">= %s", lower);
1091 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1095 else if (G_IS_PARAM_SPEC_UCHAR (spec))
1097 GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
1099 lower = describe_unsigned_constant (sizeof(guchar), pspec->minimum);
1100 upper = describe_unsigned_constant (sizeof(guchar), pspec->maximum);
1101 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT8)
1102 desc = g_strdup ("");
1103 else if (pspec->minimum == 0)
1104 desc = g_strdup_printf ("<= %s", upper);
1105 else if (pspec->maximum == G_MAXUINT8)
1106 desc = g_strdup_printf (">= %s", lower);
1108 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1112 else if (G_IS_PARAM_SPEC_INT (spec))
1114 GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
1116 lower = describe_signed_constant (sizeof(gint), pspec->minimum);
1117 upper = describe_signed_constant (sizeof(gint), pspec->maximum);
1118 if (pspec->minimum == G_MININT && pspec->maximum == G_MAXINT)
1119 desc = g_strdup ("");
1120 else if (pspec->minimum == G_MININT)
1121 desc = g_strdup_printf ("<= %s", upper);
1122 else if (pspec->maximum == G_MAXINT)
1123 desc = g_strdup_printf (">= %s", lower);
1125 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1129 else if (G_IS_PARAM_SPEC_UINT (spec))
1131 GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
1133 lower = describe_unsigned_constant (sizeof(guint), pspec->minimum);
1134 upper = describe_unsigned_constant (sizeof(guint), pspec->maximum);
1135 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT)
1136 desc = g_strdup ("");
1137 else if (pspec->minimum == 0)
1138 desc = g_strdup_printf ("<= %s", upper);
1139 else if (pspec->maximum == G_MAXUINT)
1140 desc = g_strdup_printf (">= %s", lower);
1142 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1146 else if (G_IS_PARAM_SPEC_LONG (spec))
1148 GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
1150 lower = describe_signed_constant (sizeof(glong), pspec->minimum);
1151 upper = describe_signed_constant (sizeof(glong), pspec->maximum);
1152 if (pspec->minimum == G_MINLONG && pspec->maximum == G_MAXLONG)
1153 desc = g_strdup ("");
1154 else if (pspec->minimum == G_MINLONG)
1155 desc = g_strdup_printf ("<= %s", upper);
1156 else if (pspec->maximum == G_MAXLONG)
1157 desc = g_strdup_printf (">= %s", lower);
1159 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1163 else if (G_IS_PARAM_SPEC_ULONG (spec))
1165 GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
1167 lower = describe_unsigned_constant (sizeof(gulong), pspec->minimum);
1168 upper = describe_unsigned_constant (sizeof(gulong), pspec->maximum);
1169 if (pspec->minimum == 0 && pspec->maximum == G_MAXULONG)
1170 desc = g_strdup ("");
1171 else if (pspec->minimum == 0)
1172 desc = g_strdup_printf ("<= %s", upper);
1173 else if (pspec->maximum == G_MAXULONG)
1174 desc = g_strdup_printf (">= %s", lower);
1176 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1180 else if (G_IS_PARAM_SPEC_INT64 (spec))
1182 GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
1184 lower = describe_signed_constant (sizeof(gint64), pspec->minimum);
1185 upper = describe_signed_constant (sizeof(gint64), pspec->maximum);
1186 if (pspec->minimum == G_MININT64 && pspec->maximum == G_MAXINT64)
1187 desc = g_strdup ("");
1188 else if (pspec->minimum == G_MININT64)
1189 desc = g_strdup_printf ("<= %s", upper);
1190 else if (pspec->maximum == G_MAXINT64)
1191 desc = g_strdup_printf (">= %s", lower);
1193 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1197 else if (G_IS_PARAM_SPEC_UINT64 (spec))
1199 GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
1201 lower = describe_unsigned_constant (sizeof(guint64), pspec->minimum);
1202 upper = describe_unsigned_constant (sizeof(guint64), pspec->maximum);
1203 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT64)
1204 desc = g_strdup ("");
1205 else if (pspec->minimum == 0)
1206 desc = g_strdup_printf ("<= %s", upper);
1207 else if (pspec->maximum == G_MAXUINT64)
1208 desc = g_strdup_printf (">= %s", lower);
1210 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1214 else if (G_IS_PARAM_SPEC_FLOAT (spec))
1216 GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
1218 lower = describe_double_constant (pspec->minimum);
1219 upper = describe_double_constant (pspec->maximum);
1220 if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXFLOAT))
1222 if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
1223 desc = g_strdup ("");
1225 desc = g_strdup_printf ("<= %s", upper);
1227 else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
1228 desc = g_strdup_printf (">= %s", lower);
1230 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1234 else if (G_IS_PARAM_SPEC_DOUBLE (spec))
1236 GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
1238 lower = describe_double_constant (pspec->minimum);
1239 upper = describe_double_constant (pspec->maximum);
1240 if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXDOUBLE))
1242 if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
1243 desc = g_strdup ("");
1245 desc = g_strdup_printf ("<= %s", upper);
1247 else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
1248 desc = g_strdup_printf (">= %s", lower);
1250 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1254 #if GLIB_CHECK_VERSION (2, 12, 0)
1255 else if (G_IS_PARAM_SPEC_GTYPE (spec))
1257 GParamSpecGType *pspec = G_PARAM_SPEC_GTYPE (spec);
1258 gboolean is_pointer;
1260 desc = g_strdup (get_type_name (pspec->is_a_type, &is_pointer));
1263 #if GLIB_CHECK_VERSION (2, 25, 9)
1264 else if (G_IS_PARAM_SPEC_VARIANT (spec))
1266 GParamSpecVariant *pspec = G_PARAM_SPEC_VARIANT (spec);
1267 gchar *variant_type;
1269 variant_type = g_variant_type_dup_string (pspec->type);
1270 desc = g_strdup_printf ("GVariant<%s>", variant_type);
1271 g_free (variant_type);
1276 desc = g_strdup ("");
1283 describe_default (GParamSpec *spec)
1287 if (G_IS_PARAM_SPEC_CHAR (spec))
1289 GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
1291 desc = g_strdup_printf ("%d", pspec->default_value);
1293 else if (G_IS_PARAM_SPEC_UCHAR (spec))
1295 GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
1297 desc = g_strdup_printf ("%u", pspec->default_value);
1299 else if (G_IS_PARAM_SPEC_BOOLEAN (spec))
1301 GParamSpecBoolean *pspec = G_PARAM_SPEC_BOOLEAN (spec);
1303 desc = g_strdup_printf ("%s", pspec->default_value ? "TRUE" : "FALSE");
1305 else if (G_IS_PARAM_SPEC_INT (spec))
1307 GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
1309 desc = g_strdup_printf ("%d", pspec->default_value);
1311 else if (G_IS_PARAM_SPEC_UINT (spec))
1313 GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
1315 desc = g_strdup_printf ("%u", pspec->default_value);
1317 else if (G_IS_PARAM_SPEC_LONG (spec))
1319 GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
1321 desc = g_strdup_printf ("%ld", pspec->default_value);
1323 else if (G_IS_PARAM_SPEC_LONG (spec))
1325 GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
1327 desc = g_strdup_printf ("%lu", pspec->default_value);
1329 else if (G_IS_PARAM_SPEC_INT64 (spec))
1331 GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
1333 desc = g_strdup_printf ("%" G_GINT64_FORMAT, pspec->default_value);
1335 else if (G_IS_PARAM_SPEC_UINT64 (spec))
1337 GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
1339 desc = g_strdup_printf ("%" G_GUINT64_FORMAT, pspec->default_value);
1341 else if (G_IS_PARAM_SPEC_UNICHAR (spec))
1343 GParamSpecUnichar *pspec = G_PARAM_SPEC_UNICHAR (spec);
1345 if (g_unichar_isprint (pspec->default_value))
1346 desc = g_strdup_printf ("'%c'", pspec->default_value);
1348 desc = g_strdup_printf ("%u", pspec->default_value);
1350 else if (G_IS_PARAM_SPEC_ENUM (spec))
1352 GParamSpecEnum *pspec = G_PARAM_SPEC_ENUM (spec);
1354 GEnumValue *value = g_enum_get_value (pspec->enum_class, pspec->default_value);
1356 desc = g_strdup_printf ("%s", value->value_name);
1358 desc = g_strdup_printf ("%d", pspec->default_value);
1360 else if (G_IS_PARAM_SPEC_FLAGS (spec))
1362 GParamSpecFlags *pspec = G_PARAM_SPEC_FLAGS (spec);
1363 guint default_value;
1366 default_value = pspec->default_value;
1367 acc = g_string_new ("");
1369 while (default_value)
1371 GFlagsValue *value = g_flags_get_first_value (pspec->flags_class, default_value);
1377 g_string_append (acc, "|");
1378 g_string_append (acc, value->value_name);
1380 default_value &= ~value->value;
1383 if (default_value == 0)
1384 desc = g_string_free (acc, FALSE);
1387 desc = g_strdup_printf ("%d", pspec->default_value);
1388 g_string_free (acc, TRUE);
1391 else if (G_IS_PARAM_SPEC_FLOAT (spec))
1393 GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
1395 /* make sure floats are output with a decimal dot irrespective of
1396 * current locale. Use formatd since we want human-readable numbers
1397 * and do not need the exact same bit representation when deserialising */
1398 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
1399 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
1400 pspec->default_value);
1402 else if (G_IS_PARAM_SPEC_DOUBLE (spec))
1404 GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
1406 /* make sure floats are output with a decimal dot irrespective of
1407 * current locale. Use formatd since we want human-readable numbers
1408 * and do not need the exact same bit representation when deserialising */
1409 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
1410 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
1411 pspec->default_value);
1413 else if (G_IS_PARAM_SPEC_STRING (spec))
1415 GParamSpecString *pspec = G_PARAM_SPEC_STRING (spec);
1417 if (pspec->default_value)
1419 gchar *esc = g_strescape (pspec->default_value, NULL);
1421 desc = g_strdup_printf ("\\"%s\\"", esc);
1426 desc = g_strdup_printf ("NULL");
1430 desc = g_strdup ("");
1438 output_object_args (FILE *fp, GType object_type)
1441 const gchar *object_class_name;
1443 gchar flags[16], *pos;
1444 GParamSpec **properties;
1446 gboolean child_prop;
1447 gboolean style_prop;
1448 gboolean is_pointer;
1449 const gchar *type_name;
1451 gchar *default_value;
1453 if (G_TYPE_IS_OBJECT (object_type))
1455 class = g_type_class_peek (object_type);
1459 properties = g_object_class_list_properties (class, &n_properties);
1461 #if GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 3)
1462 else if (G_TYPE_IS_INTERFACE (object_type))
1464 class = g_type_default_interface_ref (object_type);
1469 properties = g_object_interface_list_properties (class, &n_properties);
1475 object_class_name = g_type_name (object_type);
1481 qsort (properties, n_properties, sizeof (GParamSpec *), compare_param_specs);
1482 for (arg = 0; arg < n_properties; arg++)
1484 GParamSpec *spec = properties[arg];
1485 const gchar *nick, *blurb, *dot;
1487 if (spec->owner_type != object_type)
1491 /* We use one-character flags for simplicity. */
1492 if (child_prop && !style_prop)
1496 if (spec->flags & G_PARAM_READABLE)
1498 if (spec->flags & G_PARAM_WRITABLE)
1500 if (spec->flags & G_PARAM_CONSTRUCT)
1502 if (spec->flags & G_PARAM_CONSTRUCT_ONLY)
1506 nick = g_param_spec_get_nick (spec);
1507 blurb = g_param_spec_get_blurb (spec);
1511 int str_len = strlen (blurb);
1512 if (str_len > 0 && blurb[str_len - 1] != '.')
1516 type_desc = describe_type (spec);
1517 default_value = describe_default (spec);
1518 type_name = get_type_name (spec->value_type, &is_pointer);
1519 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",
1520 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);
1522 g_free (default_value);
1525 g_free (properties);
1527 #ifdef GTK_IS_CONTAINER_CLASS
1528 if (!child_prop && GTK_IS_CONTAINER_CLASS (class)) {
1529 properties = gtk_container_class_list_child_properties (class, &n_properties);
1535 #ifdef GTK_IS_CELL_AREA_CLASS
1536 if (!child_prop && GTK_IS_CELL_AREA_CLASS (class)) {
1537 properties = gtk_cell_area_class_list_cell_properties (class, &n_properties);
1543 #ifdef GTK_IS_WIDGET_CLASS
1544 #if GTK_CHECK_VERSION(2,1,0)
1545 if (!style_prop && GTK_IS_WIDGET_CLASS (class)) {
1546 properties = gtk_widget_class_list_style_properties (GTK_WIDGET_CLASS (class), &n_properties);
1560 # Compile and run our file
1562 $CC = $ENV{CC} ? $ENV{CC} : "gcc";
1563 $LD = $ENV{LD} ? $ENV{LD} : $CC;
1564 $CFLAGS = $ENV{CFLAGS} ? "$ENV{CFLAGS}" : "";
1565 $LDFLAGS = $ENV{LDFLAGS} ? $ENV{LDFLAGS} : "";
1568 if ($CC =~ /libtool/) {
1569 $o_file = "$MODULE-scan.lo"
1571 $o_file = "$MODULE-scan.o"
1575 if (!defined($VERBOSE) or $VERBOSE eq "0") {
1576 $stdout=">/dev/null";
1580 $command = "$CC $stdout $CFLAGS -c -o $o_file $MODULE-scan.c";
1581 system("($command)") == 0 or die "Compilation of scanner failed: $!\n";
1584 $command = "$LD $stdout -o $MODULE-scan $o_file $LDFLAGS";
1585 system($command) == 0 or die "Linking of scanner failed: $!\n";
1587 # Running scanner $MODULE-scan ";
1588 system("sh -c ./$MODULE-scan") == 0 or die "Scan failed: $!\n";
1590 if (!defined($ENV{"GTK_DOC_KEEP_INTERMEDIATE"})) {
1591 unlink "./$MODULE-scan.c", "./$MODULE-scan.o", "./$MODULE-scan.lo", "./$MODULE-scan";
1594 &UpdateFileIfChanged ($old_hierarchy_filename, $new_hierarchy_filename, 0);
1595 # we will merge these in scangobj-merge.py
1596 #&UpdateFileIfChanged ($old_interfaces_filename, $new_interfaces_filename, 0);
1597 #&UpdateFileIfChanged ($old_prerequisites_filename, $new_prerequisites_filename, 0);
1598 #&UpdateFileIfChanged ($old_signals_filename, $new_signals_filename, 0);
1599 #&UpdateFileIfChanged ($old_args_filename, $new_args_filename, 0);