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 /*g_print ("plugin: %s source: %s\\n", plugin->desc.name, source);*/
225 if (!source || strcmp (source, "$SOURCE") != 0) {
229 /* skip static coreelements plugin with pipeline and bin element factory */
230 if (gst_plugin_get_filename (plugin) == NULL)
233 g_print ("plugin: %s source: %s\\n", plugin->desc.name, source);
236 inspect_name = g_strdup_printf ("$INSPECT_DIR" G_DIR_SEPARATOR_S "plugin-%s.xml",
238 inspect = fopen (inspect_name, "w");
239 if (inspect == NULL) {
240 g_error ("Could not open %s for writing: %s\\n", inspect_name,
243 g_free (inspect_name);
245 /* output plugin data */
246 fputs ("<plugin>\\n",inspect);
247 fputs (xmlprint(2, "name", plugin->desc.name),inspect);
248 fputs (xmlprint(2, "description", plugin->desc.description),inspect);
249 fputs (xmlprint(2, "filename", plugin->filename),inspect);
250 fputs (xmlprint(2, "basename", plugin->basename),inspect);
251 fputs (xmlprint(2, "version", plugin->desc.version),inspect);
252 fputs (xmlprint(2, "license", plugin->desc.license),inspect);
253 fputs (xmlprint(2, "source", plugin->desc.source),inspect);
254 fputs (xmlprint(2, "package", plugin->desc.package),inspect);
255 fputs (xmlprint(2, "origin", plugin->desc.origin),inspect);
256 fputs (" <elements>\\n", inspect);
260 gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
263 /* sort factories by feature->name */
264 features = g_list_sort (features, gst_feature_sort_compare);
267 GstPluginFeature *feature;
268 feature = GST_PLUGIN_FEATURE (features->data);
269 feature = gst_plugin_feature_load (feature);
271 g_warning ("Could not load plugin feature %s",
272 gst_plugin_feature_get_name (feature));
275 if (GST_IS_ELEMENT_FACTORY (feature)) {
276 const gchar *pad_dir[] = { "unknown","source","sink" };
277 const gchar *pad_pres[] = { "always","sometimes","request" };
280 /*g_print (" feature: %s\\n", feature->name);*/
282 factory = GST_ELEMENT_FACTORY (feature);
283 factories = g_list_prepend (factories, factory);
286 /* output element data */
287 fputs (" <element>\\n", inspect);
288 fputs (xmlprint(6, "name", feature->name),inspect);
289 fputs (xmlprint(6, "longname", gst_element_factory_get_longname (factory)),inspect);
290 fputs (xmlprint(6, "class", gst_element_factory_get_klass (factory)),inspect);
291 fputs (xmlprint(6, "description", gst_element_factory_get_description (factory)),inspect);
292 fputs (xmlprint(6, "author", gst_element_factory_get_author (factory)),inspect);
293 fputs (" <pads>\\n", inspect);
295 /* output pad-template data */
296 pads = g_list_copy ((GList *) gst_element_factory_get_static_pad_templates (factory));
297 pads = g_list_sort (pads, static_pad_template_compare);
298 for (pad = pads; pad != NULL; pad = pad->next) {
299 GstStaticPadTemplate *pt = pad->data;
301 fputs (" <caps>\\n", inspect);
302 fputs (xmlprint(10, "name", pt->name_template),inspect);
303 fputs (xmlprint(10, "direction", pad_dir[pt->direction]),inspect);
304 fputs (xmlprint(10, "presence", pad_pres[pt->presence]),inspect);
305 fputs (xmlprint(10, "details", pt->static_caps.string),inspect);
306 fputs (" </caps>\\n", inspect);
309 fputs (" </pads>\\n </element>\\n", inspect);
312 features = g_list_next (features);
316 fputs (" </elements>\\n</plugin>", inspect);
321 g_string_free (xmlstr, TRUE);
323 g_message ("number of element factories: %d", g_list_length (factories));
325 /* allocate the object_types array to hold them */
326 object_types = g_new0 (GType, g_list_length (factories)+$ntypes+1);
333 factory = GST_ELEMENT_FACTORY (l->data);
334 type = gst_element_factory_get_element_type (factory);
336 g_message ("adding type %p for factory %s", (void *) type, gst_element_factory_get_longname (factory));
337 object_types[i++] = type;
339 g_message ("type info for factory %s not found",
340 gst_element_factory_get_longname (factory));
347 # get_type functions:
352 g_message ("$_ () didn't return a valid type");
355 object_types[i++] = type;
360 # Implicit types retrieved from GLib:
363 type = g_type_from_name ("$_");
365 g_message ("Implicit type $_ not found");
368 object_types[i++] = type;
377 /* reference the GObjectClass to initialize the param spec pool
378 * potentially needed by interfaces. See http://bugs.gnome.org/571820 */
379 g_object_class = g_type_class_ref (G_TYPE_OBJECT);
381 /* Need to make sure all the types are loaded in and initialize
382 * their signals and properties.
384 for (i=0; object_types[i]; i++)
386 if (G_TYPE_IS_CLASSED (object_types[i]))
387 g_type_class_ref (object_types[i]);
388 if (G_TYPE_IS_INTERFACE (object_types[i]))
389 g_type_default_interface_ref (object_types[i]);
392 g_type_class_unref (g_object_class);
398 * This uses GObject type functions to output signal prototypes and the object
402 /* The output files */
403 const gchar *signals_filename = "$new_signals_filename";
404 const gchar *hierarchy_filename = "$new_hierarchy_filename";
405 const gchar *interfaces_filename = "$new_interfaces_filename";
406 const gchar *prerequisites_filename = "$new_prerequisites_filename";
407 const gchar *args_filename = "$new_args_filename";
410 static void output_signals (void);
411 static void output_object_signals (FILE *fp,
413 static void output_object_signal (FILE *fp,
414 const gchar *object_class_name,
416 static const gchar * get_type_name (GType type,
417 gboolean * is_pointer);
418 static void output_object_hierarchy (void);
419 static void output_hierarchy (FILE *fp,
423 static void output_object_interfaces (void);
424 static void output_interfaces (FILE *fp,
427 static void output_interface_prerequisites (void);
428 static void output_prerequisites (FILE *fp,
431 static void output_args (void);
432 static void output_object_args (FILE *fp, GType object_type);
435 main (int argc, char *argv[])
437 /* Silence the compiler: */
438 if (argv != argv) argc = argc;
445 output_object_hierarchy ();
446 output_object_interfaces ();
447 output_interface_prerequisites ();
455 output_signals (void)
460 fp = fopen (signals_filename, "w");
463 g_warning ("Couldn't open output file: %s : %s", signals_filename, g_strerror(errno));
467 for (i = 0; object_types[i]; i++)
468 output_object_signals (fp, object_types[i]);
474 compare_signals (const void *a, const void *b)
476 const guint *signal_a = a;
477 const guint *signal_b = b;
479 return strcmp (g_signal_name (*signal_a), g_signal_name (*signal_b));
482 /* This outputs all the signals of one object. */
484 output_object_signals (FILE *fp, GType object_type)
486 const gchar *object_class_name;
487 guint *signals, n_signals;
490 if (G_TYPE_IS_INSTANTIATABLE (object_type) ||
491 G_TYPE_IS_INTERFACE (object_type))
494 object_class_name = g_type_name (object_type);
496 signals = g_signal_list_ids (object_type, &n_signals);
497 qsort (signals, n_signals, sizeof (guint), compare_signals);
499 for (sig = 0; sig < n_signals; sig++)
501 output_object_signal (fp, object_class_name, signals[sig]);
508 /* This outputs one signal. */
510 output_object_signal (FILE *fp,
511 const gchar *object_name,
514 GSignalQuery query_info;
515 const gchar *type_name, *ret_type, *object_arg, *arg_name;
516 gchar *pos, *object_arg_lower;
520 gint param_num, widget_num, event_num, callback_num;
522 gchar signal_name[128];
525 /* g_print ("Object: %s Signal: %u\\n", object_name, signal_id);*/
528 widget_num = event_num = callback_num = 0;
530 g_signal_query (signal_id, &query_info);
532 /* Output the signal object type and the argument name. We assume the
533 type is a pointer - I think that is OK. We remove "Gtk" or "Gnome" and
534 convert to lower case for the argument name. */
536 sprintf (pos, "%s ", object_name);
539 /* Try to come up with a sensible variable name for the first arg
540 * It chops off 2 know prefixes :/ and makes the name lowercase
541 * It should replace lowercase -> uppercase with '_'
542 * GFileMonitor -> file_monitor
543 * GIOExtensionPoint -> extension_point
544 * GtkTreeView -> tree_view
545 * if 2nd char is upper case too
546 * search for first lower case and go back one char
548 * search for next upper case
550 if (!strncmp (object_name, "Gtk", 3))
551 object_arg = object_name + 3;
552 else if (!strncmp (object_name, "Gnome", 5))
553 object_arg = object_name + 5;
555 object_arg = object_name;
557 object_arg_lower = g_ascii_strdown (object_arg, -1);
558 sprintf (pos, "*%s\\n", object_arg_lower);
560 if (!strncmp (object_arg_lower, "widget", 6))
562 g_free(object_arg_lower);
564 /* Convert signal name to use underscores rather than dashes '-'. */
565 strncpy (signal_name, query_info.signal_name, 127);
566 signal_name[127] = '\\0';
567 for (i = 0; signal_name[i]; i++)
569 if (signal_name[i] == '-')
570 signal_name[i] = '_';
573 /* Output the signal parameters. */
574 for (param = 0; param < query_info.n_params; param++)
576 type_name = get_type_name (query_info.param_types[param] & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
578 /* Most arguments to the callback are called "arg1", "arg2", etc.
579 GtkWidgets are called "widget", "widget2", ...
580 GtkCallbacks are called "callback", "callback2", ... */
581 if (!strcmp (type_name, "GtkWidget"))
584 arg_num = &widget_num;
586 else if (!strcmp (type_name, "GtkCallback")
587 || !strcmp (type_name, "GtkCCallback"))
589 arg_name = "callback";
590 arg_num = &callback_num;
595 arg_num = ¶m_num;
597 sprintf (pos, "%s ", type_name);
600 if (!arg_num || *arg_num == 0)
601 sprintf (pos, "%s%s\\n", is_pointer ? "*" : " ", arg_name);
603 sprintf (pos, "%s%s%i\\n", is_pointer ? "*" : " ", arg_name,
617 /* We use one-character flags for simplicity. */
618 if (query_info.signal_flags & G_SIGNAL_RUN_FIRST)
620 if (query_info.signal_flags & G_SIGNAL_RUN_LAST)
622 if (query_info.signal_flags & G_SIGNAL_RUN_CLEANUP)
624 if (query_info.signal_flags & G_SIGNAL_NO_RECURSE)
626 if (query_info.signal_flags & G_SIGNAL_DETAILED)
628 if (query_info.signal_flags & G_SIGNAL_ACTION)
630 if (query_info.signal_flags & G_SIGNAL_NO_HOOKS)
634 /* Output the return type and function name. */
635 ret_type = get_type_name (query_info.return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
638 "<SIGNAL>\\n<NAME>%s::%s</NAME>\\n<RETURNS>%s%s</RETURNS>\\n<FLAGS>%s</FLAGS>\\n%s</SIGNAL>\\n\\n",
639 object_name, query_info.signal_name, ret_type, is_pointer ? "*" : "", flags, buffer);
643 /* Returns the type name to use for a signal argument or return value, given
644 the GtkType from the signal info. It also sets is_pointer to TRUE if the
645 argument needs a '*' since it is a pointer. */
647 get_type_name (GType type, gboolean * is_pointer)
649 const gchar *type_name;
652 type_name = g_type_name (type);
666 /* These all have normal C type names so they are OK. */
670 /* A GtkString is really a gchar*. */
676 /* We use a gint for both of these. Hopefully a subtype with a decent
677 name will be registered and used instead, as GTK+ does itself. */
681 /* The boxed type shouldn't be used itself, only subtypes. Though we
682 return 'gpointer' just in case. */
686 /* A GParam is really a GParamSpec*. */
690 #if GLIB_CHECK_VERSION (2, 25, 9)
700 /* For all GObject subclasses we can use the class name with a "*",
701 e.g. 'GtkWidget *'. */
702 if (g_type_is_a (type, G_TYPE_OBJECT))
705 /* Also catch non GObject root types */
706 if (G_TYPE_IS_CLASSED (type))
709 /* All boxed subtypes will be pointers as well. */
710 /* Exception: GStrv */
711 if (g_type_is_a (type, G_TYPE_BOXED) &&
712 !g_type_is_a (type, G_TYPE_STRV))
715 /* All pointer subtypes will be pointers as well. */
716 if (g_type_is_a (type, G_TYPE_POINTER))
719 /* But enums are not */
720 if (g_type_is_a (type, G_TYPE_ENUM) ||
721 g_type_is_a (type, G_TYPE_FLAGS))
728 /* This outputs the hierarchy of all objects which have been initialized,
729 i.e. by calling their XXX_get_type() initialization function. */
731 output_object_hierarchy (void)
736 GType root_types[$ntypes] = { G_TYPE_INVALID, };
738 fp = fopen (hierarchy_filename, "w");
741 g_warning ("Couldn't open output file: %s : %s", hierarchy_filename, g_strerror(errno));
744 output_hierarchy (fp, G_TYPE_OBJECT, 0);
745 output_hierarchy (fp, G_TYPE_INTERFACE, 0);
747 for (i=0; object_types[i]; i++) {
748 root = object_types[i];
749 while ((type = g_type_parent (root))) {
752 if ((root != G_TYPE_OBJECT) && (root != G_TYPE_INTERFACE)) {
753 for (j=0; root_types[j]; j++) {
754 if (root == root_types[j]) {
755 root = G_TYPE_INVALID; break;
759 root_types[j] = root;
760 output_hierarchy (fp, root, 0);
768 /* This is called recursively to output the hierarchy of a object. */
770 output_hierarchy (FILE *fp,
781 for (i = 0; i < level; i++)
783 fprintf (fp, "%s\\n", g_type_name (type));
785 children = g_type_children (type, &n_children);
787 for (i=0; i < n_children; i++)
788 output_hierarchy (fp, children[i], level + 1);
793 static void output_object_interfaces (void)
798 fp = fopen (interfaces_filename, "w");
801 g_warning ("Couldn't open output file: %s : %s", interfaces_filename, g_strerror(errno));
804 output_interfaces (fp, G_TYPE_OBJECT);
806 for (i = 0; object_types[i]; i++)
808 if (!g_type_parent (object_types[i]) &&
809 (object_types[i] != G_TYPE_OBJECT) &&
810 G_TYPE_IS_INSTANTIATABLE (object_types[i]))
812 output_interfaces (fp, object_types[i]);
819 output_interfaces (FILE *fp,
823 GType *children, *interfaces;
824 guint n_children, n_interfaces;
829 interfaces = g_type_interfaces (type, &n_interfaces);
831 if (n_interfaces > 0)
833 fprintf (fp, "%s", g_type_name (type));
834 for (i=0; i < n_interfaces; i++)
835 fprintf (fp, " %s", g_type_name (interfaces[i]));
840 children = g_type_children (type, &n_children);
842 for (i=0; i < n_children; i++)
843 output_interfaces (fp, children[i]);
848 static void output_interface_prerequisites (void)
852 fp = fopen (prerequisites_filename, "w");
855 g_warning ("Couldn't open output file: %s : %s", prerequisites_filename, g_strerror(errno));
858 output_prerequisites (fp, G_TYPE_INTERFACE);
863 output_prerequisites (FILE *fp,
866 #if GLIB_CHECK_VERSION(2,1,0)
868 GType *children, *prerequisites;
869 guint n_children, n_prerequisites;
874 prerequisites = g_type_interface_prerequisites (type, &n_prerequisites);
876 if (n_prerequisites > 0)
878 fprintf (fp, "%s", g_type_name (type));
879 for (i=0; i < n_prerequisites; i++)
880 fprintf (fp, " %s", g_type_name (prerequisites[i]));
883 g_free (prerequisites);
885 children = g_type_children (type, &n_children);
887 for (i=0; i < n_children; i++)
888 output_prerequisites (fp, children[i]);
900 fp = fopen (args_filename, "w");
903 g_warning ("Couldn't open output file: %s : %s", args_filename, g_strerror(errno));
907 for (i = 0; object_types[i]; i++) {
908 output_object_args (fp, object_types[i]);
915 compare_param_specs (const void *a, const void *b)
917 GParamSpec *spec_a = *(GParamSpec **)a;
918 GParamSpec *spec_b = *(GParamSpec **)b;
920 return strcmp (g_param_spec_get_name (spec_a), g_param_spec_get_name (spec_b));
923 /* Its common to have unsigned properties restricted
924 * to the signed range. Therefore we make this look
925 * a bit nicer by spelling out the max constants.
928 /* Don't use "==" with floats, it might trigger a gcc warning. */
929 #define GTKDOC_COMPARE_FLOAT(x, y) (x <= y && x >= y)
932 describe_double_constant (gdouble value)
936 if (GTKDOC_COMPARE_FLOAT (value, G_MAXDOUBLE))
937 desc = g_strdup ("G_MAXDOUBLE");
938 else if (GTKDOC_COMPARE_FLOAT (value, G_MINDOUBLE))
939 desc = g_strdup ("G_MINDOUBLE");
940 else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXDOUBLE))
941 desc = g_strdup ("-G_MAXDOUBLE");
942 else if (GTKDOC_COMPARE_FLOAT (value, G_MAXFLOAT))
943 desc = g_strdup ("G_MAXFLOAT");
944 else if (GTKDOC_COMPARE_FLOAT (value, G_MINFLOAT))
945 desc = g_strdup ("G_MINFLOAT");
946 else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXFLOAT))
947 desc = g_strdup ("-G_MAXFLOAT");
949 /* make sure floats are output with a decimal dot irrespective of
950 * current locale. Use formatd since we want human-readable numbers
951 * and do not need the exact same bit representation when deserialising */
952 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
953 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g", value);
960 describe_signed_constant (gsize size, gint64 value)
966 if (sizeof (int) == 2) {
967 if (value == G_MAXINT)
968 desc = g_strdup ("G_MAXINT");
969 else if (value == G_MININT)
970 desc = g_strdup ("G_MININT");
971 else if (value == (gint64)G_MAXUINT)
972 desc = g_strdup ("G_MAXUINT");
976 if (sizeof (int) == 4) {
977 if (value == G_MAXINT)
978 desc = g_strdup ("G_MAXINT");
979 else if (value == G_MININT)
980 desc = g_strdup ("G_MININT");
981 else if (value == (gint64)G_MAXUINT)
982 desc = g_strdup ("G_MAXUINT");
984 if (value == G_MAXLONG)
985 desc = g_strdup ("G_MAXLONG");
986 else if (value == G_MINLONG)
987 desc = g_strdup ("G_MINLONG");
988 else if (value == (gint64)G_MAXULONG)
989 desc = g_strdup ("G_MAXULONG");
992 if (value == G_MAXINT64)
993 desc = g_strdup ("G_MAXINT64");
994 else if (value == G_MININT64)
995 desc = g_strdup ("G_MININT64");
1001 desc = g_strdup_printf ("%" G_GINT64_FORMAT, value);
1007 describe_unsigned_constant (gsize size, guint64 value)
1013 if (sizeof (int) == 2) {
1014 if (value == (guint64)G_MAXINT)
1015 desc = g_strdup ("G_MAXINT");
1016 else if (value == G_MAXUINT)
1017 desc = g_strdup ("G_MAXUINT");
1021 if (sizeof (int) == 4) {
1022 if (value == (guint64)G_MAXINT)
1023 desc = g_strdup ("G_MAXINT");
1024 else if (value == G_MAXUINT)
1025 desc = g_strdup ("G_MAXUINT");
1027 if (value == (guint64)G_MAXLONG)
1028 desc = g_strdup ("G_MAXLONG");
1029 else if (value == G_MAXULONG)
1030 desc = g_strdup ("G_MAXULONG");
1033 if (value == G_MAXINT64)
1034 desc = g_strdup ("G_MAXINT64");
1035 else if (value == G_MAXUINT64)
1036 desc = g_strdup ("G_MAXUINT64");
1042 desc = g_strdup_printf ("%" G_GUINT64_FORMAT, value);
1048 describe_type (GParamSpec *spec)
1054 if (G_IS_PARAM_SPEC_CHAR (spec))
1056 GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
1058 lower = describe_signed_constant (sizeof(gchar), pspec->minimum);
1059 upper = describe_signed_constant (sizeof(gchar), pspec->maximum);
1060 if (pspec->minimum == G_MININT8 && pspec->maximum == G_MAXINT8)
1061 desc = g_strdup ("");
1062 else if (pspec->minimum == G_MININT8)
1063 desc = g_strdup_printf ("<= %s", upper);
1064 else if (pspec->maximum == G_MAXINT8)
1065 desc = g_strdup_printf (">= %s", lower);
1067 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1071 else if (G_IS_PARAM_SPEC_UCHAR (spec))
1073 GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
1075 lower = describe_unsigned_constant (sizeof(guchar), pspec->minimum);
1076 upper = describe_unsigned_constant (sizeof(guchar), pspec->maximum);
1077 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT8)
1078 desc = g_strdup ("");
1079 else if (pspec->minimum == 0)
1080 desc = g_strdup_printf ("<= %s", upper);
1081 else if (pspec->maximum == G_MAXUINT8)
1082 desc = g_strdup_printf (">= %s", lower);
1084 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1088 else if (G_IS_PARAM_SPEC_INT (spec))
1090 GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
1092 lower = describe_signed_constant (sizeof(gint), pspec->minimum);
1093 upper = describe_signed_constant (sizeof(gint), pspec->maximum);
1094 if (pspec->minimum == G_MININT && pspec->maximum == G_MAXINT)
1095 desc = g_strdup ("");
1096 else if (pspec->minimum == G_MININT)
1097 desc = g_strdup_printf ("<= %s", upper);
1098 else if (pspec->maximum == G_MAXINT)
1099 desc = g_strdup_printf (">= %s", lower);
1101 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1105 else if (G_IS_PARAM_SPEC_UINT (spec))
1107 GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
1109 lower = describe_unsigned_constant (sizeof(guint), pspec->minimum);
1110 upper = describe_unsigned_constant (sizeof(guint), pspec->maximum);
1111 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT)
1112 desc = g_strdup ("");
1113 else if (pspec->minimum == 0)
1114 desc = g_strdup_printf ("<= %s", upper);
1115 else if (pspec->maximum == G_MAXUINT)
1116 desc = g_strdup_printf (">= %s", lower);
1118 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1122 else if (G_IS_PARAM_SPEC_LONG (spec))
1124 GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
1126 lower = describe_signed_constant (sizeof(glong), pspec->minimum);
1127 upper = describe_signed_constant (sizeof(glong), pspec->maximum);
1128 if (pspec->minimum == G_MINLONG && pspec->maximum == G_MAXLONG)
1129 desc = g_strdup ("");
1130 else if (pspec->minimum == G_MINLONG)
1131 desc = g_strdup_printf ("<= %s", upper);
1132 else if (pspec->maximum == G_MAXLONG)
1133 desc = g_strdup_printf (">= %s", lower);
1135 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1139 else if (G_IS_PARAM_SPEC_ULONG (spec))
1141 GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
1143 lower = describe_unsigned_constant (sizeof(gulong), pspec->minimum);
1144 upper = describe_unsigned_constant (sizeof(gulong), pspec->maximum);
1145 if (pspec->minimum == 0 && pspec->maximum == G_MAXULONG)
1146 desc = g_strdup ("");
1147 else if (pspec->minimum == 0)
1148 desc = g_strdup_printf ("<= %s", upper);
1149 else if (pspec->maximum == G_MAXULONG)
1150 desc = g_strdup_printf (">= %s", lower);
1152 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1156 else if (G_IS_PARAM_SPEC_INT64 (spec))
1158 GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
1160 lower = describe_signed_constant (sizeof(gint64), pspec->minimum);
1161 upper = describe_signed_constant (sizeof(gint64), pspec->maximum);
1162 if (pspec->minimum == G_MININT64 && pspec->maximum == G_MAXINT64)
1163 desc = g_strdup ("");
1164 else if (pspec->minimum == G_MININT64)
1165 desc = g_strdup_printf ("<= %s", upper);
1166 else if (pspec->maximum == G_MAXINT64)
1167 desc = g_strdup_printf (">= %s", lower);
1169 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1173 else if (G_IS_PARAM_SPEC_UINT64 (spec))
1175 GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
1177 lower = describe_unsigned_constant (sizeof(guint64), pspec->minimum);
1178 upper = describe_unsigned_constant (sizeof(guint64), pspec->maximum);
1179 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT64)
1180 desc = g_strdup ("");
1181 else if (pspec->minimum == 0)
1182 desc = g_strdup_printf ("<= %s", upper);
1183 else if (pspec->maximum == G_MAXUINT64)
1184 desc = g_strdup_printf (">= %s", lower);
1186 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1190 else if (G_IS_PARAM_SPEC_FLOAT (spec))
1192 GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
1194 lower = describe_double_constant (pspec->minimum);
1195 upper = describe_double_constant (pspec->maximum);
1196 if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXFLOAT))
1198 if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
1199 desc = g_strdup ("");
1201 desc = g_strdup_printf ("<= %s", upper);
1203 else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
1204 desc = g_strdup_printf (">= %s", lower);
1206 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1210 else if (G_IS_PARAM_SPEC_DOUBLE (spec))
1212 GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
1214 lower = describe_double_constant (pspec->minimum);
1215 upper = describe_double_constant (pspec->maximum);
1216 if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXDOUBLE))
1218 if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
1219 desc = g_strdup ("");
1221 desc = g_strdup_printf ("<= %s", upper);
1223 else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
1224 desc = g_strdup_printf (">= %s", lower);
1226 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1230 #if GLIB_CHECK_VERSION (2, 12, 0)
1231 else if (G_IS_PARAM_SPEC_GTYPE (spec))
1233 GParamSpecGType *pspec = G_PARAM_SPEC_GTYPE (spec);
1234 gboolean is_pointer;
1236 desc = g_strdup (get_type_name (pspec->is_a_type, &is_pointer));
1239 #if GLIB_CHECK_VERSION (2, 25, 9)
1240 else if (G_IS_PARAM_SPEC_VARIANT (spec))
1242 GParamSpecVariant *pspec = G_PARAM_SPEC_VARIANT (spec);
1243 gchar *variant_type;
1245 variant_type = g_variant_type_dup_string (pspec->type);
1246 desc = g_strdup_printf ("GVariant<%s>", variant_type);
1247 g_free (variant_type);
1252 desc = g_strdup ("");
1259 describe_default (GParamSpec *spec)
1263 if (G_IS_PARAM_SPEC_CHAR (spec))
1265 GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
1267 desc = g_strdup_printf ("%d", pspec->default_value);
1269 else if (G_IS_PARAM_SPEC_UCHAR (spec))
1271 GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
1273 desc = g_strdup_printf ("%u", pspec->default_value);
1275 else if (G_IS_PARAM_SPEC_BOOLEAN (spec))
1277 GParamSpecBoolean *pspec = G_PARAM_SPEC_BOOLEAN (spec);
1279 desc = g_strdup_printf ("%s", pspec->default_value ? "TRUE" : "FALSE");
1281 else if (G_IS_PARAM_SPEC_INT (spec))
1283 GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
1285 desc = g_strdup_printf ("%d", pspec->default_value);
1287 else if (G_IS_PARAM_SPEC_UINT (spec))
1289 GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
1291 desc = g_strdup_printf ("%u", pspec->default_value);
1293 else if (G_IS_PARAM_SPEC_LONG (spec))
1295 GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
1297 desc = g_strdup_printf ("%ld", pspec->default_value);
1299 else if (G_IS_PARAM_SPEC_LONG (spec))
1301 GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
1303 desc = g_strdup_printf ("%lu", pspec->default_value);
1305 else if (G_IS_PARAM_SPEC_INT64 (spec))
1307 GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
1309 desc = g_strdup_printf ("%" G_GINT64_FORMAT, pspec->default_value);
1311 else if (G_IS_PARAM_SPEC_UINT64 (spec))
1313 GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
1315 desc = g_strdup_printf ("%" G_GUINT64_FORMAT, pspec->default_value);
1317 else if (G_IS_PARAM_SPEC_UNICHAR (spec))
1319 GParamSpecUnichar *pspec = G_PARAM_SPEC_UNICHAR (spec);
1321 if (g_unichar_isprint (pspec->default_value))
1322 desc = g_strdup_printf ("'%c'", pspec->default_value);
1324 desc = g_strdup_printf ("%u", pspec->default_value);
1326 else if (G_IS_PARAM_SPEC_ENUM (spec))
1328 GParamSpecEnum *pspec = G_PARAM_SPEC_ENUM (spec);
1330 GEnumValue *value = g_enum_get_value (pspec->enum_class, pspec->default_value);
1332 desc = g_strdup_printf ("%s", value->value_name);
1334 desc = g_strdup_printf ("%d", pspec->default_value);
1336 else if (G_IS_PARAM_SPEC_FLAGS (spec))
1338 GParamSpecFlags *pspec = G_PARAM_SPEC_FLAGS (spec);
1339 guint default_value;
1342 default_value = pspec->default_value;
1343 acc = g_string_new ("");
1345 while (default_value)
1347 GFlagsValue *value = g_flags_get_first_value (pspec->flags_class, default_value);
1353 g_string_append (acc, "|");
1354 g_string_append (acc, value->value_name);
1356 default_value &= ~value->value;
1359 if (default_value == 0)
1360 desc = g_string_free (acc, FALSE);
1363 desc = g_strdup_printf ("%d", pspec->default_value);
1364 g_string_free (acc, TRUE);
1367 else if (G_IS_PARAM_SPEC_FLOAT (spec))
1369 GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
1371 /* make sure floats are output with a decimal dot irrespective of
1372 * current locale. Use formatd since we want human-readable numbers
1373 * and do not need the exact same bit representation when deserialising */
1374 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
1375 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
1376 pspec->default_value);
1378 else if (G_IS_PARAM_SPEC_DOUBLE (spec))
1380 GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
1382 /* make sure floats are output with a decimal dot irrespective of
1383 * current locale. Use formatd since we want human-readable numbers
1384 * and do not need the exact same bit representation when deserialising */
1385 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
1386 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
1387 pspec->default_value);
1389 else if (G_IS_PARAM_SPEC_STRING (spec))
1391 GParamSpecString *pspec = G_PARAM_SPEC_STRING (spec);
1393 if (pspec->default_value)
1395 gchar *esc = g_strescape (pspec->default_value, NULL);
1397 desc = g_strdup_printf ("\\"%s\\"", esc);
1402 desc = g_strdup_printf ("NULL");
1406 desc = g_strdup ("");
1414 output_object_args (FILE *fp, GType object_type)
1417 const gchar *object_class_name;
1419 gchar flags[16], *pos;
1420 GParamSpec **properties;
1422 gboolean child_prop;
1423 gboolean style_prop;
1424 gboolean is_pointer;
1425 const gchar *type_name;
1427 gchar *default_value;
1429 if (G_TYPE_IS_OBJECT (object_type))
1431 class = g_type_class_peek (object_type);
1435 properties = g_object_class_list_properties (class, &n_properties);
1437 #if GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 3)
1438 else if (G_TYPE_IS_INTERFACE (object_type))
1440 class = g_type_default_interface_ref (object_type);
1445 properties = g_object_interface_list_properties (class, &n_properties);
1451 object_class_name = g_type_name (object_type);
1457 qsort (properties, n_properties, sizeof (GParamSpec *), compare_param_specs);
1458 for (arg = 0; arg < n_properties; arg++)
1460 GParamSpec *spec = properties[arg];
1461 const gchar *nick, *blurb, *dot;
1463 if (spec->owner_type != object_type)
1467 /* We use one-character flags for simplicity. */
1468 if (child_prop && !style_prop)
1472 if (spec->flags & G_PARAM_READABLE)
1474 if (spec->flags & G_PARAM_WRITABLE)
1476 if (spec->flags & G_PARAM_CONSTRUCT)
1478 if (spec->flags & G_PARAM_CONSTRUCT_ONLY)
1482 nick = g_param_spec_get_nick (spec);
1483 blurb = g_param_spec_get_blurb (spec);
1487 int str_len = strlen (blurb);
1488 if (str_len > 0 && blurb[str_len - 1] != '.')
1492 type_desc = describe_type (spec);
1493 default_value = describe_default (spec);
1494 type_name = get_type_name (spec->value_type, &is_pointer);
1495 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",
1496 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);
1498 g_free (default_value);
1501 g_free (properties);
1503 #ifdef GTK_IS_CONTAINER_CLASS
1504 if (!child_prop && GTK_IS_CONTAINER_CLASS (class)) {
1505 properties = gtk_container_class_list_child_properties (class, &n_properties);
1511 #ifdef GTK_IS_CELL_AREA_CLASS
1512 if (!child_prop && GTK_IS_CELL_AREA_CLASS (class)) {
1513 properties = gtk_cell_area_class_list_cell_properties (class, &n_properties);
1519 #ifdef GTK_IS_WIDGET_CLASS
1520 #if GTK_CHECK_VERSION(2,1,0)
1521 if (!style_prop && GTK_IS_WIDGET_CLASS (class)) {
1522 properties = gtk_widget_class_list_style_properties (GTK_WIDGET_CLASS (class), &n_properties);
1536 # Compile and run our file
1538 $CC = $ENV{CC} ? $ENV{CC} : "gcc";
1539 $LD = $ENV{LD} ? $ENV{LD} : $CC;
1540 $CFLAGS = $ENV{CFLAGS} ? "$ENV{CFLAGS}" : "";
1541 $LDFLAGS = $ENV{LDFLAGS} ? $ENV{LDFLAGS} : "";
1544 if ($CC =~ /libtool/) {
1545 $o_file = "$MODULE-scan.lo"
1547 $o_file = "$MODULE-scan.o"
1550 print "gtk-doc: Compiling scanner\n";
1551 $command = "$CC $CFLAGS -c -o $o_file $MODULE-scan.c";
1552 system($command) == 0 or die "Compilation of scanner failed: $!\n";
1554 print "gtk-doc: Linking scanner\n";
1555 $command = "$LD -o $MODULE-scan $o_file $LDFLAGS";
1556 system($command) == 0 or die "Linking of scanner failed: $!\n";
1558 print "gtk-doc: Running scanner $MODULE-scan\n";
1559 system("sh -c ./$MODULE-scan") == 0 or die "Scan failed: $!\n";
1561 if (!defined($ENV{"GTK_DOC_KEEP_INTERMEDIATE"})) {
1562 unlink "./$MODULE-scan.c", "./$MODULE-scan.o", "./$MODULE-scan.lo", "./$MODULE-scan";
1565 #&UpdateFileIfChanged ($old_signals_filename, $new_signals_filename, 0);
1566 &UpdateFileIfChanged ($old_hierarchy_filename, $new_hierarchy_filename, 0);
1567 &UpdateFileIfChanged ($old_interfaces_filename, $new_interfaces_filename, 0);
1568 &UpdateFileIfChanged ($old_prerequisites_filename, $new_prerequisites_filename, 0);
1569 #&UpdateFileIfChanged ($old_args_filename, $new_args_filename, 0);