From: Thomas Roessler Date: Mon, 7 Sep 1998 09:13:53 +0000 (+0000) Subject: Fix simple patterns. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=87e1041ed79cf2bc7d44677104e493c84738a709;p=neomutt Fix simple patterns. --- diff --git a/curs_lib.c b/curs_lib.c index f324e40a7..2d49dd476 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -115,7 +115,7 @@ void mutt_edit_file (const char *editor, const char *data) char cmd[LONG_STRING]; endwin (); - mutt_expand_fmt (cmd, sizeof (cmd), editor, data); + mutt_expand_file_fmt (cmd, sizeof (cmd), editor, data); mutt_system (cmd); keypad (stdscr, TRUE); clearok (stdscr, TRUE); @@ -279,7 +279,7 @@ int mutt_do_pager (const char *banner, char cmd[STRING]; endwin (); - mutt_expand_fmt (cmd, sizeof(cmd), Pager, tempfile); + mutt_expand_file_fmt (cmd, sizeof(cmd), Pager, tempfile); mutt_system (cmd); mutt_unlink (tempfile); rc = 0; diff --git a/lib.c b/lib.c index 9bc715295..13d2faaf8 100644 --- a/lib.c +++ b/lib.c @@ -590,22 +590,23 @@ int mutt_copy_stream (FILE *fin, FILE *fout) return 0; } +void mutt_expand_file_fmt (char *dest, size_t destlen, const char *fmt, const char *src) +{ + char *_src = mutt_quote_filename(src); + + mutt_expand_fmt(dest, destlen, fmt, _src); + safe_free((void **) &_src); +} + void mutt_expand_fmt (char *dest, size_t destlen, const char *fmt, const char *src) { const char *p = fmt; const char *last = p; size_t len; - char *_src; size_t slen; int found = 0; - /* some rationale should be given here: mutt's quoting - * rules are similar enough to the shell's rules so we - * can use mutt_quote_filename() even for patterns. - */ - - _src = mutt_quote_filename(src); - slen = strlen (_src); + slen = strlen (src); while ((p = strchr (p, '%')) != NULL) { @@ -630,7 +631,7 @@ void mutt_expand_fmt (char *dest, size_t destlen, const char *fmt, const char *s } } - strfcpy (dest, _src, destlen); + strfcpy (dest, src, destlen); if (slen > destlen) { /* no more room */ @@ -651,9 +652,8 @@ void mutt_expand_fmt (char *dest, size_t destlen, const char *fmt, const char *s if (found) strfcpy (dest, last, destlen); else - snprintf (dest, destlen, "%s %s", fmt, _src); + snprintf (dest, destlen, "%s %s", fmt, src); - FREE(&_src); } static int diff --git a/pattern.c b/pattern.c index 53b85d470..7d8c4846e 100644 --- a/pattern.c +++ b/pattern.c @@ -824,6 +824,21 @@ mutt_pattern_exec (struct pattern_t *pat, pattern_exec_flag flags, CONTEXT *ctx, return (-1); } +static void quote_simple(char *tmp, size_t len, const char *p) +{ + int i = 0; + + tmp[i++] = '"'; + while (*p && i < len - 2) + { + if (*p == '\\' || *p == '"') + tmp[i++] = '\\'; + tmp[i++] = *p++; + } + tmp[i++] = '"'; + tmp[i] = 0; +} + /* convert a simple search into a real request */ void mutt_check_simple (char *s, size_t len, const char *simple) { @@ -853,18 +868,7 @@ void mutt_check_simple (char *s, size_t len, const char *simple) strfcpy (s, "~U", len); else { - const char *p = s; - int i = 0; - - tmp[i++] = '"'; - while (*p && i < sizeof (tmp) - 2) - { - if (*p == '\\' || *p == '"') - tmp[i++] = '\\'; - tmp[i++] = *p++; - } - tmp[i++] = '"'; - tmp[i] = 0; + quote_simple (tmp, sizeof(tmp), s); mutt_expand_fmt (s, len, simple, tmp); } } diff --git a/protos.h b/protos.h index 3f086e57f..08f93e4ad 100644 --- a/protos.h +++ b/protos.h @@ -141,6 +141,7 @@ void mutt_edit_headers (const char *, const char *, HEADER *, char *, size_t); void mutt_curses_error (const char *, ...); void mutt_enter_command (void); void mutt_exit (int); +void mutt_expand_file_fmt (char *, size_t, const char *, const char *); void mutt_expand_fmt (char *, size_t, const char *, const char *); void mutt_expand_link (char *, const char *, const char *); void mutt_fetchPopMail (void); diff --git a/query.c b/query.c index 0e90b66b0..d09040f18 100644 --- a/query.c +++ b/query.c @@ -80,7 +80,7 @@ static QUERY *run_query (char *s, int quiet) int l; - mutt_expand_fmt (cmd, sizeof(cmd), QueryCmd, s); + mutt_expand_file_fmt (cmd, sizeof(cmd), QueryCmd, s); if ((thepid = mutt_create_filter (cmd, NULL, &fp, NULL)) < 0) {