char *add(char *, char *);
void create_folder(char *, int, void (*)());
int num_digits(int);
+
+struct msgs_array {
+ int max, size;
+ char **msgs;
+};
+
+void app_msgarg(struct msgs_array *, char *);
#include <errno.h>
/*
+ * We allocate space for messages (msgs array)
+ * this number of elements at a time.
+ */
+#define MAXMSGS 256
+
+/*
* Safely call malloc
*/
void *
return ndigits;
}
+
+/*
+ * Append a message arg to an array of them, resizing it if necessary.
+ * The function is written to suit the arg parsing code it was extracted
+ * from, and will probably be changed when the other code is cleaned up.
+ */
+void
+app_msgarg(struct msgs_array *msgs, char *cp)
+{
+ if(msgs->size >= msgs->max)
+ msgs->msgs = mh_xrealloc(msgs->msgs, (msgs->max+=MAXMSGS)*sizeof(*msgs->msgs));
+ msgs->msgs[msgs->size++] = cp;
+}
#include <h/mh.h>
#include <h/utils.h>
-/*
- * We allocate space for messages (msgs array)
- * this number of elements at a time.
- */
-#define MAXMSGS 256
-
-
static struct swit switches[] = {
#define COMPSW 0
{ "component field", 0 },
main (int argc, char **argv)
{
int inplace = 1, datesw = 1;
- int nummsgs, maxmsgs, msgnum;
+ int msgnum;
char *cp, *maildir, *comp = NULL;
char *text = NULL, *folder = NULL, buf[BUFSIZ];
- char **argp, **arguments, **msgs;
+ char **argp, **arguments;
+ struct msgs_array msgs = { 0, 0, NULL };
struct msgs *mp;
int append = 0; /* append annotations instead of default prepend */
int delete = -2; /* delete header element if set */
arguments = getarguments (invo_name, argc, argv, 1);
argp = arguments;
- /*
- * Allocate the initial space to record message
- * names and ranges.
- */
- nummsgs = 0;
- maxmsgs = MAXMSGS;
- msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs)));
-
while ((cp = *argp++)) {
if (*cp == '-') {
switch (smatch (++cp, switches)) {
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 name/ranges.
- */
- if (nummsgs >= maxmsgs) {
- maxmsgs += MAXMSGS;
- msgs = (char **) mh_xrealloc (msgs,
- (size_t) (maxmsgs * sizeof(*msgs)));
- }
- msgs[nummsgs++] = cp;
- }
+ } else
+ app_msgarg(&msgs, cp);
}
/*
*/
if (draft != (char *)0) {
- if (nummsgs != 0)
+ if (msgs.size != 0)
adios(NULL, "can only have message numbers or -draft.");
draft = getcpy(m_draft(folder, (char *)0, 1, &isdf));
if (!context_find ("path"))
free (path ("./", TFOLDER));
- if (!nummsgs)
- msgs[nummsgs++] = "cur";
+ if (!msgs.size)
+ app_msgarg(&msgs, "cur");
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);
make_comp (&comp);
#include <h/mh.h>
#include <h/utils.h>
-/*
- * We allocate space for messages (msgs array)
- * this number of elements at a time.
- */
-#define MAXMSGS 256
-
-
static struct swit switches[] = {
#define ADDSW 0
{ "add", 0 },
{
int addsw = 0, deletesw = 0, debugsw = 0;
int listsw = 0, publicsw = -1, zerosw = 0;
- int seqp = 0, msgnum, nummsgs, maxmsgs;
+ int seqp = 0, msgnum;
char *cp, *maildir, *folder = NULL, buf[BUFSIZ];
char **argp, **arguments;
- char *seqs[NUMATTRS + 1], **msgs;
+ char *seqs[NUMATTRS + 1];
+ struct msgs_array msgs = { 0, 0, NULL };
struct msgs *mp;
#ifdef LOCALE
argp = arguments;
/*
- * Allocate the initial space to record message
- * names, ranges, and sequences.
- */
- nummsgs = 0;
- maxmsgs = MAXMSGS;
- msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs)));
-
- /*
* Parse arguments
*/
while ((cp = *argp++)) {
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;
- msgs = (char **) mh_xrealloc (msgs,
- (size_t) (maxmsgs * sizeof(*msgs)));
- }
- msgs[nummsgs++] = cp;
- }
+ } else
+ app_msgarg(&msgs, cp);
}
/*
if (!context_find ("path"))
free (path ("./", TFOLDER));
- if (!nummsgs)
- msgs[nummsgs++] = listsw ? "all" :"cur";
+ if (!msgs.size)
+ app_msgarg(&msgs, listsw ? "all" :"cur");
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);
if (publicsw == 1 && is_readonly(mp))
# include <sys/wait.h>
#endif
-/*
- * We allocate space for message names (msgs array)
- * this number of elements at a time.
- */
-#define MAXMSGS 256
-
-
static struct swit switches[] = {
#define CHECKSW 0
{ "check", 0 },
main (int argc, char **argv)
{
int sizesw = 1, headsw = 1;
- int nummsgs, maxmsgs, msgnum, *icachesw;
+ int msgnum, *icachesw;
char *cp, *file = NULL, *folder = NULL;
char *maildir, buf[100], **argp;
- char **arguments, **msgs;
+ char **arguments;
+ struct msgs_array msgs = { 0, 0, NULL };
struct msgs *mp = NULL;
CT ct, *ctp;
argp = arguments;
/*
- * Allocate the initial space to record message
- * names, ranges, and sequences.
- */
- nummsgs = 0;
- maxmsgs = MAXMSGS;
- msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs)));
-
- /*
* Parse arguments
*/
while ((cp = *argp++)) {
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;
- msgs = (char **) mh_xrealloc (msgs,
- (size_t) (maxmsgs * sizeof(*msgs)));
- }
- msgs[nummsgs++] = cp;
- }
+ } else
+ app_msgarg(&msgs, cp);
}
/* null terminate the list of acceptable parts/types */
if (!context_find ("path"))
free (path ("./", TFOLDER));
- if (file && nummsgs)
+ if (file && msgs.size)
adios (NULL, "cannot specify msg and file at same time!");
/*
/*
* message(s) are coming from a folder
*/
- if (!nummsgs)
- msgs[nummsgs++] = "cur";
+ if (!msgs.size)
+ app_msgarg(&msgs, "cur");
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 */
# include <sys/wait.h>
#endif
-/*
- * We allocate space for message names (msgs array)
- * this number of elements at a time.
- */
-#define MAXMSGS 256
-
-
static struct swit switches[] = {
#define AUTOSW 0
{ "auto", 0 },
main (int argc, char **argv)
{
int sizesw = 1, headsw = 1;
- int nummsgs, maxmsgs, msgnum, *icachesw;
+ int msgnum, *icachesw;
char *cp, *file = NULL, *folder = NULL;
char *maildir, buf[100], **argp;
- char **arguments, **msgs;
+ char **arguments;
+ struct msgs_array msgs = { 0, 0, NULL };
struct msgs *mp = NULL;
CT ct, *ctp;
FILE *fp;
argp = arguments;
/*
- * Allocate the initial space to record message
- * names, ranges, and sequences.
- */
- nummsgs = 0;
- maxmsgs = MAXMSGS;
- msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs)));
-
- /*
* Parse arguments
*/
while ((cp = *argp++)) {
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;
- msgs = (char **) mh_xrealloc (msgs,
- (size_t) (maxmsgs * sizeof(*msgs)));
- }
- msgs[nummsgs++] = cp;
- }
+ } else
+ app_msgarg(&msgs, cp);
}
/* null terminate the list of acceptable parts/types */
if (showsw || storesw || cachesw)
adios (NULL, "cannot use -build with -show, -store, -cache");
- if (nummsgs < 1)
+ if (msgs.size < 1)
adios (NULL, "need to specify a %s composition file", invo_name);
- if (nummsgs > 1)
+ if (msgs.size > 1)
adios (NULL, "only one %s composition file at a time", invo_name);
vecp = 0;
else if (rfc934sw == -1)
vec[vecp++] = "-norfc934mode";
- vec[vecp++] = msgs[0];
+ vec[vecp++] = msgs.msgs[0];
vec[vecp] = NULL;
execvp ("mhbuild", vec);
/*
* Process a mhn composition file (old MH style)
*/
- if (nummsgs == 1 && !folder && !npart && !cachesw
+ if (msgs.size == 1 && !folder && !npart && !cachesw
&& !showsw && !storesw && !ntype && !file
&& (cp = getenv ("mhdraft"))
- && strcmp (cp, msgs[0]) == 0) {
+ && strcmp (cp, msgs.msgs[0]) == 0) {
char *vec[MAXARGS];
int vecp;
_exit (-1);
}
- if (file && nummsgs)
+ if (file && msgs.size)
adios (NULL, "cannot specify msg and file at same time!");
/*
/*
* message(s) are coming from a folder
*/
- if (!nummsgs)
- msgs[nummsgs++] = "cur";
+ if (!msgs.size)
+ app_msgarg(&msgs, "cur");
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 */
{ NULL, 0 }
};
-/*
- * Add space for message/sequence names
- * by MAXMSGS at a time.
- */
-#define MAXMSGS 256
-
-
int
main(int argc, char **argv)
{
- int i, maxmsgs, nummsgs;
+ int i;
char *cp, *maildir, *folder = NULL;
- char **argp, **msgs;
+ char **argp;
char **arguments, buf[BUFSIZ];
+ struct msgs_array msgs = { 0, 0, NULL };
struct msgs *mp;
#ifdef LOCALE
argp = arguments;
/*
- * Allocate initial space to record message
- * and sequence names
- */
- nummsgs = 0;
- maxmsgs = MAXMSGS;
- msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs)));
-
- /*
* Parse arguments
*/
while ((cp = *argp++)) {
adios (NULL, "only one folder at a time!");
else
folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
- } else {
- /*
- * if necessary, reallocate space for
- * message/sequence names
- */
- if (nummsgs >= maxmsgs) {
- maxmsgs += MAXMSGS;
- msgs = (char **) mh_xrealloc (msgs,
- (size_t) (maxmsgs * sizeof(*msgs)));
- }
- msgs[nummsgs++] = cp;
- }
+ } else
+ app_msgarg(&msgs, cp);
}
if (!context_find ("path"))
maildir = m_maildir (folder);
/* If no messages are given, print folder pathname */
- if (!nummsgs) {
+ if (!msgs.size) {
printf ("%s\n", maildir);
done (0);
}
mp->msgflags |= ALLOW_NEW; /* allow the "new" sequence */
/* parse all the message ranges/sequences and set SELECTED */
- for (i = 0; i < nummsgs; i++)
- if (!m_convert (mp, msgs[i]))
+ for (i = 0; i < msgs.size; i++)
+ if (!m_convert (mp, msgs.msgs[i]))
done (1);
seq_setprev (mp); /* set the previous-sequence */
# include <sys/wait.h>
#endif
-/*
- * We allocate space for message names (msgs array)
- * this number of elements at a time.
- */
-#define MAXMSGS 256
-
-
static struct swit switches[] = {
#define CHECKSW 0
{ "check", 0 },
int
main (int argc, char **argv)
{
- int nummsgs, maxmsgs, msgnum, *icachesw;
+ int msgnum, *icachesw;
char *cp, *file = NULL, *folder = NULL;
char *maildir, buf[100], **argp;
- char **arguments, **msgs;
+ char **arguments;
+ struct msgs_array msgs = { 0, 0, NULL };
struct msgs *mp = NULL;
CT ct, *ctp;
FILE *fp;
argp = arguments;
/*
- * Allocate the initial space to record message
- * names, ranges, and sequences.
- */
- nummsgs = 0;
- maxmsgs = MAXMSGS;
- msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs)));
-
- /*
* Parse arguments
*/
while ((cp = *argp++)) {
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;
- msgs = (char **) mh_xrealloc (msgs,
- (size_t) (maxmsgs * sizeof(*msgs)));
- }
- msgs[nummsgs++] = cp;
- }
+ } else
+ app_msgarg(&msgs, cp);
}
/* null terminate the list of acceptable parts/types */
if (!context_find ("path"))
free (path ("./", TFOLDER));
- if (file && nummsgs)
+ if (file && msgs.size)
adios (NULL, "cannot specify msg and file at same time!");
/*
/*
* message(s) are coming from a folder
*/
- if (!nummsgs)
- msgs[nummsgs++] = "cur";
+ if (!msgs.size)
+ app_msgarg(&msgs, "cur");
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);
/*
# include <sys/wait.h>
#endif
-/*
- * We allocate space for message names (msgs array)
- * this number of elements at a time.
- */
-#define MAXMSGS 256
-
-
static struct swit switches[] = {
#define AUTOSW 0
{ "auto", 0 },
int
main (int argc, char **argv)
{
- int nummsgs, maxmsgs, msgnum, *icachesw;
+ int msgnum, *icachesw;
char *cp, *file = NULL, *folder = NULL;
char *maildir, buf[100], **argp;
- char **arguments, **msgs;
+ char **arguments;
+ struct msgs_array msgs = { 0, 0, NULL };
struct msgs *mp = NULL;
CT ct, *ctp;
FILE *fp;
argp = arguments;
/*
- * Allocate the initial space to record message
- * names, ranges, and sequences.
- */
- nummsgs = 0;
- maxmsgs = MAXMSGS;
- msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs)));
-
- /*
* Parse arguments
*/
while ((cp = *argp++)) {
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;
- msgs = (char **) mh_xrealloc (msgs,
- (size_t) (maxmsgs * sizeof(*msgs)));
- }
- msgs[nummsgs++] = cp;
- }
+ } else
+ app_msgarg(&msgs, cp);
}
/* null terminate the list of acceptable parts/types */
if (!context_find ("path"))
free (path ("./", TFOLDER));
- if (file && nummsgs)
+ if (file && msgs.size)
adios (NULL, "cannot specify msg and file at same time!");
/*
/*
* message(s) are coming from a folder
*/
- if (!nummsgs)
- msgs[nummsgs++] = "cur";
+ if (!msgs.size)
+ app_msgarg(&msgs, "cur");
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 */
# include <sys/wait.h>
#endif
-/*
- * We allocate space for message names (msgs array)
- * this number of elements at a time.
- */
-#define MAXMSGS 256
-
-
static struct swit switches[] = {
#define CHECKSW 0
{ "check", 0 },
int
main (int argc, char **argv)
{
- int nummsgs, maxmsgs, msgnum, *icachesw;
+ int msgnum, *icachesw;
char *cp, *file = NULL, *folder = NULL;
char *maildir, buf[100], *outfile = NULL;
- char **argp, **arguments, **msgs;
+ char **argp, **arguments;
+ struct msgs_array msgs = { 0, 0, NULL };
struct msgs *mp = NULL;
CT ct, *ctp;
argp = arguments;
/*
- * Allocate the initial space to record message
- * names, ranges, and sequences.
- */
- nummsgs = 0;
- maxmsgs = MAXMSGS;
- msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs)));
-
- /*
* Parse arguments
*/
while ((cp = *argp++)) {
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;
- msgs = (char **) mh_xrealloc (msgs,
- (size_t) (maxmsgs * sizeof(*msgs)));
- }
- msgs[nummsgs++] = cp;
- }
+ } else
+ app_msgarg(&msgs, cp);
}
/* null terminate the list of acceptable parts/types */
if (!context_find ("path"))
free (path ("./", TFOLDER));
- if (file && nummsgs)
+ if (file && msgs.size)
adios (NULL, "cannot specify msg and file at same time!");
/*
/*
* message(s) are coming from a folder
*/
- if (!nummsgs)
- msgs[nummsgs++] = "cur";
+ if (!msgs.size)
+ app_msgarg(&msgs, "cur");
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 */
#include <h/utils.h>
#include <errno.h>
-/*
- * We allocate space for messages (msgs array)
- * this number of elements at a time.
- */
-#define MAXMSGS 256
-
-
static struct swit switches[] = {
#define FILESW 0
{ "file name", 0 },
int
main (int argc, char **argv)
{
- int nummsgs, maxmsgs, fd, msgnum;
+ int fd, msgnum;
char *cp, *maildir, *msgnam, *folder = NULL, buf[BUFSIZ];
- char **argp, **arguments, **msgs;
+ char **argp, **arguments;
+ struct msgs_array msgs = { 0, 0, NULL };
struct msgs *mp;
struct stat st;
arguments = getarguments (invo_name, argc, argv, 1);
argp = arguments;
- /* Allocate the initial space to record message
- * names and ranges.
- */
- nummsgs = 0;
- maxmsgs = MAXMSGS;
- msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs)));
-
/*
* Parse arguments
*/
if (folder)
adios (NULL, "only one folder at a time!");
folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
- } else {
- /*
- * Check if we need to allocate more space
- * for message name/ranges.
- */
- if (nummsgs >= maxmsgs) {
- maxmsgs += MAXMSGS;
- msgs = (char **) mh_xrealloc (msgs,
- (size_t) (maxmsgs * sizeof(*msgs)));
- }
- msgs[nummsgs++] = cp;
- }
+ } else
+ app_msgarg(&msgs, cp);
}
if (!file)
free (path ("./", TFOLDER));
/* default is to pack whole folder */
- if (!nummsgs)
- msgs[nummsgs++] = "all";
+ if (!msgs.size)
+ app_msgarg(&msgs, "all");
if (!folder)
folder = getfolder (1);
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 */
#include <h/picksbr.h>
#include <h/utils.h>
-/*
- * We allocate space for messages (msgs array)
- * this number of elements at a time.
- */
-#define MAXMSGS 256
-
-
static struct swit switches[] = {
#define ANDSW 0
{ "and", 0 },
main (int argc, char **argv)
{
int publicsw = -1, zerosw = 1, seqp = 0, vecp = 0;
- int nummsgs, maxmsgs, lo, hi, msgnum;
+ int lo, hi, msgnum;
char *maildir, *folder = NULL, buf[100];
char *cp, **argp, **arguments;
- char **msgs, *seqs[NUMATTRS + 1], *vec[MAXARGS];
+ char *seqs[NUMATTRS + 1], *vec[MAXARGS];
+ struct msgs_array msgs = { 0, 0, NULL };
struct msgs *mp;
register FILE *fp;
arguments = getarguments (invo_name, argc, argv, 1);
argp = arguments;
- /*
- * Allocate the initial space to record message
- * names, ranges, and sequences.
- */
- nummsgs = 0;
- maxmsgs = MAXMSGS;
- msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs)));
-
while ((cp = *argp++)) {
if (*cp == '-') {
if (*++cp == '-') {
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 name/ranges/sequences.
- */
- if (nummsgs >= maxmsgs) {
- maxmsgs += MAXMSGS;
- msgs = (char **) mh_xrealloc (msgs,
- (size_t) (maxmsgs * sizeof(*msgs)));
- }
- msgs[nummsgs++] = cp;
- }
+ } else
+ app_msgarg(&msgs, cp);
}
vec[vecp] = NULL;
* If we didn't specify which messages to search,
* then search the whole folder.
*/
- if (!nummsgs)
- msgs[nummsgs++] = "all";
+ if (!msgs.size)
+ app_msgarg(&msgs, "all");
if (!folder)
folder = getfolder (1);
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 */
#include <fcntl.h>
#include <errno.h>
-/*
- * We allocate spaces for messages (msgs array)
- * this number of elements at a time.
- */
-#define MAXMSGS 256
-
-
static struct swit switches[] = {
#define DRAFTSW 0
{ "draft", 0 },
{
int linkf = 0, preserve = 0, filep = 0;
int foldp = 0, isdf = 0, unlink_msgs = 0;
- int i, msgnum, nummsgs, maxmsgs;
+ int i, msgnum;
char *cp, *folder = NULL, buf[BUFSIZ];
- char **argp, **arguments, **msgs;
+ char **argp, **arguments;
char *filevec[NFOLDERS + 2];
char **files = &filevec[1]; /* leave room for remove_files:vec[0] */
struct st_fold folders[NFOLDERS + 1];
+ struct msgs_array msgs = { 0, 0, NULL };
struct msgs *mp;
#ifdef LOCALE
argp = arguments;
/*
- * Allocate the initial space to record message
- * names, ranges, and sequences.
- */
- nummsgs = 0;
- maxmsgs = MAXMSGS;
- msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs)));
-
- /*
* Parse arguments
*/
while ((cp = *argp++)) {
adios (NULL, "only %d folders allowed!", NFOLDERS);
folders[foldp++].f_name =
path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
- } else {
- /*
- * Check if we need to allocate more space
- * for message names, ranges, and sequences.
- */
- if (nummsgs >= maxmsgs) {
- maxmsgs += MAXMSGS;
- msgs = (char **) mh_xrealloc (msgs,
- (size_t) (maxmsgs * sizeof(*msgs)));
- }
- msgs[nummsgs++] = cp;
- }
+ } else
+ app_msgarg(&msgs, cp);
}
if (!context_find ("path"))
adios (NULL, "no folder specified");
#ifdef WHATNOW
- if (!nummsgs && !foldp && !filep && (cp = getenv ("mhdraft")) && *cp)
+ if (!msgs.size && !foldp && !filep && (cp = getenv ("mhdraft")) && *cp)
files[filep++] = cp;
#endif /* WHATNOW */
* We are refiling a file to the folders
*/
if (filep > 0) {
- if (folder || nummsgs)
+ if (folder || msgs.size)
adios (NULL, "use -file or some messages, not both");
opnfolds (folders, foldp);
for (i = 0; i < filep; i++)
done (0);
}
- if (!nummsgs)
- msgs[nummsgs++] = "cur";
+ if (!msgs.size)
+ app_msgarg(&msgs, "cur");
if (!folder)
folder = getfolder (1);
strncpy (maildir, m_maildir (folder), sizeof(maildir));
adios (NULL, "no messages in %s", folder);
/* parse the message range/sequence/name 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 */
#include <h/mh.h>
#include <h/utils.h>
-/*
- * We allocate space for message names and ranges
- * (msgs array) this number of elements at a time.
- */
-#define MAXMSGS 256
-
static struct swit switches[] = {
#define UNLINKSW 0
{ "unlink", 0 },
int
main (int argc, char **argv)
{
- int nummsgs, maxmsgs, msgnum, unlink_msgs = 0;
+ int msgnum, unlink_msgs = 0;
char *cp, *maildir, *folder = NULL;
char buf[BUFSIZ], **argp;
- char **arguments, **msgs;
+ char **arguments;
+ struct msgs_array msgs = { 0, 0, NULL };
struct msgs *mp;
#ifdef LOCALE
arguments = getarguments (invo_name, argc, argv, 1);
argp = arguments;
- /*
- * Allocate the initial space to record message
- * names and ranges.
- */
- nummsgs = 0;
- maxmsgs = MAXMSGS;
- msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs)));
-
/* parse arguments */
while ((cp = *argp++)) {
if (*cp == '-') {
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.
- */
- if (nummsgs >= maxmsgs){
- maxmsgs += MAXMSGS;
- msgs = (char **) mh_xrealloc (msgs,
- (size_t) (maxmsgs * sizeof(*msgs)));
- }
- msgs[nummsgs++] = cp;
- }
+ } else
+ app_msgarg(&msgs, cp);
}
if (!context_find ("path"))
free (path ("./", TFOLDER));
- if (!nummsgs)
- msgs[nummsgs++] = "cur";
+ if (!msgs.size)
+ app_msgarg(&msgs, "cur");
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 */
#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 },
{
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;
- msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs)));
-
- /*
* Parse arguments
*/
while ((cp = *argp++)) {
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;
- msgs = (char **) mh_xrealloc (msgs,
- (size_t) (maxmsgs * sizeof(*msgs)));
- }
- msgs[nummsgs++] = 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 */
#include <h/tws.h>
#include <h/utils.h>
-/*
- * We allocate space for messages (msgs array)
- * this number of elements at a time.
- */
-#define MAXMSGS 256
-
-
static struct swit switches[] = {
#define DATESW 0
{ "datefield field", 0 },
int
main (int argc, char **argv)
{
- int nummsgs, maxmsgs, i, msgnum;
+ int i, msgnum;
char *cp, *maildir, *datesw = NULL;
char *folder = NULL, buf[BUFSIZ], **argp;
- char **arguments, **msgs;
+ char **arguments;
+ struct msgs_array msgs = { 0, 0, NULL };
struct msgs *mp;
struct smsg **dlist;
argp = arguments;
/*
- * Allocate the initial space to record message
- * names and ranges.
- */
- nummsgs = 0;
- maxmsgs = MAXMSGS;
- msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs)));
-
- /*
* Parse arguments
*/
while ((cp = *argp++)) {
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.
- */
- if (nummsgs >= maxmsgs) {
- maxmsgs += MAXMSGS;
- msgs = (char **) mh_xrealloc (msgs,
- (size_t) (maxmsgs * sizeof(*msgs)));
- }
- msgs[nummsgs++] = cp;
- }
+ } else
+ app_msgarg(&msgs, cp);
}
if (!context_find ("path"))
free (path ("./", TFOLDER));
- if (!nummsgs)
- msgs[nummsgs++] = "all";
+ if (!msgs.size)
+ app_msgarg(&msgs, "all");
if (!datesw)
datesw = "date";
if (!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 */