gnumeric r16709 - in trunk: . src



Author: mortenw
Date: Thu Jul 10 03:01:34 2008
New Revision: 16709
URL: http://svn.gnome.org/viewvc/gnumeric?rev=16709&view=rev

Log:
Support -F -l -L and --results too.



Modified:
   trunk/ChangeLog
   trunk/src/ssconvert.c
   trunk/src/ssgrep.c

Modified: trunk/src/ssconvert.c
==============================================================================
--- trunk/src/ssconvert.c	(original)
+++ trunk/src/ssconvert.c	Thu Jul 10 03:01:34 2008
@@ -316,6 +316,8 @@
 
 			if (ssconvert_recalc)
 				workbook_recalc_all (wb);
+			else
+				workbook_recalc (wb);
 
 			if (ssconvert_range)
 				setup_range (G_OBJECT (wb),

Modified: trunk/src/ssgrep.c
==============================================================================
--- trunk/src/ssgrep.c	(original)
+++ trunk/src/ssgrep.c	Thu Jul 10 03:01:34 2008
@@ -40,12 +40,16 @@
 static gboolean ssgrep_quiet = FALSE;
 static gboolean ssgrep_count = FALSE;
 static gboolean ssgrep_print_filenames = (gboolean)2;
+static gboolean ssgrep_print_matching_filenames = FALSE;
+static gboolean ssgrep_print_nonmatching_filenames = FALSE;
 static gboolean ssgrep_print_locus = FALSE;
 static char *ssgrep_pattern = NULL;
+static gboolean ssgrep_fixed_strings = FALSE;
 static gboolean ssgrep_recalc = FALSE;
+static gboolean ssgrep_invert_match = FALSE;  /* Unimplemented */
 
 static gboolean ssgrep_show_version = FALSE;
-static char *ssgrep_keyword_file = NULL;
+static char *ssgrep_pattern_file = NULL;
 
 static gboolean ssgrep_error = FALSE;
 static gboolean ssgrep_any_matches = FALSE;
@@ -59,6 +63,20 @@
 	},
 
 	{
+		"pattern-file", 'f',
+		0, G_OPTION_ARG_STRING, &ssgrep_pattern_file,
+		N_("Get patterns from a file, one per line"),
+		N_("FILE")
+	},
+
+	{
+		"fixed-strings", 'F',
+		0, G_OPTION_ARG_NONE, &ssgrep_fixed_strings,
+		N_("Pattern is a set of fixed strings"),
+		NULL
+	},
+
+	{
 		"with-filename", 'H',
 		0, G_OPTION_ARG_NONE, &ssgrep_print_filenames,
 		N_("Print the filename for each match"),
@@ -80,6 +98,20 @@
 	},
 
 	{
+		"files-with-matches", 'l',
+		0, G_OPTION_ARG_NONE, &ssgrep_print_matching_filenames,
+		N_("Print filenames with matches"),
+		NULL
+	},
+
+	{
+		"files-without-matches", 'L',
+		0, G_OPTION_ARG_NONE, &ssgrep_print_nonmatching_filenames,
+		N_("Print filenames without matches"),
+		NULL
+	},
+
+	{
 		"print-locus", 'n',
 		0, G_OPTION_ARG_NONE, &ssgrep_print_locus,
 		N_("Print the location of each match"),
@@ -94,7 +126,21 @@
 	},
 
 	{
-		"version", 0,
+		"search-results", 'R',
+		0, G_OPTION_ARG_NONE, &ssgrep_locus_results,
+		N_("Search results of expressions too"),
+		NULL
+	},
+
+	{
+		"invert-match", 'v',
+		0, G_OPTION_ARG_NONE, &ssgrep_invert_match,
+		N_("Search for cells that do not match"),
+		NULL
+	},
+
+	{
+		"version", 'V',
 		0, G_OPTION_ARG_NONE, &ssgrep_show_version,
 		N_("Display program version"),
 		NULL
@@ -108,16 +154,9 @@
 	},
 
 	{
-		"keyword-file", 'f',
-		0, G_OPTION_ARG_STRING, &ssgrep_keyword_file,
-		N_("Get keywords from a file, one per line"),
-		N_("KEYWORD_FILE")
-	},
-
-	{
 		"recalc", 0,
 		0, G_OPTION_ARG_NONE, &ssgrep_recalc,
-		N_("Recalculate all cells before matching values"),
+		N_("Recalculate all cells"),
 		NULL
 	},
 
@@ -142,13 +181,21 @@
 	}
 	wb = wb_view_get_workbook (wbv);
 
-	if (ssgrep_recalc && ssgrep_locus_results)
-		workbook_recalc_all (wb);
+	if (ssgrep_locus_results) {
+		if (ssgrep_recalc)
+			workbook_recalc_all (wb);
+		else
+			workbook_recalc (wb);
+	}
 
 	search = (GnmSearchReplace*)
 		g_object_new (GNM_SEARCH_REPLACE_TYPE,
 			      "search-text", ssgrep_pattern,
 			      "is-regexp", TRUE,
+#if 0
+			      /* This does not exist yet.  */
+			      "invert", ssgrep_invert_match,
+#endif
 			      "ignore-case", ssgrep_ignore_case,
 			      "match-words", ssgrep_match_words,
 			      "search-strings", ssgrep_locus_values,
@@ -168,6 +215,12 @@
 
 	if (ssgrep_quiet) {
 		/* Nothing */
+	} else if (ssgrep_print_nonmatching_filenames) {
+		if (matches->len == 0)
+			g_print ("%s", arg);
+	} else if (ssgrep_print_matching_filenames) {
+		if (matches->len > 0)
+			g_print ("%s", arg);
 	} else if (ssgrep_count) {
 		if (ssgrep_print_filenames)
 			g_print ("%s:", arg);
@@ -265,8 +318,8 @@
 		return 0;
 	} 
 
-	if (ssgrep_keyword_file) {
-		char *uri = go_shell_arg_to_uri (ssgrep_keyword_file);
+	if (ssgrep_pattern_file) {
+		char *uri = go_shell_arg_to_uri (ssgrep_pattern_file);
 		GsfInput     	 *input;
 		GsfInputTextline *textline;
 		GError       	 *err = NULL;
@@ -278,19 +331,23 @@
 
 		if (!input) {
 			g_printerr (_("%s: Cannot read %s: %s\n"),
-				    g_get_prgname (), ssgrep_keyword_file, err->message);
+				    g_get_prgname (), ssgrep_pattern_file, err->message);
 			g_error_free (err);
 			return 1;
 		}
 
 		textline = (GsfInputTextline *)gsf_input_textline_new (input);
 		g_object_unref (G_OBJECT (input));
-
+		
 		pat = g_string_new (NULL);
 		while (NULL != (line = gsf_input_textline_ascii_gets (textline))) {
 			if (pat->len)
 				g_string_append_c (pat, '|');
-			g_string_append (pat, line);
+
+			if (ssgrep_fixed_strings)
+				go_regexp_quote (pat, line);
+			else
+				g_string_append (pat, line);
 		}
 
 		ssgrep_pattern = g_string_free (pat, FALSE);
@@ -304,7 +361,13 @@
 			g_printerr (_("%s: Missing pattern\n"), g_get_prgname ());
 			return 1;
 		}
-		ssgrep_pattern = g_strdup (argv[1]);
+
+		if (ssgrep_fixed_strings) {
+			GString *pat = g_string_new (NULL);
+			go_regexp_quote (pat, argv[1]);
+			ssgrep_pattern = g_string_free (pat, FALSE);
+		} else
+			ssgrep_pattern = g_strdup (argv[1]);
 		i = 2;
 		N = argc - i;
 	}



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