X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fmark.c;h=372568a0e6b637aa6e697b18ab9c8d535bb1b44c;hp=9bd45619932afc8c97b808b2e5052ecaa90cb1e8;hb=d8916ff5d389de5ab225cd6f40aeda1b285d0f28;hpb=197f95940cc0860683e6988352f721e6603f9339 diff --git a/uip/mark.c b/uip/mark.c index 9bd4561..372568a 100644 --- a/uip/mark.c +++ b/uip/mark.c @@ -5,16 +5,14 @@ * -- list sequences in given folder * * $Id$ + * + * This code is Copyright (c) 2002, by the authors of nmh. See the + * COPYRIGHT file in the root directory of the nmh distribution for + * complete copyright information. */ #include - -/* - * We allocate space for messages (msgs array) - * this number of elements at a time. - */ -#define MAXMSGS 256 - +#include static struct swit switches[] = { #define ADDSW 0 @@ -36,7 +34,7 @@ static struct swit switches[] = { #define VERSIONSW 8 { "version", 0 }, #define HELPSW 9 - { "help", 4 }, + { "help", 0 }, #define DEBUGSW 10 { "debug", -5 }, { NULL, 0 } @@ -54,10 +52,11 @@ main (int argc, char **argv) { 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 @@ -72,15 +71,6 @@ main (int argc, char **argv) argp = arguments; /* - * Allocate the initial space to record message - * names, ranges, and sequences. - */ - nummsgs = 0; - maxmsgs = MAXMSGS; - if (!(msgs = (char **) malloc ((size_t) (maxmsgs * sizeof(*msgs))))) - adios (NULL, "unable to allocate storage"); - - /* * Parse arguments */ while ((cp = *argp++)) { @@ -147,20 +137,9 @@ main (int argc, char **argv) if (folder) adios (NULL, "only one folder at a time!"); else - folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF); - } else { - /* - * Check if we need to allocate more space - * for message names/ranges/sequences. - */ - if (nummsgs >= maxmsgs) { - maxmsgs += MAXMSGS; - if (!(msgs = (char **) realloc (msgs, - (size_t) (maxmsgs * sizeof(*msgs))))) - adios (NULL, "unable to reallocate msgs storage"); - } - msgs[nummsgs++] = cp; - } + folder = pluspath (cp); + } else + app_msgarg(&msgs, cp); } /* @@ -177,8 +156,8 @@ main (int argc, char **argv) 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); @@ -199,8 +178,8 @@ main (int argc, char **argv) adios (NULL, "no messages in %s", folder); /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < nummsgs; msgnum++) - if (!m_convert (mp, msgs[msgnum])) + for (msgnum = 0; msgnum < msgs.size; msgnum++) + if (!m_convert (mp, msgs.msgs[msgnum])) done (1); if (publicsw == 1 && is_readonly(mp)) @@ -249,7 +228,8 @@ main (int argc, char **argv) context_replace (pfolder, folder); /* update current folder */ context_save (); /* save the context file */ folder_free (mp); /* free folder/message structure */ - return done (0); + done (0); + return 1; }