Renamed -version switch to -Version to remove the conflict with -verbose.
[mmh] / uip / scan.c
index 478e4a6..085cc7f 100644 (file)
 #include <h/fmt_scan.h>
 #include <h/scansbr.h>
 #include <h/tws.h>
-#include <h/mts.h>
 #include <h/utils.h>
 #include <errno.h>
 
 static struct swit switches[] = {
-#define CLRSW  0
-       { "clear", 0 },
-#define NCLRSW  1
-       { "noclear", 0 },
-#define FORMSW  2
+#define FORMSW  0
        { "form formatfile", 0 },
-#define FMTSW  3
-       { "format string", 5 },
-#define HEADSW  4
-       { "header", 0 },
-#define NHEADSW  5
-       { "noheader", 0 },
-#define WIDTHSW  6
+#define WIDTHSW  1
        { "width columns", 0 },
-#define REVSW  7
-       { "reverse", 0 },
-#define NREVSW  8
-       { "noreverse", 0 },
-#define FILESW  9
+#define FILESW  2
        { "file file", 4 },
-#define VERSIONSW 10
-       { "version", 0 },
-#define HELPSW  11
+#define VERSIONSW 3
+       { "Version", 0 },
+#define HELPSW  4
        { "help", 0 },
        { NULL, 0 }
 };
 
 
-/*
-** global for sbr/formatsbr.c - yech!
-*/
-#ifdef LBL
-extern struct msgs *fmt_current_folder;
-#endif
-
-/*
-** prototypes
-*/
-void clear_screen(void);  /* from termsbr.c */
-
-
 int
 main(int argc, char **argv)
 {
-       int clearflag = 0, hdrflag = 0, ontty;
-       int width = 0, revflag = 0;
+       int width = 0;
        int i, state, msgnum;
        int seqnum[NUMATTRS], unseen, num_unseen_seq = 0;
        char *cp, *maildir, *file = NULL, *folder = NULL;
-       char *form = NULL, *format = NULL, buf[BUFSIZ];
-       char **argp, *nfs, **arguments;
+       char *form = NULL, buf[BUFSIZ];
+       char **argp, *fmtstr, **arguments;
        struct msgs_array msgs = { 0, 0, NULL };
        struct msgs *mp;
        FILE *in;
@@ -78,7 +49,6 @@ main(int argc, char **argv)
        /* read user profile/context */
        context_read();
 
-       mts_init(invo_name);
        arguments = getarguments(invo_name, argc, argv, 1);
        argp = arguments;
 
@@ -102,31 +72,10 @@ main(int argc, char **argv)
                                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:
@@ -135,12 +84,6 @@ main(int argc, char **argv)
                                                        argp[-2]);
                                width = atoi(cp);
                                continue;
-                       case REVSW:
-                               revflag++;
-                               continue;
-                       case NREVSW:
-                               revflag = 0;
-                               continue;
 
                        case FILESW:
                                if (!(cp = *argp++) || (cp[0] == '-' && cp[1]))
@@ -163,7 +106,7 @@ main(int argc, char **argv)
        /*
        ** Get new format string.  Must be before chdir().
        */
-       nfs = new_fs(form, format, FORMAT);
+       fmtstr = new_fs(form, FORMAT);
 
        /*
        ** We are scanning a maildrop file
@@ -182,17 +125,10 @@ main(int argc, char **argv)
                        adios(file, "unable to open");
                }
 
-#ifndef JLR
-               if (hdrflag) {
-                       printf("FOLDER %s\t%s\n", file, dtimenow(1));
-               }
-#endif /* JLR */
-
-               m_unknown(in);
+               thisisanmbox(in);
                for (msgnum = 1; ; ++msgnum) {
-                       state = scan(in, msgnum, -1, nfs, width, 0, 0,
-                                       hdrflag ? file : NULL, 0L, 1);
-                       if (state != SCNMSG && state != SCNENC)
+                       state = scan(in, msgnum, SCN_MBOX, fmtstr, width, 0, 0);
+                       if (state != SCNMSG)
                                break;
                }
                fclose(in);
@@ -250,36 +186,13 @@ main(int argc, char **argv)
                }
        }
 
-       ontty = isatty(fileno(stdout));
-
-#ifdef LBL
-       else
-               fmt_current_folder = mp;
-#endif
-
-       for (msgnum = revflag ? mp->hghsel : mp->lowsel;
-                (revflag ? msgnum >= mp->lowsel : msgnum <= mp->hghsel);
-                msgnum += (revflag ? -1 : 1)) {
+       for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
                if (is_selected(mp, msgnum)) {
                        if ((in = fopen(cp = m_name(msgnum), "r")) == NULL) {
-#if 0
-                               if (errno != EACCES)
-#endif
-                                       admonish(cp, "unable to open message");
-#if 0
-                               else
-                                       printf("%*d  unreadable\n",
-                                                       DMAXFOLDER, msgnum);
-#endif
+                               admonish(cp, "unable to open message");
                                continue;
                        }
 
-#ifndef JLR
-                       if (hdrflag) {
-                               printf("FOLDER %s\t%s\n", folder, dtimenow(1));
-                       }
-#endif /* JLR */
-
                        /*
                        ** Check if message is in any sequence given
                        ** by Unseen-Sequence profile entry.
@@ -292,11 +205,9 @@ main(int argc, char **argv)
                                }
                        }
 
-                       switch (state = scan(in, msgnum, 0, nfs, width,
-                                               msgnum == mp->curmsg, unseen,
-                                               folder, 0L, 1)) {
+                       switch (state = scan(in, msgnum, SCN_FOLD, fmtstr,
+                                       width, msgnum==mp->curmsg, unseen)) {
                        case SCNMSG:
-                       case SCNENC:
                        case SCNERR:
                                break;
 
@@ -304,27 +215,14 @@ main(int argc, char **argv)
                                adios(NULL, "scan() botch(%d)", state);
 
                        case SCNEOF:
-#if 0
-                               printf("%*d  empty\n", DMAXFOLDER, msgnum);
-#else
                                advise(NULL, "message %d: empty", msgnum);
-#endif
                                break;
                        }
-                       hdrflag = 0;
                        fclose(in);
-                       if (ontty)
-                               fflush(stdout);
                }
        }
 
-#ifdef LBL
-       seq_save(mp);  /* because formatsbr might have made changes */
-#endif
-
        folder_free(mp);  /* free folder/message structure */
-       if (clearflag)
-               clear_screen();
 
        done(0);
        return 1;