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++) {
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;
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 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 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 IOERR2:
+ 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);