]> diplodocus.org Git - nmh/blobdiff - uip/show.c
mts/smtp/smtp.c: Replace int with bool.
[nmh] / uip / show.c
index 32917398e409630ec707d4e2c9cc17aef1362fb1..25ede029d4b8e35571a0dd7c3428f7cf7c924488 100644 (file)
@@ -1,5 +1,4 @@
-/*
- * show.c -- show/list messages
+/* show.c -- show/list messages
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -8,7 +7,9 @@
 
 #include <h/mh.h>
 #include <h/mime.h>
 
 #include <h/mh.h>
 #include <h/mime.h>
+#include "h/done.h"
 #include <h/utils.h>
 #include <h/utils.h>
+#include "sbr/m_maildir.h"
 
 #define SHOW_SWITCHES \
     X("checkmime", 0, CHECKMIMESW) \
 
 #define SHOW_SWITCHES \
     X("checkmime", 0, CHECKMIMESW) \
@@ -74,7 +75,7 @@ main (int argc, char **argv)
     struct msgs_array msgs = { 0, 0, NULL };
     struct msgs_array vec = { 0, 0, NULL }, non_mhl_vec = { 0, 0, NULL };
 
     struct msgs_array msgs = { 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], true, true)) { return 1; }
 
     if (!strcasecmp (invo_name, "next")) {
        mode = NEXT;
 
     if (!strcasecmp (invo_name, "next")) {
        mode = NEXT;
@@ -96,6 +97,7 @@ main (int argc, char **argv)
                    goto non_mhl_switches;
                case NHEADSW:
                    headersw = 0;
                    goto non_mhl_switches;
                case NHEADSW:
                    headersw = 0;
+                   /* FALLTHRU */
                case CONCATSW:
                case NCONCATSW:
 non_mhl_switches:
                case CONCATSW:
                case NCONCATSW:
 non_mhl_switches:
@@ -121,29 +123,28 @@ non_mhl_switches:
 
                case DRFTSW:
                    if (file)
 
                case DRFTSW:
                    if (file)
-                       adios (NULL, "only one file at a time!");
+                       die("only one file at a time!");
                    draftsw++;
                    if (mode == SHOW)
                        continue;
 usage:
                    draftsw++;
                    if (mode == SHOW)
                        continue;
 usage:
-                   adios (NULL,
-                           "usage: %s [+folder] [switches] [switches for showproc]",
+                   die(                            "usage: %s [+folder] [switches] [switches for showproc]",
                            invo_name);
                case FILESW:
                    if (mode != SHOW)
                        goto usage;
                    if (draftsw || file)
                            invo_name);
                case FILESW:
                    if (mode != SHOW)
                        goto usage;
                    if (draftsw || file)
-                       adios (NULL, "only one file at a time!");
+                       die("only one file at a time!");
                    if (!(cp = *argp++) || *cp == '-')
                    if (!(cp = *argp++) || *cp == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
+                       die("missing argument to %s", argp[-2]);
                    file = path (cp, TFILE);
                    continue;
 
                case FORMSW:
                    app_msgarg(&vec, --cp);
                    if (!(cp = *argp++) || *cp == '-')
                    file = path (cp, TFILE);
                    continue;
 
                case FORMSW:
                    app_msgarg(&vec, --cp);
                    if (!(cp = *argp++) || *cp == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
-                   app_msgarg(&vec, getcpy (etcpath(cp)));
+                       die("missing argument to %s", argp[-2]);
+                   app_msgarg(&vec, mh_xstrdup(etcpath(cp)));
                    continue;
 
                case PROGSW:
                    continue;
 
                case PROGSW:
@@ -158,13 +159,13 @@ usage:
                case WCACHESW:
                    app_msgarg(&vec, --cp);
                    if (!(cp = *argp++) || *cp == '-')
                case WCACHESW:
                    app_msgarg(&vec, --cp);
                    if (!(cp = *argp++) || *cp == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
+                       die("missing argument to %s", argp[-2]);
                    app_msgarg(&vec, cp);
                    continue;
 
                case SHOWSW:
                    if (!(showproc = *argp++) || *showproc == '-')
                    app_msgarg(&vec, cp);
                    continue;
 
                case SHOWSW:
                    if (!(showproc = *argp++) || *showproc == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
+                       die("missing argument to %s", argp[-2]);
                    nshow = 0;
                    continue;
                case NSHOWSW:
                    nshow = 0;
                    continue;
                case NSHOWSW:
@@ -173,7 +174,7 @@ usage:
 
                case SHOWMIMESW:
                    if (!(showmimeproc = *argp++) || *showmimeproc == '-')
 
                case SHOWMIMESW:
                    if (!(showmimeproc = *argp++) || *showmimeproc == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
+                       die("missing argument to %s", argp[-2]);
                    nshow = 0;
                    continue;
                case CHECKMIMESW:
                    nshow = 0;
                    continue;
                case CHECKMIMESW:
@@ -186,14 +187,12 @@ usage:
        }
        if (*cp == '+' || *cp == '@') {
            if (folder)
        }
        if (*cp == '+' || *cp == '@') {
            if (folder)
-               adios (NULL, "only one folder at a time!");
-           else
-               folder = pluspath (cp);
+               die("only one folder at a time!");
+            folder = pluspath (cp);
        } else {
            if (mode != SHOW)
                goto usage;
        } else {
            if (mode != SHOW)
                goto usage;
-           else
-               app_msgarg(&msgs, cp);
+            app_msgarg(&msgs, cp);
        }
     }
 
        }
     }
 
@@ -202,9 +201,9 @@ usage:
 
     if (draftsw || file) {
        if (msgs.size)
 
     if (draftsw || file) {
        if (msgs.size)
-           adios (NULL, "only one file at a time!");
+           die("only one file at a time!");
        if (draftsw)
        if (draftsw)
-           app_msgarg(&vec, getcpy (m_draft (folder, NULL, 1, &isdf)));
+           app_msgarg(&vec, mh_xstrdup(m_draft(folder, NULL, 1, &isdf)));
        else
            app_msgarg(&vec, file);
        headersw = 0;
        else
            app_msgarg(&vec, file);
        headersw = 0;
@@ -234,11 +233,11 @@ usage:
 
     /* read folder and create message structure */
     if (!(mp = folder_read (folder, 1)))
 
     /* read folder and create message structure */
     if (!(mp = folder_read (folder, 1)))
-       adios (NULL, "unable to read folder %s", folder);
+       die("unable to read folder %s", folder);
 
     /* check for empty folder */
     if (mp->nummsg == 0)
 
     /* check for empty folder */
     if (mp->nummsg == 0)
-       adios (NULL, "no messages in %s", folder);
+       die("no messages in %s", folder);
 
     /* parse all the message ranges/sequences and set SELECTED */
     for (msgnum = 0; msgnum < msgs.size; msgnum++)
 
     /* parse all the message ranges/sequences and set SELECTED */
     for (msgnum = 0; msgnum < msgs.size; msgnum++)
@@ -259,7 +258,7 @@ usage:
 
     for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
        if (is_selected(mp, msgnum))
 
     for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
        if (is_selected(mp, msgnum))
-           app_msgarg(&vec, getcpy (m_name (msgnum)));
+           app_msgarg(&vec, mh_xstrdup(m_name (msgnum)));
 
     seq_setcur (mp, mp->hghsel);       /* update current message  */
     seq_save (mp);                     /* synchronize sequences   */
 
     seq_setcur (mp, mp->hghsel);       /* update current message  */
     seq_save (mp);                     /* synchronize sequences   */
@@ -298,7 +297,7 @@ go_to_it: ;
     }
 
     if (folder && !draftsw && !file)
     }
 
     if (folder && !draftsw && !file)
-       m_putenv ("mhfolder", folder);
+       setenv("mhfolder", folder, 1);
 
     if (strcmp (r1bindex (proc, '/'), "cat") == 0) {
 
 
     if (strcmp (r1bindex (proc, '/'), "cat") == 0) {
 
@@ -368,16 +367,16 @@ is_nontext (char *msgnam)
 {
     int        result, state;
     char *bp, *dp, *cp;
 {
     int        result, state;
     char *bp, *dp, *cp;
-    char buf[BUFSIZ], name[NAMESZ];
+    char buf[NMH_BUFSIZ], name[NAMESZ];
     FILE *fp;
     FILE *fp;
-    m_getfld_state_t gstate = 0;
+    m_getfld_state_t gstate;
 
     if ((fp = fopen (msgnam, "r")) == NULL)
        return 0;
 
     if ((fp = fopen (msgnam, "r")) == NULL)
        return 0;
-
+    gstate = m_getfld_state_init(fp);
     for (;;) {
        int bufsz = sizeof buf;
     for (;;) {
        int bufsz = sizeof buf;
-       switch (state = m_getfld (&gstate, name, buf, &bufsz, fp)) {
+       switch (state = m_getfld2(&gstate, name, buf, &bufsz)) {
        case FLD:
        case FLDPLUS:
            /*
        case FLD:
        case FLDPLUS:
            /*
@@ -387,10 +386,10 @@ is_nontext (char *msgnam)
                int passno;
                char c;
 
                int passno;
                char c;
 
-               cp = add (buf, NULL);
+               cp = mh_xstrdup(buf);
                while (state == FLDPLUS) {
                    bufsz = sizeof buf;
                while (state == FLDPLUS) {
                    bufsz = sizeof buf;
-                   state = m_getfld (&gstate, name, buf, &bufsz, fp);
+                   state = m_getfld2(&gstate, name, buf, &bufsz);
                    cp = add (buf, cp);
                }
                bp = cp;
                    cp = add (buf, cp);
                }
                bp = cp;
@@ -414,7 +413,7 @@ invalid:
                            continue;
                        case '(':
                            i++;
                            continue;
                        case '(':
                            i++;
-                           /* and fall... */
+                           continue;
                        default:
                            continue;
                        case ')':
                        default:
                            continue;
                        case ')':
@@ -447,7 +446,7 @@ invalid:
                    if (*dp) {
                        if ((result = !uprf (dp, "charset")))
                            goto out;
                    if (*dp) {
                        if ((result = !uprf (dp, "charset")))
                            goto out;
-                       dp += sizeof("charset") - 1;
+                       dp += LEN("charset");
                        while (isspace ((unsigned char) *dp))
                            dp++;
                        if (*dp++ != '=')
                        while (isspace ((unsigned char) *dp))
                            dp++;
                        if (*dp++ != '=')
@@ -492,10 +491,10 @@ out:
             * Check Content-Transfer-Encoding field
             */
            if (!strcasecmp (name, ENCODING_FIELD)) {
             * Check Content-Transfer-Encoding field
             */
            if (!strcasecmp (name, ENCODING_FIELD)) {
-               cp = add (buf, NULL);
+               cp = mh_xstrdup(buf);
                while (state == FLDPLUS) {
                    bufsz = sizeof buf;
                while (state == FLDPLUS) {
                    bufsz = sizeof buf;
-                   state = m_getfld (&gstate, name, buf, &bufsz, fp);
+                   state = m_getfld2(&gstate, name, buf, &bufsz);
                    cp = add (buf, cp);
                }
                for (bp = cp; isspace ((unsigned char) *bp); bp++)
                    cp = add (buf, cp);
                }
                for (bp = cp; isspace ((unsigned char) *bp); bp++)
@@ -522,7 +521,7 @@ out:
             */
            while (state == FLDPLUS) {
                bufsz = sizeof buf;
             */
            while (state == FLDPLUS) {
                bufsz = sizeof buf;
-               state = m_getfld (&gstate, name, buf, &bufsz, fp);
+               state = m_getfld2(&gstate, name, buf, &bufsz);
            }
            break;
 
            }
            break;