]> diplodocus.org Git - nmh/blobdiff - uip/show.c
fdcompare.c: Move interface to own file.
[nmh] / uip / show.c
index 25ed7573fb5e3fbf38a7e855a2098e246262527b..9d387f63c25b4e3698aacd176c38c863b355147f 100644 (file)
@@ -1,14 +1,25 @@
-/*
- * 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
  * complete copyright information.
  */
 
-#include <h/mh.h>
-#include <h/mime.h>
-#include <h/utils.h>
+#include "h/mh.h"
+#include "sbr/folder_read.h"
+#include "sbr/context_save.h"
+#include "sbr/context_replace.h"
+#include "sbr/context_find.h"
+#include "sbr/ambigsw.h"
+#include "sbr/path.h"
+#include "sbr/print_version.h"
+#include "sbr/print_help.h"
+#include "sbr/arglist.h"
+#include "sbr/error.h"
+#include "h/mime.h"
+#include "h/done.h"
+#include "h/utils.h"
+#include "sbr/m_maildir.h"
 
 #define SHOW_SWITCHES \
     X("checkmime", 0, CHECKMIMESW) \
@@ -65,8 +76,11 @@ static int is_nontext(char *);
 int
 main (int argc, char **argv)
 {
-    int draftsw = 0, headersw = 1;
-    int nshow = 0, checkmime = 1, mime = 0;
+    bool draftsw = false;
+    bool headersw = true;
+    bool nshow = false;
+    bool checkmime = true;
+    bool mime = false;
     int isdf = 0, mode = SHOW, msgnum;
     char *cp, *maildir, *file = NULL, *folder = NULL, *proc, *program;
     char buf[BUFSIZ], **argp, **arguments;
@@ -74,7 +88,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 };
 
-    if (nmh_init(argv[0], 1)) { return 1; }
+    if (nmh_init(argv[0], true, true)) { return 1; }
 
     if (!strcasecmp (invo_name, "next")) {
        mode = NEXT;
@@ -92,10 +106,11 @@ main (int argc, char **argv)
                    done (1);
 
                case HEADSW:
-                   headersw = 1;
+                   headersw = true;
                    goto non_mhl_switches;
                case NHEADSW:
-                   headersw = 0;
+                   headersw = false;
+                   /* FALLTHRU */
                case CONCATSW:
                case NCONCATSW:
 non_mhl_switches:
@@ -121,29 +136,28 @@ non_mhl_switches:
 
                case DRFTSW:
                    if (file)
-                       adios (NULL, "only one file at a time!");
-                   draftsw++;
+                       die("only one file at a time!");
+                   draftsw = true;
                    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)
-                       adios (NULL, "only one file at a time!");
+                       die("only one file at a time!");
                    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 == '-')
-                       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:
@@ -158,37 +172,36 @@ usage:
                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 == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
-                   nshow = 0;
+                       die("missing argument to %s", argp[-2]);
+                   nshow = false;
                    continue;
                case NSHOWSW:
-                   nshow++;
+                   nshow = true;
                    continue;
 
                case SHOWMIMESW:
                    if (!(showmimeproc = *argp++) || *showmimeproc == '-')
-                       adios (NULL, "missing argument to %s", argp[-2]);
-                   nshow = 0;
+                       die("missing argument to %s", argp[-2]);
+                   nshow = false;
                    continue;
                case CHECKMIMESW:
-                   checkmime++;
+                   checkmime = true;
                    continue;
                case NOCHECKMIMESW:
-                   checkmime = 0;
+                   checkmime = false;
                    continue;
            }
        }
        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;
@@ -201,12 +214,12 @@ usage:
 
     if (draftsw || file) {
        if (msgs.size)
-           adios (NULL, "only one file at a time!");
+           die("only one file at a time!");
        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;
+       headersw = false;
        goto go_to_it;
     }
 
@@ -233,11 +246,11 @@ usage:
 
     /* 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)
-       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++)
@@ -279,13 +292,13 @@ go_to_it: ;
                /* loop through selected messages and check for MIME */
                for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
                    if (is_selected (mp, msgnum) && is_nontext (m_name (msgnum))) {
-                       mime = 1;
+                       mime = true;
                        break;
                    }
            } else {
                /* check the file or draft for MIME */
                if (is_nontext (vec.msgs[vec.size - 1]))
-                   mime = 1;
+                   mime = true;
            }
        }
 
@@ -297,7 +310,7 @@ go_to_it: ;
     }
 
     if (folder && !draftsw && !file)
-       m_putenv ("mhfolder", folder);
+       setenv("mhfolder", folder, 1);
 
     if (strcmp (r1bindex (proc, '/'), "cat") == 0) {
 
@@ -367,16 +380,16 @@ is_nontext (char *msgnam)
 {
     int        result, state;
     char *bp, *dp, *cp;
-    char buf[BUFSIZ], name[NAMESZ];
+    char buf[NMH_BUFSIZ], name[NAMESZ];
     FILE *fp;
-    m_getfld_state_t gstate = 0;
+    m_getfld_state_t gstate;
 
     if ((fp = fopen (msgnam, "r")) == NULL)
        return 0;
-
+    gstate = m_getfld_state_init(fp);
     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:
            /*
@@ -386,10 +399,10 @@ is_nontext (char *msgnam)
                int passno;
                char c;
 
-               cp = add (buf, NULL);
+               cp = mh_xstrdup(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;
@@ -413,7 +426,7 @@ invalid:
                            continue;
                        case '(':
                            i++;
-                           /* and fall... */
+                           continue;
                        default:
                            continue;
                        case ')':
@@ -491,10 +504,10 @@ out:
             * Check Content-Transfer-Encoding field
             */
            if (!strcasecmp (name, ENCODING_FIELD)) {
-               cp = add (buf, NULL);
+               cp = mh_xstrdup(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++)
@@ -521,7 +534,7 @@ out:
             */
            while (state == FLDPLUS) {
                bufsz = sizeof buf;
-               state = m_getfld (&gstate, name, buf, &bufsz, fp);
+               state = m_getfld2(&gstate, name, buf, &bufsz);
            }
            break;