]> granicus.if.org Git - mutt/commitdiff
Including Vikas' search code for the "attach message" menu.
authorThomas Roessler <roessler@does-not-exist.org>
Tue, 16 Jun 1998 00:22:10 +0000 (00:22 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Tue, 16 Jun 1998 00:22:10 +0000 (00:22 +0000)
addrbook.c
compose.c
curs_main.c
menu.c
pattern.c
protos.h

index e7b0732dbff007efb32fd0dd656a4d5187dcf0c8..e14ca9b1d7f5f6076887892c0e498671ab5c3472 100644 (file)
@@ -68,17 +68,12 @@ alias_format_str (char *dest, size_t destlen, char op, const char *src,
 
 int alias_search (MUTTMENU *m, regex_t *re, int n)
 {
-  int i, match = 0;
   char s[LONG_STRING];
   int slen = sizeof(s);
 
-  for (i=0; i < m->max; i++)
-  {
-   mutt_FormatString (s, slen, NONULL (AliasFmt), alias_format_str,
-                      (unsigned long) ((ALIAS **) m->data)[n], 0);
-   if ((match = regexec (re, s, 0, NULL, 0))) return match;
-  }
-  return (0);
+  mutt_FormatString (s, slen, NONULL (AliasFmt), alias_format_str,
+                    (unsigned long) ((ALIAS **) m->data)[n], 0);
+  return regexec (re, s, 0, NULL, 0);
 }
 
 
index 285a4d37d6ca2cd616bd4925b141a3b321bed0f7..a256f454ab49255b264c9832e3aaf8ab04a631eb 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -416,10 +416,12 @@ static HEADER *select_msg (CONTEXT *ctx)
   MUTTMENU *menu;
   int i, done=0, r=-1;
   char helpstr[SHORT_STRING];
-  char title[SHORT_STRING];
+  char title[SHORT_STRING], from_folder[SHORT_STRING];
 
-  snprintf(title, sizeof (title), "Messages to attach from folder %s",
-          ctx->path);
+  strfcpy(from_folder, ctx->path, sizeof (from_folder));
+  mutt_pretty_mailbox (from_folder);
+  snprintf(title, sizeof (title), "Attach messages from folder: %s", 
+                                   from_folder);
 
   menu = mutt_new_menu ();
   menu->make_entry = attach_msg_make_entry;
@@ -427,6 +429,7 @@ static HEADER *select_msg (CONTEXT *ctx)
   menu->max = ctx->msgcount;
   menu->title = title;
   menu->data = ctx;
+  menu->search = (int (*)(MUTTMENU *, regex_t *, int)) -1;
   menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_GENERIC,
                                  AttachMsgHelp);
 
index cf06bcf909aedf0353dddadd94e59a9dbff19ae0..2782c3342b6f2387d0242790b5cf49d817610518 100644 (file)
@@ -655,7 +655,7 @@ void mutt_index_menu (void)
       case OP_SEARCH_OPPOSITE:
 
        CHECK_MSGCOUNT;
-       if ((menu->current = mutt_search_command (menu->current, op)) == -1)
+       if ((menu->current = mutt_search_command (Context, menu->current, op)) == -1)
          menu->current = menu->oldcurrent;
        else
          menu->redraw = REDRAW_MOTION;
diff --git a/menu.c b/menu.c
index f582a1eba157da53672ae7dbcc05005fc33232d4..474d4382ef9ae23e6b67155ad147d0fcc8ef34d2 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -574,14 +574,21 @@ void mutt_menuDestroy (MUTTMENU **p)
 static int menu_search (MUTTMENU *menu, int op)
 {
   int r;
-  int searchDir = (menu->searchDir == M_SEARCH_UP) ? -1 : 1;
+  int searchDir;
   regex_t re;
   char buf[SHORT_STRING];
 
+  /* Need to search the folder using the pattern matching language,
+   * not plain regexps. mutt_search_command() does just this */
+  if (menu->search == (int (*)(MUTTMENU *, regex_t *, int)) -1 )
+    return mutt_search_command (menu->data, menu->current, op);
+
   if (op != OP_SEARCH_NEXT && op != OP_SEARCH_OPPOSITE)
   {
     strfcpy (buf, menu->searchBuf ? menu->searchBuf : "", sizeof (buf));
-    if (mutt_get_field ("Search for: ", buf, sizeof (buf), M_CLEAR) != 0 || !buf[0])
+    if (mutt_get_field ((op == OP_SEARCH) ? "Search for: " : 
+                                            "Reverse search for: ",
+                        buf, sizeof (buf), M_CLEAR) != 0 || !buf[0])
       return (-1);
     safe_free ((void **) &menu->searchBuf);
     menu->searchBuf = safe_strdup (buf);
@@ -594,11 +601,12 @@ static int menu_search (MUTTMENU *menu, int op)
       mutt_error ("No search pattern.");
       return (-1);
     }
-
-    if (op == OP_SEARCH_OPPOSITE)
-      searchDir = -searchDir;
   }
 
+  searchDir = (menu->searchDir == M_SEARCH_UP) ? -1 : 1;
+  if (op == OP_SEARCH_OPPOSITE)
+    searchDir = -searchDir;
+
   if ((r = REGCOMP (&re, menu->searchBuf, REG_NOSUB | mutt_which_case (menu->searchBuf))) != 0)
   {
     regerror (r, &re, buf, sizeof (buf));
index 0435ac76f64664ee8b5c682292532de353518f69..a720c8aa302756dcd965cd3810a2613d9a2c6b77 100644 (file)
--- a/pattern.c
+++ b/pattern.c
@@ -960,7 +960,7 @@ int mutt_pattern_func (int op, char *prompt, HEADER *hdr)
   return 0;
 }
 
-int mutt_search_command (int cur, int op)
+int mutt_search_command (CONTEXT *ctx, int cur, int op)
 {
   int i, j;
   char buf[STRING];
@@ -1011,8 +1011,8 @@ int mutt_search_command (int cur, int op)
 
   if (option (OPTSEARCHINVALID))
   {
-    for (i = 0; i < Context->msgcount; i++)
-      Context->hdrs[i]->searched = 0;
+    for (i = 0; i < ctx->msgcount; i++)
+      ctx->hdrs[i]->searched = 0;
     unset_option (OPTSEARCHINVALID);
   }
 
@@ -1020,9 +1020,9 @@ int mutt_search_command (int cur, int op)
   if (op == OP_SEARCH_OPPOSITE)
     incr = -incr;
 
-  for (i = cur + incr, j = 0 ; j != Context->vcount; j++)
+  for (i = cur + incr, j = 0 ; j != ctx->vcount; j++)
   {
-    if (i > Context->vcount - 1)
+    if (i > ctx->vcount - 1)
     {
       i = 0;
       if (option (OPTWRAPSEARCH))
@@ -1035,7 +1035,7 @@ int mutt_search_command (int cur, int op)
     }
     else if (i < 0)
     {
-      i = Context->vcount - 1;
+      i = ctx->vcount - 1;
       if (option (OPTWRAPSEARCH))
         mutt_message ("Search wrapped to bottom.");
       else 
@@ -1045,7 +1045,7 @@ int mutt_search_command (int cur, int op)
       }
     }
 
-    h = Context->hdrs[Context->v2r[i]];
+    h = ctx->hdrs[ctx->v2r[i]];
     if (h->searched)
     {
       /* if we've already evaulated this message, use the cached value */
@@ -1056,7 +1056,7 @@ int mutt_search_command (int cur, int op)
     {
       /* remember that we've already searched this message */
       h->searched = 1;
-      if ((h->matched = (mutt_pattern_exec (SearchPattern, M_MATCH_FULL_ADDRESS, Context, h) > 0)))
+      if ((h->matched = (mutt_pattern_exec (SearchPattern, M_MATCH_FULL_ADDRESS, ctx, h) > 0)))
        return i;
     }
 
index f8b85baf462aa1a5a0ec539d9e67ab61b86ca10d..4405cf3987acee3aae00a57dc3d4aa293110bbac 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -219,7 +219,7 @@ int mutt_print_attachment (FILE *, BODY *);
 int mutt_query_complete (char *, size_t);
 int mutt_save_attachment (FILE *, BODY *, char *, int);
 int mutt_save_message (HEADER *, int, int, int *);
-int mutt_search_command (int, int);
+int mutt_search_command (CONTEXT *, int, int);
 int mutt_send_menu (HEADER *, char *, size_t, HEADER *);
 int mutt_send_message (HEADER *, const char *);
 int mutt_strcmp (const char *, const char *);