X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fmhpath.c;h=c4fd935b815e9a9b96ded8da99ffd3cc0e0d1ddf;hp=918371a954f4cd3bb792f4d5da5038ae5f45ed14;hb=d8916ff5d389de5ab225cd6f40aeda1b285d0f28;hpb=3c9700d8d045f3ff26ce5dd2a174454dafc14822 diff --git a/uip/mhpath.c b/uip/mhpath.c index 918371a..c4fd935 100644 --- a/uip/mhpath.c +++ b/uip/mhpath.c @@ -3,32 +3,31 @@ * mhpath.c -- print full pathnames of nmh messages and folders * * $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 +#include static struct swit switches[] = { #define VERSIONSW 0 { "version", 0 }, #define HELPSW 1 - { "help", 4 }, + { "help", 0 }, { 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 @@ -43,15 +42,6 @@ main(int argc, char **argv) argp = arguments; /* - * Allocate initial space to record message - * and sequence names - */ - nummsgs = 0; - maxmsgs = MAXMSGS; - if (!(msgs = (char **) malloc ((size_t) (maxmsgs * sizeof(*msgs))))) - adios (NULL, "unable to allocate storage"); - - /* * Parse arguments */ while ((cp = *argp++)) { @@ -77,20 +67,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 { - /* - * if necessary, reallocate space for - * message/sequence names - */ - if (nummsgs >= maxmsgs) { - maxmsgs += MAXMSGS; - if (!(msgs = (char **) realloc (msgs, - (size_t) (maxmsgs * sizeof(*msgs))))) - adios (NULL, "unable to reallocate msgs storage "); - } - msgs[nummsgs++] = cp; - } + folder = pluspath (cp); + } else + app_msgarg(&msgs, cp); } if (!context_find ("path")) @@ -101,7 +80,7 @@ main(int argc, char **argv) maildir = m_maildir (folder); /* If no messages are given, print folder pathname */ - if (!nummsgs) { + if (!msgs.size) { printf ("%s\n", maildir); done (0); } @@ -130,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 */ - 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 */ @@ -144,5 +123,6 @@ main(int argc, char **argv) seq_save (mp); /* synchronize message sequences */ context_save (); /* save the context file */ folder_free (mp); /* free folder/message structure */ - return done (0); + done (0); + return 1; }