nmh-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nmh-commits] nmh h/utils.h sbr/utils.c uip/anno.c uip/mark.c...


From: Joel Reicher
Subject: [Nmh-commits] nmh h/utils.h sbr/utils.c uip/anno.c uip/mark.c...
Date: Tue, 11 Apr 2006 14:09:12 +0000

CVSROOT:        /sources/nmh
Module name:    nmh
Branch:         
Changes by:     Joel Reicher <address@hidden>   06/04/11 14:09:11

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

Log message:
        Created app_msgarg() (append message arg) and a simple resizable array
        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().

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/h/utils.h.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/sbr/utils.c.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/uip/anno.c.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/uip/mark.c.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/uip/mhlist.c.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/uip/mhn.c.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/uip/mhpath.c.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/uip/mhshow.c.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/uip/mhstore.c.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/uip/mhtest.c.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/uip/packf.c.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/uip/pick.c.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/uip/refile.c.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/uip/rmm.c.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/uip/scan.c.diff?tr1=1.12&tr2=1.13&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/uip/sortm.c.diff?tr1=1.11&tr2=1.12&r1=text&r2=text

Patches:
Index: nmh/h/utils.h
diff -u nmh/h/utils.h:1.6 nmh/h/utils.h:1.7
--- nmh/h/utils.h:1.6   Tue Feb 21 01:11:51 2006
+++ nmh/h/utils.h       Tue Apr 11 14:09:11 2006
@@ -2,7 +2,7 @@
 /*
  * utils.h -- utility prototypes
  *
- * $Id: utils.h,v 1.6 2006/02/21 01:11:51 bress Exp $
+ * $Id: utils.h,v 1.7 2006/04/11 14:09:11 jjr Exp $
  */
 
 void *mh_xmalloc(size_t);
@@ -11,3 +11,10 @@
 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: nmh/sbr/utils.c
diff -u nmh/sbr/utils.c:1.7 nmh/sbr/utils.c:1.8
--- nmh/sbr/utils.c:1.7 Tue Feb 21 01:11:51 2006
+++ nmh/sbr/utils.c     Tue Apr 11 14:09:11 2006
@@ -2,7 +2,7 @@
 /*
  * utils.c -- various utility routines
  *
- * $Id: utils.c,v 1.7 2006/02/21 01:11:51 bress Exp $
+ * $Id: utils.c,v 1.8 2006/04/11 14:09:11 jjr Exp $
  *
  * This code is Copyright (c) 2006, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -15,6 +15,12 @@
 #include <errno.h>
 
 /*
+ * We allocate space for messages (msgs array)
+ * this number of elements at a time.
+ */
+#define MAXMSGS 256
+
+/*
  * Safely call malloc
  */
 void *
@@ -165,3 +171,16 @@
 
     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: nmh/uip/anno.c
diff -u nmh/uip/anno.c:1.8 nmh/uip/anno.c:1.9
--- nmh/uip/anno.c:1.8  Mon Jan  2 03:25:18 2006
+++ nmh/uip/anno.c      Tue Apr 11 14:09:11 2006
@@ -2,7 +2,7 @@
 /*
  * anno.c -- annotate messages
  *
- * $Id: anno.c,v 1.8 2006/01/02 03:25:18 bress Exp $
+ * $Id: anno.c,v 1.9 2006/04/11 14:09:11 jjr Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -48,13 +48,6 @@
 #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 },
@@ -99,10 +92,11 @@
 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 
*/
@@ -122,14 +116,6 @@
     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)) {
@@ -226,18 +212,8 @@
                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 @@
      */
 
     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));
@@ -269,8 +245,8 @@
 
     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);
@@ -287,8 +263,8 @@
        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);
Index: nmh/uip/mark.c
diff -u nmh/uip/mark.c:1.6 nmh/uip/mark.c:1.7
--- nmh/uip/mark.c:1.6  Mon Jan  2 03:25:18 2006
+++ nmh/uip/mark.c      Tue Apr 11 14:09:11 2006
@@ -4,7 +4,7 @@
  *        -- delete messages (s) from sequences in given folder
  *        -- list sequences in given folder
  *
- * $Id: mark.c,v 1.6 2006/01/02 03:25:18 bress Exp $
+ * $Id: mark.c,v 1.7 2006/04/11 14:09:11 jjr Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -14,13 +14,6 @@
 #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 },
@@ -59,10 +52,11 @@
 {
     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
@@ -77,14 +71,6 @@
     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++)) {
@@ -152,18 +138,8 @@
                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 @@
 
     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);
@@ -202,8 +178,8 @@
        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))
Index: nmh/uip/mhlist.c
diff -u nmh/uip/mhlist.c:1.10 nmh/uip/mhlist.c:1.11
--- nmh/uip/mhlist.c:1.10       Mon Jan  2 03:25:18 2006
+++ nmh/uip/mhlist.c    Tue Apr 11 14:09:11 2006
@@ -2,7 +2,7 @@
 /*
  * mhlist.c -- list the contents of MIME messages
  *
- * $Id: mhlist.c,v 1.10 2006/01/02 03:25:18 bress Exp $
+ * $Id: mhlist.c,v 1.11 2006/04/11 14:09:11 jjr Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -26,13 +26,6 @@
 # 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 },
@@ -130,10 +123,11 @@
 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;
 
@@ -149,14 +143,6 @@
     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++)) {
@@ -257,18 +243,8 @@
                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 */
@@ -299,7 +275,7 @@
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
-    if (file && nummsgs)
+    if (file && msgs.size)
        adios (NULL, "cannot specify msg and file at same time!");
 
     /*
@@ -316,8 +292,8 @@
        /*
         * 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);
@@ -334,8 +310,8 @@
            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 */
 
Index: nmh/uip/mhn.c
diff -u nmh/uip/mhn.c:1.10 nmh/uip/mhn.c:1.11
--- nmh/uip/mhn.c:1.10  Mon Jan  2 03:25:18 2006
+++ nmh/uip/mhn.c       Tue Apr 11 14:09:11 2006
@@ -2,7 +2,7 @@
 /*
  * mhn.c -- display, list, cache, or store the contents of MIME messages
  *
- * $Id: mhn.c,v 1.10 2006/01/02 03:25:18 bress Exp $
+ * $Id: mhn.c,v 1.11 2006/04/11 14:09:11 jjr Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -26,13 +26,6 @@
 # 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 },
@@ -218,10 +211,11 @@
 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;
@@ -238,14 +232,6 @@
     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++)) {
@@ -442,18 +428,8 @@
                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 */
@@ -524,9 +500,9 @@
 
        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;
@@ -542,7 +518,7 @@
        else if (rfc934sw == -1)
            vec[vecp++] = "-norfc934mode";
 
-       vec[vecp++] = msgs[0];
+       vec[vecp++] = msgs.msgs[0];
        vec[vecp] = NULL;
 
        execvp ("mhbuild", vec);
@@ -553,10 +529,10 @@
     /*
      * 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;
@@ -582,7 +558,7 @@
        _exit (-1);
     }
 
-    if (file && nummsgs)
+    if (file && msgs.size)
        adios (NULL, "cannot specify msg and file at same time!");
 
     /*
@@ -599,8 +575,8 @@
        /*
         * 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);
@@ -617,8 +593,8 @@
            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 */
 
Index: nmh/uip/mhpath.c
diff -u nmh/uip/mhpath.c:1.6 nmh/uip/mhpath.c:1.7
--- nmh/uip/mhpath.c:1.6        Mon Jan  2 03:25:18 2006
+++ nmh/uip/mhpath.c    Tue Apr 11 14:09:11 2006
@@ -2,7 +2,7 @@
 /*
  * mhpath.c -- print full pathnames of nmh messages and folders
  *
- * $Id: mhpath.c,v 1.6 2006/01/02 03:25:18 bress Exp $
+ * $Id: mhpath.c,v 1.7 2006/04/11 14:09:11 jjr Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -20,20 +20,14 @@
     { 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
@@ -48,14 +42,6 @@
     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++)) {
@@ -82,18 +68,8 @@
                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"))
@@ -104,7 +80,7 @@
     maildir = m_maildir (folder);
 
     /* If no messages are given, print folder pathname */
-    if (!nummsgs) {
+    if (!msgs.size) {
        printf ("%s\n", maildir);
        done (0);
     }
@@ -133,8 +109,8 @@
     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 */
Index: nmh/uip/mhshow.c
diff -u nmh/uip/mhshow.c:1.10 nmh/uip/mhshow.c:1.11
--- nmh/uip/mhshow.c:1.10       Mon Jan  2 03:25:18 2006
+++ nmh/uip/mhshow.c    Tue Apr 11 14:09:11 2006
@@ -2,7 +2,7 @@
 /*
  * mhshow.c -- display the contents of MIME messages
  *
- * $Id: mhshow.c,v 1.10 2006/01/02 03:25:18 bress Exp $
+ * $Id: mhshow.c,v 1.11 2006/04/11 14:09:11 jjr Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -26,13 +26,6 @@
 # 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 },
@@ -145,10 +138,11 @@
 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;
@@ -165,14 +159,6 @@
     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++)) {
@@ -298,18 +284,8 @@
                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 */
@@ -365,7 +341,7 @@
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
-    if (file && nummsgs)
+    if (file && msgs.size)
        adios (NULL, "cannot specify msg and file at same time!");
 
     /*
@@ -382,8 +358,8 @@
        /*
         * 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);
@@ -400,8 +376,8 @@
            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);
 
        /*
Index: nmh/uip/mhstore.c
diff -u nmh/uip/mhstore.c:1.10 nmh/uip/mhstore.c:1.11
--- nmh/uip/mhstore.c:1.10      Mon Jan  2 03:25:18 2006
+++ nmh/uip/mhstore.c   Tue Apr 11 14:09:11 2006
@@ -2,7 +2,7 @@
 /*
  * mhstore.c -- store the contents of MIME messages
  *
- * $Id: mhstore.c,v 1.10 2006/01/02 03:25:18 bress Exp $
+ * $Id: mhstore.c,v 1.11 2006/04/11 14:09:11 jjr Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -26,13 +26,6 @@
 # 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 },
@@ -123,10 +116,11 @@
 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;
@@ -143,14 +137,6 @@
     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++)) {
@@ -244,18 +230,8 @@
                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 */
@@ -311,7 +287,7 @@
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
-    if (file && nummsgs)
+    if (file && msgs.size)
        adios (NULL, "cannot specify msg and file at same time!");
 
     /*
@@ -328,8 +304,8 @@
        /*
         * 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);
@@ -346,8 +322,8 @@
            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 */
 
Index: nmh/uip/mhtest.c
diff -u nmh/uip/mhtest.c:1.10 nmh/uip/mhtest.c:1.11
--- nmh/uip/mhtest.c:1.10       Mon Jan  2 03:25:18 2006
+++ nmh/uip/mhtest.c    Tue Apr 11 14:09:11 2006
@@ -2,7 +2,7 @@
 /*
  * mhtest.c -- test harness for MIME routines
  *
- * $Id: mhtest.c,v 1.10 2006/01/02 03:25:18 bress Exp $
+ * $Id: mhtest.c,v 1.11 2006/04/11 14:09:11 jjr Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -26,13 +26,6 @@
 # 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 },
@@ -126,10 +119,11 @@
 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;
 
@@ -145,14 +139,6 @@
     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++)) {
@@ -245,18 +231,8 @@
                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 */
@@ -290,7 +266,7 @@
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
-    if (file && nummsgs)
+    if (file && msgs.size)
        adios (NULL, "cannot specify msg and file at same time!");
 
     /*
@@ -307,8 +283,8 @@
        /*
         * 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);
@@ -325,8 +301,8 @@
            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 */
 
Index: nmh/uip/packf.c
diff -u nmh/uip/packf.c:1.7 nmh/uip/packf.c:1.8
--- nmh/uip/packf.c:1.7 Mon Jan  2 03:25:18 2006
+++ nmh/uip/packf.c     Tue Apr 11 14:09:11 2006
@@ -2,7 +2,7 @@
 /*
  * packf.c -- pack a nmh folder into a file
  *
- * $Id: packf.c,v 1.7 2006/01/02 03:25:18 bress Exp $
+ * $Id: packf.c,v 1.8 2006/04/11 14:09:11 jjr Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -15,13 +15,6 @@
 #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 },
@@ -46,9 +39,10 @@
 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;
 
@@ -63,13 +57,6 @@
     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
      */
@@ -112,18 +99,8 @@
            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)
@@ -147,8 +124,8 @@
        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);
@@ -166,8 +143,8 @@
        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 */
 
Index: nmh/uip/pick.c
diff -u nmh/uip/pick.c:1.8 nmh/uip/pick.c:1.9
--- nmh/uip/pick.c:1.8  Mon Jan  2 03:25:18 2006
+++ nmh/uip/pick.c      Tue Apr 11 14:09:11 2006
@@ -2,7 +2,7 @@
 /*
  * pick.c -- search for messages by content
  *
- * $Id: pick.c,v 1.8 2006/01/02 03:25:18 bress Exp $
+ * $Id: pick.c,v 1.9 2006/04/11 14:09:11 jjr Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -14,13 +14,6 @@
 #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 },
@@ -80,10 +73,11 @@
 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;
 
@@ -98,14 +92,6 @@
     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 == '-') {
@@ -192,18 +178,8 @@
                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;
 
@@ -214,8 +190,8 @@
      * 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);
@@ -233,8 +209,8 @@
        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 */
 
Index: nmh/uip/refile.c
diff -u nmh/uip/refile.c:1.10 nmh/uip/refile.c:1.11
--- nmh/uip/refile.c:1.10       Mon Feb 20 03:09:08 2006
+++ nmh/uip/refile.c    Tue Apr 11 14:09:11 2006
@@ -3,7 +3,7 @@
  * refile.c -- move or link message(s) from a source folder
  *          -- into one or more destination folders
  *
- * $Id: refile.c,v 1.10 2006/02/20 03:09:08 bress Exp $
+ * $Id: refile.c,v 1.11 2006/04/11 14:09:11 jjr Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -15,13 +15,6 @@
 #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 },
@@ -73,12 +66,13 @@
 {
     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
@@ -93,14 +87,6 @@
     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++)) {
@@ -178,18 +164,8 @@
                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"))
@@ -198,7 +174,7 @@
        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 */
 
@@ -206,7 +182,7 @@
      * 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++)
@@ -218,8 +194,8 @@
        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));
@@ -236,8 +212,8 @@
        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 */
 
Index: nmh/uip/rmm.c
diff -u nmh/uip/rmm.c:1.7 nmh/uip/rmm.c:1.8
--- nmh/uip/rmm.c:1.7   Mon Jan  2 03:25:18 2006
+++ nmh/uip/rmm.c       Tue Apr 11 14:09:11 2006
@@ -2,7 +2,7 @@
 /*
  * rmm.c -- remove a message(s)
  *
- * $Id: rmm.c,v 1.7 2006/01/02 03:25:18 bress Exp $
+ * $Id: rmm.c,v 1.8 2006/04/11 14:09:11 jjr Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -12,12 +12,6 @@
 #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 },
@@ -34,10 +28,11 @@
 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
@@ -51,14 +46,6 @@
     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 == '-') {
@@ -91,24 +78,14 @@
                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);
@@ -125,8 +102,8 @@
        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      */
 
Index: nmh/uip/scan.c
diff -u nmh/uip/scan.c:1.12 nmh/uip/scan.c:1.13
--- nmh/uip/scan.c:1.12 Mon Jan  2 03:25:18 2006
+++ nmh/uip/scan.c      Tue Apr 11 14:09:11 2006
@@ -2,7 +2,7 @@
 /*
  * scan.c -- display a one-line "scan" listing of folder or messages
  *
- * $Id: scan.c,v 1.12 2006/01/02 03:25:18 bress Exp $
+ * $Id: scan.c,v 1.13 2006/04/11 14:09:11 jjr Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -17,13 +17,6 @@
 #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 },
@@ -71,11 +64,12 @@
 {
     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;
 
@@ -92,14 +86,6 @@
     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++)) {
@@ -170,18 +156,8 @@
                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"))
@@ -196,7 +172,7 @@
      * 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");
@@ -231,8 +207,8 @@
      * 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);
@@ -249,8 +225,8 @@
        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 */
 
Index: nmh/uip/sortm.c
diff -u nmh/uip/sortm.c:1.11 nmh/uip/sortm.c:1.12
--- nmh/uip/sortm.c:1.11        Wed Mar  8 12:14:16 2006
+++ nmh/uip/sortm.c     Tue Apr 11 14:09:11 2006
@@ -2,7 +2,7 @@
 /*
  * sortm.c -- sort messages in a folder by date/time
  *
- * $Id: sortm.c,v 1.11 2006/03/08 12:14:16 bress Exp $
+ * $Id: sortm.c,v 1.12 2006/04/11 14:09:11 jjr Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -13,13 +13,6 @@
 #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 },
@@ -76,10 +69,11 @@
 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;
 
@@ -95,14 +89,6 @@
     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++)) {
@@ -175,24 +161,14 @@
                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)
@@ -211,8 +187,8 @@
        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 */
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]