Commit 1c84d742 authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Support -v and --print-type.

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.


svn path=/trunk/; revision=16711
parent 4b533e3b
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.
2008-07-09 Morten Welinder <terra@gnome.org>
* src/ssgrep.c (main): Support -q -c -i -w -h -H -n -l -L -F.
......
......@@ -36,6 +36,7 @@ enum {
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 @@ gnm_search_filter_matching (GnmSearchReplace *sr, const GPtrArray *cells)
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 @@ gnm_search_replace_get_property (GObject *object,
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 @@ gnm_search_replace_set_property (GObject *object,
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;
......@@ -587,6 +596,15 @@ gnm_search_replace_class_init (GObjectClass *gobject_class)
FALSE,
GSF_PARAM_STATIC |
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,
......
......@@ -62,6 +62,7 @@ struct _GnmSearchReplace {
gboolean search_expressions;
gboolean search_expression_results;
gboolean search_comments;
gboolean invert;
GnmSearchReplaceError error_behaviour;
gboolean replace_keep_strings;
......
......@@ -43,10 +43,11 @@ 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 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;
......@@ -132,6 +133,13 @@ static GOptionEntry const ssgrep_options [] = {
NULL
},
{
"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,
......@@ -173,6 +181,7 @@ ssgrep (const char *arg, char const *uri, IOContext *ioc)
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 @@ ssgrep (const char *arg, char const *uri, IOContext *ioc)
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 @@ ssgrep (const char *arg, char const *uri, IOContext *ioc)
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 @@ ssgrep (const char *arg, char const *uri, IOContext *ioc)
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 @@ ssgrep (const char *arg, char const *uri, IOContext *ioc)
item->ep.eval.col,
item->ep.eval.row);
txt = gnm_cell_get_entered_text (cell);
locus_type = _("cell");
break;
}
......@@ -249,13 +257,14 @@ ssgrep (const char *arg, char const *uri, IOContext *ioc)
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 @@ ssgrep (const char *arg, char const *uri, IOContext *ioc)
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));
......
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