2 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
26 /* global vars used for the string-history routines */
35 static struct history History[HC_LAST];
36 static int OldSize = 0;
38 static void init_history (struct history *h)
46 for (i = 0 ; i < OldSize ; i ++)
53 h->hist = safe_calloc (HistSize, sizeof (char *));
59 void mutt_init_history(void)
61 history_class_t hclass;
63 if (HistSize == OldSize)
66 for(hclass = HC_FIRST; hclass < HC_LAST; hclass++)
67 init_history(&History[hclass]);
72 void mutt_history_add (history_class_t hclass, const char *s)
75 struct history *h = &History[hclass];
78 return; /* disabled */
83 if (prev < 0) prev = HistSize - 1;
84 if (!h->hist[prev] || mutt_strcmp (h->hist[prev], s) != 0)
86 mutt_str_replace (&h->hist[h->last++], s);
87 if (h->last > HistSize - 1)
91 h->cur = h->last; /* reset to the last entry */
94 char *mutt_history_next (history_class_t hclass)
97 struct history *h = &History[hclass];
100 return (""); /* disabled */
103 if (next > HistSize - 1)
105 h->cur = h->hist[next] ? next : 0;
106 return (h->hist[h->cur] ? h->hist[h->cur] : "");
109 char *mutt_history_prev (history_class_t hclass)
112 struct history *h = &History[hclass];
115 return (""); /* disabled */
121 while (prev > 0 && h->hist[prev] == NULL)
126 return (h->hist[h->cur] ? h->hist[h->cur] : "");