summaryrefslogtreecommitdiff
path: root/libgdict
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@src.gnome.org>2007-09-06 17:05:16 +0000
committerEmmanuele Bassi <ebassi@src.gnome.org>2007-09-06 17:05:16 +0000
commit7bbe862950ff5b8695fdf1f0e0df1efd1bf8a1e7 (patch)
treed7645a20f34f419869e9494bf28fdb0213c70968 /libgdict
parent18f7942129dd631ff6955227497ac0641ace9cbe (diff)
downloadgnome-dictionary-7bbe862950ff5b8695fdf1f0e0df1efd1bf8a1e7.tar.gz
Improve GDict debug messages handling
This commit changes the debug messages handling in GDict, using a system similar to the one GLib and GTK+ use. You can either set the GDICT_DEBUG environment variable to a colon-separated or comma-separated list of debug flags, or you can use the --gdict-debug and --gdict-no-debug command line arguments to switch on (and off) the debug flags. The GDICT_NOTE() macro has been added as well, replacing _gdict_debug() for a more comprehensive debug output. The entire debug message system is enabled either by calling the gdict_debug_init() function or by using the GOptionGroup that is returned by gdict_get_option_group(). The debug message system is also depending on whether the GDict library has been compiled with the GDICT_ENABLE_DEBUG flag -- which is the default for development/unstable cycles. svn path=/trunk/; revision=7661
Diffstat (limited to 'libgdict')
-rw-r--r--libgdict/Makefile.am9
-rw-r--r--libgdict/gdict-client-context.c122
-rw-r--r--libgdict/gdict-database-chooser.c17
-rw-r--r--libgdict/gdict-debug.c49
-rw-r--r--libgdict/gdict-debug.h39
-rw-r--r--libgdict/gdict-defbox.c7
-rw-r--r--libgdict/gdict-speller.c18
-rw-r--r--libgdict/gdict-strategy-chooser.c17
-rw-r--r--libgdict/gdict-utils.c181
-rw-r--r--libgdict/gdict-utils.h4
10 files changed, 312 insertions, 151 deletions
diff --git a/libgdict/Makefile.am b/libgdict/Makefile.am
index f86a5d2..5ea890d 100644
--- a/libgdict/Makefile.am
+++ b/libgdict/Makefile.am
@@ -2,12 +2,6 @@
NULL =
-if ENABLE_DEBUG
-GDICT_ENABLE_DEBUG=-DGDICT_ENABLE_DEBUG=1
-else
-GDICT_ENABLE_DEBUG=
-endif
-
INCLUDES = -DG_LOG_DOMAIN=\"Gdict\" \
-DDATADIR=\""$(datadir)"\" \
-DLIBDIR=\""$(libdir)"\" \
@@ -16,7 +10,7 @@ INCLUDES = -DG_LOG_DOMAIN=\"Gdict\" \
-DGNOMELOCALEDIR=\""$(gnomeutilslocaledir)"\" \
-DGDICTSOURCESDIR=\""$(datadir)/gdict-1.0/sources"\" \
-DGDICT_ENABLE_INTERNALS=1 \
- $(GDICT_ENABLE_DEBUG) \
+ $(GDICT_DEBUG_CFLAGS) \
$(DISABLE_DEPRECATED_CFLAGS) \
$(WARN_CFLAGS) \
$(NULL)
@@ -26,7 +20,6 @@ lib_LTLIBRARIES = libgdict-1.0.la
# GNOME Dictionary shared library
libgdict_1_0_la_SOURCES = \
gdict-private.h \
- gdict-debug.c \
gdict-debug.h \
gdict-context.c \
gdict-context.h \
diff --git a/libgdict/gdict-client-context.c b/libgdict/gdict-client-context.c
index db8cd29..4528bb8 100644
--- a/libgdict/gdict-client-context.c
+++ b/libgdict/gdict-client-context.c
@@ -55,6 +55,7 @@
#include "gdict-client-context.h"
#include "gdict-enum-types.h"
#include "gdict-marshal.h"
+#include "gdict-debug.h"
#include "gdict-utils.h"
#include "gdict-private.h"
@@ -723,8 +724,9 @@ gdict_client_context_push_command (GdictClientContext *context,
return FALSE;
}
- _gdict_debug ("Pushing command ('%s') into the queue...\n",
- dict_command_strings[command->cmd_type]);
+ GDICT_NOTE (DICT, "Pushing command ('%s') into the queue...",
+ dict_command_strings[command->cmd_type]);
+
g_queue_push_head (priv->commands_queue, command);
return TRUE;
@@ -744,8 +746,8 @@ gdict_client_context_pop_command (GdictClientContext *context)
if (!retval)
return NULL;
- _gdict_debug ("Getting command ('%s') from the queue...\n",
- dict_command_strings[retval->cmd_type]);
+ GDICT_NOTE (DICT, "Getting command ('%s') from the queue...",
+ dict_command_strings[retval->cmd_type]);
return retval;
}
@@ -768,7 +770,7 @@ gdict_client_context_send_command (GdictClientContext *context,
if (!priv->channel)
{
- _gdict_debug ("No connection established\n");
+ GDICT_NOTE (DICT, "No connection established");
g_set_error (error, GDICT_CLIENT_CONTEXT_ERROR,
GDICT_CLIENT_CONTEXT_ERROR_NO_CONNECTION,
@@ -795,8 +797,7 @@ gdict_client_context_send_command (GdictClientContext *context,
/* force flushing of the write buffer */
g_io_channel_flush (priv->channel, NULL);
- _gdict_debug ("Wrote (%d bytes) to the channel\n",
- written_bytes);
+ GDICT_NOTE (DICT, "Wrote %d bytes to the channel", written_bytes);
return TRUE;
}
@@ -819,17 +820,17 @@ gdict_client_context_run_command (GdictClientContext *context,
g_assert (command != NULL);
g_assert (IS_VALID_CMD (command->cmd_type));
- _gdict_debug ("GdictCommand command =\n"
- "{\n"
- " .cmd_type = '%02d' ('%s');\n"
- " .database = '%s';\n"
- " .strategy = '%s';\n"
- " .word = '%s';\n"
- "}\n",
- command->cmd_type, dict_command_strings[command->cmd_type],
- command->database ? command->database : "<none>",
- command->strategy ? command->strategy : "<none>",
- command->word ? command->word : "<none>");
+ GDICT_NOTE (DICT, "GdictCommand command =\n"
+ "{\n"
+ " .cmd_type = '%02d' ('%s');\n"
+ " .database = '%s';\n"
+ " .strategy = '%s';\n"
+ " .word = '%s';\n"
+ "}\n",
+ command->cmd_type, dict_command_strings[command->cmd_type],
+ command->database ? command->database : "<none>",
+ command->strategy ? command->strategy : "<none>",
+ command->word ? command->word : "<none>");
priv = context->priv;
@@ -885,8 +886,8 @@ gdict_client_context_run_command (GdictClientContext *context,
g_assert (command->cmd_string);
- _gdict_debug ("Sending command ('%s') to the server\n",
- dict_command_strings[command->cmd_type]);
+ GDICT_NOTE (DICT, "Sending command ('%s') to the server",
+ dict_command_strings[command->cmd_type]);
send_error = NULL;
res = gdict_client_context_send_command (context, command, &send_error);
@@ -1028,14 +1029,14 @@ gdict_client_context_lookup_server (GdictClientContext *context,
/* clear any previously acquired lookup data */
gdict_client_context_clear_hostinfo (context);
- _gdict_debug ("Looking up hostname '%s'\n", priv->hostname);
+ GDICT_NOTE (DICT, "Looking up hostname '%s'", priv->hostname);
#ifdef ENABLE_IPV6
if (_gdict_has_ipv6 ())
{
struct addrinfo hints, *res;
- _gdict_debug ("Hostname '%s' look-up (using IPv6)\n", priv->hostname);
+ GDICT_NOTE (DICT, "Hostname '%s' look-up (using IPv6)", priv->hostname);
memset (&hints, 0, sizeof (hints));
hints.ai_socktype = SOCK_STREAM;
@@ -1069,8 +1070,8 @@ gdict_client_context_lookup_server (GdictClientContext *context,
priv->sockaddr.ss_family = res->ai_family;
- _gdict_debug ("Hostname '%s' found (using IPv6)\n",
- priv->hostname);
+ GDICT_NOTE (DICT, "Hostname '%s' found (using IPv6)\n",
+ priv->hostname);
priv->last_lookup = time (NULL);
@@ -1093,8 +1094,7 @@ gdict_client_context_lookup_server (GdictClientContext *context,
#endif /* ENABLE_IPV6 */
/* if we don't support IPv6, fallback to usual IPv4 lookup */
- _gdict_debug ("Hostname '%s' look-up (using IPv4)\n",
- priv->hostname);
+ GDICT_NOTE ("Hostname '%s' look-up (using IPv4)", priv->hostname);
((struct sockaddr_in *) &priv->sockaddr)->sin_family = AF_INET;
@@ -1105,8 +1105,8 @@ gdict_client_context_lookup_server (GdictClientContext *context,
priv->hostinfo->h_addr,
priv->hostinfo->h_length);
- _gdict_debug ("Hostname '%s' found (using IPv4)\n",
- priv->hostname);
+ GDICT_NOTE (DICT, "Hostname '%s' found (using IPv4)\n",
+ priv->hostname);
priv->last_lookup = time (NULL);
@@ -1146,7 +1146,7 @@ gdict_client_context_parse_line (GdictClientContext *context,
priv = context->priv;
- _gdict_debug ("parse buffer: '%s'\n", buffer);
+ GDICT_NOTE (DICT, "parse buffer: '%s'", buffer);
/* connection is a special case: we don't have a command, so we just
* make sure that the server replied with the correct code. WARNING:
@@ -1219,7 +1219,7 @@ gdict_client_context_parse_line (GdictClientContext *context,
_("No definitions found for '%s'"),
priv->command->word);
- _gdict_debug ("error: %s\n", server_error->message);
+ GDICT_NOTE ("No match: %s", server_error->message);
g_signal_emit_by_name (context, "error", server_error);
@@ -1234,7 +1234,7 @@ gdict_client_context_parse_line (GdictClientContext *context,
_("Invalid database '%s'"),
priv->command->database);
- _gdict_debug ("error: %s\n", server_error->message);
+ GDICT_NOTE (DICT, "Bad DB: %s", server_error->message);
g_signal_emit_by_name (context, "error", server_error);
@@ -1249,7 +1249,7 @@ gdict_client_context_parse_line (GdictClientContext *context,
_("Invalid strategy '%s'"),
priv->command->strategy);
- _gdict_debug ("error: %s\n", server_error->message);
+ GDICT_NOTE (DICT, "Bad strategy: %s", server_error->message);
g_signal_emit_by_name (context, "error", server_error);
@@ -1264,7 +1264,7 @@ gdict_client_context_parse_line (GdictClientContext *context,
_("Bad command '%s'"),
dict_command_strings[priv->command->cmd_type]);
- _gdict_debug ("error: %s\n", server_error->message);
+ GDICT_NOTE (DICT, "Bad command: %s", server_error->message);
g_signal_emit_by_name (context, "error", server_error);
@@ -1279,7 +1279,7 @@ gdict_client_context_parse_line (GdictClientContext *context,
_("Bad parameters for command '%s'"),
dict_command_strings[priv->command->cmd_type]);
- _gdict_debug ("error: %s\n", server_error->message);
+ GDICT_NOTE (DICT, "Bad params: %s", server_error->message);
g_signal_emit_by_name (context, "error", server_error);
@@ -1294,7 +1294,7 @@ gdict_client_context_parse_line (GdictClientContext *context,
_("No databases found on dictionary server at '%s'"),
priv->hostname);
- _gdict_debug ("error: %s\n", server_error->message);
+ GDICT_NOTE (DICT, "No DB: %s", server_error->message);
g_signal_emit_by_name (context, "error", server_error);
@@ -1309,7 +1309,7 @@ gdict_client_context_parse_line (GdictClientContext *context,
_("No strategies found on dictionary server at '%s'"),
priv->hostname);
- _gdict_debug ("error: %s\n", server_error->message);
+ GDICT_NOTE (DICT, "No strategies: %s", server_error->message);
g_signal_emit_by_name (context, "error", server_error);
@@ -1319,7 +1319,7 @@ gdict_client_context_parse_line (GdictClientContext *context,
priv->command->state = S_FINISH;
break;
default:
- _gdict_debug ("non error code: %d\n", priv->status_code);
+ GDICT_NOTE (DICT, "non-error code: %d", priv->status_code);
break;
}
@@ -1366,10 +1366,10 @@ gdict_client_context_parse_line (GdictClientContext *context,
return TRUE;
}
- _gdict_debug ("check command %d ('%s')[state:%d]\n",
- priv->command->cmd_type,
- dict_command_strings[priv->command->cmd_type],
- priv->command->state);
+ GDICT_NOTE (DICT, "check command %d ('%s')[state:%d]",
+ priv->command->cmd_type,
+ dict_command_strings[priv->command->cmd_type],
+ priv->command->state);
/* check command type */
switch (priv->command->cmd_type)
@@ -1388,9 +1388,8 @@ gdict_client_context_parse_line (GdictClientContext *context,
if (p)
p = g_utf8_next_char (p);
- _gdict_debug ("server replied: %d databases found\n", atoi (p));
+ GDICT_NOTE (DICT, "server replied: %d databases found", atoi (p));
- _gdict_debug ("emitting lookup-start\n");
g_signal_emit_by_name (context, "lookup-start");
}
else if (0 == strcmp (buffer, "."))
@@ -1425,7 +1424,6 @@ gdict_client_context_parse_line (GdictClientContext *context,
db = _gdict_database_new (name);
db->full_name = g_strdup (full);
- _gdict_debug ("emitting database-found\n");
g_signal_emit_by_name (context, "database-found", db);
gdict_database_unref (db);
@@ -1442,9 +1440,8 @@ gdict_client_context_parse_line (GdictClientContext *context,
if (p)
p = g_utf8_next_char (p);
- _gdict_debug ("server replied: %d strategies found\n", atoi (p));
+ GDICT_NOTE (DICT, "server replied: %d strategies found", atoi (p));
- _gdict_debug ("emitting lookup-start\n");
g_signal_emit_by_name (context, "lookup-start");
}
else if (0 == strcmp (buffer, "."))
@@ -1476,7 +1473,6 @@ gdict_client_context_parse_line (GdictClientContext *context,
strat = _gdict_strategy_new (name);
strat->description = g_strdup (desc);
- _gdict_debug ("emitting strategy-found\n");
g_signal_emit_by_name (context, "strategy-found", strat);
gdict_strategy_unref (strat);
@@ -1494,14 +1490,13 @@ gdict_client_context_parse_line (GdictClientContext *context,
if (p)
p = g_utf8_next_char (p);
- _gdict_debug ("server replied: %d definitions found\n", atoi (p));
-
+ GDICT_NOTE (DICT, "server replied: %d definitions found", atoi (p));
+
def = _gdict_definition_new (atoi (p));
priv->command->data = def;
priv->command->data_destroy = (GDestroyNotify) gdict_definition_unref;
- _gdict_debug ("emitting lookup-start\n");
g_signal_emit_by_name (context, "lookup-start");
}
else if (priv->status_code == GDICT_STATUS_WORD_DB_NAME)
@@ -1548,11 +1543,11 @@ gdict_client_context_parse_line (GdictClientContext *context,
def = (GdictDefinition *) priv->command->data;
- _gdict_debug ("{ word .= '%s', db_name .= '%s', db_full .= '%s' }\n",
- word,
- db_name,
- db_full);
-
+ GDICT_NOTE (DICT, "{ word = '%s', db_name = '%s', db_full = '%s' }",
+ word,
+ db_name,
+ db_full);
+
def->word = g_strdup (word);
def->database_name = g_strdup (db_name);
def->database_full = g_strdup (db_full);
@@ -1575,8 +1570,7 @@ gdict_client_context_parse_line (GdictClientContext *context,
/* store the numer of definitions */
num = def->total;
-
- _gdict_debug ("emitting definition-found\n");
+
g_signal_emit_by_name (context, "definition-found", def);
gdict_definition_unref (def);
@@ -1593,7 +1587,7 @@ gdict_client_context_parse_line (GdictClientContext *context,
if (!priv->command->buffer)
priv->command->buffer = g_string_new (NULL);
- _gdict_debug ("appending line:\n %s\n", buffer);
+ GDICT_NOTE (DICT, "appending to buffer:\n %s\n", buffer);
/* TODO - collapse '..' to '.' */
g_string_append_printf (priv->command->buffer, "%s\n", buffer);
@@ -1610,9 +1604,8 @@ gdict_client_context_parse_line (GdictClientContext *context,
if (p)
p = g_utf8_next_char (p);
- _gdict_debug ("server replied: %d matches found\n", atoi (p));
+ GDICT_NOTE (DICT, "server replied: %d matches found", atoi (p));
- _gdict_debug ("emitting lookup-start\n");
g_signal_emit_by_name (context, "lookup-start");
}
else if (0 == strcmp (buffer, "."))
@@ -1644,7 +1637,6 @@ gdict_client_context_parse_line (GdictClientContext *context,
match = _gdict_match_new (word);
match->database = g_strdup (db_name);
- _gdict_debug ("emitting match-found\n");
g_signal_emit_by_name (context, "match-found", match);
gdict_match_unref (match);
@@ -1811,7 +1803,7 @@ gdict_client_context_io_watch_cb (GIOChannel *channel,
{
priv->status_code = status_code;
- _gdict_debug ("new status = '%d'\n", priv->status_code);
+ GDICT_NOTE (DICT, "new status = '%d'", priv->status_code);
}
else
priv->status_code = GDICT_STATUS_INVALID;
@@ -1825,15 +1817,13 @@ gdict_client_context_io_watch_cb (GIOChannel *channel,
{
g_free (line);
- _gdict_debug ("Parse failed\n");
+ g_warning ("Parsing failed");
gdict_client_context_force_disconnect (context);
return FALSE;
}
- _gdict_debug ("Line parsed\n");
-
g_free (line);
}
@@ -1854,7 +1844,7 @@ check_for_connection (gpointer data)
{
GError *err = NULL;
- _gdict_debug ("Forcing a disconnection due to timeout");
+ GDICT_NOTE (DICT, "Forcing a disconnection due to timeout");
g_set_error (&err, GDICT_CLIENT_CONTEXT_ERROR,
GDICT_CLIENT_CONTEXT_ERROR_SOCKET,
diff --git a/libgdict/gdict-database-chooser.c b/libgdict/gdict-database-chooser.c
index 2c50b3e..a8cd959 100644
--- a/libgdict/gdict-database-chooser.c
+++ b/libgdict/gdict-database-chooser.c
@@ -44,6 +44,7 @@
#include "gdict-database-chooser.h"
#include "gdict-utils.h"
+#include "gdict-debug.h"
#include "gdict-private.h"
#include "gdict-enum-types.h"
#include "gdict-marshal.h"
@@ -126,7 +127,7 @@ set_gdict_context (GdictDatabaseChooser *chooser,
{
if (priv->start_id)
{
- _gdict_debug ("Removing old context handlers\n");
+ GDICT_NOTE (CHOOSER, "Removing old context handlers");
g_signal_handler_disconnect (priv->context, priv->start_id);
g_signal_handler_disconnect (priv->context, priv->match_id);
@@ -144,7 +145,7 @@ set_gdict_context (GdictDatabaseChooser *chooser,
priv->error_id = 0;
}
- _gdict_debug ("Removing old context\n");
+ GDICT_NOTE (CHOOSER, "Removing old context");
g_object_unref (G_OBJECT (priv->context));
@@ -162,7 +163,7 @@ set_gdict_context (GdictDatabaseChooser *chooser,
return;
}
- _gdict_debug ("Setting new context\n");
+ GDICT_NOTE (CHOOSER, "Setting new context");
priv->context = g_object_ref (context);
priv->results = 0;
@@ -679,9 +680,9 @@ database_found_cb (GdictContext *context,
GdictDatabaseChooserPrivate *priv = chooser->priv;
GtkTreeIter iter;
- _gdict_debug ("DATABASE: `%s' (`%s')\n",
- gdict_database_get_name (database),
- gdict_database_get_full_name (database));
+ GDICT_NOTE (CHOOSER, "DATABASE: `%s' (`%s')\n",
+ gdict_database_get_name (database),
+ gdict_database_get_full_name (database));
gtk_list_store_append (priv->store, &iter);
gtk_list_store_set (priv->store, &iter,
@@ -774,7 +775,9 @@ gdict_database_chooser_refresh (GdictDatabaseChooser *chooser)
DB_COLUMN_DESCRIPTION, NULL,
-1);
- _gdict_debug ("Error while searching: %s", db_error->message);
+ g_warning ("Error while looking for databases: %s",
+ db_error->message);
+
g_error_free (db_error);
}
}
diff --git a/libgdict/gdict-debug.c b/libgdict/gdict-debug.c
deleted file mode 100644
index d6c12c4..0000000
--- a/libgdict/gdict-debug.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/* gdict-debug.h - Debug facilities for Gdict
- *
- * Copyright (C) 2006 Emmanuele Bassi <ebassi@gmail.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <sys/types.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include <glib.h>
-#include <glib/gi18n-lib.h>
-
-#ifdef GDICT_ENABLE_DEBUG
-void
-_gdict_debug (const gchar *fmt,
- ...)
-{
- va_list args;
-
- fprintf (stderr, "GDICT_DEBUG: ");
-
- va_start (args, fmt);
- vfprintf (stderr, fmt, args);
- va_end (args);
-}
-#endif
diff --git a/libgdict/gdict-debug.h b/libgdict/gdict-debug.h
index b9cfb78..03c6d70 100644
--- a/libgdict/gdict-debug.h
+++ b/libgdict/gdict-debug.h
@@ -17,8 +17,39 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
*/
-#ifdef GDICT_ENABLE_DEBUG
-void _gdict_debug (const gchar *fmt, ...);
+#ifndef __GDICT_DEBUG_H__
+#define __GDICT_DEBUG_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef enum {
+ GDICT_DEBUG_MISC = 1 << 0,
+ GDICT_DEBUG_CONTEXT = 1 << 1,
+ GDICT_DEBUG_DICT = 1 << 2,
+ GDICT_DEBUG_SOURCE = 1 << 3,
+ GDICT_DEBUG_LOADER = 1 << 4,
+ GDICT_DEBUG_CHOOSER = 1 << 5,
+ GDICT_DEBUG_DEFBOX = 1 << 6,
+ GDICT_DEBUG_SPELLER = 1 << 7
+} GdictDebugFlags;
+
+#ifndef GDICT_ENABLE_DEBUG
+
+#define GDICT_NOTE(type,x,a...) G_STMT_START { \
+ if (gdict_debug_flags & GDICT_DEBUG_##type) { \
+ g_message ("[" #type "]: " x, ##a); \
+ } } G_STMT_END
+
#else
-#define _gdict_debug(...)
-#endif
+
+#define GDICT_NOTE(type,x,a...)
+
+#endif /* !GDICT_ENABLE_DEBUG */
+
+extern guint gdict_debug_flags;
+
+G_END_DECLS
+
+#endif /* __GDICT_DEBUG_H__ */
diff --git a/libgdict/gdict-defbox.c b/libgdict/gdict-defbox.c
index 4217c50..30ff90a 100644
--- a/libgdict/gdict-defbox.c
+++ b/libgdict/gdict-defbox.c
@@ -45,6 +45,7 @@
#include "gdict-defbox.h"
#include "gdict-utils.h"
+#include "gdict-debug.h"
#include "gdict-private.h"
#include "gdict-enum-types.h"
#include "gdict-marshal.h"
@@ -241,7 +242,7 @@ set_gdict_context (GdictDefbox *defbox,
{
if (priv->start_id)
{
- _gdict_debug ("Removing old context handlers\n");
+ GDICT_NOTE (DEFBOX, "Removing old context handlers");
g_signal_handler_disconnect (priv->context, priv->start_id);
g_signal_handler_disconnect (priv->context, priv->define_id);
@@ -259,7 +260,7 @@ set_gdict_context (GdictDefbox *defbox,
priv->error_id = 0;
}
- _gdict_debug ("Removing old context\n");
+ GDICT_NOTE (DEFBOX, "Removing old context");
g_object_unref (G_OBJECT (priv->context));
}
@@ -274,7 +275,7 @@ set_gdict_context (GdictDefbox *defbox,
return;
}
- _gdict_debug ("Setting new context\n");
+ GDICT_NOTE (DEFBOX, "Setting new context");
priv->context = context;
g_object_ref (G_OBJECT (priv->context));
diff --git a/libgdict/gdict-speller.c b/libgdict/gdict-speller.c
index e45230a..fe87745 100644
--- a/libgdict/gdict-speller.c
+++ b/libgdict/gdict-speller.c
@@ -43,6 +43,7 @@
#include "gdict-utils.h"
#include "gdict-enum-types.h"
#include "gdict-marshal.h"
+#include "gdict-debug.h"
#include "gdict-private.h"
#define GDICT_SPELLER_GET_PRIVATE(obj) \
@@ -124,7 +125,7 @@ set_gdict_context (GdictSpeller *speller,
{
if (priv->start_id)
{
- _gdict_debug ("Removing old context handlers\n");
+ GDICT_NOTE (SPELLER, "Removing old context handlers");
g_signal_handler_disconnect (priv->context, priv->start_id);
g_signal_handler_disconnect (priv->context, priv->match_id);
@@ -142,7 +143,7 @@ set_gdict_context (GdictSpeller *speller,
priv->error_id = 0;
}
- _gdict_debug ("Removing old context\n");
+ GDICT_NOTE (SPELLER, "Removing old context");
g_object_unref (G_OBJECT (priv->context));
}
@@ -157,7 +158,7 @@ set_gdict_context (GdictSpeller *speller,
return;
}
- _gdict_debug ("Setting new context\n");
+ GDICT_NOTE (SPELLER, "Setting new context\n");
priv->context = context;
g_object_ref (G_OBJECT (priv->context));
@@ -664,9 +665,9 @@ match_found_cb (GdictContext *context,
GdictSpellerPrivate *priv = speller->priv;
GtkTreeIter iter;
- _gdict_debug ("MATCH: `%s' (from `%s')\n",
- gdict_match_get_word (match),
- gdict_match_get_database (match));
+ GDICT_NOTE (SPELLER, "MATCH: `%s' (from `%s')",
+ gdict_match_get_word (match),
+ gdict_match_get_database (match));
gtk_list_store_append (priv->store, &iter);
gtk_list_store_set (priv->store, &iter,
@@ -780,7 +781,10 @@ gdict_speller_match (GdictSpeller *speller,
MATCH_COLUMN_WORD, NULL,
-1);
- _gdict_debug ("Error while matching: %s", match_error->message);
+ g_warning ("Error while matching `%s': %s",
+ priv->word,
+ match_error->message);
+
g_error_free (match_error);
}
}
diff --git a/libgdict/gdict-strategy-chooser.c b/libgdict/gdict-strategy-chooser.c
index 49529f5..db24393 100644
--- a/libgdict/gdict-strategy-chooser.c
+++ b/libgdict/gdict-strategy-chooser.c
@@ -42,6 +42,7 @@
#include "gdict-strategy-chooser.h"
#include "gdict-utils.h"
+#include "gdict-debug.h"
#include "gdict-private.h"
#include "gdict-enum-types.h"
#include "gdict-marshal.h"
@@ -124,7 +125,7 @@ set_gdict_context (GdictStrategyChooser *chooser,
{
if (priv->start_id)
{
- _gdict_debug ("Removing old context handlers\n");
+ GDICT_NOTE (CHOOSER, "Removing old context handlers");
g_signal_handler_disconnect (priv->context, priv->start_id);
g_signal_handler_disconnect (priv->context, priv->match_id);
@@ -142,7 +143,7 @@ set_gdict_context (GdictStrategyChooser *chooser,
priv->error_id = 0;
}
- _gdict_debug ("Removing old context\n");
+ GDICT_NOTE (CHOOSER, "Removing old context");
g_object_unref (G_OBJECT (priv->context));
}
@@ -157,7 +158,7 @@ set_gdict_context (GdictStrategyChooser *chooser,
return;
}
- _gdict_debug ("Setting new context\n");
+ GDICT_NOTE (CHOOSER, "Setting new context");
priv->context = context;
g_object_ref (G_OBJECT (priv->context));
@@ -608,9 +609,9 @@ strategy_found_cb (GdictContext *context,
GdictStrategyChooserPrivate *priv = chooser->priv;
GtkTreeIter iter;
- _gdict_debug ("STRATEGY: `%s' (`%s')\n",
- gdict_strategy_get_name (strategy),
- gdict_strategy_get_description (strategy));
+ GDICT_NOTE (CHOOSER, "STRATEGY: `%s' (`%s')",
+ gdict_strategy_get_name (strategy),
+ gdict_strategy_get_description (strategy));
gtk_list_store_append (priv->store, &iter);
gtk_list_store_set (priv->store, &iter,
@@ -705,7 +706,9 @@ gdict_strategy_chooser_refresh (GdictStrategyChooser *chooser)
STRAT_COLUMN_DESCRIPTION, NULL,
-1);
- _gdict_debug ("Error while searching: %s", db_error->message);
+ g_warning ("Error while retrieving strategies: %s",
+ db_error->message);
+
g_error_free (db_error);
}
}
diff --git a/libgdict/gdict-utils.c b/libgdict/gdict-utils.c
index 44e560b..df885fb 100644
--- a/libgdict/gdict-utils.c
+++ b/libgdict/gdict-utils.c
@@ -41,8 +41,189 @@
#include "gdict-context-private.h"
#include "gdict-debug.h"
#include "gdict-utils.h"
+#include "gdict-version.h"
#include "gdict-private.h"
+guint gdict_major_version = GDICT_MAJOR_VERSION;
+guint gdict_minor_version = GDICT_MINOR_VERSION;
+guint gdict_micro_version = GDICT_MICRO_VERSION;
+
+guint gdict_debug_flags = 0; /* global gdict debug flag */
+
+#ifdef GDICT_ENABLE_DEBUG
+static const GDebugKey gdict_debug_keys[] = {
+ { "misc", GDICT_DEBUG_MISC },
+ { "context", GDICT_DEBUG_CONTEXT },
+ { "dict", GDICT_DEBUG_DICT },
+ { "source", GDICT_DEBUG_SOURCE },
+ { "loader", GDICT_DEBUG_LOADER },
+ { "chooser", GDICT_DEBUG_CHOOSER },
+ { "defbux", GDICT_DEBUG_DEFBOX },
+ { "speller", GDICT_DEBUG_SPELLER },
+};
+#endif /* GDICT_ENABLE_DEBUG */
+
+static gboolean gdict_is_initialized = FALSE;
+
+#ifdef GDICT_ENABLE_DEBUG
+static gboolean
+gdict_arg_debug_cb (const char *key,
+ const char *value,
+ gpointer user_data)
+{
+ gdict_debug_flags |=
+ g_parse_debug_string (value,
+ gdict_debug_keys,
+ G_N_ELEMENTS (gdict_debug_keys));
+ return TRUE;
+}
+
+static gboolean
+gdict_arg_no_debug_cb (const char *key,
+ const char *value,
+ gpointer user_data)
+{
+ gdict_debug_flags &=
+ ~g_parse_debug_string (value,
+ gdict_debug_keys,
+ G_N_ELEMENTS (gdict_debug_keys));
+ return TRUE;
+}
+#endif /* CLUTTER_ENABLE_DEBUG */
+
+static GOptionEntry gdict_args[] = {
+#ifdef GDICT_ENABLE_DEBUG
+ { "gdict-debug", 0, 0, G_OPTION_ARG_CALLBACK, gdict_arg_debug_cb,
+ "GDict debugging flags to set", "FLAGS" },
+ { "gdict-no-debug", 0, 0, G_OPTION_ARG_CALLBACK, gdict_arg_no_debug_cb,
+ "GDict debugging flags to unset", "FLAGS" },
+#endif /* GDICT_ENABLE_DEBUG */
+ { NULL, },
+};
+
+static gboolean
+pre_parse_hook (GOptionContext *context,
+ GOptionGroup *group,
+ gpointer data,
+ GError **error)
+{
+ const char *env_string;
+
+ if (gdict_is_initialized)
+ return TRUE;
+
+#ifdef GDICT_ENABLE_DEBUG
+ env_string = g_getenv ("GDICT_DEBUG");
+ if (env_string != NULL)
+ {
+ gdict_debug_flags =
+ g_parse_debug_string (env_string,
+ gdict_debug_keys,
+ G_N_ELEMENTS (gdict_debug_keys));
+ }
+#else
+ env_string = NULL;
+#endif /* GDICT_ENABLE_DEBUG */
+
+ return TRUE;
+}
+
+static gboolean
+post_parse_hook (GOptionContext *context,
+ GOptionGroup *group,
+ gpointer data,
+ GError **error)
+{
+ gdict_is_initialized = TRUE;
+
+ return TRUE;
+}
+
+/**
+ * gdict_get_option_group:
+ *
+ * FIXME
+ *
+ * Return value: FIXME
+ *
+ * Since: 0.11
+ */
+GOptionGroup *
+gdict_get_option_group (void)
+{
+ GOptionGroup *group;
+
+ group = g_option_group_new ("gdict",
+ _("GDict Options"),
+ _("Show GDict Options"),
+ NULL,
+ NULL);
+
+ g_option_group_set_parse_hooks (group, pre_parse_hook, post_parse_hook);
+ g_option_group_add_entries (group, gdict_args);
+ g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
+
+ return group;
+}
+
+/**
+ * gdict_debug_init:
+ * @argc: FIXME
+ * @argv: FIXME
+ *
+ * FIXME
+ *
+ * Since: 0.11
+ */
+void
+gdict_debug_init (gint *argc,
+ gchar ***argv)
+{
+ GOptionContext *option_context;
+ GOptionGroup *gdict_group;
+ GError *error = NULL;
+
+ if (gdict_is_initialized)
+ return;
+
+ option_context = g_option_context_new (NULL);
+ g_option_context_set_ignore_unknown_options (option_context, TRUE);
+ g_option_context_set_help_enabled (option_context, FALSE);
+
+ gdict_group = gdict_get_option_group ();
+ g_option_context_set_main_group (option_context, gdict_group);
+
+ if (!g_option_context_parse (option_context, argc, argv, &error))
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
+
+ g_option_context_free (option_context);
+}
+
+gboolean
+gdict_check_version (guint required_major,
+ guint required_minor,
+ guint required_micro)
+{
+ gint gdict_effective_micro = 100 * GDICT_MINOR_VERSION + GDICT_MICRO_VERSION;
+ gint required_effective_micro = 100 * required_minor + required_micro;
+
+ if (required_major > GDICT_MAJOR_VERSION)
+ return FALSE;
+
+ if (required_major < GDICT_MAJOR_VERSION)
+ return FALSE;
+
+ if (required_effective_micro < gdict_effective_micro)
+ return FALSE;
+
+ if (required_effective_micro > gdict_effective_micro)
+ return FALSE;
+
+ return TRUE;
+}
/* gdict_has_ipv6: checks for the existence of the IPv6 extensions; if
* IPv6 support was not enabled, this function always return false
*/
diff --git a/libgdict/gdict-utils.h b/libgdict/gdict-utils.h
index 90a5047..02bd996 100644
--- a/libgdict/gdict-utils.h
+++ b/libgdict/gdict-utils.h
@@ -76,6 +76,10 @@ typedef enum {
#define GDICT_IS_VALID_STATUS_CODE(x) (((x) > GDICT_STATUS_INVALID) && \
((x) <= GDICT_STATUS_NO_STRATEGIES_PRESENT))
+GOptionGroup *gdict_get_option_group (void);
+void gdict_debug_init (gint *argc,
+ gchar ***argv);
+
G_END_DECLS
#endif /* __GDICT_UTILS_H__ */