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 */
157 print OUTPUT $includes;
160 print OUTPUT "extern GType $_ (void);\n";
166 #ifdef GTK_IS_WIDGET_CLASS
167 #include <gtk/gtkversion.h>
170 static GType *object_types = NULL;
172 static GString *xmlstr = NULL;
175 xmlprint (gint indent, const gchar *tag, const gchar *data)
177 const gchar indent_str[] = " ";
180 g_string_truncate (xmlstr, 0);
181 g_string_append_len (xmlstr, indent_str, MIN (indent, strlen (indent_str)));
182 g_string_append_printf (xmlstr, "<%s>", tag);
187 s = g_markup_escape_text (data, -1);
188 g_string_append (xmlstr, s);
192 g_string_append_printf (xmlstr, "</%s>\\n", tag);
197 gst_feature_sort_compare (gconstpointer a, gconstpointer b)
199 const gchar *name_a = gst_plugin_feature_get_name ((GstPluginFeature *) a);
200 const gchar *name_b = gst_plugin_feature_get_name ((GstPluginFeature *) b);
201 return strcmp (name_a, name_b);
205 static_pad_template_compare (gconstpointer a, gconstpointer b)
207 GstStaticPadTemplate *spt_a = (GstStaticPadTemplate *) a;
208 GstStaticPadTemplate *spt_b = (GstStaticPadTemplate *) b;
210 /* we want SINK before SRC (enum is UNKNOWN, SRC, SINK) */
211 if (spt_a->direction != spt_b->direction)
212 return spt_b->direction - spt_a->direction;
214 /* we want ALWAYS first, SOMETIMES second, REQUEST last
215 * (enum is ALWAYS, SOMETIMES, REQUEST) */
216 if (spt_a->presence != spt_b->presence)
217 return spt_a->presence - spt_b->presence;
219 return strcmp (spt_a->name_template, spt_b->name_template);
223 get_object_types (void)
225 gpointer g_object_class;
226 GList *plugins = NULL;
227 GList *factories = NULL;
229 GstElementFactory *factory = NULL;
234 /* get a list of features from plugins in our source module */
235 plugins = gst_registry_get_plugin_list (gst_registry_get ());
237 xmlstr = g_string_new ("");
239 reinspect = !g_file_test ("scanobj-build.stamp", G_FILE_TEST_EXISTS);
245 FILE *inspect = NULL;
248 plugin = (GstPlugin *) (plugins->data);
249 plugins = g_list_next (plugins);
250 source = gst_plugin_get_source (plugin);
251 if (!source || strcmp (source, "$SOURCE") != 0) {
255 /* skip static coreelements plugin with pipeline and bin element factory */
256 if (gst_plugin_get_filename (plugin) == NULL)
259 $debug_log ("plugin: %s source: %s", gst_plugin_get_name (plugin), source);
264 inspect_name = g_strdup_printf ("$INSPECT_DIR" G_DIR_SEPARATOR_S "plugin-%s.xml",
265 gst_plugin_get_name (plugin));
266 inspect = fopen (inspect_name, "w");
267 if (inspect == NULL) {
268 g_error ("Could not open %s for writing: %s\\n", inspect_name,
271 g_free (inspect_name);
273 basename = g_path_get_basename (gst_plugin_get_filename (plugin));
275 /* output plugin data */
276 fputs ("<plugin>\\n",inspect);
277 fputs (xmlprint(2, "name", gst_plugin_get_name (plugin)),inspect);
278 fputs (xmlprint(2, "description", gst_plugin_get_description (plugin)),inspect);
279 fputs (xmlprint(2, "filename", gst_plugin_get_filename (plugin)),inspect);
280 fputs (xmlprint(2, "basename", basename),inspect);
281 fputs (xmlprint(2, "version", gst_plugin_get_version (plugin)),inspect);
282 fputs (xmlprint(2, "license", gst_plugin_get_license (plugin)),inspect);
283 fputs (xmlprint(2, "source", gst_plugin_get_source (plugin)),inspect);
284 fputs (xmlprint(2, "package", gst_plugin_get_package (plugin)),inspect);
285 fputs (xmlprint(2, "origin", gst_plugin_get_origin (plugin)),inspect);
286 fputs (" <elements>\\n", inspect);
292 gst_registry_get_feature_list_by_plugin (gst_registry_get (),
293 gst_plugin_get_name (plugin));
295 /* sort factories by feature->name */
296 features = g_list_sort (features, gst_feature_sort_compare);
299 GstPluginFeature *feature;
300 feature = GST_PLUGIN_FEATURE (features->data);
301 feature = gst_plugin_feature_load (feature);
303 g_warning ("Could not load plugin feature %s",
304 gst_plugin_feature_get_name (feature));
307 if (GST_IS_ELEMENT_FACTORY (feature)) {
308 const gchar *pad_dir[] = { "unknown","source","sink" };
309 const gchar *pad_pres[] = { "always","sometimes","request" };
312 $debug_log (" feature: %s", gst_plugin_feature_get_name (feature));
314 factory = GST_ELEMENT_FACTORY (feature);
315 factories = g_list_prepend (factories, factory);
318 /* output element data */
319 fputs (" <element>\\n", inspect);
320 fputs (xmlprint(6, "name", gst_plugin_feature_get_name (feature)),inspect);
321 fputs (xmlprint(6, "longname", gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_LONGNAME)),inspect);
322 fputs (xmlprint(6, "class", gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS)),inspect);
323 fputs (xmlprint(6, "description", gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_DESCRIPTION)),inspect);
324 fputs (xmlprint(6, "author", gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_AUTHOR)),inspect);
325 fputs (" <pads>\\n", inspect);
327 /* output pad-template data */
328 pads = g_list_copy ((GList *) gst_element_factory_get_static_pad_templates (factory));
329 pads = g_list_sort (pads, static_pad_template_compare);
330 for (pad = pads; pad != NULL; pad = pad->next) {
331 GstStaticPadTemplate *pt = pad->data;
333 fputs (" <caps>\\n", inspect);
334 fputs (xmlprint(10, "name", pt->name_template),inspect);
335 fputs (xmlprint(10, "direction", pad_dir[pt->direction]),inspect);
336 fputs (xmlprint(10, "presence", pad_pres[pt->presence]),inspect);
337 fputs (xmlprint(10, "details", pt->static_caps.string),inspect);
338 fputs (" </caps>\\n", inspect);
341 fputs (" </pads>\\n </element>\\n", inspect);
344 features = g_list_next (features);
348 fputs (" </elements>\\n</plugin>", inspect);
353 g_string_free (xmlstr, TRUE);
355 $debug_log ("number of element factories: %d", g_list_length (factories));
357 /* allocate the object_types array to hold them */
358 object_types = g_new0 (GType, g_list_length (factories)+$ntypes+1);
365 factory = GST_ELEMENT_FACTORY (l->data);
366 type = gst_element_factory_get_element_type (factory);
368 $debug_log ("adding type for factory %s", gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_LONGNAME));
369 object_types[i++] = type;
371 g_message ("type info for factory %s not found",
372 gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_LONGNAME));
379 # get_type functions:
384 g_message ("$_ () didn't return a valid type");
387 object_types[i++] = type;
392 # Implicit types retrieved from GLib:
395 type = g_type_from_name ("$_");
397 g_message ("Implicit type $_ not found");
400 object_types[i++] = type;
409 /* reference the GObjectClass to initialize the param spec pool
410 * potentially needed by interfaces. See http://bugs.gnome.org/571820 */
411 g_object_class = g_type_class_ref (G_TYPE_OBJECT);
413 /* Need to make sure all the types are loaded in and initialize
414 * their signals and properties.
416 for (i=0; object_types[i]; i++)
418 if (G_TYPE_IS_CLASSED (object_types[i]))
419 g_type_class_ref (object_types[i]);
420 if (G_TYPE_IS_INTERFACE (object_types[i]))
421 g_type_default_interface_ref (object_types[i]);
424 g_type_class_unref (g_object_class);
430 * This uses GObject type functions to output signal prototypes and the object
434 /* The output files */
435 const gchar *signals_filename = "$new_signals_filename";
436 const gchar *hierarchy_filename = "$new_hierarchy_filename";
437 const gchar *interfaces_filename = "$new_interfaces_filename";
438 const gchar *prerequisites_filename = "$new_prerequisites_filename";
439 const gchar *args_filename = "$new_args_filename";
442 static void output_signals (void);
443 static void output_object_signals (FILE *fp,
445 static void output_object_signal (FILE *fp,
446 const gchar *object_class_name,
448 static const gchar * get_type_name (GType type,
449 gboolean * is_pointer);
450 static void output_object_hierarchy (void);
451 static void output_hierarchy (FILE *fp,
455 static void output_object_interfaces (void);
456 static void output_interfaces (FILE *fp,
459 static void output_interface_prerequisites (void);
460 static void output_prerequisites (FILE *fp,
463 static void output_args (void);
464 static void output_object_args (FILE *fp, GType object_type);
467 main (G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
474 output_object_hierarchy ();
475 output_object_interfaces ();
476 output_interface_prerequisites ();
484 output_signals (void)
489 fp = fopen (signals_filename, "w");
492 g_warning ("Couldn't open output file: %s : %s", signals_filename, g_strerror(errno));
496 for (i = 0; object_types[i]; i++)
497 output_object_signals (fp, object_types[i]);
503 compare_signals (const void *a, const void *b)
505 const guint *signal_a = a;
506 const guint *signal_b = b;
508 return strcmp (g_signal_name (*signal_a), g_signal_name (*signal_b));
511 /* This outputs all the signals of one object. */
513 output_object_signals (FILE *fp, GType object_type)
515 const gchar *object_class_name;
516 guint *signals, n_signals;
519 if (G_TYPE_IS_INSTANTIATABLE (object_type) ||
520 G_TYPE_IS_INTERFACE (object_type))
523 object_class_name = g_type_name (object_type);
525 signals = g_signal_list_ids (object_type, &n_signals);
526 qsort (signals, n_signals, sizeof (guint), compare_signals);
528 for (sig = 0; sig < n_signals; sig++)
530 output_object_signal (fp, object_class_name, signals[sig]);
537 /* This outputs one signal. */
539 output_object_signal (FILE *fp,
540 const gchar *object_name,
543 GSignalQuery query_info;
544 const gchar *type_name, *ret_type, *object_arg, *arg_name;
545 gchar *pos, *object_arg_lower;
549 gint param_num, widget_num, event_num, callback_num;
551 gchar signal_name[128];
554 $debug_log ("Object: %s Signal: %u", object_name, signal_id);
557 widget_num = event_num = callback_num = 0;
559 g_signal_query (signal_id, &query_info);
561 /* Output the signal object type and the argument name. We assume the
562 type is a pointer - I think that is OK. We remove "Gtk" or "Gnome" and
563 convert to lower case for the argument name. */
565 sprintf (pos, "%s ", object_name);
568 /* Try to come up with a sensible variable name for the first arg
569 * It chops off 2 know prefixes :/ and makes the name lowercase
570 * It should replace lowercase -> uppercase with '_'
571 * GFileMonitor -> file_monitor
572 * GIOExtensionPoint -> extension_point
573 * GtkTreeView -> tree_view
574 * if 2nd char is upper case too
575 * search for first lower case and go back one char
577 * search for next upper case
579 if (!strncmp (object_name, "Gtk", 3))
580 object_arg = object_name + 3;
581 else if (!strncmp (object_name, "Gnome", 5))
582 object_arg = object_name + 5;
584 object_arg = object_name;
586 object_arg_lower = g_ascii_strdown (object_arg, -1);
587 sprintf (pos, "*%s\\n", object_arg_lower);
589 if (!strncmp (object_arg_lower, "widget", 6))
591 g_free(object_arg_lower);
593 /* Convert signal name to use underscores rather than dashes '-'. */
594 strncpy (signal_name, query_info.signal_name, 127);
595 signal_name[127] = '\\0';
596 for (i = 0; signal_name[i]; i++)
598 if (signal_name[i] == '-')
599 signal_name[i] = '_';
602 /* Output the signal parameters. */
603 for (param = 0; param < query_info.n_params; param++)
605 type_name = get_type_name (query_info.param_types[param] & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
607 /* Most arguments to the callback are called "arg1", "arg2", etc.
608 GtkWidgets are called "widget", "widget2", ...
609 GtkCallbacks are called "callback", "callback2", ... */
610 if (!strcmp (type_name, "GtkWidget"))
613 arg_num = &widget_num;
615 else if (!strcmp (type_name, "GtkCallback")
616 || !strcmp (type_name, "GtkCCallback"))
618 arg_name = "callback";
619 arg_num = &callback_num;
624 arg_num = ¶m_num;
626 sprintf (pos, "%s ", type_name);
629 if (!arg_num || *arg_num == 0)
630 sprintf (pos, "%s%s\\n", is_pointer ? "*" : " ", arg_name);
632 sprintf (pos, "%s%s%i\\n", is_pointer ? "*" : " ", arg_name,
646 /* We use one-character flags for simplicity. */
647 if (query_info.signal_flags & G_SIGNAL_RUN_FIRST)
649 if (query_info.signal_flags & G_SIGNAL_RUN_LAST)
651 if (query_info.signal_flags & G_SIGNAL_RUN_CLEANUP)
653 if (query_info.signal_flags & G_SIGNAL_NO_RECURSE)
655 if (query_info.signal_flags & G_SIGNAL_DETAILED)
657 if (query_info.signal_flags & G_SIGNAL_ACTION)
659 if (query_info.signal_flags & G_SIGNAL_NO_HOOKS)
663 /* Output the return type and function name. */
664 ret_type = get_type_name (query_info.return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
667 "<SIGNAL>\\n<NAME>%s::%s</NAME>\\n<RETURNS>%s%s</RETURNS>\\n<FLAGS>%s</FLAGS>\\n%s</SIGNAL>\\n\\n",
668 object_name, query_info.signal_name, ret_type, is_pointer ? "*" : "", flags, buffer);
672 /* Returns the type name to use for a signal argument or return value, given
673 the GtkType from the signal info. It also sets is_pointer to TRUE if the
674 argument needs a '*' since it is a pointer. */
676 get_type_name (GType type, gboolean * is_pointer)
678 const gchar *type_name;
681 type_name = g_type_name (type);
695 /* These all have normal C type names so they are OK. */
699 /* A GtkString is really a gchar*. */
705 /* We use a gint for both of these. Hopefully a subtype with a decent
706 name will be registered and used instead, as GTK+ does itself. */
710 /* The boxed type shouldn't be used itself, only subtypes. Though we
711 return 'gpointer' just in case. */
715 /* A GParam is really a GParamSpec*. */
719 #if GLIB_CHECK_VERSION (2, 25, 9)
729 /* For all GObject subclasses we can use the class name with a "*",
730 e.g. 'GtkWidget *'. */
731 if (g_type_is_a (type, G_TYPE_OBJECT))
734 /* Also catch non GObject root types */
735 if (G_TYPE_IS_CLASSED (type))
738 /* All boxed subtypes will be pointers as well. */
739 /* Exception: GStrv */
740 if (g_type_is_a (type, G_TYPE_BOXED) &&
741 !g_type_is_a (type, G_TYPE_STRV))
744 /* All pointer subtypes will be pointers as well. */
745 if (g_type_is_a (type, G_TYPE_POINTER))
748 /* But enums are not */
749 if (g_type_is_a (type, G_TYPE_ENUM) ||
750 g_type_is_a (type, G_TYPE_FLAGS))
757 /* This outputs the hierarchy of all objects which have been initialized,
758 i.e. by calling their XXX_get_type() initialization function. */
760 output_object_hierarchy (void)
765 GType root_types[$ntypes] = { G_TYPE_INVALID, };
767 fp = fopen (hierarchy_filename, "w");
770 g_warning ("Couldn't open output file: %s : %s", hierarchy_filename, g_strerror(errno));
773 output_hierarchy (fp, G_TYPE_OBJECT, 0);
774 output_hierarchy (fp, G_TYPE_INTERFACE, 0);
776 for (i=0; object_types[i]; i++) {
777 root = object_types[i];
778 while ((type = g_type_parent (root))) {
781 if ((root != G_TYPE_OBJECT) && (root != G_TYPE_INTERFACE)) {
782 for (j=0; root_types[j]; j++) {
783 if (root == root_types[j]) {
784 root = G_TYPE_INVALID; break;
788 root_types[j] = root;
789 output_hierarchy (fp, root, 0);
798 compare_types (const void *a, const void *b)
800 const char *na = g_type_name (*((GType *)a));
801 const char *nb = g_type_name (*((GType *)b));
803 return g_strcmp0 (na, nb);
807 /* This is called recursively to output the hierarchy of a object. */
809 output_hierarchy (FILE *fp,
820 for (i = 0; i < level; i++)
822 fprintf (fp, "%s\\n", g_type_name (type));
824 children = g_type_children (type, &n_children);
825 qsort (children, n_children, sizeof (GType), compare_types);
828 for (i=0; i < n_children; i++)
829 output_hierarchy (fp, children[i], level + 1);
834 static void output_object_interfaces (void)
839 fp = fopen (interfaces_filename, "w");
842 g_warning ("Couldn't open output file: %s : %s", interfaces_filename, g_strerror(errno));
845 output_interfaces (fp, G_TYPE_OBJECT);
847 for (i = 0; object_types[i]; i++)
849 if (!g_type_parent (object_types[i]) &&
850 (object_types[i] != G_TYPE_OBJECT) &&
851 G_TYPE_IS_INSTANTIATABLE (object_types[i]))
853 output_interfaces (fp, object_types[i]);
860 output_interfaces (FILE *fp,
864 GType *children, *interfaces;
865 guint n_children, n_interfaces;
870 interfaces = g_type_interfaces (type, &n_interfaces);
872 if (n_interfaces > 0)
874 fprintf (fp, "%s", g_type_name (type));
875 for (i=0; i < n_interfaces; i++)
876 fprintf (fp, " %s", g_type_name (interfaces[i]));
881 children = g_type_children (type, &n_children);
883 for (i=0; i < n_children; i++)
884 output_interfaces (fp, children[i]);
889 static void output_interface_prerequisites (void)
893 fp = fopen (prerequisites_filename, "w");
896 g_warning ("Couldn't open output file: %s : %s", prerequisites_filename, g_strerror(errno));
899 output_prerequisites (fp, G_TYPE_INTERFACE);
904 output_prerequisites (FILE *fp,
907 #if GLIB_CHECK_VERSION(2,1,0)
909 GType *children, *prerequisites;
910 guint n_children, n_prerequisites;
915 prerequisites = g_type_interface_prerequisites (type, &n_prerequisites);
917 if (n_prerequisites > 0)
919 fprintf (fp, "%s", g_type_name (type));
920 for (i=0; i < n_prerequisites; i++)
921 fprintf (fp, " %s", g_type_name (prerequisites[i]));
924 g_free (prerequisites);
926 children = g_type_children (type, &n_children);
928 for (i=0; i < n_children; i++)
929 output_prerequisites (fp, children[i]);
941 fp = fopen (args_filename, "w");
944 g_warning ("Couldn't open output file: %s : %s", args_filename, g_strerror(errno));
948 for (i = 0; object_types[i]; i++) {
949 output_object_args (fp, object_types[i]);
956 compare_param_specs (const void *a, const void *b)
958 GParamSpec *spec_a = *(GParamSpec **)a;
959 GParamSpec *spec_b = *(GParamSpec **)b;
961 return strcmp (g_param_spec_get_name (spec_a), g_param_spec_get_name (spec_b));
964 /* Its common to have unsigned properties restricted
965 * to the signed range. Therefore we make this look
966 * a bit nicer by spelling out the max constants.
969 /* Don't use "==" with floats, it might trigger a gcc warning. */
970 #define GTKDOC_COMPARE_FLOAT(x, y) (x <= y && x >= y)
973 describe_double_constant (gdouble value)
977 if (GTKDOC_COMPARE_FLOAT (value, G_MAXDOUBLE))
978 desc = g_strdup ("G_MAXDOUBLE");
979 else if (GTKDOC_COMPARE_FLOAT (value, G_MINDOUBLE))
980 desc = g_strdup ("G_MINDOUBLE");
981 else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXDOUBLE))
982 desc = g_strdup ("-G_MAXDOUBLE");
983 else if (GTKDOC_COMPARE_FLOAT (value, G_MAXFLOAT))
984 desc = g_strdup ("G_MAXFLOAT");
985 else if (GTKDOC_COMPARE_FLOAT (value, G_MINFLOAT))
986 desc = g_strdup ("G_MINFLOAT");
987 else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXFLOAT))
988 desc = g_strdup ("-G_MAXFLOAT");
990 /* make sure floats are output with a decimal dot irrespective of
991 * current locale. Use formatd since we want human-readable numbers
992 * and do not need the exact same bit representation when deserialising */
993 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
994 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g", value);
1001 describe_signed_constant (gsize size, gint64 value)
1007 if (value == G_MAXINT64)
1008 desc = g_strdup ("G_MAXINT64");
1009 else if (value == G_MININT64)
1010 desc = g_strdup ("G_MININT64");
1013 if (sizeof (int) == 4) {
1014 if (value == G_MAXINT)
1015 desc = g_strdup ("G_MAXINT");
1016 else if (value == G_MININT)
1017 desc = g_strdup ("G_MININT");
1018 else if (value == (gint64)G_MAXUINT)
1019 desc = g_strdup ("G_MAXUINT");
1021 if (value == G_MAXLONG)
1022 desc = g_strdup ("G_MAXLONG");
1023 else if (value == G_MINLONG)
1024 desc = g_strdup ("G_MINLONG");
1025 else if (value == (gint64)G_MAXULONG)
1026 desc = g_strdup ("G_MAXULONG");
1029 if (sizeof (int) == 2) {
1030 if (value == G_MAXINT)
1031 desc = g_strdup ("G_MAXINT");
1032 else if (value == G_MININT)
1033 desc = g_strdup ("G_MININT");
1034 else if (value == (gint64)G_MAXUINT)
1035 desc = g_strdup ("G_MAXUINT");
1042 desc = g_strdup_printf ("%" G_GINT64_FORMAT, value);
1048 describe_unsigned_constant (gsize size, guint64 value)
1054 if (value == G_MAXINT64)
1055 desc = g_strdup ("G_MAXINT64");
1056 else if (value == G_MAXUINT64)
1057 desc = g_strdup ("G_MAXUINT64");
1060 if (sizeof (int) == 4) {
1061 if (value == (guint64)G_MAXINT)
1062 desc = g_strdup ("G_MAXINT");
1063 else if (value == G_MAXUINT)
1064 desc = g_strdup ("G_MAXUINT");
1066 if (value == (guint64)G_MAXLONG)
1067 desc = g_strdup ("G_MAXLONG");
1068 else if (value == G_MAXULONG)
1069 desc = g_strdup ("G_MAXULONG");
1072 if (sizeof (int) == 2) {
1073 if (value == (guint64)G_MAXINT)
1074 desc = g_strdup ("G_MAXINT");
1075 else if (value == G_MAXUINT)
1076 desc = g_strdup ("G_MAXUINT");
1083 desc = g_strdup_printf ("%" G_GUINT64_FORMAT, value);
1089 describe_type (GParamSpec *spec)
1095 if (G_IS_PARAM_SPEC_CHAR (spec))
1097 GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
1099 lower = describe_signed_constant (sizeof(gchar), pspec->minimum);
1100 upper = describe_signed_constant (sizeof(gchar), pspec->maximum);
1101 if (pspec->minimum == G_MININT8 && pspec->maximum == G_MAXINT8)
1102 desc = g_strdup ("");
1103 else if (pspec->minimum == G_MININT8)
1104 desc = g_strdup_printf ("<= %s", upper);
1105 else if (pspec->maximum == G_MAXINT8)
1106 desc = g_strdup_printf (">= %s", lower);
1108 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1112 else if (G_IS_PARAM_SPEC_UCHAR (spec))
1114 GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
1116 lower = describe_unsigned_constant (sizeof(guchar), pspec->minimum);
1117 upper = describe_unsigned_constant (sizeof(guchar), pspec->maximum);
1118 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT8)
1119 desc = g_strdup ("");
1120 else if (pspec->minimum == 0)
1121 desc = g_strdup_printf ("<= %s", upper);
1122 else if (pspec->maximum == G_MAXUINT8)
1123 desc = g_strdup_printf (">= %s", lower);
1125 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1129 else if (G_IS_PARAM_SPEC_INT (spec))
1131 GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
1133 lower = describe_signed_constant (sizeof(gint), pspec->minimum);
1134 upper = describe_signed_constant (sizeof(gint), pspec->maximum);
1135 if (pspec->minimum == G_MININT && pspec->maximum == G_MAXINT)
1136 desc = g_strdup ("");
1137 else if (pspec->minimum == G_MININT)
1138 desc = g_strdup_printf ("<= %s", upper);
1139 else if (pspec->maximum == G_MAXINT)
1140 desc = g_strdup_printf (">= %s", lower);
1142 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1146 else if (G_IS_PARAM_SPEC_UINT (spec))
1148 GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
1150 lower = describe_unsigned_constant (sizeof(guint), pspec->minimum);
1151 upper = describe_unsigned_constant (sizeof(guint), pspec->maximum);
1152 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT)
1153 desc = g_strdup ("");
1154 else if (pspec->minimum == 0)
1155 desc = g_strdup_printf ("<= %s", upper);
1156 else if (pspec->maximum == G_MAXUINT)
1157 desc = g_strdup_printf (">= %s", lower);
1159 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1163 else if (G_IS_PARAM_SPEC_LONG (spec))
1165 GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
1167 lower = describe_signed_constant (sizeof(glong), pspec->minimum);
1168 upper = describe_signed_constant (sizeof(glong), pspec->maximum);
1169 if (pspec->minimum == G_MINLONG && pspec->maximum == G_MAXLONG)
1170 desc = g_strdup ("");
1171 else if (pspec->minimum == G_MINLONG)
1172 desc = g_strdup_printf ("<= %s", upper);
1173 else if (pspec->maximum == G_MAXLONG)
1174 desc = g_strdup_printf (">= %s", lower);
1176 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1180 else if (G_IS_PARAM_SPEC_ULONG (spec))
1182 GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
1184 lower = describe_unsigned_constant (sizeof(gulong), pspec->minimum);
1185 upper = describe_unsigned_constant (sizeof(gulong), pspec->maximum);
1186 if (pspec->minimum == 0 && pspec->maximum == G_MAXULONG)
1187 desc = g_strdup ("");
1188 else if (pspec->minimum == 0)
1189 desc = g_strdup_printf ("<= %s", upper);
1190 else if (pspec->maximum == G_MAXULONG)
1191 desc = g_strdup_printf (">= %s", lower);
1193 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1197 else if (G_IS_PARAM_SPEC_INT64 (spec))
1199 GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
1201 lower = describe_signed_constant (sizeof(gint64), pspec->minimum);
1202 upper = describe_signed_constant (sizeof(gint64), pspec->maximum);
1203 if (pspec->minimum == G_MININT64 && pspec->maximum == G_MAXINT64)
1204 desc = g_strdup ("");
1205 else if (pspec->minimum == G_MININT64)
1206 desc = g_strdup_printf ("<= %s", upper);
1207 else if (pspec->maximum == G_MAXINT64)
1208 desc = g_strdup_printf (">= %s", lower);
1210 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1214 else if (G_IS_PARAM_SPEC_UINT64 (spec))
1216 GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
1218 lower = describe_unsigned_constant (sizeof(guint64), pspec->minimum);
1219 upper = describe_unsigned_constant (sizeof(guint64), pspec->maximum);
1220 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT64)
1221 desc = g_strdup ("");
1222 else if (pspec->minimum == 0)
1223 desc = g_strdup_printf ("<= %s", upper);
1224 else if (pspec->maximum == G_MAXUINT64)
1225 desc = g_strdup_printf (">= %s", lower);
1227 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1231 else if (G_IS_PARAM_SPEC_FLOAT (spec))
1233 GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
1235 lower = describe_double_constant (pspec->minimum);
1236 upper = describe_double_constant (pspec->maximum);
1237 if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXFLOAT))
1239 if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
1240 desc = g_strdup ("");
1242 desc = g_strdup_printf ("<= %s", upper);
1244 else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
1245 desc = g_strdup_printf (">= %s", lower);
1247 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1251 else if (G_IS_PARAM_SPEC_DOUBLE (spec))
1253 GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
1255 lower = describe_double_constant (pspec->minimum);
1256 upper = describe_double_constant (pspec->maximum);
1257 if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXDOUBLE))
1259 if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
1260 desc = g_strdup ("");
1262 desc = g_strdup_printf ("<= %s", upper);
1264 else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
1265 desc = g_strdup_printf (">= %s", lower);
1267 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1271 #if GLIB_CHECK_VERSION (2, 12, 0)
1272 else if (G_IS_PARAM_SPEC_GTYPE (spec))
1274 GParamSpecGType *pspec = G_PARAM_SPEC_GTYPE (spec);
1275 gboolean is_pointer;
1277 desc = g_strdup (get_type_name (pspec->is_a_type, &is_pointer));
1280 #if GLIB_CHECK_VERSION (2, 25, 9)
1281 else if (G_IS_PARAM_SPEC_VARIANT (spec))
1283 GParamSpecVariant *pspec = G_PARAM_SPEC_VARIANT (spec);
1284 gchar *variant_type;
1286 variant_type = g_variant_type_dup_string (pspec->type);
1287 desc = g_strdup_printf ("GVariant<%s>", variant_type);
1288 g_free (variant_type);
1293 desc = g_strdup ("");
1300 describe_default (GParamSpec *spec)
1304 if (G_IS_PARAM_SPEC_CHAR (spec))
1306 GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
1308 desc = g_strdup_printf ("%d", pspec->default_value);
1310 else if (G_IS_PARAM_SPEC_UCHAR (spec))
1312 GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
1314 desc = g_strdup_printf ("%u", pspec->default_value);
1316 else if (G_IS_PARAM_SPEC_BOOLEAN (spec))
1318 GParamSpecBoolean *pspec = G_PARAM_SPEC_BOOLEAN (spec);
1320 desc = g_strdup_printf ("%s", pspec->default_value ? "TRUE" : "FALSE");
1322 else if (G_IS_PARAM_SPEC_INT (spec))
1324 GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
1326 desc = g_strdup_printf ("%d", pspec->default_value);
1328 else if (G_IS_PARAM_SPEC_UINT (spec))
1330 GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
1332 desc = g_strdup_printf ("%u", pspec->default_value);
1334 else if (G_IS_PARAM_SPEC_LONG (spec))
1336 GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
1338 desc = g_strdup_printf ("%ld", pspec->default_value);
1340 else if (G_IS_PARAM_SPEC_LONG (spec))
1342 GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
1344 desc = g_strdup_printf ("%lu", pspec->default_value);
1346 else if (G_IS_PARAM_SPEC_INT64 (spec))
1348 GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
1350 desc = g_strdup_printf ("%" G_GINT64_FORMAT, pspec->default_value);
1352 else if (G_IS_PARAM_SPEC_UINT64 (spec))
1354 GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
1356 desc = g_strdup_printf ("%" G_GUINT64_FORMAT, pspec->default_value);
1358 else if (G_IS_PARAM_SPEC_UNICHAR (spec))
1360 GParamSpecUnichar *pspec = G_PARAM_SPEC_UNICHAR (spec);
1362 if (g_unichar_isprint (pspec->default_value))
1363 desc = g_strdup_printf ("'%c'", pspec->default_value);
1365 desc = g_strdup_printf ("%u", pspec->default_value);
1367 else if (G_IS_PARAM_SPEC_ENUM (spec))
1369 GParamSpecEnum *pspec = G_PARAM_SPEC_ENUM (spec);
1371 GEnumValue *value = g_enum_get_value (pspec->enum_class, pspec->default_value);
1373 desc = g_strdup_printf ("%s", value->value_name);
1375 desc = g_strdup_printf ("%d", pspec->default_value);
1377 else if (G_IS_PARAM_SPEC_FLAGS (spec))
1379 GParamSpecFlags *pspec = G_PARAM_SPEC_FLAGS (spec);
1380 guint default_value;
1383 default_value = pspec->default_value;
1384 acc = g_string_new ("");
1386 while (default_value)
1388 GFlagsValue *value = g_flags_get_first_value (pspec->flags_class, default_value);
1394 g_string_append (acc, "|");
1395 g_string_append (acc, value->value_name);
1397 default_value &= ~value->value;
1400 if (default_value == 0)
1401 desc = g_string_free (acc, FALSE);
1404 desc = g_strdup_printf ("%d", pspec->default_value);
1405 g_string_free (acc, TRUE);
1408 else if (G_IS_PARAM_SPEC_FLOAT (spec))
1410 GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
1412 /* make sure floats are output with a decimal dot irrespective of
1413 * current locale. Use formatd since we want human-readable numbers
1414 * and do not need the exact same bit representation when deserialising */
1415 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
1416 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
1417 pspec->default_value);
1419 else if (G_IS_PARAM_SPEC_DOUBLE (spec))
1421 GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
1423 /* make sure floats are output with a decimal dot irrespective of
1424 * current locale. Use formatd since we want human-readable numbers
1425 * and do not need the exact same bit representation when deserialising */
1426 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
1427 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
1428 pspec->default_value);
1430 else if (G_IS_PARAM_SPEC_STRING (spec))
1432 GParamSpecString *pspec = G_PARAM_SPEC_STRING (spec);
1434 if (pspec->default_value)
1436 gchar *esc = g_strescape (pspec->default_value, NULL);
1438 desc = g_strdup_printf ("\\"%s\\"", esc);
1443 desc = g_strdup_printf ("NULL");
1447 desc = g_strdup ("");
1455 output_object_args (FILE *fp, GType object_type)
1458 const gchar *object_class_name;
1460 gchar flags[16], *pos;
1461 GParamSpec **properties;
1463 gboolean child_prop;
1464 gboolean style_prop;
1465 gboolean is_pointer;
1466 const gchar *type_name;
1468 gchar *default_value;
1470 if (G_TYPE_IS_OBJECT (object_type))
1472 class = g_type_class_peek (object_type);
1476 properties = g_object_class_list_properties (class, &n_properties);
1478 #if GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 3)
1479 else if (G_TYPE_IS_INTERFACE (object_type))
1481 class = g_type_default_interface_ref (object_type);
1486 properties = g_object_interface_list_properties (class, &n_properties);
1492 object_class_name = g_type_name (object_type);
1498 qsort (properties, n_properties, sizeof (GParamSpec *), compare_param_specs);
1499 for (arg = 0; arg < n_properties; arg++)
1501 GParamSpec *spec = properties[arg];
1502 const gchar *nick, *blurb, *dot;
1504 if (spec->owner_type != object_type)
1508 /* We use one-character flags for simplicity. */
1509 if (child_prop && !style_prop)
1513 if (spec->flags & G_PARAM_READABLE)
1515 if (spec->flags & G_PARAM_WRITABLE)
1517 if (spec->flags & G_PARAM_CONSTRUCT)
1519 if (spec->flags & G_PARAM_CONSTRUCT_ONLY)
1523 nick = g_param_spec_get_nick (spec);
1524 blurb = g_param_spec_get_blurb (spec);
1528 int str_len = strlen (blurb);
1529 if (str_len > 0 && blurb[str_len - 1] != '.')
1533 type_desc = describe_type (spec);
1534 default_value = describe_default (spec);
1535 type_name = get_type_name (spec->value_type, &is_pointer);
1536 fprintf (fp, "<ARG>\\n<NAME>%s::%s</NAME>\\n<TYPE>%s%s</TYPE>\\n<RANGE>%s</RANGE>\\n<FLAGS>%s</FLAGS>\\n<NICK>%s</NICK>\\n<BLURB>%s%s</BLURB>\\n<DEFAULT>%s</DEFAULT>\\n</ARG>\\n\\n",
1537 object_class_name, g_param_spec_get_name (spec), type_name, is_pointer ? "*" : "", type_desc, flags, nick ? nick : "(null)", blurb ? blurb : "(null)", dot, default_value);
1539 g_free (default_value);
1542 g_free (properties);
1544 #ifdef GTK_IS_CONTAINER_CLASS
1545 if (!child_prop && GTK_IS_CONTAINER_CLASS (class)) {
1546 properties = gtk_container_class_list_child_properties (class, &n_properties);
1552 #ifdef GTK_IS_CELL_AREA_CLASS
1553 if (!child_prop && GTK_IS_CELL_AREA_CLASS (class)) {
1554 properties = gtk_cell_area_class_list_cell_properties (class, &n_properties);
1560 #ifdef GTK_IS_WIDGET_CLASS
1561 #if GTK_CHECK_VERSION(2,1,0)
1562 if (!style_prop && GTK_IS_WIDGET_CLASS (class)) {
1563 properties = gtk_widget_class_list_style_properties (GTK_WIDGET_CLASS (class), &n_properties);
1577 # Compile and run our file
1579 $CC = $ENV{CC} ? $ENV{CC} : "gcc";
1580 $LD = $ENV{LD} ? $ENV{LD} : $CC;
1581 $CFLAGS = $ENV{CFLAGS} ? "$ENV{CFLAGS}" : "";
1582 $LDFLAGS = $ENV{LDFLAGS} ? $ENV{LDFLAGS} : "";
1585 if ($CC =~ /libtool/) {
1586 $o_file = "$MODULE-scan.lo"
1588 $o_file = "$MODULE-scan.o"
1592 if (!defined($VERBOSE) or $VERBOSE eq "0") {
1593 $stdout=">/dev/null";
1597 $command = "$CC $stdout $CFLAGS -c -o $o_file $MODULE-scan.c";
1598 system("($command)") == 0 or die "Compilation of scanner failed: $!\n";
1601 $command = "$LD $stdout -o $MODULE-scan $o_file $LDFLAGS";
1602 system($command) == 0 or die "Linking of scanner failed: $!\n";
1604 # Running scanner $MODULE-scan ";
1605 system("sh -c ./$MODULE-scan") == 0 or die "Scan failed: $!\n";
1607 if (!defined($ENV{"GTK_DOC_KEEP_INTERMEDIATE"})) {
1608 unlink "./$MODULE-scan.c", "./$MODULE-scan.o", "./$MODULE-scan.lo", "./$MODULE-scan";
1611 &UpdateFileIfChanged ($old_hierarchy_filename, $new_hierarchy_filename, 0);
1612 # we will merge these in scangobj-merge.py
1613 #&UpdateFileIfChanged ($old_interfaces_filename, $new_interfaces_filename, 0);
1614 #&UpdateFileIfChanged ($old_prerequisites_filename, $new_prerequisites_filename, 0);
1615 #&UpdateFileIfChanged ($old_signals_filename, $new_signals_filename, 0);
1616 #&UpdateFileIfChanged ($old_args_filename, $new_args_filename, 0);