diff --git a/man/mthread.1 b/man/mthread.1 index 7f0e0f9..cb2c29a 100644 --- a/man/mthread.1 +++ b/man/mthread.1 @@ -1,4 +1,4 @@ -.Dd July 22, 2016 +.Dd May 4, 2020 .Dt MTHREAD 1 .Os .Sh NAME @@ -7,6 +7,7 @@ .Sh SYNOPSIS .Nm .Op Fl v +.Op Fl r .Op Fl S Ar msg .Op Ar msgs\ ... .Sh DESCRIPTION @@ -33,6 +34,8 @@ The options are as follows: .Bl -tag -width Ds .It Fl v Do not prune unresolved Message-IDs at the top-level. +.It Fl r +Sort the top-level threads in reverse order (newest threads first). .It Fl S Ar msg Treat .Ar msg diff --git a/mthread.c b/mthread.c index 70b36b3..300fcae 100644 --- a/mthread.c +++ b/mthread.c @@ -21,6 +21,7 @@ #include "blaze822.h" static int vflag; +static int rflag; static int optional; struct container { @@ -347,6 +348,12 @@ dateorder(const void *a, const void *b) return 0; } +static int +reverse_dateorder(const void *a, const void *b) +{ + return dateorder(b, a); +} + void sort_tree(struct container *c, int depth) { @@ -366,7 +373,8 @@ sort_tree(struct container *c, int depth) for (r = c->child, i = 0; r; r = r->next, i++) a[i] = r; - qsort(a, i, sizeof (struct container *), dateorder); + qsort(a, i, sizeof (struct container *), + rflag && depth < 0 ? reverse_dateorder : dateorder); c->child = a[0]; for (j = 0; j+1 < i; j++) @@ -410,12 +418,13 @@ main(int argc, char *argv[]) optional = 1; - while ((c = getopt(argc, argv, "S:v")) != -1) + while ((c = getopt(argc, argv, "S:rv")) != -1) switch (c) { case 'S': blaze822_loop1(optarg, thread); break; case 'v': vflag = 1; break; + case 'r': rflag = 1; break; default: - fprintf(stderr, "Usage: mthread [-v] [-S dir] [msgs...]\n"); + fprintf(stderr, "Usage: mthread [-v] [-r] [-S dir] [msgs...]\n"); exit(1); }