From: Ken Hornstein Date: Tue, 19 Feb 2013 01:51:46 +0000 (-0500) Subject: fmttest is actually starting to get useful now. Some changes were required X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/085cedfc6d4bf43c6feac2150cad47aea37b106f?ds=sidebyside;hp=--cc fmttest is actually starting to get useful now. Some changes were required to the format code to make this code cleaner. --- 085cedfc6d4bf43c6feac2150cad47aea37b106f diff --git a/h/fmt_scan.h b/h/fmt_scan.h index 8de6f23d..b2ec6704 100644 --- a/h/fmt_scan.h +++ b/h/fmt_scan.h @@ -158,6 +158,12 @@ struct format *fmt_scan (struct format *format, char *scanl, size_t max, 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: * diff --git a/sbr/fmt_compile.c b/sbr/fmt_compile.c index 437c811c..9ef39467 100644 --- a/sbr/fmt_compile.c +++ b/sbr/fmt_compile.c @@ -856,6 +856,24 @@ fmt_free(struct format *fmt, int reset_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. diff --git a/uip/fmttest.c b/uip/fmttest.c index edf6fd5e..7e715721 100644 --- a/uip/fmttest.c +++ b/uip/fmttest.c @@ -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 @@ -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) { - 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; + FILE *in; 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 */ + + /* + * 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; } /*