[gnumeric] stf: debug improvements.



commit 26adfbca22b80349322258f3c6895352d1aeec59
Author: Morten Welinder <terra gnome org>
Date:   Mon Mar 28 13:57:01 2011 -0400

    stf: debug improvements.

 ChangeLog                         |    8 +++++
 src/dialogs/dialog-stf-csv-page.c |    2 +-
 src/stf-parse.c                   |   52 ++++++++++++++++++++++++++++++++++--
 src/stf-parse.h                   |    4 +-
 src/stf.c                         |    4 +++
 5 files changed, 64 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e7a0200..dd3e708 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-03-28  Morten Welinder  <terra gnome org>
+
+	* src/stf-parse.c (dump_guessed_options): New function.
+	(stf_parse_options_guess,stf_parse_options_guess_csv): Optionally
+	call dump_guessed_options.
+
+	* src/stf-parse.h (enum StfTrimType_t): Use the values intended.
+
 2011-03-27  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* src/sheet-control-gui.c (snap_pos_to_grid): don't move an aligned
diff --git a/src/dialogs/dialog-stf-csv-page.c b/src/dialogs/dialog-stf-csv-page.c
index 13c1904..8830214 100644
--- a/src/dialogs/dialog-stf-csv-page.c
+++ b/src/dialogs/dialog-stf-csv-page.c
@@ -176,7 +176,7 @@ csv_page_parseoptions_to_gui (StfDialogData *pagedata)
 	}
 
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_duplicates),
-				      po->duplicates);
+				      po->sep.duplicates);
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_trim_seps),
 				      po->trim_seps);
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_2x_indicator),
diff --git a/src/stf-parse.c b/src/stf-parse.c
index 4db0391..d0c2b0f 100644
--- a/src/stf-parse.c
+++ b/src/stf-parse.c
@@ -145,7 +145,7 @@ stf_parse_options_new (void)
 
 	parseoptions->stringindicator = '"';
 	parseoptions->indicator_2x_is_single = TRUE;
-	parseoptions->duplicates = FALSE;
+	parseoptions->sep.duplicates = FALSE;
 	parseoptions->trim_seps = FALSE;
 
 	parseoptions->sep.str = NULL;
@@ -336,7 +336,7 @@ stf_parse_options_csv_set_duplicates (StfParseOptions_t *parseoptions, gboolean
 {
 	g_return_if_fail (parseoptions != NULL);
 
-	parseoptions->duplicates = duplicates;
+	parseoptions->sep.duplicates = duplicates;
 }
 
 /**
@@ -656,7 +656,7 @@ stf_parse_csv_cell (GString *text, Source_t *src, StfParseOptions_t *parseoption
 
 	src->position = cur;
 
-	if (saw_sep && parseoptions->duplicates)
+	if (saw_sep && parseoptions->sep.duplicates)
 		stf_parse_eat_separators (src, parseoptions);
 
 	return saw_sep ? STF_CELL_FIELD_SEP : STF_CELL_FIELD_NO_SEP;
@@ -1457,6 +1457,46 @@ count_character (GPtrArray *lines, gunichar c, double quantile)
 	return res;
 }
 
+static void
+dump_guessed_options (const StfParseOptions_t *res)
+{
+	GSList *l;
+	char ubuffer[6 + 1];
+
+	g_printerr ("Guessed format:\n");
+	switch (res->parsetype) {
+	case PARSE_TYPE_CSV:
+		g_printerr ("  type = sep\n");
+		g_printerr ("  separator = %s\n", res->sep.chr);
+		g_printerr ("    see two as one = %s\n",
+			    res->sep.duplicates ? "yes" : "no");
+		break;
+	case PARSE_TYPE_FIXED:
+		g_printerr ("  type = sep\n");
+		break;
+	default:
+		;
+	}
+	g_printerr ("  trim space = %d\n", res->trim_spaces);
+
+	ubuffer[g_unichar_to_utf8 (res->stringindicator, ubuffer)] = 0;
+	g_printerr ("  string indicator = %s\n", ubuffer);
+	g_printerr ("    see two as one = %s\n",
+		    res->indicator_2x_is_single ? "yes" : "no");
+
+	g_printerr ("  line terminators =");
+	for (l = res->terminator; l; l = l->next) {
+		const char *t = l->data;
+		if (strcmp (t, "\n"))
+			g_printerr (" unix");
+		else if (strcmp (t, "\r"))
+			g_printerr (" mac");
+		else if (strcmp (t, "\r\n"))
+			g_printerr (" dos");
+	}
+	g_printerr ("\n");
+}
+
 
 StfParseOptions_t *
 stf_parse_options_guess (char const *data)
@@ -1530,6 +1570,9 @@ stf_parse_options_guess (char const *data)
 	stf_parse_general_free (lines);
 	g_string_chunk_free (lines_chunk);
 
+	if (gnm_debug_flag ("stf"))
+		dump_guessed_options (res);
+
 	return res;
 }
 
@@ -1614,5 +1657,8 @@ stf_parse_options_guess_csv (char const *data)
 	stf_parse_general_free (lines);
 	g_string_chunk_free (lines_chunk);
 
+	if (gnm_debug_flag ("stf"))
+		dump_guessed_options (res);
+
 	return res;
 }
diff --git a/src/stf-parse.h b/src/stf-parse.h
index d093a77..57e800b 100644
--- a/src/stf-parse.h
+++ b/src/stf-parse.h
@@ -17,7 +17,7 @@ typedef enum {
 typedef enum {
 	TRIM_TYPE_NEVER      = 0,
 	TRIM_TYPE_LEFT       = 1 << 0,
-	TRIM_TYPE_RIGHT      = 2 << 1
+	TRIM_TYPE_RIGHT      = 1 << 1
 } StfTrimType_t;
 
 typedef struct {
@@ -35,10 +35,10 @@ typedef struct {
 	struct {
 		GSList *str;
 		char   *chr;
+		gboolean duplicates;         /* See two text separators as one? */
 	} sep;
 	gunichar             stringindicator;       /* String indicator */
 	gboolean             indicator_2x_is_single;/* 2 quote chars form a single non-terminating quote */
-	gboolean             duplicates;            /* See two text separators as one? */
 	gboolean             trim_seps;             /* Ignore initial seps.  */
 
 	/* Fixed width related */
diff --git a/src/stf.c b/src/stf.c
index 1675cdf..bb271d2 100644
--- a/src/stf.c
+++ b/src/stf.c
@@ -165,12 +165,16 @@ resize_columns (Sheet *sheet)
 {
 	GnmRange r;
 
+	if (gnm_debug_flag ("stf"))
+		g_printerr ("Auto-fitting columns...\n");
 	range_init_full_sheet (&r, sheet);
 	colrow_autofit (sheet, &r, TRUE,
 			TRUE, /* Ignore strings */
 			TRUE, /* Don't shrink */
 			TRUE, /* Don't shrink */
 			NULL, NULL);
+	if (gnm_debug_flag ("stf"))
+		g_printerr ("Auto-fitting columns...  done\n");
 
 	sheet_queue_respan (sheet, 0, gnm_sheet_get_last_row (sheet));
 }



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