Fix uip/whom.c for C89 compatibility
[mmh] / uip / scan.c
index 0f755ca..018cd9c 100644 (file)
@@ -30,6 +30,7 @@ static struct swit switches[] = {
        { NULL, 0 }
 };
 
+char *version=VERSION;
 
 int
 main(int argc, char **argv)
@@ -91,7 +92,7 @@ main(int argc, char **argv)
                                        adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                if (strcmp(file = cp, "-")!=0)
-                                       file = getcpy(expanddir(cp));
+                                       file = mh_xstrdup(expanddir(cp));
                                continue;
                        }
                }
@@ -99,15 +100,13 @@ main(int argc, char **argv)
                        if (folder)
                                adios(EX_USAGE, NULL, "only one folder at a time!");
                        else
-                               folder = getcpy(expandfol(cp));
+                               folder = mh_xstrdup(expandfol(cp));
                } else
                        app_msgarg(&msgs, cp);
        }
 
-       /*
-       ** Get new format string.  Must be before chdir().
-       */
-       fmtstr = new_fs(form, FORMAT);
+       /* Set format string.  Must be before chdir(). */
+       fmtstr = new_fs(form, scanformat);
 
        /*
        ** We are scanning a maildrop file
@@ -126,7 +125,6 @@ main(int argc, char **argv)
                        adios(EX_IOERR, file, "unable to open");
                }
 
-               thisisanmbox(in);
                for (msgnum = 1; ; ++msgnum) {
                        state = scan(in, msgnum, SCN_MBOX, fmtstr, width, 0, 0);
                        if (state != SCNMSG)
@@ -149,7 +147,6 @@ main(int argc, char **argv)
        if (chdir(maildir) == NOTOK)
                adios(EX_OSERR, maildir, "unable to change directory to");
 
-       /* read folder and create message structure */
        if (!(mp = folder_read(folder)))
                adios(EX_IOERR, NULL, "unable to read folder %s", folder);
 
@@ -161,11 +158,11 @@ main(int argc, char **argv)
        for (msgnum = 0; msgnum < msgs.size; msgnum++)
                if (!m_convert(mp, msgs.msgs[msgnum]))
                        exit(EX_USAGE);
-       seq_setprev(mp);  /* set the Previous-Sequence */
+       seq_setprev(mp);
 
-       context_replace(curfolder, folder);  /* update current folder */
-       seq_save(mp);  /* synchronize message sequences */
-       context_save();  /* save the context file */
+       context_replace(curfolder, folder);
+       seq_save(mp);
+       context_save();
 
        /*
        ** Get the sequence number for each `unseen' sequence
@@ -176,54 +173,55 @@ main(int argc, char **argv)
        if (*cp) {
                char **ap, *dp;
 
-               dp = getcpy(cp);
+               dp = mh_xstrdup(cp);
                ap = brkstring(dp, " ", "\n");
                for (i = 0; ap && *ap; i++, ap++) {
                        seqnum[i] = seq_getnum(mp, *ap);
                }
                num_unseen_seq = i;
                if (dp) {
-                       free(dp);
+                       mh_free0(&dp);
                }
        }
 
        for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
-               if (is_selected(mp, msgnum)) {
-                       if ((in = fopen(cp = m_name(msgnum), "r")) == NULL) {
-                               admonish(cp, "unable to open message");
-                               continue;
-                       }
+               if (!is_selected(mp, msgnum)) {
+                       continue;
+               }
 
-                       /*
-                       ** Check if message is in any sequence given
-                       ** by Unseen-Sequence profile entry.
-                       */
-                       unseen = 0;
-                       for (i = 0; i < num_unseen_seq; i++) {
-                               if (in_sequence(mp, seqnum[i], msgnum)) {
-                                       unseen = 1;
-                                       break;
-                               }
-                       }
+               if ((in = fopen(cp = m_name(msgnum), "r")) == NULL) {
+                       admonish(cp, "unable to open message");
+                       continue;
+               }
 
-                       switch (state = scan(in, msgnum, SCN_FOLD, fmtstr,
-                                       width, msgnum==mp->curmsg, unseen)) {
-                       case SCNMSG:
-                       case SCNERR:
+               /*
+               ** Check if message is in any sequence given
+               ** by Unseen-Sequence profile entry.
+               */
+               unseen = 0;
+               for (i = 0; i < num_unseen_seq; i++) {
+                       if (in_sequence(mp, seqnum[i], msgnum)) {
+                               unseen = 1;
                                break;
+                       }
+               }
 
-                       default:
-                               adios(EX_SOFTWARE, NULL, "scan() botch(%d)", state);
+               switch (state = scan(in, msgnum, SCN_FOLD, fmtstr,
+                               width, msgnum==mp->curmsg, unseen)) {
+               case SCNMSG:
+               case SCNERR:
+                       break;
 
-                       case SCNEOF:
-                               advise(NULL, "message %d: empty", msgnum);
-                               break;
-                       }
-                       fclose(in);
+               default:
+                       adios(EX_SOFTWARE, NULL, "scan() botch(%d)", state);
+
+               case SCNEOF:
+                       advise(NULL, "message %d: empty", msgnum);
+                       break;
                }
+               fclose(in);
        }
-
-       folder_free(mp);  /* free folder/message structure */
+       folder_free(mp);
 
        return 0;
 }