mthread: add -r to reverse top-level order

pull/150/head
Leah Neukirchen 4 years ago
parent a5c77c71bc
commit 62da7c59ea

@ -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

@ -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);
}

Loading…
Cancel
Save