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>
20 /* global vars used for the string-history routines */
28 static struct history History[HC_LAST];
29 static int OldSize = 0;
31 static void init_history (struct history *h)
37 for (i = 0; i < OldSize; i++)
38 p_delete(&h->hist[i]);
44 h->hist = p_new(char *, HistSize);
50 void mutt_init_history (void)
52 history_class_t hclass;
54 if (HistSize == OldSize)
57 for (hclass = HC_FIRST; hclass < HC_LAST; hclass++)
58 init_history (&History[hclass]);
63 void mutt_history_add (history_class_t hclass, const char *s)
66 struct history *h = &History[hclass];
69 return; /* disabled */
75 if (!h->hist[prev] || str_cmp (h->hist[prev], s) != 0) {
76 str_replace (&h->hist[h->last++], s);
77 if (h->last > HistSize - 1)
81 h->cur = h->last; /* reset to the last entry */
84 const char *mutt_history_next (history_class_t hclass)
87 struct history *h = &History[hclass];
90 return (""); /* disabled */
93 if (next > HistSize - 1)
95 h->cur = h->hist[next] ? next : 0;
96 return (h->hist[h->cur] ? h->hist[h->cur] : "");
99 const char *mutt_history_prev (history_class_t hclass)
102 struct history *h = &History[hclass];
105 return (""); /* disabled */
110 while (prev > 0 && h->hist[prev] == NULL)
115 return (h->hist[h->cur] ? h->hist[h->cur] : "");