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 \
# 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
#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"
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;
#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"
#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"
*/
#include "config.h"
-#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
-#include <unistd.h>
-#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 */
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];
}
/**
- * 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;
* 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);
-}
#define _MUTT_HISTORY_H
#include <stdbool.h>
-#include <stdio.h>
-/* 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;
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 */
+
* | 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 |
#include "exit.h"
#include "file.h"
#include "hash.h"
+#include "history.h"
#include "idna2.h"
#include "list.h"
#include "logging.h"
--- /dev/null
+/**
+ * @file
+ * Read/write command history from/to a file
+ *
+ * @authors
+ * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include <stdio.h>
+#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);
+}
--- /dev/null
+/**
+ * @file
+ * Read/write command history from/to a file
+ *
+ * @authors
+ * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _MUTT_HISTORY2_H
+#define _MUTT_HISTORY2_H
+
+#include <stdio.h>
+#include "mutt/mutt.h"
+
+void mutt_hist_complete(char *buf, size_t buflen, enum HistoryClass hclass);
+
+#endif /* _MUTT_HISTORY2_H */
+