head 1.20; access; symbols; locks; strict; comment @ * @; 1.20 date 95.12.06.23.46.23; author jromine; state Exp; branches; next 1.19; 1.19 date 92.12.15.00.20.22; author jromine; state Exp; branches; next 1.18; 1.18 date 92.12.03.16.50.27; author jromine; state Exp; branches; next 1.17; 1.17 date 92.12.03.16.28.56; author jromine; state Exp; branches; next 1.16; 1.16 date 92.11.04.01.03.50; author jromine; state Exp; branches; next 1.15; 1.15 date 92.01.31.22.28.01; author jromine; state Exp; branches; next 1.14; 1.14 date 90.12.19.10.02.16; author mh; state Exp; branches; next 1.13; 1.13 date 90.12.19.09.42.20; author mh; state Exp; branches; next 1.12; 1.12 date 90.04.05.15.02.27; author sources; state Exp; branches; next 1.11; 1.11 date 90.03.23.13.55.40; author sources; state Exp; branches; next 1.10; 1.10 date 90.03.23.13.44.45; author sources; state Exp; branches; next 1.9; 1.9 date 90.03.22.17.11.16; author sources; state Exp; branches; next 1.8; 1.8 date 90.03.22.17.06.05; author sources; state Exp; branches; next 1.7; 1.7 date 90.03.22.15.33.44; author sources; state Exp; branches; next 1.6; 1.6 date 90.03.22.15.11.11; author sources; state Exp; branches; next 1.5; 1.5 date 90.03.22.15.10.28; author sources; state Exp; branches; next 1.4; 1.4 date 90.03.22.15.03.10; author sources; state Exp; branches; next 1.3; 1.3 date 90.03.21.23.23.43; author sources; state Exp; branches; next 1.2; 1.2 date 90.02.06.13.32.04; author sources; state Exp; branches; next 1.1; 1.1 date 90.02.06.13.31.45; author sources; state Exp; branches; next ; desc @@ 1.20 log @fix: use int for msgstats @ text @/* sortm.c - sort messages in a folder by date/time */ /* 21Apr90 do subject sorts too - from V. Jacobson */ #ifndef lint static char ident[] = "@@(#)$Id: sortm.c,v 1.19 1992/12/15 00:20:22 jromine Exp jromine $"; #endif /* lint */ #include "../h/mh.h" #include "../zotnet/tws.h" #define getws _getws #include #undef getws #include #include #include #ifdef LOCALE #include #endif #if defined(SYS5) && defined(AUX) #define u_short ushort #define u_long ulong #endif static struct swit switches[] = { #define DATESW 0 "datefield field", 0, #define TEXTSW 1 "textfield field", 0, #define NSUBJSW 2 "notextfield", 0, #define SUBJSW 3 "subject", -3, /* backward-compatibility */ #define LIMSW 4 "limit days", 0, #define NLIMSW 5 "nolimit", 0, #define VERBSW 6 "verbose", 0, #define NVERBSW 7 "noverbose", 0, #define HELPSW 8 "help", 4, NULL, 0 }; struct smsg { int s_msg; unsigned long s_clock; char *s_subj; }; static struct smsg *smsgs; int nmsgs; char *subjsort = (char *)0; /* sort on subject if != 0 */ u_long datelimit = 0; int submajor = 0; /* if true, sort on subject-major */ int verbose; #ifdef __STDC__ static int getws (char *datesw, int msg, struct smsg *smsg); #else static int getws (); #endif static int dsort(), read_hdrs (), subsort(), txtsort(); static void rename_chain(), rename_msgs(); /* */ main (argc, argv) int argc; char **argv; { int msgp = 0, i, msgnum; char *cp, *maildir, *datesw = NULL, *folder = NULL, buf[100], **ap, **argp, *arguments[MAXARGS], *msgs[MAXARGS]; struct msgs *mp; struct smsg **dlist; #ifdef LOCALE setlocale(LC_ALL, ""); #endif invo_name = r1bindex (argv[0], '/'); if ((cp = m_find (invo_name)) != NULL) { ap = brkstring (cp = getcpy (cp), " ", "\n"); ap = copyip (ap, arguments); } else ap = arguments; (void) copyip (argv + 1, ap); argp = arguments; while (cp = *argp++) { if (*cp == '-') switch (smatch (++cp, switches)) { case AMBIGSW: ambigsw (cp, switches); done (1); case UNKWNSW: adios (NULLCP, "-%s unknown", cp); case HELPSW: (void) sprintf(buf, "%s [+folder] [msgs] [switches]", invo_name); help (buf, switches); done (1); case DATESW: if (datesw) adios (NULLCP, "only one date field at a time"); if (!(datesw = *argp++) || *datesw == '-') adios (NULLCP, "missing argument to %s", argp[-2]); continue; case TEXTSW: if (subjsort) adios (NULLCP, "only one text field at a time"); if (!(subjsort = *argp++) || *subjsort == '-') adios (NULLCP, "missing argument to %s", argp[-2]); continue; case SUBJSW: subjsort = "subject"; continue; case NSUBJSW: subjsort = (char *)0; continue; case LIMSW: if (!(cp = *argp++) || *cp == '-') adios (NULLCP, "missing argument to %s", argp[-2]); while (*cp == '0') cp++; /* skip any leading zeros */ if (!*cp) { /* hit end of string */ submajor++; /* sort subject-major */ continue; } if (!isdigit(*cp) || !(datelimit = atoi(cp))) adios (NULLCP, "impossible limit %s", cp); datelimit *= 60*60*24; continue; case NLIMSW: submajor = 0; /* use date-major, but */ datelimit = 0; /* use no limit */ continue; case VERBSW: verbose++; continue; case NVERBSW: verbose = 0; continue; } if (*cp == '+' || *cp == '@@') { if (folder) adios (NULLCP, "only one folder at a time!"); else folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF); } else msgs[msgp++] = cp; } if (!m_find ("path")) free (path ("./", TFOLDER)); if (!msgp) msgs[msgp++] = "all"; if (!datesw) datesw = "date"; if (!folder) folder = m_getfolder (); maildir = m_maildir (folder); if (chdir (maildir) == NOTOK) adios (maildir, "unable to change directory to"); if (!(mp = m_gmsg (folder))) adios (NULLCP, "unable to read folder %s", folder); if (mp->hghmsg == 0) adios (NULLCP, "no messages in %s", folder); for (msgnum = 0; msgnum < msgp; msgnum++) if (!m_convert (mp, msgs[msgnum])) done (1); m_setseq (mp); if ((nmsgs = read_hdrs (mp, datesw)) <= 0) adios (NULLCP, "no messages to sort"); /* * sort a list of pointers to our "messages to be sorted". */ dlist = (struct smsg **) malloc ((nmsgs+1) * sizeof(*dlist)); if (! dlist) adios (NULLCP, "couldn't allocate sort memory"); for (i = 0; i < nmsgs; i++) dlist[i] = &smsgs[i]; dlist[nmsgs] = 0; if (verbose) /* announce what we're doing */ if (subjsort) printf ("sorting by %s-major %s-minor\n", submajor ? subjsort : datesw, submajor ? datesw : subjsort); else printf ("sorting by datefield %s\n", datesw); /* first sort by date, or by subject-major, date-minor */ qsort ((char *) dlist, nmsgs, sizeof(*dlist), submajor && subjsort ? txtsort : dsort); /* * if we're sorting on subject, we need another list * in subject order, then a merge pass to collate the * two sorts. */ if (!submajor && subjsort) { /* already date sorted */ struct smsg **slist, **flist; register struct smsg ***il, **fp, **dp; slist = (struct smsg **) malloc ((nmsgs+1) * sizeof(*slist)); if (! slist) adios (NULLCP, "couldn't allocate sort memory"); bcopy ((char *)dlist, (char *)slist, (nmsgs+1)*sizeof(*slist)); qsort ((char *)slist, nmsgs, sizeof(*slist), subsort); /* * make an inversion list so we can quickly find * the collection of messages with the same subj * given a message number. */ il = (struct smsg ***) calloc (mp->hghsel+1, sizeof(*il)); if (! il) adios (NULLCP, "couldn't allocate msg list"); for (i = 0; i < nmsgs; i++) il[slist[i]->s_msg] = &slist[i]; /* * make up the final list, chronological but with * all the same subjects grouped together. */ flist = (struct smsg **) malloc ((nmsgs+1) * sizeof(*flist)); if (! flist) adios (NULLCP, "couldn't allocate msg list"); fp = flist; for (dp = dlist; *dp;) { register struct smsg **s = il[(*dp++)->s_msg]; /* see if we already did this guy */ if (! s) continue; *fp++ = *s++; /* * take the next message(s) if there is one, * its subject isn't null and its subject * is the same as this one and it's not too * far away in time. */ while (*s && (*s)->s_subj[0] && strcmp((*s)->s_subj, s[-1]->s_subj) == 0 && (datelimit == 0 || (*s)->s_clock - s[-1]->s_clock <= datelimit)) { il[(*s)->s_msg] = 0; *fp++ = *s++; } } *fp = 0; (void) free (slist); (void) free (dlist); dlist = flist; } rename_msgs (mp, dlist); m_replace (pfolder, folder); m_sync (mp); m_update (); done (0); } static int read_hdrs (mp, datesw) register struct msgs *mp; register char *datesw; { int msgnum; struct tws tb; register struct smsg *s; twscopy (&tb, dtwstime ()); smsgs = (struct smsg *) calloc ((unsigned) (mp->hghsel - mp->lowsel + 2), sizeof *smsgs); if (smsgs == NULL) adios (NULLCP, "unable to allocate sort storage"); s = smsgs; for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { if (mp->msgstats[msgnum] & SELECTED) { if (getws (datesw, msgnum, s)) { s->s_msg = msgnum; s++; } } } s->s_msg = 0; return(s - smsgs); } static getws (datesw, msg, smsg) register char *datesw; int msg; register struct smsg *smsg; { register int state; int compnum; char *msgnam, buf[BUFSIZ], nam[NAMESZ]; register struct tws *tw; register char *datecomp = NULLCP, *subjcomp = NULLCP; register FILE *in; if ((in = fopen (msgnam = m_name (msg), "r")) == NULL) { 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 (uleq (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) break; } else if (subjsort && uleq (nam, subjsort)) { subjcomp = add (buf, subjcomp); while (state == FLDPLUS) { state = m_getfld (state, nam, buf, sizeof buf, in); subjcomp = add (buf, subjcomp); } 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: break; case LENERR: case FMTERR: if (state == LENERR || state == FMTERR) admonish (NULLCP, "format error in message %d (header #%d)", msg, compnum); if (datecomp) free (datecomp); if (subjcomp) free (subjcomp); (void) fclose (in); return (0); default: adios (NULLCP, "internal error -- you lose"); } break; } if (!datecomp || (tw = dparsetime (datecomp)) == NULL) { struct stat st; admonish (NULLCP, "can't parse %s field in message %d", datesw, msg); /* use the modify time of the file as its date */ (void) fstat (fileno (in), &st); smsg->s_clock = st.st_mtime; } else smsg->s_clock = twclock (tw); if (subjsort) { if (subjcomp) { /* * try to make the subject "canonical": delete * leading "re:", everything but letters & smash * letters to lower case. */ register char *cp, *cp2, c; cp = subjcomp; cp2 = subjcomp; if (strcmp (subjsort, "subject") == 0) while (c = *cp) { if (! isspace(c)) { if(uprf(cp, "re:")) cp += 2; else { if (isalnum(c)) *cp2++ = isupper(c) ? tolower(c) : c; break; } } cp++; } while (c = *cp++) { if (isalnum(c)) *cp2++ = isupper(c) ? tolower(c) : c; } *cp2 = '\0'; } else subjcomp = ""; smsg->s_subj = subjcomp; } (void) fclose (in); if (datecomp) free (datecomp); return (1); } /* * sort on dates. */ static int dsort (a, b) register struct smsg **a, **b; { if ((*a)->s_clock < (*b)->s_clock) return (-1); else if ((*a)->s_clock > (*b)->s_clock) return (1); else if ((*a)->s_msg < (*b)->s_msg) return (-1); else return (1); } /* * sort on subjects. */ static int subsort (a, b) register struct smsg **a, **b; { register int i; if (i = strcmp ((*a)->s_subj, (*b)->s_subj)) return (i); return (dsort (a, b)); } static int txtsort (a, b) register struct smsg **a, **b; { register int i; if (i = strcmp ((*a)->s_subj, (*b)->s_subj)) return (i); else if ((*a)->s_msg < (*b)->s_msg) return (-1); else return (1); } static void rename_chain (mp, mlist, msg, endmsg) register struct msgs *mp; struct smsg **mlist; int msg, endmsg; { int nxt, old, new; char *newname, oldname[BUFSIZ]; for (;;) { nxt = mlist[msg] - smsgs; /* mlist[msg] is a ptr into smsgs */ mlist[msg] = (struct smsg *)0; old = smsgs[nxt].s_msg; new = smsgs[msg].s_msg; (void) strcpy (oldname, m_name (old)); newname = m_name (new); if (verbose) printf ("message %d becomes message %d\n", old, new); if (rename (oldname, newname) == NOTOK) adios (newname, "unable to rename %s to", oldname); mp->msgstats[new] = mp->msgstats[old]; if (mp->curmsg == old) m_setcur (mp, new); if (nxt == endmsg) break; msg = nxt; } /* if (nxt != endmsg); */ /* rename_chain (mp, mlist, nxt, endmsg); */ } static void rename_msgs (mp, mlist) register struct msgs *mp; register struct smsg **mlist; { register int i, j, old, new; int stats; char f1[BUFSIZ], tmpfil[BUFSIZ]; register struct smsg *sp; (void) strcpy (tmpfil, m_name (mp->hghmsg + 1)); for (i = 0; i < nmsgs; i++) { if (! (sp = mlist[i])) continue; /* did this one */ j = sp - smsgs; if (j == i) continue; /* this one doesn't move */ /* * the guy that was msg j is about to become msg i. * rename 'j' to make a hole, then recursively rename * guys to fill up the hole. */ old = smsgs[j].s_msg; new = smsgs[i].s_msg; (void) strcpy (f1, m_name (old)); if (verbose) printf ("renaming message chain from %d to %d\n", old, new); if (rename (f1, tmpfil) == NOTOK) adios (tmpfil, "unable to rename %s to ", f1); stats = mp->msgstats[old]; rename_chain (mp, mlist, j, i); if (rename (tmpfil, m_name(new)) == NOTOK) adios (m_name(new), "unable to rename %s to", tmpfil); mp->msgstats[new] = stats; mp->msgflags |= SEQMOD; } } @ 1.19 log @endif sugar @ text @d4 1 a4 1 static char ident[] = "@@(#)$Id: sortm.c,v 1.18 1992/12/03 16:50:27 jromine Exp jromine $"; d554 1 a554 1 short stats; @ 1.18 log @put u_short ifdef under #if AUX @ text @d4 2 a5 2 static char ident[] = "@@(#)$Id: sortm.c,v 1.17 1992/12/03 16:28:56 jromine Exp jromine $"; #endif lint @ 1.17 log @u_short AUX changes from Jim Guyton @ text @d4 1 a4 1 static char ident[] = "@@(#)$Id: sortm.c,v 1.16 1992/11/04 01:03:50 jromine Exp jromine $"; d18 1 a18 1 #ifdef SYS5 @ 1.16 log @LOCALE @ text @d4 1 a4 1 static char ident[] = "@@(#)$Id: sortm.c,v 1.15 1992/01/31 22:28:01 jromine Exp jromine $"; d18 5 @ 1.15 log @kerberos @ text @d4 1 a4 1 static char ident[] = "@@(#)$Id: sortm.c,v 1.14 1990/12/19 10:02:16 mh Exp jromine $"; d15 3 d90 3 d422 1 a422 1 while (c = *cp++) { d424 1 a424 3 if ((c == 'r' || c == 'R') && (cp[0] == 'e' || cp[0] == 'E') && cp[1] == ':') d432 1 @ 1.14 log @convert to tail recursion remove unused variable jlr @ text @d4 1 a4 1 static char ident[] = "@@(#)$Id: sortm.c,v 1.13 90/12/19 09:42:20 mh Exp Locker: mh $"; d9 1 d11 1 d40 1 a40 1 NULL, NULL d57 6 a62 1 static getws(); @ 1.13 log @sortm could lose a message if interrupted. jlr @ text @d4 1 a4 1 static char ident[] = "@@(#)$Id: sortm.c,v 1.12 90/04/05 15:02:27 sources Exp Locker: mh $"; d502 9 a510 8 nxt = mlist[msg] - smsgs; mlist[msg] = 0; old = smsgs[nxt].s_msg; new = smsgs[msg].s_msg; (void) strcpy (oldname, m_name (old)); newname = m_name (new); if (verbose) printf ("message %d becomes message %d\n", old, new); d512 2 a513 2 if (rename (oldname, newname) == NOTOK) adios (newname, "unable to rename %s to", oldname); d515 3 a517 3 mp->msgstats[new] = mp->msgstats[old]; if (mp->curmsg == old) m_setcur (mp, new); d519 7 a525 2 if (nxt != endmsg) rename_chain (mp, mlist, nxt, endmsg); a538 1 f2[BUFSIZ], @ 1.12 log @add ID @ text @d4 1 a4 1 static char ident[] = "@@(#)$Id:$"; d537 1 a537 1 (void) strcpy (tmpfil, m_scratch ("", invo_name)); @ 1.11 log @allow numeric strings @ text @d3 3 @ 1.10 log @use arbitrary textfield not just "subject" @ text @d413 2 a414 3 if (isalpha(c)) *cp2++ = islower(c)? c : tolower(c); d420 2 a421 2 if (isalpha(c)) *cp2++ = islower(c)? c : tolower(c); @ 1.9 log @typo @ text @d15 4 a18 4 #define VERBSW 1 "verbose", 0, #define NVERBSW 2 "noverbose", 0, d21 2 a22 5 "subject", 0, #define NSUBJSW 4 "nosubject", 0, #define LIMSW 5 d24 1 a24 1 #define NLIMSW 6 d27 6 a32 1 #define HELPSW 7 d47 3 a49 2 int subjsort; /* sort on subject if != 0 */ u_long datelimit = ~0; d53 1 a53 1 static int dsort(), read_hdrs (), subsort(); d108 7 d116 1 a116 1 subjsort = 1; d119 1 a119 1 subjsort = 0; d125 6 d136 2 a137 1 datelimit = ~0; /* should be MAXINT ? */ d192 7 a198 1 qsort ((char *) dlist, nmsgs, sizeof(*dlist), dsort); d200 4 d209 1 a209 1 if (subjsort) { d256 2 a257 1 (*s)->s_clock - s[-1]->s_clock <= datelimit) { d340 1 a340 1 else if (subjsort && uleq (nam, "subject")) { d405 13 a417 11 while (c = *cp++) { if (! isspace(c)) { if ((c == 'r' || c == 'R') && (cp[0] == 'e' || cp[0] == 'E') && cp[1] == ':') cp += 2; else { if (isalpha(c)) *cp2++ = islower(c)? c : tolower(c); break; a419 1 } d471 15 @ 1.8 log @typo @ text @d463 1 a463 1 printf ("message %s becomes message %s\n", old, new); @ 1.7 log @typo and add -nosubject @ text @d444 1 a444 2 static void rename_chain (mp, mlist, msg, endmsg) d446 3 a448 2 struct smsg **mlist; int msg, endmsg; d463 1 a463 1 printf ("message %s becomes message %s\n", f2, f1); @ 1.6 log @typo @ text @d22 2 d25 1 a25 1 #define LIMSW 4 d27 2 a28 2 #define NLIMSW 5 "nolimit", 0 d30 1 a30 1 #define HELPSW 6 d107 3 @ 1.5 log @add -nolimit @ text @d111 1 a111 1 adios (NULLCP, "impossible limit %d", outputlinelen); @ 1.4 log @make -verbose messages more standard @ text @d25 2 d28 1 a28 1 #define HELPSW 5 d41 1 a41 1 int nmsgs; d43 3 a45 3 int subjsort; /* sort on subject if != 0 */ u_long datelimit = ~0; int verbose; d109 3 a111 3 adios (NULLCP, "missing argument to %s", argp[-2]); if (! isdigit(*cp) || !(datelimit = atoi(cp))) adios (NULLCP, "non-zero number must follow %s", argp[-2]); d113 3 @ 1.3 log @big rewrite -- sort by subject too! @ text @d453 1 a453 1 printf (" %s becomes %s\n", oldname, newname); d501 1 a501 1 printf ("renaming chain from %d to %d\n", old, new); @ 1.2 log @ANSI Compilance @ text @d2 1 d7 3 a10 2 /* */ d12 2 a13 2 #define DATESW 0 "datefield field", 0, d15 4 a18 4 #define VERBSW 1 "verbose", 0, #define NVERBSW 2 "noverbose", 0, d20 2 a21 2 #define HELPSW 3 "help", 4, d23 7 a29 1 NULL, NULL a31 2 /* */ d33 3 a35 2 int s_msg; struct tws s_tws; d39 1 d41 3 d45 3 a47 1 static int msgsort (); a48 7 static struct tws *getws (); static int read_dates(); static file_dates(); long time (); a50 2 /* ARGSUSED */ d52 2 a53 2 int argc; char **argv; d55 1 a55 2 int verbosw = 0, msgp = 0, d57 1 a57 1 msgnum; d59 8 a66 8 *maildir, *datesw = NULL, *folder = NULL, buf[100], **ap, **argp, *arguments[MAXARGS], *msgs[MAXARGS]; d68 1 a79 2 /* */ d83 10 a92 10 case AMBIGSW: ambigsw (cp, switches); done (1); case UNKWNSW: adios (NULLCP, "-%s unknown", cp); case HELPSW: (void) sprintf (buf, "%s [+folder] [msgs] [switches]", invo_name); help (buf, switches); done (1); d94 6 a99 6 case DATESW: if (datesw) adios (NULLCP, "only one date field at a time!"); if (!(datesw = *argp++) || *datesw == '-') adios (NULLCP, "missing argument to %s", argp[-2]); continue; d101 18 a118 6 case VERBSW: verbosw++; continue; case NVERBSW: verbosw = 0; continue; a129 2 /* */ d135 1 a135 1 datesw = "Date"; d144 1 a144 1 if (mp -> hghmsg == 0) d152 1 a152 1 if ((i = read_dates (mp, datesw)) <= 0) a153 2 qsort ((char *) smsgs, i, sizeof *smsgs, msgsort); file_dates (mp, verbosw); d155 76 a233 1 d237 4 a240 5 /* */ static int read_dates (mp, datesw) register struct msgs *mp; register char *datesw; d242 2 a243 2 int msgnum; struct tws tb; a244 1 register struct tws *tw; d248 3 a250 3 smsgs = (struct smsg *) calloc ((unsigned) (mp -> hghsel - mp -> lowsel + 2), sizeof *smsgs); d255 6 a260 5 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++) { tw = NULL; if (mp -> msgstats[msgnum] & SELECTED) { if ((tw = getws (datesw, msgnum)) == NULL) tw = msgnum != mp -> lowsel ? &((s - 1) -> s_tws) : &tb; a261 9 else if (mp -> msgstats[msgnum] & EXISTS) tw = &tb; if (tw) { s -> s_msg = msgnum; twscopy (&s -> s_tws, tw); s++; } d263 2 a264 3 s -> s_msg = 0; return (s - smsgs); d267 5 a271 5 /* */ static struct tws *getws (datesw, msg) register char *datesw; int msg; d273 5 a277 6 int compnum, state; register char *hp, *msgnam; char buf[BUFSIZ], nam[NAMESZ]; d279 3 a281 1 register FILE *in; d285 1 a285 1 return NULL; d287 1 a287 4 /* */ for (compnum = 1, state = FLD, hp = NULL;;) { d289 6 a294 7 case FLD: case FLDEOF: case FLDPLUS: compnum++; if (hp != NULL) free (hp), hp = NULL; hp = add (buf, NULLCP); d297 1 a297 1 hp = add (buf, hp); d299 1 a299 1 if (uleq (nam, datesw)) d301 16 a316 2 if (state != FLDEOF) continue; d318 4 a321 4 case BODY: case BODYEOF: case FILEEOF: admonish (NULLCP, "no %s field in message %d", datesw, msg); d323 11 a333 10 case LENERR: case FMTERR: if (state == LENERR || state == FMTERR) admonish (NULLCP, "format error in message %d(header #%d)", msg, compnum); if (hp != NULL) free (hp); (void) fclose (in); return NULL; d335 2 a336 2 default: adios (NULLCP, "internal error -- you lose"); d341 2 a342 3 if ((tw = dparsetime (hp)) == NULL) admonish (NULLCP, "unable to parse %s field in message %d", datesw, msg); d344 49 a392 2 if (hp != NULL) free (hp); d394 4 a397 1 return tw; d400 17 a416 1 /* */ d418 7 a424 3 static int msgsort (a, b) register struct smsg *a, *b; d426 6 a431 1 return twsort (&a -> s_tws, &b -> s_tws); d434 11 a444 1 /* */ d446 24 a469 3 static file_dates (mp, verbosw) register struct msgs *mp; int verbosw; d471 9 a479 7 register int i, j, k; short stats; char f1[BUFSIZ], f2[BUFSIZ], tmpfil[BUFSIZ]; d483 3 a485 7 for (i = 0; j = smsgs[i++].s_msg;) if (i != j) { (void) strcpy (f1, m_name (i)); (void) strcpy (f2, m_name (j)); if (mp -> msgstats[i] & EXISTS) { if (verbosw) printf ("swap messages %s and %s\n", f2, f1); d487 3 a489 4 if (rename (f1, tmpfil) == NOTOK) { admonish (tmpfil, "unable to rename %s to ", f1); continue; } d491 8 a498 4 if (rename (f2, f1) == NOTOK) { admonish (f1, "unable to rename %s to", f2); continue; } d500 2 a501 4 if (rename (tmpfil, f2) == NOTOK) { admonish (f2, "unable to rename %s to", tmpfil); continue; } d503 3 a505 9 for (k = i; smsgs[k].s_msg; k++) if (smsgs[k].s_msg == i) { smsgs[k].s_msg = j; break; } } else { if (verbosw) printf ("message %s becomes message %s\n", f2, f1); d507 3 a509 5 if (rename (f2, f1) == NOTOK) { admonish (f1, "unable to rename %s to ", f2); continue; } } d511 3 a513 8 smsgs[i - 1].s_msg = i; stats = mp -> msgstats[i]; mp -> msgstats[i] = mp -> msgstats[j]; mp -> msgstats[j] = stats; if (mp -> curmsg == j) m_setcur (mp, i); mp -> msgflags |= SEQMOD; } @ 1.1 log @Initial revision @ text @d34 1 a34 1 int msgsort (); d36 1 a36 1 struct tws *getws (); d38 2 @