From 3fbf23455f182c757e22ceca4d438215b5929b26 Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Tue, 16 Jun 1998 00:22:10 +0000 Subject: [PATCH] Including Vikas' search code for the "attach message" menu. --- addrbook.c | 11 +++-------- compose.c | 9 ++++++--- curs_main.c | 2 +- menu.c | 18 +++++++++++++----- pattern.c | 16 ++++++++-------- protos.h | 2 +- 6 files changed, 32 insertions(+), 26 deletions(-) diff --git a/addrbook.c b/addrbook.c index e7b0732d..e14ca9b1 100644 --- a/addrbook.c +++ b/addrbook.c @@ -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); } diff --git a/compose.c b/compose.c index 285a4d37..a256f454 100644 --- 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); diff --git a/curs_main.c b/curs_main.c index cf06bcf9..2782c334 100644 --- a/curs_main.c +++ b/curs_main.c @@ -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 f582a1eb..474d4382 100644 --- 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)); diff --git a/pattern.c b/pattern.c index 0435ac76..a720c8aa 100644 --- 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; } diff --git a/protos.h b/protos.h index f8b85baf..4405cf39 100644 --- 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 *); -- 2.40.0