sl@0: /* GObject - GLib Type, Object, Parameter and Signal Library sl@0: * Copyright (C) 1998-1999, 2000-2001 Tim Janik and Red Hat, Inc. sl@0: * Portions copyright (c) 2009 Nokia Corporation. All rights reserved. sl@0: * This library is free software; you can redistribute it and/or sl@0: * modify it under the terms of the GNU Lesser General Public sl@0: * License as published by the Free Software Foundation; either sl@0: * version 2 of the License, or (at your option) any later version. sl@0: * sl@0: * This library is distributed in the hope that it will be useful, sl@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of sl@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU sl@0: * Lesser General Public License for more details. sl@0: * sl@0: * You should have received a copy of the GNU Lesser General sl@0: * Public License along with this library; if not, write to the sl@0: * Free Software Foundation, Inc., 59 Temple Place, Suite 330, sl@0: * Boston, MA 02111-1307, USA. sl@0: */ sl@0: sl@0: #include "config.h" sl@0: sl@0: #include sl@0: #include sl@0: #ifdef HAVE_UNISTD_H sl@0: #include sl@0: #endif sl@0: #include sl@0: #include sl@0: sl@0: #include sl@0: #include sl@0: #ifdef __SYMBIAN32__ sl@0: #include "mrt2_glib2_test.h" sl@0: #endif /*__SYMBIAN32__*/ sl@0: sl@0: static gchar *indent_inc = NULL; sl@0: static guint spacing = 1; sl@0: static FILE *f_out = NULL; sl@0: static GType root = 0; sl@0: static gboolean recursion = TRUE; sl@0: sl@0: #if 0 sl@0: # define O_SPACE "\\as" sl@0: # define O_ESPACE " " sl@0: # define O_BRANCH "\\aE" sl@0: # define O_VLINE "\\al" sl@0: # define O_LLEAF "\\aL" sl@0: # define O_KEY_FILL "_" sl@0: #else sl@0: # define O_SPACE " " sl@0: # define O_ESPACE "" sl@0: # define O_BRANCH "+" sl@0: # define O_VLINE "|" sl@0: # define O_LLEAF "`" sl@0: # define O_KEY_FILL "_" sl@0: #endif sl@0: sl@0: static void sl@0: show_nodes (GType type, sl@0: GType sibling, sl@0: const gchar *indent) sl@0: { sl@0: GType *children; sl@0: guint i; sl@0: sl@0: if (!type) sl@0: return; sl@0: sl@0: children = g_type_children (type, NULL); sl@0: sl@0: if (type != root) sl@0: for (i = 0; i < spacing; i++) sl@0: g_fprintf (f_out, "%s%s\n", indent, O_VLINE); sl@0: sl@0: g_fprintf (f_out, "%s%s%s%s", sl@0: indent, sl@0: sibling ? O_BRANCH : (type != root ? O_LLEAF : O_SPACE), sl@0: O_ESPACE, sl@0: g_type_name (type)); sl@0: sl@0: for (i = strlen (g_type_name (type)); i <= strlen (indent_inc); i++) sl@0: fputs (O_KEY_FILL, f_out); sl@0: sl@0: fputc ('\n', f_out); sl@0: sl@0: if (children && recursion) sl@0: { sl@0: gchar *new_indent; sl@0: GType *child; sl@0: sl@0: if (sibling) sl@0: new_indent = g_strconcat (indent, O_VLINE, indent_inc, NULL); sl@0: else sl@0: new_indent = g_strconcat (indent, O_SPACE, indent_inc, NULL); sl@0: sl@0: for (child = children; *child; child++) sl@0: show_nodes (child[0], child[1], new_indent); sl@0: sl@0: g_free (new_indent); sl@0: } sl@0: sl@0: g_free (children); sl@0: } sl@0: sl@0: static gint sl@0: help (gchar *arg) sl@0: { sl@0: g_fprintf (stderr, "usage: gobject-query [-r ] [-{i|b} \"\"] [-s #] [-{h|x|y}]\n"); sl@0: g_fprintf (stderr, " -r specifiy root type\n"); sl@0: g_fprintf (stderr, " -n don't descend type tree\n"); sl@0: g_fprintf (stderr, " -h guess what ;)\n"); sl@0: g_fprintf (stderr, " -b specify indent string\n"); sl@0: g_fprintf (stderr, " -i specify incremental indent string\n"); sl@0: g_fprintf (stderr, " -s specify line spacing\n"); sl@0: g_fprintf (stderr, "qualifiers:\n"); sl@0: g_fprintf (stderr, " froots iterate over fundamental roots\n"); sl@0: g_fprintf (stderr, " tree print type tree\n"); sl@0: sl@0: return arg != NULL; sl@0: } sl@0: sl@0: int sl@0: main (gint argc, sl@0: gchar *argv[]) sl@0: { sl@0: GLogLevelFlags fatal_mask; sl@0: gboolean gen_froots = 0; sl@0: gboolean gen_tree = 0; sl@0: gint i; sl@0: gchar *iindent = ""; sl@0: #ifdef __SYMBIAN32__ sl@0: g_log_set_handler (NULL, G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL); sl@0: g_set_print_handler(mrtPrintHandler); sl@0: #endif /*__SYMBIAN32__*/ sl@0: f_out = stdout; sl@0: sl@0: fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK); sl@0: fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL; sl@0: g_log_set_always_fatal (fatal_mask); sl@0: sl@0: root = G_TYPE_OBJECT; sl@0: sl@0: g_type_init (); sl@0: sl@0: for (i = 1; i < argc; i++) sl@0: { sl@0: if (strcmp ("-s", argv[i]) == 0) sl@0: { sl@0: i++; sl@0: if (i < argc) sl@0: spacing = atoi (argv[i]); sl@0: } sl@0: else if (strcmp ("-i", argv[i]) == 0) sl@0: { sl@0: i++; sl@0: if (i < argc) sl@0: { sl@0: char *p; sl@0: guint n; sl@0: sl@0: p = argv[i]; sl@0: while (*p) sl@0: p++; sl@0: n = p - argv[i]; sl@0: indent_inc = g_new (gchar, n * strlen (O_SPACE) + 1); sl@0: *indent_inc = 0; sl@0: while (n) sl@0: { sl@0: n--; sl@0: strcpy (indent_inc, O_SPACE); sl@0: } sl@0: } sl@0: } sl@0: else if (strcmp ("-b", argv[i]) == 0) sl@0: { sl@0: i++; sl@0: if (i < argc) sl@0: iindent = argv[i]; sl@0: } sl@0: else if (strcmp ("-r", argv[i]) == 0) sl@0: { sl@0: i++; sl@0: if (i < argc) sl@0: root = g_type_from_name (argv[i]); sl@0: } sl@0: else if (strcmp ("-n", argv[i]) == 0) sl@0: { sl@0: recursion = FALSE; sl@0: } sl@0: else if (strcmp ("froots", argv[i]) == 0) sl@0: { sl@0: gen_froots = 1; sl@0: } sl@0: else if (strcmp ("tree", argv[i]) == 0) sl@0: { sl@0: gen_tree = 1; sl@0: } sl@0: else if (strcmp ("-h", argv[i]) == 0) sl@0: { sl@0: return help (NULL); sl@0: } sl@0: else if (strcmp ("--help", argv[i]) == 0) sl@0: { sl@0: return help (NULL); sl@0: } sl@0: else sl@0: return help (argv[i]); sl@0: } sl@0: sl@0: if (!gen_froots && !gen_tree) sl@0: return help (argv[i-1]); sl@0: sl@0: if (!indent_inc) sl@0: { sl@0: indent_inc = g_new (gchar, strlen (O_SPACE) + 1); sl@0: *indent_inc = 0; sl@0: strcpy (indent_inc, O_SPACE); sl@0: } sl@0: sl@0: if (gen_tree) sl@0: show_nodes (root, 0, iindent); sl@0: if (gen_froots) sl@0: { sl@0: root = ~0; sl@0: for (i = 0; i <= G_TYPE_FUNDAMENTAL_MAX; i += G_TYPE_MAKE_FUNDAMENTAL (1)) sl@0: { sl@0: const gchar *name = g_type_name (i); sl@0: sl@0: if (name) sl@0: show_nodes (i, 0, iindent); sl@0: } sl@0: } sl@0: #ifdef __SYMBIAN32__ sl@0: testResultXml("gobject-querry"); sl@0: #endif /* EMULATOR */ sl@0: return 0; sl@0: }