X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fscan.c;h=31aa245f1cfd7670ae47265bdc0643579986af17;hp=56980e95b95a9dbd3cd7e0df3fa550714c7f8120;hb=d8916ff5d389de5ab225cd6f40aeda1b285d0f28;hpb=dee387b53ab0d42922f857b60d6f980c9e79d16f diff --git a/uip/scan.c b/uip/scan.c index 56980e9..31aa245 100644 --- a/uip/scan.c +++ b/uip/scan.c @@ -3,6 +3,10 @@ * scan.c -- display a one-line "scan" listing of folder or messages * * $Id$ + * + * This code is Copyright (c) 2002, by the authors of nmh. See the + * COPYRIGHT file in the root directory of the nmh distribution for + * complete copyright information. */ #include @@ -10,15 +14,9 @@ #include #include #include +#include #include -/* - * We allocate space for message names (msgs array) - * this number of elements at a time. - */ -#define MAXMSGS 256 - - static struct swit switches[] = { #define CLRSW 0 { "clear", 0 }, @@ -47,7 +45,6 @@ static struct swit switches[] = { { NULL, 0 } }; -extern int errno; /* * global for sbr/formatsbr.c - yech! @@ -67,11 +64,12 @@ main (int argc, char **argv) { int clearflag = 0, hdrflag = 0, ontty; int width = 0, revflag = 0; - int i, state, msgnum, nummsgs, maxmsgs; + int i, state, msgnum; int seqnum[NUMATTRS], unseen, num_unseen_seq = 0; char *cp, *maildir, *file = NULL, *folder = NULL; char *form = NULL, *format = NULL, buf[BUFSIZ]; - char **argp, *nfs, **arguments, **msgs; + char **argp, *nfs, **arguments; + struct msgs_array msgs = { 0, 0, NULL }; struct msgs *mp; FILE *in; @@ -88,15 +86,6 @@ main (int argc, char **argv) argp = arguments; /* - * Allocate the initial space to record message - * names, ranges, and sequences. - */ - nummsgs = 0; - maxmsgs = MAXMSGS; - if (!(msgs = (char **) malloc ((size_t) (maxmsgs * sizeof(*msgs))))) - adios (NULL, "unable to allocate storage"); - - /* * Parse arguments */ while ((cp = *argp++)) { @@ -166,20 +155,9 @@ main (int argc, char **argv) if (folder) adios (NULL, "only one folder at a time!"); else - folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF); - } else { - /* - * Check if we need to allocate more space - * for message names/ranges/sequences. - */ - if (nummsgs >= maxmsgs) { - maxmsgs += MAXMSGS; - if (!(msgs = (char **) realloc (msgs, - (size_t) (maxmsgs * sizeof(*msgs))))) - adios (NULL, "unable to reallocate msgs storage"); - } - msgs[nummsgs++] = cp; - } + folder = pluspath (cp); + } else + app_msgarg(&msgs, cp); } if (!context_find ("path")) @@ -194,7 +172,7 @@ main (int argc, char **argv) * We are scanning a maildrop file */ if (file) { - if (nummsgs) + if (msgs.size) adios (NULL, "\"msgs\" not allowed with -file"); if (folder) adios (NULL, "\"+folder\" not allowed with -file"); @@ -229,8 +207,8 @@ main (int argc, char **argv) * We are scanning a folder */ - if (!nummsgs) - msgs[nummsgs++] = "all"; + if (!msgs.size) + app_msgarg(&msgs, "all"); if (!folder) folder = getfolder (1); maildir = m_maildir (folder); @@ -247,8 +225,8 @@ main (int argc, char **argv) adios (NULL, "no messages in %s", folder); /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < nummsgs; msgnum++) - if (!m_convert (mp, msgs[msgnum])) + for (msgnum = 0; msgnum < msgs.size; msgnum++) + if (!m_convert (mp, msgs.msgs[msgnum])) done(1); seq_setprev (mp); /* set the Previous-Sequence */ @@ -316,7 +294,7 @@ main (int argc, char **argv) switch (state = scan (in, msgnum, 0, nfs, width, msgnum == mp->curmsg, unseen, - hdrflag ? folder : NULL, 0L, 1)) { + folder, 0L, 1)) { case SCNMSG: case SCNENC: case SCNERR: @@ -348,5 +326,6 @@ main (int argc, char **argv) if (clearflag) clear_screen (); - return done (0); + done (0); + return 1; }