]> granicus.if.org Git - neomutt/commitdiff
Fix simple patterns.
authorThomas Roessler <roessler@does-not-exist.org>
Mon, 7 Sep 1998 09:13:53 +0000 (09:13 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Mon, 7 Sep 1998 09:13:53 +0000 (09:13 +0000)
curs_lib.c
lib.c
pattern.c
protos.h
query.c

index f324e40a77c22fb1086389fb85604eb2c5a7fb96..2d49dd47646cdbd790c3b52e814b4c70c94f3912 100644 (file)
@@ -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 9bc71529525009e895f988c81ddb6138d4780018..13d2faaf8637e33e48f040d38996b30db2f7f19a 100644 (file)
--- 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 
index 53b85d4701b39d355539ee62806eed5a387886e2..7d8c4846e6eadbe75275a913b3a7b692999493bb 100644 (file)
--- 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);
     }
   }
index 3f086e57fd7d24b90c9358675437490a60f2f959..08f93e4ad1c5bb33886ed966b14054c6d4ae0476 100644 (file)
--- 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 0e90b66b099dc1b5e1ae6b542e79a048bbd5bd30..d09040f18d4b891e8a486c978e7308465a795290 100644 (file)
--- 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)
   {