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
41 my $TYPE_INIT_FUNC="g_type_init(); g_type_class_ref(G_TYPE_OBJECT)";
42 my $QUERY_CHILD_PROPERTIES;
44 # --nogtkinit is deprecated, as it is the default now anyway.
45 %optctl = (module => \$MODULE,
46 types => \$TYPES_FILE,
47 nogtkinit => \$NO_GTK_INIT,
48 'type-init-func' => \$TYPE_INIT_FUNC,
49 'query-child-properties' => \$QUERY_CHILD_PROPERTIES,
50 'output-dir' => \$OUTPUT_DIR,
51 'verbose' => \$VERBOSE,
52 'version' => \$PRINT_VERSION,
53 'help' => \$PRINT_HELP);
55 GetOptions(\%optctl, "module=s", "types:s", "output-dir:s", "nogtkinit", "type-init-func:s", "query-child-properties:s", "verbose", "version", "help");
58 # Do nothing. This just avoids a warning.
59 # the option is not used anymore
73 gtkdoc-scangobj version @VERSION@ - introspect g-objects
75 --module=MODULE_NAME Name of the doc module being parsed
76 --types=FILE The name of the file to store the types in
77 --type-init-func=FUNC The init function to call instead of g_type_init()
78 --query-child-properties=FUNC A function that returns a list of child
79 properties for a class
80 --output-dir=DIRNAME The directory where the results are stored
81 --verbose Print extra output while processing
82 --version Print the version of this program
83 --help Print this help
88 $OUTPUT_DIR = $OUTPUT_DIR ? $OUTPUT_DIR : ".";
90 $TYPES_FILE = $TYPES_FILE ? $TYPES_FILE : "$OUTPUT_DIR/$MODULE.types";
92 open (TYPES, $TYPES_FILE) || die "Cannot open $TYPES_FILE: $!\n";
93 open (OUTPUT, ">$MODULE-scan.c") || die "Cannot open $MODULE-scan.c: $!\n";
95 my $old_signals_filename = "$OUTPUT_DIR/$MODULE.signals";
96 my $new_signals_filename = "$OUTPUT_DIR/$MODULE.signals.new";
97 my $old_hierarchy_filename = "$OUTPUT_DIR/$MODULE.hierarchy";
98 my $new_hierarchy_filename = "$OUTPUT_DIR/$MODULE.hierarchy.new";
99 my $old_interfaces_filename = "$OUTPUT_DIR/$MODULE.interfaces";
100 my $new_interfaces_filename = "$OUTPUT_DIR/$MODULE.interfaces.new";
101 my $old_prerequisites_filename = "$OUTPUT_DIR/$MODULE.prerequisites";
102 my $new_prerequisites_filename = "$OUTPUT_DIR/$MODULE.prerequisites.new";
103 my $old_args_filename = "$OUTPUT_DIR/$MODULE.args";
104 my $new_args_filename = "$OUTPUT_DIR/$MODULE.args.new";
106 # write a C program to scan the types
114 } elsif (/^gnome_keyring_item_info_get_type$/) {
115 # HACK: This isn't really a GObject type so skip it.
127 $ntypes = @types + 1;
134 #include <glib-object.h>
139 print OUTPUT $includes;
142 print OUTPUT "extern GType $_ (void);\n";
146 if ($QUERY_CHILD_PROPERTIES) {
148 extern GParamSpec** $QUERY_CHILD_PROPERTIES (gpointer class, guint *n_properties);
154 #ifdef GTK_IS_WIDGET_CLASS
157 GType object_types[$ntypes];
160 get_object_types (void)
162 gpointer g_object_class;
167 print OUTPUT " object_types[i++] = $_ ();\n";
173 /* reference the GObjectClass to initialize the param spec pool
174 * potentially needed by interfaces. See http://bugs.gnome.org/571820 */
175 g_object_class = g_type_class_ref (G_TYPE_OBJECT);
177 /* Need to make sure all the types are loaded in and initialize
178 * their signals and properties.
180 for (i=0; object_types[i]; i++)
182 if (G_TYPE_IS_CLASSED (object_types[i]))
183 g_type_class_ref (object_types[i]);
184 if (G_TYPE_IS_INTERFACE (object_types[i]))
185 g_type_default_interface_ref (object_types[i]);
188 g_type_class_unref (g_object_class);
194 * This uses GObject type functions to output signal prototypes and the object
198 /* The output files */
199 const gchar *signals_filename = "$new_signals_filename";
200 const gchar *hierarchy_filename = "$new_hierarchy_filename";
201 const gchar *interfaces_filename = "$new_interfaces_filename";
202 const gchar *prerequisites_filename = "$new_prerequisites_filename";
203 const gchar *args_filename = "$new_args_filename";
206 static void output_signals (void);
207 static void output_object_signals (FILE *fp,
209 static void output_object_signal (FILE *fp,
210 const gchar *object_class_name,
212 static const gchar * get_type_name (GType type,
213 gboolean * is_pointer);
214 static void output_object_hierarchy (void);
215 static void output_hierarchy (FILE *fp,
219 static void output_object_interfaces (void);
220 static void output_interfaces (FILE *fp,
223 static void output_interface_prerequisites (void);
224 static void output_prerequisites (FILE *fp,
227 static void output_args (void);
228 static void output_object_args (FILE *fp, GType object_type);
231 main (int argc, char *argv[])
238 output_object_hierarchy ();
239 output_object_interfaces ();
240 output_interface_prerequisites ();
248 output_signals (void)
253 fp = fopen (signals_filename, "w");
256 g_warning ("Couldn't open output file: %s : %s", signals_filename, g_strerror(errno));
260 for (i = 0; object_types[i]; i++)
261 output_object_signals (fp, object_types[i]);
267 compare_signals (const void *a, const void *b)
269 const guint *signal_a = a;
270 const guint *signal_b = b;
272 return strcmp (g_signal_name (*signal_a), g_signal_name (*signal_b));
275 /* This outputs all the signals of one object. */
277 output_object_signals (FILE *fp, GType object_type)
279 const gchar *object_class_name;
280 guint *signals, n_signals;
283 if (G_TYPE_IS_INSTANTIATABLE (object_type) ||
284 G_TYPE_IS_INTERFACE (object_type))
287 object_class_name = g_type_name (object_type);
289 signals = g_signal_list_ids (object_type, &n_signals);
290 qsort (signals, n_signals, sizeof (guint), compare_signals);
292 for (sig = 0; sig < n_signals; sig++)
294 output_object_signal (fp, object_class_name, signals[sig]);
301 /* This outputs one signal. */
303 output_object_signal (FILE *fp,
304 const gchar *object_name,
307 GSignalQuery query_info;
308 const gchar *type_name, *ret_type, *object_arg, *arg_name;
309 gchar *pos, *object_arg_lower;
313 gint param_num, widget_num, event_num, callback_num;
315 gchar signal_name[128];
318 /* g_print ("Object: %s Signal: %u\\n", object_name, signal_id);*/
321 widget_num = event_num = callback_num = 0;
323 g_signal_query (signal_id, &query_info);
325 /* Output the signal object type and the argument name. We assume the
326 type is a pointer - I think that is OK. We remove "Gtk" or "Gnome" and
327 convert to lower case for the argument name. */
329 sprintf (pos, "%s ", object_name);
332 /* Try to come up with a sensible variable name for the first arg
333 * It chops off 2 know prefixes :/ and makes the name lowercase
334 * It should replace lowercase -> uppercase with '_'
335 * GFileMonitor -> file_monitor
336 * GIOExtensionPoint -> extension_point
337 * GtkTreeView -> tree_view
338 * if 2nd char is upper case too
339 * search for first lower case and go back one char
341 * search for next upper case
343 if (!strncmp (object_name, "Gtk", 3))
344 object_arg = object_name + 3;
345 else if (!strncmp (object_name, "Gnome", 5))
346 object_arg = object_name + 5;
348 object_arg = object_name;
350 object_arg_lower = g_ascii_strdown (object_arg, -1);
351 sprintf (pos, "*%s\\n", object_arg_lower);
353 if (!strncmp (object_arg_lower, "widget", 6))
355 g_free(object_arg_lower);
357 /* Convert signal name to use underscores rather than dashes '-'. */
358 strncpy (signal_name, query_info.signal_name, 127);
359 signal_name[127] = '\\0';
360 for (i = 0; signal_name[i]; i++)
362 if (signal_name[i] == '-')
363 signal_name[i] = '_';
366 /* Output the signal parameters. */
367 for (param = 0; param < query_info.n_params; param++)
369 type_name = get_type_name (query_info.param_types[param] & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
371 /* Most arguments to the callback are called "arg1", "arg2", etc.
372 GtkWidgets are called "widget", "widget2", ...
373 GtkCallbacks are called "callback", "callback2", ... */
374 if (!strcmp (type_name, "GtkWidget"))
377 arg_num = &widget_num;
379 else if (!strcmp (type_name, "GtkCallback")
380 || !strcmp (type_name, "GtkCCallback"))
382 arg_name = "callback";
383 arg_num = &callback_num;
388 arg_num = ¶m_num;
390 sprintf (pos, "%s ", type_name);
393 if (!arg_num || *arg_num == 0)
394 sprintf (pos, "%s%s\\n", is_pointer ? "*" : " ", arg_name);
396 sprintf (pos, "%s%s%i\\n", is_pointer ? "*" : " ", arg_name,
410 /* We use one-character flags for simplicity. */
411 if (query_info.signal_flags & G_SIGNAL_RUN_FIRST)
413 if (query_info.signal_flags & G_SIGNAL_RUN_LAST)
415 if (query_info.signal_flags & G_SIGNAL_RUN_CLEANUP)
417 if (query_info.signal_flags & G_SIGNAL_NO_RECURSE)
419 if (query_info.signal_flags & G_SIGNAL_DETAILED)
421 if (query_info.signal_flags & G_SIGNAL_ACTION)
423 if (query_info.signal_flags & G_SIGNAL_NO_HOOKS)
427 /* Output the return type and function name. */
428 ret_type = get_type_name (query_info.return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
431 "<SIGNAL>\\n<NAME>%s::%s</NAME>\\n<RETURNS>%s%s</RETURNS>\\n<FLAGS>%s</FLAGS>\\n%s</SIGNAL>\\n\\n",
432 object_name, query_info.signal_name, ret_type, is_pointer ? "*" : "", flags, buffer);
436 /* Returns the type name to use for a signal argument or return value, given
437 the GtkType from the signal info. It also sets is_pointer to TRUE if the
438 argument needs a '*' since it is a pointer. */
440 get_type_name (GType type, gboolean * is_pointer)
442 const gchar *type_name;
445 type_name = g_type_name (type);
459 /* These all have normal C type names so they are OK. */
463 /* A GtkString is really a gchar*. */
469 /* We use a gint for both of these. Hopefully a subtype with a decent
470 name will be registered and used instead, as GTK+ does itself. */
474 /* The boxed type shouldn't be used itself, only subtypes. Though we
475 return 'gpointer' just in case. */
479 /* A GParam is really a GParamSpec*. */
483 #if GLIB_CHECK_VERSION (2, 25, 9)
493 /* For all GObject subclasses we can use the class name with a "*",
494 e.g. 'GtkWidget *'. */
495 if (g_type_is_a (type, G_TYPE_OBJECT))
498 /* Also catch non GObject root types */
499 if (G_TYPE_IS_CLASSED (type))
502 /* All boxed subtypes will be pointers as well. */
503 /* Exception: GStrv */
504 if (g_type_is_a (type, G_TYPE_BOXED) &&
505 !g_type_is_a (type, G_TYPE_STRV))
508 /* All pointer subtypes will be pointers as well. */
509 if (g_type_is_a (type, G_TYPE_POINTER))
512 /* But enums are not */
513 if (g_type_is_a (type, G_TYPE_ENUM) ||
514 g_type_is_a (type, G_TYPE_FLAGS))
521 /* This outputs the hierarchy of all objects which have been initialized,
522 i.e. by calling their XXX_get_type() initialization function. */
524 output_object_hierarchy (void)
529 GType root_types[$ntypes] = { G_TYPE_INVALID, };
531 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");
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++)
601 if (!g_type_parent (object_types[i]) &&
602 (object_types[i] != G_TYPE_OBJECT) &&
603 G_TYPE_IS_INSTANTIATABLE (object_types[i]))
605 output_interfaces (fp, object_types[i]);
612 output_interfaces (FILE *fp,
616 GType *children, *interfaces;
617 guint n_children, n_interfaces;
622 interfaces = g_type_interfaces (type, &n_interfaces);
624 if (n_interfaces > 0)
626 fprintf (fp, "%s", g_type_name (type));
627 for (i=0; i < n_interfaces; i++)
628 fprintf (fp, " %s", g_type_name (interfaces[i]));
633 children = g_type_children (type, &n_children);
635 for (i=0; i < n_children; i++)
636 output_interfaces (fp, children[i]);
641 static void output_interface_prerequisites (void)
645 fp = fopen (prerequisites_filename, "w");
648 g_warning ("Couldn't open output file: %s : %s", prerequisites_filename, g_strerror(errno));
651 output_prerequisites (fp, G_TYPE_INTERFACE);
656 output_prerequisites (FILE *fp,
659 #if GLIB_CHECK_VERSION(2,1,0)
661 GType *children, *prerequisites;
662 guint n_children, n_prerequisites;
667 prerequisites = g_type_interface_prerequisites (type, &n_prerequisites);
669 if (n_prerequisites > 0)
671 fprintf (fp, "%s", g_type_name (type));
672 for (i=0; i < n_prerequisites; i++)
673 fprintf (fp, " %s", g_type_name (prerequisites[i]));
676 g_free (prerequisites);
678 children = g_type_children (type, &n_children);
680 for (i=0; i < n_children; i++)
681 output_prerequisites (fp, children[i]);
693 fp = fopen (args_filename, "w");
696 g_warning ("Couldn't open output file: %s : %s", args_filename, g_strerror(errno));
700 for (i = 0; object_types[i]; i++) {
701 output_object_args (fp, object_types[i]);
708 compare_param_specs (const void *a, const void *b)
710 GParamSpec *spec_a = *(GParamSpec **)a;
711 GParamSpec *spec_b = *(GParamSpec **)b;
713 return strcmp (g_param_spec_get_name (spec_a), g_param_spec_get_name (spec_b));
716 /* Its common to have unsigned properties restricted
717 * to the signed range. Therefore we make this look
718 * a bit nicer by spelling out the max constants.
721 /* Don't use "==" with floats, it might trigger a gcc warning. */
722 #define GTKDOC_COMPARE_FLOAT(x, y) (x <= y && x >= y)
725 describe_double_constant (gdouble value)
729 if (GTKDOC_COMPARE_FLOAT (value, G_MAXDOUBLE))
730 desc = g_strdup ("G_MAXDOUBLE");
731 else if (GTKDOC_COMPARE_FLOAT (value, G_MINDOUBLE))
732 desc = g_strdup ("G_MINDOUBLE");
733 else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXDOUBLE))
734 desc = g_strdup ("-G_MAXDOUBLE");
735 else if (GTKDOC_COMPARE_FLOAT (value, G_MAXFLOAT))
736 desc = g_strdup ("G_MAXFLOAT");
737 else if (GTKDOC_COMPARE_FLOAT (value, G_MINFLOAT))
738 desc = g_strdup ("G_MINFLOAT");
739 else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXFLOAT))
740 desc = g_strdup ("-G_MAXFLOAT");
742 /* make sure floats are output with a decimal dot irrespective of
743 * current locale. Use formatd since we want human-readable numbers
744 * and do not need the exact same bit representation when deserialising */
745 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
746 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g", value);
753 describe_signed_constant (gsize size, gint64 value)
759 if (sizeof (int) == 2) {
760 if (value == G_MAXINT)
761 desc = g_strdup ("G_MAXINT");
762 else if (value == G_MININT)
763 desc = g_strdup ("G_MININT");
764 else if (value == (gint64)G_MAXUINT)
765 desc = g_strdup ("G_MAXUINT");
769 if (sizeof (int) == 4) {
770 if (value == G_MAXINT)
771 desc = g_strdup ("G_MAXINT");
772 else if (value == G_MININT)
773 desc = g_strdup ("G_MININT");
774 else if (value == (gint64)G_MAXUINT)
775 desc = g_strdup ("G_MAXUINT");
777 if (value == G_MAXLONG)
778 desc = g_strdup ("G_MAXLONG");
779 else if (value == G_MINLONG)
780 desc = g_strdup ("G_MINLONG");
781 else if (value == (gint64)G_MAXULONG)
782 desc = g_strdup ("G_MAXULONG");
785 if (value == G_MAXINT64)
786 desc = g_strdup ("G_MAXINT64");
787 else if (value == G_MININT64)
788 desc = g_strdup ("G_MININT64");
794 desc = g_strdup_printf ("%" G_GINT64_FORMAT, value);
800 describe_unsigned_constant (gsize size, guint64 value)
806 if (sizeof (int) == 2) {
807 if (value == (guint64)G_MAXINT)
808 desc = g_strdup ("G_MAXINT");
809 else if (value == G_MAXUINT)
810 desc = g_strdup ("G_MAXUINT");
814 if (sizeof (int) == 4) {
815 if (value == (guint64)G_MAXINT)
816 desc = g_strdup ("G_MAXINT");
817 else if (value == G_MAXUINT)
818 desc = g_strdup ("G_MAXUINT");
820 if (value == (guint64)G_MAXLONG)
821 desc = g_strdup ("G_MAXLONG");
822 else if (value == G_MAXULONG)
823 desc = g_strdup ("G_MAXULONG");
826 if (value == G_MAXINT64)
827 desc = g_strdup ("G_MAXINT64");
828 else if (value == G_MAXUINT64)
829 desc = g_strdup ("G_MAXUINT64");
835 desc = g_strdup_printf ("%" G_GUINT64_FORMAT, value);
841 describe_type (GParamSpec *spec)
847 if (G_IS_PARAM_SPEC_CHAR (spec))
849 GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
851 lower = describe_signed_constant (sizeof(gchar), pspec->minimum);
852 upper = describe_signed_constant (sizeof(gchar), pspec->maximum);
853 if (pspec->minimum == G_MININT8 && pspec->maximum == G_MAXINT8)
854 desc = g_strdup ("");
855 else if (pspec->minimum == G_MININT8)
856 desc = g_strdup_printf ("<= %s", upper);
857 else if (pspec->maximum == G_MAXINT8)
858 desc = g_strdup_printf (">= %s", lower);
860 desc = g_strdup_printf ("[%s,%s]", lower, upper);
864 else if (G_IS_PARAM_SPEC_UCHAR (spec))
866 GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
868 lower = describe_unsigned_constant (sizeof(guchar), pspec->minimum);
869 upper = describe_unsigned_constant (sizeof(guchar), pspec->maximum);
870 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT8)
871 desc = g_strdup ("");
872 else if (pspec->minimum == 0)
873 desc = g_strdup_printf ("<= %s", upper);
874 else if (pspec->maximum == G_MAXUINT8)
875 desc = g_strdup_printf (">= %s", lower);
877 desc = g_strdup_printf ("[%s,%s]", lower, upper);
881 else if (G_IS_PARAM_SPEC_INT (spec))
883 GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
885 lower = describe_signed_constant (sizeof(gint), pspec->minimum);
886 upper = describe_signed_constant (sizeof(gint), pspec->maximum);
887 if (pspec->minimum == G_MININT && pspec->maximum == G_MAXINT)
888 desc = g_strdup ("");
889 else if (pspec->minimum == G_MININT)
890 desc = g_strdup_printf ("<= %s", upper);
891 else if (pspec->maximum == G_MAXINT)
892 desc = g_strdup_printf (">= %s", lower);
894 desc = g_strdup_printf ("[%s,%s]", lower, upper);
898 else if (G_IS_PARAM_SPEC_UINT (spec))
900 GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
902 lower = describe_unsigned_constant (sizeof(guint), pspec->minimum);
903 upper = describe_unsigned_constant (sizeof(guint), pspec->maximum);
904 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT)
905 desc = g_strdup ("");
906 else if (pspec->minimum == 0)
907 desc = g_strdup_printf ("<= %s", upper);
908 else if (pspec->maximum == G_MAXUINT)
909 desc = g_strdup_printf (">= %s", lower);
911 desc = g_strdup_printf ("[%s,%s]", lower, upper);
915 else if (G_IS_PARAM_SPEC_LONG (spec))
917 GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
919 lower = describe_signed_constant (sizeof(glong), pspec->minimum);
920 upper = describe_signed_constant (sizeof(glong), pspec->maximum);
921 if (pspec->minimum == G_MINLONG && pspec->maximum == G_MAXLONG)
922 desc = g_strdup ("");
923 else if (pspec->minimum == G_MINLONG)
924 desc = g_strdup_printf ("<= %s", upper);
925 else if (pspec->maximum == G_MAXLONG)
926 desc = g_strdup_printf (">= %s", lower);
928 desc = g_strdup_printf ("[%s,%s]", lower, upper);
932 else if (G_IS_PARAM_SPEC_ULONG (spec))
934 GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
936 lower = describe_unsigned_constant (sizeof(gulong), pspec->minimum);
937 upper = describe_unsigned_constant (sizeof(gulong), pspec->maximum);
938 if (pspec->minimum == 0 && pspec->maximum == G_MAXULONG)
939 desc = g_strdup ("");
940 else if (pspec->minimum == 0)
941 desc = g_strdup_printf ("<= %s", upper);
942 else if (pspec->maximum == G_MAXULONG)
943 desc = g_strdup_printf (">= %s", lower);
945 desc = g_strdup_printf ("[%s,%s]", lower, upper);
949 else if (G_IS_PARAM_SPEC_INT64 (spec))
951 GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
953 lower = describe_signed_constant (sizeof(gint64), pspec->minimum);
954 upper = describe_signed_constant (sizeof(gint64), pspec->maximum);
955 if (pspec->minimum == G_MININT64 && pspec->maximum == G_MAXINT64)
956 desc = g_strdup ("");
957 else if (pspec->minimum == G_MININT64)
958 desc = g_strdup_printf ("<= %s", upper);
959 else if (pspec->maximum == G_MAXINT64)
960 desc = g_strdup_printf (">= %s", lower);
962 desc = g_strdup_printf ("[%s,%s]", lower, upper);
966 else if (G_IS_PARAM_SPEC_UINT64 (spec))
968 GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
970 lower = describe_unsigned_constant (sizeof(guint64), pspec->minimum);
971 upper = describe_unsigned_constant (sizeof(guint64), pspec->maximum);
972 if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT64)
973 desc = g_strdup ("");
974 else if (pspec->minimum == 0)
975 desc = g_strdup_printf ("<= %s", upper);
976 else if (pspec->maximum == G_MAXUINT64)
977 desc = g_strdup_printf (">= %s", lower);
979 desc = g_strdup_printf ("[%s,%s]", lower, upper);
983 else if (G_IS_PARAM_SPEC_FLOAT (spec))
985 GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
987 lower = describe_double_constant (pspec->minimum);
988 upper = describe_double_constant (pspec->maximum);
989 if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXFLOAT))
991 if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
992 desc = g_strdup ("");
994 desc = g_strdup_printf ("<= %s", upper);
996 else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
997 desc = g_strdup_printf (">= %s", lower);
999 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1003 else if (G_IS_PARAM_SPEC_DOUBLE (spec))
1005 GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
1007 lower = describe_double_constant (pspec->minimum);
1008 upper = describe_double_constant (pspec->maximum);
1009 if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXDOUBLE))
1011 if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
1012 desc = g_strdup ("");
1014 desc = g_strdup_printf ("<= %s", upper);
1016 else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
1017 desc = g_strdup_printf (">= %s", lower);
1019 desc = g_strdup_printf ("[%s,%s]", lower, upper);
1023 #if GLIB_CHECK_VERSION (2, 12, 0)
1024 else if (G_IS_PARAM_SPEC_GTYPE (spec))
1026 GParamSpecGType *pspec = G_PARAM_SPEC_GTYPE (spec);
1027 gboolean is_pointer;
1029 desc = g_strdup (get_type_name (pspec->is_a_type, &is_pointer));
1032 #if GLIB_CHECK_VERSION (2, 25, 9)
1033 else if (G_IS_PARAM_SPEC_VARIANT (spec))
1035 GParamSpecVariant *pspec = G_PARAM_SPEC_VARIANT (spec);
1036 gchar *variant_type;
1038 variant_type = g_variant_type_dup_string (pspec->type);
1039 desc = g_strdup_printf ("GVariant<%s>", variant_type);
1040 g_free (variant_type);
1045 desc = g_strdup ("");
1052 describe_default (GParamSpec *spec)
1056 if (G_IS_PARAM_SPEC_CHAR (spec))
1058 GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);
1060 desc = g_strdup_printf ("%d", pspec->default_value);
1062 else if (G_IS_PARAM_SPEC_UCHAR (spec))
1064 GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);
1066 desc = g_strdup_printf ("%u", pspec->default_value);
1068 else if (G_IS_PARAM_SPEC_BOOLEAN (spec))
1070 GParamSpecBoolean *pspec = G_PARAM_SPEC_BOOLEAN (spec);
1072 desc = g_strdup_printf ("%s", pspec->default_value ? "TRUE" : "FALSE");
1074 else if (G_IS_PARAM_SPEC_INT (spec))
1076 GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);
1078 desc = g_strdup_printf ("%d", pspec->default_value);
1080 else if (G_IS_PARAM_SPEC_UINT (spec))
1082 GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);
1084 desc = g_strdup_printf ("%u", pspec->default_value);
1086 else if (G_IS_PARAM_SPEC_LONG (spec))
1088 GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);
1090 desc = g_strdup_printf ("%ld", pspec->default_value);
1092 else if (G_IS_PARAM_SPEC_LONG (spec))
1094 GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
1096 desc = g_strdup_printf ("%lu", pspec->default_value);
1098 else if (G_IS_PARAM_SPEC_INT64 (spec))
1100 GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);
1102 desc = g_strdup_printf ("%" G_GINT64_FORMAT, pspec->default_value);
1104 else if (G_IS_PARAM_SPEC_UINT64 (spec))
1106 GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);
1108 desc = g_strdup_printf ("%" G_GUINT64_FORMAT, pspec->default_value);
1110 else if (G_IS_PARAM_SPEC_UNICHAR (spec))
1112 GParamSpecUnichar *pspec = G_PARAM_SPEC_UNICHAR (spec);
1114 if (g_unichar_isprint (pspec->default_value))
1115 desc = g_strdup_printf ("'%c'", pspec->default_value);
1117 desc = g_strdup_printf ("%u", pspec->default_value);
1119 else if (G_IS_PARAM_SPEC_ENUM (spec))
1121 GParamSpecEnum *pspec = G_PARAM_SPEC_ENUM (spec);
1123 GEnumValue *value = g_enum_get_value (pspec->enum_class, pspec->default_value);
1125 desc = g_strdup_printf ("%s", value->value_name);
1127 desc = g_strdup_printf ("%d", pspec->default_value);
1129 else if (G_IS_PARAM_SPEC_FLAGS (spec))
1131 GParamSpecFlags *pspec = G_PARAM_SPEC_FLAGS (spec);
1132 guint default_value;
1135 default_value = pspec->default_value;
1136 acc = g_string_new ("");
1138 while (default_value)
1140 GFlagsValue *value = g_flags_get_first_value (pspec->flags_class, default_value);
1146 g_string_append (acc, "|");
1147 g_string_append (acc, value->value_name);
1149 default_value &= ~value->value;
1152 if (default_value == 0)
1153 desc = g_string_free (acc, FALSE);
1156 desc = g_strdup_printf ("%d", pspec->default_value);
1157 g_string_free (acc, TRUE);
1160 else if (G_IS_PARAM_SPEC_FLOAT (spec))
1162 GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);
1164 /* make sure floats are output with a decimal dot irrespective of
1165 * current locale. Use formatd since we want human-readable numbers
1166 * and do not need the exact same bit representation when deserialising */
1167 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
1168 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
1169 pspec->default_value);
1171 else if (G_IS_PARAM_SPEC_DOUBLE (spec))
1173 GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);
1175 /* make sure floats are output with a decimal dot irrespective of
1176 * current locale. Use formatd since we want human-readable numbers
1177 * and do not need the exact same bit representation when deserialising */
1178 desc = g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
1179 g_ascii_formatd (desc, G_ASCII_DTOSTR_BUF_SIZE, "%g",
1180 pspec->default_value);
1182 else if (G_IS_PARAM_SPEC_STRING (spec))
1184 GParamSpecString *pspec = G_PARAM_SPEC_STRING (spec);
1186 if (pspec->default_value)
1188 gchar *esc = g_strescape (pspec->default_value, NULL);
1190 desc = g_strdup_printf ("\\"%s\\"", esc);
1195 desc = g_strdup_printf ("NULL");
1197 #if GLIB_CHECK_VERSION (2, 25, 9)
1198 else if (G_IS_PARAM_SPEC_VARIANT (spec))
1200 GParamSpecVariant *pspec = G_PARAM_SPEC_VARIANT (spec);
1202 if (pspec->default_value)
1203 desc = g_variant_print (pspec->default_value, TRUE);
1205 desc = g_strdup ("NULL");
1210 desc = g_strdup ("");
1218 output_object_args (FILE *fp, GType object_type)
1221 const gchar *object_class_name;
1223 gchar flags[16], *pos;
1224 GParamSpec **properties;
1226 gboolean child_prop;
1227 gboolean style_prop;
1228 gboolean is_pointer;
1229 const gchar *type_name;
1231 gchar *default_value;
1233 if (G_TYPE_IS_OBJECT (object_type))
1235 class = g_type_class_peek (object_type);
1239 properties = g_object_class_list_properties (class, &n_properties);
1241 #if GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 3)
1242 else if (G_TYPE_IS_INTERFACE (object_type))
1244 class = g_type_default_interface_ref (object_type);
1249 properties = g_object_interface_list_properties (class, &n_properties);
1255 object_class_name = g_type_name (object_type);
1261 qsort (properties, n_properties, sizeof (GParamSpec *), compare_param_specs);
1262 for (arg = 0; arg < n_properties; arg++)
1264 GParamSpec *spec = properties[arg];
1265 const gchar *nick, *blurb, *dot;
1267 if (spec->owner_type != object_type)
1271 /* We use one-character flags for simplicity. */
1272 if (child_prop && !style_prop)
1276 if (spec->flags & G_PARAM_READABLE)
1278 if (spec->flags & G_PARAM_WRITABLE)
1280 if (spec->flags & G_PARAM_CONSTRUCT)
1282 if (spec->flags & G_PARAM_CONSTRUCT_ONLY)
1286 nick = g_param_spec_get_nick (spec);
1287 blurb = g_param_spec_get_blurb (spec);
1291 int str_len = strlen (blurb);
1292 if (str_len > 0 && blurb[str_len - 1] != '.')
1296 type_desc = describe_type (spec);
1297 default_value = describe_default (spec);
1298 type_name = get_type_name (spec->value_type, &is_pointer);
1299 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",
1300 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);
1302 g_free (default_value);
1305 g_free (properties);
1307 #ifdef GTK_IS_CONTAINER_CLASS
1308 if (!child_prop && GTK_IS_CONTAINER_CLASS (class)) {
1309 properties = gtk_container_class_list_child_properties (class, &n_properties);
1315 #ifdef GTK_IS_CELL_AREA_CLASS
1316 if (!child_prop && GTK_IS_CELL_AREA_CLASS (class)) {
1317 properties = gtk_cell_area_class_list_cell_properties (class, &n_properties);
1323 #ifdef GTK_IS_WIDGET_CLASS
1324 #if GTK_CHECK_VERSION(2,1,0)
1325 if (!style_prop && GTK_IS_WIDGET_CLASS (class)) {
1326 properties = gtk_widget_class_list_style_properties (GTK_WIDGET_CLASS (class), &n_properties);
1335 if ($QUERY_CHILD_PROPERTIES) {
1338 properties = $QUERY_CHILD_PROPERTIES (class, &n_properties);
1356 # Compile and run our file
1358 $CC = $ENV{CC} ? $ENV{CC} : "gcc";
1359 $LD = $ENV{LD} ? $ENV{LD} : $CC;
1360 $CFLAGS = $ENV{CFLAGS} ? $ENV{CFLAGS} : "";
1361 $LDFLAGS = $ENV{LDFLAGS} ? $ENV{LDFLAGS} : "";
1362 $RUN = $ENV{RUN} ? $ENV{RUN} : "";
1365 if ($CC =~ /libtool/) {
1366 $o_file = "$MODULE-scan.lo"
1368 $o_file = "$MODULE-scan.o"
1372 if (!defined($VERBOSE) or $VERBOSE eq "0") {
1373 $stdout=">/dev/null";
1377 $command = "$CC $stdout $CFLAGS -c -o $o_file $MODULE-scan.c";
1378 system("($command)") == 0 or die "Compilation of scanner failed: $!\n";
1381 # FIXME: Can we turn off as-needed for the docs (or better fix it?)
1382 #$command = "$LD -Wl,--no-as-needed $o_file $LDFLAGS -o $MODULE-scan";
1383 $command = "$LD $stdout $o_file $LDFLAGS -o $MODULE-scan";
1384 system("($command)") == 0 or die "Linking of scanner failed: $!\n";
1386 # Running scanner $MODULE-scan ";
1387 system("($RUN ./$MODULE-scan)") == 0 or die "Scan failed: $!\n";
1390 if (!defined($ENV{"GTK_DOC_KEEP_INTERMEDIATE"})) {
1391 unlink "./$MODULE-scan.c", "./$MODULE-scan.o", "./$MODULE-scan.lo", "./$MODULE-scan";
1394 &UpdateFileIfChanged ($old_signals_filename, $new_signals_filename, 0);
1395 &UpdateFileIfChanged ($old_hierarchy_filename, $new_hierarchy_filename, 0);
1396 &UpdateFileIfChanged ($old_interfaces_filename, $new_interfaces_filename, 0);
1397 &UpdateFileIfChanged ($old_prerequisites_filename, $new_prerequisites_filename, 0);
1398 &UpdateFileIfChanged ($old_args_filename, $new_args_filename, 0);