9front - general discussion about 9front
 help / color / mirror / Atom feed
From: qwx@sciops.net
To: 9front@9front.org
Subject: Re: [9front] delete in page(1)
Date: Fri, 31 Dec 2021 21:10:13 +0200	[thread overview]
Message-ID: <05E1EE387D50B7795E24DCDAA0C33033@wopr.sciops.net> (raw)
In-Reply-To: <AC3E61AEB5AB5963BF3A02C73DB836A3@prosimetrum.com>

On Fri Dec 31 04:16:49 +0200 2021, umbraticus@prosimetrum.com wrote:
> hmm, still messes up. what I am doing:
> 1. plumb 1.jpg, opens in new page
> 2. press d
> 3. plumb 2.jpg → shows image
> 
> can continue to plumb new images but b3menu doesn't open
> and prev/next doesn't work.
> 
> Also, maybe at least have the key be D instead of d to prevent mistakes...
> 
> umbraticus

Here's a patched patch fixing this and another issue;  it
also has the delete command on the `D' key as suggested and
has a separate `pop' command on the `p' key to only remove
an entry from the list, without deleting the file.  Thoughts?

Thanks,
qwx


diff 855cf4326f5a07d7142c2d8918f5fa856d912b85 uncommitted
--- a/sys/src/cmd/page.c
+++ b/sys/src/cmd/page.c
@@ -74,7 +74,10 @@
 	Czerox,
 	Cwrite,
 	Cext,
+	Cpop,
 	Cdummy2,
+	Cdelete,
+	Cdummy3,
 	Cquit,
 };
 
@@ -98,7 +101,10 @@
 	[Czerox]	"zerox",	'z', 0, 0,
 	[Cwrite]	"write",	'w', 0, 0,
 	[Cext]		"ext",		'x', 0, 0,
+	[Cpop]		"pop",		'p', 0, 0,
 	[Cdummy2]	"",		0, 0, 0,
+	[Cdelete]	"delete",	'D', 0, 0,
+	[Cdummy3]	"",		0, 0, 0,
 	[Cquit]		"quit",		'q', Kdel, Keof,
 };
 
@@ -134,6 +140,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 +993,71 @@
 	}
 }
 
+/* page entries are never freed, there's no point
+ * and would break everything */
+Page*
+poppage(Page *p)
+{
+	Page *t, *q;
+
+	if(p == nil)
+		return nil;
+	if(p->up != root)
+		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;
+	t = prevpage(p);
+	if(root->tail == p)
+		root->tail = t;
+	if(root->down == p || t == nil)
+		root->down = p->next;
+	else
+		t->next = p->next;
+	qunlock(&pagelock);
+	qunlock(p);
+	if(p->next != nil){
+		forward = 1;
+		return p->next;
+	}
+	forward = -1;
+	return t;
+}
+
+Page*
+delpage(Page *p)
+{
+	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;
+	}
+	return poppage(p);
+}
+
 /*
  * 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 +1533,7 @@
 	char buf[NPATH], *s;
 	Point o;
 	int fd;
+	Page *p;
 
 	switch(i){
 	case Corigsize:
@@ -1546,6 +1619,28 @@
 	case Csnarf:
 		writeaddr(current, "/dev/snarf");
 		break;
+	case Cpop:
+		if(current == nil || !canqlock(current))
+			break;
+		if((p = poppage(current)) == current)
+			break;
+	Reset:
+		current = p;
+		if(current == nil){
+			drawlock(0);
+			draw(screen, screen->r, paper, nil, ZP);
+			drawframe(screen->r);
+			drawlock(1);
+			break;
+		}
+		showpage(current);
+		break;
+	case Cdelete:
+		if(current == nil || !canqlock(current))
+			break;
+		if((p = delpage(current)) == current)
+			break;
+		goto Reset;
 	case Cnext:
 		forward = 1;
 		showpage(nextpage(current));

  reply	other threads:[~2021-12-31 19:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2022-01-01 10:42         ` umbraticus
2022-01-02  0:20           ` qwx
2022-01-02  1:19             ` umbraticus
     [not found] <E7A7795549A08A34B4881C447544CF63@wopr.sciops.net>
2022-01-21  8:10 ` umbraticus
2022-01-23  1:06   ` qwx

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=05E1EE387D50B7795E24DCDAA0C33033@wopr.sciops.net \
    --to=qwx@sciops.net \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).