Created app_msgarg() (append message arg) and a simple resizable array
authorJoel Reicher <jjr@panacea.null.org>
Tue, 11 Apr 2006 14:09:11 +0000 (14:09 +0000)
committerJoel Reicher <jjr@panacea.null.org>
Tue, 11 Apr 2006 14:09:11 +0000 (14:09 +0000)
struct to go with it that do almost exactly what the code they've replaced
was doing.
Replaced this (duplicated) code in many files with a call to app_msgarg().

16 files changed:
h/utils.h
sbr/utils.c
uip/anno.c
uip/mark.c
uip/mhlist.c
uip/mhn.c
uip/mhpath.c
uip/mhshow.c
uip/mhstore.c
uip/mhtest.c
uip/packf.c
uip/pick.c
uip/refile.c
uip/rmm.c
uip/scan.c
uip/sortm.c

index 8246a5d..3eda9d3 100644 (file)
--- a/h/utils.h
+++ b/h/utils.h
@@ -11,3 +11,10 @@ char *pwd(void);
 char *add(char *, char *);
 void create_folder(char *, int, void (*)());
 int num_digits(int);
 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 *);
index c433e8f..8aba5b6 100644 (file)
 #include <errno.h>
 
 /*
 #include <errno.h>
 
 /*
+ * We allocate space for messages (msgs array)
+ * this number of elements at a time.
+ */
+#define MAXMSGS 256
+
+/*
  * Safely call malloc
  */
 void *
  * Safely call malloc
  */
 void *
@@ -165,3 +171,16 @@ num_digits (int n)
 
     return ndigits;
 }
 
     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;
+}
index 9fbb37f..0d44134 100644 (file)
 #include <h/mh.h>
 #include <h/utils.h>
 
 #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 },
 static struct swit switches[] = {
 #define        COMPSW  0
     { "component field", 0 },
@@ -99,10 +92,11 @@ int
 main (int argc, char **argv)
 {
     int inplace = 1, datesw = 1;
 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 *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 */
     struct msgs *mp;
     int                append = 0;             /* append annotations instead of default prepend */
     int                delete = -2;            /* delete header element if set */
@@ -122,14 +116,6 @@ main (int argc, char **argv)
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
     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)) {
     while ((cp = *argp++)) {
        if (*cp == '-') {
            switch (smatch (++cp, switches)) {
@@ -226,18 +212,8 @@ main (int argc, char **argv)
                adios (NULL, "only one folder at a time!");
            else
                folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
                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);
     }
 
     /*
     }
 
     /*
@@ -247,7 +223,7 @@ main (int argc, char **argv)
      */
 
     if (draft != (char *)0) {
      */
 
     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));
            adios(NULL, "can only have message numbers or -draft.");
 
        draft = getcpy(m_draft(folder, (char *)0, 1, &isdf));
@@ -269,8 +245,8 @@ main (int argc, char **argv)
 
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
     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);
     if (!folder)
        folder = getfolder (1);
     maildir = m_maildir (folder);
@@ -287,8 +263,8 @@ main (int argc, char **argv)
        adios (NULL, "no messages in %s", folder);
 
     /* parse all the message ranges/sequences and set SELECTED */
        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);
            done (1);
 
     make_comp (&comp);
index 0333722..e26ca6a 100644 (file)
 #include <h/mh.h>
 #include <h/utils.h>
 
 #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 },
 static struct swit switches[] = {
 #define        ADDSW               0
     { "add", 0 },
@@ -59,10 +52,11 @@ main (int argc, char **argv)
 {
     int addsw = 0, deletesw = 0, debugsw = 0;
     int listsw = 0, publicsw = -1, zerosw = 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 *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
     struct msgs *mp;
 
 #ifdef LOCALE
@@ -77,14 +71,6 @@ main (int argc, char **argv)
     argp = arguments;
 
     /*
     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++)) {
      * Parse arguments
      */
     while ((cp = *argp++)) {
@@ -152,18 +138,8 @@ main (int argc, char **argv)
                adios (NULL, "only one folder at a time!");
            else
                folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
                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);
     }
 
     /*
     }
 
     /*
@@ -180,8 +156,8 @@ main (int argc, char **argv)
 
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
     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);
     if (!folder)
        folder = getfolder (1);
     maildir = m_maildir (folder);
@@ -202,8 +178,8 @@ main (int argc, char **argv)
        adios (NULL, "no messages in %s", folder);
 
     /* parse all the message ranges/sequences and set SELECTED */
        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))
            done (1);
 
     if (publicsw == 1 && is_readonly(mp))
index 03480b3..b130cf1 100644 (file)
 # include <sys/wait.h>
 #endif
 
 # 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 },
 static struct swit switches[] = {
 #define        CHECKSW                 0
     { "check", 0 },
@@ -130,10 +123,11 @@ int
 main (int argc, char **argv)
 {
     int sizesw = 1, headsw = 1;
 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 *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;
 
     struct msgs *mp = NULL;
     CT ct, *ctp;
 
@@ -149,14 +143,6 @@ main (int argc, char **argv)
     argp = arguments;
 
     /*
     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++)) {
      * Parse arguments
      */
     while ((cp = *argp++)) {
@@ -257,18 +243,8 @@ do_cache:
                adios (NULL, "only one folder at a time!");
            else
                folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
                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 */
     }
 
     /* null terminate the list of acceptable parts/types */
@@ -299,7 +275,7 @@ do_cache:
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
-    if (file && nummsgs)
+    if (file && msgs.size)
        adios (NULL, "cannot specify msg and file at same time!");
 
     /*
        adios (NULL, "cannot specify msg and file at same time!");
 
     /*
@@ -316,8 +292,8 @@ do_cache:
        /*
         * message(s) are coming from a folder
         */
        /*
         * 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);
        if (!folder)
            folder = getfolder (1);
        maildir = m_maildir (folder);
@@ -334,8 +310,8 @@ do_cache:
            adios (NULL, "no messages in %s", folder);
 
        /* parse all the message ranges/sequences and set SELECTED */
            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 */
 
                done (1);
        seq_setprev (mp);       /* set the previous-sequence */
 
index 685a74e..cfeac94 100644 (file)
--- a/uip/mhn.c
+++ b/uip/mhn.c
 # include <sys/wait.h>
 #endif
 
 # 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 },
 static struct swit switches[] = {
 #define        AUTOSW                  0
     { "auto", 0 },
@@ -218,10 +211,11 @@ int
 main (int argc, char **argv)
 {
     int sizesw = 1, headsw = 1;
 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 *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;
     struct msgs *mp = NULL;
     CT ct, *ctp;
     FILE *fp;
@@ -238,14 +232,6 @@ main (int argc, char **argv)
     argp = arguments;
 
     /*
     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++)) {
      * Parse arguments
      */
     while ((cp = *argp++)) {
@@ -442,18 +428,8 @@ do_cache:
                adios (NULL, "only one folder at a time!");
            else
                folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
                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 */
     }
 
     /* null terminate the list of acceptable parts/types */
@@ -524,9 +500,9 @@ do_cache:
 
        if (showsw || storesw || cachesw)
            adios (NULL, "cannot use -build with -show, -store, -cache");
 
        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);
            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;
            adios (NULL, "only one %s composition file at a time", invo_name);
 
        vecp = 0;
@@ -542,7 +518,7 @@ do_cache:
        else if (rfc934sw == -1)
            vec[vecp++] = "-norfc934mode";
 
        else if (rfc934sw == -1)
            vec[vecp++] = "-norfc934mode";
 
-       vec[vecp++] = msgs[0];
+       vec[vecp++] = msgs.msgs[0];
        vec[vecp] = NULL;
 
        execvp ("mhbuild", vec);
        vec[vecp] = NULL;
 
        execvp ("mhbuild", vec);
@@ -553,10 +529,10 @@ do_cache:
     /*
      * Process a mhn composition file (old MH style)
      */
     /*
      * 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"))
        && !showsw && !storesw && !ntype && !file
        && (cp = getenv ("mhdraft"))
-       && strcmp (cp, msgs[0]) == 0) {
+       && strcmp (cp, msgs.msgs[0]) == 0) {
 
        char *vec[MAXARGS];
        int vecp;
 
        char *vec[MAXARGS];
        int vecp;
@@ -582,7 +558,7 @@ do_cache:
        _exit (-1);
     }
 
        _exit (-1);
     }
 
-    if (file && nummsgs)
+    if (file && msgs.size)
        adios (NULL, "cannot specify msg and file at same time!");
 
     /*
        adios (NULL, "cannot specify msg and file at same time!");
 
     /*
@@ -599,8 +575,8 @@ do_cache:
        /*
         * message(s) are coming from a folder
         */
        /*
         * 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);
        if (!folder)
            folder = getfolder (1);
        maildir = m_maildir (folder);
@@ -617,8 +593,8 @@ do_cache:
            adios (NULL, "no messages in %s", folder);
 
        /* parse all the message ranges/sequences and set SELECTED */
            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 */
 
                done (1);
        seq_setprev (mp);       /* set the previous-sequence */
 
index 4a88605..00983d5 100644 (file)
@@ -20,20 +20,14 @@ static struct swit switches[] = {
     { NULL, 0 }
 };
 
     { NULL, 0 }
 };
 
-/*
- * Add space for message/sequence names
- * by MAXMSGS at a time.
- */
-#define MAXMSGS 256
-
-
 int
 main(int argc, char **argv)
 {
 int
 main(int argc, char **argv)
 {
-    int i, maxmsgs, nummsgs;
+    int i;
     char *cp, *maildir, *folder = NULL;
     char *cp, *maildir, *folder = NULL;
-    char **argp, **msgs;
+    char **argp;
     char **arguments, buf[BUFSIZ];
     char **arguments, buf[BUFSIZ];
+    struct msgs_array msgs = { 0, 0, NULL };
     struct msgs *mp;
 
 #ifdef LOCALE
     struct msgs *mp;
 
 #ifdef LOCALE
@@ -48,14 +42,6 @@ main(int argc, char **argv)
     argp = arguments;
 
     /*
     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++)) {
      * Parse arguments
      */
     while ((cp = *argp++)) {
@@ -82,18 +68,8 @@ main(int argc, char **argv)
                adios (NULL, "only one folder at a time!");
            else
                folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
                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"))
     }
 
     if (!context_find ("path"))
@@ -104,7 +80,7 @@ main(int argc, char **argv)
     maildir = m_maildir (folder);
 
     /* If no messages are given, print folder pathname */
     maildir = m_maildir (folder);
 
     /* If no messages are given, print folder pathname */
-    if (!nummsgs) {
+    if (!msgs.size) {
        printf ("%s\n", maildir);
        done (0);
     }
        printf ("%s\n", maildir);
        done (0);
     }
@@ -133,8 +109,8 @@ main(int argc, char **argv)
     mp->msgflags |= ALLOW_NEW; /* allow the "new" sequence */
 
     /* parse all the message ranges/sequences and set SELECTED */
     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 */
            done (1);
 
     seq_setprev (mp);  /* set the previous-sequence */
index 909c440..df4cf51 100644 (file)
 # include <sys/wait.h>
 #endif
 
 # 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 },
 static struct swit switches[] = {
 #define        CHECKSW                 0
     { "check", 0 },
@@ -145,10 +138,11 @@ static RETSIGTYPE pipeser (int);
 int
 main (int argc, char **argv)
 {
 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 *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;
     struct msgs *mp = NULL;
     CT ct, *ctp;
     FILE *fp;
@@ -165,14 +159,6 @@ main (int argc, char **argv)
     argp = arguments;
 
     /*
     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++)) {
      * Parse arguments
      */
     while ((cp = *argp++)) {
@@ -298,18 +284,8 @@ do_cache:
                adios (NULL, "only one folder at a time!");
            else
                folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
                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 */
     }
 
     /* null terminate the list of acceptable parts/types */
@@ -365,7 +341,7 @@ do_cache:
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
-    if (file && nummsgs)
+    if (file && msgs.size)
        adios (NULL, "cannot specify msg and file at same time!");
 
     /*
        adios (NULL, "cannot specify msg and file at same time!");
 
     /*
@@ -382,8 +358,8 @@ do_cache:
        /*
         * message(s) are coming from a folder
         */
        /*
         * 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);
        if (!folder)
            folder = getfolder (1);
        maildir = m_maildir (folder);
@@ -400,8 +376,8 @@ do_cache:
            adios (NULL, "no messages in %s", folder);
 
        /* parse all the message ranges/sequences and set SELECTED */
            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);
 
        /*
                done (1);
 
        /*
index b756956..08891f5 100644 (file)
 # include <sys/wait.h>
 #endif
 
 # 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 },
 static struct swit switches[] = {
 #define        AUTOSW                  0
     { "auto", 0 },
@@ -123,10 +116,11 @@ static RETSIGTYPE pipeser (int);
 int
 main (int argc, char **argv)
 {
 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 *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;
     struct msgs *mp = NULL;
     CT ct, *ctp;
     FILE *fp;
@@ -143,14 +137,6 @@ main (int argc, char **argv)
     argp = arguments;
 
     /*
     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++)) {
      * Parse arguments
      */
     while ((cp = *argp++)) {
@@ -244,18 +230,8 @@ do_cache:
                adios (NULL, "only one folder at a time!");
            else
                folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
                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 */
     }
 
     /* null terminate the list of acceptable parts/types */
@@ -311,7 +287,7 @@ do_cache:
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
-    if (file && nummsgs)
+    if (file && msgs.size)
        adios (NULL, "cannot specify msg and file at same time!");
 
     /*
        adios (NULL, "cannot specify msg and file at same time!");
 
     /*
@@ -328,8 +304,8 @@ do_cache:
        /*
         * message(s) are coming from a folder
         */
        /*
         * 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);
        if (!folder)
            folder = getfolder (1);
        maildir = m_maildir (folder);
@@ -346,8 +322,8 @@ do_cache:
            adios (NULL, "no messages in %s", folder);
 
        /* parse all the message ranges/sequences and set SELECTED */
            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 */
 
                done (1);
        seq_setprev (mp);       /* set the previous-sequence */
 
index 298ef03..140c7d9 100644 (file)
 # include <sys/wait.h>
 #endif
 
 # 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 },
 static struct swit switches[] = {
 #define        CHECKSW                 0
     { "check", 0 },
@@ -126,10 +119,11 @@ static RETSIGTYPE pipeser (int);
 int
 main (int argc, char **argv)
 {
 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 *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;
 
     struct msgs *mp = NULL;
     CT ct, *ctp;
 
@@ -145,14 +139,6 @@ main (int argc, char **argv)
     argp = arguments;
 
     /*
     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++)) {
      * Parse arguments
      */
     while ((cp = *argp++)) {
@@ -245,18 +231,8 @@ do_cache:
                adios (NULL, "only one folder at a time!");
            else
                folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
                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 */
     }
 
     /* null terminate the list of acceptable parts/types */
@@ -290,7 +266,7 @@ do_cache:
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
-    if (file && nummsgs)
+    if (file && msgs.size)
        adios (NULL, "cannot specify msg and file at same time!");
 
     /*
        adios (NULL, "cannot specify msg and file at same time!");
 
     /*
@@ -307,8 +283,8 @@ do_cache:
        /*
         * message(s) are coming from a folder
         */
        /*
         * 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);
        if (!folder)
            folder = getfolder (1);
        maildir = m_maildir (folder);
@@ -325,8 +301,8 @@ do_cache:
            adios (NULL, "no messages in %s", folder);
 
        /* parse all the message ranges/sequences and set SELECTED */
            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 */
 
                done (1);
        seq_setprev (mp);       /* set the previous-sequence */
 
index 6f3638c..e074505 100644 (file)
 #include <h/utils.h>
 #include <errno.h>
 
 #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 },
 static struct swit switches[] = {
 #define FILESW         0
     { "file name", 0 },
@@ -46,9 +39,10 @@ char *file = NULL;
 int
 main (int argc, char **argv)
 {
 int
 main (int argc, char **argv)
 {
-    int nummsgs, maxmsgs, fd, msgnum;
+    int fd, msgnum;
     char *cp, *maildir, *msgnam, *folder = NULL, buf[BUFSIZ];
     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;
 
     struct msgs *mp;
     struct stat st;
 
@@ -63,13 +57,6 @@ main (int argc, char **argv)
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
     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
      */
     /*
      * Parse arguments
      */
@@ -112,18 +99,8 @@ main (int argc, char **argv)
            if (folder)
                adios (NULL, "only one folder at a time!");
            folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
            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)
     }
 
     if (!file)
@@ -147,8 +124,8 @@ main (int argc, char **argv)
        free (path ("./", TFOLDER));
 
     /* default is to pack whole folder */
        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);
 
     if (!folder)
        folder = getfolder (1);
@@ -166,8 +143,8 @@ main (int argc, char **argv)
        adios (NULL, "no messages in %s", folder);
 
     /* parse all the message ranges/sequences and set SELECTED */
        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 */
 
            done (1);
     seq_setprev (mp);  /* set the previous-sequence */
 
index 8cdfa58..8fd294e 100644 (file)
 #include <h/picksbr.h>
 #include <h/utils.h>
 
 #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 },
 static struct swit switches[] = {
 #define        ANDSW                   0
     { "and", 0 },
@@ -80,10 +73,11 @@ int
 main (int argc, char **argv)
 {
     int publicsw = -1, zerosw = 1, seqp = 0, vecp = 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 *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;
 
     struct msgs *mp;
     register FILE *fp;
 
@@ -98,14 +92,6 @@ main (int argc, char **argv)
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
     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 == '-') {
     while ((cp = *argp++)) {
        if (*cp == '-') {
            if (*++cp == '-') {
@@ -192,18 +178,8 @@ main (int argc, char **argv)
                adios (NULL, "only one folder at a time!");
            else
                folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
                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;
 
     }
     vec[vecp] = NULL;
 
@@ -214,8 +190,8 @@ main (int argc, char **argv)
      * If we didn't specify which messages to search,
      * then search the whole folder.
      */
      * 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);
 
     if (!folder)
        folder = getfolder (1);
@@ -233,8 +209,8 @@ main (int argc, char **argv)
        adios (NULL, "no messages in %s", folder);
 
     /* parse all the message ranges/sequences and set SELECTED */
        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 */
 
            done (1);
     seq_setprev (mp);  /* set the previous-sequence */
 
index bb7f00a..acafbf4 100644 (file)
 #include <fcntl.h>
 #include <errno.h>
 
 #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 },
 static struct swit switches[] = {
 #define        DRAFTSW          0
     { "draft", 0 },
@@ -73,12 +66,13 @@ main (int argc, char **argv)
 {
     int        linkf = 0, preserve = 0, filep = 0;
     int foldp = 0, isdf = 0, unlink_msgs = 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 *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];
     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
     struct msgs *mp;
 
 #ifdef LOCALE
@@ -93,14 +87,6 @@ main (int argc, char **argv)
     argp = arguments;
 
     /*
     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++)) {
      * Parse arguments
      */
     while ((cp = *argp++)) {
@@ -178,18 +164,8 @@ main (int argc, char **argv)
                adios (NULL, "only %d folders allowed!", NFOLDERS);
            folders[foldp++].f_name =
                path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
                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"))
     }
 
     if (!context_find ("path"))
@@ -198,7 +174,7 @@ main (int argc, char **argv)
        adios (NULL, "no folder specified");
 
 #ifdef WHATNOW
        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 */
 
        files[filep++] = cp;
 #endif /* WHATNOW */
 
@@ -206,7 +182,7 @@ main (int argc, char **argv)
      * We are refiling a file to the folders
      */
     if (filep > 0) {
      * 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++)
            adios (NULL, "use -file or some messages, not both");
        opnfolds (folders, foldp);
        for (i = 0; i < filep; i++)
@@ -218,8 +194,8 @@ main (int argc, char **argv)
        done (0);
     }
 
        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));
     if (!folder)
        folder = getfolder (1);
     strncpy (maildir, m_maildir (folder), sizeof(maildir));
@@ -236,8 +212,8 @@ main (int argc, char **argv)
        adios (NULL, "no messages in %s", folder);
 
     /* parse the message range/sequence/name and set SELECTED */
        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 */
 
            done (1);
     seq_setprev (mp);  /* set the previous-sequence */
 
index b9fd80d..75b1c70 100644 (file)
--- a/uip/rmm.c
+++ b/uip/rmm.c
 #include <h/mh.h>
 #include <h/utils.h>
 
 #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 },
 static struct swit switches[] = {
 #define UNLINKSW      0
     { "unlink", 0 },
@@ -34,10 +28,11 @@ static struct swit switches[] = {
 int
 main (int argc, char **argv)
 {
 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 *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
     struct msgs *mp;
 
 #ifdef LOCALE
@@ -51,14 +46,6 @@ main (int argc, char **argv)
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
     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 == '-') {
     /* parse arguments */
     while ((cp = *argp++)) {
        if (*cp == '-') {
@@ -91,24 +78,14 @@ main (int argc, char **argv)
                adios (NULL, "only one folder at a time!");
            else
                folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
                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 (!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);
     if (!folder)
        folder = getfolder (1);
     maildir = m_maildir (folder);
@@ -125,8 +102,8 @@ main (int argc, char **argv)
        adios (NULL, "no messages in %s", folder);
 
     /* parse all the message ranges/sequences and set SELECTED */
        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      */
 
            done (1);
     seq_setprev (mp);          /* set the previous-sequence      */
 
index 705ff69..4334efe 100644 (file)
 #include <h/utils.h>
 #include <errno.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 },
 static struct swit switches[] = {
 #define        CLRSW   0
     { "clear", 0 },
@@ -71,11 +64,12 @@ main (int argc, char **argv)
 {
     int clearflag = 0, hdrflag = 0, ontty;
     int width = 0, revflag = 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];
     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;
 
     struct msgs *mp;
     FILE *in;
 
@@ -92,14 +86,6 @@ main (int argc, char **argv)
     argp = arguments;
 
     /*
     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++)) {
      * Parse arguments
      */
     while ((cp = *argp++)) {
@@ -170,18 +156,8 @@ main (int argc, char **argv)
                adios (NULL, "only one folder at a time!");
            else
                folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
                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"))
     }
 
     if (!context_find ("path"))
@@ -196,7 +172,7 @@ main (int argc, char **argv)
      * We are scanning a maildrop file
      */
     if (file) {
      * 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");
            adios (NULL, "\"msgs\" not allowed with -file");
        if (folder)
            adios (NULL, "\"+folder\" not allowed with -file");
@@ -231,8 +207,8 @@ main (int argc, char **argv)
      * We are scanning a folder
      */
 
      * 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);
     if (!folder)
        folder = getfolder (1);
     maildir = m_maildir (folder);
@@ -249,8 +225,8 @@ main (int argc, char **argv)
        adios (NULL, "no messages in %s", folder);
 
     /* parse all the message ranges/sequences and set SELECTED */
        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 */
 
            done(1);
     seq_setprev (mp);                  /* set the Previous-Sequence */
 
index 9263c79..5faec79 100644 (file)
 #include <h/tws.h>
 #include <h/utils.h>
 
 #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 },
 static struct swit switches[] = {
 #define DATESW                 0
      { "datefield field", 0 },
@@ -76,10 +69,11 @@ static void rename_msgs (struct msgs *, struct smsg **);
 int
 main (int argc, char **argv)
 {
 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 *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;
 
     struct msgs *mp;
     struct smsg **dlist;
 
@@ -95,14 +89,6 @@ main (int argc, char **argv)
     argp = arguments;
 
     /*
     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++)) {
      * Parse arguments
      */
     while ((cp = *argp++)) {
@@ -175,24 +161,14 @@ main (int argc, char **argv)
                adios (NULL, "only one folder at a time!");
            else
                folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
                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 (!context_find ("path"))
        free (path ("./", TFOLDER));
-    if (!nummsgs)
-       msgs[nummsgs++] = "all";
+    if (!msgs.size)
+       app_msgarg(&msgs, "all");
     if (!datesw)
        datesw = "date";
     if (!folder)
     if (!datesw)
        datesw = "date";
     if (!folder)
@@ -211,8 +187,8 @@ main (int argc, char **argv)
        adios (NULL, "no messages in %s", folder);
 
     /* parse all the message ranges/sequences and set SELECTED */
        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 */
 
            done (1);
     seq_setprev (mp);  /* set the previous sequence */