Commit 99945290 authored by Morten Welinder's avatar Morten Welinder

GNM_DEBUG: factor out common code.

parent 3fd0b9fe
2009-05-12 Morten Welinder <terra@gnome.org>
* src/gutils.c (gnm_debug_flag): New function.
* src/sheet-style.c (sheet_style_optimize): Use gnm_debug_flag.
* src/gui-clipboard.c (debug_clipboard): Ditto.
* src/main-application.c (main): Ditto.
* src/wbc-gtk.c (cb_workbook_debug_info,
wbc_gtk_create_edit_area): Ditto.
2009-05-11 Morten Welinder <terra@gnome.org>
* src/ssconvert.c (merge): Rearrange to read files only once.
......
......@@ -48,24 +48,15 @@
static gboolean
debug_clipboard (void)
{
static guint flags;
static gboolean d_clipboard;
static gboolean inited = FALSE;
if (!inited) {
/* not static */
const GDebugKey keys[] = {
{ (char*)"clipboard", 1 },
};
const char *val = g_getenv ("GNM_DEBUG");
flags = val
? g_parse_debug_string (val, keys, G_N_ELEMENTS (keys))
: 0;
inited = TRUE;
d_clipboard = gnm_debug_flag ("clipboard");
}
return (flags & 1) != 0;
return d_clipboard;
}
typedef struct {
......
......@@ -349,3 +349,14 @@ gnm_pop_C_locale (GnmLocale *locale)
g_free (locale->num_locale);
g_free (locale);
}
gboolean
gnm_debug_flag (const char *flag)
{
GDebugKey key;
key.key = (char *)flag;
key.value = 1;
return g_parse_debug_string (g_getenv ("GNM_DEBUG"), &key, 1) != 0;
}
......@@ -27,6 +27,8 @@ typedef struct _GnmLocale GnmLocale;
GnmLocale *gnm_push_C_locale (void);
void gnm_pop_C_locale (GnmLocale *locale);
gboolean gnm_debug_flag (const char *flag);
G_END_DECLS
#endif /* _GNM_GUTILS_H_ */
......@@ -103,18 +103,6 @@ static GOptionEntry const libspreadsheet_options [] = {
/**************************************
* Hidden debugging flags */
{
"debug-deps", 0,
G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_INT, &wbc_gtk_debug_deps,
N_("Enables some dependency related debugging functions"),
N_("LEVEL")
},
{
"debug-share", 0,
G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_INT, &wbc_gtk_debug_expr_share,
N_("Enables some debugging functions for expression sharing"),
N_("LEVEL")
},
{
"debug-print", 0,
G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_INT, &gnm_print_debug,
......
......@@ -285,34 +285,6 @@ cb_workbook_removed (void)
}
}
enum {
GNM_DEBUG_CLOSE_DISPLAY = 1
};
static gboolean
debug_flags (guint test)
{
static guint flags;
static gboolean inited = FALSE;
if (!inited) {
/* not static */
const GDebugKey keys[] = {
{ (char*)"close-displays", GNM_DEBUG_CLOSE_DISPLAY },
};
const char *val = g_getenv ("GNM_DEBUG");
flags = val
? g_parse_debug_string (val, keys, G_N_ELEMENTS (keys))
: 0;
inited = TRUE;
}
return (flags & test) != 0;
}
int
main (int argc, char const **argv)
{
......@@ -507,7 +479,7 @@ main (int argc, char const **argv)
* This helps finding leaks. We might want it in developent
* only.
*/
if (with_gui && debug_flags (GNM_DEBUG_CLOSE_DISPLAY)) {
if (with_gui && gnm_debug_flag ("close-displays")) {
GSList *displays;
gdk_flush();
......
......@@ -2838,37 +2838,17 @@ sheet_style_optimize (Sheet *sheet)
{
CellTileOptimize data;
GSList *pre;
static guint debug_flags;
static gboolean debug_inited = FALSE;
gboolean verify;
enum { GNM_DEBUG_STYLE_OPTIMIZE = 1,
GNM_DEBUG_STYLE_OPTIMIZE_VERIFY = 2
};
g_return_if_fail (IS_SHEET (sheet));
if (!debug_inited) {
/* not static */
const GDebugKey keys[] = {
{ (char*)"style-optimize", GNM_DEBUG_STYLE_OPTIMIZE },
{ (char*)"style-optimize-verify", GNM_DEBUG_STYLE_OPTIMIZE_VERIFY },
};
const char *val = g_getenv ("GNM_DEBUG");
debug_flags = val
? g_parse_debug_string (val, keys, G_N_ELEMENTS (keys))
: 0;
debug_inited = TRUE;
}
verify = (debug_flags & GNM_DEBUG_STYLE_OPTIMIZE_VERIFY) != 0;
data.ss = gnm_sheet_get_size (sheet);
data.debug = (debug_flags & GNM_DEBUG_STYLE_OPTIMIZE) != 0;
data.debug = gnm_debug_flag ("style-optimize");
if (data.debug)
g_printerr ("Optimizing %s\n", sheet->name_unquoted);
verify = gnm_debug_flag ("style-optimize-verify");
pre = verify ? sample_styles (sheet) : NULL;
cell_tile_optimize (&sheet->style_data->styles,
......
......@@ -168,9 +168,6 @@ void wbc_gtk_init_editline (WBCGtk *wbcg);
void wbc_gtk_init_actions (WBCGtk *wbcg);
void wbc_gtk_markup_changer (WBCGtk *wbcg);
extern gint wbc_gtk_debug_deps;
extern gint wbc_gtk_debug_expr_share;
G_END_DECLS
#endif /* _GNM_WBC_GTK_IMPL_H_ */
......@@ -103,9 +103,6 @@ char const *uifilename = NULL;
static guint wbc_gtk_signals[WBC_GTK_LAST_SIGNAL];
static GObjectClass *parent_class = NULL;
gint wbc_gtk_debug_deps = 0;
gint wbc_gtk_debug_expr_share = 0;
/****************************************************************************/
static void
......@@ -1758,13 +1755,13 @@ cb_workbook_debug_info (WBCGtk *wbcg)
{
Workbook *wb = wb_control_get_workbook (WORKBOOK_CONTROL (wbcg));
if (wbc_gtk_debug_deps > 0) {
if (gnm_debug_flag ("deps")) {
WORKBOOK_FOREACH_SHEET (wb, sheet,
g_printerr ("Dependencies for %s:\n", sheet->name_unquoted);
gnm_dep_container_dump (sheet->deps, sheet););
}
if (wbc_gtk_debug_expr_share > 0) {
if (gnm_debug_flag ("expr-sharer")) {
GnmExprSharer *es = workbook_share_expressions (wb, FALSE);
g_printerr ("Expression sharer results:\n"
......@@ -2250,8 +2247,7 @@ wbc_gtk_create_edit_area (WBCGtk *wbcg)
_("Enter formula..."));
/* Dependency debugger */
if (wbc_gtk_debug_deps > 0 ||
wbc_gtk_debug_expr_share > 0) {
if (gnm_debug_flag ("deps") || gnm_debug_flag ("expr-sharer")) {
(void)edit_area_button (wbcg, tb, TRUE,
G_CALLBACK (cb_workbook_debug_info),
GTK_STOCK_DIALOG_INFO,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment