X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fscan.c;h=31aa245f1cfd7670ae47265bdc0643579986af17;hp=cbd92773fe2d6f6452c69e6aa53574698669fe62;hb=d8916ff5d389de5ab225cd6f40aeda1b285d0f28;hpb=3c9700d8d045f3ff26ce5dd2a174454dafc14822 diff --git a/uip/scan.c b/uip/scan.c index cbd9277..31aa245 100644 --- a/uip/scan.c +++ b/uip/scan.c @@ -3,21 +3,20 @@ * 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 #include #include -#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 }, @@ -42,11 +41,10 @@ static struct swit switches[] = { #define VERSIONSW 10 { "version", 0 }, #define HELPSW 11 - { "help", 4 }, + { "help", 0 }, { NULL, 0 } }; -extern int errno; /* * global for sbr/formatsbr.c - yech! @@ -66,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; @@ -87,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++)) { @@ -165,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")) @@ -193,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"); @@ -228,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); @@ -246,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 */ @@ -315,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: @@ -347,5 +326,6 @@ main (int argc, char **argv) if (clearflag) clear_screen (); - return done (0); + done (0); + return 1; }