X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=history.c;h=d61d0ceeabec5401239a3f8552639d1cd9880c3f;hp=ca3a2d7979c109323f5eb25881d8a481dc6160b6;hb=841a368ddea400022328f35dd8c7a3eb6f543892;hpb=6833ce8bdca2d64e14485118f2a4417b7e1cb1b1 diff --git a/history.c b/history.c index ca3a2d7..d61d0ce 100644 --- a/history.c +++ b/history.c @@ -1,32 +1,27 @@ /* + * Copyright notice from original mutt: * Copyright (C) 1996-2000 Michael R. Elkins - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + * + * This file is part of mutt-ng, see http://www.muttng.org/. + * It's licensed under the GNU General Public License, + * please see the file GPL in the top level source directory. + */ + +#if HAVE_CONFIG_H +# include "config.h" +#endif #include "mutt.h" #include "history.h" +#include "lib/mem.h" /* global vars used for the string-history routines */ -struct history -{ +struct history { char **hist; short cur; short last; -}; +}; static struct history History[HC_LAST]; static int OldSize = 0; @@ -35,65 +30,62 @@ static void init_history (struct history *h) { int i; - if(OldSize) - { - if (h->hist) - { - for (i = 0 ; i < OldSize ; i ++) - FREE (&h->hist[i]); - FREE (&h->hist); + if (OldSize) { + if (h->hist) { + for (i = 0; i < OldSize; i++) + mem_free (&h->hist[i]); + mem_free (&h->hist); } } - + if (HistSize) - h->hist = safe_calloc (HistSize, sizeof (char *)); - + h->hist = mem_calloc (HistSize, sizeof (char *)); + h->cur = 0; h->last = 0; } -void mutt_init_history(void) +void mutt_init_history (void) { history_class_t hclass; - + if (HistSize == OldSize) return; - - for(hclass = HC_FIRST; hclass < HC_LAST; hclass++) - init_history(&History[hclass]); + + for (hclass = HC_FIRST; hclass < HC_LAST; hclass++) + init_history (&History[hclass]); OldSize = HistSize; } - + void mutt_history_add (history_class_t hclass, const char *s) { int prev; struct history *h = &History[hclass]; - + if (!HistSize) - return; /* disabled */ + return; /* disabled */ - if (*s) - { + if (*s) { prev = h->last - 1; - if (prev < 0) prev = HistSize - 1; - if (!h->hist[prev] || mutt_strcmp (h->hist[prev], s) != 0) - { - mutt_str_replace (&h->hist[h->last++], s); + if (prev < 0) + prev = HistSize - 1; + if (!h->hist[prev] || str_cmp (h->hist[prev], s) != 0) { + str_replace (&h->hist[h->last++], s); if (h->last > HistSize - 1) - h->last = 0; + h->last = 0; } } - h->cur = h->last; /* reset to the last entry */ + h->cur = h->last; /* reset to the last entry */ } char *mutt_history_next (history_class_t hclass) { int next; struct history *h = &History[hclass]; - + if (!HistSize) - return (""); /* disabled */ + return (""); /* disabled */ next = h->cur + 1; if (next > HistSize - 1) @@ -108,11 +100,10 @@ char *mutt_history_prev (history_class_t hclass) struct history *h = &History[hclass]; if (!HistSize) - return (""); /* disabled */ + return (""); /* disabled */ prev = h->cur - 1; - if (prev < 0) - { + if (prev < 0) { prev = HistSize - 1; while (prev > 0 && h->hist[prev] == NULL) prev--;