gstdoc-scangobj 44.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#!/usr/bin/perl -w
# -*- cperl -*-
#
# gtk-doc - GTK DocBook documentation generator.
# Copyright (C) 1998  Damon Chaplin
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

#
# This gets information about object heirarchies and signals
# by compiling a small C program. CFLAGS and LDFLAGS must be
# set appropriately before running this script.
#
# NOTE: the lookup_signal_arg_names() function contains the argument names of
#       standard GTK signal handlers. This may need to be updated for new
#       GTK signals or Gnome widget signals.

use Getopt::Long;

unshift @INC, '/usr/share/gtk-doc/data';
require "gtkdoc-common.pl";

# Options

# name of documentation module
my $MODULE;
my $OUTPUT_DIR;
my $PRINT_VERSION;
my $PRINT_HELP;
my $TYPE_INIT_FUNC="g_type_init ()";

# --nogtkinit is deprecated, as it is the default now anyway.
%optctl = (module => \$MODULE,
47
           source => \$SOURCE,
48 49 50 51 52 53 54
	   types => \$TYPES_FILE,
	   nogtkinit => \$NO_GTK_INIT,
	   'type-init-func' => \$TYPE_INIT_FUNC,
	   'output-dir' => \$OUTPUT_DIR,
	   'version' => \$PRINT_VERSION,
	   'help' => \$PRINT_HELP);
	   
55
GetOptions(\%optctl, "module=s", "source=s", "types:s", "output-dir:s", "nogtkinit", "type-init-func:s", "version", "help");
56 57 58 59 60 61

if ($NO_GTK_INIT) {
  # Do nothing. This just avoids a warning.
}

if ($PRINT_VERSION) {
62
    print "1.5\n";
63 64 65 66 67 68 69 70
    exit 0;
}

if (!$MODULE) {
    $PRINT_HELP = 1;
}

if ($PRINT_HELP) {
71
    print "gstdoc-scangobj version 1.5\n";
72
    print "\n--module=MODULE_NAME  Name of the doc module being parsed";
73
    print "\n--source=SOURCE_NAME  Name of the source module for plugins";
74 75 76 77 78 79 80 81 82 83
    print "\n--types=FILE          The name of the file to store the types in";
    print "\n--type-init-func=FUNC The init function to call instead of g_type_init ()";
    print "\n--output-dir=DIRNAME  The directory where the results are stored";
    print "\n--version             Print the version of this program";
    print "\n--help                Print this help\n";
    exit 0;
}

$OUTPUT_DIR = $OUTPUT_DIR ? $OUTPUT_DIR : ".";

84
$TYPES_FILE = $TYPES_FILE ? $TYPES_FILE : "$OUTPUT_DIR/$MODULE.types";
85

86 87
open (TYPES, $TYPES_FILE) || die "Cannot open $TYPES_FILE: $!\n";
open (OUTPUT, ">$MODULE-scan.c") || die "Cannot open $MODULE-scan.c: $!\n";
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102

my $old_signals_filename = "$OUTPUT_DIR/$MODULE.signals";
my $new_signals_filename = "$OUTPUT_DIR/$MODULE.signals.new";
my $old_hierarchy_filename = "$OUTPUT_DIR/$MODULE.hierarchy";
my $new_hierarchy_filename = "$OUTPUT_DIR/$MODULE.hierarchy.new";
my $old_interfaces_filename = "$OUTPUT_DIR/$MODULE.interfaces";
my $new_interfaces_filename = "$OUTPUT_DIR/$MODULE.interfaces.new";
my $old_prerequisites_filename = "$OUTPUT_DIR/$MODULE.prerequisites";
my $new_prerequisites_filename = "$OUTPUT_DIR/$MODULE.prerequisites.new";
my $old_args_filename = "$OUTPUT_DIR/$MODULE.args";
my $new_args_filename = "$OUTPUT_DIR/$MODULE.args.new";

# write a C program to scan the types

$includes = "";
103 104
@types = ();
@impl_types = ();
105 106 107 108

for (<TYPES>) {
    if (/^#include/) {
	$includes .= $_;
109 110 111 112 113 114 115 116 117 118 119
    } elsif (/^%/) {
	next;
    } elsif (/^\s*$/) {
	next;
    } elsif (/^type:(.*)$/) {
	$t = $1;
        chomp $t;
	push @impl_types, $t;
    } else {
	chomp;
	push @types, $_;
120 121 122
    }
}

123
$ntypes = @types + @impl_types;
124 125 126 127 128

print OUTPUT <<EOT;
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
129
#include <errno.h>
130 131

$includes
132

133 134 135 136 137 138 139 140 141 142 143 144
#ifdef GTK_IS_WIDGET_CLASS
#include <gtk/gtkversion.h>
#endif
GType *object_types = NULL;

static GType *
get_object_types (void)
{
    GList *plugins = NULL;
    GList *factories = NULL;
    GList *l;
    GstElementFactory *factory = NULL;
145
    GType type;
146 147 148

    gint i = 0;

149
    /* get a list of features from plugins in our source module */
150
    plugins = gst_registry_get_plugin_list (gst_registry_get_default());
151 152 153 154

    while (plugins) {
      GList *features;
      GstPlugin *plugin;
155
      const gchar *source;
156 157 158

      plugin = (GstPlugin *) (plugins->data);
      plugins = g_list_next (plugins);
159
      source = gst_plugin_get_source (plugin);
160 161
      /*g_print ("plugin: %s source: %s\\n", plugin->desc.name, source);*/
      if (!source || strcmp (source, "$SOURCE") != 0) {
162 163
        continue;
      }
164
      g_print ("plugin: %s source: %s\\n", plugin->desc.name, source);
165

166 167 168
      features =
          gst_registry_get_feature_list_by_plugin (gst_registry_get_default (),
          plugin->desc.name);
169 170 171
      while (features) {
        GstPluginFeature *feature;
        feature = GST_PLUGIN_FEATURE (features->data);
172 173
        feature = gst_plugin_feature_load (feature);
        if (!feature) {
174 175 176 177 178 179
          g_warning ("Could not load plugin feature %s",
                     gst_plugin_feature_get_name (feature));
        }

        if (GST_IS_ELEMENT_FACTORY (feature)) {
          factory = GST_ELEMENT_FACTORY (feature);
180
          factories = g_list_prepend (factories, factory);
181 182 183 184 185
        }
        features = g_list_next (features);
      }
    }

186
    g_message ("number of element factories: %d", g_list_length (factories));
187 188

    /* allocate the object_types array to hold them */
189
    object_types = g_new0 (GType, g_list_length (factories)+$ntypes+1);
190 191 192 193 194 195 196 197

    l = factories;
    i = 0;

    /* fill it */
    while (l) {
      factory = GST_ELEMENT_FACTORY (l->data);
      type = gst_element_factory_get_element_type (factory);
198 199 200 201 202 203 204
      if (type != 0) {
        g_message ("adding type %p for factory %s", (void *) type, gst_element_factory_get_longname (factory));
        object_types[i++] = type;
      } else {
        g_message ("type info for factory %s not found",
            gst_element_factory_get_longname (factory));
      }
205 206
      l = g_list_next (l);
    }
207

208 209
EOT

210 211
# get_type functions:
for (@types) {
212 213 214 215 216 217 218 219 220
print OUTPUT <<EOT;
    type = $_ ();
    if (type == 0) {
      g_message ("$_ () didn't return a valid type");
    }
    else {
      object_types[i++] = type;
    }
EOT
221 222 223 224
}

# Implicit types retrieved from GLib:
for (@impl_types) {
225 226 227 228 229 230 231 232 233
print OUTPUT <<EOT;
    type = g_type_from_name ("$_");
    if (type == 0) {
      g_message ("Implicit type $_ not found");
    }
    else {
      object_types[i++] = type;
    }
EOT
234 235
}

236 237
print OUTPUT <<EOT;

238 239
    object_types[i] = 0;

240 241 242
    /* Need to make sure all the types are loaded in and initialize
     * their signals and properties.
     */
243
    for (i=0; object_types[i]; i++) {
244 245
      if (G_TYPE_IS_CLASSED (object_types[i]))
        g_type_class_ref (object_types[i]);
246 247 248
        else {
          g_warning ("not reffing type: %s", g_type_name (object_types[i]));
        }
249 250 251 252 253 254
    }

    return object_types;
}

/*
255
 * This uses GObject type functions to output signal prototypes and the object
256 257 258 259
 * hierarchy.
 */

/* The output files */
260 261 262 263 264
const gchar *signals_filename = "$new_signals_filename";
const gchar *hierarchy_filename = "$new_hierarchy_filename";
const gchar *interfaces_filename = "$new_interfaces_filename";
const gchar *prerequisites_filename = "$new_prerequisites_filename";
const gchar *args_filename = "$new_args_filename";
265 266 267


static void output_signals (void);
268
static void output_object_signals (FILE *fp,
269
				   GType object_type);
270
static void output_object_signal (FILE *fp,
271 272 273 274
				  const gchar *object_class_name,
				  guint signal_id);
static const gchar * get_type_name (GType type,
			            gboolean * is_pointer);
275 276 277
static const gchar * get_gdk_event (const gchar * signal_name);
static const gchar ** lookup_signal_arg_names (const gchar * type,
					       const gchar * signal_name);
278

279
static void output_object_hierarchy (void);
280 281 282 283
static void output_hierarchy (FILE *fp,
			      GType type,
			      guint level);

284
static void output_object_interfaces (void);
285 286 287 288 289 290 291 292
static void output_interfaces (FILE *fp,
			       GType type);

static void output_interface_prerequisites (void);
static void output_prerequisites (FILE *fp,
			          GType type);

static void output_args (void);
293
static void output_object_args (FILE *fp, GType object_type);
294 295 296 297

int
main (int argc, char *argv[])
{
298 299 300
  /* Silence the compiler: */
  if (argv != argv) argc = argc;

301 302 303 304 305
  $TYPE_INIT_FUNC;

  get_object_types ();

  output_signals ();
306 307
  output_object_hierarchy ();
  output_object_interfaces ();
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
  output_interface_prerequisites ();
  output_args ();

  return 0;
}


static void
output_signals (void)
{
  FILE *fp;
  gint i;

  fp = fopen (signals_filename, "w");
  if (fp == NULL)
    {
324
      g_warning ("Couldn't open output file: %s : %s", signals_filename, strerror(errno));
325 326 327
      return;
    }

328 329
  for (i = 0; object_types[i]; i++)
    output_object_signals (fp, object_types[i]);
330 331 332 333 334 335 336 337 338 339 340 341 342

  fclose (fp);
}

static gint
compare_signals (const void *a, const void *b)
{
  const guint *signal_a = a;
  const guint *signal_b = b;

  return strcmp (g_signal_name (*signal_a), g_signal_name (*signal_b));
}

343
/* This outputs all the signals of one object. */
344
static void
345
output_object_signals (FILE *fp, GType object_type)
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
{
  const gchar *object_class_name;
  guint *signals, n_signals;
  guint sig;

  if (G_TYPE_IS_INSTANTIATABLE (object_type) ||
      G_TYPE_IS_INTERFACE (object_type))
    {

      object_class_name = g_type_name (object_type);

      signals = g_signal_list_ids (object_type, &n_signals);
      qsort (signals, n_signals, sizeof (guint), compare_signals);

      for (sig = 0; sig < n_signals; sig++)
        {
362
           output_object_signal (fp, object_class_name, signals[sig]);
363 364 365 366 367 368 369 370
        }
      g_free (signals);
   }
}


/* This outputs one signal. */
static void
371
output_object_signal (FILE *fp,
372 373 374 375
		      const gchar *object_name,
		      guint signal_id)
{
  GSignalQuery query_info;
376 377
  const gchar *type_name, *ret_type, *object_arg, *arg_name;
  gchar *pos, *object_arg_lower;
378 379 380
  gboolean is_pointer;
  gchar ret_type_buffer[1024], buffer[1024];
  guint i, param;
381
  const gchar **arg_names;
382 383 384
  gint param_num, widget_num, event_num, callback_num;
  gint *arg_num;
  gchar signal_name[128];
385
  gchar flags[16];
386

387
  /*  g_print ("Object: %s Signal: %u\\n", object_name, signal_id);*/
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487

  param_num = 1;
  widget_num = event_num = callback_num = 0;

  g_signal_query (signal_id, &query_info);

  /* Output the return type and function name. */
  ret_type = get_type_name (query_info.return_type & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);
  sprintf (ret_type_buffer, "%s%s", ret_type, is_pointer ? "*" : "");

  /* Output the signal object type and the argument name. We assume the
     type is a pointer - I think that is OK. We remove "Gtk" or "Gnome" and
     convert to lower case for the argument name. */
  pos = buffer;
  sprintf (pos, "%s ", object_name);
  pos += strlen (pos);

  if (!strncmp (object_name, "Gtk", 3))
      object_arg = object_name + 3;
  else if (!strncmp (object_name, "Gnome", 5))
      object_arg = object_name + 5;
  else
      object_arg = object_name;

  object_arg_lower = g_ascii_strdown (object_arg, -1);
  sprintf (pos, "*%s\\n", object_arg_lower);
  pos += strlen (pos);
  if (!strncmp (object_arg_lower, "widget", 6))
    widget_num = 2;
  g_free(object_arg_lower);

  /* Convert signal name to use underscores rather than dashes '-'. */
  strcpy (signal_name, query_info.signal_name);
  for (i = 0; signal_name[i]; i++)
    {
      if (signal_name[i] == '-')
	signal_name[i] = '_';
    }

  /* Output the signal parameters. */
  arg_names = lookup_signal_arg_names (object_name, signal_name);

  for (param = 0; param < query_info.n_params; param++)
    {
      if (arg_names)
	{
	  sprintf (pos, "%s\\n", arg_names[param]);
	  pos += strlen (pos);
	}
      else
	{
	  type_name = get_type_name (query_info.param_types[param] & ~G_SIGNAL_TYPE_STATIC_SCOPE, &is_pointer);

	  /* Most arguments to the callback are called "arg1", "arg2", etc.
	     GdkWidgets are called "widget", "widget2", ...
	     GdkEvents are called "event", "event2", ...
	     GtkCallbacks are called "callback", "callback2", ... */
	  if (!strcmp (type_name, "GtkWidget"))
	    {
	      arg_name = "widget";
	      arg_num = &widget_num;
	    }
	  else if (!strcmp (type_name, "GdkEvent"))
	    {
	      type_name = get_gdk_event (signal_name);
	      arg_name = "event";
	      arg_num = &event_num;
	      is_pointer = TRUE;
	    }
	  else if (!strcmp (type_name, "GtkCallback")
		   || !strcmp (type_name, "GtkCCallback"))
	    {
	      arg_name = "callback";
	      arg_num = &callback_num;
	    }
	  else
	    {
	      arg_name = "arg";
	      arg_num = &param_num;
	    }
	  sprintf (pos, "%s ", type_name);
	  pos += strlen (pos);

	  if (!arg_num || *arg_num == 0)
	    sprintf (pos, "%s%s\\n", is_pointer ? "*" : " ", arg_name);
	  else
	    sprintf (pos, "%s%s%i\\n", is_pointer ? "*" : " ", arg_name,
		     *arg_num);
	  pos += strlen (pos);

	  if (arg_num)
	    {
	      if (*arg_num == 0)
		*arg_num = 2;
	      else
	        *arg_num += 1;
	    }
	}
    }

488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
  pos = flags;
  /* We use one-character flags for simplicity. */
  if (query_info.signal_flags & G_SIGNAL_RUN_FIRST)
    *pos++ = 'f';
  if (query_info.signal_flags & G_SIGNAL_RUN_LAST)
    *pos++ = 'l';
  if (query_info.signal_flags & G_SIGNAL_RUN_CLEANUP)
    *pos++ = 'c';
  if (query_info.signal_flags & G_SIGNAL_NO_RECURSE)
    *pos++ = 'r';
  if (query_info.signal_flags & G_SIGNAL_DETAILED)
    *pos++ = 'd';
  if (query_info.signal_flags & G_SIGNAL_ACTION)
    *pos++ = 'a';
  if (query_info.signal_flags & G_SIGNAL_NO_HOOKS)
    *pos++ = 'h';
  *pos = 0;

506
  fprintf (fp,
507 508
	   "<SIGNAL>\\n<NAME>%s::%s</NAME>\\n<RETURNS>%s</RETURNS>\\n<FLAGS>%s</FLAGS>\\n%s</SIGNAL>\\n\\n",
	   object_name, query_info.signal_name, ret_type_buffer, flags, buffer);
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
}


/* Returns the type name to use for a signal argument or return value, given
   the GtkType from the signal info. It also sets is_pointer to TRUE if the
   argument needs a '*' since it is a pointer. */
static const gchar *
get_type_name (GType type, gboolean * is_pointer)
{
  const gchar *type_name;

  *is_pointer = FALSE;
  type_name = g_type_name (type);

  switch (type) {
  case G_TYPE_NONE:
  case G_TYPE_CHAR:
  case G_TYPE_UCHAR:
  case G_TYPE_BOOLEAN:
  case G_TYPE_INT:
  case G_TYPE_UINT:
  case G_TYPE_LONG:
  case G_TYPE_ULONG:
  case G_TYPE_FLOAT:
  case G_TYPE_DOUBLE:
  case G_TYPE_POINTER:
    /* These all have normal C type names so they are OK. */
    return type_name;

  case G_TYPE_STRING:
    /* A GtkString is really a gchar*. */
    *is_pointer = TRUE;
    return "gchar";

  case G_TYPE_ENUM:
  case G_TYPE_FLAGS:
    /* We use a gint for both of these. Hopefully a subtype with a decent
       name will be registered and used instead, as GTK+ does itself. */
    return "gint";

  case G_TYPE_BOXED:
    /* The boxed type shouldn't be used itself, only subtypes. Though we
       return 'gpointer' just in case. */
    return "gpointer";

  case G_TYPE_PARAM:
    /* A GParam is really a GParamSpec*. */
    *is_pointer = TRUE;
    return "GParamSpec";

  default:
    break;
  }

563
  /* For all GObject subclasses we can use the class name with a "*",
564 565 566
     e.g. 'GtkWidget *'. */
  if (g_type_is_a (type, G_TYPE_OBJECT))
    *is_pointer = TRUE;
567

568 569
  if (G_TYPE_IS_CLASSED (type))
    *is_pointer = TRUE;
570 571 572 573 574 575 576 577 578

  /* All boxed subtypes will be pointers as well. */
  if (g_type_is_a (type, G_TYPE_BOXED))
    *is_pointer = TRUE;

  /* All pointer subtypes will be pointers as well. */
  if (g_type_is_a (type, G_TYPE_POINTER))
    *is_pointer = TRUE;

579 580 581 582 583
  /* But enums are not */
  if (g_type_is_a (type, G_TYPE_ENUM) ||
      g_type_is_a (type, G_TYPE_FLAGS))
    *is_pointer = FALSE;

584 585 586 587
  return type_name;
}


588
static const gchar *
589 590
get_gdk_event (const gchar * signal_name)
{
591
  static const gchar *GbGDKEvents[] =
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
  {
    "button_press_event", "GdkEventButton",
    "button_release_event", "GdkEventButton",
    "motion_notify_event", "GdkEventMotion",
    "delete_event", "GdkEvent",
    "destroy_event", "GdkEvent",
    "expose_event", "GdkEventExpose",
    "key_press_event", "GdkEventKey",
    "key_release_event", "GdkEventKey",
    "enter_notify_event", "GdkEventCrossing",
    "leave_notify_event", "GdkEventCrossing",
    "configure_event", "GdkEventConfigure",
    "focus_in_event", "GdkEventFocus",
    "focus_out_event", "GdkEventFocus",
    "map_event", "GdkEvent",
    "unmap_event", "GdkEvent",
    "property_notify_event", "GdkEventProperty",
    "selection_clear_event", "GdkEventSelection",
    "selection_request_event", "GdkEventSelection",
    "selection_notify_event", "GdkEventSelection",
    "proximity_in_event", "GdkEventProximity",
    "proximity_out_event", "GdkEventProximity",
    "drag_begin_event", "GdkEventDragBegin",
    "drag_request_event", "GdkEventDragRequest",
    "drag_end_event", "GdkEventDragRequest",
    "drop_enter_event", "GdkEventDropEnter",
    "drop_leave_event", "GdkEventDropLeave",
    "drop_data_available_event", "GdkEventDropDataAvailable",
    "other_event", "GdkEventOther",
    "client_event", "GdkEventClient",
    "no_expose_event", "GdkEventNoExpose",
    "visibility_notify_event", "GdkEventVisibility",
    "window_state_event", "GdkEventWindowState",
    "scroll_event", "GdkEventScroll",
    NULL
  };

  gint i;

  for (i = 0; GbGDKEvents[i]; i += 2)
    {
      if (!strcmp (signal_name, GbGDKEvents[i]))
	return GbGDKEvents[i + 1];
    }
  return "GdkEvent";
}


/* This returns argument names to use for some known GTK signals.
    It is passed a widget name, e.g. 'GtkCList' and a signal name, e.g.
    'select_row' and it returns a pointer to an array of argument types and
    names. */
644
static const gchar **
645 646 647 648
lookup_signal_arg_names (const gchar * type, const gchar * signal_name)
{
  /* Each arg array starts with the object type name and the signal name,
     and then signal arguments follow. */
649
  static const gchar *GbArgTable[][16] =
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863
  {
    {"GtkCList", "select_row",
     "gint             row",
     "gint             column",
     "GdkEventButton  *event"},
    {"GtkCList", "unselect_row",
     "gint             row",
     "gint             column",
     "GdkEventButton  *event"},
    {"GtkCList", "click_column",
     "gint             column"},

    {"GtkCList", "resize_column",
     "gint             column",
     "gint             width"},

    {"GtkCList", "extend_selection",
     "GtkScrollType    scroll_type",
     "gfloat           position",
     "gboolean         auto_start_selection"},
    {"GtkCList", "scroll_vertical",
     "GtkScrollType    scroll_type",
     "gfloat           position"},
    {"GtkCList", "scroll_horizontal",
     "GtkScrollType    scroll_type",
     "gfloat           position"},

    {"GtkCTree", "tree_select_row",
     "GtkCTreeNode    *node",
     "gint             column"},
    {"GtkCTree", "tree_unselect_row",
     "GtkCTreeNode    *node",
     "gint             column"},
    {"GtkCTree", "tree_expand",
     "GtkCTreeNode    *node"},
    {"GtkCTree", "tree_collapse",
     "GtkCTreeNode    *node"},
    {"GtkCTree", "tree_move",
     "GtkCTreeNode    *node",
     "GtkCTreeNode    *new_parent",
     "GtkCTreeNode    *new_sibling"},
    {"GtkCTree", "change_focus_row_expansion",
     "GtkCTreeExpansionType expansion"},

    {"GtkEditable", "insert_text",
     "gchar           *new_text",
     "gint             new_text_length",
     "gint            *position"},
    {"GtkEditable", "delete_text",
     "gint             start_pos",
     "gint             end_pos"},
    {"GtkEditable", "set_editable",
     "gboolean         is_editable"},
    {"GtkEditable", "move_cursor",
     "gint             x",
     "gint             y"},
    {"GtkEditable", "move_word",
     "gint             num_words"},
    {"GtkEditable", "move_page",
     "gint             x",
     "gint             y"},
    {"GtkEditable", "move_to_row",
     "gint             row"},
    {"GtkEditable", "move_to_column",
     "gint             column"},

    {"GtkEditable", "kill_char",
     "gint             direction"},
    {"GtkEditable", "kill_word",
     "gint             direction"},
    {"GtkEditable", "kill_line",
     "gint             direction"},


    {"GtkInputDialog", "enable_device",
     "GdkDevice       *deviceid"},
    {"GtkInputDialog", "disable_device",
     "GdkDevice       *deviceid"},

    {"GtkListItem", "extend_selection",
     "GtkScrollType    scroll_type",
     "gfloat           position",
     "gboolean         auto_start_selection"},
    {"GtkListItem", "scroll_vertical",
     "GtkScrollType    scroll_type",
     "gfloat           position"},
    {"GtkListItem", "scroll_horizontal",
     "GtkScrollType    scroll_type",
     "gfloat           position"},

    {"GtkMenuShell", "move_current",
     "GtkMenuDirectionType direction"},
    {"GtkMenuShell", "activate_current",
     "gboolean         force_hide"},


    {"GtkNotebook", "switch_page",
     "GtkNotebookPage *page",
     "guint            page_num"},
    {"GtkStatusbar", "text_pushed",
     "guint            context_id",
     "gchar           *text"},
    {"GtkStatusbar", "text_popped",
     "guint            context_id",
     "gchar           *text"},
    {"GtkTipsQuery", "widget_entered",
     "GtkWidget       *widget",
     "gchar           *tip_text",
     "gchar           *tip_private"},
    {"GtkTipsQuery", "widget_selected",
     "GtkWidget       *widget",
     "gchar           *tip_text",
     "gchar           *tip_private",
     "GdkEventButton  *event"},
    {"GtkToolbar", "orientation_changed",
     "GtkOrientation   orientation"},
    {"GtkToolbar", "style_changed",
     "GtkToolbarStyle  style"},
    {"GtkWidget", "draw",
     "GdkRectangle    *area"},
    {"GtkWidget", "size_request",
     "GtkRequisition  *requisition"},
    {"GtkWidget", "size_allocate",
     "GtkAllocation   *allocation"},
    {"GtkWidget", "state_changed",
     "GtkStateType     state"},
    {"GtkWidget", "style_set",
     "GtkStyle        *previous_style"},

    {"GtkWidget", "install_accelerator",
     "gchar           *signal_name",
     "gchar            key",
     "gint             modifiers"},

    {"GtkWidget", "add_accelerator",
     "guint            accel_signal_id",
     "GtkAccelGroup   *accel_group",
     "guint            accel_key",
     "GdkModifierType  accel_mods",
     "GtkAccelFlags    accel_flags"},

    {"GtkWidget", "parent_set",
     "GtkObject       *old_parent"},

    {"GtkWidget", "remove_accelerator",
     "GtkAccelGroup   *accel_group",
     "guint            accel_key",
     "GdkModifierType  accel_mods"},
    {"GtkWidget", "debug_msg",
     "gchar           *message"},
    {"GtkWindow", "move_resize",
     "gint            *x",
     "gint            *y",
     "gint             width",
     "gint             height"},
    {"GtkWindow", "set_focus",
     "GtkWidget       *widget"},

    {"GtkWidget", "selection_get",
     "GtkSelectionData *data",
     "guint            info",
     "guint            time"},
    {"GtkWidget", "selection_received",
     "GtkSelectionData *data",
     "guint            time"},

    {"GtkWidget", "drag_begin",
     "GdkDragContext  *drag_context"},
    {"GtkWidget", "drag_end",
     "GdkDragContext  *drag_context"},
    {"GtkWidget", "drag_data_delete",
     "GdkDragContext  *drag_context"},
    {"GtkWidget", "drag_leave",
     "GdkDragContext  *drag_context",
     "guint            time"},
    {"GtkWidget", "drag_motion",
     "GdkDragContext  *drag_context",
     "gint             x",
     "gint             y",
     "guint            time"},
    {"GtkWidget", "drag_drop",
     "GdkDragContext  *drag_context",
     "gint             x",
     "gint             y",
     "guint            time"},
    {"GtkWidget", "drag_data_get",
     "GdkDragContext  *drag_context",
     "GtkSelectionData *data",
     "guint            info",
     "guint            time"},
    {"GtkWidget", "drag_data_received",
     "GdkDragContext  *drag_context",
     "gint             x",
     "gint             y",
     "GtkSelectionData *data",
     "guint            info",
     "guint            time"},

    {NULL}
  };

  gint i;

  for (i = 0; GbArgTable[i][0]; i++)
    {
#if 1
      if (!strcmp (type, GbArgTable[i][0])
	  && !strcmp (signal_name, GbArgTable[i][1]))
	return &GbArgTable[i][2];
#endif
    }
  return NULL;
}

864
/* This outputs the hierarchy of all objects which have been initialized,
865 866
   i.e. by calling their XXX_get_type() initialization function. */
static void
867
output_object_hierarchy (void)
868 869
{
  FILE *fp;
870
  gint i;
871 872 873 874

  fp = fopen (hierarchy_filename, "w");
  if (fp == NULL)
    {
875
      g_warning ("Couldn't open output file: %s : %s", hierarchy_filename, strerror(errno));
876 877 878 879
      return;
    }
  output_hierarchy (fp, G_TYPE_OBJECT, 0);
  output_hierarchy (fp, G_TYPE_INTERFACE, 0);
880 881 882
  
  for (i=0; object_types[i]; i++) {
    if (!g_type_parent (object_types[i]) &&
883
      (object_types[i] != G_TYPE_NONE) &&
884 885 886
      (object_types[i] != G_TYPE_OBJECT) &&
      (object_types[i] != G_TYPE_INTERFACE)
    ) {
887 888
      g_warning ("printing hierarchy for root type: %s",
          g_type_name (object_types[i]));
889 890 891
      output_hierarchy (fp, object_types[i], 0);
    }
  }
892 893 894 895 896 897 898 899
  /* for debugging
  for (i=0; object_types[i]; i++) {
    if(object_types[i] != G_TYPE_NONE) {
      g_print ("type has not been added to hierarchy: %s\\n",
        g_type_name (object_types[i]));
    }
  }
  for debugging */
900

901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916
  fclose (fp);
}

/* This is called recursively to output the hierarchy of a widget. */
static void
output_hierarchy (FILE  *fp,
		  GType  type,
		  guint   level)
{
  guint i;
  GType *children;
  guint n_children;

  if (!type)
    return;

917 918 919 920 921 922 923 924 925 926 927
  /* for debugging
  for (i=0; object_types[i]; i++) {
    if(object_types[i] == type) {
      g_print ("added type to hierarchy (level %d): %s\\n",
        level, g_type_name (type));
      object_types[i] = G_TYPE_NONE;
      break;
    }
  }
  for debugging */

928 929
  for (i = 0; i < level; i++)
    fprintf (fp, "  ");
930
  fprintf (fp, "%s", g_type_name (type));
931 932 933 934
  fprintf (fp, "\\n");

  children = g_type_children (type, &n_children);

935
  for (i=0; i < n_children; i++) {
936
    output_hierarchy (fp, children[i], level + 1);
937
  }
938 939 940 941

  g_free (children);
}

942
static void output_object_interfaces (void)
943
{
944
  guint i;
945 946 947 948 949
  FILE *fp;

  fp = fopen (interfaces_filename, "w");
  if (fp == NULL)
    {
950
      g_warning ("Couldn't open output file: %s : %s", interfaces_filename, strerror(errno));
951 952 953
      return;
    }
  output_interfaces (fp, G_TYPE_OBJECT);
954 955 956 957 958 959 960 961 962 963

  for (i = 0; object_types[i]; i++)
    {
      if (!g_type_parent (object_types[i]) &&
          (object_types[i] != G_TYPE_OBJECT) &&
          G_TYPE_IS_INSTANTIATABLE (object_types[i]))
        {
          output_interfaces (fp, object_types[i]);
        }
    }
964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981
  fclose (fp);
}

static void
output_interfaces (FILE  *fp,
		   GType  type)
{
  guint i;
  GType *children, *interfaces;
  guint n_children, n_interfaces;

  if (!type)
    return;

  interfaces = g_type_interfaces (type, &n_interfaces);

  if (n_interfaces > 0)
    {
982
      fprintf (fp, "%s", g_type_name (type));
983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
      for (i=0; i < n_interfaces; i++)
          fprintf (fp, " %s", g_type_name (interfaces[i]));
      fprintf (fp, "\\n");
     }
  g_free (interfaces);

  children = g_type_children (type, &n_children);

  for (i=0; i < n_children; i++)
    output_interfaces (fp, children[i]);

  g_free (children);
}

static void output_interface_prerequisites (void)
{
  FILE *fp;

  fp = fopen (prerequisites_filename, "w");
  if (fp == NULL)
    {
1004
      g_warning ("Couldn't open output file: %s : %s", prerequisites_filename, strerror(errno));
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
      return;
    }
  output_prerequisites (fp, G_TYPE_INTERFACE);
  fclose (fp);
}

static void
output_prerequisites (FILE  *fp,
		      GType  type)
{
#if GLIB_CHECK_VERSION(2,1,0)
  guint i;
  GType *children, *prerequisites;
  guint n_children, n_prerequisites;

  if (!type)
    return;

  prerequisites = g_type_interface_prerequisites (type, &n_prerequisites);

  if (n_prerequisites > 0)
    {
1027
      fprintf (fp, "%s", g_type_name (type));
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
      for (i=0; i < n_prerequisites; i++)
          fprintf (fp, " %s", g_type_name (prerequisites[i]));
      fprintf (fp, "\\n");
     }
  g_free (prerequisites);

  children = g_type_children (type, &n_children);

  for (i=0; i < n_children; i++)
    output_prerequisites (fp, children[i]);

  g_free (children);
#endif
}

static void
output_args (void)
{
  FILE *fp;
  gint i;

  fp = fopen (args_filename, "w");
  if (fp == NULL)
    {
1052
      g_warning ("Couldn't open output file: %s : %s", args_filename, strerror(errno));
1053 1054 1055
      return;
    }

1056 1057 1058
  for (i = 0; object_types[i]; i++) {
    output_object_args (fp, object_types[i]);
  }
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076

  fclose (fp);
}

static gint
compare_param_specs (const void *a, const void *b)
{
  GParamSpec *spec_a = *(GParamSpec **)a;
  GParamSpec *spec_b = *(GParamSpec **)b;

  return strcmp (g_param_spec_get_name (spec_a), g_param_spec_get_name (spec_b));
}

/* Its common to have unsigned properties restricted
 * to the signed range. Therefore we make this look
 * a bit nicer by spelling out the max constants.
 */

1077 1078 1079
/* Don't use "==" with floats, it might trigger a gcc warning.  */
#define GTKDOC_COMPARE_FLOAT(x, y) (x <= y && x >= y)

1080 1081 1082 1083 1084
static gchar*
describe_double_constant (gdouble value)
{
  gchar *desc;

1085
  if (GTKDOC_COMPARE_FLOAT (value, G_MAXDOUBLE))
1086
    desc = g_strdup ("G_MAXDOUBLE");
1087
  else if (GTKDOC_COMPARE_FLOAT (value, G_MINDOUBLE))
1088
    desc = g_strdup ("G_MINDOUBLE");
1089
  else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXDOUBLE))
1090
    desc = g_strdup ("-G_MAXDOUBLE");
1091
  else if (GTKDOC_COMPARE_FLOAT (value, G_MAXFLOAT))
1092
    desc = g_strdup ("G_MAXFLOAT");
1093
  else if (GTKDOC_COMPARE_FLOAT (value, G_MINFLOAT))
1094
    desc = g_strdup ("G_MINFLOAT");
1095
  else if (GTKDOC_COMPARE_FLOAT (value, -G_MAXFLOAT))
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308
    desc = g_strdup ("-G_MAXFLOAT");
  else
    desc = g_strdup_printf ("%lg", value);

  return desc;
}

static gchar*
describe_signed_constant (gint64 value)
{
  gchar *desc;

  if (value == G_MAXINT)
    desc = g_strdup ("G_MAXINT");
  else if (value == G_MININT)
    desc = g_strdup ("G_MININT");
  else if (value == G_MAXUINT)
    desc = g_strdup ("G_MAXUINT");
  else if (value == G_MAXLONG)
    desc = g_strdup ("G_MAXLONG");
  else if (value == G_MINLONG)
    desc = g_strdup ("G_MINLONG");
  else if (value == G_MAXULONG)
    desc = g_strdup ("G_MAXULONG");
  else if (value == G_MAXINT64)
    desc = g_strdup ("G_MAXINT64");
  else if (value == G_MININT64)
    desc = g_strdup ("G_MININT64");
  else
    desc = g_strdup_printf ("%" G_GINT64_FORMAT, value);

  return desc;
}

static gchar*
describe_unsigned_constant (guint64 value)
{
  gchar *desc;

  if (value == G_MAXINT)
    desc = g_strdup ("G_MAXINT");
  else if (value == G_MININT)
    desc = g_strdup ("G_MININT");
  else if (value == G_MAXUINT)
    desc = g_strdup ("G_MAXUINT");
  else if (value == G_MAXLONG)
    desc = g_strdup ("G_MAXLONG");
  else if (value == G_MINLONG)
    desc = g_strdup ("G_MINLONG");
  else if (value == G_MAXULONG)
    desc = g_strdup ("G_MAXULONG");
  else if (value == G_MAXINT64)
    desc = g_strdup ("G_MAXINT64");
  else if (value == G_MININT64)
    desc = g_strdup ("G_MININT64");
  else if (value == G_MAXUINT64)
    desc = g_strdup ("G_MAXUINT64");
  else
    desc = g_strdup_printf ("%" G_GUINT64_FORMAT, value);

  return desc;
}

static gchar*
describe_type (GParamSpec *spec)
{
  gchar *desc;
  gchar *lower;
  gchar *upper;

  if (G_IS_PARAM_SPEC_CHAR (spec))
    {
      GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);

      lower = describe_signed_constant (pspec->minimum);
      upper = describe_signed_constant (pspec->maximum);
      if (pspec->minimum == G_MININT8 && pspec->maximum == G_MAXINT8)
	desc = g_strdup ("");
      else if (pspec->minimum == G_MININT8)
	desc = g_strdup_printf ("<= %s", upper);
      else if (pspec->maximum == G_MAXINT8)
	desc = g_strdup_printf (">= %s", lower);
      else
	desc = g_strdup_printf ("[%s,%s]", lower, upper);
      g_free (lower);
      g_free (upper);
    }
  else if (G_IS_PARAM_SPEC_UCHAR (spec))
    {
      GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);

      lower = describe_unsigned_constant (pspec->minimum);
      upper = describe_unsigned_constant (pspec->maximum);
      if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT8)
	desc = g_strdup ("");
      else if (pspec->minimum == 0)
	desc = g_strdup_printf ("<= %s", upper);
      else if (pspec->maximum == G_MAXUINT8)
	desc = g_strdup_printf (">= %s", lower);
      else
	desc = g_strdup_printf ("[%s,%s]", lower, upper);
      g_free (lower);
      g_free (upper);
    }
  else if (G_IS_PARAM_SPEC_INT (spec))
    {
      GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);

      lower = describe_signed_constant (pspec->minimum);
      upper = describe_signed_constant (pspec->maximum);
      if (pspec->minimum == G_MININT && pspec->maximum == G_MAXINT)
	desc = g_strdup ("");
      else if (pspec->minimum == G_MININT)
	desc = g_strdup_printf ("<= %s", upper);
      else if (pspec->maximum == G_MAXINT)
	desc = g_strdup_printf (">= %s", lower);
      else
	desc = g_strdup_printf ("[%s,%s]", lower, upper);
      g_free (lower);
      g_free (upper);
    }
  else if (G_IS_PARAM_SPEC_UINT (spec))
    {
      GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);

      lower = describe_unsigned_constant (pspec->minimum);
      upper = describe_unsigned_constant (pspec->maximum);
      if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT)
	desc = g_strdup ("");
      else if (pspec->minimum == 0)
	desc = g_strdup_printf ("<= %s", upper);
      else if (pspec->maximum == G_MAXUINT)
	desc = g_strdup_printf (">= %s", lower);
      else
	desc = g_strdup_printf ("[%s,%s]", lower, upper);
      g_free (lower);
      g_free (upper);
    }
  else if (G_IS_PARAM_SPEC_LONG (spec))
    {
      GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);

      lower = describe_signed_constant (pspec->minimum);
      upper = describe_signed_constant (pspec->maximum);
      if (pspec->minimum == G_MINLONG && pspec->maximum == G_MAXLONG)
	desc = g_strdup ("");
      else if (pspec->minimum == G_MINLONG)
	desc = g_strdup_printf ("<= %s", upper);
      else if (pspec->maximum == G_MAXLONG)
	desc = g_strdup_printf (">= %s", lower);
      else
	desc = g_strdup_printf ("[%s,%s]", lower, upper);
      g_free (lower);
      g_free (upper);
    }
  else if (G_IS_PARAM_SPEC_ULONG (spec))
    {
      GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);
      gchar *upper;

      lower = describe_unsigned_constant (pspec->minimum);
      upper = describe_unsigned_constant (pspec->maximum);
      if (pspec->minimum == 0 && pspec->maximum == G_MAXULONG)
	desc = g_strdup ("");
      else if (pspec->minimum == 0)
	desc = g_strdup_printf ("<= %s", upper);
      else if (pspec->maximum == G_MAXULONG)
	desc = g_strdup_printf (">= %s", lower);
      else
	desc = g_strdup_printf ("[%s,%s]", lower, upper);
      g_free (lower);
      g_free (upper);
    }
  else if (G_IS_PARAM_SPEC_INT64 (spec))
    {
      GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);

      lower = describe_signed_constant (pspec->minimum);
      upper = describe_signed_constant (pspec->maximum);
      if (pspec->minimum == G_MININT64 && pspec->maximum == G_MAXINT64)
	desc = g_strdup ("");
      else if (pspec->minimum == G_MININT64)
	desc = g_strdup_printf ("<= %s", upper);
      else if (pspec->maximum == G_MAXINT64)
	desc = g_strdup_printf (">= %s", lower);
      else
	desc = g_strdup_printf ("[%s,%s]", lower, upper);
      g_free (lower);
      g_free (upper);
    }
  else if (G_IS_PARAM_SPEC_UINT64 (spec))
    {
      GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);

      lower = describe_unsigned_constant (pspec->minimum);
      upper = describe_unsigned_constant (pspec->maximum);
      if (pspec->minimum == 0 && pspec->maximum == G_MAXUINT64)
	desc = g_strdup ("");
      else if (pspec->minimum == 0)
	desc = g_strdup_printf ("<= %s", upper);
      else if (pspec->maximum == G_MAXUINT64)
	desc = g_strdup_printf (">= %s", lower);
      else
	desc = g_strdup_printf ("[%s,%s]", lower, upper);
      g_free (lower);
      g_free (upper);
    }
  else if (G_IS_PARAM_SPEC_FLOAT (spec))
    {
      GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);

      lower = describe_double_constant (pspec->minimum);
      upper = describe_double_constant (pspec->maximum);
1309 1310 1311 1312 1313 1314 1315 1316
      if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXFLOAT))
	{
	  if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
	    desc = g_strdup ("");
	  else
	    desc = g_strdup_printf ("<= %s", upper);
	}
      else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXFLOAT))
1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328
	desc = g_strdup_printf (">= %s", lower);
      else
	desc = g_strdup_printf ("[%s,%s]", lower, upper);
      g_free (lower);
      g_free (upper);
    }
  else if (G_IS_PARAM_SPEC_DOUBLE (spec))
    {
      GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);

      lower = describe_double_constant (pspec->minimum);
      upper = describe_double_constant (pspec->maximum);
1329 1330 1331 1332 1333 1334 1335 1336
      if (GTKDOC_COMPARE_FLOAT (pspec->minimum, -G_MAXDOUBLE))
	{
	  if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
	    desc = g_strdup ("");
	  else
	    desc = g_strdup_printf ("<= %s", upper);
	}
      else if (GTKDOC_COMPARE_FLOAT (pspec->maximum, G_MAXDOUBLE))
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496
	desc = g_strdup_printf (">= %s", lower);
      else
	desc = g_strdup_printf ("[%s,%s]", lower, upper);
      g_free (lower);
      g_free (upper);
    }
  else
    {
      desc = g_strdup ("");
    }

  return desc;
}

static gchar*
describe_default (GParamSpec *spec)
{
  gchar *desc;

  if (G_IS_PARAM_SPEC_CHAR (spec))
    {
      GParamSpecChar *pspec = G_PARAM_SPEC_CHAR (spec);

      desc = g_strdup_printf ("%d", pspec->default_value);
    }
  else if (G_IS_PARAM_SPEC_UCHAR (spec))
    {
      GParamSpecUChar *pspec = G_PARAM_SPEC_UCHAR (spec);

      desc = g_strdup_printf ("%u", pspec->default_value);
    }
  else if (G_IS_PARAM_SPEC_BOOLEAN (spec))
    {
      GParamSpecBoolean *pspec = G_PARAM_SPEC_BOOLEAN (spec);

      desc = g_strdup_printf ("%s", pspec->default_value ? "TRUE" : "FALSE");
    }
  else if (G_IS_PARAM_SPEC_INT (spec))
    {
      GParamSpecInt *pspec = G_PARAM_SPEC_INT (spec);

      desc = g_strdup_printf ("%d", pspec->default_value);
    }
  else if (G_IS_PARAM_SPEC_UINT (spec))
    {
      GParamSpecUInt *pspec = G_PARAM_SPEC_UINT (spec);

      desc = g_strdup_printf ("%u", pspec->default_value);
    }
  else if (G_IS_PARAM_SPEC_LONG (spec))
    {
      GParamSpecLong *pspec = G_PARAM_SPEC_LONG (spec);

      desc = g_strdup_printf ("%ld", pspec->default_value);
    }
  else if (G_IS_PARAM_SPEC_LONG (spec))
    {
      GParamSpecULong *pspec = G_PARAM_SPEC_ULONG (spec);

      desc = g_strdup_printf ("%lu", pspec->default_value);
    }
  else if (G_IS_PARAM_SPEC_INT64 (spec))
    {
      GParamSpecInt64 *pspec = G_PARAM_SPEC_INT64 (spec);

      desc = g_strdup_printf ("%" G_GINT64_FORMAT, pspec->default_value);
    }
  else if (G_IS_PARAM_SPEC_UINT64 (spec))
    {
      GParamSpecUInt64 *pspec = G_PARAM_SPEC_UINT64 (spec);

      desc = g_strdup_printf ("%" G_GUINT64_FORMAT, pspec->default_value);
    }
  else if (G_IS_PARAM_SPEC_UNICHAR (spec))
    {
      GParamSpecUnichar *pspec = G_PARAM_SPEC_UNICHAR (spec);

      if (g_unichar_isprint (pspec->default_value))
	desc = g_strdup_printf ("'%c'", pspec->default_value);
      else
	desc = g_strdup_printf ("%u", pspec->default_value);
    }
  else if (G_IS_PARAM_SPEC_ENUM (spec))
    {
      GParamSpecEnum *pspec = G_PARAM_SPEC_ENUM (spec);

      GEnumValue *value = g_enum_get_value (pspec->enum_class, pspec->default_value);
      if (value)
	desc = g_strdup_printf ("%s", value->value_name);
      else
	desc = g_strdup_printf ("%d", pspec->default_value);
    }
  else if (G_IS_PARAM_SPEC_FLAGS (spec))
    {
      GParamSpecFlags *pspec = G_PARAM_SPEC_FLAGS (spec);
      guint default_value;
      GString *acc;

      default_value = pspec->default_value;
      acc = g_string_new ("");

      while (default_value)
	{
	  GFlagsValue *value = g_flags_get_first_value (pspec->flags_class, default_value);

	  if (!value)
	    break;

	  if (acc->len > 0)
	    g_string_append (acc, "|");
	  g_string_append (acc, value->value_name);

	  default_value &= ~value->value;
	}

      if (default_value == 0)
	desc = g_string_free (acc, FALSE);
      else
	{
	  desc = g_strdup_printf ("%d", pspec->default_value);
	  g_string_free (acc, TRUE);
	}
    }
  else if (G_IS_PARAM_SPEC_FLOAT (spec))
    {
      GParamSpecFloat *pspec = G_PARAM_SPEC_FLOAT (spec);

      desc = g_strdup_printf ("%g", pspec->default_value);
    }
  else if (G_IS_PARAM_SPEC_DOUBLE (spec))
    {
      GParamSpecDouble *pspec = G_PARAM_SPEC_DOUBLE (spec);

      desc = g_strdup_printf ("%lg", pspec->default_value);
    }
  else if (G_IS_PARAM_SPEC_STRING (spec))
    {
      GParamSpecString *pspec = G_PARAM_SPEC_STRING (spec);

      if (pspec->default_value)
	{
	  gchar *esc = g_strescape (pspec->default_value, NULL);

	  desc = g_strdup_printf ("\\"%s\\"", esc);

	  g_free (esc);
	}
      else
	desc = g_strdup_printf ("NULL");
    }
  else
    {
      desc = g_strdup ("");
    }

  return desc;
}


static void
1497
output_object_args (FILE *fp, GType object_type)
1498 1499 1500 1501 1502 1503 1504 1505 1506
{
  gpointer class;
  const gchar *object_class_name;
  guint arg;
  gchar flags[16], *pos;
  GParamSpec **properties;
  guint n_properties;
  gboolean child_prop;
  gboolean style_prop;
1507 1508
  gboolean is_pointer;
  const gchar *type_name;
1509 1510 1511
  gchar *type_desc;
  gchar *default_value;

1512
  if (G_TYPE_IS_OBJECT (object_type))
1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576
    {
      class = g_type_class_peek (object_type);
      if (!class)
	return;

      properties = g_object_class_list_properties (class, &n_properties);
    }
#if GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 3)
  else if (G_TYPE_IS_INTERFACE (object_type))
    {
      class = g_type_default_interface_ref (object_type);

      if (!class)
	return;

      properties = g_object_interface_list_properties (class, &n_properties);
    }
#endif
  else
    return;

  object_class_name = g_type_name (object_type);

  child_prop = FALSE;
  style_prop = FALSE;

  while (TRUE) {
    qsort (properties, n_properties, sizeof (GParamSpec *), compare_param_specs);
    for (arg = 0; arg < n_properties; arg++)
      {
        GParamSpec *spec = properties[arg];
        const gchar *nick, *blurb, *dot;

        if (spec->owner_type != object_type)
          continue;

        pos = flags;
        /* We use one-character flags for simplicity. */
        if (child_prop && !style_prop)
   	  *pos++ = 'c';
        if (style_prop)
   	  *pos++ = 's';
        if (spec->flags & G_PARAM_READABLE)
 	  *pos++ = 'r';
        if (spec->flags & G_PARAM_WRITABLE)
	  *pos++ = 'w';
        if (spec->flags & G_PARAM_CONSTRUCT)
	  *pos++ = 'x';
        if (spec->flags & G_PARAM_CONSTRUCT_ONLY)
	  *pos++ = 'X';
        *pos = 0;

        nick = g_param_spec_get_nick (spec);
        blurb = g_param_spec_get_blurb (spec);

        dot = "";
        if (blurb) {
          int str_len = strlen (blurb);
          if (str_len > 0  && blurb[str_len - 1] != '.')
            dot = ".";
        }

	type_desc = describe_type (spec);
	default_value = describe_default (spec);
1577 1578 1579
	type_name = get_type_name (spec->value_type, &is_pointer);
        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",
	         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);
1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614
	g_free (type_desc);
	g_free (default_value);
      }

    g_free (properties);

#ifdef GTK_IS_CONTAINER_CLASS
    if (!child_prop && GTK_IS_CONTAINER_CLASS (class)) {
      properties = gtk_container_class_list_child_properties (class, &n_properties);
      child_prop = TRUE;
      continue;
    }
#endif

#ifdef GTK_IS_WIDGET_CLASS
#if GTK_CHECK_VERSION(2,1,0)
    if (!style_prop && GTK_IS_WIDGET_CLASS (class)) {
      properties = gtk_widget_class_list_style_properties (GTK_WIDGET_CLASS (class), &n_properties);
      style_prop = TRUE;
      continue;
    }
#endif
#endif

    break;
  }
}
EOT

close OUTPUT;

# Compile and run our file

$CC = $ENV{CC} ? $ENV{CC} : "gcc";
$LD = $ENV{LD} ? $ENV{LD} : $CC;
1615
$CFLAGS = $ENV{CFLAGS} ? "$ENV{CFLAGS} -Wall -g" : "-Wall -g";
1616 1617 1618 1619 1620 1621 1622 1623 1624
$LDFLAGS = $ENV{LDFLAGS} ? $ENV{LDFLAGS} : "";

my $o_file;
if ($CC =~ /libtool/) {
  $o_file  = "$MODULE-scan.lo"
} else {
  $o_file = "$MODULE-scan.o"
}

1625 1626 1627
print "gtk-doc: Compiling scanner\n";
$command = "$CC $CFLAGS -c -o $o_file $MODULE-scan.c";
system($command) == 0 or die "Compilation of scanner failed: $!\n";
1628

1629 1630 1631
print "gtk-doc: Linking scanner\n";
$command = "$LD -o $MODULE-scan $o_file $LDFLAGS";
system($command) == 0 or die "Linking of scanner failed: $!\n";
1632

1633 1634
print "gtk-doc: Running scanner $MODULE-scan\n";
system("sh -c ./$MODULE-scan") == 0 or die "Scan failed: $!\n";
1635 1636 1637

unlink "./$MODULE-scan.c", "./$MODULE-scan.o", "./$MODULE-scan.lo", "./$MODULE-scan";

1638
#&UpdateFileIfChanged ($old_signals_filename, $new_signals_filename, 0);
1639 1640 1641
&UpdateFileIfChanged ($old_hierarchy_filename, $new_hierarchy_filename, 0);
&UpdateFileIfChanged ($old_interfaces_filename, $new_interfaces_filename, 0);
&UpdateFileIfChanged ($old_prerequisites_filename, $new_prerequisites_filename, 0);
1642
#&UpdateFileIfChanged ($old_args_filename, $new_args_filename, 0);
1643 1644