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.
22 /* global vars used for the string-history routines */
31 static struct history History[HC_LAST];
32 static int OldSize = 0;
34 static void init_history (struct history *h)
42 for (i = 0 ; i < OldSize ; i ++)
49 h->hist = safe_calloc (HistSize, sizeof (char *));
55 void mutt_init_history(void)
57 history_class_t hclass;
59 if (HistSize == OldSize)
62 for(hclass = HC_FIRST; hclass < HC_LAST; hclass++)
63 init_history(&History[hclass]);
68 void mutt_history_add (history_class_t hclass, const char *s)
71 struct history *h = &History[hclass];
74 return; /* disabled */
79 if (prev < 0) prev = HistSize - 1;
80 if (!h->hist[prev] || mutt_strcmp (h->hist[prev], s) != 0)
82 mutt_str_replace (&h->hist[h->last++], s);
83 if (h->last > HistSize - 1)
87 h->cur = h->last; /* reset to the last entry */
90 char *mutt_history_next (history_class_t hclass)
93 struct history *h = &History[hclass];
96 return (""); /* disabled */
99 if (next > HistSize - 1)
101 h->cur = h->hist[next] ? next : 0;
102 return (h->hist[h->cur] ? h->hist[h->cur] : "");
105 char *mutt_history_prev (history_class_t hclass)
108 struct history *h = &History[hclass];
111 return (""); /* disabled */
117 while (prev > 0 && h->hist[prev] == NULL)
122 return (h->hist[h->cur] ? h->hist[h->cur] : "");