X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/61e09274bb3338efbd9c50f797751853c99dba3b..86b1fbb19b287c67f43fd280a13c81eea72583a3:/uip/sortm.c diff --git a/uip/sortm.c b/uip/sortm.c index 6e7a7491..f0d3248a 100644 --- a/uip/sortm.c +++ b/uip/sortm.c @@ -78,13 +78,7 @@ main (int argc, char **argv) struct smsg **dlist; int checksw = 0; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); + if (nmh_init(argv[0], 1)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; @@ -199,7 +193,7 @@ main (int argc, char **argv) adios (maildir, "unable to change directory to"); /* read folder and create message structure */ - if (!(mp = folder_read (folder))) + if (!(mp = folder_read (folder, 1))) adios (NULL, "unable to read folder %s", folder); /* check for empty folder */ @@ -248,7 +242,7 @@ main (int argc, char **argv) */ if (!submajor && subjsort) { /* already date sorted */ struct smsg **slist, **flist; - register struct smsg ***il, **fp, **dp; + struct smsg ***il, **fp, **dp; slist = (struct smsg **) mh_xmalloc ((nmsgs+1) * sizeof(*slist)); memcpy((char *)slist, (char *)dlist, (nmsgs+1)*sizeof(*slist)); @@ -259,9 +253,7 @@ main (int argc, char **argv) * the collection of messages with the same subj * given a message number. */ - il = (struct smsg ***) calloc (mp->hghsel+1, sizeof(*il)); - if (! il) - adios (NULL, "couldn't allocate msg list"); + il = mh_xcalloc(mp->hghsel + 1, sizeof *il); for (i = 0; i < nmsgs; i++) il[slist[i]->s_msg] = &slist[i]; /* @@ -271,7 +263,7 @@ main (int argc, char **argv) flist = (struct smsg **) mh_xmalloc ((nmsgs+1) * sizeof(*flist)); fp = flist; for (dp = dlist; *dp;) { - register struct smsg **s = il[(*dp++)->s_msg]; + struct smsg **s = il[(*dp++)->s_msg]; /* see if we already did this guy */ if (! s) @@ -293,6 +285,7 @@ main (int argc, char **argv) } } *fp = 0; + free (il); free (slist); free (dlist); dlist = flist; @@ -318,16 +311,11 @@ read_hdrs (struct msgs *mp, char *datesw) { int msgnum; struct tws tb; - register struct smsg *s; + struct smsg *s; twscopy (&tb, dlocaltimenow ()); - smsgs = (struct smsg *) - calloc ((size_t) (mp->hghsel - mp->lowsel + 2), - sizeof(*smsgs)); - if (smsgs == NULL) - adios (NULL, "unable to allocate sort storage"); - + smsgs = mh_xcalloc(mp->hghsel - mp->lowsel + 2, sizeof *smsgs); s = smsgs; for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { if (is_selected(mp, msgnum)) { @@ -350,12 +338,12 @@ read_hdrs (struct msgs *mp, char *datesw) static int get_fields (char *datesw, int msg, struct smsg *smsg) { - register int state; + int state; int compnum; char *msgnam, buf[BUFSIZ], nam[NAMESZ]; - register struct tws *tw; - register char *datecomp = NULL, *subjcomp = NULL; - register FILE *in; + struct tws *tw; + char *datecomp = NULL, *subjcomp = NULL; + FILE *in; m_getfld_state_t gstate = 0; if ((in = fopen (msgnam = m_name (msg), "r")) == NULL) { @@ -368,7 +356,7 @@ get_fields (char *datesw, int msg, struct smsg *smsg) case FLD: case FLDPLUS: compnum++; - if (!mh_strcasecmp (nam, datesw)) { + if (!strcasecmp (nam, datesw)) { datecomp = add (buf, datecomp); while (state == FLDPLUS) { bufsz = sizeof buf; @@ -377,7 +365,7 @@ get_fields (char *datesw, int msg, struct smsg *smsg) } if (!subjsort || subjcomp) break; - } else if (subjsort && !mh_strcasecmp (nam, subjsort)) { + } else if (subjsort && !strcasecmp (nam, subjsort)) { subjcomp = add (buf, subjcomp); while (state == FLDPLUS) { bufsz = sizeof buf; @@ -445,7 +433,7 @@ get_fields (char *datesw, int msg, struct smsg *smsg) * leading "re:", everything but letters & smash * letters to lower case. */ - register char *cp, *cp2, c; + char *cp, *cp2, c; cp = subjcomp; cp2 = subjcomp; @@ -503,7 +491,7 @@ dsort (struct smsg **a, struct smsg **b) static int subsort (struct smsg **a, struct smsg **b) { - register int i; + int i; if ((i = strcmp ((*a)->s_subj, (*b)->s_subj))) return (i); @@ -514,7 +502,7 @@ subsort (struct smsg **a, struct smsg **b) static int txtsort (struct smsg **a, struct smsg **b) { - register int i; + int i; if ((i = strcmp ((*a)->s_subj, (*b)->s_subj))) return (i); @@ -565,7 +553,7 @@ static void rename_msgs (struct msgs *mp, struct smsg **mlist) { int i, j, old, new; - seqset_t tmpset; + bvector_t tmpset = bvector_create (0); char f1[BUFSIZ], tmpfil[BUFSIZ]; char newbuf[PATH_MAX + 1]; struct smsg *sp; @@ -605,7 +593,7 @@ rename_msgs (struct msgs *mp, struct smsg **mlist) if (rename (f1, tmpfil) == NOTOK) adios (tmpfil, "unable to rename %s to ", f1); - get_msg_flags (mp, &tmpset, old); + get_msg_flags (mp, tmpset, old); rename_chain (mp, mlist, j, i); @@ -620,7 +608,9 @@ rename_msgs (struct msgs *mp, struct smsg **mlist) if (rename (tmpfil, m_name(new)) == NOTOK) adios (m_name(new), "unable to rename %s to", tmpfil); - set_msg_flags (mp, &tmpset, new); + set_msg_flags (mp, tmpset, new); mp->msgflags |= SEQMOD; } + + bvector_free (tmpset); }