X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fsortm.c;h=43dc7dc0bbed6cdef9623293e9a06e63754e4146;hp=ae4038db6c2b3d68211fef3e21b92a7d29766ee1;hb=6e7d34c614291079de750ceda1d4f5ec537beb81;hpb=72795bfcbe9f7fee8927b1a4942c0230b0f857a8 diff --git a/uip/sortm.c b/uip/sortm.c index ae4038d..43dc7dc 100644 --- a/uip/sortm.c +++ b/uip/sortm.c @@ -297,8 +297,6 @@ read_hdrs(struct msgs *mp, char *datesw) smsgs = (struct smsg *) mh_xcalloc((size_t) (mp->hghsel - mp->lowsel + 2), sizeof(*smsgs)); - if (smsgs == NULL) - adios(EX_OSERR, NULL, "unable to allocate sort storage"); s = smsgs; for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { @@ -322,9 +320,10 @@ read_hdrs(struct msgs *mp, char *datesw) static int get_fields(char *datesw, int msg, struct smsg *smsg) { - int state; + enum state state; + struct field f = {{0}}; int compnum; - char *msgnam, buf[BUFSIZ], nam[NAMESZ]; + char *msgnam; struct tws *tw; char *datecomp = NULL, *subjcomp = NULL; FILE *in; @@ -333,51 +332,37 @@ get_fields(char *datesw, int msg, struct smsg *smsg) admonish(msgnam, "unable to read message"); return (0); } - for (compnum = 1, state = FLD;;) { - switch (state = m_getfld(state, nam, buf, sizeof(buf), in)) { - case FLD: - case FLDEOF: - case FLDPLUS: - compnum++; - if (!mh_strcasecmp(nam, datesw)) { - datecomp = add(buf, datecomp); - while (state == FLDPLUS) { - state = m_getfld(state, nam, buf, - sizeof(buf), in); - datecomp = add(buf, datecomp); - } - if (!subjsort || subjcomp) + for (compnum = 1, state = FLD2;; compnum++) { + switch (state = m_getfld2(state, &f, in)) { + case FLD2: + if (mh_strcasecmp(f.name, datesw)==0) { + datecomp = getcpy(f.value); + if (!subjsort || subjcomp) { break; - } else if (subjsort && !mh_strcasecmp(nam, subjsort)) { - subjcomp = add(buf, subjcomp); - while (state == FLDPLUS) { - state = m_getfld(state, nam, buf, - sizeof(buf), in); - subjcomp = add(buf, subjcomp); } - if (datecomp) + } else if (subjsort && mh_strcasecmp(f.name, + subjsort)==0) { + subjcomp = getcpy(f.value); + if (datecomp) { break; - } else { - /* just flush this guy */ - while (state == FLDPLUS) - state = m_getfld(state, nam, buf, - sizeof(buf), in); + } } continue; - case BODY: - case BODYEOF: - case FILEEOF: + case BODY2: + case FILEEOF2: break; - case LENERR: - case FMTERR: - if (state == LENERR || state == FMTERR) - admonish(NULL, "format error in message %d (header #%d)", msg, compnum); - if (datecomp) + case LENERR2: + case FMTERR2: + case ERR2: + admonish(NULL, "format error in message %d (header #%d)", msg, compnum); + if (datecomp) { free(datecomp); - if (subjcomp) + } + if (subjcomp) { free(subjcomp); + } fclose(in); return (0);