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.
10 #include <lib-ui/lib-ui.h>
15 /* global vars used for the string-history routines */
23 static struct history History[HC_LAST];
24 static int OldSize = 0;
26 static void init_history (struct history *h)
32 for (i = 0; i < OldSize; i++)
33 p_delete(&h->hist[i]);
39 h->hist = p_new(char *, HistSize);
45 void mutt_init_history (void)
47 history_class_t hclass;
49 if (HistSize == OldSize)
52 for (hclass = HC_FIRST; hclass < HC_LAST; hclass++)
53 init_history (&History[hclass]);
58 void mutt_history_add (history_class_t hclass, const char *s)
61 struct history *h = &History[hclass];
64 return; /* disabled */
70 if (!h->hist[prev] || m_strcmp(h->hist[prev], s) != 0) {
71 m_strreplace(&h->hist[h->last++], s);
72 if (h->last > HistSize - 1)
76 h->cur = h->last; /* reset to the last entry */
79 const char *mutt_history_next (history_class_t hclass)
82 struct history *h = &History[hclass];
85 return ""; /* disabled */
88 if (next > HistSize - 1)
90 h->cur = h->hist[next] ? next : 0;
91 return h->hist[h->cur] ? h->hist[h->cur] : "";
94 const char *mutt_history_prev (history_class_t hclass)
97 struct history *h = &History[hclass];
100 return ""; /* disabled */
105 while (prev > 0 && h->hist[prev] == NULL)
110 return h->hist[h->cur] ? h->hist[h->cur] : "";