/*
* 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 <h/mh.h>
#include <h/fmt_scan.h>
#include <h/scansbr.h>
#include <h/tws.h>
-#include <zotnet/mts/mts.h>
+#include <h/mts.h>
+#include <h/utils.h>
#include <errno.h>
-/*
- * 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 },
{ NULL, 0 }
};
-extern int errno;
/*
* global for sbr/formatsbr.c - yech!
{
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;
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++)) {
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++;
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"))
* 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");
* 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);
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 */
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:
if (clearflag)
clear_screen ();
- return done (0);
+ done (0);
+ return 1;
}