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 return strcmp (((GstPluginFeature *)a)->name, ((GstPluginFeature *)b)->name);
189 static_pad_template_compare (gconstpointer a, gconstpointer b)
191 GstStaticPadTemplate *spt_a = (GstStaticPadTemplate *) a;
192 GstStaticPadTemplate *spt_b = (GstStaticPadTemplate *) b;
194 /* we want SINK before SRC (enum is UNKNOWN, SRC, SINK) */
195 if (spt_a->direction != spt_b->direction)
196 return spt_b->direction - spt_a->direction;
198 /* we want ALWAYS first, SOMETIMES second, REQUEST last
199 * (enum is ALWAYS, SOMETIMES, REQUEST) */
200 if (spt_a->presence != spt_b->presence)
201 return spt_a->presence - spt_b->presence;
203 return strcmp (spt_a->name_template, spt_b->name_template);
207 get_object_types (void)
209 gpointer g_object_class;
210 GList *plugins = NULL;
211 GList *factories = NULL;
213 GstElementFactory *factory = NULL;
218 /* get a list of features from plugins in our source module */
219 plugins = gst_registry_get_plugin_list (gst_registry_get_default());
221 xmlstr = g_string_new ("");
223 reinspect = !g_file_test ("scanobj-build.stamp", G_FILE_TEST_EXISTS);
229 FILE *inspect = NULL;
232 plugin = (GstPlugin *) (plugins->data);
233 plugins = g_list_next (plugins);
234 source = gst_plugin_get_source (plugin);
235 if (!source || strcmp (source, "$SOURCE") != 0) {
239 /* skip static coreelements plugin with pipeline and bin element factory */
240 if (gst_plugin_get_filename (plugin) == NULL)
243 $debug_log ("plugin: %s source: %s", plugin->desc.name, source);
246 inspect_name = g_strdup_printf ("$INSPECT_DIR" G_DIR_SEPARATOR_S "plugin-%s.xml",
248 inspect = fopen (inspect_name, "w");
249 if (inspect == NULL) {
250 g_error ("Could not open %s for writing: %s\\n", inspect_name,
253 g_free (inspect_name);
255 /* output plugin data */
256 fputs ("<plugin>\\n",inspect);
257 fputs (xmlprint(2, "name", plugin->desc.name),inspect);
258 fputs (xmlprint(2, "description", plugin->desc.description),inspect);
259 fputs (xmlprint(2, "filename", plugin->filename),inspect);
260 fputs (xmlprint(2, "basename", plugin->basename),inspect);
261 fputs (xmlprint(2, "version", plugin->desc.version),inspect);
262 fputs (xmlprint(2, "license", plugin->desc.license),inspect);
263 fputs (xmlprint(2, "source", plugin->desc.source),inspect);
264 fputs (xmlprint(2, "package", plugin->desc.package),inspect);
265 fputs (xmlprint(2, "origin", plugin->desc.origin),inspect);
266 fputs (" <elements>\\n", inspect);
270 gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
273 /* sort factories by feature->name */
274 features = g_list_sort (features, gst_feature_sort_compare);
277 GstPluginFeature *feature;
278 feature = GST_PLUGIN_FEATURE (features->data);
279 feature = gst_plugin_feature_load (feature);
281 g_warning ("Could not load plugin feature %s",
282 gst_plugin_feature_get_name (feature));
285 if (GST_IS_ELEMENT_FACTORY (feature)) {
286 const gchar *pad_dir[] = { "unknown","source","sink" };
287 const gchar *pad_pres[] = { "always","sometimes","request" };
290 $debug_log (" feature: %s", feature->name);
292 factory = GST_ELEMENT_FACTORY (feature);
293 factories = g_list_prepend (factories, factory);
296 /* output element data */
297 fputs (" <element>\\n", inspect);
298 fputs (xmlprint(6, "name", feature->name),inspect);
299 fputs (xmlprint(6, "longname", gst_element_factory_get_longname (factory)),inspect);
300 fputs (xmlprint(6, "class", gst_element_factory_get_klass (factory)),inspect);
301 fputs (xmlprint(6, "description", gst_element_factory_get_description (factory)),inspect);
302 fputs (xmlprint(6, "author", gst_element_factory_get_author (factory)),inspect);
303 fputs (" <pads>\\n", inspect);
305 /* output pad-template data */
306 pads = g_list_copy ((GList *) gst_element_factory_get_static_pad_templates (factory));
307 pads = g_list_sort (pads, static_pad_template_compare);
308 for (pad = pads; pad != NULL; pad = pad->next) {
309 GstStaticPadTemplate *pt = pad->data;
311 fputs (" <caps>\\n", inspect);
312 fputs (xmlprint(10, "name", pt->name_template),inspect);
313 fputs (xmlprint(10, "direction", pad_dir[pt->direction]),inspect);
314 fputs (xmlprint(10, "presence", pad_pres[pt->presence]),inspect);
315 fputs (xmlprint(10, "details", pt->static_caps.string),inspect);
316 fputs (" </caps>\\n", inspect);
319 fputs (" </pads>\\n </element>\\n", inspect);
322 features = g_list_next (features);
326 fputs (" </elements>\\n</plugin>", inspect);
331 g_string_free (xmlstr, TRUE);
333 $debug_log ("number of element factories: %d", g_list_length (factories));
335 /* allocate the object_types array to hold them */
336 object_types = g_new0 (GType, g_list_length (factories)+$ntypes+1);
343 factory = GST_ELEMENT_FACTORY (l->data);
344 type = gst_element_factory_get_element_type (factory);
346 $debug_log ("adding type for factory %s", gst_element_factory_get_longname (factory));
347 object_types[i++] = type;
349 g_message ("type info for factory %s not found",
350 gst_element_factory_get_longname (factory));
357 # get_type functions:
362 g_message ("$_ () didn't return a valid type");
365 object_types[i++] = type;
370 # Implicit types retrieved from GLib:
373 type = g_type_from_name ("$_");
375 g_message ("Implicit type $_ not found");
378 object_types[i++] = type;
387 /* reference the GObjectClass to initialize the param spec pool
388 * potentially needed by interfaces. See http://bugs.gnome.org/571820 */
389 g_object_class = g_type_class_ref (G_TYPE_OBJECT);
391 /* Need to make sure all the types are loaded in and initialize
392 * their signals and properties.
394 for (i=0; object_types[i]; i++)
396 if (G_TYPE_IS_CLASSED (object_types[i]))
397 g_type_class_ref (object_types[i]);
398 if (G_TYPE_IS_INTERFACE (object_types[i]))
399 g_type_default_interface_ref (object_types[i]);
402 g_type_class_unref (g_object_class);
408 * This uses GObject type functions to output signal prototypes and the object
412 /* The output files */
413 const gchar *signals_filename = "$new_signals_filename";
414 const gchar *hierarchy_filename = "$new_hierarchy_filename";
415 const gchar *interfaces_filename = "$new_interfaces_filename";
416 const gchar *prerequisites_filename = "$new_prerequisites_filename";
417 const gchar *args_filename = "$new_args_filename";
420 static void output_signals (void);
421 static void output_object_signals (FILE *fp,
423 static void output_object_signal (FILE *fp,
424 const gchar *object_class_name,
426 static const gchar * get_type_name (GType type,
427 gboolean * is_pointer);
428 static void output_object_hierarchy (void);
429 static void output_hierarchy (FILE *fp,
433 static void output_object_interfaces (void);
434 static void output_interfaces (FILE *fp,
437 static void output_interface_prerequisites (void);
438 static void output_prerequisites (FILE *fp,
441 static void output_args (void);
442 static void output_object_args (FILE *fp, GType object_type);
445 main (int argc, char *argv[])
447 /* Silence the compiler: */
448 if (argv != argv) argc = argc;
455 output_object_hierarchy ();
456 output_object_interfaces ();
457 output_interface_prerequisites ();
465 output_signals (void)
470 fp = fopen (signals_filename, "w");
473 g_warning ("Couldn't open output file: %s : %s", signals_filename, g_strerror(errno));
477 for (i = 0; object_types[i]; i++)
478 output_object_signals (fp, object_types[i]);
484 compare_signals (const void *a, const void *b)
486 const guint *signal_a = a;
487 const guint *signal_b = b;
489 return strcmp (g_signal_name (*signal_a), g_signal_name (*signal_b));
492 /* This outputs all the signals of one object. */
494 output_object_signals (FILE *fp, GType object_type)
496 const gchar *object_class_name;
497 guint *signals, n_signals;
500 if (G_TYPE_IS_INSTANTIATABLE (object_type) ||
501 G_TYPE_IS_INTERFACE (object_type))
504 object_class_name = g_type_name (object_type);
506 signals = g_signal_list_ids (object_type, &n_signals);
507 qsort (signals, n_signals, sizeof (guint), compare_signals);
509 for (sig = 0; sig < n_signals; sig++)
511 output_object_signal (fp, object_class_name, signals[sig]);
518 /* This outputs one signal. */
520 output_object_signal (FILE *fp,
521 const gchar *object_name,
524 GSignalQuery query_info;
525 const gchar *type_name, *ret_type, *object_arg, *arg_name;
526 gchar *pos, *object_arg_lower;
530 gint param_num, widget_num, event_num, callback_num;
532 gchar signal_name[128];
535 $debug_log ("Object: %s Signal: %u", object_name, signal_id);
538 widget_num = event_num = callback_num = 0;
540 g_signal_query (signal_id, &query_info);
542 /* Output the signal object type and the argument name. We assume the
543 type is a pointer - I think that is OK. We remove "Gtk" or "Gnome" and
544 convert to lower case for the argument name. */
546 sprintf (pos, "%s ", object_name);
549 /* Try to come up with a sensible variable name for the first arg
550 * It chops off 2 know prefixes :/ and makes the name lowercase
551 * It should replace lowercase -> uppercase with '_'
552 * GFileMonitor -> file_monitor
553 * GIOExtensionPoint -> extension_point
554 * GtkTreeView -> tree_view
555 * if 2nd char is upper case too
556 * search for first lower case and go back one char
558 * search for next upper case
560 if (!strncmp (object_name, "Gtk", 3))
561 object_arg = object_name + 3;
562 else if (!strncmp (object_name, "Gnome", 5))
563 object_arg = object_name + 5;
565 object_arg = object_name;
567 object_arg_lower = g_ascii_strdown (object_arg, -1);
568 sprintf (pos, "*%s\\n", object_arg_lower);
570 if (!strncmp (object_arg_lower, "widget", 6))
572 g_free(object_arg_lower);
574 /* Convert signal name to use underscores rather than dashes '-'. */
575 strncpy (signal_name, query_info.signal_name, 127);
576 signal_name[127] = '\\0';
577 for (i = 0; signal_name[i]; i++)
579 if (signal_name[i] == '-')
580 signal_name[i] = '_';
583 /* Output the signal parameters. */
584 for (param = 0; param < query_info.n_params; param++)
586 type_name = get_type_name (query_info.param_types[param] & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
588 /* Most arguments to the callback are called "arg1", "arg2", etc.
589 GtkWidgets are called "widget", "widget2", ...
590 GtkCallbacks are called "callback", "callback2", ... */
591 if (!strcmp (type_name, "GtkWidget"))
594 arg_num = &widget_num;
596 else if (!strcmp (type_name, "GtkCallback")
597 || !strcmp (type_name, "GtkCCallback"))
599 arg_name = "callback";
600 arg_num = &callback_num;
605 arg_num = ¶m_num;
607 sprintf (pos, "%s ", type_name);
610 if (!arg_num || *arg_num == 0)
611 sprintf (pos, "%s%s\\n", is_pointer ? "*" : " ", arg_name);
613 sprintf (pos, "%s%s%i\\n", is_pointer ? "*" : " ", arg_name,
627 /* We use one-character flags for simplicity. */
628 if (query_info.signal_flags & G_SIGNAL_RUN_FIRST)
630 if (query_info.signal_flags & G_SIGNAL_RUN_LAST)
632 if (query_info.signal_flags & G_SIGNAL_RUN_CLEANUP)
634 if (query_info.signal_flags & G_SIGNAL_NO_RECURSE)
636 if (query_info.signal_flags & G_SIGNAL_DETAILED)
638 if (query_info.signal_flags & G_SIGNAL_ACTION)
640 if (query_info.signal_flags & G_SIGNAL_NO_HOOKS)
644 /* Output the return type and function name. */
645 ret_type = get_type_name (query_info.return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
648 "<SIGNAL>\\n<NAME>%s::%s</NAME>\\n<RETURNS>%s%s</RETURNS>\\n<FLAGS>%s</FLAGS>\\n%s</SIGNAL>\\n\\n",
649 object_name, query_info.signal_name, ret_type, is_pointer ? "*" : "", flags, buffer);
653 /* Returns the type name to use for a signal argument or return value, given
654 the GtkType from the signal info. It also sets is_pointer to TRUE if the
655 argument needs a '*' since it is a pointer. */
657 get_type_name (GType type, gboolean * is_pointer)
659 const gchar *type_name;
662 type_name = g_type_name (type);
676 /* These all have normal C type names so they are OK. */
680 /* A GtkString is really a gchar*. */
686 /* We use a gint for both of these. Hopefully a subtype with a decent
687 name will be registered and used instead, as GTK+ does itself. */
691 /* The boxed type shouldn't be used itself, only subtypes. Though we
692 return 'gpointer' just in case. */
696 /* A GParam is really a GParamSpec*. */
700 #if GLIB_CHECK_VERSION (2, 25, 9)
710 /* For all GObject subclasses we can use the class name with a "*",
711 e.g. 'GtkWidget *'. */
712 if (g_type_is_a (type, G_TYPE_OBJECT))
715 /* Also catch non GObject root types */
716 if (G_TYPE_IS_CLASSED (type))
719 /* All boxed subtypes will be pointers as well. */
720 /* Exception: GStrv */
721 if (g_type_is_a (type, G_TYPE_BOXED) &&
722 !g_type_is_a (type, G_TYPE_STRV))
725 /* All pointer subtypes will be pointers as well. */
726 if (g_type_is_a (type, G_TYPE_POINTER))
729 /* But enums are not */
730 if (g_type_is_a (type, G_TYPE_ENUM) ||
731 g_type_is_a (type, G_TYPE_FLAGS))
738 /* This outputs the hierarchy of all objects which have been initialized,
739 i.e. by calling their XXX_get_type() initialization function. */
741 output_object_hierarchy (void)
746 GType root_types[$ntypes] = { G_TYPE_INVALID, };
748 fp = fopen (hierarchy_filename, "w");
751 g_warning ("Couldn't open output file: %s : %s", hierarchy_filename, g_strerror(errno));
754 output_hierarchy (fp, G_TYPE_OBJECT, 0);
755 output_hierarchy (fp, G_TYPE_INTERFACE, 0);
757 for (i=0; object_types[i]; i++) {
758 root = object_types[i];
759 while ((type = g_type_parent (root))) {
762 if ((root != G_TYPE_OBJECT) && (root != G_TYPE_INTERFACE)) {
763 for (j=0; root_types[j]; j++) {
764 if (root == root_types[j]) {
765 root = G_TYPE_INVALID; break;
769 root_types[j] = root;
770 output_hierarchy (fp, root, 0);
779 compare_types (const void *a, const void *b)
781 const char *na = g_type_name (*((GType *)a));
782 const char *nb = g_type_name (*((GType *)b));
784 return g_strcmp0 (na, nb);
788 /* This is called recursively to output the hierarchy of a object. */
790 output_hierarchy (FILE *fp,
801 for (i = 0; i < level; i++)
803 fprintf (fp, "%s\\n", g_type_name (type));
805 children = g_type_children (type, &n_children);
806 qsort (children, n_children, sizeof (GType), compare_types);
809 for (i=0; i < n_children; i++)
810 output_hierarchy (fp, children[i], level + 1);
815 static void output_object_interfaces (void)
820 fp = fopen (interfaces_filename, "w");
823 g_warning ("Couldn't open output file: %s : %s", interfaces_filename, g_strerror(errno));
826 output_interfaces (fp, G_TYPE_OBJECT);
828 for (i = 0; object_types[i]; i++)
830 if (!g_type_parent (object_types[i]) &&
831 (object_types[i] != G_TYPE_OBJECT) &&
832 G_TYPE_IS_INSTANTIATABLE (object_types[i]))
834 output_interfaces (fp, object_types[i]);
841 output_interfaces (FILE *fp,
845 GType *children, *interfaces;
846 guint n_children, n_interfaces;
851 interfaces = g_type_interfaces (type, &n_interfaces);
853 if (n_interfaces > 0)
855 fprintf (fp, "%s", g_type_name (type));
856 for (i=0; i < n_interfaces; i++)
857 fprintf (fp, " %s", g_type_name (interfaces[i]));
862 children = g_type_children (type, &n_children);
864 for (i=0; i < n_children; i++)
865 output_interfaces (fp, children[i]);
870 static void output_interface_prerequisites (void)
874 fp = fopen (prerequisites_filename, "w");
877 g_warning ("Couldn't open output file: %s : %s", prerequisites_filename, g_strerror(errno));
880 output_prerequisites (fp, G_TYPE_INTERFACE);
885 output_prerequisites (FILE *fp,
888 #if GLIB_CHECK_VERSION(2,1,0)
890 GType *children, *prerequisites;
891 guint n_children, n_prerequisites;
896 prerequisites = g_type_interface_prerequisites (type, &n_prerequisites);
898 if (n_prerequisites > 0)
900 fprintf (fp, "%s", g_type_name (type));
901 for (i=0; i < n_prerequisites; i++)
902 fprintf (fp, " %s", g_type_name (prerequisites[i]));
905 g_free (prerequisites);
907 children = g_type_children (type, &n_children);
909 for (i=0; i < n_children; i++)
910 output_prerequisites (fp, children[i]);
922 fp = fopen (args_filename, "w");
925 g_warning ("Couldn't open output file: %s : %s", args_filename, g_strerror(errno));
929 for (i = 0; object_types[i]; i++) {
930 output_object_args (fp, object_types[i]);
937 compare_param_specs (const void *a, const void *b)
939 GParamSpec *spec_a = *(GParamSpec **)a;
940 GParamSpec *spec_b = *(GParamSpec **)b;
942 return strcmp (g_param_spec_get_name (spec_a), g_param_spec_get_name (spec_b));
945 /* Its common to have unsigned properties restricted
946 * to the signed range. Therefore we make this look
947 * a bit nicer by spelling out the max constants.
950 /* Don't use "==" with floats, it might trigger a gcc warning. */
951 #define GTKDOC_COMPARE_FLOAT(x, y) (x <= y && x >= y)
954 describe_double_constant (gdouble value)
958 if (GTKDOC_COMPARE_FLOAT (value, G_MAXDOUBLE))
959 desc = g_strdup ("G_MAXDOUBLE");
960 else if (GTKDOC_COMPARE_FLOAT (value, G_MINDOUBLE))
961 desc = g_strdup ("G_MINDOUBLE");
962 else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXDOUBLE))
963 desc = g_strdup ("-G_MAXDOUBLE");
964 else if (GTKDOC_COMPARE_FLOAT (value, G_MAXFLOAT))
965 desc = g_strdup ("G_MAXFLOAT");
966 else if (GTKDOC_COMPARE_FLOAT (value, G_MINFLOAT))
967 desc = g_strdup ("G_MINFLOAT");
968 else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXFLOAT))
969 desc = g_strdup ("-G_MAXFLOAT");
971 /* make sure floats are output with a decimal dot irrespective of
972 * current locale. Use formatd since we want human-readable numbers
973 * and do not need the exact same bit representation when deserialising */
974 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
975 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g", value);
982 describe_signed_constant (gsize size, gint64 value)
988 if (value == G_MAXINT64)
989 desc = g_strdup ("G_MAXINT64");
990 else if (value == G_MININT64)
991 desc = g_strdup ("G_MININT64");
994 if (sizeof (int) == 4) {
995 if (value == G_MAXINT)
996 desc = g_strdup ("G_MAXINT");
997 else if (value == G_MININT)
998 desc = g_strdup ("G_MININT");
999 else if (value == (gint64)G_MAXUINT)
1000 desc = g_strdup ("G_MAXUINT");
1002 if (value == G_MAXLONG)
1003 desc = g_strdup ("G_MAXLONG");
1004 else if (value == G_MINLONG)
1005 desc = g_strdup ("G_MINLONG");
1006 else if (value == (gint64)G_MAXULONG)
1007 desc = g_strdup ("G_MAXULONG");
1010 if (sizeof (int) == 2) {
1011 if (value == G_MAXINT)
1012 desc = g_strdup ("G_MAXINT");
1013 else if (value == G_MININT)
1014 desc = g_strdup ("G_MININT");
1015 else if (value == (gint64)G_MAXUINT)
1016 desc = g_strdup ("G_MAXUINT");
1023 desc = g_strdup_printf ("%" G_GINT64_FORMAT, value);
1029 describe_unsigned_constant (gsize size, guint64 value)
1035 if (value == G_MAXINT64)
1036 desc = g_strdup ("G_MAXINT64");
1037 else if (value == G_MAXUINT64)
1038 desc = g_strdup ("G_MAXUINT64");
1041 if (sizeof (int) == 4) {
1042 if (value == (guint64)G_MAXINT)
1043 desc = g_strdup ("G_MAXINT");
1044 else if (value == G_MAXUINT)
1045 desc = g_strdup ("G_MAXUINT");
1047 if (value == (guint64)G_MAXLONG)
1048 desc = g_strdup ("G_MAXLONG");
1049 else if (value == G_MAXULONG)
1050 desc = g_strdup ("G_MAXULONG");
1053 if (sizeof (int) == 2) {
1054 if (value == (guint64)G_MAXINT)
1055 desc = g_strdup ("G_MAXINT");
1056 else if (value == G_MAXUINT)
1057 desc = g_strdup ("G_MAXUINT");
1064 desc = g_strdup_printf ("%" G_GUINT64_FORMAT, value);
1070 describe_type (GParamSpec *spec)
1076 if (G_IS_PARAM_SPEC_CHAR (spec))
1078 GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
1080 lower = describe_signed_constant (sizeof(gchar), pspec->minimum);
1081 upper = describe_signed_constant (sizeof(gchar), pspec->maximum);
1082 if (pspec->minimum == G_MININT8 && pspec->maximum == G_MAXINT8)
1083 desc = g_strdup ("");
1084 else if (pspec->minimum == G_MININT8)
1085 desc = g_strdup_printf ("<= %s", upper);
1086 else if (pspec->maximum == G_MAXINT8)
1087 desc = g_strdup_printf (">= %s", lower);
1089 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1093 else if (G_IS_PARAM_SPEC_UCHAR (spec))
1095 GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
1097 lower = describe_unsigned_constant (sizeof(guchar), pspec->minimum);
1098 upper = describe_unsigned_constant (sizeof(guchar), pspec->maximum);
1099 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT8)
1100 desc = g_strdup ("");
1101 else if (pspec->minimum == 0)
1102 desc = g_strdup_printf ("<= %s", upper);
1103 else if (pspec->maximum == G_MAXUINT8)
1104 desc = g_strdup_printf (">= %s", lower);
1106 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1110 else if (G_IS_PARAM_SPEC_INT (spec))
1112 GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
1114 lower = describe_signed_constant (sizeof(gint), pspec->minimum);
1115 upper = describe_signed_constant (sizeof(gint), pspec->maximum);
1116 if (pspec->minimum == G_MININT && pspec->maximum == G_MAXINT)
1117 desc = g_strdup ("");
1118 else if (pspec->minimum == G_MININT)
1119 desc = g_strdup_printf ("<= %s", upper);
1120 else if (pspec->maximum == G_MAXINT)
1121 desc = g_strdup_printf (">= %s", lower);
1123 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1127 else if (G_IS_PARAM_SPEC_UINT (spec))
1129 GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
1131 lower = describe_unsigned_constant (sizeof(guint), pspec->minimum);
1132 upper = describe_unsigned_constant (sizeof(guint), pspec->maximum);
1133 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT)
1134 desc = g_strdup ("");
1135 else if (pspec->minimum == 0)
1136 desc = g_strdup_printf ("<= %s", upper);
1137 else if (pspec->maximum == G_MAXUINT)
1138 desc = g_strdup_printf (">= %s", lower);
1140 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1144 else if (G_IS_PARAM_SPEC_LONG (spec))
1146 GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
1148 lower = describe_signed_constant (sizeof(glong), pspec->minimum);
1149 upper = describe_signed_constant (sizeof(glong), pspec->maximum);
1150 if (pspec->minimum == G_MINLONG && pspec->maximum == G_MAXLONG)
1151 desc = g_strdup ("");
1152 else if (pspec->minimum == G_MINLONG)
1153 desc = g_strdup_printf ("<= %s", upper);
1154 else if (pspec->maximum == G_MAXLONG)
1155 desc = g_strdup_printf (">= %s", lower);
1157 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1161 else if (G_IS_PARAM_SPEC_ULONG (spec))
1163 GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
1165 lower = describe_unsigned_constant (sizeof(gulong), pspec->minimum);
1166 upper = describe_unsigned_constant (sizeof(gulong), pspec->maximum);
1167 if (pspec->minimum == 0 && pspec->maximum == G_MAXULONG)
1168 desc = g_strdup ("");
1169 else if (pspec->minimum == 0)
1170 desc = g_strdup_printf ("<= %s", upper);
1171 else if (pspec->maximum == G_MAXULONG)
1172 desc = g_strdup_printf (">= %s", lower);
1174 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1178 else if (G_IS_PARAM_SPEC_INT64 (spec))
1180 GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
1182 lower = describe_signed_constant (sizeof(gint64), pspec->minimum);
1183 upper = describe_signed_constant (sizeof(gint64), pspec->maximum);
1184 if (pspec->minimum == G_MININT64 && pspec->maximum == G_MAXINT64)
1185 desc = g_strdup ("");
1186 else if (pspec->minimum == G_MININT64)
1187 desc = g_strdup_printf ("<= %s", upper);
1188 else if (pspec->maximum == G_MAXINT64)
1189 desc = g_strdup_printf (">= %s", lower);
1191 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1195 else if (G_IS_PARAM_SPEC_UINT64 (spec))
1197 GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
1199 lower = describe_unsigned_constant (sizeof(guint64), pspec->minimum);
1200 upper = describe_unsigned_constant (sizeof(guint64), pspec->maximum);
1201 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT64)
1202 desc = g_strdup ("");
1203 else if (pspec->minimum == 0)
1204 desc = g_strdup_printf ("<= %s", upper);
1205 else if (pspec->maximum == G_MAXUINT64)
1206 desc = g_strdup_printf (">= %s", lower);
1208 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1212 else if (G_IS_PARAM_SPEC_FLOAT (spec))
1214 GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
1216 lower = describe_double_constant (pspec->minimum);
1217 upper = describe_double_constant (pspec->maximum);
1218 if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXFLOAT))
1220 if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
1221 desc = g_strdup ("");
1223 desc = g_strdup_printf ("<= %s", upper);
1225 else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
1226 desc = g_strdup_printf (">= %s", lower);
1228 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1232 else if (G_IS_PARAM_SPEC_DOUBLE (spec))
1234 GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
1236 lower = describe_double_constant (pspec->minimum);
1237 upper = describe_double_constant (pspec->maximum);
1238 if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXDOUBLE))
1240 if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
1241 desc = g_strdup ("");
1243 desc = g_strdup_printf ("<= %s", upper);
1245 else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
1246 desc = g_strdup_printf (">= %s", lower);
1248 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1252 #if GLIB_CHECK_VERSION (2, 12, 0)
1253 else if (G_IS_PARAM_SPEC_GTYPE (spec))
1255 GParamSpecGType *pspec = G_PARAM_SPEC_GTYPE (spec);
1256 gboolean is_pointer;
1258 desc = g_strdup (get_type_name (pspec->is_a_type, &is_pointer));
1261 #if GLIB_CHECK_VERSION (2, 25, 9)
1262 else if (G_IS_PARAM_SPEC_VARIANT (spec))
1264 GParamSpecVariant *pspec = G_PARAM_SPEC_VARIANT (spec);
1265 gchar *variant_type;
1267 variant_type = g_variant_type_dup_string (pspec->type);
1268 desc = g_strdup_printf ("GVariant<%s>", variant_type);
1269 g_free (variant_type);
1274 desc = g_strdup ("");
1281 describe_default (GParamSpec *spec)
1285 if (G_IS_PARAM_SPEC_CHAR (spec))
1287 GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
1289 desc = g_strdup_printf ("%d", pspec->default_value);
1291 else if (G_IS_PARAM_SPEC_UCHAR (spec))
1293 GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
1295 desc = g_strdup_printf ("%u", pspec->default_value);
1297 else if (G_IS_PARAM_SPEC_BOOLEAN (spec))
1299 GParamSpecBoolean *pspec = G_PARAM_SPEC_BOOLEAN (spec);
1301 desc = g_strdup_printf ("%s", pspec->default_value ? "TRUE" : "FALSE");
1303 else if (G_IS_PARAM_SPEC_INT (spec))
1305 GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
1307 desc = g_strdup_printf ("%d", pspec->default_value);
1309 else if (G_IS_PARAM_SPEC_UINT (spec))
1311 GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
1313 desc = g_strdup_printf ("%u", pspec->default_value);
1315 else if (G_IS_PARAM_SPEC_LONG (spec))
1317 GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
1319 desc = g_strdup_printf ("%ld", pspec->default_value);
1321 else if (G_IS_PARAM_SPEC_LONG (spec))
1323 GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
1325 desc = g_strdup_printf ("%lu", pspec->default_value);
1327 else if (G_IS_PARAM_SPEC_INT64 (spec))
1329 GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
1331 desc = g_strdup_printf ("%" G_GINT64_FORMAT, pspec->default_value);
1333 else if (G_IS_PARAM_SPEC_UINT64 (spec))
1335 GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
1337 desc = g_strdup_printf ("%" G_GUINT64_FORMAT, pspec->default_value);
1339 else if (G_IS_PARAM_SPEC_UNICHAR (spec))
1341 GParamSpecUnichar *pspec = G_PARAM_SPEC_UNICHAR (spec);
1343 if (g_unichar_isprint (pspec->default_value))
1344 desc = g_strdup_printf ("'%c'", pspec->default_value);
1346 desc = g_strdup_printf ("%u", pspec->default_value);
1348 else if (G_IS_PARAM_SPEC_ENUM (spec))
1350 GParamSpecEnum *pspec = G_PARAM_SPEC_ENUM (spec);
1352 GEnumValue *value = g_enum_get_value (pspec->enum_class, pspec->default_value);
1354 desc = g_strdup_printf ("%s", value->value_name);
1356 desc = g_strdup_printf ("%d", pspec->default_value);
1358 else if (G_IS_PARAM_SPEC_FLAGS (spec))
1360 GParamSpecFlags *pspec = G_PARAM_SPEC_FLAGS (spec);
1361 guint default_value;
1364 default_value = pspec->default_value;
1365 acc = g_string_new ("");
1367 while (default_value)
1369 GFlagsValue *value = g_flags_get_first_value (pspec->flags_class, default_value);
1375 g_string_append (acc, "|");
1376 g_string_append (acc, value->value_name);
1378 default_value &= ~value->value;
1381 if (default_value == 0)
1382 desc = g_string_free (acc, FALSE);
1385 desc = g_strdup_printf ("%d", pspec->default_value);
1386 g_string_free (acc, TRUE);
1389 else if (G_IS_PARAM_SPEC_FLOAT (spec))
1391 GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
1393 /* make sure floats are output with a decimal dot irrespective of
1394 * current locale. Use formatd since we want human-readable numbers
1395 * and do not need the exact same bit representation when deserialising */
1396 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
1397 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
1398 pspec->default_value);
1400 else if (G_IS_PARAM_SPEC_DOUBLE (spec))
1402 GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (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_STRING (spec))
1413 GParamSpecString *pspec = G_PARAM_SPEC_STRING (spec);
1415 if (pspec->default_value)
1417 gchar *esc = g_strescape (pspec->default_value, NULL);
1419 desc = g_strdup_printf ("\\"%s\\"", esc);
1424 desc = g_strdup_printf ("NULL");
1428 desc = g_strdup ("");
1436 output_object_args (FILE *fp, GType object_type)
1439 const gchar *object_class_name;
1441 gchar flags[16], *pos;
1442 GParamSpec **properties;
1444 gboolean child_prop;
1445 gboolean style_prop;
1446 gboolean is_pointer;
1447 const gchar *type_name;
1449 gchar *default_value;
1451 if (G_TYPE_IS_OBJECT (object_type))
1453 class = g_type_class_peek (object_type);
1457 properties = g_object_class_list_properties (class, &n_properties);
1459 #if GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 3)
1460 else if (G_TYPE_IS_INTERFACE (object_type))
1462 class = g_type_default_interface_ref (object_type);
1467 properties = g_object_interface_list_properties (class, &n_properties);
1473 object_class_name = g_type_name (object_type);
1479 qsort (properties, n_properties, sizeof (GParamSpec *), compare_param_specs);
1480 for (arg = 0; arg < n_properties; arg++)
1482 GParamSpec *spec = properties[arg];
1483 const gchar *nick, *blurb, *dot;
1485 if (spec->owner_type != object_type)
1489 /* We use one-character flags for simplicity. */
1490 if (child_prop && !style_prop)
1494 if (spec->flags & G_PARAM_READABLE)
1496 if (spec->flags & G_PARAM_WRITABLE)
1498 if (spec->flags & G_PARAM_CONSTRUCT)
1500 if (spec->flags & G_PARAM_CONSTRUCT_ONLY)
1504 nick = g_param_spec_get_nick (spec);
1505 blurb = g_param_spec_get_blurb (spec);
1509 int str_len = strlen (blurb);
1510 if (str_len > 0 && blurb[str_len - 1] != '.')
1514 type_desc = describe_type (spec);
1515 default_value = describe_default (spec);
1516 type_name = get_type_name (spec->value_type, &is_pointer);
1517 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",
1518 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);
1520 g_free (default_value);
1523 g_free (properties);
1525 #ifdef GTK_IS_CONTAINER_CLASS
1526 if (!child_prop && GTK_IS_CONTAINER_CLASS (class)) {
1527 properties = gtk_container_class_list_child_properties (class, &n_properties);
1533 #ifdef GTK_IS_CELL_AREA_CLASS
1534 if (!child_prop && GTK_IS_CELL_AREA_CLASS (class)) {
1535 properties = gtk_cell_area_class_list_cell_properties (class, &n_properties);
1541 #ifdef GTK_IS_WIDGET_CLASS
1542 #if GTK_CHECK_VERSION(2,1,0)
1543 if (!style_prop && GTK_IS_WIDGET_CLASS (class)) {
1544 properties = gtk_widget_class_list_style_properties (GTK_WIDGET_CLASS (class), &n_properties);
1558 # Compile and run our file
1560 $CC = $ENV{CC} ? $ENV{CC} : "gcc";
1561 $LD = $ENV{LD} ? $ENV{LD} : $CC;
1562 $CFLAGS = $ENV{CFLAGS} ? "$ENV{CFLAGS}" : "";
1563 $LDFLAGS = $ENV{LDFLAGS} ? $ENV{LDFLAGS} : "";
1566 if ($CC =~ /libtool/) {
1567 $o_file = "$MODULE-scan.lo"
1569 $o_file = "$MODULE-scan.o"
1573 if (!defined($VERBOSE) or $VERBOSE eq "0") {
1574 $stdout=">/dev/null";
1578 $command = "$CC $stdout $CFLAGS -c -o $o_file $MODULE-scan.c";
1579 system("($command)") == 0 or die "Compilation of scanner failed: $!\n";
1582 $command = "$LD $stdout -o $MODULE-scan $o_file $LDFLAGS";
1583 system($command) == 0 or die "Linking of scanner failed: $!\n";
1585 # Running scanner $MODULE-scan ";
1586 system("sh -c ./$MODULE-scan") == 0 or die "Scan failed: $!\n";
1588 if (!defined($ENV{"GTK_DOC_KEEP_INTERMEDIATE"})) {
1589 unlink "./$MODULE-scan.c", "./$MODULE-scan.o", "./$MODULE-scan.lo", "./$MODULE-scan";
1592 &UpdateFileIfChanged ($old_hierarchy_filename, $new_hierarchy_filename, 0);
1593 # we will merge these in scangobj-merge.py
1594 #&UpdateFileIfChanged ($old_interfaces_filename, $new_interfaces_filename, 0);
1595 #&UpdateFileIfChanged ($old_prerequisites_filename, $new_prerequisites_filename, 0);
1596 #&UpdateFileIfChanged ($old_signals_filename, $new_signals_filename, 0);
1597 #&UpdateFileIfChanged ($old_args_filename, $new_args_filename, 0);