From: qwx@sciops.net
To: 9front@9front.org
Subject: Re: [9front] delete in page(1)
Date: Sun, 23 Jan 2022 02:06:49 +0100 [thread overview]
Message-ID: <3C8884F6BBE0B93D0C93B16F93BD589F@wopr.sciops.net> (raw)
In-Reply-To: <54BF37272CB09CDCF27C49908F804900@prosimetrum.com>
> I like this new feature too but am able to crash by popping pages of
> a large pdf. At first I thought it only happened when the whole doc
> had not yet loaded but I think it may also occur even when every
> thing is in memory. Of course being able to drop pages from a pdf is
> probably of questionable utility...
In fact it occurs all the time in pdfs, probably elsewhere. It's a
stupid bug that should be fixed with this new patch. The patch
actually doesn't distinguish between pages of a pdf or files in a
subdirectory. Previously, you couldn't pop or delete anything that
wasn't directly at the root, meaning that if you did `page $dir',
you would not be able to do anything to pages under $dir. Hopefully
this thing is done and dusted for now...
Thanks,
qwx
diff 9d43029ff984435111eff658308a44b4f3eee1cc 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)
@@ -987,6 +994,72 @@
}
}
+/* doesn't actually free the page entry or touch links to avoid breakage */
+Page*
+freepage(Page *p, Page *prev)
+{
+ Page *next, *up;
+
+ drawlock(0);
+ unloadpage(p);
+ drawlock(1);
+ if(p->fd >= 0)
+ close(p->fd);
+ p->fd = -1;
+ /* not touching p->data */
+ free(p->name);
+ p->name = nil;
+ p->open = nil;
+ next = nextpage(p);
+ up = p->up;
+ if(up->down == p){
+ if(up->tail != p)
+ up->down = next;
+ else
+ up->down = nil;
+ }else if(up->tail == p){
+ up->tail = prev;
+ prev->next = nil;
+ }else
+ prev->next = next;
+ return next;
+}
+
+Page*
+poppage(Page *p, int del)
+{
+ Page *t, *prev, *next;
+
+ if(p == nil)
+ return nil;
+ if(p == root)
+ return p;
+ if(del){
+ if(!(access(p->name, OREAD) == 0 && remove(p->name) == 0
+ || p->data != nil && access(p->data, OREAD) == 0 && remove(p->data) == 0)){
+ fprint(2, "remove %s: %r", p->name);
+ return p;
+ }
+ }
+ qlock(&pagelock);
+ for(t = p->down, prev = p; t != nil && t->up != p->up; prev = t, t = next){
+ qlock(t);
+ next = freepage(t, prev);
+ qunlock(t);
+ }
+ p->down = nil;
+ prev = prevpage(p);
+ next = freepage(p, prev);
+ qunlock(&pagelock);
+ qunlock(p);
+ if(next != nil){
+ forward = 1;
+ return next;
+ }
+ forward = -1;
+ return prev;
+}
+
/*
* A draw operation that touches only the area contained in bot but not in top.
* mp and sp get aligned with bot.min.
@@ -1462,8 +1535,10 @@
{
char buf[NPATH], *s;
Point o;
- int fd;
+ int fd, del;
+ Page *p;
+ del = 0;
switch(i){
case Corigsize:
pos = ZP;
@@ -1547,6 +1622,25 @@
break;
case Csnarf:
writeaddr(current, "/dev/snarf");
+ break;
+ case Cdelete:
+ del = 1;
+ /* wet floor */
+ case Cpop:
+ if(current == nil || !canqlock(current))
+ break;
+ if((p = poppage(current, del)) == current){
+ qunlock(current);
+ break;
+ }
+ if((current = p) == nil){
+ drawlock(0);
+ draw(screen, screen->r, paper, nil, ZP);
+ drawframe(screen->r);
+ drawlock(1);
+ break;
+ }
+ showpage(current);
break;
case Cnext:
forward = 1;
next prev parent reply other threads:[~2022-01-23 10:09 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <E7A7795549A08A34B4881C447544CF63@wopr.sciops.net>
2022-01-21 8:10 ` umbraticus
2022-01-23 1:06 ` qwx [this message]
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
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=3C8884F6BBE0B93D0C93B16F93BD589F@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).