4 # gtk-doc - GTK DocBook documentation generator.
5 # Copyright (C) 1998 Damon Chaplin
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 # This gets information about object hierarchies and signals
24 # by compiling a small C program. CFLAGS and LDFLAGS must be
25 # set appropriately before running this script.
30 push @INC, '@PACKAGE_DATA_DIR@';
31 require "gtkdoc-common.pl";
35 # name of documentation module
40 my $TYPE_INIT_FUNC="g_type_init(); g_type_class_ref(G_TYPE_OBJECT)";
41 my $QUERY_CHILD_PROPERTIES;
43 # --nogtkinit is deprecated, as it is the default now anyway.
44 %optctl = (module => \$MODULE,
45 types => \$TYPES_FILE,
46 nogtkinit => \$NO_GTK_INIT,
47 'type-init-func' => \$TYPE_INIT_FUNC,
48 'query-child-properties' => \$QUERY_CHILD_PROPERTIES,
49 'output-dir' => \$OUTPUT_DIR,
50 'version' => \$PRINT_VERSION,
51 'help' => \$PRINT_HELP);
53 GetOptions(\%optctl, "module=s", "types:s", "output-dir:s", "nogtkinit", "type-init-func:s", "query-child-properties:s", "version", "help");
56 # Do nothing. This just avoids a warning.
57 # the option is not used anymore
71 gtkdoc-scangobj version @VERSION@ - introspect g-objects
73 --module=MODULE_NAME Name of the doc module being parsed
74 --types=FILE The name of the file to store the types in
75 --type-init-func=FUNC The init function to call instead of g_type_init()
76 --query-child-properties=FUNC A function that returns a list of child
77 properties for a class
78 --output-dir=DIRNAME The directory where the results are stored
79 --version Print the version of this program
80 --help Print this help
85 $OUTPUT_DIR = $OUTPUT_DIR ? $OUTPUT_DIR : ".";
87 $TYPES_FILE = $TYPES_FILE ? $TYPES_FILE : "$OUTPUT_DIR/$MODULE.types";
89 open (TYPES, $TYPES_FILE) || die "Cannot open $TYPES_FILE: $!\n";
90 open (OUTPUT, ">$MODULE-scan.c") || die "Cannot open $MODULE-scan.c: $!\n";
92 my $old_signals_filename = "$OUTPUT_DIR/$MODULE.signals";
93 my $new_signals_filename = "$OUTPUT_DIR/$MODULE.signals.new";
94 my $old_hierarchy_filename = "$OUTPUT_DIR/$MODULE.hierarchy";
95 my $new_hierarchy_filename = "$OUTPUT_DIR/$MODULE.hierarchy.new";
96 my $old_interfaces_filename = "$OUTPUT_DIR/$MODULE.interfaces";
97 my $new_interfaces_filename = "$OUTPUT_DIR/$MODULE.interfaces.new";
98 my $old_prerequisites_filename = "$OUTPUT_DIR/$MODULE.prerequisites";
99 my $new_prerequisites_filename = "$OUTPUT_DIR/$MODULE.prerequisites.new";
100 my $old_args_filename = "$OUTPUT_DIR/$MODULE.args";
101 my $new_args_filename = "$OUTPUT_DIR/$MODULE.args.new";
103 # write a C program to scan the types
111 } elsif (/^gnome_keyring_item_info_get_type$/) {
112 # HACK: This isn't really a GObject type so skip it.
124 $ntypes = @types + 1;
131 #include <glib-object.h>
136 print OUTPUT $includes;
139 print OUTPUT "extern GType $_ (void);\n";
143 if ($QUERY_CHILD_PROPERTIES) {
145 extern GParamSpec** $QUERY_CHILD_PROPERTIES (gpointer class, guint *n_properties);
151 #ifdef GTK_IS_WIDGET_CLASS
154 GType object_types[$ntypes];
157 get_object_types (void)
159 gpointer g_object_class;
164 print OUTPUT " object_types[i++] = $_ ();\n";
170 /* reference the GObjectClass to initialize the param spec pool
171 * potentially needed by interfaces. See http://bugs.gnome.org/571820 */
172 g_object_class = g_type_class_ref (G_TYPE_OBJECT);
174 /* Need to make sure all the types are loaded in and initialize
175 * their signals and properties.
177 for (i=0; object_types[i]; i++)
179 if (G_TYPE_IS_CLASSED (object_types[i]))
180 g_type_class_ref (object_types[i]);
181 if (G_TYPE_IS_INTERFACE (object_types[i]))
182 g_type_default_interface_ref (object_types[i]);
185 g_type_class_unref (g_object_class);
191 * This uses GObject type functions to output signal prototypes and the object
195 /* The output files */
196 const gchar *signals_filename = "$new_signals_filename";
197 const gchar *hierarchy_filename = "$new_hierarchy_filename";
198 const gchar *interfaces_filename = "$new_interfaces_filename";
199 const gchar *prerequisites_filename = "$new_prerequisites_filename";
200 const gchar *args_filename = "$new_args_filename";
203 static void output_signals (void);
204 static void output_object_signals (FILE *fp,
206 static void output_object_signal (FILE *fp,
207 const gchar *object_class_name,
209 static const gchar * get_type_name (GType type,
210 gboolean * is_pointer);
211 static void output_object_hierarchy (void);
212 static void output_hierarchy (FILE *fp,
216 static void output_object_interfaces (void);
217 static void output_interfaces (FILE *fp,
220 static void output_interface_prerequisites (void);
221 static void output_prerequisites (FILE *fp,
224 static void output_args (void);
225 static void output_object_args (FILE *fp, GType object_type);
228 main (int argc, char *argv[])
235 output_object_hierarchy ();
236 output_object_interfaces ();
237 output_interface_prerequisites ();
245 output_signals (void)
250 fp = fopen (signals_filename, "w");
253 g_warning ("Couldn't open output file: %s : %s", signals_filename, g_strerror(errno));
257 for (i = 0; object_types[i]; i++)
258 output_object_signals (fp, object_types[i]);
264 compare_signals (const void *a, const void *b)
266 const guint *signal_a = a;
267 const guint *signal_b = b;
269 return strcmp (g_signal_name (*signal_a), g_signal_name (*signal_b));
272 /* This outputs all the signals of one object. */
274 output_object_signals (FILE *fp, GType object_type)
276 const gchar *object_class_name;
277 guint *signals, n_signals;
280 if (G_TYPE_IS_INSTANTIATABLE (object_type) ||
281 G_TYPE_IS_INTERFACE (object_type))
284 object_class_name = g_type_name (object_type);
286 signals = g_signal_list_ids (object_type, &n_signals);
287 qsort (signals, n_signals, sizeof (guint), compare_signals);
289 for (sig = 0; sig < n_signals; sig++)
291 output_object_signal (fp, object_class_name, signals[sig]);
298 /* This outputs one signal. */
300 output_object_signal (FILE *fp,
301 const gchar *object_name,
304 GSignalQuery query_info;
305 const gchar *type_name, *ret_type, *object_arg, *arg_name;
306 gchar *pos, *object_arg_lower;
310 gint param_num, widget_num, event_num, callback_num;
312 gchar signal_name[128];
315 /* g_print ("Object: %s Signal: %u\\n", object_name, signal_id);*/
318 widget_num = event_num = callback_num = 0;
320 g_signal_query (signal_id, &query_info);
322 /* Output the signal object type and the argument name. We assume the
323 type is a pointer - I think that is OK. We remove "Gtk" or "Gnome" and
324 convert to lower case for the argument name. */
326 sprintf (pos, "%s ", object_name);
329 /* Try to come up with a sensible variable name for the first arg
330 * It chops off 2 know prefixes :/ and makes the name lowercase
331 * It should replace lowercase -> uppercase with '_'
332 * GFileMonitor -> file_monitor
333 * GIOExtensionPoint -> extension_point
334 * GtkTreeView -> tree_view
335 * if 2nd char is upper case too
336 * search for first lower case and go back one char
338 * search for next upper case
340 if (!strncmp (object_name, "Gtk", 3))
341 object_arg = object_name + 3;
342 else if (!strncmp (object_name, "Gnome", 5))
343 object_arg = object_name + 5;
345 object_arg = object_name;
347 object_arg_lower = g_ascii_strdown (object_arg, -1);
348 sprintf (pos, "*%s\\n", object_arg_lower);
350 if (!strncmp (object_arg_lower, "widget", 6))
352 g_free(object_arg_lower);
354 /* Convert signal name to use underscores rather than dashes '-'. */
355 strncpy (signal_name, query_info.signal_name, 127);
356 signal_name[127] = '\\0';
357 for (i = 0; signal_name[i]; i++)
359 if (signal_name[i] == '-')
360 signal_name[i] = '_';
363 /* Output the signal parameters. */
364 for (param = 0; param < query_info.n_params; param++)
366 type_name = get_type_name (query_info.param_types[param] & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
368 /* Most arguments to the callback are called "arg1", "arg2", etc.
369 GtkWidgets are called "widget", "widget2", ...
370 GtkCallbacks are called "callback", "callback2", ... */
371 if (!strcmp (type_name, "GtkWidget"))
374 arg_num = &widget_num;
376 else if (!strcmp (type_name, "GtkCallback")
377 || !strcmp (type_name, "GtkCCallback"))
379 arg_name = "callback";
380 arg_num = &callback_num;
385 arg_num = ¶m_num;
387 sprintf (pos, "%s ", type_name);
390 if (!arg_num || *arg_num == 0)
391 sprintf (pos, "%s%s\\n", is_pointer ? "*" : " ", arg_name);
393 sprintf (pos, "%s%s%i\\n", is_pointer ? "*" : " ", arg_name,
407 /* We use one-character flags for simplicity. */
408 if (query_info.signal_flags & G_SIGNAL_RUN_FIRST)
410 if (query_info.signal_flags & G_SIGNAL_RUN_LAST)
412 if (query_info.signal_flags & G_SIGNAL_RUN_CLEANUP)
414 if (query_info.signal_flags & G_SIGNAL_NO_RECURSE)
416 if (query_info.signal_flags & G_SIGNAL_DETAILED)
418 if (query_info.signal_flags & G_SIGNAL_ACTION)
420 if (query_info.signal_flags & G_SIGNAL_NO_HOOKS)
424 /* Output the return type and function name. */
425 ret_type = get_type_name (query_info.return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
428 "<SIGNAL>\\n<NAME>%s::%s</NAME>\\n<RETURNS>%s%s</RETURNS>\\n<FLAGS>%s</FLAGS>\\n%s</SIGNAL>\\n\\n",
429 object_name, query_info.signal_name, ret_type, is_pointer ? "*" : "", flags, buffer);
433 /* Returns the type name to use for a signal argument or return value, given
434 the GtkType from the signal info. It also sets is_pointer to TRUE if the
435 argument needs a '*' since it is a pointer. */
437 get_type_name (GType type, gboolean * is_pointer)
439 const gchar *type_name;
442 type_name = g_type_name (type);
456 /* These all have normal C type names so they are OK. */
460 /* A GtkString is really a gchar*. */
466 /* We use a gint for both of these. Hopefully a subtype with a decent
467 name will be registered and used instead, as GTK+ does itself. */
471 /* The boxed type shouldn't be used itself, only subtypes. Though we
472 return 'gpointer' just in case. */
476 /* A GParam is really a GParamSpec*. */
480 #if GLIB_CHECK_VERSION (2, 25, 9)
490 /* For all GObject subclasses we can use the class name with a "*",
491 e.g. 'GtkWidget *'. */
492 if (g_type_is_a (type, G_TYPE_OBJECT))
495 /* Also catch non GObject root types */
496 if (G_TYPE_IS_CLASSED (type))
499 /* All boxed subtypes will be pointers as well. */
500 /* Exception: GStrv */
501 if (g_type_is_a (type, G_TYPE_BOXED) &&
502 !g_type_is_a (type, G_TYPE_STRV))
505 /* All pointer subtypes will be pointers as well. */
506 if (g_type_is_a (type, G_TYPE_POINTER))
509 /* But enums are not */
510 if (g_type_is_a (type, G_TYPE_ENUM) ||
511 g_type_is_a (type, G_TYPE_FLAGS))
518 /* This outputs the hierarchy of all objects which have been initialized,
519 i.e. by calling their XXX_get_type() initialization function. */
521 output_object_hierarchy (void)
526 GType root_types[$ntypes] = { G_TYPE_INVALID, };
528 fp = fopen (hierarchy_filename, "w");
531 g_warning ("Couldn't open output file: %s : %s", hierarchy_filename, g_strerror(errno));
534 output_hierarchy (fp, G_TYPE_OBJECT, 0);
535 output_hierarchy (fp, G_TYPE_INTERFACE, 0);
537 for (i=0; object_types[i]; i++) {
538 root = object_types[i];
539 while ((type = g_type_parent (root))) {
542 if ((root != G_TYPE_OBJECT) && (root != G_TYPE_INTERFACE)) {
543 for (j=0; root_types[j]; j++) {
544 if (root == root_types[j]) {
545 root = G_TYPE_INVALID; break;
549 root_types[j] = root;
550 output_hierarchy (fp, root, 0);
558 /* This is called recursively to output the hierarchy of a object. */
560 output_hierarchy (FILE *fp,
571 for (i = 0; i < level; i++)
573 fprintf (fp, "%s\\n", g_type_name (type));
575 children = g_type_children (type, &n_children);
577 for (i=0; i < n_children; i++)
578 output_hierarchy (fp, children[i], level + 1);
583 static void output_object_interfaces (void)
588 fp = fopen (interfaces_filename, "w");
591 g_warning ("Couldn't open output file: %s : %s", interfaces_filename, g_strerror(errno));
594 output_interfaces (fp, G_TYPE_OBJECT);
596 for (i = 0; object_types[i]; i++)
598 if (!g_type_parent (object_types[i]) &&
599 (object_types[i] != G_TYPE_OBJECT) &&
600 G_TYPE_IS_INSTANTIATABLE (object_types[i]))
602 output_interfaces (fp, object_types[i]);
609 output_interfaces (FILE *fp,
613 GType *children, *interfaces;
614 guint n_children, n_interfaces;
619 interfaces = g_type_interfaces (type, &n_interfaces);
621 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");
645 g_warning ("Couldn't open output file: %s : %s", prerequisites_filename, g_strerror(errno));
648 output_prerequisites (fp, G_TYPE_INTERFACE);
653 output_prerequisites (FILE *fp,
656 #if GLIB_CHECK_VERSION(2,1,0)
658 GType *children, *prerequisites;
659 guint n_children, n_prerequisites;
664 prerequisites = g_type_interface_prerequisites (type, &n_prerequisites);
666 if (n_prerequisites > 0)
668 fprintf (fp, "%s", g_type_name (type));
669 for (i=0; i < n_prerequisites; i++)
670 fprintf (fp, " %s", g_type_name (prerequisites[i]));
673 g_free (prerequisites);
675 children = g_type_children (type, &n_children);
677 for (i=0; i < n_children; i++)
678 output_prerequisites (fp, children[i]);
690 fp = fopen (args_filename, "w");
693 g_warning ("Couldn't open output file: %s : %s", args_filename, g_strerror(errno));
697 for (i = 0; object_types[i]; i++) {
698 output_object_args (fp, object_types[i]);
705 compare_param_specs (const void *a, const void *b)
707 GParamSpec *spec_a = *(GParamSpec **)a;
708 GParamSpec *spec_b = *(GParamSpec **)b;
710 return strcmp (g_param_spec_get_name (spec_a), g_param_spec_get_name (spec_b));
713 /* Its common to have unsigned properties restricted
714 * to the signed range. Therefore we make this look
715 * a bit nicer by spelling out the max constants.
718 /* Don't use "==" with floats, it might trigger a gcc warning. */
719 #define GTKDOC_COMPARE_FLOAT(x, y) (x <= y && x >= y)
722 describe_double_constant (gdouble value)
726 if (GTKDOC_COMPARE_FLOAT (value, G_MAXDOUBLE))
727 desc = g_strdup ("G_MAXDOUBLE");
728 else if (GTKDOC_COMPARE_FLOAT (value, G_MINDOUBLE))
729 desc = g_strdup ("G_MINDOUBLE");
730 else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXDOUBLE))
731 desc = g_strdup ("-G_MAXDOUBLE");
732 else if (GTKDOC_COMPARE_FLOAT (value, G_MAXFLOAT))
733 desc = g_strdup ("G_MAXFLOAT");
734 else if (GTKDOC_COMPARE_FLOAT (value, G_MINFLOAT))
735 desc = g_strdup ("G_MINFLOAT");
736 else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXFLOAT))
737 desc = g_strdup ("-G_MAXFLOAT");
739 /* make sure floats are output with a decimal dot irrespective of
740 * current locale. Use formatd since we want human-readable numbers
741 * and do not need the exact same bit representation when deserialising */
742 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
743 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g", value);
750 describe_signed_constant (gsize size, gint64 value)
756 if (sizeof (int) == 2) {
757 if (value == G_MAXINT)
758 desc = g_strdup ("G_MAXINT");
759 else if (value == G_MININT)
760 desc = g_strdup ("G_MININT");
761 else if (value == (gint64)G_MAXUINT)
762 desc = g_strdup ("G_MAXUINT");
766 if (sizeof (int) == 4) {
767 if (value == G_MAXINT)
768 desc = g_strdup ("G_MAXINT");
769 else if (value == G_MININT)
770 desc = g_strdup ("G_MININT");
771 else if (value == (gint64)G_MAXUINT)
772 desc = g_strdup ("G_MAXUINT");
774 if (value == G_MAXLONG)
775 desc = g_strdup ("G_MAXLONG");
776 else if (value == G_MINLONG)
777 desc = g_strdup ("G_MINLONG");
778 else if (value == (gint64)G_MAXULONG)
779 desc = g_strdup ("G_MAXULONG");
782 if (value == G_MAXINT64)
783 desc = g_strdup ("G_MAXINT64");
784 else if (value == G_MININT64)
785 desc = g_strdup ("G_MININT64");
791 desc = g_strdup_printf ("%" G_GINT64_FORMAT, value);
797 describe_unsigned_constant (gsize size, guint64 value)
803 if (sizeof (int) == 2) {
804 if (value == (guint64)G_MAXINT)
805 desc = g_strdup ("G_MAXINT");
806 else if (value == G_MAXUINT)
807 desc = g_strdup ("G_MAXUINT");
811 if (sizeof (int) == 4) {
812 if (value == (guint64)G_MAXINT)
813 desc = g_strdup ("G_MAXINT");
814 else if (value == G_MAXUINT)
815 desc = g_strdup ("G_MAXUINT");
817 if (value == (guint64)G_MAXLONG)
818 desc = g_strdup ("G_MAXLONG");
819 else if (value == G_MAXULONG)
820 desc = g_strdup ("G_MAXULONG");
823 if (value == G_MAXINT64)
824 desc = g_strdup ("G_MAXINT64");
825 else if (value == G_MAXUINT64)
826 desc = g_strdup ("G_MAXUINT64");
832 desc = g_strdup_printf ("%" G_GUINT64_FORMAT, value);
838 describe_type (GParamSpec *spec)
844 if (G_IS_PARAM_SPEC_CHAR (spec))
846 GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
848 lower = describe_signed_constant (sizeof(gchar), pspec->minimum);
849 upper = describe_signed_constant (sizeof(gchar), pspec->maximum);
850 if (pspec->minimum == G_MININT8 && pspec->maximum == G_MAXINT8)
851 desc = g_strdup ("");
852 else if (pspec->minimum == G_MININT8)
853 desc = g_strdup_printf ("<= %s", upper);
854 else if (pspec->maximum == G_MAXINT8)
855 desc = g_strdup_printf (">= %s", lower);
857 desc = g_strdup_printf ("[%s,%s]", lower, upper);
861 else if (G_IS_PARAM_SPEC_UCHAR (spec))
863 GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
865 lower = describe_unsigned_constant (sizeof(guchar), pspec->minimum);
866 upper = describe_unsigned_constant (sizeof(guchar), pspec->maximum);
867 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT8)
868 desc = g_strdup ("");
869 else if (pspec->minimum == 0)
870 desc = g_strdup_printf ("<= %s", upper);
871 else if (pspec->maximum == G_MAXUINT8)
872 desc = g_strdup_printf (">= %s", lower);
874 desc = g_strdup_printf ("[%s,%s]", lower, upper);
878 else if (G_IS_PARAM_SPEC_INT (spec))
880 GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
882 lower = describe_signed_constant (sizeof(gint), pspec->minimum);
883 upper = describe_signed_constant (sizeof(gint), pspec->maximum);
884 if (pspec->minimum == G_MININT && pspec->maximum == G_MAXINT)
885 desc = g_strdup ("");
886 else if (pspec->minimum == G_MININT)
887 desc = g_strdup_printf ("<= %s", upper);
888 else if (pspec->maximum == G_MAXINT)
889 desc = g_strdup_printf (">= %s", lower);
891 desc = g_strdup_printf ("[%s,%s]", lower, upper);
895 else if (G_IS_PARAM_SPEC_UINT (spec))
897 GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
899 lower = describe_unsigned_constant (sizeof(guint), pspec->minimum);
900 upper = describe_unsigned_constant (sizeof(guint), pspec->maximum);
901 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT)
902 desc = g_strdup ("");
903 else if (pspec->minimum == 0)
904 desc = g_strdup_printf ("<= %s", upper);
905 else if (pspec->maximum == G_MAXUINT)
906 desc = g_strdup_printf (">= %s", lower);
908 desc = g_strdup_printf ("[%s,%s]", lower, upper);
912 else if (G_IS_PARAM_SPEC_LONG (spec))
914 GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
916 lower = describe_signed_constant (sizeof(glong), pspec->minimum);
917 upper = describe_signed_constant (sizeof(glong), pspec->maximum);
918 if (pspec->minimum == G_MINLONG && pspec->maximum == G_MAXLONG)
919 desc = g_strdup ("");
920 else if (pspec->minimum == G_MINLONG)
921 desc = g_strdup_printf ("<= %s", upper);
922 else if (pspec->maximum == G_MAXLONG)
923 desc = g_strdup_printf (">= %s", lower);
925 desc = g_strdup_printf ("[%s,%s]", lower, upper);
929 else if (G_IS_PARAM_SPEC_ULONG (spec))
931 GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
933 lower = describe_unsigned_constant (sizeof(gulong), pspec->minimum);
934 upper = describe_unsigned_constant (sizeof(gulong), pspec->maximum);
935 if (pspec->minimum == 0 && pspec->maximum == G_MAXULONG)
936 desc = g_strdup ("");
937 else if (pspec->minimum == 0)
938 desc = g_strdup_printf ("<= %s", upper);
939 else if (pspec->maximum == G_MAXULONG)
940 desc = g_strdup_printf (">= %s", lower);
942 desc = g_strdup_printf ("[%s,%s]", lower, upper);
946 else if (G_IS_PARAM_SPEC_INT64 (spec))
948 GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
950 lower = describe_signed_constant (sizeof(gint64), pspec->minimum);
951 upper = describe_signed_constant (sizeof(gint64), pspec->maximum);
952 if (pspec->minimum == G_MININT64 && pspec->maximum == G_MAXINT64)
953 desc = g_strdup ("");
954 else if (pspec->minimum == G_MININT64)
955 desc = g_strdup_printf ("<= %s", upper);
956 else if (pspec->maximum == G_MAXINT64)
957 desc = g_strdup_printf (">= %s", lower);
959 desc = g_strdup_printf ("[%s,%s]", lower, upper);
963 else if (G_IS_PARAM_SPEC_UINT64 (spec))
965 GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
967 lower = describe_unsigned_constant (sizeof(guint64), pspec->minimum);
968 upper = describe_unsigned_constant (sizeof(guint64), pspec->maximum);
969 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT64)
970 desc = g_strdup ("");
971 else if (pspec->minimum == 0)
972 desc = g_strdup_printf ("<= %s", upper);
973 else if (pspec->maximum == G_MAXUINT64)
974 desc = g_strdup_printf (">= %s", lower);
976 desc = g_strdup_printf ("[%s,%s]", lower, upper);
980 else if (G_IS_PARAM_SPEC_FLOAT (spec))
982 GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
984 lower = describe_double_constant (pspec->minimum);
985 upper = describe_double_constant (pspec->maximum);
986 if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXFLOAT))
988 if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
989 desc = g_strdup ("");
991 desc = g_strdup_printf ("<= %s", upper);
993 else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
994 desc = g_strdup_printf (">= %s", lower);
996 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1000 else if (G_IS_PARAM_SPEC_DOUBLE (spec))
1002 GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
1004 lower = describe_double_constant (pspec->minimum);
1005 upper = describe_double_constant (pspec->maximum);
1006 if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXDOUBLE))
1008 if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
1009 desc = g_strdup ("");
1011 desc = g_strdup_printf ("<= %s", upper);
1013 else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
1014 desc = g_strdup_printf (">= %s", lower);
1016 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1020 #if GLIB_CHECK_VERSION (2, 12, 0)
1021 else if (G_IS_PARAM_SPEC_GTYPE (spec))
1023 GParamSpecGType *pspec = G_PARAM_SPEC_GTYPE (spec);
1024 gboolean is_pointer;
1026 desc = g_strdup (get_type_name (pspec->is_a_type, &is_pointer));
1029 #if GLIB_CHECK_VERSION (2, 25, 9)
1030 else if (G_IS_PARAM_SPEC_VARIANT (spec))
1032 GParamSpecVariant *pspec = G_PARAM_SPEC_VARIANT (spec);
1033 gchar *variant_type;
1035 variant_type = g_variant_type_dup_string (pspec->type);
1036 desc = g_strdup_printf ("GVariant<%s>", variant_type);
1037 g_free (variant_type);
1042 desc = g_strdup ("");
1049 describe_default (GParamSpec *spec)
1053 if (G_IS_PARAM_SPEC_CHAR (spec))
1055 GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
1057 desc = g_strdup_printf ("%d", pspec->default_value);
1059 else if (G_IS_PARAM_SPEC_UCHAR (spec))
1061 GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
1063 desc = g_strdup_printf ("%u", pspec->default_value);
1065 else if (G_IS_PARAM_SPEC_BOOLEAN (spec))
1067 GParamSpecBoolean *pspec = G_PARAM_SPEC_BOOLEAN (spec);
1069 desc = g_strdup_printf ("%s", pspec->default_value ? "TRUE" : "FALSE");
1071 else if (G_IS_PARAM_SPEC_INT (spec))
1073 GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
1075 desc = g_strdup_printf ("%d", pspec->default_value);
1077 else if (G_IS_PARAM_SPEC_UINT (spec))
1079 GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
1081 desc = g_strdup_printf ("%u", pspec->default_value);
1083 else if (G_IS_PARAM_SPEC_LONG (spec))
1085 GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
1087 desc = g_strdup_printf ("%ld", pspec->default_value);
1089 else if (G_IS_PARAM_SPEC_LONG (spec))
1091 GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
1093 desc = g_strdup_printf ("%lu", pspec->default_value);
1095 else if (G_IS_PARAM_SPEC_INT64 (spec))
1097 GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
1099 desc = g_strdup_printf ("%" G_GINT64_FORMAT, pspec->default_value);
1101 else if (G_IS_PARAM_SPEC_UINT64 (spec))
1103 GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
1105 desc = g_strdup_printf ("%" G_GUINT64_FORMAT, pspec->default_value);
1107 else if (G_IS_PARAM_SPEC_UNICHAR (spec))
1109 GParamSpecUnichar *pspec = G_PARAM_SPEC_UNICHAR (spec);
1111 if (g_unichar_isprint (pspec->default_value))
1112 desc = g_strdup_printf ("'%c'", pspec->default_value);
1114 desc = g_strdup_printf ("%u", pspec->default_value);
1116 else if (G_IS_PARAM_SPEC_ENUM (spec))
1118 GParamSpecEnum *pspec = G_PARAM_SPEC_ENUM (spec);
1120 GEnumValue *value = g_enum_get_value (pspec->enum_class, pspec->default_value);
1122 desc = g_strdup_printf ("%s", value->value_name);
1124 desc = g_strdup_printf ("%d", pspec->default_value);
1126 else if (G_IS_PARAM_SPEC_FLAGS (spec))
1128 GParamSpecFlags *pspec = G_PARAM_SPEC_FLAGS (spec);
1129 guint default_value;
1132 default_value = pspec->default_value;
1133 acc = g_string_new ("");
1135 while (default_value)
1137 GFlagsValue *value = g_flags_get_first_value (pspec->flags_class, default_value);
1143 g_string_append (acc, "|");
1144 g_string_append (acc, value->value_name);
1146 default_value &= ~value->value;
1149 if (default_value == 0)
1150 desc = g_string_free (acc, FALSE);
1153 desc = g_strdup_printf ("%d", pspec->default_value);
1154 g_string_free (acc, TRUE);
1157 else if (G_IS_PARAM_SPEC_FLOAT (spec))
1159 GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
1161 /* make sure floats are output with a decimal dot irrespective of
1162 * current locale. Use formatd since we want human-readable numbers
1163 * and do not need the exact same bit representation when deserialising */
1164 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
1165 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
1166 pspec->default_value);
1168 else if (G_IS_PARAM_SPEC_DOUBLE (spec))
1170 GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
1172 /* make sure floats are output with a decimal dot irrespective of
1173 * current locale. Use formatd since we want human-readable numbers
1174 * and do not need the exact same bit representation when deserialising */
1175 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
1176 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
1177 pspec->default_value);
1179 else if (G_IS_PARAM_SPEC_STRING (spec))
1181 GParamSpecString *pspec = G_PARAM_SPEC_STRING (spec);
1183 if (pspec->default_value)
1185 gchar *esc = g_strescape (pspec->default_value, NULL);
1187 desc = g_strdup_printf ("\\"%s\\"", esc);
1192 desc = g_strdup_printf ("NULL");
1194 #if GLIB_CHECK_VERSION (2, 25, 9)
1195 else if (G_IS_PARAM_SPEC_VARIANT (spec))
1197 GParamSpecVariant *pspec = G_PARAM_SPEC_VARIANT (spec);
1199 if (pspec->default_value)
1200 desc = g_variant_print (pspec->default_value, TRUE);
1202 desc = g_strdup ("NULL");
1207 desc = g_strdup ("");
1215 output_object_args (FILE *fp, GType object_type)
1218 const gchar *object_class_name;
1220 gchar flags[16], *pos;
1221 GParamSpec **properties;
1223 gboolean child_prop;
1224 gboolean style_prop;
1225 gboolean is_pointer;
1226 const gchar *type_name;
1228 gchar *default_value;
1230 if (G_TYPE_IS_OBJECT (object_type))
1232 class = g_type_class_peek (object_type);
1236 properties = g_object_class_list_properties (class, &n_properties);
1238 #if GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 3)
1239 else if (G_TYPE_IS_INTERFACE (object_type))
1241 class = g_type_default_interface_ref (object_type);
1246 properties = g_object_interface_list_properties (class, &n_properties);
1252 object_class_name = g_type_name (object_type);
1258 qsort (properties, n_properties, sizeof (GParamSpec *), compare_param_specs);
1259 for (arg = 0; arg < n_properties; arg++)
1261 GParamSpec *spec = properties[arg];
1262 const gchar *nick, *blurb, *dot;
1264 if (spec->owner_type != object_type)
1268 /* We use one-character flags for simplicity. */
1269 if (child_prop && !style_prop)
1273 if (spec->flags & G_PARAM_READABLE)
1275 if (spec->flags & G_PARAM_WRITABLE)
1277 if (spec->flags & G_PARAM_CONSTRUCT)
1279 if (spec->flags & G_PARAM_CONSTRUCT_ONLY)
1283 nick = g_param_spec_get_nick (spec);
1284 blurb = g_param_spec_get_blurb (spec);
1288 int str_len = strlen (blurb);
1289 if (str_len > 0 && blurb[str_len - 1] != '.')
1293 type_desc = describe_type (spec);
1294 default_value = describe_default (spec);
1295 type_name = get_type_name (spec->value_type, &is_pointer);
1296 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",
1297 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);
1299 g_free (default_value);
1302 g_free (properties);
1304 #ifdef GTK_IS_CONTAINER_CLASS
1305 if (!child_prop && GTK_IS_CONTAINER_CLASS (class)) {
1306 properties = gtk_container_class_list_child_properties (class, &n_properties);
1312 #ifdef GTK_IS_CELL_AREA_CLASS
1313 if (!child_prop && GTK_IS_CELL_AREA_CLASS (class)) {
1314 properties = gtk_cell_area_class_list_cell_properties (class, &n_properties);
1320 #ifdef GTK_IS_WIDGET_CLASS
1321 #if GTK_CHECK_VERSION(2,1,0)
1322 if (!style_prop && GTK_IS_WIDGET_CLASS (class)) {
1323 properties = gtk_widget_class_list_style_properties (GTK_WIDGET_CLASS (class), &n_properties);
1332 if ($QUERY_CHILD_PROPERTIES) {
1335 properties = $QUERY_CHILD_PROPERTIES (class, &n_properties);
1353 # Compile and run our file
1355 $CC = $ENV{CC} ? $ENV{CC} : "gcc";
1356 $LD = $ENV{LD} ? $ENV{LD} : $CC;
1357 $CFLAGS = $ENV{CFLAGS} ? $ENV{CFLAGS} : "";
1358 $LDFLAGS = $ENV{LDFLAGS} ? $ENV{LDFLAGS} : "";
1359 $RUN = $ENV{RUN} ? $ENV{RUN} : "";
1362 if ($CC =~ /libtool/) {
1363 $o_file = "$MODULE-scan.lo"
1365 $o_file = "$MODULE-scan.o"
1368 print "gtk-doc: Compiling scanner\n";
1369 $command = "$CC $CFLAGS -c -o $o_file $MODULE-scan.c";
1370 system("($command)") == 0 or die "Compilation of scanner failed: $!\n";
1372 print "gtk-doc: Linking scanner\n";
1373 # FIXME: Can we turn off as-needed for the docs (or better fix it?)
1374 #$command = "$LD -Wl,--no-as-needed $o_file $LDFLAGS -o $MODULE-scan";
1375 $command = "$LD $o_file $LDFLAGS -o $MODULE-scan";
1376 system("($command)") == 0 or die "Linking of scanner failed: $!\n";
1378 print "gtk-doc: Running scanner $MODULE-scan\n";
1379 system("($RUN ./$MODULE-scan)") == 0 or die "Scan failed: $!\n";
1382 if (!defined($ENV{"GTK_DOC_KEEP_INTERMEDIATE"})) {
1383 unlink "./$MODULE-scan.c", "./$MODULE-scan.o", "./$MODULE-scan.lo", "./$MODULE-scan";
1386 &UpdateFileIfChanged ($old_signals_filename, $new_signals_filename, 0);
1387 &UpdateFileIfChanged ($old_hierarchy_filename, $new_hierarchy_filename, 0);
1388 &UpdateFileIfChanged ($old_interfaces_filename, $new_interfaces_filename, 0);
1389 &UpdateFileIfChanged ($old_prerequisites_filename, $new_prerequisites_filename, 0);
1390 &UpdateFileIfChanged ($old_args_filename, $new_args_filename, 0);