4 # gtk-doc - GTK DocBook documentation generator.
5 # Copyright (C) 1998 Damon Chaplin
6 # 2007-2016 Stefan Sauer
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 # This gets information about object hierarchies and signals
25 # by compiling a small C program. CFLAGS and LDFLAGS must be
26 # set appropriately before running this script.
32 push @INC, '@PACKAGE_DATA_DIR@';
33 require "gtkdoc-common.pl";
37 # name of documentation module
45 my $TYPE_INIT_FUNC="#if !GLIB_CHECK_VERSION(2,35,0)\n g_type_init();\n #endif\n g_type_class_ref(G_TYPE_OBJECT)";
46 my $QUERY_CHILD_PROPERTIES;
54 # --nogtkinit is deprecated, as it is the default now anyway.
55 my %optctl = (module => \$MODULE,
56 types => \$TYPES_FILE,
57 nogtkinit => \$NO_GTK_INIT,
58 'type-init-func' => \$TYPE_INIT_FUNC,
59 'query-child-properties' => \$QUERY_CHILD_PROPERTIES,
60 'output-dir' => \$OUTPUT_DIR,
64 'ldflags' => \$LDFLAGS,
66 'verbose' => \$VERBOSE,
67 'version' => \$PRINT_VERSION,
68 'help' => \$PRINT_HELP);
70 GetOptions(\%optctl, "module=s", "types:s", "output-dir:s", "nogtkinit", "type-init-func:s", "query-child-properties:s", "cc:s", "ld:s", "run:s", "cflags:s", "ldflags:s", "verbose", "version", "help");
73 # Do nothing. This just avoids a warning.
74 # the option is not used anymore
88 gtkdoc-scangobj version @VERSION@ - introspect g-objects
90 --module=MODULE_NAME Name of the doc module being parsed
91 --types=FILE The name of the file to store the types in
92 --type-init-func=FUNC The init function to call instead of g_type_init()
93 --query-child-properties=FUNC A function that returns a list of child
94 properties for a class
95 --output-dir=DIRNAME The directory where the results are stored
96 --cc=COMPILER The compiler to use
97 --ld=LINKER The linker to use
98 --run=RUN Command for running the scanner
99 --cflags=CFLAGS Compiler flags
100 --ldflags=LDFLAGS Linker flags
101 --verbose Print extra output while processing
102 --version Print the version of this program
103 --help Print this help
108 $OUTPUT_DIR = $OUTPUT_DIR ? $OUTPUT_DIR : ".";
110 $TYPES_FILE = $TYPES_FILE ? $TYPES_FILE : "$OUTPUT_DIR/$MODULE.types";
112 open (TYPES, $TYPES_FILE) || die "Cannot open $TYPES_FILE: $!\n";
113 open (OUTPUT, ">$MODULE-scan.c") || die "Cannot open $MODULE-scan.c: $!\n";
115 my $old_signals_filename = "$OUTPUT_DIR/$MODULE.signals";
116 my $new_signals_filename = "$OUTPUT_DIR/$MODULE.signals.new";
117 my $old_hierarchy_filename = "$OUTPUT_DIR/$MODULE.hierarchy";
118 my $new_hierarchy_filename = "$OUTPUT_DIR/$MODULE.hierarchy.new";
119 my $old_interfaces_filename = "$OUTPUT_DIR/$MODULE.interfaces";
120 my $new_interfaces_filename = "$OUTPUT_DIR/$MODULE.interfaces.new";
121 my $old_prerequisites_filename = "$OUTPUT_DIR/$MODULE.prerequisites";
122 my $new_prerequisites_filename = "$OUTPUT_DIR/$MODULE.prerequisites.new";
123 my $old_args_filename = "$OUTPUT_DIR/$MODULE.args";
124 my $new_args_filename = "$OUTPUT_DIR/$MODULE.args.new";
126 # generate a C program to scan the types
129 my $forward_decls = "";
136 } elsif (/^gnome_keyring_item_info_get_type$/) {
137 # HACK: This isn't really a GObject type so skip it.
145 $get_types .= " object_types[i++] = $_ ();\n";
146 $forward_decls .= "extern GType $_ (void);\n";
156 #include <glib-object.h>
161 print OUTPUT $includes;
163 print OUTPUT $forward_decls;
166 if ($QUERY_CHILD_PROPERTIES) {
168 extern GParamSpec** $QUERY_CHILD_PROPERTIES (gpointer class, guint *n_properties);
174 #ifdef GTK_IS_WIDGET_CLASS
177 static GType object_types[$ntypes];
180 get_object_types (void)
182 gpointer g_object_class;
186 object_types[i] = G_TYPE_INVALID;
188 /* reference the GObjectClass to initialize the param spec pool
189 * potentially needed by interfaces. See http://bugs.gnome.org/571820 */
190 g_object_class = g_type_class_ref (G_TYPE_OBJECT);
192 /* Need to make sure all the types are loaded in and initialize
193 * their signals and properties.
195 for (i=0; object_types[i]; i++) {
196 if (G_TYPE_IS_CLASSED (object_types[i]))
197 g_type_class_ref (object_types[i]);
198 if (G_TYPE_IS_INTERFACE (object_types[i]))
199 g_type_default_interface_ref (object_types[i]);
202 g_type_class_unref (g_object_class);
208 * This uses GObject type functions to output signal prototypes and the object
212 /* The output files */
213 const gchar *signals_filename = "$new_signals_filename";
214 const gchar *hierarchy_filename = "$new_hierarchy_filename";
215 const gchar *interfaces_filename = "$new_interfaces_filename";
216 const gchar *prerequisites_filename = "$new_prerequisites_filename";
217 const gchar *args_filename = "$new_args_filename";
219 static void output_signals (void);
220 static void output_object_signals (FILE *fp,
222 static void output_object_signal (FILE *fp,
223 const gchar *object_class_name,
225 static const gchar * get_type_name (GType type,
226 gboolean * is_pointer);
227 static void output_object_hierarchy (void);
228 static void output_hierarchy (FILE *fp,
232 static void output_object_interfaces (void);
233 static void output_interfaces (FILE *fp,
236 static void output_interface_prerequisites (void);
237 static void output_prerequisites (FILE *fp,
240 static void output_args (void);
241 static void output_object_args (FILE *fp, GType object_type);
244 main (int argc, char *argv[])
251 output_object_hierarchy ();
252 output_object_interfaces ();
253 output_interface_prerequisites ();
260 output_signals (void)
265 fp = fopen (signals_filename, "w");
267 g_warning ("Couldn't open output file: %s : %s", signals_filename, g_strerror(errno));
271 for (i = 0; object_types[i]; i++)
272 output_object_signals (fp, object_types[i]);
278 compare_signals (const void *a, const void *b)
280 const guint *signal_a = a;
281 const guint *signal_b = b;
283 return strcmp (g_signal_name (*signal_a), g_signal_name (*signal_b));
286 /* This outputs all the signals of one object. */
288 output_object_signals (FILE *fp, GType object_type)
290 const gchar *object_class_name;
291 guint *signals, n_signals;
294 if (G_TYPE_IS_INSTANTIATABLE (object_type) ||
295 G_TYPE_IS_INTERFACE (object_type)) {
297 object_class_name = g_type_name (object_type);
299 signals = g_signal_list_ids (object_type, &n_signals);
300 qsort (signals, n_signals, sizeof (guint), compare_signals);
302 for (sig = 0; sig < n_signals; sig++) {
303 output_object_signal (fp, object_class_name, signals[sig]);
309 /* This outputs one signal. */
311 output_object_signal (FILE *fp,
312 const gchar *object_name,
315 GSignalQuery query_info;
316 const gchar *type_name, *ret_type, *object_arg, *arg_name;
317 gchar *pos, *object_arg_lower;
321 gint param_num, widget_num, event_num, callback_num;
323 gchar signal_name[128];
326 /* g_print ("Object: %s Signal: %u\\n", object_name, signal_id);*/
329 widget_num = event_num = callback_num = 0;
331 g_signal_query (signal_id, &query_info);
333 /* Output the signal object type and the argument name. We assume the
334 * type is a pointer - I think that is OK. We remove "Gtk" or "Gnome" and
335 * convert to lower case for the argument name. */
337 sprintf (pos, "%s ", object_name);
340 /* Try to come up with a sensible variable name for the first arg
341 * It chops off 2 know prefixes :/ and makes the name lowercase
342 * It should replace lowercase -> uppercase with '_'
343 * GFileMonitor -> file_monitor
344 * GIOExtensionPoint -> extension_point
345 * GtkTreeView -> tree_view
346 * if 2nd char is upper case too
347 * search for first lower case and go back one char
349 * search for next upper case
351 if (!strncmp (object_name, "Gtk", 3))
352 object_arg = object_name + 3;
353 else if (!strncmp (object_name, "Gnome", 5))
354 object_arg = object_name + 5;
356 object_arg = object_name;
358 object_arg_lower = g_ascii_strdown (object_arg, -1);
359 sprintf (pos, "*%s\\n", object_arg_lower);
361 if (!strncmp (object_arg_lower, "widget", 6))
363 g_free(object_arg_lower);
365 /* Convert signal name to use underscores rather than dashes '-'. */
366 strncpy (signal_name, query_info.signal_name, 127);
367 signal_name[127] = '\\0';
368 for (i = 0; signal_name[i]; i++) {
369 if (signal_name[i] == '-')
370 signal_name[i] = '_';
373 /* Output the signal parameters. */
374 for (param = 0; param < query_info.n_params; param++) {
375 type_name = get_type_name (query_info.param_types[param] & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
377 /* Most arguments to the callback are called "arg1", "arg2", etc.
378 GtkWidgets are called "widget", "widget2", ...
379 GtkCallbacks are called "callback", "callback2", ... */
380 if (!strcmp (type_name, "GtkWidget")) {
382 arg_num = &widget_num;
384 else if (!strcmp (type_name, "GtkCallback")
385 || !strcmp (type_name, "GtkCCallback")) {
386 arg_name = "callback";
387 arg_num = &callback_num;
391 arg_num = ¶m_num;
393 sprintf (pos, "%s ", type_name);
396 if (!arg_num || *arg_num == 0)
397 sprintf (pos, "%s%s\\n", is_pointer ? "*" : " ", arg_name);
399 sprintf (pos, "%s%s%i\\n", is_pointer ? "*" : " ", arg_name,
412 /* We use one-character flags for simplicity. */
413 if (query_info.signal_flags & G_SIGNAL_RUN_FIRST)
415 if (query_info.signal_flags & G_SIGNAL_RUN_LAST)
417 if (query_info.signal_flags & G_SIGNAL_RUN_CLEANUP)
419 if (query_info.signal_flags & G_SIGNAL_NO_RECURSE)
421 if (query_info.signal_flags & G_SIGNAL_DETAILED)
423 if (query_info.signal_flags & G_SIGNAL_ACTION)
425 if (query_info.signal_flags & G_SIGNAL_NO_HOOKS)
429 /* Output the return type and function name. */
430 ret_type = get_type_name (query_info.return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
433 "<SIGNAL>\\n<NAME>%s::%s</NAME>\\n<RETURNS>%s%s</RETURNS>\\n<FLAGS>%s</FLAGS>\\n%s</SIGNAL>\\n\\n",
434 object_name, query_info.signal_name, ret_type, is_pointer ? "*" : "", flags, buffer);
438 /* Returns the type name to use for a signal argument or return value, given
439 the GtkType from the signal info. It also sets is_pointer to TRUE if the
440 argument needs a '*' since it is a pointer. */
442 get_type_name (GType type, gboolean * is_pointer)
444 const gchar *type_name;
447 type_name = g_type_name (type);
461 /* These all have normal C type names so they are OK. */
465 /* A GtkString is really a gchar*. */
471 /* We use a gint for both of these. Hopefully a subtype with a decent
472 name will be registered and used instead, as GTK+ does itself. */
476 /* The boxed type shouldn't be used itself, only subtypes. Though we
477 return 'gpointer' just in case. */
481 /* A GParam is really a GParamSpec*. */
485 #if GLIB_CHECK_VERSION (2, 25, 9)
495 /* For all GObject subclasses we can use the class name with a "*",
496 e.g. 'GtkWidget *'. */
497 if (g_type_is_a (type, G_TYPE_OBJECT))
500 /* Also catch non GObject root types */
501 if (G_TYPE_IS_CLASSED (type))
504 /* All boxed subtypes will be pointers as well. */
505 /* Exception: GStrv */
506 if (g_type_is_a (type, G_TYPE_BOXED) &&
507 !g_type_is_a (type, G_TYPE_STRV))
510 /* All pointer subtypes will be pointers as well. */
511 if (g_type_is_a (type, G_TYPE_POINTER))
514 /* But enums are not */
515 if (g_type_is_a (type, G_TYPE_ENUM) ||
516 g_type_is_a (type, G_TYPE_FLAGS))
523 /* This outputs the hierarchy of all objects which have been initialized,
524 i.e. by calling their XXX_get_type() initialization function. */
526 output_object_hierarchy (void)
531 GType root_types[$ntypes] = { G_TYPE_INVALID, };
533 fp = fopen (hierarchy_filename, "w");
535 g_warning ("Couldn't open output file: %s : %s", hierarchy_filename, g_strerror(errno));
538 output_hierarchy (fp, G_TYPE_OBJECT, 0);
539 output_hierarchy (fp, G_TYPE_INTERFACE, 0);
541 for (i=0; object_types[i]; i++) {
542 root = object_types[i];
543 while ((type = g_type_parent (root))) {
546 if ((root != G_TYPE_OBJECT) && (root != G_TYPE_INTERFACE)) {
547 for (j=0; root_types[j]; j++) {
548 if (root == root_types[j]) {
549 root = G_TYPE_INVALID; break;
553 root_types[j] = root;
554 output_hierarchy (fp, root, 0);
562 /* This is called recursively to output the hierarchy of a object. */
564 output_hierarchy (FILE *fp,
575 for (i = 0; i < level; i++)
577 fprintf (fp, "%s\\n", g_type_name (type));
579 children = g_type_children (type, &n_children);
581 for (i=0; i < n_children; i++)
582 output_hierarchy (fp, children[i], level + 1);
587 static void output_object_interfaces (void)
592 fp = fopen (interfaces_filename, "w");
594 g_warning ("Couldn't open output file: %s : %s", interfaces_filename, g_strerror(errno));
597 output_interfaces (fp, G_TYPE_OBJECT);
599 for (i = 0; object_types[i]; i++) {
600 if (!g_type_parent (object_types[i]) &&
601 (object_types[i] != G_TYPE_OBJECT) &&
602 G_TYPE_IS_INSTANTIATABLE (object_types[i])) {
603 output_interfaces (fp, object_types[i]);
610 output_interfaces (FILE *fp,
614 GType *children, *interfaces;
615 guint n_children, n_interfaces;
620 interfaces = g_type_interfaces (type, &n_interfaces);
622 if (n_interfaces > 0) {
623 fprintf (fp, "%s", g_type_name (type));
624 for (i=0; i < n_interfaces; i++)
625 fprintf (fp, " %s", g_type_name (interfaces[i]));
630 children = g_type_children (type, &n_children);
632 for (i=0; i < n_children; i++)
633 output_interfaces (fp, children[i]);
638 static void output_interface_prerequisites (void)
642 fp = fopen (prerequisites_filename, "w");
644 g_warning ("Couldn't open output file: %s : %s", prerequisites_filename, g_strerror(errno));
647 output_prerequisites (fp, G_TYPE_INTERFACE);
652 output_prerequisites (FILE *fp,
655 #if GLIB_CHECK_VERSION(2,1,0)
657 GType *children, *prerequisites;
658 guint n_children, n_prerequisites;
663 prerequisites = g_type_interface_prerequisites (type, &n_prerequisites);
665 if (n_prerequisites > 0) {
666 fprintf (fp, "%s", g_type_name (type));
667 for (i=0; i < n_prerequisites; i++)
668 fprintf (fp, " %s", g_type_name (prerequisites[i]));
671 g_free (prerequisites);
673 children = g_type_children (type, &n_children);
675 for (i=0; i < n_children; i++)
676 output_prerequisites (fp, children[i]);
688 fp = fopen (args_filename, "w");
690 g_warning ("Couldn't open output file: %s : %s", args_filename, g_strerror(errno));
694 for (i = 0; object_types[i]; i++) {
695 output_object_args (fp, object_types[i]);
702 compare_param_specs (const void *a, const void *b)
704 GParamSpec *spec_a = *(GParamSpec **)a;
705 GParamSpec *spec_b = *(GParamSpec **)b;
707 return strcmp (g_param_spec_get_name (spec_a), g_param_spec_get_name (spec_b));
710 /* Its common to have unsigned properties restricted
711 * to the signed range. Therefore we make this look
712 * a bit nicer by spelling out the max constants.
715 /* Don't use "==" with floats, it might trigger a gcc warning. */
716 #define GTKDOC_COMPARE_FLOAT(x, y) (x <= y && x >= y)
719 describe_double_constant (gdouble value)
723 if (GTKDOC_COMPARE_FLOAT (value, G_MAXDOUBLE))
724 desc = g_strdup ("G_MAXDOUBLE");
725 else if (GTKDOC_COMPARE_FLOAT (value, G_MINDOUBLE))
726 desc = g_strdup ("G_MINDOUBLE");
727 else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXDOUBLE))
728 desc = g_strdup ("-G_MAXDOUBLE");
729 else if (GTKDOC_COMPARE_FLOAT (value, G_MAXFLOAT))
730 desc = g_strdup ("G_MAXFLOAT");
731 else if (GTKDOC_COMPARE_FLOAT (value, G_MINFLOAT))
732 desc = g_strdup ("G_MINFLOAT");
733 else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXFLOAT))
734 desc = g_strdup ("-G_MAXFLOAT");
736 /* make sure floats are output with a decimal dot irrespective of
737 * current locale. Use formatd since we want human-readable numbers
738 * and do not need the exact same bit representation when deserialising */
739 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
740 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g", value);
747 describe_signed_constant (gsize size, gint64 value)
753 if (sizeof (int) == 2) {
754 if (value == G_MAXINT)
755 desc = g_strdup ("G_MAXINT");
756 else if (value == G_MININT)
757 desc = g_strdup ("G_MININT");
761 if (sizeof (int) == 4) {
762 if (value == G_MAXINT)
763 desc = g_strdup ("G_MAXINT");
764 else if (value == G_MININT)
765 desc = g_strdup ("G_MININT");
767 if (value == G_MAXLONG)
768 desc = g_strdup ("G_MAXLONG");
769 else if (value == G_MINLONG)
770 desc = g_strdup ("G_MINLONG");
773 if (value == G_MAXINT64)
774 desc = g_strdup ("G_MAXINT64");
775 else if (value == G_MININT64)
776 desc = g_strdup ("G_MININT64");
782 desc = g_strdup_printf ("%" G_GINT64_FORMAT, value);
788 describe_unsigned_constant (gsize size, guint64 value)
794 if (sizeof (int) == 2) {
795 if (value == (guint64)G_MAXINT)
796 desc = g_strdup ("G_MAXINT");
797 else if (value == G_MAXUINT)
798 desc = g_strdup ("G_MAXUINT");
802 if (sizeof (int) == 4) {
803 if (value == (guint64)G_MAXINT)
804 desc = g_strdup ("G_MAXINT");
805 else if (value == G_MAXUINT)
806 desc = g_strdup ("G_MAXUINT");
808 if (value == (guint64)G_MAXLONG)
809 desc = g_strdup ("G_MAXLONG");
810 else if (value == G_MAXULONG)
811 desc = g_strdup ("G_MAXULONG");
814 if (value == G_MAXINT64)
815 desc = g_strdup ("G_MAXINT64");
816 else if (value == G_MAXUINT64)
817 desc = g_strdup ("G_MAXUINT64");
823 desc = g_strdup_printf ("%" G_GUINT64_FORMAT, value);
829 describe_type (GParamSpec *spec)
835 if (G_IS_PARAM_SPEC_CHAR (spec)) {
836 GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
838 lower = describe_signed_constant (sizeof(gchar), pspec->minimum);
839 upper = describe_signed_constant (sizeof(gchar), pspec->maximum);
840 if (pspec->minimum == G_MININT8 && pspec->maximum == G_MAXINT8)
841 desc = g_strdup ("");
842 else if (pspec->minimum == G_MININT8)
843 desc = g_strdup_printf ("<= %s", upper);
844 else if (pspec->maximum == G_MAXINT8)
845 desc = g_strdup_printf (">= %s", lower);
847 desc = g_strdup_printf ("[%s,%s]", lower, upper);
851 else if (G_IS_PARAM_SPEC_UCHAR (spec)) {
852 GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
854 lower = describe_unsigned_constant (sizeof(guchar), pspec->minimum);
855 upper = describe_unsigned_constant (sizeof(guchar), pspec->maximum);
856 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT8)
857 desc = g_strdup ("");
858 else if (pspec->minimum == 0)
859 desc = g_strdup_printf ("<= %s", upper);
860 else if (pspec->maximum == G_MAXUINT8)
861 desc = g_strdup_printf (">= %s", lower);
863 desc = g_strdup_printf ("[%s,%s]", lower, upper);
867 else if (G_IS_PARAM_SPEC_INT (spec)) {
868 GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
870 lower = describe_signed_constant (sizeof(gint), pspec->minimum);
871 upper = describe_signed_constant (sizeof(gint), pspec->maximum);
872 if (pspec->minimum == G_MININT && pspec->maximum == G_MAXINT)
873 desc = g_strdup ("");
874 else if (pspec->minimum == G_MININT)
875 desc = g_strdup_printf ("<= %s", upper);
876 else if (pspec->maximum == G_MAXINT)
877 desc = g_strdup_printf (">= %s", lower);
879 desc = g_strdup_printf ("[%s,%s]", lower, upper);
883 else if (G_IS_PARAM_SPEC_UINT (spec)) {
884 GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
886 lower = describe_unsigned_constant (sizeof(guint), pspec->minimum);
887 upper = describe_unsigned_constant (sizeof(guint), pspec->maximum);
888 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT)
889 desc = g_strdup ("");
890 else if (pspec->minimum == 0)
891 desc = g_strdup_printf ("<= %s", upper);
892 else if (pspec->maximum == G_MAXUINT)
893 desc = g_strdup_printf (">= %s", lower);
895 desc = g_strdup_printf ("[%s,%s]", lower, upper);
899 else if (G_IS_PARAM_SPEC_LONG (spec)) {
900 GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
902 lower = describe_signed_constant (sizeof(glong), pspec->minimum);
903 upper = describe_signed_constant (sizeof(glong), pspec->maximum);
904 if (pspec->minimum == G_MINLONG && pspec->maximum == G_MAXLONG)
905 desc = g_strdup ("");
906 else if (pspec->minimum == G_MINLONG)
907 desc = g_strdup_printf ("<= %s", upper);
908 else if (pspec->maximum == G_MAXLONG)
909 desc = g_strdup_printf (">= %s", lower);
911 desc = g_strdup_printf ("[%s,%s]", lower, upper);
915 else if (G_IS_PARAM_SPEC_ULONG (spec)) {
916 GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
918 lower = describe_unsigned_constant (sizeof(gulong), pspec->minimum);
919 upper = describe_unsigned_constant (sizeof(gulong), pspec->maximum);
920 if (pspec->minimum == 0 && pspec->maximum == G_MAXULONG)
921 desc = g_strdup ("");
922 else if (pspec->minimum == 0)
923 desc = g_strdup_printf ("<= %s", upper);
924 else if (pspec->maximum == G_MAXULONG)
925 desc = g_strdup_printf (">= %s", lower);
927 desc = g_strdup_printf ("[%s,%s]", lower, upper);
931 else if (G_IS_PARAM_SPEC_INT64 (spec)) {
932 GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
934 lower = describe_signed_constant (sizeof(gint64), pspec->minimum);
935 upper = describe_signed_constant (sizeof(gint64), pspec->maximum);
936 if (pspec->minimum == G_MININT64 && pspec->maximum == G_MAXINT64)
937 desc = g_strdup ("");
938 else if (pspec->minimum == G_MININT64)
939 desc = g_strdup_printf ("<= %s", upper);
940 else if (pspec->maximum == G_MAXINT64)
941 desc = g_strdup_printf (">= %s", lower);
943 desc = g_strdup_printf ("[%s,%s]", lower, upper);
947 else if (G_IS_PARAM_SPEC_UINT64 (spec)) {
948 GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
950 lower = describe_unsigned_constant (sizeof(guint64), pspec->minimum);
951 upper = describe_unsigned_constant (sizeof(guint64), pspec->maximum);
952 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT64)
953 desc = g_strdup ("");
954 else if (pspec->minimum == 0)
955 desc = g_strdup_printf ("<= %s", upper);
956 else if (pspec->maximum == G_MAXUINT64)
957 desc = g_strdup_printf (">= %s", lower);
959 desc = g_strdup_printf ("[%s,%s]", lower, upper);
963 else if (G_IS_PARAM_SPEC_FLOAT (spec)) {
964 GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
966 lower = describe_double_constant (pspec->minimum);
967 upper = describe_double_constant (pspec->maximum);
968 if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXFLOAT)) {
969 if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
970 desc = g_strdup ("");
972 desc = g_strdup_printf ("<= %s", upper);
974 else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
975 desc = g_strdup_printf (">= %s", lower);
977 desc = g_strdup_printf ("[%s,%s]", lower, upper);
981 else if (G_IS_PARAM_SPEC_DOUBLE (spec)) {
982 GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
984 lower = describe_double_constant (pspec->minimum);
985 upper = describe_double_constant (pspec->maximum);
986 if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXDOUBLE)) {
987 if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
988 desc = g_strdup ("");
990 desc = g_strdup_printf ("<= %s", upper);
992 else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
993 desc = g_strdup_printf (">= %s", lower);
995 desc = g_strdup_printf ("[%s,%s]", lower, upper);
999 #if GLIB_CHECK_VERSION (2, 12, 0)
1000 else if (G_IS_PARAM_SPEC_GTYPE (spec)) {
1001 GParamSpecGType *pspec = G_PARAM_SPEC_GTYPE (spec);
1002 gboolean is_pointer;
1004 desc = g_strdup (get_type_name (pspec->is_a_type, &is_pointer));
1007 #if GLIB_CHECK_VERSION (2, 25, 9)
1008 else if (G_IS_PARAM_SPEC_VARIANT (spec)) {
1009 GParamSpecVariant *pspec = G_PARAM_SPEC_VARIANT (spec);
1010 gchar *variant_type;
1012 variant_type = g_variant_type_dup_string (pspec->type);
1013 desc = g_strdup_printf ("GVariant<%s>", variant_type);
1014 g_free (variant_type);
1018 desc = g_strdup ("");
1025 describe_default (GParamSpec *spec)
1029 if (G_IS_PARAM_SPEC_CHAR (spec)) {
1030 GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
1032 desc = g_strdup_printf ("%d", pspec->default_value);
1034 else if (G_IS_PARAM_SPEC_UCHAR (spec)) {
1035 GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
1037 desc = g_strdup_printf ("%u", pspec->default_value);
1039 else if (G_IS_PARAM_SPEC_BOOLEAN (spec)) {
1040 GParamSpecBoolean *pspec = G_PARAM_SPEC_BOOLEAN (spec);
1042 desc = g_strdup_printf ("%s", pspec->default_value ? "TRUE" : "FALSE");
1044 else if (G_IS_PARAM_SPEC_INT (spec)) {
1045 GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
1047 desc = g_strdup_printf ("%d", pspec->default_value);
1049 else if (G_IS_PARAM_SPEC_UINT (spec)) {
1050 GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
1052 desc = g_strdup_printf ("%u", pspec->default_value);
1054 else if (G_IS_PARAM_SPEC_LONG (spec)) {
1055 GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
1057 desc = g_strdup_printf ("%ld", pspec->default_value);
1059 else if (G_IS_PARAM_SPEC_LONG (spec)) {
1060 GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
1062 desc = g_strdup_printf ("%lu", pspec->default_value);
1064 else if (G_IS_PARAM_SPEC_INT64 (spec)) {
1065 GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
1067 desc = g_strdup_printf ("%" G_GINT64_FORMAT, pspec->default_value);
1069 else if (G_IS_PARAM_SPEC_UINT64 (spec))
1071 GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
1073 desc = g_strdup_printf ("%" G_GUINT64_FORMAT, pspec->default_value);
1075 else if (G_IS_PARAM_SPEC_UNICHAR (spec)) {
1076 GParamSpecUnichar *pspec = G_PARAM_SPEC_UNICHAR (spec);
1078 if (g_unichar_isprint (pspec->default_value))
1079 desc = g_strdup_printf ("'%c'", pspec->default_value);
1081 desc = g_strdup_printf ("%u", pspec->default_value);
1083 else if (G_IS_PARAM_SPEC_ENUM (spec)) {
1084 GParamSpecEnum *pspec = G_PARAM_SPEC_ENUM (spec);
1086 GEnumValue *value = g_enum_get_value (pspec->enum_class, pspec->default_value);
1088 desc = g_strdup_printf ("%s", value->value_name);
1090 desc = g_strdup_printf ("%d", pspec->default_value);
1092 else if (G_IS_PARAM_SPEC_FLAGS (spec)) {
1093 GParamSpecFlags *pspec = G_PARAM_SPEC_FLAGS (spec);
1094 guint default_value;
1097 default_value = pspec->default_value;
1098 acc = g_string_new ("");
1100 while (default_value) {
1101 GFlagsValue *value = g_flags_get_first_value (pspec->flags_class, default_value);
1107 g_string_append (acc, " | ");
1108 g_string_append (acc, value->value_name);
1110 default_value &= ~value->value;
1113 if (default_value == 0)
1114 desc = g_string_free (acc, FALSE);
1116 desc = g_strdup_printf ("%d", pspec->default_value);
1117 g_string_free (acc, TRUE);
1120 else if (G_IS_PARAM_SPEC_FLOAT (spec)) {
1121 GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
1123 /* make sure floats are output with a decimal dot irrespective of
1124 * current locale. Use formatd since we want human-readable numbers
1125 * and do not need the exact same bit representation when deserialising */
1126 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
1127 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
1128 pspec->default_value);
1130 else if (G_IS_PARAM_SPEC_DOUBLE (spec)) {
1131 GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
1133 /* make sure floats are output with a decimal dot irrespective of
1134 * current locale. Use formatd since we want human-readable numbers
1135 * and do not need the exact same bit representation when deserialising */
1136 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
1137 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
1138 pspec->default_value);
1140 else if (G_IS_PARAM_SPEC_STRING (spec)) {
1141 GParamSpecString *pspec = G_PARAM_SPEC_STRING (spec);
1143 if (pspec->default_value) {
1144 gchar *esc = g_strescape (pspec->default_value, NULL);
1145 desc = g_strdup_printf ("\\"%s\\"", esc);
1149 desc = g_strdup_printf ("NULL");
1151 #if GLIB_CHECK_VERSION (2, 25, 9)
1152 else if (G_IS_PARAM_SPEC_VARIANT (spec)) {
1153 GParamSpecVariant *pspec = G_PARAM_SPEC_VARIANT (spec);
1155 if (pspec->default_value)
1156 desc = g_variant_print (pspec->default_value, TRUE);
1158 desc = g_strdup ("NULL");
1162 desc = g_strdup ("");
1170 output_object_args (FILE *fp, GType object_type)
1173 const gchar *object_class_name;
1175 gchar flags[16], *pos;
1176 GParamSpec **properties;
1178 gboolean child_prop;
1179 gboolean style_prop;
1180 gboolean is_pointer;
1181 const gchar *type_name;
1183 gchar *default_value;
1185 if (G_TYPE_IS_OBJECT (object_type)) {
1186 class = g_type_class_peek (object_type);
1190 properties = g_object_class_list_properties (class, &n_properties);
1192 #if GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 3)
1193 else if (G_TYPE_IS_INTERFACE (object_type)) {
1194 class = g_type_default_interface_ref (object_type);
1199 properties = g_object_interface_list_properties (class, &n_properties);
1205 object_class_name = g_type_name (object_type);
1211 qsort (properties, n_properties, sizeof (GParamSpec *), compare_param_specs);
1212 for (arg = 0; arg < n_properties; arg++) {
1213 GParamSpec *spec = properties[arg];
1214 const gchar *nick, *blurb, *dot;
1216 if (spec->owner_type != object_type)
1220 /* We use one-character flags for simplicity. */
1221 if (child_prop && !style_prop)
1225 if (spec->flags & G_PARAM_READABLE)
1227 if (spec->flags & G_PARAM_WRITABLE)
1229 if (spec->flags & G_PARAM_CONSTRUCT)
1231 if (spec->flags & G_PARAM_CONSTRUCT_ONLY)
1235 nick = g_param_spec_get_nick (spec);
1236 blurb = g_param_spec_get_blurb (spec);
1240 int str_len = strlen (blurb);
1241 if (str_len > 0 && blurb[str_len - 1] != '.')
1245 type_desc = describe_type (spec);
1246 default_value = describe_default (spec);
1247 type_name = get_type_name (spec->value_type, &is_pointer);
1248 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",
1249 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);
1251 g_free (default_value);
1254 g_free (properties);
1256 #ifdef GTK_IS_CONTAINER_CLASS
1257 if (!child_prop && GTK_IS_CONTAINER_CLASS (class)) {
1258 properties = gtk_container_class_list_child_properties (class, &n_properties);
1264 #ifdef GTK_IS_CELL_AREA_CLASS
1265 if (!child_prop && GTK_IS_CELL_AREA_CLASS (class)) {
1266 properties = gtk_cell_area_class_list_cell_properties (class, &n_properties);
1272 #ifdef GTK_IS_WIDGET_CLASS
1273 #if GTK_CHECK_VERSION(2,1,0) && !GTK_CHECK_VERSION(3,89,2)
1274 if (!style_prop && GTK_IS_WIDGET_CLASS (class)) {
1275 properties = gtk_widget_class_list_style_properties (GTK_WIDGET_CLASS (class), &n_properties);
1284 if ($QUERY_CHILD_PROPERTIES) {
1287 properties = $QUERY_CHILD_PROPERTIES (class, &n_properties);
1305 # Compile and run our file
1308 $CC = $ENV{CC} ? $ENV{CC} : "gcc";
1311 $LD = $ENV{LD} ? $ENV{LD} : $CC;
1314 $CFLAGS = $ENV{CFLAGS} ? $ENV{CFLAGS} : "";
1317 $LDFLAGS = $ENV{LDFLAGS} ? $ENV{LDFLAGS} : "";
1320 $RUN = $ENV{RUN} ? $ENV{RUN} : "";
1323 my $o_file = $CC =~ /libtool/ ? "$MODULE-scan.lo" :"$MODULE-scan.o";
1326 if (!defined($VERBOSE) or $VERBOSE eq "0") {
1327 $stdout=">/dev/null";
1331 my $command = "$CC $stdout $CFLAGS -c -o $o_file $MODULE-scan.c";
1332 system("($command)") == 0 or die "Compilation of scanner failed: $!\n";
1335 # FIXME: Can we turn off as-needed for the docs (or better fix it?)
1336 #$command = "$LD -Wl,--no-as-needed $o_file $LDFLAGS -o $MODULE-scan@EXEEXT@";
1337 $command = "$LD $stdout $o_file $LDFLAGS -o $MODULE-scan@EXEEXT@";
1338 system("($command)") == 0 or die "Linking of scanner failed: $!\n";
1340 # Running scanner $MODULE-scan ";
1341 system("($RUN ./$MODULE-scan@EXEEXT@)") == 0 or die "Scan failed: $!\n";
1344 if (!defined($ENV{"GTK_DOC_KEEP_INTERMEDIATE"})) {
1345 unlink "./$MODULE-scan.c", "./$MODULE-scan.o", "./$MODULE-scan.lo", "./$MODULE-scan@EXEEXT@";
1348 &UpdateFileIfChanged ($old_signals_filename, $new_signals_filename, 0);
1349 &UpdateFileIfChanged ($old_hierarchy_filename, $new_hierarchy_filename, 0);
1350 &UpdateFileIfChanged ($old_interfaces_filename, $new_interfaces_filename, 0);
1351 &UpdateFileIfChanged ($old_prerequisites_filename, $new_prerequisites_filename, 0);
1352 &UpdateFileIfChanged ($old_args_filename, $new_args_filename, 0);