]> diplodocus.org Git - nmh/commitdiff
fmttest is actually starting to get useful now. Some changes were required
authorKen Hornstein <kenh@pobox.com>
Tue, 19 Feb 2013 01:51:46 +0000 (20:51 -0500)
committerKen Hornstein <kenh@pobox.com>
Tue, 19 Feb 2013 01:51:46 +0000 (20:51 -0500)
to the format code to make this code cleaner.

h/fmt_scan.h
sbr/fmt_compile.c
uip/fmttest.c

index 8de6f23d3760e6a5725d7383b04bc0b5f9225970..b2ec67046ae6dc34f8977e12dc1163b112ab8b44 100644 (file)
@@ -158,6 +158,12 @@ struct format *fmt_scan (struct format *format, char *scanl, size_t max,
 
 void fmt_free (struct format *fmt, int reset);
 
 
 void fmt_free (struct format *fmt, int reset);
 
+/*
+ * Free all of the component text structures in the component hash table
+ */
+
+void fmt_freecomptext(void);
+
 /*
  * Search for a component structure in the component hash table.  Arguments are:
  *
 /*
  * Search for a component structure in the component hash table.  Arguments are:
  *
index 437c811cff974ac173981c63b8748a39cfbc1fb3..9ef3946748cf932b977fdfff2b734deda81f67c3 100644 (file)
@@ -856,6 +856,24 @@ fmt_free(struct format *fmt, int reset_comptable)
        free_comptable();
 }
 
        free_comptable();
 }
 
+/*
+ * Free just the text strings from all of the component hash table entries
+ */
+
+void
+fmt_freecomptext(void)
+{
+    unsigned int i;
+    struct comp *cm;
+
+    for (i = 0; i < sizeof(wantcomp)/sizeof(wantcomp[0]); i++)
+       for (cm = wantcomp[i]; cm; cm = cm->c_next)
+           if (cm->c_text) {
+               free(cm->c_text);
+               cm->c_text = NULL;
+           }
+}
+       
 /*
  * Find a component in our hash table.  This is just a public interface to
  * the FINDCOMP macro, so we don't have to expose our hash table.
 /*
  * Find a component in our hash table.  This is just a public interface to
  * the FINDCOMP macro, so we don't have to expose our hash table.
index edf6fd5e9ea7eefa08699c3a5c083ec2c0a26316..7e71572196178fc2d448e5c3b4825c80c19cdd67 100644 (file)
@@ -383,7 +383,8 @@ process_addresses(struct format *fmt, struct msgs_array *addrs, char *buffer,
 }
 
 /*
 }
 
 /*
- * Process messages and run them through the format engine
+ * Process messages and run them through the format engine.  A lot taken
+ * from scan.c.
  */
 
 static void
  */
 
 static void
@@ -391,9 +392,11 @@ process_messages(struct format *fmt, struct msgs_array *comps,
                 struct msgs_array *msgs, char *buffer, char *folder,
                 int bufsize, int outwidth, int *dat)
 {
                 struct msgs_array *msgs, char *buffer, char *folder,
                 int bufsize, int outwidth, int *dat)
 {
-    int i;
-    char *maildir;
+    int i, state, msgnum, msgsize = dat[2], num = dat[0], cur = dat[1];
+    int num_unseen_seq = 0, seqnum[NUMATTRS];
+    char *maildir, *cp, name[NAMESZ], rbuf[BUFSIZ];
     struct msgs *mp;
     struct msgs *mp;
+    FILE *in;
 
     if (! folder)
        folder = getfolder(1);
 
     if (! folder)
        folder = getfolder(1);
@@ -417,6 +420,113 @@ process_messages(struct format *fmt, struct msgs_array *comps,
     context_replace(pfolder, folder);  /* update curren folder */
     seq_save(mp);                      /* synchronize message sequences */
     context_save();                    /* save the context file */
     context_replace(pfolder, folder);  /* update curren folder */
     seq_save(mp);                      /* synchronize message sequences */
     context_save();                    /* save the context file */
+
+    /*
+     * We want to set the unseen flag if requested, so we have to check
+     * the unseen sequence as well.
+     */
+
+    if (dat[4] == -1) {
+       if ((cp = context_find(usequence)) && *cp) {
+           char **ap, *dp;
+
+           dp = getcpy(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);
+       }
+    }
+
+    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;
+           }
+
+           fmt_freecomptext();
+
+           if (num == -1)
+               dat[0] = msgnum;
+
+           if (cur == -1)
+               dat[1] = msgnum == mp->curmsg;
+
+           /*
+            * Get our size if we didn't include one
+            */
+
+           if (msgsize == -1) {
+               struct stat st;
+
+               if (fstat(fileno(in), &st) < 0)
+                   dat[2] = 0;
+               else
+                   dat[2] = st.st_size;
+           }
+
+           /*
+            * Check to see if this is in the unseen sequence
+            */
+
+           dat[4] = 0;
+           for (i = 0; i < num_unseen_seq; i++) {
+               if (in_sequence(mp, seqnum[i], msgnum)) {
+                   dat[4] = 1;
+                   break;
+               }
+           }
+
+           /*
+            * Read in the message and process the components
+            */
+
+           for (state = FLD;;) {
+               state = m_getfld(state, name, rbuf, sizeof(rbuf), in);
+               switch (state) {
+               case FLD:
+               case FLDPLUS:
+                   i = fmt_addcomptext(name, rbuf);
+                   if (i != -1) {
+                       while (state == FLDPLUS) {
+                           state = m_getfld(state, name, rbuf,
+                                            sizeof(rbuf), in);
+                           fmt_appendcomp(i, name, rbuf);
+                       }
+                   }
+
+                   while (state == FLDPLUS)
+                       state = m_getfld(state, name, rbuf,
+                                        sizeof(rbuf), in);
+                   break;
+
+               case BODY:
+                   if (fmt_findcomp("body")) {
+                       if ((i = strlen(rbuf)) < outwidth)
+                           state = m_getfld(state, name, rbuf + i,
+                                            outwidth - 1, in);
+
+                       fmt_addcomptext("body", rbuf);
+                   }
+                   /* fall through */
+
+               default:
+                   goto finished;
+               }
+           }
+finished:
+           fclose(in);
+           fmt_scan(fmt, buffer, bufsize, outwidth, dat);
+           fputs(buffer, stdout);
+       }
+    }
+
+    folder_free(mp);
+    return;
 }
 
 /*
 }
 
 /*