- int printsw = 0, listsw = 0;
- int pushsw = 0, popsw = 0;
- char *cp, *dp, *msg = NULL, *argfolder = NULL;
- char **ap, **argp, buf[BUFSIZ], **arguments;
-
-#ifdef LOCALE
- setlocale(LC_ALL, "");
-#endif
- invo_name = r1bindex (argv[0], '/');
-
- /* read user profile/context */
- context_read();
-
- /*
- * If program was invoked with name ending
- * in `s', then add switch `-all'.
- */
- if (argv[0][strlen (argv[0]) - 1] == 's')
- all = 1;
-
- arguments = getarguments (invo_name, argc, argv, 1);
- argp = 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] [msg] [switches]",
- invo_name);
- print_help (buf, switches, 1);
- done (1);
- case VERSIONSW:
- print_version(invo_name);
- done (1);
-
- case ALLSW:
- all = 1;
- continue;
-
- case NALLSW:
- all = 0;
- continue;
-
- case CREATSW:
- fcreat = 1;
- continue;
- case NCREATSW:
- fcreat = -1;
- continue;
-
- case FASTSW:
- fshort++;
- continue;
- case NFASTSW:
- fshort = 0;
- continue;
-
- case HDRSW:
- fheader = 1;
- continue;
- case NHDRSW:
- fheader = -1;
- continue;
-
- case PACKSW:
- fpack++;
- continue;
- case NPACKSW:
- fpack = 0;
- continue;
-
- case VERBSW:
- fverb++;
- continue;
- case NVERBSW:
- fverb = 0;
- continue;
-
- case RECURSW:
- frecurse++;
- continue;
- case NRECRSW:
- frecurse = 0;
- continue;
-
- case TOTALSW:
- ftotal = 1;
- continue;
- case NTOTLSW:
- ftotal = -1;
- continue;
-
- case PRNTSW:
- printsw = 1;
- continue;
- case NPRNTSW:
- printsw = 0;
- continue;
-
- case LISTSW:
- listsw = 1;
- continue;
- case NLISTSW:
- listsw = 0;
- continue;
-
- case PUSHSW:
- pushsw = 1;
- listsw = 1;
- popsw = 0;
- continue;
- case POPSW:
- popsw = 1;
- listsw = 1;
- pushsw = 0;
- continue;
- }
- }
- if (*cp == '+' || *cp == '@') {
- if (argfolder)
- adios (NULL, "only one folder at a time!");
- else
- argfolder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
- } else {
- if (msg)
- adios (NULL, "only one (current) message at a time!");
- else
- msg = cp;
- }
- }
-
- if (!context_find ("path"))
- free (path ("./", TFOLDER));
- nmhdir = concat (m_maildir (""), "/", NULL);
-
- /*
- * If we aren't working with the folder stack
- * (-push, -pop, -list) then the default is to print.
- */
- if (pushsw == 0 && popsw == 0 && listsw == 0)
- printsw++;
-
- /* Pushing a folder onto the folder stack */
- if (pushsw) {
- if (!argfolder) {
- /* If no folder is given, the current folder and */
- /* the top of the folder stack are swapped. */
- if ((cp = context_find (stack))) {
- dp = getcpy (cp);
- ap = brkstring (dp, " ", "\n");
- argfolder = getcpy(*ap++);
- } else {
- adios (NULL, "no other folder");
- }
- for (cp = getcpy (getfolder (1)); *ap; ap++)
- cp = add (*ap, add (" ", cp));
- free (dp);
- context_replace (stack, cp); /* update folder stack */
- } else {
- /* update folder stack */
- context_replace (stack,
- (cp = context_find (stack))
- ? concat (getfolder (1), " ", cp, NULL)
- : getcpy (getfolder (1)));
+ int printsw = 0, listsw = 0;
+ int pushsw = 0, popsw = 0;
+ char *cp, *dp, *msg = NULL, *argfolder = NULL;
+ char **ap, **argp, buf[BUFSIZ], **arguments;
+
+ setlocale(LC_ALL, "");
+ invo_name = mhbasename(argv[0]);
+
+ /* read user profile/context */
+ context_read();
+
+ /*
+ ** If program was invoked with name ending
+ ** in `s', then add switch `-all'.
+ */
+ if (argv[0][strlen(argv[0]) - 1] == 's')
+ all = 1;
+
+ arguments = getarguments(invo_name, argc, argv, 1);
+ argp = 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", cp);
+
+ case HELPSW:
+ snprintf(buf, sizeof(buf), "%s [+folder] [msg] [switches]", 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 ALLSW:
+ all = 1;
+ continue;
+
+ case NALLSW:
+ all = 0;
+ continue;
+
+ case CREATSW:
+ fcreat = 1;
+ continue;
+ case NCREATSW:
+ fcreat = -1;
+ continue;
+
+ case FASTSW:
+ fshort++;
+ continue;
+ case NFASTSW:
+ fshort = 0;
+ continue;
+
+ case PACKSW:
+ fpack++;
+ continue;
+ case NPACKSW:
+ fpack = 0;
+ continue;
+
+ case VERBSW:
+ fverb++;
+ continue;
+ case NVERBSW:
+ fverb = 0;
+ continue;
+
+ case RECURSW:
+ frecurse++;
+ continue;
+ case NRECRSW:
+ frecurse = 0;
+ continue;
+
+ case TOTALSW:
+ ftotal = 1;
+ continue;
+ case NTOTLSW:
+ ftotal = -1;
+ continue;
+
+ case PRNTSW:
+ printsw = 1;
+ continue;
+ case NPRNTSW:
+ printsw = 0;
+ continue;
+
+ case LISTSW:
+ listsw = 1;
+ continue;
+ case NLISTSW:
+ listsw = 0;
+ continue;
+
+ case PUSHSW:
+ pushsw = 1;
+ listsw = 1;
+ popsw = 0;
+ continue;
+ case POPSW:
+ popsw = 1;
+ listsw = 1;
+ pushsw = 0;
+ continue;
+ }
+ }
+ if (*cp == '+' || *cp == '@') {
+ if (argfolder)
+ adios(EX_USAGE, NULL, "only one folder at a time!");
+ else
+ argfolder = mh_xstrdup(expandfol(cp));
+ } else {
+ if (msg)
+ adios(EX_USAGE, NULL, "only one (current) message at a time!");
+ else
+ msg = cp;
+ }