]> diplodocus.org Git - nmh/blobdiff - uip/show.c
Replace getcpy() with mh_xstrdup() where the string isn't NULL.
[nmh] / uip / show.c
index 4a53c914e581713097425813c8629711c36bd3de..32917398e409630ec707d4e2c9cc17aef1362fb1 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * show.c -- show/list messages
  *
 /*
  * show.c -- show/list messages
  *
     /*                         \
      * switches for mhlproc    \
      */                                \
     /*                         \
      * switches for mhlproc    \
      */                                \
-    X("concat", -6, CONCATSW) \
-    X("noconcat", -8, NCONCATSW) \
+    X("concat", 0, CONCATSW) \
+    X("noconcat", 0, NCONCATSW) \
+    /*                         \
+     * switches for mhshow     \
+     */                                \
+    X("part number", 0, PARTSW) \
+    X("type content", 0, TYPESW) \
+    X("prefer content", 0, PREFERSW) \
+    X("markform file", 0, MARKFORMSW) \
+    X("rcache policy", 0, RCACHESW) \
+    X("wcache policy", 0, WCACHESW) \
 
 #define X(sw, minchars, id) id,
 DEFINE_SWITCH_ENUM(SHOW);
 
 #define X(sw, minchars, id) id,
 DEFINE_SWITCH_ENUM(SHOW);
@@ -64,7 +72,7 @@ main (int argc, char **argv)
     char buf[BUFSIZ], **argp, **arguments;
     struct msgs *mp = NULL;
     struct msgs_array msgs = { 0, 0, NULL };
     char buf[BUFSIZ], **argp, **arguments;
     struct msgs *mp = NULL;
     struct msgs_array msgs = { 0, 0, NULL };
-    struct msgs_array vec = { 0, 0, NULL };
+    struct msgs_array vec = { 0, 0, NULL }, non_mhl_vec = { 0, 0, NULL };
 
     if (nmh_init(argv[0], 1)) { return 1; }
 
 
     if (nmh_init(argv[0], 1)) { return 1; }
 
@@ -79,23 +87,29 @@ main (int argc, char **argv)
     while ((cp = *argp++)) {
        if (*cp == '-') {
            switch (smatch (++cp, switches)) {
     while ((cp = *argp++)) {
        if (*cp == '-') {
            switch (smatch (++cp, switches)) {
-               case AMBIGSW: 
+               case AMBIGSW:
                    ambigsw (cp, switches);
                    done (1);
 
                    ambigsw (cp, switches);
                    done (1);
 
+               case HEADSW:
+                   headersw = 1;
+                   goto non_mhl_switches;
+               case NHEADSW:
+                   headersw = 0;
                case CONCATSW:
                case NCONCATSW:
                case CONCATSW:
                case NCONCATSW:
-                   /* Use showmimeproc if one of these switches was
-                      specified because mhl doesn't understand them. */
-                   mime = 1;
-                   /* fall thru */
-               case UNKWNSW: 
+non_mhl_switches:
+                   /* mhl can't handle these, so keep them separate. */
+                   app_msgarg(&non_mhl_vec, --cp);
+                   continue;
+
+               case UNKWNSW:
                case NPROGSW:
                case NFMTPROCSW:
                    app_msgarg(&vec, --cp);
                    continue;
 
                case NPROGSW:
                case NFMTPROCSW:
                    app_msgarg(&vec, --cp);
                    continue;
 
-               case HELPSW: 
+               case HELPSW:
                    snprintf (buf, sizeof(buf),
                        "%s [+folder] %s[switches] [switches for showproc]",
                        invo_name, mode == SHOW ? "[msgs] ": "");
                    snprintf (buf, sizeof(buf),
                        "%s [+folder] %s[switches] [switches for showproc]",
                        invo_name, mode == SHOW ? "[msgs] ": "");
@@ -105,7 +119,7 @@ main (int argc, char **argv)
                    print_version(invo_name);
                    done (0);
 
                    print_version(invo_name);
                    done (0);
 
-               case DRFTSW: 
+               case DRFTSW:
                    if (file)
                        adios (NULL, "only one file at a time!");
                    draftsw++;
                    if (file)
                        adios (NULL, "only one file at a time!");
                    draftsw++;
@@ -115,7 +129,7 @@ usage:
                    adios (NULL,
                            "usage: %s [+folder] [switches] [switches for showproc]",
                            invo_name);
                    adios (NULL,
                            "usage: %s [+folder] [switches] [switches for showproc]",
                            invo_name);
-               case FILESW: 
+               case FILESW:
                    if (mode != SHOW)
                        goto usage;
                    if (draftsw || file)
                    if (mode != SHOW)
                        goto usage;
                    if (draftsw || file)
@@ -125,13 +139,6 @@ usage:
                    file = path (cp, TFILE);
                    continue;
 
                    file = path (cp, TFILE);
                    continue;
 
-               case HEADSW: 
-                   headersw++;
-                   continue;
-               case NHEADSW: 
-                   headersw = 0;
-                   continue;
-
                case FORMSW:
                    app_msgarg(&vec, --cp);
                    if (!(cp = *argp++) || *cp == '-')
                case FORMSW:
                    app_msgarg(&vec, --cp);
                    if (!(cp = *argp++) || *cp == '-')
@@ -143,18 +150,24 @@ usage:
                case LENSW:
                case WIDTHSW:
                case FMTPROCSW:
                case LENSW:
                case WIDTHSW:
                case FMTPROCSW:
+               case PARTSW:
+               case TYPESW:
+               case PREFERSW:
+               case MARKFORMSW:
+               case RCACHESW:
+               case WCACHESW:
                    app_msgarg(&vec, --cp);
                    if (!(cp = *argp++) || *cp == '-')
                        adios (NULL, "missing argument to %s", argp[-2]);
                    app_msgarg(&vec, cp);
                    continue;
 
                    app_msgarg(&vec, --cp);
                    if (!(cp = *argp++) || *cp == '-')
                        adios (NULL, "missing argument to %s", argp[-2]);
                    app_msgarg(&vec, cp);
                    continue;
 
-               case SHOWSW: 
+               case SHOWSW:
                    if (!(showproc = *argp++) || *showproc == '-')
                        adios (NULL, "missing argument to %s", argp[-2]);
                    nshow = 0;
                    continue;
                    if (!(showproc = *argp++) || *showproc == '-')
                        adios (NULL, "missing argument to %s", argp[-2]);
                    nshow = 0;
                    continue;
-               case NSHOWSW: 
+               case NSHOWSW:
                    nshow++;
                    continue;
 
                    nshow++;
                    continue;
 
@@ -194,6 +207,7 @@ usage:
            app_msgarg(&vec, getcpy (m_draft (folder, NULL, 1, &isdf)));
        else
            app_msgarg(&vec, file);
            app_msgarg(&vec, getcpy (m_draft (folder, NULL, 1, &isdf)));
        else
            app_msgarg(&vec, file);
+       headersw = 0;
        goto go_to_it;
     }
 
        goto go_to_it;
     }
 
@@ -252,11 +266,7 @@ usage:
     context_replace (pfolder, folder); /* update current folder   */
     context_save ();                   /* save the context file   */
 
     context_replace (pfolder, folder); /* update current folder   */
     context_save ();                   /* save the context file   */
 
-    if (headersw && vec.size == 1)
-       printf ("(Message %s:%s)\n", folder, vec.msgs[0]);
-
 go_to_it: ;
 go_to_it: ;
-    fflush (stdout);
 
     /*
      * Decide which "proc" to use
 
     /*
      * Decide which "proc" to use
@@ -290,28 +300,58 @@ go_to_it: ;
     if (folder && !draftsw && !file)
        m_putenv ("mhfolder", folder);
 
     if (folder && !draftsw && !file)
        m_putenv ("mhfolder", folder);
 
-    if (strcmp (r1bindex (proc, '/'), "mhn") == 0) {
-       /* Add "-file" if showing file or draft, */
-       if (draftsw || file) {
-           app_msgarg(&vec, vec.msgs[vec.size - 1]);
-           vec.msgs[vec.size - 2] = "-file";
-       }
-       /* and add -show for backward compatibility */
-       app_msgarg(&vec, "-show");
-    } else if (strcmp (r1bindex (proc, '/'), "mhshow") == 0) {
-       /* If "mhshow", add "-file" if showing file or draft. */
-       if (draftsw || file) {
-           app_msgarg(&vec, vec.msgs[vec.size - 1]);
-           vec.msgs[vec.size - 2] = "-file";
-       }
+    if (strcmp (r1bindex (proc, '/'), "cat") == 0) {
+
+       if (headersw && vec.size == 1)
+           printf ("(Message %s:%s)\n", folder, vec.msgs[0]);
+
     } else if (strcmp (r1bindex (proc, '/'), "mhl") == 0) {
     } else if (strcmp (r1bindex (proc, '/'), "mhl") == 0) {
+
+       if (headersw && vec.size == 1)
+           printf ("(Message %s:%s)\n", folder, vec.msgs[0]);
+
        /* If "mhl", then run it internally */
        argsplit_insert(&vec, "mhl", &program);
        app_msgarg(&vec, NULL);
        mhl (vec.size, vec.msgs);
        done (0);
        /* If "mhl", then run it internally */
        argsplit_insert(&vec, "mhl", &program);
        app_msgarg(&vec, NULL);
        mhl (vec.size, vec.msgs);
        done (0);
+
+    } else {
+       int i;
+       char **mp;
+
+       for (i = 0, mp = non_mhl_vec.msgs; i < non_mhl_vec.size; ++i, ++mp) {
+           if (draftsw || file) {
+               /* Insert the switch before the filename. */
+               app_msgarg(&vec, vec.msgs[vec.size - 1]);
+               vec.msgs[vec.size - 2] = *mp;
+           } else {
+               app_msgarg(&vec, *mp);
+           }
+       }
+
+       if (strcmp (r1bindex (proc, '/'), "mhn") == 0) {
+           /* Add "-file" if showing file or draft, */
+           if (draftsw || file) {
+               app_msgarg(&vec, vec.msgs[vec.size - 1]);
+               vec.msgs[vec.size - 2] = "-file";
+           }
+           /* and add -show for backward compatibility */
+           app_msgarg(&vec, "-show");
+       } else if (strcmp (r1bindex (proc, '/'), "mhshow") == 0) {
+           /* If "mhshow", add "-file" if showing file or draft. */
+           if (draftsw || file) {
+               app_msgarg(&vec, vec.msgs[vec.size - 1]);
+               vec.msgs[vec.size - 2] = "-file";
+           }
+       } else {
+           if (headersw && vec.size == 1)
+               printf ("(Message %s:%s)\n", folder, vec.msgs[0]);
+       }
     }
 
     }
 
+    fflush (stdout);
+
     argsplit_insert(&vec, proc, &program);
     app_msgarg(&vec, NULL);
     execvp (program, vec.msgs);
     argsplit_insert(&vec, proc, &program);
     app_msgarg(&vec, NULL);
     execvp (program, vec.msgs);