gnumeric r16711 - in trunk: . src



Author: mortenw
Date: Thu Jul 10 15:30:57 2008
New Revision: 16711
URL: http://svn.gnome.org/viewvc/gnumeric?rev=16711&view=rev

Log:
2008-07-10  Morten Welinder  <terra gnome org>

	* src/ssgrep.c (main): Support -v and --print-type.

	* src/search.c (gnm_search_filter_matching): Handle new invert
	flag.



Modified:
   trunk/ChangeLog
   trunk/src/search.c
   trunk/src/search.h
   trunk/src/ssgrep.c

Modified: trunk/src/search.c
==============================================================================
--- trunk/src/search.c	(original)
+++ trunk/src/search.c	Thu Jul 10 15:30:57 2008
@@ -36,6 +36,7 @@
 	PROP_SEARCH_EXPRESSIONS,
 	PROP_SEARCH_EXPRESSION_RESULTS,
 	PROP_SEARCH_COMMENTS,
+	PROP_INVERT,
 	PROP_BY_ROW,
 	PROP_QUERY,
 	PROP_REPLACE_KEEP_STRINGS,
@@ -202,21 +203,23 @@
 
 		found = gnm_search_replace_cell (sr, ep, FALSE, &cell_res);
 		g_free (cell_res.old_text);
-		if (found) {
+		if (cell_res.cell != NULL && found != sr->invert) {
 			GnmSearchFilterResult *item = g_new (GnmSearchFilterResult, 1);
 			item->ep = *ep;
 			item->locus = GNM_SRL_CONTENTS;
 			g_ptr_array_add (result, item);
 		}
 
-		if (gnm_search_replace_value (sr, ep, &value_res)) {
+		found = gnm_search_replace_value (sr, ep, &value_res);
+		if (value_res.cell != NULL && gnm_cell_has_expr (value_res.cell) && found != sr->invert) {
 			GnmSearchFilterResult *item = g_new (GnmSearchFilterResult, 1);
 			item->ep = *ep;
 			item->locus = GNM_SRL_VALUE;
 			g_ptr_array_add (result, item);
 		}
 
-		if (gnm_search_replace_comment (sr, ep, FALSE, &comment_res)) {
+		found = gnm_search_replace_comment (sr, ep, FALSE, &comment_res);
+		if (comment_res.comment != NULL && found != sr->invert) {
 			GnmSearchFilterResult *item = g_new (GnmSearchFilterResult, 1);
 			item->ep = *ep;
 			item->locus = GNM_SRL_COMMENT;
@@ -426,6 +429,9 @@
 	case PROP_SEARCH_COMMENTS:
 		g_value_set_boolean (value, sr->search_comments);
 		break;
+	case PROP_INVERT:
+		g_value_set_boolean (value, sr->invert);
+		break;
 	case PROP_BY_ROW:
 		g_value_set_boolean (value, sr->by_row);
 		break;
@@ -494,6 +500,9 @@
 	case PROP_SEARCH_COMMENTS:
 		sr->search_comments = g_value_get_boolean (value);
 		break;
+	case PROP_INVERT:
+		sr->invert = g_value_get_boolean (value);
+		break;
 	case PROP_BY_ROW:
 		sr->by_row = g_value_get_boolean (value);
 		break;
@@ -589,6 +598,15 @@
 				       G_PARAM_READWRITE));
 	g_object_class_install_property
 		(gobject_class,
+		 PROP_INVERT,
+		 g_param_spec_boolean ("invert",
+				       _("Invert"),
+				       _("Collect non-matching items"),
+				       FALSE,
+				       GSF_PARAM_STATIC |
+				       G_PARAM_READWRITE));
+	g_object_class_install_property
+		(gobject_class,
 		 PROP_BY_ROW,
 		 g_param_spec_boolean ("by-row",
 				       _("By Row"),

Modified: trunk/src/search.h
==============================================================================
--- trunk/src/search.h	(original)
+++ trunk/src/search.h	Thu Jul 10 15:30:57 2008
@@ -62,6 +62,7 @@
 	gboolean search_expressions;
 	gboolean search_expression_results;
 	gboolean search_comments;
+	gboolean invert;
 
 	GnmSearchReplaceError error_behaviour;
 	gboolean replace_keep_strings;

Modified: trunk/src/ssgrep.c
==============================================================================
--- trunk/src/ssgrep.c	(original)
+++ trunk/src/ssgrep.c	Thu Jul 10 15:30:57 2008
@@ -43,10 +43,11 @@
 static gboolean ssgrep_print_matching_filenames = FALSE;
 static gboolean ssgrep_print_nonmatching_filenames = FALSE;
 static gboolean ssgrep_print_locus = FALSE;
+static gboolean ssgrep_print_type = 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_invert_match = FALSE;
 
 static gboolean ssgrep_show_version = FALSE;
 static char *ssgrep_pattern_file = NULL;
@@ -133,6 +134,13 @@
 	},
 
 	{
+		"print-type", 'T',
+		0, G_OPTION_ARG_NONE, &ssgrep_print_type,
+		N_("Print the location type of each match"),
+		NULL
+	},
+
+	{
 		"invert-match", 'v',
 		0, G_OPTION_ARG_NONE, &ssgrep_invert_match,
 		N_("Search for cells that do not match"),
@@ -173,6 +181,7 @@
 	GnmSearchReplace *search;
 	GPtrArray *cells;
 	GPtrArray *matches;
+	gboolean has_match;
 
 	wbv = wb_view_new_from_uri (uri, NULL, ioc, NULL);
 	if (wbv == NULL) {
@@ -192,10 +201,7 @@
 		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,
@@ -209,18 +215,19 @@
 
 	cells = gnm_search_collect_cells (search);
 	matches = gnm_search_filter_matching (search, cells);
+	has_match = (matches->len > 0);
 
-	if (matches->len > 0)
+	if (has_match)
 		ssgrep_any_matches = TRUE;
 
 	if (ssgrep_quiet) {
 		/* Nothing */
 	} else if (ssgrep_print_nonmatching_filenames) {
-		if (matches->len == 0)
-			g_print ("%s", arg);
+		if (!has_match)
+			g_print ("%s\n", arg);
 	} else if (ssgrep_print_matching_filenames) {
-		if (matches->len > 0)
-			g_print ("%s", arg);
+		if (has_match)
+			g_print ("%s\n", arg);
 	} else if (ssgrep_count) {
 		if (ssgrep_print_filenames)
 			g_print ("%s:", arg);
@@ -230,7 +237,7 @@
 		for (ui = 0; ui < matches->len; ui++) {
 			const GnmSearchFilterResult *item = g_ptr_array_index (matches, ui);
 			char *txt = NULL;
-			const char *locus_prefix = "";
+			const char *locus_type = "";
 
 			switch (item->locus) {
 			case GNM_SRL_CONTENTS: {
@@ -239,6 +246,7 @@
 							item->ep.eval.col,
 							item->ep.eval.row);
 				txt = gnm_cell_get_entered_text (cell);
+				locus_type = _("cell");
 				break;
 			}
 
@@ -249,13 +257,14 @@
 							item->ep.eval.row);
 				if (cell && cell->value)
 					txt = value_get_as_string (cell->value);
+				locus_type = _("result");
 				break;
 			}
 
 			case GNM_SRL_COMMENT: {
 				GnmComment *comment = sheet_get_comment (item->ep.sheet, &item->ep.eval);
 				txt = g_strdup (cell_comment_text_get (comment));
-				locus_prefix = _("Comment of ");
+				locus_type = _("comment");
 				break;
 			}
 			default:
@@ -265,9 +274,11 @@
 			if (ssgrep_print_filenames)
 				g_print ("%s:", arg);
 
+			if (ssgrep_print_type)
+				g_print ("%s:", locus_type);
+
 			if (ssgrep_print_locus)
-				g_print ("%s%s!%s:",
-					 locus_prefix,
+				g_print ("%s!%s:",
 					 item->ep.sheet->name_quoted,
 					 cellpos_as_string (&item->ep.eval));
 



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