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.
31 push @INC, '@PACKAGE_DATA_DIR@';
32 require "gtkdoc-common.pl";
36 # name of documentation module
44 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)";
45 my $QUERY_CHILD_PROPERTIES;
53 # --nogtkinit is deprecated, as it is the default now anyway.
54 my %optctl = (module => \$MODULE,
55 types => \$TYPES_FILE,
56 nogtkinit => \$NO_GTK_INIT,
57 'type-init-func' => \$TYPE_INIT_FUNC,
58 'query-child-properties' => \$QUERY_CHILD_PROPERTIES,
59 'output-dir' => \$OUTPUT_DIR,
63 'ldflags' => \$LDFLAGS,
65 'verbose' => \$VERBOSE,
66 'version' => \$PRINT_VERSION,
67 'help' => \$PRINT_HELP);
69 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");
72 # Do nothing. This just avoids a warning.
73 # the option is not used anymore
87 gtkdoc-scangobj version @VERSION@ - introspect g-objects
89 --module=MODULE_NAME Name of the doc module being parsed
90 --types=FILE The name of the file to store the types in
91 --type-init-func=FUNC The init function to call instead of g_type_init()
92 --query-child-properties=FUNC A function that returns a list of child
93 properties for a class
94 --output-dir=DIRNAME The directory where the results are stored
95 --cc=COMPILER The compiler to use
96 --ld=LINKER The linker to use
97 --run=RUN Command for running the scanner
98 --cflags=CFLAGS Compiler flags
99 --ldflags=LDFLAGS Linker flags
100 --verbose Print extra output while processing
101 --version Print the version of this program
102 --help Print this help
107 $OUTPUT_DIR = $OUTPUT_DIR ? $OUTPUT_DIR : ".";
109 $TYPES_FILE = $TYPES_FILE ? $TYPES_FILE : "$OUTPUT_DIR/$MODULE.types";
111 open (TYPES, $TYPES_FILE) || die "Cannot open $TYPES_FILE: $!\n";
112 open (OUTPUT, ">$MODULE-scan.c") || die "Cannot open $MODULE-scan.c: $!\n";
114 my $old_signals_filename = "$OUTPUT_DIR/$MODULE.signals";
115 my $new_signals_filename = "$OUTPUT_DIR/$MODULE.signals.new";
116 my $old_hierarchy_filename = "$OUTPUT_DIR/$MODULE.hierarchy";
117 my $new_hierarchy_filename = "$OUTPUT_DIR/$MODULE.hierarchy.new";
118 my $old_interfaces_filename = "$OUTPUT_DIR/$MODULE.interfaces";
119 my $new_interfaces_filename = "$OUTPUT_DIR/$MODULE.interfaces.new";
120 my $old_prerequisites_filename = "$OUTPUT_DIR/$MODULE.prerequisites";
121 my $new_prerequisites_filename = "$OUTPUT_DIR/$MODULE.prerequisites.new";
122 my $old_args_filename = "$OUTPUT_DIR/$MODULE.args";
123 my $new_args_filename = "$OUTPUT_DIR/$MODULE.args.new";
125 # generate a C program to scan the types
128 my $forward_decls = "";
135 } elsif (/^gnome_keyring_item_info_get_type$/) {
136 # HACK: This isn't really a GObject type so skip it.
144 $get_types .= " object_types[i++] = $_ ();\n";
145 $forward_decls .= "extern GType $_ (void);\n";
155 #include <glib-object.h>
160 print OUTPUT $includes;
162 print OUTPUT $forward_decls;
165 if ($QUERY_CHILD_PROPERTIES) {
167 extern GParamSpec** $QUERY_CHILD_PROPERTIES (gpointer class, guint *n_properties);
173 #ifdef GTK_IS_WIDGET_CLASS
176 static GType object_types[$ntypes];
179 get_object_types (void)
181 gpointer g_object_class;
185 object_types[i] = G_TYPE_INVALID;
187 /* reference the GObjectClass to initialize the param spec pool
188 * potentially needed by interfaces. See http://bugs.gnome.org/571820 */
189 g_object_class = g_type_class_ref (G_TYPE_OBJECT);
191 /* Need to make sure all the types are loaded in and initialize
192 * their signals and properties.
194 for (i=0; object_types[i]; i++) {
195 if (G_TYPE_IS_CLASSED (object_types[i]))
196 g_type_class_ref (object_types[i]);
197 if (G_TYPE_IS_INTERFACE (object_types[i]))
198 g_type_default_interface_ref (object_types[i]);
201 g_type_class_unref (g_object_class);
207 * This uses GObject type functions to output signal prototypes and the object
211 /* The output files */
212 const gchar *signals_filename = "$new_signals_filename";
213 const gchar *hierarchy_filename = "$new_hierarchy_filename";
214 const gchar *interfaces_filename = "$new_interfaces_filename";
215 const gchar *prerequisites_filename = "$new_prerequisites_filename";
216 const gchar *args_filename = "$new_args_filename";
218 static void output_signals (void);
219 static void output_object_signals (FILE *fp,
221 static void output_object_signal (FILE *fp,
222 const gchar *object_class_name,
224 static const gchar * get_type_name (GType type,
225 gboolean * is_pointer);
226 static void output_object_hierarchy (void);
227 static void output_hierarchy (FILE *fp,
231 static void output_object_interfaces (void);
232 static void output_interfaces (FILE *fp,
235 static void output_interface_prerequisites (void);
236 static void output_prerequisites (FILE *fp,
239 static void output_args (void);
240 static void output_object_args (FILE *fp, GType object_type);
243 main (int argc, char *argv[])
250 output_object_hierarchy ();
251 output_object_interfaces ();
252 output_interface_prerequisites ();
259 output_signals (void)
264 fp = fopen (signals_filename, "w");
266 g_warning ("Couldn't open output file: %s : %s", signals_filename, g_strerror(errno));
270 for (i = 0; object_types[i]; i++)
271 output_object_signals (fp, object_types[i]);
277 compare_signals (const void *a, const void *b)
279 const guint *signal_a = a;
280 const guint *signal_b = b;
282 return strcmp (g_signal_name (*signal_a), g_signal_name (*signal_b));
285 /* This outputs all the signals of one object. */
287 output_object_signals (FILE *fp, GType object_type)
289 const gchar *object_class_name;
290 guint *signals, n_signals;
293 if (G_TYPE_IS_INSTANTIATABLE (object_type) ||
294 G_TYPE_IS_INTERFACE (object_type)) {
296 object_class_name = g_type_name (object_type);
298 signals = g_signal_list_ids (object_type, &n_signals);
299 qsort (signals, n_signals, sizeof (guint), compare_signals);
301 for (sig = 0; sig < n_signals; sig++) {
302 output_object_signal (fp, object_class_name, signals[sig]);
308 /* This outputs one signal. */
310 output_object_signal (FILE *fp,
311 const gchar *object_name,
314 GSignalQuery query_info;
315 const gchar *type_name, *ret_type, *object_arg, *arg_name;
316 gchar *pos, *object_arg_lower;
320 gint param_num, widget_num, event_num, callback_num;
322 gchar signal_name[128];
325 /* g_print ("Object: %s Signal: %u\\n", object_name, signal_id);*/
328 widget_num = event_num = callback_num = 0;
330 g_signal_query (signal_id, &query_info);
332 /* Output the signal object type and the argument name. We assume the
333 * type is a pointer - I think that is OK. We remove "Gtk" or "Gnome" and
334 * convert to lower case for the argument name. */
336 sprintf (pos, "%s ", object_name);
339 /* Try to come up with a sensible variable name for the first arg
340 * It chops off 2 know prefixes :/ and makes the name lowercase
341 * It should replace lowercase -> uppercase with '_'
342 * GFileMonitor -> file_monitor
343 * GIOExtensionPoint -> extension_point
344 * GtkTreeView -> tree_view
345 * if 2nd char is upper case too
346 * search for first lower case and go back one char
348 * search for next upper case
350 if (!strncmp (object_name, "Gtk", 3))
351 object_arg = object_name + 3;
352 else if (!strncmp (object_name, "Gnome", 5))
353 object_arg = object_name + 5;
355 object_arg = object_name;
357 object_arg_lower = g_ascii_strdown (object_arg, -1);
358 sprintf (pos, "*%s\\n", object_arg_lower);
360 if (!strncmp (object_arg_lower, "widget", 6))
362 g_free(object_arg_lower);
364 /* Convert signal name to use underscores rather than dashes '-'. */
365 strncpy (signal_name, query_info.signal_name, 127);
366 signal_name[127] = '\\0';
367 for (i = 0; signal_name[i]; i++) {
368 if (signal_name[i] == '-')
369 signal_name[i] = '_';
372 /* Output the signal parameters. */
373 for (param = 0; param < query_info.n_params; param++) {
374 type_name = get_type_name (query_info.param_types[param] & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
376 /* Most arguments to the callback are called "arg1", "arg2", etc.
377 GtkWidgets are called "widget", "widget2", ...
378 GtkCallbacks are called "callback", "callback2", ... */
379 if (!strcmp (type_name, "GtkWidget")) {
381 arg_num = &widget_num;
383 else if (!strcmp (type_name, "GtkCallback")
384 || !strcmp (type_name, "GtkCCallback")) {
385 arg_name = "callback";
386 arg_num = &callback_num;
390 arg_num = ¶m_num;
392 sprintf (pos, "%s ", type_name);
395 if (!arg_num || *arg_num == 0)
396 sprintf (pos, "%s%s\\n", is_pointer ? "*" : " ", arg_name);
398 sprintf (pos, "%s%s%i\\n", is_pointer ? "*" : " ", arg_name,
411 /* We use one-character flags for simplicity. */
412 if (query_info.signal_flags & G_SIGNAL_RUN_FIRST)
414 if (query_info.signal_flags & G_SIGNAL_RUN_LAST)
416 if (query_info.signal_flags & G_SIGNAL_RUN_CLEANUP)
418 if (query_info.signal_flags & G_SIGNAL_NO_RECURSE)
420 if (query_info.signal_flags & G_SIGNAL_DETAILED)
422 if (query_info.signal_flags & G_SIGNAL_ACTION)
424 if (query_info.signal_flags & G_SIGNAL_NO_HOOKS)
428 /* Output the return type and function name. */
429 ret_type = get_type_name (query_info.return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
432 "<SIGNAL>\\n<NAME>%s::%s</NAME>\\n<RETURNS>%s%s</RETURNS>\\n<FLAGS>%s</FLAGS>\\n%s</SIGNAL>\\n\\n",
433 object_name, query_info.signal_name, ret_type, is_pointer ? "*" : "", flags, buffer);
437 /* Returns the type name to use for a signal argument or return value, given
438 the GtkType from the signal info. It also sets is_pointer to TRUE if the
439 argument needs a '*' since it is a pointer. */
441 get_type_name (GType type, gboolean * is_pointer)
443 const gchar *type_name;
446 type_name = g_type_name (type);
460 /* These all have normal C type names so they are OK. */
464 /* A GtkString is really a gchar*. */
470 /* We use a gint for both of these. Hopefully a subtype with a decent
471 name will be registered and used instead, as GTK+ does itself. */
475 /* The boxed type shouldn't be used itself, only subtypes. Though we
476 return 'gpointer' just in case. */
480 /* A GParam is really a GParamSpec*. */
484 #if GLIB_CHECK_VERSION (2, 25, 9)
494 /* For all GObject subclasses we can use the class name with a "*",
495 e.g. 'GtkWidget *'. */
496 if (g_type_is_a (type, G_TYPE_OBJECT))
499 /* Also catch non GObject root types */
500 if (G_TYPE_IS_CLASSED (type))
503 /* All boxed subtypes will be pointers as well. */
504 /* Exception: GStrv */
505 if (g_type_is_a (type, G_TYPE_BOXED) &&
506 !g_type_is_a (type, G_TYPE_STRV))
509 /* All pointer subtypes will be pointers as well. */
510 if (g_type_is_a (type, G_TYPE_POINTER))
513 /* But enums are not */
514 if (g_type_is_a (type, G_TYPE_ENUM) ||
515 g_type_is_a (type, G_TYPE_FLAGS))
522 /* This outputs the hierarchy of all objects which have been initialized,
523 i.e. by calling their XXX_get_type() initialization function. */
525 output_object_hierarchy (void)
530 GType root_types[$ntypes] = { G_TYPE_INVALID, };
532 fp = fopen (hierarchy_filename, "w");
534 g_warning ("Couldn't open output file: %s : %s", hierarchy_filename, g_strerror(errno));
537 output_hierarchy (fp, G_TYPE_OBJECT, 0);
538 output_hierarchy (fp, G_TYPE_INTERFACE, 0);
540 for (i=0; object_types[i]; i++) {
541 root = object_types[i];
542 while ((type = g_type_parent (root))) {
545 if ((root != G_TYPE_OBJECT) && (root != G_TYPE_INTERFACE)) {
546 for (j=0; root_types[j]; j++) {
547 if (root == root_types[j]) {
548 root = G_TYPE_INVALID; break;
552 root_types[j] = root;
553 output_hierarchy (fp, root, 0);
561 /* This is called recursively to output the hierarchy of a object. */
563 output_hierarchy (FILE *fp,
574 for (i = 0; i < level; i++)
576 fprintf (fp, "%s\\n", g_type_name (type));
578 children = g_type_children (type, &n_children);
580 for (i=0; i < n_children; i++)
581 output_hierarchy (fp, children[i], level + 1);
586 static void output_object_interfaces (void)
591 fp = fopen (interfaces_filename, "w");
593 g_warning ("Couldn't open output file: %s : %s", interfaces_filename, g_strerror(errno));
596 output_interfaces (fp, G_TYPE_OBJECT);
598 for (i = 0; object_types[i]; i++) {
599 if (!g_type_parent (object_types[i]) &&
600 (object_types[i] != G_TYPE_OBJECT) &&
601 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) {
622 fprintf (fp, "%s", g_type_name (type));
623 for (i=0; i < n_interfaces; i++)
624 fprintf (fp, " %s", g_type_name (interfaces[i]));
629 children = g_type_children (type, &n_children);
631 for (i=0; i < n_children; i++)
632 output_interfaces (fp, children[i]);
637 static void output_interface_prerequisites (void)
641 fp = fopen (prerequisites_filename, "w");
643 g_warning ("Couldn't open output file: %s : %s", prerequisites_filename, g_strerror(errno));
646 output_prerequisites (fp, G_TYPE_INTERFACE);
651 output_prerequisites (FILE *fp,
654 #if GLIB_CHECK_VERSION(2,1,0)
656 GType *children, *prerequisites;
657 guint n_children, n_prerequisites;
662 prerequisites = g_type_interface_prerequisites (type, &n_prerequisites);
664 if (n_prerequisites > 0) {
665 fprintf (fp, "%s", g_type_name (type));
666 for (i=0; i < n_prerequisites; i++)
667 fprintf (fp, " %s", g_type_name (prerequisites[i]));
670 g_free (prerequisites);
672 children = g_type_children (type, &n_children);
674 for (i=0; i < n_children; i++)
675 output_prerequisites (fp, children[i]);
687 fp = fopen (args_filename, "w");
689 g_warning ("Couldn't open output file: %s : %s", args_filename, g_strerror(errno));
693 for (i = 0; object_types[i]; i++) {
694 output_object_args (fp, object_types[i]);
701 compare_param_specs (const void *a, const void *b)
703 GParamSpec *spec_a = *(GParamSpec **)a;
704 GParamSpec *spec_b = *(GParamSpec **)b;
706 return strcmp (g_param_spec_get_name (spec_a), g_param_spec_get_name (spec_b));
709 /* Its common to have unsigned properties restricted
710 * to the signed range. Therefore we make this look
711 * a bit nicer by spelling out the max constants.
714 /* Don't use "==" with floats, it might trigger a gcc warning. */
715 #define GTKDOC_COMPARE_FLOAT(x, y) (x <= y && x >= y)
718 describe_double_constant (gdouble value)
722 if (GTKDOC_COMPARE_FLOAT (value, G_MAXDOUBLE))
723 desc = g_strdup ("G_MAXDOUBLE");
724 else if (GTKDOC_COMPARE_FLOAT (value, G_MINDOUBLE))
725 desc = g_strdup ("G_MINDOUBLE");
726 else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXDOUBLE))
727 desc = g_strdup ("-G_MAXDOUBLE");
728 else if (GTKDOC_COMPARE_FLOAT (value, G_MAXFLOAT))
729 desc = g_strdup ("G_MAXFLOAT");
730 else if (GTKDOC_COMPARE_FLOAT (value, G_MINFLOAT))
731 desc = g_strdup ("G_MINFLOAT");
732 else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXFLOAT))
733 desc = g_strdup ("-G_MAXFLOAT");
735 /* make sure floats are output with a decimal dot irrespective of
736 * current locale. Use formatd since we want human-readable numbers
737 * and do not need the exact same bit representation when deserialising */
738 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
739 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g", value);
746 describe_signed_constant (gsize size, gint64 value)
752 if (sizeof (int) == 2) {
753 if (value == G_MAXINT)
754 desc = g_strdup ("G_MAXINT");
755 else if (value == G_MININT)
756 desc = g_strdup ("G_MININT");
760 if (sizeof (int) == 4) {
761 if (value == G_MAXINT)
762 desc = g_strdup ("G_MAXINT");
763 else if (value == G_MININT)
764 desc = g_strdup ("G_MININT");
766 if (value == G_MAXLONG)
767 desc = g_strdup ("G_MAXLONG");
768 else if (value == G_MINLONG)
769 desc = g_strdup ("G_MINLONG");
772 if (value == G_MAXINT64)
773 desc = g_strdup ("G_MAXINT64");
774 else if (value == G_MININT64)
775 desc = g_strdup ("G_MININT64");
781 desc = g_strdup_printf ("%" G_GINT64_FORMAT, value);
787 describe_unsigned_constant (gsize size, guint64 value)
793 if (sizeof (int) == 2) {
794 if (value == (guint64)G_MAXINT)
795 desc = g_strdup ("G_MAXINT");
796 else if (value == G_MAXUINT)
797 desc = g_strdup ("G_MAXUINT");
801 if (sizeof (int) == 4) {
802 if (value == (guint64)G_MAXINT)
803 desc = g_strdup ("G_MAXINT");
804 else if (value == G_MAXUINT)
805 desc = g_strdup ("G_MAXUINT");
807 if (value == (guint64)G_MAXLONG)
808 desc = g_strdup ("G_MAXLONG");
809 else if (value == G_MAXULONG)
810 desc = g_strdup ("G_MAXULONG");
813 if (value == G_MAXINT64)
814 desc = g_strdup ("G_MAXINT64");
815 else if (value == G_MAXUINT64)
816 desc = g_strdup ("G_MAXUINT64");
822 desc = g_strdup_printf ("%" G_GUINT64_FORMAT, value);
828 describe_type (GParamSpec *spec)
834 if (G_IS_PARAM_SPEC_CHAR (spec)) {
835 GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
837 lower = describe_signed_constant (sizeof(gchar), pspec->minimum);
838 upper = describe_signed_constant (sizeof(gchar), pspec->maximum);
839 if (pspec->minimum == G_MININT8 && pspec->maximum == G_MAXINT8)
840 desc = g_strdup ("");
841 else if (pspec->minimum == G_MININT8)
842 desc = g_strdup_printf ("<= %s", upper);
843 else if (pspec->maximum == G_MAXINT8)
844 desc = g_strdup_printf (">= %s", lower);
846 desc = g_strdup_printf ("[%s,%s]", lower, upper);
850 else if (G_IS_PARAM_SPEC_UCHAR (spec)) {
851 GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
853 lower = describe_unsigned_constant (sizeof(guchar), pspec->minimum);
854 upper = describe_unsigned_constant (sizeof(guchar), pspec->maximum);
855 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT8)
856 desc = g_strdup ("");
857 else if (pspec->minimum == 0)
858 desc = g_strdup_printf ("<= %s", upper);
859 else if (pspec->maximum == G_MAXUINT8)
860 desc = g_strdup_printf (">= %s", lower);
862 desc = g_strdup_printf ("[%s,%s]", lower, upper);
866 else if (G_IS_PARAM_SPEC_INT (spec)) {
867 GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
869 lower = describe_signed_constant (sizeof(gint), pspec->minimum);
870 upper = describe_signed_constant (sizeof(gint), pspec->maximum);
871 if (pspec->minimum == G_MININT && pspec->maximum == G_MAXINT)
872 desc = g_strdup ("");
873 else if (pspec->minimum == G_MININT)
874 desc = g_strdup_printf ("<= %s", upper);
875 else if (pspec->maximum == G_MAXINT)
876 desc = g_strdup_printf (">= %s", lower);
878 desc = g_strdup_printf ("[%s,%s]", lower, upper);
882 else if (G_IS_PARAM_SPEC_UINT (spec)) {
883 GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
885 lower = describe_unsigned_constant (sizeof(guint), pspec->minimum);
886 upper = describe_unsigned_constant (sizeof(guint), pspec->maximum);
887 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT)
888 desc = g_strdup ("");
889 else if (pspec->minimum == 0)
890 desc = g_strdup_printf ("<= %s", upper);
891 else if (pspec->maximum == G_MAXUINT)
892 desc = g_strdup_printf (">= %s", lower);
894 desc = g_strdup_printf ("[%s,%s]", lower, upper);
898 else if (G_IS_PARAM_SPEC_LONG (spec)) {
899 GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
901 lower = describe_signed_constant (sizeof(glong), pspec->minimum);
902 upper = describe_signed_constant (sizeof(glong), pspec->maximum);
903 if (pspec->minimum == G_MINLONG && pspec->maximum == G_MAXLONG)
904 desc = g_strdup ("");
905 else if (pspec->minimum == G_MINLONG)
906 desc = g_strdup_printf ("<= %s", upper);
907 else if (pspec->maximum == G_MAXLONG)
908 desc = g_strdup_printf (">= %s", lower);
910 desc = g_strdup_printf ("[%s,%s]", lower, upper);
914 else if (G_IS_PARAM_SPEC_ULONG (spec)) {
915 GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
917 lower = describe_unsigned_constant (sizeof(gulong), pspec->minimum);
918 upper = describe_unsigned_constant (sizeof(gulong), pspec->maximum);
919 if (pspec->minimum == 0 && pspec->maximum == G_MAXULONG)
920 desc = g_strdup ("");
921 else if (pspec->minimum == 0)
922 desc = g_strdup_printf ("<= %s", upper);
923 else if (pspec->maximum == G_MAXULONG)
924 desc = g_strdup_printf (">= %s", lower);
926 desc = g_strdup_printf ("[%s,%s]", lower, upper);
930 else if (G_IS_PARAM_SPEC_INT64 (spec)) {
931 GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
933 lower = describe_signed_constant (sizeof(gint64), pspec->minimum);
934 upper = describe_signed_constant (sizeof(gint64), pspec->maximum);
935 if (pspec->minimum == G_MININT64 && pspec->maximum == G_MAXINT64)
936 desc = g_strdup ("");
937 else if (pspec->minimum == G_MININT64)
938 desc = g_strdup_printf ("<= %s", upper);
939 else if (pspec->maximum == G_MAXINT64)
940 desc = g_strdup_printf (">= %s", lower);
942 desc = g_strdup_printf ("[%s,%s]", lower, upper);
946 else if (G_IS_PARAM_SPEC_UINT64 (spec)) {
947 GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
949 lower = describe_unsigned_constant (sizeof(guint64), pspec->minimum);
950 upper = describe_unsigned_constant (sizeof(guint64), pspec->maximum);
951 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT64)
952 desc = g_strdup ("");
953 else if (pspec->minimum == 0)
954 desc = g_strdup_printf ("<= %s", upper);
955 else if (pspec->maximum == G_MAXUINT64)
956 desc = g_strdup_printf (">= %s", lower);
958 desc = g_strdup_printf ("[%s,%s]", lower, upper);
962 else if (G_IS_PARAM_SPEC_FLOAT (spec)) {
963 GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
965 lower = describe_double_constant (pspec->minimum);
966 upper = describe_double_constant (pspec->maximum);
967 if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXFLOAT)) {
968 if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
969 desc = g_strdup ("");
971 desc = g_strdup_printf ("<= %s", upper);
973 else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
974 desc = g_strdup_printf (">= %s", lower);
976 desc = g_strdup_printf ("[%s,%s]", lower, upper);
980 else if (G_IS_PARAM_SPEC_DOUBLE (spec)) {
981 GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
983 lower = describe_double_constant (pspec->minimum);
984 upper = describe_double_constant (pspec->maximum);
985 if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXDOUBLE)) {
986 if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
987 desc = g_strdup ("");
989 desc = g_strdup_printf ("<= %s", upper);
991 else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
992 desc = g_strdup_printf (">= %s", lower);
994 desc = g_strdup_printf ("[%s,%s]", lower, upper);
998 #if GLIB_CHECK_VERSION (2, 12, 0)
999 else if (G_IS_PARAM_SPEC_GTYPE (spec)) {
1000 GParamSpecGType *pspec = G_PARAM_SPEC_GTYPE (spec);
1001 gboolean is_pointer;
1003 desc = g_strdup (get_type_name (pspec->is_a_type, &is_pointer));
1006 #if GLIB_CHECK_VERSION (2, 25, 9)
1007 else if (G_IS_PARAM_SPEC_VARIANT (spec)) {
1008 GParamSpecVariant *pspec = G_PARAM_SPEC_VARIANT (spec);
1009 gchar *variant_type;
1011 variant_type = g_variant_type_dup_string (pspec->type);
1012 desc = g_strdup_printf ("GVariant<%s>", variant_type);
1013 g_free (variant_type);
1017 desc = g_strdup ("");
1024 describe_default (GParamSpec *spec)
1028 if (G_IS_PARAM_SPEC_CHAR (spec)) {
1029 GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
1031 desc = g_strdup_printf ("%d", pspec->default_value);
1033 else if (G_IS_PARAM_SPEC_UCHAR (spec)) {
1034 GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
1036 desc = g_strdup_printf ("%u", pspec->default_value);
1038 else if (G_IS_PARAM_SPEC_BOOLEAN (spec)) {
1039 GParamSpecBoolean *pspec = G_PARAM_SPEC_BOOLEAN (spec);
1041 desc = g_strdup_printf ("%s", pspec->default_value ? "TRUE" : "FALSE");
1043 else if (G_IS_PARAM_SPEC_INT (spec)) {
1044 GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
1046 desc = g_strdup_printf ("%d", pspec->default_value);
1048 else if (G_IS_PARAM_SPEC_UINT (spec)) {
1049 GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
1051 desc = g_strdup_printf ("%u", pspec->default_value);
1053 else if (G_IS_PARAM_SPEC_LONG (spec)) {
1054 GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
1056 desc = g_strdup_printf ("%ld", pspec->default_value);
1058 else if (G_IS_PARAM_SPEC_LONG (spec)) {
1059 GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
1061 desc = g_strdup_printf ("%lu", pspec->default_value);
1063 else if (G_IS_PARAM_SPEC_INT64 (spec)) {
1064 GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
1066 desc = g_strdup_printf ("%" G_GINT64_FORMAT, pspec->default_value);
1068 else if (G_IS_PARAM_SPEC_UINT64 (spec))
1070 GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
1072 desc = g_strdup_printf ("%" G_GUINT64_FORMAT, pspec->default_value);
1074 else if (G_IS_PARAM_SPEC_UNICHAR (spec)) {
1075 GParamSpecUnichar *pspec = G_PARAM_SPEC_UNICHAR (spec);
1077 if (g_unichar_isprint (pspec->default_value))
1078 desc = g_strdup_printf ("'%c'", pspec->default_value);
1080 desc = g_strdup_printf ("%u", pspec->default_value);
1082 else if (G_IS_PARAM_SPEC_ENUM (spec)) {
1083 GParamSpecEnum *pspec = G_PARAM_SPEC_ENUM (spec);
1085 GEnumValue *value = g_enum_get_value (pspec->enum_class, pspec->default_value);
1087 desc = g_strdup_printf ("%s", value->value_name);
1089 desc = g_strdup_printf ("%d", pspec->default_value);
1091 else if (G_IS_PARAM_SPEC_FLAGS (spec)) {
1092 GParamSpecFlags *pspec = G_PARAM_SPEC_FLAGS (spec);
1093 guint default_value;
1096 default_value = pspec->default_value;
1097 acc = g_string_new ("");
1099 while (default_value) {
1100 GFlagsValue *value = g_flags_get_first_value (pspec->flags_class, default_value);
1106 g_string_append (acc, " | ");
1107 g_string_append (acc, value->value_name);
1109 default_value &= ~value->value;
1112 if (default_value == 0)
1113 desc = g_string_free (acc, FALSE);
1115 desc = g_strdup_printf ("%d", pspec->default_value);
1116 g_string_free (acc, TRUE);
1119 else if (G_IS_PARAM_SPEC_FLOAT (spec)) {
1120 GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
1122 /* make sure floats are output with a decimal dot irrespective of
1123 * current locale. Use formatd since we want human-readable numbers
1124 * and do not need the exact same bit representation when deserialising */
1125 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
1126 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
1127 pspec->default_value);
1129 else if (G_IS_PARAM_SPEC_DOUBLE (spec)) {
1130 GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
1132 /* make sure floats are output with a decimal dot irrespective of
1133 * current locale. Use formatd since we want human-readable numbers
1134 * and do not need the exact same bit representation when deserialising */
1135 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
1136 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
1137 pspec->default_value);
1139 else if (G_IS_PARAM_SPEC_STRING (spec)) {
1140 GParamSpecString *pspec = G_PARAM_SPEC_STRING (spec);
1142 if (pspec->default_value) {
1143 gchar *esc = g_strescape (pspec->default_value, NULL);
1144 desc = g_strdup_printf ("\\"%s\\"", esc);
1148 desc = g_strdup_printf ("NULL");
1150 #if GLIB_CHECK_VERSION (2, 25, 9)
1151 else if (G_IS_PARAM_SPEC_VARIANT (spec)) {
1152 GParamSpecVariant *pspec = G_PARAM_SPEC_VARIANT (spec);
1154 if (pspec->default_value)
1155 desc = g_variant_print (pspec->default_value, TRUE);
1157 desc = g_strdup ("NULL");
1161 desc = g_strdup ("");
1169 output_object_args (FILE *fp, GType object_type)
1172 const gchar *object_class_name;
1174 gchar flags[16], *pos;
1175 GParamSpec **properties;
1177 gboolean child_prop;
1178 gboolean style_prop;
1179 gboolean is_pointer;
1180 const gchar *type_name;
1182 gchar *default_value;
1184 if (G_TYPE_IS_OBJECT (object_type)) {
1185 class = g_type_class_peek (object_type);
1189 properties = g_object_class_list_properties (class, &n_properties);
1191 #if GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 3)
1192 else if (G_TYPE_IS_INTERFACE (object_type)) {
1193 class = g_type_default_interface_ref (object_type);
1198 properties = g_object_interface_list_properties (class, &n_properties);
1204 object_class_name = g_type_name (object_type);
1210 qsort (properties, n_properties, sizeof (GParamSpec *), compare_param_specs);
1211 for (arg = 0; arg < n_properties; arg++) {
1212 GParamSpec *spec = properties[arg];
1213 const gchar *nick, *blurb, *dot;
1215 if (spec->owner_type != object_type)
1219 /* We use one-character flags for simplicity. */
1220 if (child_prop && !style_prop)
1224 if (spec->flags & G_PARAM_READABLE)
1226 if (spec->flags & G_PARAM_WRITABLE)
1228 if (spec->flags & G_PARAM_CONSTRUCT)
1230 if (spec->flags & G_PARAM_CONSTRUCT_ONLY)
1234 nick = g_param_spec_get_nick (spec);
1235 blurb = g_param_spec_get_blurb (spec);
1239 int str_len = strlen (blurb);
1240 if (str_len > 0 && blurb[str_len - 1] != '.')
1244 type_desc = describe_type (spec);
1245 default_value = describe_default (spec);
1246 type_name = get_type_name (spec->value_type, &is_pointer);
1247 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",
1248 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);
1250 g_free (default_value);
1253 g_free (properties);
1255 #ifdef GTK_IS_CONTAINER_CLASS
1256 if (!child_prop && GTK_IS_CONTAINER_CLASS (class)) {
1257 properties = gtk_container_class_list_child_properties (class, &n_properties);
1263 #ifdef GTK_IS_CELL_AREA_CLASS
1264 if (!child_prop && GTK_IS_CELL_AREA_CLASS (class)) {
1265 properties = gtk_cell_area_class_list_cell_properties (class, &n_properties);
1271 #ifdef GTK_IS_WIDGET_CLASS
1272 #if GTK_CHECK_VERSION(2,1,0)
1273 if (!style_prop && GTK_IS_WIDGET_CLASS (class)) {
1274 properties = gtk_widget_class_list_style_properties (GTK_WIDGET_CLASS (class), &n_properties);
1283 if ($QUERY_CHILD_PROPERTIES) {
1286 properties = $QUERY_CHILD_PROPERTIES (class, &n_properties);
1304 # Compile and run our file
1307 $CC = $ENV{CC} ? $ENV{CC} : "gcc";
1310 $LD = $ENV{LD} ? $ENV{LD} : $CC;
1313 $CFLAGS = $ENV{CFLAGS} ? $ENV{CFLAGS} : "";
1316 $LDFLAGS = $ENV{LDFLAGS} ? $ENV{LDFLAGS} : "";
1319 $RUN = $ENV{RUN} ? $ENV{RUN} : "";
1322 my $o_file = $CC =~ /libtool/ ? "$MODULE-scan.lo" :"$MODULE-scan.o";
1325 if (!defined($VERBOSE) or $VERBOSE eq "0") {
1326 $stdout=">/dev/null";
1330 my $command = "$CC $stdout $CFLAGS -c -o $o_file $MODULE-scan.c";
1331 system("($command)") == 0 or die "Compilation of scanner failed: $!\n";
1334 # FIXME: Can we turn off as-needed for the docs (or better fix it?)
1335 #$command = "$LD -Wl,--no-as-needed $o_file $LDFLAGS -o $MODULE-scan@EXEEXT@";
1336 $command = "$LD $stdout $o_file $LDFLAGS -o $MODULE-scan@EXEEXT@";
1337 system("($command)") == 0 or die "Linking of scanner failed: $!\n";
1339 # Running scanner $MODULE-scan ";
1340 system("($RUN ./$MODULE-scan@EXEEXT@)") == 0 or die "Scan failed: $!\n";
1343 if (!defined($ENV{"GTK_DOC_KEEP_INTERMEDIATE"})) {
1344 unlink "./$MODULE-scan.c", "./$MODULE-scan.o", "./$MODULE-scan.lo", "./$MODULE-scan@EXEEXT@";
1347 &UpdateFileIfChanged ($old_signals_filename, $new_signals_filename, 0);
1348 &UpdateFileIfChanged ($old_hierarchy_filename, $new_hierarchy_filename, 0);
1349 &UpdateFileIfChanged ($old_interfaces_filename, $new_interfaces_filename, 0);
1350 &UpdateFileIfChanged ($old_prerequisites_filename, $new_prerequisites_filename, 0);
1351 &UpdateFileIfChanged ($old_args_filename, $new_args_filename, 0);