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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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;
146 /* file generated by common/gstdoc-scangobj */
155 #ifdef GTK_IS_WIDGET_CLASS
156 #include <gtk/gtkversion.h>
159 static GType *object_types = NULL;
161 static GString *xmlstr = NULL;
164 xmlprint (gint indent, const gchar *tag, const gchar *data)
166 const gchar indent_str[] = " ";
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);
176 s = g_markup_escape_text (data, -1);
177 g_string_append (xmlstr, s);
181 g_string_append_printf (xmlstr, "</%s>\\n", tag);
186 gst_feature_sort_compare (gconstpointer a, gconstpointer b)
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);
194 static_pad_template_compare (gconstpointer a, gconstpointer b)
196 GstStaticPadTemplate *spt_a = (GstStaticPadTemplate *) a;
197 GstStaticPadTemplate *spt_b = (GstStaticPadTemplate *) b;
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;
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;
208 return strcmp (spt_a->name_template, spt_b->name_template);
212 get_object_types (void)
214 gpointer g_object_class;
215 GList *plugins = NULL;
216 GList *factories = NULL;
218 GstElementFactory *factory = NULL;
223 /* get a list of features from plugins in our source module */
224 plugins = gst_registry_get_plugin_list (gst_registry_get ());
226 xmlstr = g_string_new ("");
228 reinspect = !g_file_test ("scanobj-build.stamp", G_FILE_TEST_EXISTS);
234 FILE *inspect = NULL;
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) {
244 /* skip static coreelements plugin with pipeline and bin element factory */
245 if (gst_plugin_get_filename (plugin) == NULL)
248 $debug_log ("plugin: %s source: %s", gst_plugin_get_name (plugin), source);
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,
260 g_free (inspect_name);
262 basename = g_path_get_basename (gst_plugin_get_filename (plugin));
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);
281 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
282 gst_plugin_get_name (plugin));
284 /* sort factories by feature->name */
285 features = g_list_sort (features, gst_feature_sort_compare);
288 GstPluginFeature *feature;
289 feature = GST_PLUGIN_FEATURE (features->data);
290 feature = gst_plugin_feature_load (feature);
292 g_warning ("Could not load plugin feature %s",
293 gst_plugin_feature_get_name (feature));
296 if (GST_IS_ELEMENT_FACTORY (feature)) {
297 const gchar *pad_dir[] = { "unknown","source","sink" };
298 const gchar *pad_pres[] = { "always","sometimes","request" };
301 $debug_log (" feature: %s", gst_plugin_feature_get_name (feature));
303 factory = GST_ELEMENT_FACTORY (feature);
304 factories = g_list_prepend (factories, factory);
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);
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;
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);
330 fputs (" </pads>\\n </element>\\n", inspect);
333 features = g_list_next (features);
337 fputs (" </elements>\\n</plugin>", inspect);
342 g_string_free (xmlstr, TRUE);
344 $debug_log ("number of element factories: %d", g_list_length (factories));
346 /* allocate the object_types array to hold them */
347 object_types = g_new0 (GType, g_list_length (factories)+$ntypes+1);
354 factory = GST_ELEMENT_FACTORY (l->data);
355 type = gst_element_factory_get_element_type (factory);
357 $debug_log ("adding type for factory %s", gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_LONGNAME));
358 object_types[i++] = type;
360 g_message ("type info for factory %s not found",
361 gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_LONGNAME));
368 # get_type functions:
373 g_message ("$_ () didn't return a valid type");
376 object_types[i++] = type;
381 # Implicit types retrieved from GLib:
384 type = g_type_from_name ("$_");
386 g_message ("Implicit type $_ not found");
389 object_types[i++] = type;
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);
402 /* Need to make sure all the types are loaded in and initialize
403 * their signals and properties.
405 for (i=0; object_types[i]; i++)
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]);
413 g_type_class_unref (g_object_class);
419 * This uses GObject type functions to output signal prototypes and the object
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";
431 static void output_signals (void);
432 static void output_object_signals (FILE *fp,
434 static void output_object_signal (FILE *fp,
435 const gchar *object_class_name,
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,
444 static void output_object_interfaces (void);
445 static void output_interfaces (FILE *fp,
448 static void output_interface_prerequisites (void);
449 static void output_prerequisites (FILE *fp,
452 static void output_args (void);
453 static void output_object_args (FILE *fp, GType object_type);
456 main (int argc, char *argv[])
458 /* Silence the compiler: */
459 if (argv != argv) argc = argc;
466 output_object_hierarchy ();
467 output_object_interfaces ();
468 output_interface_prerequisites ();
476 output_signals (void)
481 fp = fopen (signals_filename, "w");
484 g_warning ("Couldn't open output file: %s : %s", signals_filename, g_strerror(errno));
488 for (i = 0; object_types[i]; i++)
489 output_object_signals (fp, object_types[i]);
495 compare_signals (const void *a, const void *b)
497 const guint *signal_a = a;
498 const guint *signal_b = b;
500 return strcmp (g_signal_name (*signal_a), g_signal_name (*signal_b));
503 /* This outputs all the signals of one object. */
505 output_object_signals (FILE *fp, GType object_type)
507 const gchar *object_class_name;
508 guint *signals, n_signals;
511 if (G_TYPE_IS_INSTANTIATABLE (object_type) ||
512 G_TYPE_IS_INTERFACE (object_type))
515 object_class_name = g_type_name (object_type);
517 signals = g_signal_list_ids (object_type, &n_signals);
518 qsort (signals, n_signals, sizeof (guint), compare_signals);
520 for (sig = 0; sig < n_signals; sig++)
522 output_object_signal (fp, object_class_name, signals[sig]);
529 /* This outputs one signal. */
531 output_object_signal (FILE *fp,
532 const gchar *object_name,
535 GSignalQuery query_info;
536 const gchar *type_name, *ret_type, *object_arg, *arg_name;
537 gchar *pos, *object_arg_lower;
541 gint param_num, widget_num, event_num, callback_num;
543 gchar signal_name[128];
546 $debug_log ("Object: %s Signal: %u", object_name, signal_id);
549 widget_num = event_num = callback_num = 0;
551 g_signal_query (signal_id, &query_info);
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. */
557 sprintf (pos, "%s ", object_name);
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
569 * search for next upper case
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;
576 object_arg = object_name;
578 object_arg_lower = g_ascii_strdown (object_arg, -1);
579 sprintf (pos, "*%s\\n", object_arg_lower);
581 if (!strncmp (object_arg_lower, "widget", 6))
583 g_free(object_arg_lower);
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++)
590 if (signal_name[i] == '-')
591 signal_name[i] = '_';
594 /* Output the signal parameters. */
595 for (param = 0; param < query_info.n_params; param++)
597 type_name = get_type_name (query_info.param_types[param] & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
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"))
605 arg_num = &widget_num;
607 else if (!strcmp (type_name, "GtkCallback")
608 || !strcmp (type_name, "GtkCCallback"))
610 arg_name = "callback";
611 arg_num = &callback_num;
616 arg_num = ¶m_num;
618 sprintf (pos, "%s ", type_name);
621 if (!arg_num || *arg_num == 0)
622 sprintf (pos, "%s%s\\n", is_pointer ? "*" : " ", arg_name);
624 sprintf (pos, "%s%s%i\\n", is_pointer ? "*" : " ", arg_name,
638 /* We use one-character flags for simplicity. */
639 if (query_info.signal_flags & G_SIGNAL_RUN_FIRST)
641 if (query_info.signal_flags & G_SIGNAL_RUN_LAST)
643 if (query_info.signal_flags & G_SIGNAL_RUN_CLEANUP)
645 if (query_info.signal_flags & G_SIGNAL_NO_RECURSE)
647 if (query_info.signal_flags & G_SIGNAL_DETAILED)
649 if (query_info.signal_flags & G_SIGNAL_ACTION)
651 if (query_info.signal_flags & G_SIGNAL_NO_HOOKS)
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);
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);
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. */
668 get_type_name (GType type, gboolean * is_pointer)
670 const gchar *type_name;
673 type_name = g_type_name (type);
687 /* These all have normal C type names so they are OK. */
691 /* A GtkString is really a gchar*. */
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. */
702 /* The boxed type shouldn't be used itself, only subtypes. Though we
703 return 'gpointer' just in case. */
707 /* A GParam is really a GParamSpec*. */
711 #if GLIB_CHECK_VERSION (2, 25, 9)
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))
726 /* Also catch non GObject root types */
727 if (G_TYPE_IS_CLASSED (type))
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))
736 /* All pointer subtypes will be pointers as well. */
737 if (g_type_is_a (type, G_TYPE_POINTER))
740 /* But enums are not */
741 if (g_type_is_a (type, G_TYPE_ENUM) ||
742 g_type_is_a (type, G_TYPE_FLAGS))
749 /* This outputs the hierarchy of all objects which have been initialized,
750 i.e. by calling their XXX_get_type() initialization function. */
752 output_object_hierarchy (void)
757 GType root_types[$ntypes] = { G_TYPE_INVALID, };
759 fp = fopen (hierarchy_filename, "w");
762 g_warning ("Couldn't open output file: %s : %s", hierarchy_filename, g_strerror(errno));
765 output_hierarchy (fp, G_TYPE_OBJECT, 0);
766 output_hierarchy (fp, G_TYPE_INTERFACE, 0);
768 for (i=0; object_types[i]; i++) {
769 root = object_types[i];
770 while ((type = g_type_parent (root))) {
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;
780 root_types[j] = root;
781 output_hierarchy (fp, root, 0);
790 compare_types (const void *a, const void *b)
792 const char *na = g_type_name (*((GType *)a));
793 const char *nb = g_type_name (*((GType *)b));
795 return g_strcmp0 (na, nb);
799 /* This is called recursively to output the hierarchy of a object. */
801 output_hierarchy (FILE *fp,
812 for (i = 0; i < level; i++)
814 fprintf (fp, "%s\\n", g_type_name (type));
816 children = g_type_children (type, &n_children);
817 qsort (children, n_children, sizeof (GType), compare_types);
820 for (i=0; i < n_children; i++)
821 output_hierarchy (fp, children[i], level + 1);
826 static void output_object_interfaces (void)
831 fp = fopen (interfaces_filename, "w");
834 g_warning ("Couldn't open output file: %s : %s", interfaces_filename, g_strerror(errno));
837 output_interfaces (fp, G_TYPE_OBJECT);
839 for (i = 0; object_types[i]; i++)
841 if (!g_type_parent (object_types[i]) &&
842 (object_types[i] != G_TYPE_OBJECT) &&
843 G_TYPE_IS_INSTANTIATABLE (object_types[i]))
845 output_interfaces (fp, object_types[i]);
852 output_interfaces (FILE *fp,
856 GType *children, *interfaces;
857 guint n_children, n_interfaces;
862 interfaces = g_type_interfaces (type, &n_interfaces);
864 if (n_interfaces > 0)
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]));
873 children = g_type_children (type, &n_children);
875 for (i=0; i < n_children; i++)
876 output_interfaces (fp, children[i]);
881 static void output_interface_prerequisites (void)
885 fp = fopen (prerequisites_filename, "w");
888 g_warning ("Couldn't open output file: %s : %s", prerequisites_filename, g_strerror(errno));
891 output_prerequisites (fp, G_TYPE_INTERFACE);
896 output_prerequisites (FILE *fp,
899 #if GLIB_CHECK_VERSION(2,1,0)
901 GType *children, *prerequisites;
902 guint n_children, n_prerequisites;
907 prerequisites = g_type_interface_prerequisites (type, &n_prerequisites);
909 if (n_prerequisites > 0)
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]));
916 g_free (prerequisites);
918 children = g_type_children (type, &n_children);
920 for (i=0; i < n_children; i++)
921 output_prerequisites (fp, children[i]);
933 fp = fopen (args_filename, "w");
936 g_warning ("Couldn't open output file: %s : %s", args_filename, g_strerror(errno));
940 for (i = 0; object_types[i]; i++) {
941 output_object_args (fp, object_types[i]);
948 compare_param_specs (const void *a, const void *b)
950 GParamSpec *spec_a = *(GParamSpec **)a;
951 GParamSpec *spec_b = *(GParamSpec **)b;
953 return strcmp (g_param_spec_get_name (spec_a), g_param_spec_get_name (spec_b));
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.
961 /* Don't use "==" with floats, it might trigger a gcc warning. */
962 #define GTKDOC_COMPARE_FLOAT(x, y) (x <= y && x >= y)
965 describe_double_constant (gdouble value)
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");
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);
993 describe_signed_constant (gsize size, gint64 value)
999 if (value == G_MAXINT64)
1000 desc = g_strdup ("G_MAXINT64");
1001 else if (value == G_MININT64)
1002 desc = g_strdup ("G_MININT64");
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");
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");
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");
1034 desc = g_strdup_printf ("%" G_GINT64_FORMAT, value);
1040 describe_unsigned_constant (gsize size, guint64 value)
1046 if (value == G_MAXINT64)
1047 desc = g_strdup ("G_MAXINT64");
1048 else if (value == G_MAXUINT64)
1049 desc = g_strdup ("G_MAXUINT64");
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");
1058 if (value == (guint64)G_MAXLONG)
1059 desc = g_strdup ("G_MAXLONG");
1060 else if (value == G_MAXULONG)
1061 desc = g_strdup ("G_MAXULONG");
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");
1075 desc = g_strdup_printf ("%" G_GUINT64_FORMAT, value);
1081 describe_type (GParamSpec *spec)
1087 if (G_IS_PARAM_SPEC_CHAR (spec))
1089 GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
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);
1100 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1104 else if (G_IS_PARAM_SPEC_UCHAR (spec))
1106 GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
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);
1117 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1121 else if (G_IS_PARAM_SPEC_INT (spec))
1123 GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
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);
1134 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1138 else if (G_IS_PARAM_SPEC_UINT (spec))
1140 GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
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);
1151 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1155 else if (G_IS_PARAM_SPEC_LONG (spec))
1157 GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
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);
1168 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1172 else if (G_IS_PARAM_SPEC_ULONG (spec))
1174 GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
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);
1185 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1189 else if (G_IS_PARAM_SPEC_INT64 (spec))
1191 GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
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);
1202 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1206 else if (G_IS_PARAM_SPEC_UINT64 (spec))
1208 GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
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);
1219 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1223 else if (G_IS_PARAM_SPEC_FLOAT (spec))
1225 GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
1227 lower = describe_double_constant (pspec->minimum);
1228 upper = describe_double_constant (pspec->maximum);
1229 if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXFLOAT))
1231 if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
1232 desc = g_strdup ("");
1234 desc = g_strdup_printf ("<= %s", upper);
1236 else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
1237 desc = g_strdup_printf (">= %s", lower);
1239 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1243 else if (G_IS_PARAM_SPEC_DOUBLE (spec))
1245 GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
1247 lower = describe_double_constant (pspec->minimum);
1248 upper = describe_double_constant (pspec->maximum);
1249 if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXDOUBLE))
1251 if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
1252 desc = g_strdup ("");
1254 desc = g_strdup_printf ("<= %s", upper);
1256 else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
1257 desc = g_strdup_printf (">= %s", lower);
1259 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1263 #if GLIB_CHECK_VERSION (2, 12, 0)
1264 else if (G_IS_PARAM_SPEC_GTYPE (spec))
1266 GParamSpecGType *pspec = G_PARAM_SPEC_GTYPE (spec);
1267 gboolean is_pointer;
1269 desc = g_strdup (get_type_name (pspec->is_a_type, &is_pointer));
1272 #if GLIB_CHECK_VERSION (2, 25, 9)
1273 else if (G_IS_PARAM_SPEC_VARIANT (spec))
1275 GParamSpecVariant *pspec = G_PARAM_SPEC_VARIANT (spec);
1276 gchar *variant_type;
1278 variant_type = g_variant_type_dup_string (pspec->type);
1279 desc = g_strdup_printf ("GVariant<%s>", variant_type);
1280 g_free (variant_type);
1285 desc = g_strdup ("");
1292 describe_default (GParamSpec *spec)
1296 if (G_IS_PARAM_SPEC_CHAR (spec))
1298 GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
1300 desc = g_strdup_printf ("%d", pspec->default_value);
1302 else if (G_IS_PARAM_SPEC_UCHAR (spec))
1304 GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
1306 desc = g_strdup_printf ("%u", pspec->default_value);
1308 else if (G_IS_PARAM_SPEC_BOOLEAN (spec))
1310 GParamSpecBoolean *pspec = G_PARAM_SPEC_BOOLEAN (spec);
1312 desc = g_strdup_printf ("%s", pspec->default_value ? "TRUE" : "FALSE");
1314 else if (G_IS_PARAM_SPEC_INT (spec))
1316 GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
1318 desc = g_strdup_printf ("%d", pspec->default_value);
1320 else if (G_IS_PARAM_SPEC_UINT (spec))
1322 GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
1324 desc = g_strdup_printf ("%u", pspec->default_value);
1326 else if (G_IS_PARAM_SPEC_LONG (spec))
1328 GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
1330 desc = g_strdup_printf ("%ld", pspec->default_value);
1332 else if (G_IS_PARAM_SPEC_LONG (spec))
1334 GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
1336 desc = g_strdup_printf ("%lu", pspec->default_value);
1338 else if (G_IS_PARAM_SPEC_INT64 (spec))
1340 GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
1342 desc = g_strdup_printf ("%" G_GINT64_FORMAT, pspec->default_value);
1344 else if (G_IS_PARAM_SPEC_UINT64 (spec))
1346 GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
1348 desc = g_strdup_printf ("%" G_GUINT64_FORMAT, pspec->default_value);
1350 else if (G_IS_PARAM_SPEC_UNICHAR (spec))
1352 GParamSpecUnichar *pspec = G_PARAM_SPEC_UNICHAR (spec);
1354 if (g_unichar_isprint (pspec->default_value))
1355 desc = g_strdup_printf ("'%c'", pspec->default_value);
1357 desc = g_strdup_printf ("%u", pspec->default_value);
1359 else if (G_IS_PARAM_SPEC_ENUM (spec))
1361 GParamSpecEnum *pspec = G_PARAM_SPEC_ENUM (spec);
1363 GEnumValue *value = g_enum_get_value (pspec->enum_class, pspec->default_value);
1365 desc = g_strdup_printf ("%s", value->value_name);
1367 desc = g_strdup_printf ("%d", pspec->default_value);
1369 else if (G_IS_PARAM_SPEC_FLAGS (spec))
1371 GParamSpecFlags *pspec = G_PARAM_SPEC_FLAGS (spec);
1372 guint default_value;
1375 default_value = pspec->default_value;
1376 acc = g_string_new ("");
1378 while (default_value)
1380 GFlagsValue *value = g_flags_get_first_value (pspec->flags_class, default_value);
1386 g_string_append (acc, "|");
1387 g_string_append (acc, value->value_name);
1389 default_value &= ~value->value;
1392 if (default_value == 0)
1393 desc = g_string_free (acc, FALSE);
1396 desc = g_strdup_printf ("%d", pspec->default_value);
1397 g_string_free (acc, TRUE);
1400 else if (G_IS_PARAM_SPEC_FLOAT (spec))
1402 GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
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);
1411 else if (G_IS_PARAM_SPEC_DOUBLE (spec))
1413 GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
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);
1422 else if (G_IS_PARAM_SPEC_STRING (spec))
1424 GParamSpecString *pspec = G_PARAM_SPEC_STRING (spec);
1426 if (pspec->default_value)
1428 gchar *esc = g_strescape (pspec->default_value, NULL);
1430 desc = g_strdup_printf ("\\"%s\\"", esc);
1435 desc = g_strdup_printf ("NULL");
1439 desc = g_strdup ("");
1447 output_object_args (FILE *fp, GType object_type)
1450 const gchar *object_class_name;
1452 gchar flags[16], *pos;
1453 GParamSpec **properties;
1455 gboolean child_prop;
1456 gboolean style_prop;
1457 gboolean is_pointer;
1458 const gchar *type_name;
1460 gchar *default_value;
1462 if (G_TYPE_IS_OBJECT (object_type))
1464 class = g_type_class_peek (object_type);
1468 properties = g_object_class_list_properties (class, &n_properties);
1470 #if GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 3)
1471 else if (G_TYPE_IS_INTERFACE (object_type))
1473 class = g_type_default_interface_ref (object_type);
1478 properties = g_object_interface_list_properties (class, &n_properties);
1484 object_class_name = g_type_name (object_type);
1490 qsort (properties, n_properties, sizeof (GParamSpec *), compare_param_specs);
1491 for (arg = 0; arg < n_properties; arg++)
1493 GParamSpec *spec = properties[arg];
1494 const gchar *nick, *blurb, *dot;
1496 if (spec->owner_type != object_type)
1500 /* We use one-character flags for simplicity. */
1501 if (child_prop && !style_prop)
1505 if (spec->flags & G_PARAM_READABLE)
1507 if (spec->flags & G_PARAM_WRITABLE)
1509 if (spec->flags & G_PARAM_CONSTRUCT)
1511 if (spec->flags & G_PARAM_CONSTRUCT_ONLY)
1515 nick = g_param_spec_get_nick (spec);
1516 blurb = g_param_spec_get_blurb (spec);
1520 int str_len = strlen (blurb);
1521 if (str_len > 0 && blurb[str_len - 1] != '.')
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);
1531 g_free (default_value);
1534 g_free (properties);
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);
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);
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);
1569 # Compile and run our file
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} : "";
1577 if ($CC =~ /libtool/) {
1578 $o_file = "$MODULE-scan.lo"
1580 $o_file = "$MODULE-scan.o"
1584 if (!defined($VERBOSE) or $VERBOSE eq "0") {
1585 $stdout=">/dev/null";
1589 $command = "$CC $stdout $CFLAGS -c -o $o_file $MODULE-scan.c";
1590 system("($command)") == 0 or die "Compilation of scanner failed: $!\n";
1593 $command = "$LD $stdout -o $MODULE-scan $o_file $LDFLAGS";
1594 system($command) == 0 or die "Linking of scanner failed: $!\n";
1596 # Running scanner $MODULE-scan ";
1597 system("sh -c ./$MODULE-scan") == 0 or die "Scan failed: $!\n";
1599 if (!defined($ENV{"GTK_DOC_KEEP_INTERMEDIATE"})) {
1600 unlink "./$MODULE-scan.c", "./$MODULE-scan.o", "./$MODULE-scan.lo", "./$MODULE-scan";
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);