From 284454918cc95058b026d057195eaa5279135c36 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sat, 18 Nov 2006 18:10:36 +0100 Subject: [PATCH] drop the horrible list2_t for good. replace them with ad-hoc typed arrays since buffy quite need'em Signed-off-by: Pierre Habouzit --- Makefile.am | 7 ++- browser.c | 10 ++-- buffy.c | 89 ++++++++++++++++---------------- buffy.h | 5 +- configure.ac | 1 - copy.c | 10 ++-- imap/imap.c | 6 +-- lib-lib/Makefile.am | 6 +-- lib-lib/lib-lib.h | 3 +- lib-ui/sidebar.c | 46 ++++++++--------- lib/Makefile.am | 12 ----- lib/list.c | 122 -------------------------------------------- lib/list.h | 76 --------------------------- main.c | 2 +- mx.c | 6 +-- nntp/nntp.c | 4 +- 16 files changed, 96 insertions(+), 309 deletions(-) delete mode 100644 lib/Makefile.am delete mode 100644 lib/list.c delete mode 100644 lib/list.h diff --git a/Makefile.am b/Makefile.am index 6ee39c9..1b74d01 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,7 +10,7 @@ NNTP_INCLUDES = -I$(top_srcdir)/nntp endif SUBDIRS = intl m4 po $(XXXXXXXXXXXX_doc) contrib \ - lib-mime lib-lib lib-crypt lib-hash lib-sys lib-ui lib \ + lib-mime lib-lib lib-crypt lib-hash lib-sys lib-ui \ pop imap $(NNTP_SUBDIR) BUILT_SOURCES = keymap_defs.h version.h charset.gperf @@ -29,7 +29,7 @@ madmutt_LDADD = @MUTT_LIB_OBJECTS@ @LIBOBJS@ \ -Limap -limap -Lpop -lpop $(LIBNNTP) \ -Llib-lib -llib -Llib-mime -lmime -Llib-crypt -lcrypt -Llib-hash -lhash \ -Llib-sys -lsys -Llib-ui -lui \ - -Llib -lsane $(MUTTLIBS) $(INTLLIBS) $(LIBICONV) + $(MUTTLIBS) $(INTLLIBS) $(LIBICONV) madmutt_DEPENDENCIES = @MUTT_LIB_OBJECTS@ @LIBOBJS@ \ $(top_builddir)/lib-lib/liblib.a \ @@ -37,7 +37,6 @@ madmutt_DEPENDENCIES = @MUTT_LIB_OBJECTS@ @LIBOBJS@ \ $(top_builddir)/lib-crypt/libcrypt.a \ $(top_builddir)/lib-hash/libhash.a \ $(top_builddir)/lib-ui/libui.a \ - $(top_builddir)/lib/libsane.a \ \ $(top_builddir)/pop/libpop.a \ $(top_builddir)/imap/libimap.a \ @@ -77,7 +76,7 @@ madmutt_dotlock_DEPENDENCIES = @LIBOBJS@ $(top_builddir)/lib-lib/liblib.a pgpringng_SOURCES = pgppubring.c lib.c extlib.c pgpringng_LDADD = @LIBOBJS@ $(INTLLIBS) \ - -Llib-lib -llib -Llib-hash -lhash -Llib-crypt -lcrypt -Llib -lsane + -Llib-lib -llib -Llib-hash -lhash -Llib-crypt -lcrypt pgpringng_DEPENDENCIES = @LIBOBJS@ $(INTLDEPS) \ $(top_builddir)/lib-lib/liblib.a \ $(top_builddir)/lib-hash/libhash.a diff --git a/browser.c b/browser.c index 93a5d76..8ff73d8 100644 --- a/browser.c +++ b/browser.c @@ -533,9 +533,9 @@ static int examine_directory (MUTTMENU * menu, struct browser_state *state, i = buffy_lookup (buffer); #ifdef USE_NNTP - add_folder (menu, state, de->d_name, &s, NULL, i >= 0 ? ((BUFFY*) Incoming->data[i])->new : 0); + add_folder (menu, state, de->d_name, &s, NULL, i >= 0 ? Incoming.arr[i]->new : 0); #else - add_folder (menu, state, de->d_name, &s, i >= 0 ? ((BUFFY*) Incoming->data[i])->new : 0); + add_folder (menu, state, de->d_name, &s, i >= 0 ? Incoming.arr[i]->new : 0); #endif } closedir (dp); @@ -576,14 +576,14 @@ static int examine_mailboxes (MUTTMENU * menu, struct browser_state *state) int i = 0; BUFFY* tmp; - if (!Incoming) + if (!Incoming.len) return (-1); buffy_check (0); init_state (state, menu); - for (i = 0; i < Incoming->length; i++) { - tmp = (BUFFY*) Incoming->data[i]; + for (i = 0; i < Incoming.len; i++) { + tmp = Incoming.arr[i]; tmp->magic = mx_get_magic (tmp->path); if (tmp->magic == M_IMAP) { #ifdef USE_NNTP diff --git a/buffy.c b/buffy.c index 5fdf725..124ffff 100644 --- a/buffy.c +++ b/buffy.c @@ -30,21 +30,23 @@ static time_t ImapBuffyTime = 0; /* last time we started checking for mai static short BuffyCount = 0; /* how many boxes with new mail */ static short BuffyNotify = 0; /* # of unnotified new boxes */ -/* func to free buffy for list_del() */ -static inline void buffy_free (BUFFY** p) { - p_delete(&(*p)->path); - p_delete(p); +static inline void buffy_delete(BUFFY** p) +{ + p_delete(&(*p)->path); + p_delete(p); } +DO_ARRAY_FUNCS(BUFFY, buffy, buffy_delete); + /* Return the index number of path in Incoming list */ int buffy_lookup (const char* path) { int i = 0; - if (list_empty(Incoming) || !path || !*path) + if (!Incoming.len || !path || !*path) return (-1); - for (i = 0; i < Incoming->length; i++) { - if (!m_strcmp(((BUFFY *)Incoming->data[i])->path, path)) + for (i = 0; i < Incoming.len; i++) { + if (!m_strcmp(Incoming.arr[i]->path, path)) return (i); } @@ -63,7 +65,7 @@ int buffy_parse_mailboxes (BUFFER * path, BUFFER * s, unsigned long data, m_strcpy(buf, sizeof(buf), path->data); if (data == M_UNMAILBOXES && !strcmp(buf, "*")) { - list_del (&Incoming, (list_del_t*) buffy_free); + buffy_array_wipe(&Incoming); return 0; } @@ -75,10 +77,8 @@ int buffy_parse_mailboxes (BUFFER * path, BUFFER * s, unsigned long data, i = buffy_lookup (buf); if (data == M_UNMAILBOXES) { - if (i >= 0) { - tmp = (BUFFY*) list_pop_idx (Incoming, i); - buffy_free (&tmp); - } + tmp = buffy_array_take(&Incoming, i); + buffy_delete(&tmp); continue; } @@ -86,10 +86,11 @@ int buffy_parse_mailboxes (BUFFER * path, BUFFER * s, unsigned long data, tmp = p_new(BUFFY, 1); tmp->path = m_strdup(buf); tmp->magic = 0; - list_push_back (&Incoming, tmp); - i = Incoming->length-1; - } else - tmp = (BUFFY*) Incoming->data[i]; + buffy_array_append(&Incoming, tmp); + i = Incoming.len-1; + } else { + tmp = Incoming.arr[i]; + } tmp->new = 0; tmp->notified = 1; @@ -125,7 +126,7 @@ int buffy_check (int force) mutt_update_num_postponed (); /* fastest return if there are no mailboxes */ - if (list_empty(Incoming)) + if (!Incoming.len) return 0; now = time (NULL); if (force == 0 && (now - BuffyTime < BuffyTimeout) @@ -150,8 +151,8 @@ int buffy_check (int force) contex_sb.st_ino = 0; } - for (i = 0; i < Incoming->length; i++) { - tmp = (BUFFY*) Incoming->data[i]; + for (i = 0; i < Incoming.len; i++) { + tmp = Incoming.arr[i]; tmp->magic = mx_get_magic (tmp->path); local = mx_is_local (tmp->magic-1); if ((tmp->magic <= 0 || local) && (stat (tmp->path, &sb) != 0 || sb.st_size == 0)) { @@ -332,30 +333,29 @@ int buffy_list (void) first = 1; buffylist[0] = 0; pos += m_strlen(strncat (buffylist, _("New mail in "), sizeof (buffylist) - 1 - pos)); /* __STRNCAT_CHECKED__ */ - if (Incoming) { - for (i = 0; i < Incoming->length; i++) { - tmp = Incoming->data[i]; - /* Is there new mail in this mailbox? */ - if (tmp->new <= 0 || (have_unnotified && tmp->notified)) - continue; + for (i = 0; i < Incoming.len; i++) { + tmp = Incoming.arr[i]; + /* Is there new mail in this mailbox? */ + if (tmp->new <= 0 || (have_unnotified && tmp->notified)) + continue; - m_strcpy(path, sizeof(path), tmp->path); - mutt_pretty_mailbox (path); + m_strcpy(path, sizeof(path), tmp->path); + mutt_pretty_mailbox (path); - if (!first && pos + m_strlen(path) >= COLS - 7) - break; + if (!first && pos + m_strlen(path) >= COLS - 7) + break; - if (!first) - pos += m_strlen(strncat (buffylist + pos, ", ", sizeof (buffylist) - 1 - pos)); /* __STRNCAT_CHECKED__ */ + if (!first) + pos += m_strlen(strncat (buffylist + pos, ", ", sizeof (buffylist) - 1 - pos)); /* __STRNCAT_CHECKED__ */ - tmp->notified = 1; - BuffyNotify--; + tmp->notified = 1; + BuffyNotify--; - pos += m_strlen(strncat (buffylist + pos, path, sizeof (buffylist) - 1 - pos)); /* __STRNCAT_CHECKED__ */ - first = 0; - } + pos += m_strlen(strncat (buffylist + pos, path, sizeof (buffylist) - 1 - pos)); /* __STRNCAT_CHECKED__ */ + first = 0; } - if (!first && i < Incoming->length) { + + if (!first && i < Incoming.len) { strncat (buffylist + pos, ", ...", sizeof (buffylist) - 1 - pos); /* __STRNCAT_CHECKED__ */ } if (!first) { @@ -398,25 +398,24 @@ void buffy_next (char *s, size_t slen) /* * buffy_lookup returns the index, - * or -1 if not found (-1..Incoming->length-1); - * plus one --> (0..Incoming->length). + * or -1 if not found (-1..Incoming.len-1); + * plus one --> (0..Incoming.len). * Modulo mapps it into the correct range. */ i = 1 + buffy_lookup (s); - for (l = 0; l < Incoming->length; l++) { - c = (l+i) % Incoming->length; + for (l = 0; l < Incoming.len; l++) { + c = (l+i) % Incoming.len; - if (m_strcmp(((BUFFY*) Incoming->data[c])->path, s) && - ((BUFFY*) Incoming->data[c])->new > 0) + if (m_strcmp(Incoming.arr[c]->path, s) && Incoming.arr[c]->new > 0) break; } - if (l >= Incoming->length) { + if (l >= Incoming.len) { *s = '\0'; /* something went wrong since we're here when buffy_check * reported new mail */ buffy_check (1); } else { - m_strcpy(s, slen, ((BUFFY*)Incoming->data[c])->path); + m_strcpy(s, slen, Incoming.arr[c]->path); mutt_pretty_mailbox (s); } } diff --git a/buffy.h b/buffy.h index 1e1c55f..0662b94 100644 --- a/buffy.h +++ b/buffy.h @@ -9,8 +9,6 @@ #ifndef _BUFFY_H #define _BUFFY_H -#include "lib/list.h" - /*parameter to mutt_parse_mailboxes*/ #define M_MAILBOXES 1 #define M_UNMAILBOXES 2 @@ -26,9 +24,10 @@ typedef struct buffy_t { short magic; /* mailbox type */ short newly_created; /* mbox or mmdf just popped into existence */ } BUFFY; +DO_ARRAY_TYPE(BUFFY, buffy); /* folders with incomming mail (via mailboxes command) */ -WHERE list2_t* Incoming; +WHERE buffy_array Incoming; WHERE short BuffyTimeout INITVAL (3); extern time_t BuffyDoneTime; /* last time we knew for sure how much mail there was */ diff --git a/configure.ac b/configure.ac index 5da3b60..2b944ef 100644 --- a/configure.ac +++ b/configure.ac @@ -734,7 +734,6 @@ AC_OUTPUT(Makefile lib-hash/Makefile lib-sys/Makefile lib-ui/Makefile - lib/Makefile imap/Makefile pop/Makefile nntp/Makefile diff --git a/copy.c b/copy.c index 6df4003..8310f6f 100644 --- a/copy.c +++ b/copy.c @@ -33,7 +33,7 @@ mutt_copy_hdr (FILE* in, FILE* out, off_t off_start, off_t off_end, int this_is_from; int ignore = 0; char buf[STRING]; /* should be long enough to get most fields in one pass */ - char *nl; + char *eol; string_list_t *t; char **headers; int hdr_count; @@ -55,13 +55,13 @@ mutt_copy_hdr (FILE* in, FILE* out, off_t off_start, off_t off_end, * we can do a more efficient line to line copying */ while (ftello (in) < off_end) { - nl = strchr (buf, '\n'); + eol = strchr (buf, '\n'); if ((fgets (buf, sizeof (buf), in)) == NULL) break; /* Is it the begining of a header? */ - if (nl && buf[0] != ' ' && buf[0] != '\t') { + if (eol && buf[0] != ' ' && buf[0] != '\t') { ignore = 1; if (!from && m_strncmp("From ", buf, 5) == 0) { if ((flags & CH_FROM) == 0) @@ -116,14 +116,14 @@ mutt_copy_hdr (FILE* in, FILE* out, off_t off_start, off_t off_end, /* Read all the headers into the array */ while (ftello (in) < off_end) { - nl = strchr (buf, '\n'); + eol = strchr (buf, '\n'); /* Read a line */ if ((fgets (buf, sizeof (buf), in)) == NULL) break; /* Is it the begining of a header? */ - if (nl && buf[0] != ' ' && buf[0] != '\t') { + if (eol && buf[0] != ' ' && buf[0] != '\t') { /* set curline to 1 for To:/Cc:/Bcc: and 0 otherwise */ curline = (flags & CH_WEED) && (m_strncmp("To:", buf, 3) == 0 || diff --git a/imap/imap.c b/imap/imap.c index e426e33..fe99c06 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -1434,10 +1434,10 @@ static int imap_complete_hosts (char *dest, ssize_t len) { int i = 0; matchlen = m_strlen(dest); - if (list_empty (Incoming)) + if (!Incoming.len) return (-1); - for (i = 0; i < Incoming->length; i++) { - mailbox = (BUFFY*) Incoming->data[i]; + for (i = 0; i < Incoming.len; i++) { + mailbox = Incoming.arr[i]; if (!m_strncmp(dest, mailbox->path, matchlen)) { if (rc) { m_strcpy(dest, len, mailbox->path); diff --git a/lib-lib/Makefile.am b/lib-lib/Makefile.am index 17c2e93..28d0665 100644 --- a/lib-lib/Makefile.am +++ b/lib-lib/Makefile.am @@ -1,10 +1,10 @@ noinst_LIBRARIES = liblib.a liblib_a_SOURCES = lib-lib.h mem.h \ - str.h buffer.h hash.h list.h file.h mapping.h date.h rx.h url.h \ - str.c buffer.c hash.c list.c file.c mapping.c date.c rx.c url.c + str.h buffer.h hash.h array.h list.h file.h mapping.h date.h rx.h url.h \ + str.c buffer.c hash.c array.c list.c file.c mapping.c date.c rx.c url.c noinst_HEADERS = lib-lib.h mem.h \ - str.h buffer.h hash.h list.h file.h mapping.h date.h rx.h url.h + str.h buffer.h hash.h array.h list.h file.h mapping.h date.h rx.h url.h -include ../cflags.mk diff --git a/lib-lib/lib-lib.h b/lib-lib/lib-lib.h index 90cea2f..6aead29 100644 --- a/lib-lib/lib-lib.h +++ b/lib-lib/lib-lib.h @@ -102,8 +102,9 @@ /* }}} */ #include "mem.h" - #include "str.h" + +#include "array.h" #include "buffer.h" #include "date.h" #include "file.h" diff --git a/lib-ui/sidebar.c b/lib-ui/sidebar.c index a83505c..6668ca0 100644 --- a/lib-ui/sidebar.c +++ b/lib-ui/sidebar.c @@ -32,18 +32,18 @@ static short prev_show_value; /* computes first entry to be shown */ static void calc_boundaries (void) { - if (list_empty(Incoming)) + if (!Incoming.len) return; - if (CurBuffy < 0 || CurBuffy >= Incoming->length) + if (CurBuffy < 0 || CurBuffy >= Incoming.len) CurBuffy = 0; - if (TopBuffy < 0 || TopBuffy >= Incoming->length) + if (TopBuffy < 0 || TopBuffy >= Incoming.len) TopBuffy = 0; if (option (OPTSIDEBARNEWMAILONLY)) { int i = CurBuffy; TopBuffy = CurBuffy - 1; while (i >= 0) { - if (((BUFFY*) Incoming->data[i])->new > 0) + if (Incoming.arr[i]->new > 0) TopBuffy = i; i--; } @@ -97,7 +97,7 @@ static const char* sidebar_number_format (char* dest, ssize_t destlen, char op, const char* ifstr, const char* elstr, unsigned long data, format_flag flags) { char tmp[SHORT_STRING]; - BUFFY* b = (BUFFY*) Incoming->data[data]; + BUFFY* b = Incoming.arr[data]; int opt = flags & M_FORMAT_OPTIONAL; int c = Context && !m_strcmp(Context->path, b->path); @@ -194,7 +194,7 @@ static int make_sidebar_entry (char* sbox, int idx, ssize_t len) SidebarWidth = COLS; if (option (OPTSIDEBARNEWMAILONLY) && sbox && Context && Context->path && - m_strcmp(Context->path, sbox) && ((BUFFY*) Incoming->data[idx])->new == 0) + m_strcmp(Context->path, sbox) && Incoming.arr[idx]->new == 0) /* if $sidebar_newmail_only is set, don't display the * box only if it's not the currently opened * (i.e. always display the currently opened) */ @@ -239,9 +239,9 @@ static int make_sidebar_entry (char* sbox, int idx, ssize_t len) * selected folder for */ const char* sidebar_get_current (void) { - if (list_empty(Incoming)) + if (!Incoming.len) return (NULL); - return ((char*) ((BUFFY*) Incoming->data[CurBuffy])->path); + return Incoming.arr[CurBuffy]->path; } /* internally sets item to buf */ @@ -259,9 +259,9 @@ void sidebar_set_current (const char* buf) { void sidebar_set_buffystats (CONTEXT* curContext) { int i = 0; BUFFY* tmp = NULL; - if (!curContext || list_empty(Incoming) || (i = buffy_lookup (curContext->path)) < 0) + if (!curContext || !Incoming.len || (i = buffy_lookup (curContext->path)) < 0) return; - tmp = Incoming->data[i]; + tmp = Incoming.arr[i]; tmp->new = curContext->new; tmp->msg_unread = curContext->unread; tmp->msgcount = curContext->msgcount; @@ -357,12 +357,12 @@ int sidebar_draw (void) { sidebar_draw_frames(); - if (list_empty(Incoming)) + if (!Incoming.len) return 0; /* actually print items */ - for (i = TopBuffy, line=first_line; i < Incoming->length && line < last_line; i++) { - tmp = (BUFFY*) Incoming->data[i]; + for (i = TopBuffy, line=first_line; i < Incoming.len && line < last_line; i++) { + tmp = Incoming.arr[i]; if (i == CurBuffy) SETCOLOR (MT_COLOR_INDICATOR); @@ -391,11 +391,11 @@ int sidebar_draw (void) { /* returns index of new item with new mail or -1 */ static int exist_next_new () { int i = 0; - if (list_empty(Incoming)) + if (!Incoming.len) return (-1); i = CurBuffy + 1; - while (i < Incoming->length) - if (((BUFFY*) Incoming->data[i++])->new > 0) + while (i < Incoming.len) + if (Incoming.arr[i++]->new > 0) return (i-1); return (-1); } @@ -403,11 +403,11 @@ static int exist_next_new () { /* returns index of prev item with new mail or -1 */ static int exist_prev_new () { int i = 0; - if (list_empty(Incoming)) + if (!Incoming.len) return (-1); i = CurBuffy - 1; while (i >= 0) - if (((BUFFY*) Incoming->data[i--])->new > 0) + if (Incoming.arr[i--]->new > 0) return (i+1); return (-1); } @@ -415,13 +415,13 @@ static int exist_prev_new () { void sidebar_scroll (int op) { int i = 0; - if (!SidebarWidth || list_empty(Incoming)) + if (!SidebarWidth || !Incoming.len) return; switch (op) { case OP_SIDEBAR_NEXT: if (!option (OPTSIDEBARNEWMAILONLY)) { - if (CurBuffy + 1 == Incoming->length) { + if (CurBuffy + 1 == Incoming.len) { mutt_error (_("You are on the last mailbox.")); return; } @@ -464,13 +464,13 @@ void sidebar_scroll (int op) { CurBuffy = 0; break; case OP_SIDEBAR_SCROLL_DOWN: - if (CurBuffy + 1 == Incoming->length) { + if (CurBuffy + 1 == Incoming.len) { mutt_error (_("You are on the last mailbox.")); return; } CurBuffy += known_lines; - if (CurBuffy >= Incoming->length) - CurBuffy = Incoming->length - 1; + if (CurBuffy >= Incoming.len) + CurBuffy = Incoming.len - 1; break; default: return; diff --git a/lib/Makefile.am b/lib/Makefile.am deleted file mode 100644 index 8f21b15..0000000 --- a/lib/Makefile.am +++ /dev/null @@ -1,12 +0,0 @@ -## Process this file with automake to produce Makefile.in - -AR=@AR@ - -AUTOMAKE_OPTIONS = foreign - -noinst_LIBRARIES = libsane.a -noinst_HEADERS = list.h - -libsane_a_SOURCES = list.c list.h - --include ../cflags.mk diff --git a/lib/list.c b/lib/list.c deleted file mode 100644 index 0b852e0..0000000 --- a/lib/list.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * written for mutt-ng by: - * Rocco Rutte - * - * 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. - */ - -#include -#include "list.h" - -list2_t* list_new (void) { - return p_new(list2_t, 1); -} - -void list_del (list2_t** l, list_del_t* del) { - ssize_t i = 0; - if (!l || !*l) - return; - if (del) - for (i = 0; i < (*l)->length; i++) - del (&(*l)->data[i]); - p_delete(&(*l)->data); - p_delete(l); -} - -void list_push_back (list2_t** l, void* p) { - if (!*l) - *l = list_new (); - p_realloc(&(*l)->data, ++(*l)->length); - (*l)->data[(*l)->length-1] = p; -} - -void list_push_front (list2_t** l, void* p) { - if (!*l) - *l = list_new (); - p_realloc(&(*l)->data, ++(*l)->length); - if ((*l)->length > 1) - memmove (&(*l)->data[1], &(*l)->data[0], ((*l)->length-1)*sizeof(void*)); - (*l)->data[0] = p; -} - -void* list_pop_back (list2_t* l) { - void* p = NULL; - if (list_empty(l)) - return (NULL); - p = l->data[l->length-1]; - p_realloc(&l->data, --(l->length)); - return (p); -} - -void* list_pop_front (list2_t* l) { - void* p = NULL; - if (list_empty(l)) - return (NULL); - p = l->data[0]; - memmove (&l->data[0], &l->data[1], (--(l->length))*sizeof(void*)); - p_realloc(&l->data, l->length); - return (p); -} - -void* list_pop_idx (list2_t* l, int c) { - void* p = NULL; - if (list_empty(l) || c < 0 || c >= l->length) - return (NULL); - if (c == l->length-1) - return (list_pop_back (l)); - p = l->data[c]; - memmove (&l->data[c], &l->data[c+1], (l->length-c)*sizeof(void*)); - p_realloc(&l->data, --(l->length)); - return (p); -} - -list2_t *list_cpy(list2_t *l) { - list2_t* ret = NULL; - if (list_empty(l)) - return NULL; - ret = list_new(); - ret->length = l->length; - ret->data = p_dup(l->data, l->length); - return ret; -} - -list2_t* list_dup (list2_t* l, void* (*dup_f) (void*)) { - list2_t* ret = NULL; - int i = 0; - if (list_empty(l) || !*dup_f) - return (NULL); - ret = list_new (); - ret->length = l->length; - ret->data = p_new(void*, l->length); - for (i = 0; i < l->length; i++) - ret->data[i] = dup_f (l->data[i]); - return (ret); -} - -int list_lookup (list2_t* l, int (*cmp) (const void*, const void*), const void* p) { - int i = 0; - if (list_empty(l) || !*cmp) - return (-1); - for (i = 0; i < l->length; i++) - if (cmp (l->data[i], p) == 0) - return (i); - return (-1); -} - -list2_t* list_from_str (const char* str, const char* delim) { - list2_t* ret = NULL; - char* tmp = NULL, *p = NULL; - - if (!str || !*str || !delim || !*delim) - return (NULL); - - tmp = m_strdup(str); - for (p = strtok (tmp, delim); p; p = strtok (NULL, delim)) { - list_push_back (&ret, m_strdup(p)); - } - p_delete(&tmp); - return (ret); -} - diff --git a/lib/list.h b/lib/list.h deleted file mode 100644 index 3f701be..0000000 --- a/lib/list.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * written for mutt-ng by: - * Rocco Rutte - * - * 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. - */ - -/* - * this aims to provide a generic list - * implementation using arrays only - * mostly untested - */ - -#ifndef _LIB_LIST_H -#define _LIB_LIST_H - -typedef struct list2_t { - void** data; - ssize_t length; -} list2_t; - -/* - * basics - */ - -list2_t* list_new (void); - -typedef void list_del_t (void**); - -/* free() all memory used by list and optionally - * use del function to free() items as well */ -void list_del (list2_t**, list_del_t* del); - -#define list_empty(l) (!l || l->length == 0 || !l->data) - -/* - * insertion, removal - * the list_push_* functions create a list if empty so far - * for convenience - */ -void list_push_back (list2_t**, void*); -void list_push_front (list2_t**, void*); -void* list_pop_back (list2_t*); -void* list_pop_front (list2_t*); -void* list_pop_idx (list2_t*, int); - -/* - * copying - */ - -/* plain copy */ -list2_t* list_cpy (list2_t*); -/* "hard copy" using callback to copy items */ -list2_t* list_dup (list2_t*, void* (*dup) (void*)); - -/* - * misc - */ - -/* looks up item in list using callback function and comparison item - * return: - * -1 if not found - * index in data array otherwise - * the callback must return 0 on equality - */ -typedef int list_lookup_t (const void*, const void*); -int list_lookup (list2_t*, list_lookup_t* cmp, const void*); - -/* - * dumb-splits string at boundary characters into list - */ -list2_t* list_from_str (const char* str, const char* delim); - -#endif /* !_LIB_LIST_H */ diff --git a/main.c b/main.c index 7f5581a..ea0d55f 100644 --- a/main.c +++ b/main.c @@ -865,7 +865,7 @@ int main (int argc, char **argv) } else #endif - if (!Incoming) { + if (!Incoming.len) { mutt_endwin _("No incoming mailboxes defined."); exit (1); diff --git a/mx.c b/mx.c index 4eef63e..d1534ea 100644 --- a/mx.c +++ b/mx.c @@ -1352,13 +1352,13 @@ int mx_rebuild_cache (void) { CONTEXT* ctx = NULL; BUFFY* b = NULL; - if (list_empty(Incoming)) { + if (!Incoming.len) { mutt_error (_("No mailboxes defined.")); return (1); } - for (i = 0; i < Incoming->length; i++) { - b = (BUFFY*) Incoming->data[i]; + for (i = 0; i < Incoming.len; i++) { + b = Incoming.arr[i]; magic = mx_get_magic (b->path); if (magic != M_MAILDIR && magic != M_MH && magic != M_IMAP) continue; diff --git a/nntp/nntp.c b/nntp/nntp.c index a5deac1..32f40c6 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -33,7 +33,7 @@ void nntp_sync_sidebar (NNTP_DATA* data) { BUFFY* tmp = NULL; char buf[STRING]; - if (list_empty (Incoming)) + if (!Incoming.len) return; /* unfortunately, NNTP_DATA::group only is the plain @@ -54,7 +54,7 @@ void nntp_sync_sidebar (NNTP_DATA* data) { if ((i = buffy_lookup (buf)) < 0) return; - tmp = (BUFFY*) Incoming->data[i]; + tmp = Incoming.arr[i]; /* copied from browser.c */ if (option (OPTMARKOLD) && data->lastCached >= data->firstMessage && -- 2.20.1