1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307, USA.
27 #include <glib-object.h>
28 #include <glib/gprintf.h>
31 static gchar *indent_inc = NULL;
32 static guint spacing = 1;
33 static FILE *f_out = NULL;
34 static GType root = 0;
35 static gboolean recursion = TRUE;
38 # define O_SPACE "\\as"
40 # define O_BRANCH "\\aE"
41 # define O_VLINE "\\al"
42 # define O_LLEAF "\\aL"
43 # define O_KEY_FILL "_"
50 # define O_KEY_FILL "_"
54 show_nodes (GType type,
64 children = g_type_children (type, NULL);
67 for (i = 0; i < spacing; i++)
68 g_fprintf (f_out, "%s%s\n", indent, O_VLINE);
70 g_fprintf (f_out, "%s%s%s%s",
72 sibling ? O_BRANCH : (type != root ? O_LLEAF : O_SPACE),
76 for (i = strlen (g_type_name (type)); i <= strlen (indent_inc); i++)
77 fputs (O_KEY_FILL, f_out);
81 if (children && recursion)
87 new_indent = g_strconcat (indent, O_VLINE, indent_inc, NULL);
89 new_indent = g_strconcat (indent, O_SPACE, indent_inc, NULL);
91 for (child = children; *child; child++)
92 show_nodes (child[0], child[1], new_indent);
103 g_fprintf (stderr, "usage: gobject-query <qualifier> [-r <type>] [-{i|b} \"\"] [-s #] [-{h|x|y}]\n");
104 g_fprintf (stderr, " -r specifiy root type\n");
105 g_fprintf (stderr, " -n don't descend type tree\n");
106 g_fprintf (stderr, " -h guess what ;)\n");
107 g_fprintf (stderr, " -b specify indent string\n");
108 g_fprintf (stderr, " -i specify incremental indent string\n");
109 g_fprintf (stderr, " -s specify line spacing\n");
110 g_fprintf (stderr, "qualifiers:\n");
111 g_fprintf (stderr, " froots iterate over fundamental roots\n");
112 g_fprintf (stderr, " tree print type tree\n");
121 GLogLevelFlags fatal_mask;
122 gboolean gen_froots = 0;
123 gboolean gen_tree = 0;
129 fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
130 fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
131 g_log_set_always_fatal (fatal_mask);
133 root = G_TYPE_OBJECT;
135 for (i = 1; i < argc; i++)
137 if (strcmp ("-s", argv[i]) == 0)
141 spacing = atoi (argv[i]);
143 else if (strcmp ("-i", argv[i]) == 0)
155 indent_inc = g_new (gchar, n * strlen (O_SPACE) + 1);
160 strcpy (indent_inc, O_SPACE);
164 else if (strcmp ("-b", argv[i]) == 0)
170 else if (strcmp ("-r", argv[i]) == 0)
174 root = g_type_from_name (argv[i]);
176 else if (strcmp ("-n", argv[i]) == 0)
180 else if (strcmp ("froots", argv[i]) == 0)
184 else if (strcmp ("tree", argv[i]) == 0)
188 else if (strcmp ("-h", argv[i]) == 0)
192 else if (strcmp ("--help", argv[i]) == 0)
197 return help (argv[i]);
200 if (!gen_froots && !gen_tree)
201 return help (argv[i-1]);
205 indent_inc = g_new (gchar, strlen (O_SPACE) + 1);
207 strcpy (indent_inc, O_SPACE);
211 show_nodes (root, 0, iindent);
215 for (i = 0; i <= G_TYPE_FUNDAMENTAL_MAX; i += G_TYPE_MAKE_FUNDAMENTAL (1))
217 const gchar *name = g_type_name (i);
220 show_nodes (i, 0, iindent);