9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] delete in page(1)
@ 2021-12-30 23:15 qwx
  2021-12-31  0:48 ` umbraticus
  0 siblings, 1 reply; 11+ messages in thread
From: qwx @ 2021-12-30 23:15 UTC (permalink / raw)
  To: 9front

Hi,

I wrote a patch allowing one to remove(2) the current file
directly from page(1) with the `d' key.  I've needed this
for instance for pruning image albums, especially with
shuffled lists, etc.  I've tried other strategies instead
of adding this, but they all sucked.

I don't know if anyone wants this merged since it doesn't
seem like something people do much, but in any case here
it is.  Thoughts and comments appreciated as always.

Prost,
qwx


diff 855cf4326f5a07d7142c2d8918f5fa856d912b85 uncommitted
--- a//sys/src/cmd/page.c
+++ b//sys/src/cmd/page.c
@@ -74,6 +74,7 @@
 	Czerox,
 	Cwrite,
 	Cext,
+	Cdel,
 	Cdummy2,
 	Cquit,
 };
@@ -98,6 +99,7 @@
 	[Czerox]	"zerox",	'z', 0, 0,
 	[Cwrite]	"write",	'w', 0, 0,
 	[Cext]		"ext",		'x', 0, 0,
+	[Cdel]		"del",		'd', 0, 0,
 	[Cdummy2]	"",		0, 0, 0,
 	[Cquit]		"quit",		'q', Kdel, Keof,
 };
@@ -134,6 +136,7 @@
 void showpage(Page *);
 void drawpage(Page *);
 Point pagesize(Page *);
+void drawlock(int);
 
 Page*
 addpage(Page *up, char *name, int (*popen)(Page *), void *pdata, int fd)
@@ -986,6 +989,54 @@
 	}
 }
 
+/* page entries are never freed, there's no point
+ * and would break everything */
+Page*
+delpage(Page *p)
+{
+	Page *t, *q;
+
+	if(p == nil)
+		return nil;
+	/* to remove(2) subpages in documents makes no sense, and just
+	 * removing a subentry doesn't seem like a feature worth the bother */
+	if(p->up != root)
+		return p;
+	if(p->fd >= 0)
+		close(p->fd);
+	p->fd = -1;
+	if(remove(p->name) < 0){
+		fprint(2, "remove %s: %r", p->name);
+		return p;
+	}
+	qlock(&pagelock);
+	for(t = p->down; t != nil && t->up != root; t = q){
+		qlock(t);
+		drawlock(0);
+		unloadpage(t);
+		drawlock(1);
+		free(t->name);
+		free(t->data);
+		t->name = t->data = nil;
+		q = nextpage(t);
+		qunlock(t);
+	}
+	drawlock(0);
+	unloadpage(p);
+	drawlock(1);
+	free(p->name);
+	free(p->data);
+	p->name = p->data = nil;
+	if(root->down != p){
+		t = prevpage(p);
+		t->next = p->next;
+	}else
+		root->down = p->next;
+	qunlock(&pagelock);
+	qunlock(p);
+	return p->next != nil ? p->next : t;
+}
+
 /*
  * A draw operation that touches only the area contained in bot but not in top.
  * mp and sp get aligned with bot.min.
@@ -1461,6 +1512,7 @@
 	char buf[NPATH], *s;
 	Point o;
 	int fd;
+	Page *p;
 
 	switch(i){
 	case Corigsize:
@@ -1545,6 +1597,17 @@
 		break;
 	case Csnarf:
 		writeaddr(current, "/dev/snarf");
+		break;
+	case Cdel:
+		if(current == nil || !canqlock(current))
+			break;
+		if((p = delpage(current)) == current)
+			break;
+		current = p;
+		if(current == nil)
+			break;
+		forward = 1;
+		showpage(current);
 		break;
 	case Cnext:
 		forward = 1;

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-01-23 10:09 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <E7A7795549A08A34B4881C447544CF63@wopr.sciops.net>
2022-01-21  8:10 ` [9front] delete in page(1) umbraticus
2022-01-23  1:06   ` qwx
2021-12-30 23:15 qwx
2021-12-31  0:48 ` umbraticus
2021-12-31  1:09   ` qwx
2021-12-31  1:22   ` qwx
2021-12-31  2:05     ` umbraticus
2021-12-31 19:10       ` qwx
2022-01-01 10:42         ` umbraticus
2022-01-02  0:20           ` qwx
2022-01-02  1:19             ` umbraticus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).