From 2143887efe23f591ccabb4e1f18b0cf0ed43c427 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Wed, 4 Apr 2018 12:13:26 +0100 Subject: [PATCH] history: move static functions first --- history.c | 168 +++++++++++++++++++++++++++--------------------------- 1 file changed, 84 insertions(+), 84 deletions(-) diff --git a/history.c b/history.c index 01f9eb2c5..874f55454 100644 --- a/history.c +++ b/history.c @@ -414,6 +414,90 @@ static void remove_history_dups(enum HistoryClass hclass, const char *str) h->hist[dest--] = NULL; } +static const char *history_format_str(char *dest, size_t destlen, size_t col, int cols, + char op, const char *src, const char *fmt, + const char *ifstring, const char *elsestring, + unsigned long data, enum FormatFlag flags) +{ + char *match = (char *) data; + + switch (op) + { + case 's': + mutt_format_s(dest, destlen, fmt, match); + break; + } + + return (src); +} + +static void history_entry(char *s, size_t slen, struct Menu *m, int num) +{ + char *entry = ((char **) m->data)[num]; + + mutt_expando_format(s, slen, 0, MuttIndexWindow->cols, "%s", history_format_str, + (unsigned long) entry, MUTT_FORMAT_ARROWCURSOR); +} + +static void history_menu(char *buf, size_t buflen, char **matches, int match_count) +{ + struct Menu *menu; + int done = 0; + char helpstr[LONG_STRING]; + char title[STRING]; + + snprintf(title, sizeof(title), _("History '%s'"), buf); + + menu = mutt_menu_new(MENU_GENERIC); + menu->make_entry = history_entry; + menu->title = title; + menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_GENERIC, HistoryHelp); + mutt_menu_push_current(menu); + + menu->max = match_count; + menu->data = matches; + + while (!done) + { + switch (mutt_menu_loop(menu)) + { + case OP_GENERIC_SELECT_ENTRY: + mutt_str_strfcpy(buf, matches[menu->current], buflen); + /* fall through */ + + case OP_EXIT: + done = 1; + break; + } + } + + mutt_menu_pop_current(menu); + mutt_menu_destroy(&menu); +} + +static int search_history(char *search_buf, enum HistoryClass hclass, char **matches) +{ + struct History *h = get_history(hclass); + int match_count = 0, cur; + + if ((History == 0) || !h) + return 0; + + cur = h->last; + do + { + cur--; + if (cur < 0) + cur = History; + if (cur == h->last) + break; + if (mutt_str_stristr(h->hist[cur], search_buf)) + matches[match_count++] = h->hist[cur]; + } while (match_count < History); + + return match_count; +} + /** * mutt_hist_init - Create a set of empty History ring buffers * @@ -623,90 +707,6 @@ void mutt_hist_save_scratch(enum HistoryClass hclass, const char *str) mutt_str_replace(&h->hist[h->last], str); } -static const char *history_format_str(char *dest, size_t destlen, size_t col, int cols, - char op, const char *src, const char *fmt, - const char *ifstring, const char *elsestring, - unsigned long data, enum FormatFlag flags) -{ - char *match = (char *) data; - - switch (op) - { - case 's': - mutt_format_s(dest, destlen, fmt, match); - break; - } - - return (src); -} - -static void history_entry(char *s, size_t slen, struct Menu *m, int num) -{ - char *entry = ((char **) m->data)[num]; - - mutt_expando_format(s, slen, 0, MuttIndexWindow->cols, "%s", history_format_str, - (unsigned long) entry, MUTT_FORMAT_ARROWCURSOR); -} - -static void history_menu(char *buf, size_t buflen, char **matches, int match_count) -{ - struct Menu *menu; - int done = 0; - char helpstr[LONG_STRING]; - char title[STRING]; - - snprintf(title, sizeof(title), _("History '%s'"), buf); - - menu = mutt_menu_new(MENU_GENERIC); - menu->make_entry = history_entry; - menu->title = title; - menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_GENERIC, HistoryHelp); - mutt_menu_push_current(menu); - - menu->max = match_count; - menu->data = matches; - - while (!done) - { - switch (mutt_menu_loop(menu)) - { - case OP_GENERIC_SELECT_ENTRY: - mutt_str_strfcpy(buf, matches[menu->current], buflen); - /* fall through */ - - case OP_EXIT: - done = 1; - break; - } - } - - mutt_menu_pop_current(menu); - mutt_menu_destroy(&menu); -} - -static int search_history(char *search_buf, enum HistoryClass hclass, char **matches) -{ - struct History *h = get_history(hclass); - int match_count = 0, cur; - - if ((History == 0) || !h) - return 0; - - cur = h->last; - do - { - cur--; - if (cur < 0) - cur = History; - if (cur == h->last) - break; - if (mutt_str_stristr(h->hist[cur], search_buf)) - matches[match_count++] = h->hist[cur]; - } while (match_count < History); - - return match_count; -} - void mutt_history_complete(char *buf, size_t buflen, enum HistoryClass hclass) { char **matches; -- 2.40.0