shithub: Nail

Download patch

ref: 6092354e9384faab64454e7f6b1c9ead84676f90
parent: de53a2e1ed55e81c0f9823f14304f85f6531a49b
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Nov 3 13:44:02 EST 2020

tweak sorting: threads go newest too oldest

--- a/mail.h
+++ b/mail.h
@@ -47,7 +47,7 @@
 };
 
 /*
- * A composing message.
+ * In progress compositon
  */
 struct Comp {
 	Win;
@@ -72,7 +72,7 @@
 };
 
 /*
- * A message in the mailbox
+ * Message in mailbox
  */
 struct Mesg {
 	Win;
--- a/mbox.c
+++ b/mbox.c
@@ -99,10 +99,15 @@
 	return b->time - a->time;
 }
 
-static void
-mbsort(void)
+static int
+rcmpmesg(void *pa, void *pb)
 {
-	qsort(mbox.mesg, mbox.nmesg, sizeof(Mesg*), cmpmesg);
+	Mesg *a, *b;
+
+	a = *(Mesg**)pa;
+	b = *(Mesg**)pb;
+
+	return a->time - b->time;
 }
 
 static int
@@ -163,6 +168,7 @@
 		q->nsub++;
 	p->child = erealloc(p->child, ++p->nchild*sizeof(Mesg*));
 	p->child[p->nchild - 1] = m;
+	qsort(p->child, p->nchild, sizeof(Mesg*), rcmpmesg);
 	m->parent = p;
 	return 1;
 }
@@ -410,6 +416,7 @@
 				load(d[i].name, nil, 0);
 		free(d);
 	}
+	qsort(mbox.mesg, mbox.nmesg, sizeof(Mesg*), cmpmesg);	
 }
 
 static void
@@ -646,7 +653,6 @@
 	{nil}
 };
 
-
 static void
 doevent(Event *ev)
 {
@@ -760,8 +766,7 @@
 	if(argc == 1)
 		mailbox = argv[0];
 	mbload();
-	mbsort();
-	
+
 	threadcreate(mbmain, nil, Stack);
 	proccreate(plumbsee, nil, Stack);
 	proccreate(plumbshow, nil, Stack);