From: Richard Russon Date: Fri, 13 Jul 2018 16:11:33 +0000 (+0100) Subject: split up history X-Git-Tag: 2019-10-25~756^2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fc5b69c671c19576daf8b344fe7e22dc279f7e2e;p=neomutt split up history --- diff --git a/Makefile.autosetup b/Makefile.autosetup index 469963b3a..c64920a2a 100644 --- a/Makefile.autosetup +++ b/Makefile.autosetup @@ -65,9 +65,9 @@ NEOMUTTOBJS= addrbook.o alias.o bcache.o browser.o buffy.o \ color.o commands.o complete.o compose.o compress.o \ conststrings.o copy.o curs_lib.o curs_main.o edit.o editmsg.o \ enriched.o enter.o filter.o flags.o from.o group.o handler.o \ - hdrline.o help.o history.o hook.o init.o keymap.o \ + hdrline.o help.o hook.o init.o keymap.o \ main.o menu.o muttlib.o mutt_account.o mutt_attach.o mutt_body.o mutt_header.o \ - mutt_logging.o mutt_signal.o mutt_socket.o mutt_thread.o mutt_window.o mx.o \ + mutt_history.o mutt_logging.o mutt_signal.o mutt_socket.o mutt_thread.o mutt_window.o mx.o \ pager.o parse.o pattern.o \ postpone.o progress.o query.o recvattach.o recvcmd.o resize.o rfc1524.o \ rfc2047.o rfc2231.o rfc3676.o safe_asprintf.o score.o send.o \ @@ -141,7 +141,7 @@ ALLOBJS+= $(LIBMAILDIROBJS) # libmutt LIBMUTT= libmutt.a LIBMUTTOBJS= mutt/base64.o mutt/buffer.o mutt/charset.o mutt/date.o \ - mutt/envlist.o mutt/exit.o mutt/file.o mutt/hash.o \ + mutt/envlist.o mutt/exit.o mutt/file.o mutt/hash.o mutt/history.o \ mutt/idna.o mutt/list.o mutt/logging.o mutt/mapping.o \ mutt/mbyte.o mutt/md5.o mutt/memory.o mutt/mime.o mutt/regex.o \ mutt/rfc2047.o mutt/sha1.o mutt/signal.o mutt/string.o diff --git a/enter.c b/enter.c index 3473ccce7..484034d1a 100644 --- a/enter.c +++ b/enter.c @@ -41,9 +41,9 @@ #include "curs_lib.h" #include "enter_state.h" #include "globals.h" -#include "history.h" #include "keymap.h" #include "mutt_curses.h" +#include "mutt_history.h" #include "mutt_window.h" #include "muttlib.h" #include "opcodes.h" @@ -295,7 +295,7 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, int flags, int mul case OP_EDITOR_HISTORY_SEARCH: state->curpos = state->lastchar; mutt_mb_wcstombs(buf, buflen, state->wbuf, state->curpos); - mutt_history_complete(buf, buflen, hclass); + mutt_hist_complete(buf, buflen, hclass); replace_part(state, 0, buf); rc = 1; goto bye; diff --git a/init.c b/init.c index 9bcb72d4b..8e98a5e11 100644 --- a/init.c +++ b/init.c @@ -43,12 +43,12 @@ #include "filter.h" #include "group.h" #include "hcache/hcache.h" -#include "history.h" #include "keymap.h" #include "mailbox.h" #include "mbtable.h" #include "menu.h" #include "mutt_curses.h" +#include "mutt_history.h" #include "mutt_window.h" #include "mx.h" #include "myvar.h" diff --git a/init.h b/init.h index d055c710b..18ba0e2fc 100644 --- a/init.h +++ b/init.h @@ -46,7 +46,7 @@ #include "group.h" #include "handler.h" #include "hdrline.h" -#include "history.h" +#include "mutt_history.h" #include "hook.h" #include "imap/imap.h" #include "keymap.h" diff --git a/history.c b/mutt/history.c similarity index 79% rename from history.c rename to mutt/history.c index dbb767877..49a89328e 100644 --- a/history.c +++ b/mutt/history.c @@ -69,23 +69,18 @@ */ #include "config.h" -#include #include #include #include #include -#include -#include "mutt/mutt.h" -#include "mutt.h" #include "history.h" -#include "curs_lib.h" -#include "format_flags.h" -#include "keymap.h" -#include "menu.h" -#include "mutt_window.h" -#include "muttlib.h" -#include "opcodes.h" -#include "protos.h" +#include "charset.h" +#include "file.h" +#include "hash.h" +#include "logging.h" +#include "memory.h" +#include "message.h" +#include "string2.h" /* These Config Variables are only used in history.c */ short History; /**< Number of history entries stored in memory */ @@ -107,14 +102,6 @@ struct History short last; }; -static const struct Mapping HistoryHelp[] = { - { N_("Exit"), OP_EXIT }, - { N_("Select"), OP_GENERIC_SELECT_ENTRY }, - { N_("Search"), OP_SEARCH }, - { N_("Help"), OP_HELP }, - { NULL, 0 }, -}; - /* global vars used for the string-history routines */ static struct History Histories[HC_LAST]; @@ -415,109 +402,13 @@ static void remove_history_dups(enum HistoryClass hclass, const char *str) } /** - * history_format_str - Format a string for the history list - * @param[out] buf Buffer in which to save string - * @param[in] buflen Buffer length - * @param[in] col Starting column - * @param[in] cols Number of screen columns - * @param[in] op printf-like operator, e.g. 't' - * @param[in] src printf-like format string - * @param[in] prec Field precision, e.g. "-3.4" - * @param[in] if_str If condition is met, display this string - * @param[in] else_str Otherwise, display this string - * @param[in] data Pointer to the mailbox Context - * @param[in] flags Format flags - * @retval src (unchanged) - * - * history_format_str() is a callback function for mutt_expando_format(). - * - * | Expando | Description - * |:--------|:-------------- - * | \%s | History match - */ -static const char *history_format_str(char *buf, size_t buflen, size_t col, int cols, - char op, const char *src, const char *prec, - const char *if_str, const char *else_str, - unsigned long data, enum FormatFlag flags) -{ - char *match = (char *) data; - - switch (op) - { - case 's': - mutt_format_s(buf, buflen, prec, match); - break; - } - - return src; -} - -/** - * history_entry - Format a menu item for the history list - * @param[out] buf Buffer in which to save string - * @param[in] buflen Buffer length - * @param[in] menu Menu containing aliases - * @param[in] num Index into the menu - */ -static void history_entry(char *buf, size_t buflen, struct Menu *menu, int num) -{ - char *entry = ((char **) menu->data)[num]; - - mutt_expando_format(buf, buflen, 0, MuttIndexWindow->cols, "%s", history_format_str, - (unsigned long) entry, MUTT_FORMAT_ARROWCURSOR); -} - -/** - * history_menu - Select an item from a history list - * @param buf Buffer in which to save string - * @param buflen Buffer length - * @param matches Items to choose from - * @param match_count Number of items - */ -static void history_menu(char *buf, size_t buflen, char **matches, int match_count) -{ - struct Menu *menu = NULL; - 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); -} - -/** - * search_history - Find matches in a history list + * mutt_hist_search - Find matches in a history list * @param[in] search_buf String to find * @param[in] hclass History list * @param[out] matches All the matching lines * @retval num Matches found */ -static int search_history(char *search_buf, enum HistoryClass hclass, char **matches) +int mutt_hist_search(char *search_buf, enum HistoryClass hclass, char **matches) { struct History *h = get_history(hclass); int match_count = 0, cur; @@ -768,23 +659,3 @@ void mutt_hist_save_scratch(enum HistoryClass hclass, const char *str) * an old garbage value that should be overwritten */ mutt_str_replace(&h->hist[h->last], str); } - -/** - * mutt_history_complete - Complete a string from a history list - * @param buf Buffer in which to save string - * @param buflen Buffer length - * @param hclass History list to use - */ -void mutt_history_complete(char *buf, size_t buflen, enum HistoryClass hclass) -{ - char **matches = mutt_mem_calloc(History, sizeof(char *)); - int match_count = search_history(buf, hclass, matches); - if (match_count) - { - if (match_count == 1) - mutt_str_strfcpy(buf, matches[0], buflen); - else - history_menu(buf, buflen, matches, match_count); - } - FREE(&matches); -} diff --git a/history.h b/mutt/history.h similarity index 91% rename from history.h rename to mutt/history.h index 6928d42fc..ccb8e1d2d 100644 --- a/history.h +++ b/mutt/history.h @@ -24,9 +24,8 @@ #define _MUTT_HISTORY_H #include -#include -/* These Config Variables are only used in history.c */ +/* These Config Variables are only used in mutt/history.c */ extern short History; extern char *HistoryFile; extern bool HistoryRemoveDups; @@ -57,6 +56,7 @@ char *mutt_hist_prev(enum HistoryClass hclass); void mutt_hist_read_file(void); void mutt_hist_reset_state(enum HistoryClass hclass); void mutt_hist_save_scratch(enum HistoryClass hclass, const char *str); -void mutt_history_complete(char *buf, size_t buflen, enum HistoryClass hclass); +int mutt_hist_search(char *search_buf, enum HistoryClass hclass, char **matches); #endif /* _MUTT_HISTORY_H */ + diff --git a/mutt/mutt.h b/mutt/mutt.h index a054257f2..0b4ba11d8 100644 --- a/mutt/mutt.h +++ b/mutt/mutt.h @@ -35,6 +35,7 @@ * | mutt/exit.c | @subpage exit | * | mutt/file.c | @subpage file | * | mutt/hash.c | @subpage hash | + * | mutt/history.c | @subpage history | * | mutt/idna.c | @subpage idna | * | mutt/list.c | @subpage list | * | mutt/logging.c | @subpage logging | @@ -66,6 +67,7 @@ #include "exit.h" #include "file.h" #include "hash.h" +#include "history.h" #include "idna2.h" #include "list.h" #include "logging.h" diff --git a/mutt_history.c b/mutt_history.c new file mode 100644 index 000000000..55e1853e9 --- /dev/null +++ b/mutt_history.c @@ -0,0 +1,157 @@ +/** + * @file + * Read/write command history from/to a file + * + * @authors + * Copyright (C) 1996-2000 Michael R. Elkins + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "config.h" +#include +#include "mutt/mutt.h" +#include "mutt.h" +#include "curs_lib.h" +#include "format_flags.h" +#include "keymap.h" +#include "menu.h" +#include "mutt_window.h" +#include "muttlib.h" +#include "opcodes.h" + +static const struct Mapping HistoryHelp[] = { + { N_("Exit"), OP_EXIT }, + { N_("Select"), OP_GENERIC_SELECT_ENTRY }, + { N_("Search"), OP_SEARCH }, + { N_("Help"), OP_HELP }, + { NULL, 0 }, +}; + +/** + * history_format_str - Format a string for the history list + * @param[out] buf Buffer in which to save string + * @param[in] buflen Buffer length + * @param[in] col Starting column + * @param[in] cols Number of screen columns + * @param[in] op printf-like operator, e.g. 't' + * @param[in] src printf-like format string + * @param[in] prec Field precision, e.g. "-3.4" + * @param[in] if_str If condition is met, display this string + * @param[in] else_str Otherwise, display this string + * @param[in] data Pointer to the mailbox Context + * @param[in] flags Format flags + * @retval src (unchanged) + * + * history_format_str() is a callback function for mutt_expando_format(). + * + * | Expando | Description + * |:--------|:-------------- + * | \%s | History match + */ +static const char *history_format_str(char *buf, size_t buflen, size_t col, int cols, + char op, const char *src, const char *prec, + const char *if_str, const char *else_str, + unsigned long data, enum FormatFlag flags) +{ + char *match = (char *) data; + + switch (op) + { + case 's': + mutt_format_s(buf, buflen, prec, match); + break; + } + + return src; +} + +/** + * history_entry - Format a menu item for the history list + * @param[out] buf Buffer in which to save string + * @param[in] buflen Buffer length + * @param[in] menu Menu containing aliases + * @param[in] num Index into the menu + */ +static void history_entry(char *buf, size_t buflen, struct Menu *menu, int num) +{ + char *entry = ((char **) menu->data)[num]; + + mutt_expando_format(buf, buflen, 0, MuttIndexWindow->cols, "%s", history_format_str, + (unsigned long) entry, MUTT_FORMAT_ARROWCURSOR); +} + +/** + * history_menu - Select an item from a history list + * @param buf Buffer in which to save string + * @param buflen Buffer length + * @param matches Items to choose from + * @param match_count Number of items + */ +static void history_menu(char *buf, size_t buflen, char **matches, int match_count) +{ + struct Menu *menu = NULL; + 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); +} + +/** + * mutt_hist_complete - Complete a string from a history list + * @param buf Buffer in which to save string + * @param buflen Buffer length + * @param hclass History list to use + */ +void mutt_hist_complete(char *buf, size_t buflen, enum HistoryClass hclass) +{ + char **matches = mutt_mem_calloc(History, sizeof(char *)); + int match_count = mutt_hist_search(buf, hclass, matches); + if (match_count) + { + if (match_count == 1) + mutt_str_strfcpy(buf, matches[0], buflen); + else + history_menu(buf, buflen, matches, match_count); + } + FREE(&matches); +} diff --git a/mutt_history.h b/mutt_history.h new file mode 100644 index 000000000..1ee781415 --- /dev/null +++ b/mutt_history.h @@ -0,0 +1,32 @@ +/** + * @file + * Read/write command history from/to a file + * + * @authors + * Copyright (C) 1996-2000 Michael R. Elkins + * + * @copyright + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 2 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef _MUTT_HISTORY2_H +#define _MUTT_HISTORY2_H + +#include +#include "mutt/mutt.h" + +void mutt_hist_complete(char *buf, size_t buflen, enum HistoryClass hclass); + +#endif /* _MUTT_HISTORY2_H */ +