- int linkf = 0, preserve = 0, filep = 0;
- int foldp = 0, isdf = 0, unlink_msgs = 0;
- int i, msgnum, nummsgs, maxmsgs;
- char *cp, *folder = NULL, buf[BUFSIZ];
- char **argp, **arguments, **msgs;
- char *filevec[NFOLDERS + 2];
- char **files = &filevec[1]; /* leave room for remove_files:vec[0] */
- struct st_fold folders[NFOLDERS + 1];
- 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 [msgs] [switches] +folder ...",
- invo_name);
- print_help (buf, switches, 1);
- done (1);
- case VERSIONSW:
- print_version(invo_name);
- done (1);
-
- case LINKSW:
- linkf++;
- continue;
- case NLINKSW:
- linkf = 0;
- continue;
-
- case PRESSW:
- preserve++;
- continue;
- case NPRESSW:
- preserve = 0;
- continue;
-
- case UNLINKSW:
- unlink_msgs++;
- continue;
- case NUNLINKSW:
- unlink_msgs = 0;
- continue;
-
- case SRCSW:
- if (folder)
- adios (NULL, "only one source folder at a time!");
- if (!(cp = *argp++) || *cp == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- folder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp,
- *cp != '@' ? TFOLDER : TSUBCWF);
- continue;
- case DRAFTSW:
- if (filep > NFOLDERS)
- adios (NULL, "only %d files allowed!", NFOLDERS);
- isdf = 0;
- files[filep++] = getcpy (m_draft (NULL, NULL, 1, &isdf));
- continue;
- case FILESW:
- if (filep > NFOLDERS)
- adios (NULL, "only %d files allowed!", NFOLDERS);
- if (!(cp = *argp++) || *cp == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- files[filep++] = path (cp, TFILE);
- continue;
-
- case RPROCSW:
- if (!(rmmproc = *argp++) || *rmmproc == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- continue;
- case NRPRCSW:
- rmmproc = NULL;
- continue;
- }
+ int linkf = 0, filep = 0;
+ int foldp = 0;
+ int i, msgnum;
+ char *cp, *folder = NULL, buf[BUFSIZ];
+ char **argp, **arguments;
+ char *filevec[NFOLDERS + 1];
+ char **files = filevec;
+ struct st_fold folders[NFOLDERS + 1];
+ struct msgs_array msgs = { 0, 0, NULL };
+ struct msgs *mp;
+
+ setlocale(LC_ALL, "");
+ invo_name = mhbasename(argv[0]);
+
+ 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);
+ exit(EX_USAGE);
+ case UNKWNSW:
+ adios(EX_USAGE, NULL, "-%s unknown\n", cp);
+
+ case HELPSW:
+ snprintf(buf, sizeof(buf), "%s [msgs] [switches] +folder ...", invo_name);
+ print_help(buf, switches, 1);
+ exit(argc == 2 ? EX_OK : EX_USAGE);
+ case VERSIONSW:
+ print_version(invo_name);
+ exit(argc == 2 ? EX_OK : EX_USAGE);
+
+ case LINKSW:
+ linkf++;
+ continue;
+ case NLINKSW:
+ linkf = 0;
+ continue;
+
+ case SRCSW:
+ if (folder)
+ adios(EX_USAGE, NULL, "only one source folder at a time!");
+ if (!(cp = *argp++) || *cp == '-')
+ adios(EX_USAGE, NULL, "missing argument to %s",
+ argp[-2]);
+ folder = mh_xstrdup(expandfol(cp));
+ continue;
+ case FILESW:
+ if (filep > NFOLDERS)
+ adios(EX_USAGE, NULL, "only %d files allowed!",
+ NFOLDERS);
+ if (!(cp = *argp++) || *cp == '-')
+ adios(EX_USAGE, NULL, "missing argument to %s",
+ argp[-2]);
+ files[filep++] = mh_xstrdup(expanddir(cp));
+ continue;
+ }
+ }
+ if (*cp == '+' || *cp == '@') {
+ if (foldp > NFOLDERS)
+ adios(EX_USAGE, NULL, "only %d folders allowed!",
+ NFOLDERS);
+ folders[foldp++].f_name = mh_xstrdup(expandfol(cp));
+ } else
+ app_msgarg(&msgs, cp);