- invo_name = r1bindex (argv[0], '/');
-
- /* read user profile/context */
- context_read();
-
- mts_init (invo_name);
- 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)));
-
- /*
- * Parse arguments
- */
- while ((cp = *argp++)) {
- if (*cp == '-') {
- switch (smatch (++cp, switches)) {
- case AMBIGSW:
- ambigsw (cp, switches);
- done (1);
- case UNKWNSW:
- adios (NULL, "-%s unknown", 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 CLRSW:
- clearflag++;
- continue;
- case NCLRSW:
- clearflag = 0;
- continue;
-
- case FORMSW:
- if (!(form = *argp++) || *form == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- format = NULL;
- continue;
- case FMTSW:
- if (!(format = *argp++) || *format == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- form = NULL;
- continue;
-
- case HEADSW:
- hdrflag++;
- continue;
- case NHEADSW:
- hdrflag = 0;
- continue;
-
- case WIDTHSW:
- if (!(cp = *argp++) || *cp == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- width = atoi (cp);
- continue;
- case REVSW:
- revflag++;
- continue;
- case NREVSW:
- revflag = 0;
- continue;
-
- case FILESW:
- if (!(cp = *argp++) || (cp[0] == '-' && cp[1]))
- adios (NULL, "missing argument to %s", argp[-2]);
- if (strcmp (file = cp, "-"))
- file = path (cp, TFILE);
- 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;
- }
- }
-
- if (!context_find ("path"))
- free (path ("./", TFOLDER));
-
- /*
- * Get new format string. Must be before chdir().
- */
- nfs = new_fs (form, format, FORMAT);
-
- /*
- * We are scanning a maildrop file
- */
- if (file) {
- if (nummsgs)
- adios (NULL, "\"msgs\" not allowed with -file");
- if (folder)
- adios (NULL, "\"+folder\" not allowed with -file");
-
- /* check if "file" is really stdin */
- if (strcmp (file, "-") == 0) {
- in = stdin;
- file = "stdin";
- } else {
- if ((in = fopen (file, "r")) == NULL)
- adios (file, "unable to open");
+ invo_name = r1bindex (argv[0], '/');
+
+ /* read user profile/context */
+ context_read();
+
+ mts_init (invo_name);
+ 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", 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 CLRSW:
+ clearflag++;
+ continue;
+ case NCLRSW:
+ clearflag = 0;
+ continue;
+
+ case FORMSW:
+ if (!(form = *argp++) || *form == '-')
+ adios (NULL, "missing argument to %s", argp[-2]);
+ format = NULL;
+ continue;
+ case FMTSW:
+ if (!(format = *argp++) || *format == '-')
+ adios (NULL, "missing argument to %s", argp[-2]);
+ form = NULL;
+ continue;
+
+ case HEADSW:
+ hdrflag++;
+ continue;
+ case NHEADSW:
+ hdrflag = 0;
+ continue;
+
+ case WIDTHSW:
+ if (!(cp = *argp++) || *cp == '-')
+ adios (NULL, "missing argument to %s", argp[-2]);
+ width = atoi (cp);
+ continue;
+ case REVSW:
+ revflag++;
+ continue;
+ case NREVSW:
+ revflag = 0;
+ continue;
+
+ case FILESW:
+ if (!(cp = *argp++) || (cp[0] == '-' && cp[1]))
+ adios (NULL, "missing argument to %s", argp[-2]);
+ if (strcmp (file = cp, "-"))
+ file = path (cp, TFILE);
+ continue;
+ }
+ }
+ if (*cp == '+' || *cp == '@') {
+ if (folder)
+ adios (NULL, "only one folder at a time!");
+ else
+ folder = pluspath (cp);
+ } else
+ app_msgarg(&msgs, cp);