2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
5 * This file is part of mutt-ng, see http://www.muttng.org/.
6 * It's licensed under the GNU General Public License,
7 * please see the file GPL in the top level source directory.
14 #include <lib-lib/mem.h>
19 /* global vars used for the string-history routines */
27 static struct history History[HC_LAST];
28 static int OldSize = 0;
30 static void init_history (struct history *h)
36 for (i = 0; i < OldSize; i++)
37 p_delete(&h->hist[i]);
43 h->hist = p_new(char *, HistSize);
49 void mutt_init_history (void)
51 history_class_t hclass;
53 if (HistSize == OldSize)
56 for (hclass = HC_FIRST; hclass < HC_LAST; hclass++)
57 init_history (&History[hclass]);
62 void mutt_history_add (history_class_t hclass, const char *s)
65 struct history *h = &History[hclass];
68 return; /* disabled */
74 if (!h->hist[prev] || m_strcmp(h->hist[prev], s) != 0) {
75 m_strreplace(&h->hist[h->last++], s);
76 if (h->last > HistSize - 1)
80 h->cur = h->last; /* reset to the last entry */
83 const char *mutt_history_next (history_class_t hclass)
86 struct history *h = &History[hclass];
89 return (""); /* disabled */
92 if (next > HistSize - 1)
94 h->cur = h->hist[next] ? next : 0;
95 return (h->hist[h->cur] ? h->hist[h->cur] : "");
98 const char *mutt_history_prev (history_class_t hclass)
101 struct history *h = &History[hclass];
104 return (""); /* disabled */
109 while (prev > 0 && h->hist[prev] == NULL)
114 return (h->hist[h->cur] ? h->hist[h->cur] : "");