From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.4 Received: (qmail 27032 invoked from network); 2 Jan 2022 00:28:15 -0000 Received: from 4ess.inri.net (216.126.196.42) by inbox.vuxu.org with ESMTPUTF8; 2 Jan 2022 00:28:15 -0000 Received: from wopr.sciops.net ([216.126.196.60]) by 4ess; Sat Jan 1 19:20:53 -0500 2022 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sciops.net; s=20210706; t=1641082839; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to; bh=Wl/U/OoPRGIkZOWJSIak5EtznSpy1Zqpc/etECTG670=; b=zsGELnWDd4RZ/oW/56cAhAvVJ8nud+oHHn31NqNl2lIfbZ+DCsT3/J0aeVV2E9WbZGjTPB nIvq01Z90EG3w+H8VIjWPi6pI9TY+wVKPilViLt3MWEXrV40vPeb0K2kyq4dxSvKmN+Yfz POhnwDmU5RrTZXuCUD/O5FDz7gVa3NY= Received: by wopr.sciops.net (OpenSMTPD) with ESMTPSA id b9d41246 (TLSv1.2:ECDHE-RSA-CHACHA20-POLY1305:256:NO) for <9front@9front.org>; Sat, 1 Jan 2022 16:20:38 -0800 (PST) Message-ID: <243435E940FFD9CE8577463D11CC0708@wopr.sciops.net> Date: Sun, 02 Jan 2022 02:20:39 +0200 From: qwx@sciops.net To: 9front@9front.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: rails-oriented scripting-oriented strategy rails Subject: Re: [9front] delete in page(1) Reply-To: 9front@9front.org Precedence: bulk On Sat Jan 1 12:50:01 +0200 2022, umbraticus@prosimetrum.com wrote: > Nice work, thanks! I like the isolation in the menu too. > > I found another nit :) > > Popping a doc eg. /sys/doc/troff.ps works fine > if you are at the root window of the document > (the grey one with name of the file in a box) > and popping from within the doc doesn't work, > which is fine if that's how you want it to behave > but if I open the doc, try to pop from eg. page 3, > then go back to the root and try to pop from > there things hang... > > umbraticus Thanks for testing! Just another locking fuckup, a bit of a nightmare. qwx diff c4e30bede2f79c42dacb8c91713abf4a4d91c45c 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,32 @@ case Csnarf: writeaddr(current, "/dev/snarf"); break; + case Cpop: + if(current == nil || !canqlock(current)) + break; + if((p = poppage(current)) == current){ + qunlock(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){ + qunlock(current); + break; + } + goto Reset; case Cnext: forward = 1; showpage(nextpage(current));