]> granicus.if.org Git - neomutt/commitdiff
split up history
authorRichard Russon <rich@flatcap.org>
Fri, 13 Jul 2018 16:11:33 +0000 (17:11 +0100)
committerRichard Russon <rich@flatcap.org>
Mon, 16 Jul 2018 22:44:16 +0000 (23:44 +0100)
Makefile.autosetup
enter.c
init.c
init.h
mutt/history.c [moved from history.c with 79% similarity]
mutt/history.h [moved from history.h with 91% similarity]
mutt/mutt.h
mutt_history.c [new file with mode: 0644]
mutt_history.h [new file with mode: 0644]

index 469963b3a82fcd51d5d9ffcb4d9c6bd20425d5a4..c64920a2a16bcb254503b9a78987ca353ee2c660 100644 (file)
@@ -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 3473ccce741164599cfc052c2cbc6adde78a5840..484034d1acd0dc100925c994e1a6f1249edf3742 100644 (file)
--- 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 9bcb72d4b3443045c039db454eb4b4bed9bf7c92..8e98a5e1185c7c59000f856faf8154139b4cfe7b 100644 (file)
--- a/init.c
+++ b/init.c
 #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 d055c710b654c1999755cba253b2dd8ea0545b83..18ba0e2fc3a6572d60c8079081abba70e0c48e27 100644 (file)
--- 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"
similarity index 79%
rename from history.c
rename to mutt/history.c
index dbb767877a61910f91e3f42e86f1f0969eaee1ec..49a89328ebb6dd1f259306889514ff39a664a954 100644 (file)
--- a/history.c
  */
 
 #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 */
@@ -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);
-}
similarity index 91%
rename from history.h
rename to mutt/history.h
index 6928d42fc2813749abefd1b24bee196c68a73408..ccb8e1d2db3dcdf93ef96c4f7f591266d0cc1733 100644 (file)
--- a/history.h
@@ -24,9 +24,8 @@
 #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;
@@ -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 */
+
index a054257f2f4c5f891cb665b1173c3056d68e6aa4..0b4ba11d84e44e78f259bb5a2b05228c97e16281 100644 (file)
@@ -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 (file)
index 0000000..55e1853
--- /dev/null
@@ -0,0 +1,157 @@
+/**
+ * @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);
+}
diff --git a/mutt_history.h b/mutt_history.h
new file mode 100644 (file)
index 0000000..1ee7814
--- /dev/null
@@ -0,0 +1,32 @@
+/**
+ * @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 */
+