Removed LBL compile condition (format: addtoseq).
[mmh] / uip / scan.c
index 03a260b..6881c34 100644 (file)
@@ -44,13 +44,6 @@ static struct swit switches[] = {
 
 
 /*
-** global for sbr/formatsbr.c - yech!
-*/
-#ifdef LBL
-extern struct msgs *fmt_current_folder;
-#endif
-
-/*
 ** prototypes
 */
 void clear_screen(void);  /* from termsbr.c */
@@ -73,7 +66,7 @@ main(int argc, char **argv)
 #ifdef LOCALE
        setlocale(LC_ALL, "");
 #endif
-       invo_name = r1bindex(argv[0], '/');
+       invo_name = mhbasename(argv[0]);
 
        /* read user profile/context */
        context_read();
@@ -88,78 +81,78 @@ main(int argc, char **argv)
        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] [msgs] [switches]", invo_name);
-                                       print_help(buf, switches, 1);
-                                       done(1);
-                               case VERSIONSW:
-                                       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:
-                                       if (!(cp = *argp++) || *cp == '-')
-                                               adios(NULL, "missing argument to %s", argp[-2]);
-                                       width = atoi(cp);
-                                       continue;
-                               case REVSW:
-                                       revflag++;
-                                       continue;
-                               case NREVSW:
-                                       revflag = 0;
-                                       continue;
-
-                               case FILESW:
-                                       if (!(cp = *argp++) || (cp[0] == '-' && cp[1]))
-                                               adios(NULL, "missing argument to %s", argp[-2]);
-                                       if (strcmp(file = cp, "-"))
-                                               file = path(cp, TFILE);
-                                       continue;
+                       case AMBIGSW:
+                               ambigsw(cp, switches);
+                               done(1);
+                       case UNKWNSW:
+                               adios(NULL, "-%s unknown", cp);
+
+                       case HELPSW:
+                               snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
+                               print_help(buf, switches, 1);
+                               done(1);
+                       case VERSIONSW:
+                               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:
+                               if (!(cp = *argp++) || *cp == '-')
+                                       adios(NULL, "missing argument to %s",
+                                                       argp[-2]);
+                               width = atoi(cp);
+                               continue;
+                       case REVSW:
+                               revflag++;
+                               continue;
+                       case NREVSW:
+                               revflag = 0;
+                               continue;
+
+                       case FILESW:
+                               if (!(cp = *argp++) || (cp[0] == '-' && cp[1]))
+                                       adios(NULL, "missing argument to %s",
+                                                       argp[-2]);
+                               if (strcmp(file = cp, "-")!=0)
+                                       file = getcpy(expanddir(cp));
+                               continue;
                        }
                }
                if (*cp == '+' || *cp == '@') {
                        if (folder)
                                adios(NULL, "only one folder at a time!");
                        else
-                               folder = pluspath(cp);
+                               folder = getcpy(expandfol(cp));
                } else
-                               app_msgarg(&msgs, cp);
+                       app_msgarg(&msgs, cp);
        }
 
-       if (!context_find("path"))
-               free(path("./", TFOLDER));
-
        /*
        ** Get new format string.  Must be before chdir().
        */
@@ -178,9 +171,8 @@ main(int argc, char **argv)
                if (strcmp(file, "-") == 0) {
                        in = stdin;
                        file = "stdin";
-               } else {
-                       if ((in = fopen(file, "r")) == NULL)
-                               adios(file, "unable to open");
+               } else if (!(in = fopen(file, "r"))) {
+                       adios(file, "unable to open");
                }
 
 #ifndef JLR
@@ -205,10 +197,10 @@ main(int argc, char **argv)
        */
 
        if (!msgs.size)
-               app_msgarg(&msgs, "all");
+               app_msgarg(&msgs, seq_all);
        if (!folder)
-               folder = getfolder(1);
-       maildir = m_maildir(folder);
+               folder = getcurfol();
+       maildir = toabsdir(folder);
 
        if (chdir(maildir) == NOTOK)
                adios(maildir, "unable to change directory to");
@@ -227,48 +219,38 @@ main(int argc, char **argv)
                        done(1);
        seq_setprev(mp);  /* set the Previous-Sequence */
 
-       context_replace(pfolder, folder);  /* update current folder */
+       context_replace(curfolder, folder);  /* update current folder */
        seq_save(mp);  /* synchronize message sequences */
        context_save();  /* save the context file */
 
        /*
-       ** Get the sequence number for each sequence
-       ** specified by Unseen-Sequence
+       ** Get the sequence number for each `unseen' sequence
        */
-       if ((cp = context_find(usequence)) && *cp) {
+       if (!(cp = context_find(usequence))) {
+               cp = seq_unseen;  /* use default, if not set */
+       }
+       if (*cp) {
                char **ap, *dp;
 
                dp = getcpy(cp);
                ap = brkstring(dp, " ", "\n");
-               for (i = 0; ap && *ap; i++, ap++)
+               for (i = 0; ap && *ap; i++, ap++) {
                        seqnum[i] = seq_getnum(mp, *ap);
-
+               }
                num_unseen_seq = i;
-               if (dp)
+               if (dp) {
                        free(dp);
+               }
        }
 
        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)) {
                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;
                        }
 
@@ -293,23 +275,17 @@ main(int argc, char **argv)
                        switch (state = scan(in, msgnum, 0, nfs, width,
                                                msgnum == mp->curmsg, unseen,
                                                folder, 0L, 1)) {
-                               case SCNMSG:
-                               case SCNENC:
-                               case SCNERR:
-                                       break;
+                       case SCNMSG:
+                       case SCNENC:
+                       case SCNERR:
+                               break;
 
-                               default:
-                                       adios(NULL, "scan() botch(%d)", state);
+                       default:
+                               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;
+                       case SCNEOF:
+                               advise(NULL, "message %d: empty", msgnum);
+                               break;
                        }
                        hdrflag = 0;
                        fclose(in);
@@ -318,10 +294,6 @@ main(int argc, char **argv)
                }
        }
 
-#ifdef LBL
-       seq_save(mp);  /* because formatsbr might have made changes */
-#endif
-
        folder_free(mp);  /* free folder/message structure */
        if (clearflag)
                clear_screen();