[gnumeric] GNM_DEBUG: factor out common code.



commit 99945290c19822dc7b7e6eaff0434b0842847122
Author: Morten Welinder <terra gnome org>
Date:   Tue May 12 09:44:26 2009 -0400

    GNM_DEBUG: factor out common code.
---
 ChangeLog              |    9 +++++++++
 src/gui-clipboard.c    |   15 +++------------
 src/gutils.c           |   11 +++++++++++
 src/gutils.h           |    2 ++
 src/libgnumeric.c      |   12 ------------
 src/main-application.c |   30 +-----------------------------
 src/sheet-style.c      |   24 ++----------------------
 src/wbc-gtk-impl.h     |    3 ---
 src/wbc-gtk.c          |   10 +++-------
 9 files changed, 31 insertions(+), 85 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 85cf0ab..e4e8cf2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+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.
diff --git a/src/gui-clipboard.c b/src/gui-clipboard.c
index 15c16bd..7bb2526 100644
--- a/src/gui-clipboard.c
+++ b/src/gui-clipboard.c
@@ -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 {
diff --git a/src/gutils.c b/src/gutils.c
index efbf7f7..f3c7fc6 100644
--- a/src/gutils.c
+++ b/src/gutils.c
@@ -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;
+}
diff --git a/src/gutils.h b/src/gutils.h
index bdafd57..3c02ba2 100644
--- a/src/gutils.h
+++ b/src/gutils.h
@@ -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_ */
diff --git a/src/libgnumeric.c b/src/libgnumeric.c
index 854acfb..6a37d18 100644
--- a/src/libgnumeric.c
+++ b/src/libgnumeric.c
@@ -104,18 +104,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,
 		N_("Enables some print debugging behavior"),
diff --git a/src/main-application.c b/src/main-application.c
index 434d9cd..bbf0f46 100644
--- a/src/main-application.c
+++ b/src/main-application.c
@@ -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();
diff --git a/src/sheet-style.c b/src/sheet-style.c
index afa912d..12b0cf1 100644
--- a/src/sheet-style.c
+++ b/src/sheet-style.c
@@ -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,
diff --git a/src/wbc-gtk-impl.h b/src/wbc-gtk-impl.h
index 50bc063..93d1d3e 100644
--- a/src/wbc-gtk-impl.h
+++ b/src/wbc-gtk-impl.h
@@ -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_ */
diff --git a/src/wbc-gtk.c b/src/wbc-gtk.c
index 2a6c285..20bc048 100644
--- a/src/wbc-gtk.c
+++ b/src/wbc-gtk.c
@@ -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,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]