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.
18 /* global vars used for the string-history routines */
26 static struct history History[HC_LAST];
27 static int OldSize = 0;
29 static void init_history (struct history *h)
35 for (i = 0; i < OldSize; i++)
42 h->hist = safe_calloc (HistSize, sizeof (char *));
48 void mutt_init_history (void)
50 history_class_t hclass;
52 if (HistSize == OldSize)
55 for (hclass = HC_FIRST; hclass < HC_LAST; hclass++)
56 init_history (&History[hclass]);
61 void mutt_history_add (history_class_t hclass, const char *s)
64 struct history *h = &History[hclass];
67 return; /* disabled */
73 if (!h->hist[prev] || mutt_strcmp (h->hist[prev], s) != 0) {
74 mutt_str_replace (&h->hist[h->last++], s);
75 if (h->last > HistSize - 1)
79 h->cur = h->last; /* reset to the last entry */
82 char *mutt_history_next (history_class_t hclass)
85 struct history *h = &History[hclass];
88 return (""); /* disabled */
91 if (next > HistSize - 1)
93 h->cur = h->hist[next] ? next : 0;
94 return (h->hist[h->cur] ? h->hist[h->cur] : "");
97 char *mutt_history_prev (history_class_t hclass)
100 struct history *h = &History[hclass];
103 return (""); /* disabled */
108 while (prev > 0 && h->hist[prev] == NULL)
113 return (h->hist[h->cur] ? h->hist[h->cur] : "");