X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/8a14191c0a0ad15bb8f35b49748c75c1e0a8c2f4..6547ca9f73c3f02b2356017bbd7ff85292f8e4a1:/uip/sortm.c?ds=sidebyside diff --git a/uip/sortm.c b/uip/sortm.c index bd223bc3..9d661f10 100644 --- a/uip/sortm.c +++ b/uip/sortm.c @@ -1,6 +1,4 @@ - -/* - * sortm.c -- sort messages in a folder by date/time +/* sortm.c -- sort messages in a folder by date/time * * This code is Copyright (c) 2002, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for @@ -9,7 +7,9 @@ #include #include +#include "h/done.h" #include +#include "sbr/m_maildir.h" #define SORTM_SWITCHES \ X("datefield field", 0, DATESW) \ @@ -44,7 +44,7 @@ struct smsg { static struct smsg *smsgs; int nmsgs; -char *subjsort = (char *) 0; /* sort on subject if != 0 */ +char *subjsort; /* sort on subject if != 0 */ time_t datelimit = 0; int submajor = 0; /* if true, sort on subject-major */ int verbose; @@ -168,10 +168,9 @@ main (int argc, char **argv) if (*cp == '+' || *cp == '@') { if (folder) adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); + folder = pluspath (cp); } else - app_msgarg(&msgs, cp); + app_msgarg(&msgs, cp); } if (!context_find ("path")) @@ -216,7 +215,7 @@ main (int argc, char **argv) /* * sort a list of pointers to our "messages to be sorted". */ - dlist = (struct smsg **) mh_xmalloc ((nmsgs+1) * sizeof(*dlist)); + dlist = mh_xmalloc ((nmsgs+1) * sizeof(*dlist)); for (i = 0; i < nmsgs; i++) dlist[i] = &smsgs[i]; dlist[nmsgs] = 0; @@ -232,7 +231,7 @@ main (int argc, char **argv) } /* first sort by date, or by subject-major, date-minor */ - qsort ((char *) dlist, nmsgs, sizeof(*dlist), + qsort (dlist, nmsgs, sizeof(*dlist), (qsort_comp) (submajor && subjsort ? txtsort : dsort)); /* @@ -244,9 +243,9 @@ main (int argc, char **argv) struct smsg **slist, **flist; struct smsg ***il, **fp, **dp; - slist = (struct smsg **) mh_xmalloc ((nmsgs+1) * sizeof(*slist)); - memcpy((char *)slist, (char *)dlist, (nmsgs+1)*sizeof(*slist)); - qsort((char *)slist, nmsgs, sizeof(*slist), (qsort_comp) subsort); + slist = mh_xmalloc ((nmsgs+1) * sizeof(*slist)); + memcpy(slist, dlist, (nmsgs+1)*sizeof(*slist)); + qsort(slist, nmsgs, sizeof(*slist), (qsort_comp) subsort); /* * make an inversion list so we can quickly find @@ -260,7 +259,7 @@ main (int argc, char **argv) * make up the final list, chronological but with * all the same subjects grouped together. */ - flist = (struct smsg **) mh_xmalloc ((nmsgs+1) * sizeof(*flist)); + flist = mh_xmalloc ((nmsgs+1) * sizeof(*flist)); fp = flist; for (dp = dlist; *dp;) { struct smsg **s = il[(*dp++)->s_msg]; @@ -310,11 +309,8 @@ static int read_hdrs (struct msgs *mp, char *datesw) { int msgnum; - struct tws tb; struct smsg *s; - twscopy (&tb, dlocaltimenow ()); - smsgs = mh_xcalloc(mp->hghsel - mp->lowsel + 2, sizeof *smsgs); s = smsgs; for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { @@ -326,7 +322,7 @@ read_hdrs (struct msgs *mp, char *datesw) } } s->s_msg = 0; - return(s - smsgs); + return s - smsgs; } @@ -340,19 +336,20 @@ get_fields (char *datesw, int msg, struct smsg *smsg) { int state; int compnum; - char *msgnam, buf[BUFSIZ], nam[NAMESZ]; + char *msgnam, buf[NMH_BUFSIZ], nam[NAMESZ]; struct tws *tw; char *datecomp = NULL, *subjcomp = NULL; FILE *in; - m_getfld_state_t gstate = 0; + m_getfld_state_t gstate; if ((in = fopen (msgnam = m_name (msg), "r")) == NULL) { admonish (msgnam, "unable to read message"); - return (0); + return 0; } + gstate = m_getfld_state_init(in); for (compnum = 1;;) { int bufsz = sizeof buf; - switch (state = m_getfld (&gstate, nam, buf, &bufsz, in)) { + switch (state = m_getfld2(&gstate, nam, buf, &bufsz)) { case FLD: case FLDPLUS: compnum++; @@ -360,7 +357,7 @@ get_fields (char *datesw, int msg, struct smsg *smsg) datecomp = add (buf, datecomp); while (state == FLDPLUS) { bufsz = sizeof buf; - state = m_getfld (&gstate, nam, buf, &bufsz, in); + state = m_getfld2(&gstate, nam, buf, &bufsz); datecomp = add (buf, datecomp); } if (!subjsort || subjcomp) @@ -369,7 +366,7 @@ get_fields (char *datesw, int msg, struct smsg *smsg) subjcomp = add (buf, subjcomp); while (state == FLDPLUS) { bufsz = sizeof buf; - state = m_getfld (&gstate, nam, buf, &bufsz, in); + state = m_getfld2(&gstate, nam, buf, &bufsz); subjcomp = add (buf, subjcomp); } if (datecomp) @@ -378,7 +375,7 @@ get_fields (char *datesw, int msg, struct smsg *smsg) /* just flush this guy */ while (state == FLDPLUS) { bufsz = sizeof buf; - state = m_getfld (&gstate, nam, buf, &bufsz, in); + state = m_getfld2(&gstate, nam, buf, &bufsz); } } continue; @@ -390,14 +387,14 @@ get_fields (char *datesw, int msg, struct smsg *smsg) case LENERR: case FMTERR: if (state == LENERR || state == FMTERR) { - admonish (NULL, "format error in message %d (header #%d)", + inform("format error in message %d (header #%d), continuing...", msg, compnum); check_failed = 1; } - mh_xfree(datecomp); - mh_xfree(subjcomp); + free(datecomp); + free(subjcomp); fclose (in); - return (0); + return 0; default: adios (NULL, "internal error -- you lose"); @@ -436,10 +433,9 @@ get_fields (char *datesw, int msg, struct smsg *smsg) if (strcmp (subjsort, "subject") == 0) { while ((c = *cp)) { if (! isspace((unsigned char) c)) { - if(uprf(cp, "re:")) - cp += 2; - else + if(!uprf(cp, "re:")) break; + cp += 2; } cp++; } @@ -458,9 +454,9 @@ get_fields (char *datesw, int msg, struct smsg *smsg) smsg->s_subj = subjcomp; } fclose (in); - mh_xfree(datecomp); + free(datecomp); - return (1); + return 1; } /* @@ -470,12 +466,12 @@ static int dsort (struct smsg **a, struct smsg **b) { if ((*a)->s_clock < (*b)->s_clock) - return (-1); + return -1; if ((*a)->s_clock > (*b)->s_clock) - return (1); + return 1; if ((*a)->s_msg < (*b)->s_msg) - return (-1); - return (1); + return -1; + return 1; } /* @@ -487,9 +483,9 @@ subsort (struct smsg **a, struct smsg **b) int i; if ((i = strcmp ((*a)->s_subj, (*b)->s_subj))) - return (i); + return i; - return (dsort (a, b)); + return dsort(a, b); } static int @@ -498,10 +494,10 @@ txtsort (struct smsg **a, struct smsg **b) int i; if ((i = strcmp ((*a)->s_subj, (*b)->s_subj))) - return (i); + return i; if ((*a)->s_msg < (*b)->s_msg) - return (-1); - return (1); + return -1; + return 1; } static void @@ -545,7 +541,7 @@ static void rename_msgs (struct msgs *mp, struct smsg **mlist) { int i, j, old, new; - bvector_t tmpset = bvector_create (0); + bvector_t tmpset = bvector_create (); char f1[BUFSIZ], tmpfil[BUFSIZ]; char newbuf[PATH_MAX + 1]; struct smsg *sp; @@ -590,7 +586,7 @@ rename_msgs (struct msgs *mp, struct smsg **mlist) rename_chain (mp, mlist, j, i); /* - * Run the external hook to refile the temorary message number + * Run the external hook to refile the temporary message number * to the real place. */