shithub: Nail

Download patch

ref: 5379327ffc8239978258eacff93188200d055d4f
parent: 08f307994bcfc1e6df93db072d621f570a757514
author: Ori Bernstein <[email protected]>
date: Tue Nov 10 09:55:43 EST 2020

Remove custom expansion: plumb instead

--- a/comp.c
+++ b/comp.c
@@ -94,7 +94,7 @@
 static void
 compmain(void *cp)
 {
-	char *a, *f[32];
+	char *f[32];
 	int nf;
 	Event ev;
 	Comp *c, **pc;
@@ -114,13 +114,10 @@
 		switch(ev.type){
 		case 'l':
 		case 'L':
-			if((a = matchaddr(&mbox, &ev)) != nil)
-				compose(a, nil, 0, 0);
-			else if(matchmesg(&mbox, ev.text))
+			if(matchmesg(&mbox, ev.text))
 				mesgopen(ev.text, nil);
-			else if(!(ev.flags & 0x2))
+			else
 				winreturn(c, &ev);
-			free(a);
 			break;
 		case 'x':
 		case 'X':
--- a/mail.h
+++ b/mail.h
@@ -30,8 +30,9 @@
 struct Event {
 	char	action;
 	char	type;
-	int	q0;
-	int	q1;
+	int	p0;	/* click point */
+	int	q0;	/* expand lo */
+	int	q1;	/* expand hi */
 	int	flags;
 	int	ntext;
 	char	text[Eventsz + 1];
@@ -160,7 +161,6 @@
 void	winreturn(Win*, Event*);
 int	wineval(Win*, char*, ...);
 int	winread(Win*, int, int, char*, int);
-char	*matchaddr(Win*, Event*);
 int	matchmesg(Win*, char*);
 char	*winreadsel(Win*);
 void	wingetsel(Win*, int*, int*);
--- a/mbox.c
+++ b/mbox.c
@@ -32,6 +32,8 @@
 Reprog	*mesgpat;
 
 int	threadsort = 1;
+int	sender;
+
 int	plumbsendfd;
 int	plumbseemailfd;
 int	plumbshowmailfd;
@@ -451,7 +453,7 @@
 			dots = "...";
 		}
 
-		Bprint(bfd, "%-6s\t%s %s%*.*s%s\t«%s»\n",
+		Bprint(bfd, "%-6s\t%s %s%*.*s%s\t<%s>\n",
 			m->name,
 			flag, sep, -width, width,
 			m->subject,
@@ -733,7 +735,7 @@
 static void
 doevent(Event *ev)
 {
-	char *a, *f[32];
+	char *f[32];
 	int nf;
 	Fn *p;
 
@@ -742,13 +744,10 @@
 	switch(ev->type){
 	case 'l':
 	case 'L':
-		if((a = matchaddr(&mbox, ev)) != nil)
-			compose(a, nil, 0, 0);
-		else if(matchmesg(&mbox, ev->text))
+		if(matchmesg(&mbox, ev->text))
 			mesgopen(ev->text, nil);
-		else if((ev->flags & 0x2) == 0)
+		else
 			winreturn(&mbox, ev);
-		free(a);
 		break;
 	case 'x':
 	case 'X':
@@ -802,7 +801,6 @@
 			plumbfree(pshow);
 			break;
 		case Csendmail:
-			print("got plumb: %s\n", psend->data);
 			compose(psend->data, nil, 0, 0);
 			plumbfree(psend);
 			break;
@@ -829,36 +827,45 @@
 	case 'T':
 		mbox.view = Vflat;
 		break;
+	case 's':
+		sender++;
+		break;
+
 	default:
 		usage();
 		break;
 	}ARGEND;
 
+	if(argc > 1)
+		usage();
+	if(argc == 1)
+		mailbox = argv[0];
+
 	doquote = needsrcquote;
 	quotefmtinstall();
 	tmfmtinstall();
-	/* open these early so we won't miss notification of new mail messages while we read mbox */
-	plumbsendfd = plumbopen("send", OWRITE|OCEXEC);
-	plumbseemailfd = plumbopen("seemail", OREAD|OCEXEC);
-	plumbshowmailfd = plumbopen("showmail", OREAD|OCEXEC);
-	plumbsendmailfd = plumbopen("sendmail", OREAD|OCEXEC);
+
+	addrpat = regcomp("[^ \t]*@[^ \t]*\\.[^ \t]*");
+	mesgpat = regcomp("[0-9]+(/.*)?");
+	cwait = threadwaitchan();
+
+	/* open these early so we won't miss messages while loading */
 	mbox.event = chancreate(sizeof(Event*), 0);
 	mbox.see = chancreate(sizeof(Plumbmsg*), 0);
 	mbox.show = chancreate(sizeof(Plumbmsg*), 0);
 	mbox.send = chancreate(sizeof(Plumbmsg*), 0);
 
-	addrpat = regcomp("[^ \t]*@[^ \t]*\\.[^ \t]*");
-	mesgpat = regcomp("[0-9]+(/.*)?");
-	cwait = threadwaitchan();
+	plumbsendfd = plumbopen("send", OWRITE|OCEXEC);
+	plumbseemailfd = plumbopen("seemail", OREAD|OCEXEC);
+	plumbshowmailfd = plumbopen("showmail", OREAD|OCEXEC);
 
-	if(argc > 1)
-		usage();
-	if(argc == 1)
-		mailbox = argv[0];
 	mbload();
 	proccreate(plumbseemail, nil, Stack);
 	proccreate(plumbshowmail, nil, Stack);
-	proccreate(plumbsendmail, nil, Stack);
+	if(sender || strcmp(mailbox, "mbox") == 0){
+		plumbsendmailfd = plumbopen("sendmail", OREAD|OCEXEC);
+		proccreate(plumbsendmail, nil, Stack);
+	}
 	threadcreate(mbmain, nil, Stack);
 	threadexits(nil);
 }
--- a/mesg.c
+++ b/mesg.c
@@ -379,7 +379,7 @@
 static void
 mesgmain(void *mp)
 {
-	char *a, *path, *f[32];
+	char *path, *f[32];
 	Event ev;
 	Mesg *m, **pm;
 	Fn *p;
@@ -406,13 +406,10 @@
 		switch(ev.type){
 		case 'l':
 		case 'L':
-			if((a = matchaddr(m, &ev)) != nil)
-				compose(a, nil, 0, 0);
-			else if(matchmesg(m, ev.text))
+			if(matchmesg(m, ev.text))
 				mesgopen(ev.text, nil);
-			else if((ev.flags & 0x2) == 0)
+			else
 				winreturn(m, &ev);
-			free(a);
 			break;
 		case 'x':
 		case 'X':
--- a/win.c
+++ b/win.c
@@ -59,6 +59,10 @@
 int
 winevent(Win *w, Event *e)
 {
+	int flags;
+
+	flags = 0;
+Again:
 	e->action = Bgetc(w->event);
 	e->type = Bgetc(w->event);
 	e->q0 = evgetnum(w->event);
@@ -69,6 +73,13 @@
 		werrstr("unterminated message");
 		return -1;
 	}
+//fprint(2, "event: %c%c %d %d %x %.*s\n", e->action, e->type, e->q0, e->q1, e->flags, e->ntext, e->text);
+	if(e->flags & 0x2){
+		e->p0 = e->q0;
+		flags = e->flags;
+		goto Again;
+	}
+	e->flags |= flags;
 	return e->action;
 }
 
@@ -75,7 +86,10 @@
 void
 winreturn(Win *w, Event *e)
 {
-	fprint(w->revent, "%c%c%d %d\n", e->action, e->type, e->q0, e->q1);
+	if(e->flags & 0x2)
+		fprint(w->revent, "%c%c%d %d\n", e->action, e->type, e->p0, e->p0);
+	else
+		fprint(w->revent, "%c%c%d %d\n", e->action, e->type, e->q0, e->q1);
 }
 
 int
@@ -259,47 +273,6 @@
 {
 	fprint(w->addr, "#%d,#%d", q0, q1);
 	fprint(w->ctl, "dot=addr");
-}
-
-static char*
-expandaddr(Win *w, Event *e)
-{
-	static char *delim = "/[ \t\\n<>«»()\\[\\]]/";
-	char *s;
-	int q0, q1, ns;
-
-	if(e->type != 'L' || e->q0 != e->q1)
-		return nil;
-
-	q0 = wineval(w, "#%d-%s", e->q0, delim);
-	if(q0 == -1)	/* bad char not found */
-		q0 = 0;
-	else			/* increment past bad char */
-		q0++;
-
-	q1 = wineval(w, "#%d+%s", e->q0, delim);
-	if(q1 < 0){
-		q1 = wineval(w, "$");
-		if(q1 < 0)
-			return nil;
-	}
-	if(q0 >= q1)
-		return nil;
-	ns = (q1-q0)*UTFmax+1;
-	s = emalloc(ns);
-	winread(w, q0, q1, s, ns);
-	return s;
-}
-
-char*
-matchaddr(Win *w, Event *e)
-{
-	char *s;
-
-	if((s = expandaddr(w, e)) != nil)
-		if(regexec(addrpat, s, nil, 0))
-			return s;
-	return nil;
 }
 
 int