X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=uip%2Fscan.c;h=08c893b33211b00b8660c1b2b1f336613017e465;hb=a59946091a8ee121ad89708efb0b719e0d1e179a;hp=7f5cf46ff2667d094389fe5f7a5d2aacbb4dc81a;hpb=017a82124bf2ea39ced5aa4c8f969c18b3c2fb90;p=mmh diff --git a/uip/scan.c b/uip/scan.c index 7f5cf46..08c893b 100644 --- a/uip/scan.c +++ b/uip/scan.c @@ -2,23 +2,19 @@ /* * 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 #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 +43,6 @@ static struct swit switches[] = { { NULL, 0 } }; -extern int errno; /* * global for sbr/formatsbr.c - yech! @@ -67,11 +62,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 +84,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++)) { @@ -112,10 +99,10 @@ main (int argc, char **argv) snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name); print_help (buf, switches, 1); - done (1); + done (0); case VERSIONSW: print_version(invo_name); - done (1); + done (0); case CLRSW: clearflag++; @@ -166,20 +153,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 +170,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"); @@ -208,11 +184,9 @@ main (int argc, char **argv) adios (file, "unable to open"); } -#ifndef JLR if (hdrflag) { printf ("FOLDER %s\t%s\n", file, dtimenow (1)); } -#endif /* JLR */ m_unknown (in); for (msgnum = 1; ; ++msgnum) { @@ -229,8 +203,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 +221,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 */ @@ -285,22 +259,13 @@ main (int argc, char **argv) msgnum += (revflag ? -1 : 1)) { if (is_selected(mp, msgnum)) { if ((in = fopen (cp = m_name (msgnum), "r")) == NULL) { -#if 0 - if (errno != EACCES) -#endif admonish (cp, "unable to open message"); -#if 0 - else - printf ("%*d unreadable\n", DMAXFOLDER, msgnum); -#endif continue; } -#ifndef JLR if (hdrflag) { printf ("FOLDER %s\t%s\n", folder, dtimenow(1)); } -#endif /* JLR */ /* * Check if message is in any sequence given @@ -316,7 +281,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: @@ -326,11 +291,7 @@ main (int argc, char **argv) adios (NULL, "scan() botch (%d)", state); case SCNEOF: -#if 0 - printf ("%*d empty\n", DMAXFOLDER, msgnum); -#else advise (NULL, "message %d: empty", msgnum); -#endif break; } hdrflag = 0; @@ -348,5 +309,6 @@ main (int argc, char **argv) if (clearflag) clear_screen (); - return done (0); + done (0); + return 1; }