- int addsw = 0, deletesw = 0, debugsw = 0;
- int listsw = 0, publicsw = -1, zerosw = 0;
- int seqp = 0, msgnum, nummsgs, maxmsgs;
- char *cp, *maildir, *folder = NULL, buf[BUFSIZ];
- char **argp, **arguments;
- char *seqs[NUMATTRS + 1], **msgs;
- struct msgs *mp;
-
-#ifdef LOCALE
- setlocale(LC_ALL, "");
-#endif
- invo_name = r1bindex (argv[0], '/');
-
- /* read user profile/context */
- context_read();
-
- arguments = getarguments (invo_name, argc, argv, 1);
- 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++)) {
- if (*cp == '-') {
- switch (smatch (++cp, switches)) {
- case AMBIGSW:
- ambigsw (cp, switches);
- done (1);
- case UNKWNSW:
- adios (NULL, "-%s unknown\n", cp);
-
- case HELPSW:
- snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]",
- invo_name);
- print_help (buf, switches, 1);
- done (1);
- case VERSIONSW:
- print_version(invo_name);
- done (1);
-
- case ADDSW:
- addsw++;
- deletesw = listsw = 0;
- continue;
- case DELSW:
- deletesw++;
- addsw = listsw = 0;
- continue;
- case LSTSW:
- listsw++;
- addsw = deletesw = 0;
- continue;
-
- case SEQSW:
- if (!(cp = *argp++) || *cp == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
-
- /* check if too many sequences specified */
- if (seqp >= NUMATTRS)
- adios (NULL, "too many sequences (more than %d) specified", NUMATTRS);
- seqs[seqp++] = cp;
- continue;
-
- case PUBLSW:
- publicsw = 1;
- continue;
- case NPUBLSW:
- publicsw = 0;
- continue;
-
- case DEBUGSW:
- debugsw++;
- continue;
-
- case ZEROSW:
- zerosw++;
- continue;
- case NZEROSW:
- zerosw = 0;
- continue;
- }
- }
- if (*cp == '+' || *cp == '@') {
- 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;
+ int addsw = 0, deletesw = 0, debugsw = 0;
+ int listsw = 0, publicsw = -1, zerosw = 0, msgnum;
+ unsigned int seqp = 0;
+ char *cp, *maildir, *folder = NULL, buf[BUFSIZ];
+ char **argp, **arguments;
+ char *seqs[NUMATTRS + 1];
+ struct msgs_array msgs = { 0, 0, NULL };
+ struct msgs *mp;
+
+ setlocale(LC_ALL, "");
+ invo_name = mhbasename(argv[0]);
+
+ /* read user profile/context */
+ context_read();
+
+ arguments = getarguments(invo_name, argc, argv, 1);
+ argp = arguments;
+
+ /*
+ ** Parse arguments
+ */
+ while ((cp = *argp++)) {
+ if (*cp == '-') {
+ switch (smatch(++cp, switches)) {
+ case AMBIGSW:
+ ambigsw(cp, switches);
+ done(1);
+ case UNKWNSW:
+ adios(NULL, "-%s unknown\n", cp);
+
+ case HELPSW:
+ snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
+ print_help(buf, switches, 1);
+ done(1);
+ case VERSIONSW:
+ print_version(invo_name);
+ done(1);
+
+ case ADDSW:
+ addsw++;
+ deletesw = listsw = 0;
+ continue;
+ case DELSW:
+ deletesw++;
+ addsw = listsw = 0;
+ continue;
+ case LSTSW:
+ listsw++;
+ addsw = deletesw = 0;
+ continue;
+
+ case SEQSW:
+ if (!(cp = *argp++) || *cp == '-')
+ adios(NULL, "missing argument to %s",
+ argp[-2]);
+
+ /* check if too many sequences specified */
+ if (seqp >= NUMATTRS)
+ adios(NULL, "too many sequences (more than %d) specified", NUMATTRS);
+ seqs[seqp++] = cp;
+ continue;
+
+ case PUBLSW:
+ publicsw = 1;
+ continue;
+ case NPUBLSW:
+ publicsw = 0;
+ continue;
+
+ case DEBUGSW:
+ debugsw++;
+ continue;
+
+ case ZEROSW:
+ zerosw++;
+ continue;
+ case NZEROSW:
+ zerosw = 0;
+ continue;
+ }
+ }
+ if (*cp == '+' || *cp == '@') {
+ if (folder)
+ adios(NULL, "only one folder at a time!");
+ else
+ folder = getcpy(expandfol(cp));
+ } else
+ app_msgarg(&msgs, cp);