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
48 my $TYPE_INIT_FUNC="g_type_init ()";
50 # --nogtkinit is deprecated, as it is the default now anyway.
51 %optctl = (module => \$MODULE,
53 types => \$TYPES_FILE,
54 nogtkinit => \$NO_GTK_INIT,
55 'type-init-func' => \$TYPE_INIT_FUNC,
56 'output-dir' => \$OUTPUT_DIR,
57 'inspect-dir' => \$INSPECT_DIR,
58 'version' => \$PRINT_VERSION,
59 'help' => \$PRINT_HELP);
61 GetOptions(\%optctl, "module=s", "source=s", "types:s", "output-dir:s", "inspect-dir:s", "nogtkinit", "type-init-func:s", "version", "help");
64 # Do nothing. This just avoids a warning.
65 # the option is not used anymore
78 print "gstdoc-scangobj version 1.5\n";
79 print "\n--module=MODULE_NAME Name of the doc module being parsed";
80 print "\n--source=SOURCE_NAME Name of the source module for plugins";
81 print "\n--types=FILE The name of the file to store the types in";
82 print "\n--type-init-func=FUNC The init function to call instead of g_type_init ()";
83 print "\n--output-dir=DIRNAME The directory where the results are stored";
84 print "\n--inspect-dir=DIRNAME The directory where the plugin inspect data is stored";
85 print "\n--version Print the version of this program";
86 print "\n--help Print this help\n";
90 $OUTPUT_DIR = $OUTPUT_DIR ? $OUTPUT_DIR : ".";
92 $TYPES_FILE = $TYPES_FILE ? $TYPES_FILE : "$OUTPUT_DIR/$MODULE.types";
94 open (TYPES, $TYPES_FILE) || die "Cannot open $TYPES_FILE: $!\n";
95 open (OUTPUT, ">$MODULE-scan.c") || die "Cannot open $MODULE-scan.c: $!\n";
97 my $old_signals_filename = "$OUTPUT_DIR/$MODULE.signals";
98 my $new_signals_filename = "$OUTPUT_DIR/$MODULE.signals.new";
99 my $old_hierarchy_filename = "$OUTPUT_DIR/$MODULE.hierarchy";
100 my $new_hierarchy_filename = "$OUTPUT_DIR/$MODULE.hierarchy.new";
101 my $old_interfaces_filename = "$OUTPUT_DIR/$MODULE.interfaces";
102 my $new_interfaces_filename = "$OUTPUT_DIR/$MODULE.interfaces.new";
103 my $old_prerequisites_filename = "$OUTPUT_DIR/$MODULE.prerequisites";
104 my $new_prerequisites_filename = "$OUTPUT_DIR/$MODULE.prerequisites.new";
105 my $old_args_filename = "$OUTPUT_DIR/$MODULE.args";
106 my $new_args_filename = "$OUTPUT_DIR/$MODULE.args.new";
108 # write a C program to scan the types
121 } elsif (/^type:(.*)$/) {
124 push @impl_types, $t;
131 $ntypes = @types + @impl_types + 1;
141 #ifdef GTK_IS_WIDGET_CLASS
142 #include <gtk/gtkversion.h>
145 static GType *object_types = NULL;
147 static GString *xmlstr = NULL;
150 xmlprint (gint indent, const gchar *tag, const gchar *data)
152 const gchar indent_str[] = " ";
155 g_string_truncate (xmlstr, 0);
156 g_string_append_len (xmlstr, indent_str, MIN (indent, strlen (indent_str)));
157 g_string_append_printf (xmlstr, "<%s>", tag);
162 s = g_markup_escape_text (data, -1);
163 g_string_append (xmlstr, s);
167 g_string_append_printf (xmlstr, "</%s>\\n", tag);
172 gst_feature_sort_compare (gconstpointer a, gconstpointer b)
174 return strcmp (((GstPluginFeature *)a)->name, ((GstPluginFeature *)b)->name);
178 static_pad_template_compare (gconstpointer a, gconstpointer b)
180 GstStaticPadTemplate *spt_a = (GstStaticPadTemplate *) a;
181 GstStaticPadTemplate *spt_b = (GstStaticPadTemplate *) b;
183 /* we want SINK before SRC (enum is UNKNOWN, SRC, SINK) */
184 if (spt_a->direction != spt_b->direction)
185 return spt_b->direction - spt_a->direction;
187 /* we want ALWAYS first, SOMETIMES second, REQUEST last
188 * (enum is ALWAYS, SOMETIMES, REQUEST) */
189 if (spt_a->presence != spt_b->presence)
190 return spt_a->presence - spt_b->presence;
192 return strcmp (spt_a->name_template, spt_b->name_template);
196 get_object_types (void)
198 gpointer g_object_class;
199 GList *plugins = NULL;
200 GList *factories = NULL;
202 GstElementFactory *factory = NULL;
207 /* get a list of features from plugins in our source module */
208 plugins = gst_registry_get_plugin_list (gst_registry_get_default());
210 xmlstr = g_string_new ("");
212 reinspect = !g_file_test ("scanobj-build.stamp", G_FILE_TEST_EXISTS);
218 FILE *inspect = NULL;
221 plugin = (GstPlugin *) (plugins->data);
222 plugins = g_list_next (plugins);
223 source = gst_plugin_get_source (plugin);
224 if (!source || strcmp (source, "$SOURCE") != 0) {
228 /* skip static coreelements plugin with pipeline and bin element factory */
229 if (gst_plugin_get_filename (plugin) == NULL)
232 /*g_message ("plugin: %s source: %s", plugin->desc.name, source);*/
235 inspect_name = g_strdup_printf ("$INSPECT_DIR" G_DIR_SEPARATOR_S "plugin-%s.xml",
237 inspect = fopen (inspect_name, "w");
238 if (inspect == NULL) {
239 g_error ("Could not open %s for writing: %s\\n", inspect_name,
242 g_free (inspect_name);
244 /* output plugin data */
245 fputs ("<plugin>\\n",inspect);
246 fputs (xmlprint(2, "name", plugin->desc.name),inspect);
247 fputs (xmlprint(2, "description", plugin->desc.description),inspect);
248 fputs (xmlprint(2, "filename", plugin->filename),inspect);
249 fputs (xmlprint(2, "basename", plugin->basename),inspect);
250 fputs (xmlprint(2, "version", plugin->desc.version),inspect);
251 fputs (xmlprint(2, "license", plugin->desc.license),inspect);
252 fputs (xmlprint(2, "source", plugin->desc.source),inspect);
253 fputs (xmlprint(2, "package", plugin->desc.package),inspect);
254 fputs (xmlprint(2, "origin", plugin->desc.origin),inspect);
255 fputs (" <elements>\\n", inspect);
259 gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
262 /* sort factories by feature->name */
263 features = g_list_sort (features, gst_feature_sort_compare);
266 GstPluginFeature *feature;
267 feature = GST_PLUGIN_FEATURE (features->data);
268 feature = gst_plugin_feature_load (feature);
270 g_warning ("Could not load plugin feature %s",
271 gst_plugin_feature_get_name (feature));
274 if (GST_IS_ELEMENT_FACTORY (feature)) {
275 const gchar *pad_dir[] = { "unknown","source","sink" };
276 const gchar *pad_pres[] = { "always","sometimes","request" };
279 /*g_message (" feature: %s", feature->name);*/
281 factory = GST_ELEMENT_FACTORY (feature);
282 factories = g_list_prepend (factories, factory);
285 /* output element data */
286 fputs (" <element>\\n", inspect);
287 fputs (xmlprint(6, "name", feature->name),inspect);
288 fputs (xmlprint(6, "longname", gst_element_factory_get_longname (factory)),inspect);
289 fputs (xmlprint(6, "class", gst_element_factory_get_klass (factory)),inspect);
290 fputs (xmlprint(6, "description", gst_element_factory_get_description (factory)),inspect);
291 fputs (xmlprint(6, "author", gst_element_factory_get_author (factory)),inspect);
292 fputs (" <pads>\\n", inspect);
294 /* output pad-template data */
295 pads = g_list_copy ((GList *) gst_element_factory_get_static_pad_templates (factory));
296 pads = g_list_sort (pads, static_pad_template_compare);
297 for (pad = pads; pad != NULL; pad = pad->next) {
298 GstStaticPadTemplate *pt = pad->data;
300 fputs (" <caps>\\n", inspect);
301 fputs (xmlprint(10, "name", pt->name_template),inspect);
302 fputs (xmlprint(10, "direction", pad_dir[pt->direction]),inspect);
303 fputs (xmlprint(10, "presence", pad_pres[pt->presence]),inspect);
304 fputs (xmlprint(10, "details", pt->static_caps.string),inspect);
305 fputs (" </caps>\\n", inspect);
308 fputs (" </pads>\\n </element>\\n", inspect);
311 features = g_list_next (features);
315 fputs (" </elements>\\n</plugin>", inspect);
320 g_string_free (xmlstr, TRUE);
322 g_message ("number of element factories: %d", g_list_length (factories));
324 /* allocate the object_types array to hold them */
325 object_types = g_new0 (GType, g_list_length (factories)+$ntypes+1);
332 factory = GST_ELEMENT_FACTORY (l->data);
333 type = gst_element_factory_get_element_type (factory);
335 /*g_message ("adding type for factory %s", gst_element_factory_get_longname (factory));*/
336 object_types[i++] = type;
338 g_message ("type info for factory %s not found",
339 gst_element_factory_get_longname (factory));
346 # get_type functions:
351 g_message ("$_ () didn't return a valid type");
354 object_types[i++] = type;
359 # Implicit types retrieved from GLib:
362 type = g_type_from_name ("$_");
364 g_message ("Implicit type $_ not found");
367 object_types[i++] = type;
376 /* reference the GObjectClass to initialize the param spec pool
377 * potentially needed by interfaces. See http://bugs.gnome.org/571820 */
378 g_object_class = g_type_class_ref (G_TYPE_OBJECT);
380 /* Need to make sure all the types are loaded in and initialize
381 * their signals and properties.
383 for (i=0; object_types[i]; i++)
385 if (G_TYPE_IS_CLASSED (object_types[i]))
386 g_type_class_ref (object_types[i]);
387 if (G_TYPE_IS_INTERFACE (object_types[i]))
388 g_type_default_interface_ref (object_types[i]);
391 g_type_class_unref (g_object_class);
397 * This uses GObject type functions to output signal prototypes and the object
401 /* The output files */
402 const gchar *signals_filename = "$new_signals_filename";
403 const gchar *hierarchy_filename = "$new_hierarchy_filename";
404 const gchar *interfaces_filename = "$new_interfaces_filename";
405 const gchar *prerequisites_filename = "$new_prerequisites_filename";
406 const gchar *args_filename = "$new_args_filename";
409 static void output_signals (void);
410 static void output_object_signals (FILE *fp,
412 static void output_object_signal (FILE *fp,
413 const gchar *object_class_name,
415 static const gchar * get_type_name (GType type,
416 gboolean * is_pointer);
417 static void output_object_hierarchy (void);
418 static void output_hierarchy (FILE *fp,
422 static void output_object_interfaces (void);
423 static void output_interfaces (FILE *fp,
426 static void output_interface_prerequisites (void);
427 static void output_prerequisites (FILE *fp,
430 static void output_args (void);
431 static void output_object_args (FILE *fp, GType object_type);
434 main (int argc, char *argv[])
436 /* Silence the compiler: */
437 if (argv != argv) argc = argc;
444 output_object_hierarchy ();
445 output_object_interfaces ();
446 output_interface_prerequisites ();
454 output_signals (void)
459 fp = fopen (signals_filename, "w");
462 g_warning ("Couldn't open output file: %s : %s", signals_filename, g_strerror(errno));
466 for (i = 0; object_types[i]; i++)
467 output_object_signals (fp, object_types[i]);
473 compare_signals (const void *a, const void *b)
475 const guint *signal_a = a;
476 const guint *signal_b = b;
478 return strcmp (g_signal_name (*signal_a), g_signal_name (*signal_b));
481 /* This outputs all the signals of one object. */
483 output_object_signals (FILE *fp, GType object_type)
485 const gchar *object_class_name;
486 guint *signals, n_signals;
489 if (G_TYPE_IS_INSTANTIATABLE (object_type) ||
490 G_TYPE_IS_INTERFACE (object_type))
493 object_class_name = g_type_name (object_type);
495 signals = g_signal_list_ids (object_type, &n_signals);
496 qsort (signals, n_signals, sizeof (guint), compare_signals);
498 for (sig = 0; sig < n_signals; sig++)
500 output_object_signal (fp, object_class_name, signals[sig]);
507 /* This outputs one signal. */
509 output_object_signal (FILE *fp,
510 const gchar *object_name,
513 GSignalQuery query_info;
514 const gchar *type_name, *ret_type, *object_arg, *arg_name;
515 gchar *pos, *object_arg_lower;
519 gint param_num, widget_num, event_num, callback_num;
521 gchar signal_name[128];
524 /*g_message ("Object: %s Signal: %u", object_name, signal_id);*/
527 widget_num = event_num = callback_num = 0;
529 g_signal_query (signal_id, &query_info);
531 /* Output the signal object type and the argument name. We assume the
532 type is a pointer - I think that is OK. We remove "Gtk" or "Gnome" and
533 convert to lower case for the argument name. */
535 sprintf (pos, "%s ", object_name);
538 /* Try to come up with a sensible variable name for the first arg
539 * It chops off 2 know prefixes :/ and makes the name lowercase
540 * It should replace lowercase -> uppercase with '_'
541 * GFileMonitor -> file_monitor
542 * GIOExtensionPoint -> extension_point
543 * GtkTreeView -> tree_view
544 * if 2nd char is upper case too
545 * search for first lower case and go back one char
547 * search for next upper case
549 if (!strncmp (object_name, "Gtk", 3))
550 object_arg = object_name + 3;
551 else if (!strncmp (object_name, "Gnome", 5))
552 object_arg = object_name + 5;
554 object_arg = object_name;
556 object_arg_lower = g_ascii_strdown (object_arg, -1);
557 sprintf (pos, "*%s\\n", object_arg_lower);
559 if (!strncmp (object_arg_lower, "widget", 6))
561 g_free(object_arg_lower);
563 /* Convert signal name to use underscores rather than dashes '-'. */
564 strncpy (signal_name, query_info.signal_name, 127);
565 signal_name[127] = '\\0';
566 for (i = 0; signal_name[i]; i++)
568 if (signal_name[i] == '-')
569 signal_name[i] = '_';
572 /* Output the signal parameters. */
573 for (param = 0; param < query_info.n_params; param++)
575 type_name = get_type_name (query_info.param_types[param] & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
577 /* Most arguments to the callback are called "arg1", "arg2", etc.
578 GtkWidgets are called "widget", "widget2", ...
579 GtkCallbacks are called "callback", "callback2", ... */
580 if (!strcmp (type_name, "GtkWidget"))
583 arg_num = &widget_num;
585 else if (!strcmp (type_name, "GtkCallback")
586 || !strcmp (type_name, "GtkCCallback"))
588 arg_name = "callback";
589 arg_num = &callback_num;
594 arg_num = ¶m_num;
596 sprintf (pos, "%s ", type_name);
599 if (!arg_num || *arg_num == 0)
600 sprintf (pos, "%s%s\\n", is_pointer ? "*" : " ", arg_name);
602 sprintf (pos, "%s%s%i\\n", is_pointer ? "*" : " ", arg_name,
616 /* We use one-character flags for simplicity. */
617 if (query_info.signal_flags & G_SIGNAL_RUN_FIRST)
619 if (query_info.signal_flags & G_SIGNAL_RUN_LAST)
621 if (query_info.signal_flags & G_SIGNAL_RUN_CLEANUP)
623 if (query_info.signal_flags & G_SIGNAL_NO_RECURSE)
625 if (query_info.signal_flags & G_SIGNAL_DETAILED)
627 if (query_info.signal_flags & G_SIGNAL_ACTION)
629 if (query_info.signal_flags & G_SIGNAL_NO_HOOKS)
633 /* Output the return type and function name. */
634 ret_type = get_type_name (query_info.return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
637 "<SIGNAL>\\n<NAME>%s::%s</NAME>\\n<RETURNS>%s%s</RETURNS>\\n<FLAGS>%s</FLAGS>\\n%s</SIGNAL>\\n\\n",
638 object_name, query_info.signal_name, ret_type, is_pointer ? "*" : "", flags, buffer);
642 /* Returns the type name to use for a signal argument or return value, given
643 the GtkType from the signal info. It also sets is_pointer to TRUE if the
644 argument needs a '*' since it is a pointer. */
646 get_type_name (GType type, gboolean * is_pointer)
648 const gchar *type_name;
651 type_name = g_type_name (type);
665 /* These all have normal C type names so they are OK. */
669 /* A GtkString is really a gchar*. */
675 /* We use a gint for both of these. Hopefully a subtype with a decent
676 name will be registered and used instead, as GTK+ does itself. */
680 /* The boxed type shouldn't be used itself, only subtypes. Though we
681 return 'gpointer' just in case. */
685 /* A GParam is really a GParamSpec*. */
689 #if GLIB_CHECK_VERSION (2, 25, 9)
699 /* For all GObject subclasses we can use the class name with a "*",
700 e.g. 'GtkWidget *'. */
701 if (g_type_is_a (type, G_TYPE_OBJECT))
704 /* Also catch non GObject root types */
705 if (G_TYPE_IS_CLASSED (type))
708 /* All boxed subtypes will be pointers as well. */
709 /* Exception: GStrv */
710 if (g_type_is_a (type, G_TYPE_BOXED) &&
711 !g_type_is_a (type, G_TYPE_STRV))
714 /* All pointer subtypes will be pointers as well. */
715 if (g_type_is_a (type, G_TYPE_POINTER))
718 /* But enums are not */
719 if (g_type_is_a (type, G_TYPE_ENUM) ||
720 g_type_is_a (type, G_TYPE_FLAGS))
727 /* This outputs the hierarchy of all objects which have been initialized,
728 i.e. by calling their XXX_get_type() initialization function. */
730 output_object_hierarchy (void)
735 GType root_types[$ntypes] = { G_TYPE_INVALID, };
737 fp = fopen (hierarchy_filename, "w");
740 g_warning ("Couldn't open output file: %s : %s", hierarchy_filename, g_strerror(errno));
743 output_hierarchy (fp, G_TYPE_OBJECT, 0);
744 output_hierarchy (fp, G_TYPE_INTERFACE, 0);
746 for (i=0; object_types[i]; i++) {
747 root = object_types[i];
748 while ((type = g_type_parent (root))) {
751 if ((root != G_TYPE_OBJECT) && (root != G_TYPE_INTERFACE)) {
752 for (j=0; root_types[j]; j++) {
753 if (root == root_types[j]) {
754 root = G_TYPE_INVALID; break;
758 root_types[j] = root;
759 output_hierarchy (fp, root, 0);
767 /* This is called recursively to output the hierarchy of a object. */
769 output_hierarchy (FILE *fp,
780 for (i = 0; i < level; i++)
782 fprintf (fp, "%s\\n", g_type_name (type));
784 children = g_type_children (type, &n_children);
786 for (i=0; i < n_children; i++)
787 output_hierarchy (fp, children[i], level + 1);
792 static void output_object_interfaces (void)
797 fp = fopen (interfaces_filename, "w");
800 g_warning ("Couldn't open output file: %s : %s", interfaces_filename, g_strerror(errno));
803 output_interfaces (fp, G_TYPE_OBJECT);
805 for (i = 0; object_types[i]; i++)
807 if (!g_type_parent (object_types[i]) &&
808 (object_types[i] != G_TYPE_OBJECT) &&
809 G_TYPE_IS_INSTANTIATABLE (object_types[i]))
811 output_interfaces (fp, object_types[i]);
818 output_interfaces (FILE *fp,
822 GType *children, *interfaces;
823 guint n_children, n_interfaces;
828 interfaces = g_type_interfaces (type, &n_interfaces);
830 if (n_interfaces > 0)
832 fprintf (fp, "%s", g_type_name (type));
833 for (i=0; i < n_interfaces; i++)
834 fprintf (fp, " %s", g_type_name (interfaces[i]));
839 children = g_type_children (type, &n_children);
841 for (i=0; i < n_children; i++)
842 output_interfaces (fp, children[i]);
847 static void output_interface_prerequisites (void)
851 fp = fopen (prerequisites_filename, "w");
854 g_warning ("Couldn't open output file: %s : %s", prerequisites_filename, g_strerror(errno));
857 output_prerequisites (fp, G_TYPE_INTERFACE);
862 output_prerequisites (FILE *fp,
865 #if GLIB_CHECK_VERSION(2,1,0)
867 GType *children, *prerequisites;
868 guint n_children, n_prerequisites;
873 prerequisites = g_type_interface_prerequisites (type, &n_prerequisites);
875 if (n_prerequisites > 0)
877 fprintf (fp, "%s", g_type_name (type));
878 for (i=0; i < n_prerequisites; i++)
879 fprintf (fp, " %s", g_type_name (prerequisites[i]));
882 g_free (prerequisites);
884 children = g_type_children (type, &n_children);
886 for (i=0; i < n_children; i++)
887 output_prerequisites (fp, children[i]);
899 fp = fopen (args_filename, "w");
902 g_warning ("Couldn't open output file: %s : %s", args_filename, g_strerror(errno));
906 for (i = 0; object_types[i]; i++) {
907 output_object_args (fp, object_types[i]);
914 compare_param_specs (const void *a, const void *b)
916 GParamSpec *spec_a = *(GParamSpec **)a;
917 GParamSpec *spec_b = *(GParamSpec **)b;
919 return strcmp (g_param_spec_get_name (spec_a), g_param_spec_get_name (spec_b));
922 /* Its common to have unsigned properties restricted
923 * to the signed range. Therefore we make this look
924 * a bit nicer by spelling out the max constants.
927 /* Don't use "==" with floats, it might trigger a gcc warning. */
928 #define GTKDOC_COMPARE_FLOAT(x, y) (x <= y && x >= y)
931 describe_double_constant (gdouble value)
935 if (GTKDOC_COMPARE_FLOAT (value, G_MAXDOUBLE))
936 desc = g_strdup ("G_MAXDOUBLE");
937 else if (GTKDOC_COMPARE_FLOAT (value, G_MINDOUBLE))
938 desc = g_strdup ("G_MINDOUBLE");
939 else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXDOUBLE))
940 desc = g_strdup ("-G_MAXDOUBLE");
941 else if (GTKDOC_COMPARE_FLOAT (value, G_MAXFLOAT))
942 desc = g_strdup ("G_MAXFLOAT");
943 else if (GTKDOC_COMPARE_FLOAT (value, G_MINFLOAT))
944 desc = g_strdup ("G_MINFLOAT");
945 else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXFLOAT))
946 desc = g_strdup ("-G_MAXFLOAT");
948 /* make sure floats are output with a decimal dot irrespective of
949 * current locale. Use formatd since we want human-readable numbers
950 * and do not need the exact same bit representation when deserialising */
951 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
952 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g", value);
959 describe_signed_constant (gsize size, gint64 value)
965 if (value == G_MAXINT64)
966 desc = g_strdup ("G_MAXINT64");
967 else if (value == G_MININT64)
968 desc = g_strdup ("G_MININT64");
971 if (sizeof (int) == 4) {
972 if (value == G_MAXINT)
973 desc = g_strdup ("G_MAXINT");
974 else if (value == G_MININT)
975 desc = g_strdup ("G_MININT");
976 else if (value == (gint64)G_MAXUINT)
977 desc = g_strdup ("G_MAXUINT");
979 if (value == G_MAXLONG)
980 desc = g_strdup ("G_MAXLONG");
981 else if (value == G_MINLONG)
982 desc = g_strdup ("G_MINLONG");
983 else if (value == (gint64)G_MAXULONG)
984 desc = g_strdup ("G_MAXULONG");
987 if (sizeof (int) == 2) {
988 if (value == G_MAXINT)
989 desc = g_strdup ("G_MAXINT");
990 else if (value == G_MININT)
991 desc = g_strdup ("G_MININT");
992 else if (value == (gint64)G_MAXUINT)
993 desc = g_strdup ("G_MAXUINT");
1000 desc = g_strdup_printf ("%" G_GINT64_FORMAT, value);
1006 describe_unsigned_constant (gsize size, guint64 value)
1012 if (value == G_MAXINT64)
1013 desc = g_strdup ("G_MAXINT64");
1014 else if (value == G_MAXUINT64)
1015 desc = g_strdup ("G_MAXUINT64");
1018 if (sizeof (int) == 4) {
1019 if (value == (guint64)G_MAXINT)
1020 desc = g_strdup ("G_MAXINT");
1021 else if (value == G_MAXUINT)
1022 desc = g_strdup ("G_MAXUINT");
1024 if (value == (guint64)G_MAXLONG)
1025 desc = g_strdup ("G_MAXLONG");
1026 else if (value == G_MAXULONG)
1027 desc = g_strdup ("G_MAXULONG");
1030 if (sizeof (int) == 2) {
1031 if (value == (guint64)G_MAXINT)
1032 desc = g_strdup ("G_MAXINT");
1033 else if (value == G_MAXUINT)
1034 desc = g_strdup ("G_MAXUINT");
1041 desc = g_strdup_printf ("%" G_GUINT64_FORMAT, value);
1047 describe_type (GParamSpec *spec)
1053 if (G_IS_PARAM_SPEC_CHAR (spec))
1055 GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
1057 lower = describe_signed_constant (sizeof(gchar), pspec->minimum);
1058 upper = describe_signed_constant (sizeof(gchar), pspec->maximum);
1059 if (pspec->minimum == G_MININT8 && pspec->maximum == G_MAXINT8)
1060 desc = g_strdup ("");
1061 else if (pspec->minimum == G_MININT8)
1062 desc = g_strdup_printf ("<= %s", upper);
1063 else if (pspec->maximum == G_MAXINT8)
1064 desc = g_strdup_printf (">= %s", lower);
1066 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1070 else if (G_IS_PARAM_SPEC_UCHAR (spec))
1072 GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
1074 lower = describe_unsigned_constant (sizeof(guchar), pspec->minimum);
1075 upper = describe_unsigned_constant (sizeof(guchar), pspec->maximum);
1076 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT8)
1077 desc = g_strdup ("");
1078 else if (pspec->minimum == 0)
1079 desc = g_strdup_printf ("<= %s", upper);
1080 else if (pspec->maximum == G_MAXUINT8)
1081 desc = g_strdup_printf (">= %s", lower);
1083 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1087 else if (G_IS_PARAM_SPEC_INT (spec))
1089 GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
1091 lower = describe_signed_constant (sizeof(gint), pspec->minimum);
1092 upper = describe_signed_constant (sizeof(gint), pspec->maximum);
1093 if (pspec->minimum == G_MININT && pspec->maximum == G_MAXINT)
1094 desc = g_strdup ("");
1095 else if (pspec->minimum == G_MININT)
1096 desc = g_strdup_printf ("<= %s", upper);
1097 else if (pspec->maximum == G_MAXINT)
1098 desc = g_strdup_printf (">= %s", lower);
1100 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1104 else if (G_IS_PARAM_SPEC_UINT (spec))
1106 GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
1108 lower = describe_unsigned_constant (sizeof(guint), pspec->minimum);
1109 upper = describe_unsigned_constant (sizeof(guint), pspec->maximum);
1110 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT)
1111 desc = g_strdup ("");
1112 else if (pspec->minimum == 0)
1113 desc = g_strdup_printf ("<= %s", upper);
1114 else if (pspec->maximum == G_MAXUINT)
1115 desc = g_strdup_printf (">= %s", lower);
1117 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1121 else if (G_IS_PARAM_SPEC_LONG (spec))
1123 GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
1125 lower = describe_signed_constant (sizeof(glong), pspec->minimum);
1126 upper = describe_signed_constant (sizeof(glong), pspec->maximum);
1127 if (pspec->minimum == G_MINLONG && pspec->maximum == G_MAXLONG)
1128 desc = g_strdup ("");
1129 else if (pspec->minimum == G_MINLONG)
1130 desc = g_strdup_printf ("<= %s", upper);
1131 else if (pspec->maximum == G_MAXLONG)
1132 desc = g_strdup_printf (">= %s", lower);
1134 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1138 else if (G_IS_PARAM_SPEC_ULONG (spec))
1140 GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
1142 lower = describe_unsigned_constant (sizeof(gulong), pspec->minimum);
1143 upper = describe_unsigned_constant (sizeof(gulong), pspec->maximum);
1144 if (pspec->minimum == 0 && pspec->maximum == G_MAXULONG)
1145 desc = g_strdup ("");
1146 else if (pspec->minimum == 0)
1147 desc = g_strdup_printf ("<= %s", upper);
1148 else if (pspec->maximum == G_MAXULONG)
1149 desc = g_strdup_printf (">= %s", lower);
1151 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1155 else if (G_IS_PARAM_SPEC_INT64 (spec))
1157 GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
1159 lower = describe_signed_constant (sizeof(gint64), pspec->minimum);
1160 upper = describe_signed_constant (sizeof(gint64), pspec->maximum);
1161 if (pspec->minimum == G_MININT64 && pspec->maximum == G_MAXINT64)
1162 desc = g_strdup ("");
1163 else if (pspec->minimum == G_MININT64)
1164 desc = g_strdup_printf ("<= %s", upper);
1165 else if (pspec->maximum == G_MAXINT64)
1166 desc = g_strdup_printf (">= %s", lower);
1168 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1172 else if (G_IS_PARAM_SPEC_UINT64 (spec))
1174 GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
1176 lower = describe_unsigned_constant (sizeof(guint64), pspec->minimum);
1177 upper = describe_unsigned_constant (sizeof(guint64), pspec->maximum);
1178 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT64)
1179 desc = g_strdup ("");
1180 else if (pspec->minimum == 0)
1181 desc = g_strdup_printf ("<= %s", upper);
1182 else if (pspec->maximum == G_MAXUINT64)
1183 desc = g_strdup_printf (">= %s", lower);
1185 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1189 else if (G_IS_PARAM_SPEC_FLOAT (spec))
1191 GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
1193 lower = describe_double_constant (pspec->minimum);
1194 upper = describe_double_constant (pspec->maximum);
1195 if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXFLOAT))
1197 if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
1198 desc = g_strdup ("");
1200 desc = g_strdup_printf ("<= %s", upper);
1202 else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
1203 desc = g_strdup_printf (">= %s", lower);
1205 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1209 else if (G_IS_PARAM_SPEC_DOUBLE (spec))
1211 GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
1213 lower = describe_double_constant (pspec->minimum);
1214 upper = describe_double_constant (pspec->maximum);
1215 if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXDOUBLE))
1217 if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
1218 desc = g_strdup ("");
1220 desc = g_strdup_printf ("<= %s", upper);
1222 else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
1223 desc = g_strdup_printf (">= %s", lower);
1225 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1229 #if GLIB_CHECK_VERSION (2, 12, 0)
1230 else if (G_IS_PARAM_SPEC_GTYPE (spec))
1232 GParamSpecGType *pspec = G_PARAM_SPEC_GTYPE (spec);
1233 gboolean is_pointer;
1235 desc = g_strdup (get_type_name (pspec->is_a_type, &is_pointer));
1238 #if GLIB_CHECK_VERSION (2, 25, 9)
1239 else if (G_IS_PARAM_SPEC_VARIANT (spec))
1241 GParamSpecVariant *pspec = G_PARAM_SPEC_VARIANT (spec);
1242 gchar *variant_type;
1244 variant_type = g_variant_type_dup_string (pspec->type);
1245 desc = g_strdup_printf ("GVariant<%s>", variant_type);
1246 g_free (variant_type);
1251 desc = g_strdup ("");
1258 describe_default (GParamSpec *spec)
1262 if (G_IS_PARAM_SPEC_CHAR (spec))
1264 GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
1266 desc = g_strdup_printf ("%d", pspec->default_value);
1268 else if (G_IS_PARAM_SPEC_UCHAR (spec))
1270 GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
1272 desc = g_strdup_printf ("%u", pspec->default_value);
1274 else if (G_IS_PARAM_SPEC_BOOLEAN (spec))
1276 GParamSpecBoolean *pspec = G_PARAM_SPEC_BOOLEAN (spec);
1278 desc = g_strdup_printf ("%s", pspec->default_value ? "TRUE" : "FALSE");
1280 else if (G_IS_PARAM_SPEC_INT (spec))
1282 GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
1284 desc = g_strdup_printf ("%d", pspec->default_value);
1286 else if (G_IS_PARAM_SPEC_UINT (spec))
1288 GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
1290 desc = g_strdup_printf ("%u", pspec->default_value);
1292 else if (G_IS_PARAM_SPEC_LONG (spec))
1294 GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
1296 desc = g_strdup_printf ("%ld", pspec->default_value);
1298 else if (G_IS_PARAM_SPEC_LONG (spec))
1300 GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
1302 desc = g_strdup_printf ("%lu", pspec->default_value);
1304 else if (G_IS_PARAM_SPEC_INT64 (spec))
1306 GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
1308 desc = g_strdup_printf ("%" G_GINT64_FORMAT, pspec->default_value);
1310 else if (G_IS_PARAM_SPEC_UINT64 (spec))
1312 GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
1314 desc = g_strdup_printf ("%" G_GUINT64_FORMAT, pspec->default_value);
1316 else if (G_IS_PARAM_SPEC_UNICHAR (spec))
1318 GParamSpecUnichar *pspec = G_PARAM_SPEC_UNICHAR (spec);
1320 if (g_unichar_isprint (pspec->default_value))
1321 desc = g_strdup_printf ("'%c'", pspec->default_value);
1323 desc = g_strdup_printf ("%u", pspec->default_value);
1325 else if (G_IS_PARAM_SPEC_ENUM (spec))
1327 GParamSpecEnum *pspec = G_PARAM_SPEC_ENUM (spec);
1329 GEnumValue *value = g_enum_get_value (pspec->enum_class, pspec->default_value);
1331 desc = g_strdup_printf ("%s", value->value_name);
1333 desc = g_strdup_printf ("%d", pspec->default_value);
1335 else if (G_IS_PARAM_SPEC_FLAGS (spec))
1337 GParamSpecFlags *pspec = G_PARAM_SPEC_FLAGS (spec);
1338 guint default_value;
1341 default_value = pspec->default_value;
1342 acc = g_string_new ("");
1344 while (default_value)
1346 GFlagsValue *value = g_flags_get_first_value (pspec->flags_class, default_value);
1352 g_string_append (acc, "|");
1353 g_string_append (acc, value->value_name);
1355 default_value &= ~value->value;
1358 if (default_value == 0)
1359 desc = g_string_free (acc, FALSE);
1362 desc = g_strdup_printf ("%d", pspec->default_value);
1363 g_string_free (acc, TRUE);
1366 else if (G_IS_PARAM_SPEC_FLOAT (spec))
1368 GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
1370 /* make sure floats are output with a decimal dot irrespective of
1371 * current locale. Use formatd since we want human-readable numbers
1372 * and do not need the exact same bit representation when deserialising */
1373 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
1374 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
1375 pspec->default_value);
1377 else if (G_IS_PARAM_SPEC_DOUBLE (spec))
1379 GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
1381 /* make sure floats are output with a decimal dot irrespective of
1382 * current locale. Use formatd since we want human-readable numbers
1383 * and do not need the exact same bit representation when deserialising */
1384 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
1385 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
1386 pspec->default_value);
1388 else if (G_IS_PARAM_SPEC_STRING (spec))
1390 GParamSpecString *pspec = G_PARAM_SPEC_STRING (spec);
1392 if (pspec->default_value)
1394 gchar *esc = g_strescape (pspec->default_value, NULL);
1396 desc = g_strdup_printf ("\\"%s\\"", esc);
1401 desc = g_strdup_printf ("NULL");
1405 desc = g_strdup ("");
1413 output_object_args (FILE *fp, GType object_type)
1416 const gchar *object_class_name;
1418 gchar flags[16], *pos;
1419 GParamSpec **properties;
1421 gboolean child_prop;
1422 gboolean style_prop;
1423 gboolean is_pointer;
1424 const gchar *type_name;
1426 gchar *default_value;
1428 if (G_TYPE_IS_OBJECT (object_type))
1430 class = g_type_class_peek (object_type);
1434 properties = g_object_class_list_properties (class, &n_properties);
1436 #if GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 3)
1437 else if (G_TYPE_IS_INTERFACE (object_type))
1439 class = g_type_default_interface_ref (object_type);
1444 properties = g_object_interface_list_properties (class, &n_properties);
1450 object_class_name = g_type_name (object_type);
1456 qsort (properties, n_properties, sizeof (GParamSpec *), compare_param_specs);
1457 for (arg = 0; arg < n_properties; arg++)
1459 GParamSpec *spec = properties[arg];
1460 const gchar *nick, *blurb, *dot;
1462 if (spec->owner_type != object_type)
1466 /* We use one-character flags for simplicity. */
1467 if (child_prop && !style_prop)
1471 if (spec->flags & G_PARAM_READABLE)
1473 if (spec->flags & G_PARAM_WRITABLE)
1475 if (spec->flags & G_PARAM_CONSTRUCT)
1477 if (spec->flags & G_PARAM_CONSTRUCT_ONLY)
1481 nick = g_param_spec_get_nick (spec);
1482 blurb = g_param_spec_get_blurb (spec);
1486 int str_len = strlen (blurb);
1487 if (str_len > 0 && blurb[str_len - 1] != '.')
1491 type_desc = describe_type (spec);
1492 default_value = describe_default (spec);
1493 type_name = get_type_name (spec->value_type, &is_pointer);
1494 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",
1495 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);
1497 g_free (default_value);
1500 g_free (properties);
1502 #ifdef GTK_IS_CONTAINER_CLASS
1503 if (!child_prop && GTK_IS_CONTAINER_CLASS (class)) {
1504 properties = gtk_container_class_list_child_properties (class, &n_properties);
1510 #ifdef GTK_IS_CELL_AREA_CLASS
1511 if (!child_prop && GTK_IS_CELL_AREA_CLASS (class)) {
1512 properties = gtk_cell_area_class_list_cell_properties (class, &n_properties);
1518 #ifdef GTK_IS_WIDGET_CLASS
1519 #if GTK_CHECK_VERSION(2,1,0)
1520 if (!style_prop && GTK_IS_WIDGET_CLASS (class)) {
1521 properties = gtk_widget_class_list_style_properties (GTK_WIDGET_CLASS (class), &n_properties);
1535 # Compile and run our file
1537 $CC = $ENV{CC} ? $ENV{CC} : "gcc";
1538 $LD = $ENV{LD} ? $ENV{LD} : $CC;
1539 $CFLAGS = $ENV{CFLAGS} ? "$ENV{CFLAGS}" : "";
1540 $LDFLAGS = $ENV{LDFLAGS} ? $ENV{LDFLAGS} : "";
1543 if ($CC =~ /libtool/) {
1544 $o_file = "$MODULE-scan.lo"
1546 $o_file = "$MODULE-scan.o"
1549 print "gtk-doc: Compiling scanner\n";
1550 $command = "$CC $CFLAGS -c -o $o_file $MODULE-scan.c";
1551 system($command) == 0 or die "Compilation of scanner failed: $!\n";
1553 print "gtk-doc: Linking scanner\n";
1554 $command = "$LD -o $MODULE-scan $o_file $LDFLAGS";
1555 system($command) == 0 or die "Linking of scanner failed: $!\n";
1557 print "gtk-doc: Running scanner $MODULE-scan\n";
1558 system("sh -c ./$MODULE-scan") == 0 or die "Scan failed: $!\n";
1560 if (!defined($ENV{"GTK_DOC_KEEP_INTERMEDIATE"})) {
1561 unlink "./$MODULE-scan.c", "./$MODULE-scan.o", "./$MODULE-scan.lo", "./$MODULE-scan";
1564 &UpdateFileIfChanged ($old_hierarchy_filename, $new_hierarchy_filename, 0);
1565 &UpdateFileIfChanged ($old_interfaces_filename, $new_interfaces_filename, 0);
1566 &UpdateFileIfChanged ($old_prerequisites_filename, $new_prerequisites_filename, 0);
1567 # we will merge these in scangobj-merge.py
1568 #&UpdateFileIfChanged ($old_signals_filename, $new_signals_filename, 0);
1569 #&UpdateFileIfChanged ($old_args_filename, $new_args_filename, 0);