ref: 51063a83b904375296509c9b08cc887d9cf1b3a1
parent: 3af13d52b0e2e5f608de7c0d34d7ce515830ec0e
author: qwx <qwx@sciops.net>
date: Sat Apr 25 16:26:48 EDT 2020
remove silly cmdrect patch and add some kvik-forked sam tweaks (ham)
--- /dev/null
+++ b/sam-fullfrontalnudity
@@ -1,0 +1,97 @@
+diff -Naur a/sys/src/cmd/sam/cmd.c b/sys/src/cmd/sam/cmd.c
+--- a/sys/src/cmd/sam/cmd.c Sun Mar 15 22:31:10 2020
++++ b/sys/src/cmd/sam/cmd.c Tue Feb 4 05:48:08 2020
+@@ -35,7 +35,7 @@
+ '>', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd,
+ '<', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd,
+ '|', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd,
+- '^', 0, 0, 0, 0, aNo, 0, linex, plan9_cmd,
++ '^', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd,
+ '_', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd,
+ '=', 0, 0, 0, 0, aDot, 0, linex, eq_cmd,
+ 'c'|0x100,0, 0, 0, 0, aNo, 0, wordx, cd_cmd,
+diff -Naur a/sys/src/cmd/sam/mesg.c b/sys/src/cmd/sam/mesg.c
+--- a/sys/src/cmd/sam/mesg.c Mon Apr 30 05:09:33 2012
++++ b/sys/src/cmd/sam/mesg.c Tue Feb 4 05:48:08 2020
+@@ -349,6 +349,12 @@
+ f = whichfile(inshort());
+ p0 = inlong();
+ journaln(0, p0);
++ int fd = open("/dev/snarf", OREAD);
++ if(fd < 0)
++ panic("paste: open");
++ bufreset(&snarfbuf);
++ bufload(&snarfbuf, 0, fd, &i);
++ close(fd);
+ for(l=0; l<snarfbuf.nc; l+=m){
+ m = snarfbuf.nc-l;
+ if(m>BLOCKSIZE)
+@@ -576,7 +582,9 @@
+ snarf(File *f, Posn p1, Posn p2, Buffer *buf, int emptyok)
+ {
+ Posn l;
+- int i;
++ int i, fd, n;
++ String *s;
++ char *cs;
+
+ if(!emptyok && p1==p2)
+ return;
+@@ -586,11 +594,23 @@
+ fprint(2, "bad snarf addr p1=%ld p2=%ld f->nc=%d\n", p1, p2, f->nc); /*ZZZ should never happen, can remove */
+ p2 = f->nc;
+ }
++ fd = open("/dev/snarf", OWRITE);
++ if(fd < 0){
++ fprint(2, "snarf: %r\n");
++ return;
++ }
+ for(l=p1; l<p2; l+=i){
+ i = p2-l>BLOCKSIZE? BLOCKSIZE : p2-l;
+ bufread(f, l, genbuf, i);
+- bufinsert(buf, buf->nc, tmprstr(genbuf, i)->s, i);
++ s = tmprstr(genbuf, i);
++ cs = Strtoc(s);
++ n = strlen(cs);
++ if(write(fd, cs, n) != n)
++ fprint(2, "snarf: %r\n");
++ free(cs);
++ bufinsert(buf, buf->nc, s->s, i);
+ }
++ close(fd);
+ }
+
+ int
+diff -Naur a/sys/src/cmd/sam/shell.c b/sys/src/cmd/sam/shell.c
+--- a/sys/src/cmd/sam/shell.c Sun Mar 15 22:31:10 2020
++++ b/sys/src/cmd/sam/shell.c Tue Feb 4 05:48:08 2020
+@@ -13,8 +13,7 @@
+ static void
+ updateenv(File *f)
+ {
+- static int fd = -1;
+- int n;
++ int n, fd;
+ char buf[64], *p, *e;
+
+ if(f == nil){
+@@ -33,7 +32,6 @@
+ p = seprint(p+1, e, "%lud", f->dot.r.p1);
+ p = seprint(p+1, e, "%lud", f->dot.r.p2);
+ n = p - buf;
+- if(fd == -1)
+ if((fd = create("/env/%dot", OWRITE, 0666)) < 0)
+ fprint(2, "updateenv create: %r\n");
+ if(write(fd, buf, n) != n)
+diff -Naur a/sys/src/cmd/sam/xec.c b/sys/src/cmd/sam/xec.c
+--- a/sys/src/cmd/sam/xec.c Sun Mar 15 22:31:10 2020
++++ b/sys/src/cmd/sam/xec.c Tue Feb 4 05:48:08 2020
+@@ -26,7 +26,7 @@
+ if(f && f->unread)
+ load(f);
+ if(f==0 && (cp->addr==0 || cp->addr->type!='"') &&
+- !utfrune("bBnqUXY!^", cp->cmdc) &&
++ !utfrune("bBnqUXY!", cp->cmdc) &&
+ cp->cmdc!=('c'|0x100) && !(cp->cmdc=='D' && cp->ctext))
+ error(Enofile);
+ i = lookup(cp->cmdc);
--- a/samterm-cmdrect
+++ /dev/null
@@ -1,14 +1,0 @@
-diff -r 16e46e6fee1e sys/src/cmd/samterm/main.c
---- a/sys/src/cmd/samterm/main.c Thu Oct 05 20:33:46 2017 +0200
-+++ b/sys/src/cmd/samterm/main.c Sat Oct 07 06:32:03 2017 +0200
-@@ -42,7 +42,9 @@
- scratch = alloc(100*RUNESIZE);
- nscralloc = 100;
- r = screen->r;
-- r.max.y = r.min.y+Dy(r)/5;
-+ if(Dx(r) > 8*80+FLMARGIN+FLSCROLLWID)
-+ r.max.x = r.min.x + 8*80+FLMARGIN+FLSCROLLWID;
-+ r.max.y = r.min.y+Dy(r)/6;
- flstart(screen->clipr);
- rinit(&cmd.rasp);
- flnew(&cmd.l[0], gettext, 1, &cmd);
--- /dev/null
+++ b/samterm-fullfrontalnudity
@@ -1,0 +1,321 @@
+diff -Naur a/sys/src/cmd/samterm/flayer.h b/sys/src/cmd/samterm/flayer.h
+--- a/sys/src/cmd/samterm/flayer.h Wed Jan 18 01:12:54 2012
++++ b/sys/src/cmd/samterm/flayer.h Tue Feb 4 05:48:08 2020
+@@ -42,9 +42,9 @@
+ void flupfront(Flayer*);
+ Flayer *flwhich(Point);
+
+-#define FLMARGIN 4
++#define FLMARGIN 1
+ #define FLSCROLLWID 12
+-#define FLGAP 4
++#define FLGAP 0
+
+ extern Image *maincols[NCOL];
+ extern Image *cmdcols[NCOL];
+diff -Naur a/sys/src/cmd/samterm/main.c b/sys/src/cmd/samterm/main.c
+--- a/sys/src/cmd/samterm/main.c Wed Apr 22 22:51:59 2020
++++ b/sys/src/cmd/samterm/main.c Fri Feb 21 23:51:07 2020
+@@ -42,7 +42,7 @@
+ scratch = alloc(100*RUNESIZE);
+ nscralloc = 100;
+ r = screen->r;
+- r.max.y = r.min.y+Dy(r)/5;
++ r.max.y = r.min.y+(6*font->height)+(3*FLMARGIN);
+ flstart(screen->clipr);
+ rinit(&cmd.rasp);
+ flnew(&cmd.l[0], gettext, 1, &cmd);
+@@ -235,30 +235,64 @@
+ getmouse();
+ }
+
+-int
+-getr(Rectangle *rp)
++Rectangle
++inflatepoint(Point p)
+ {
+- Point p;
++ Rectangle *c;
+ Rectangle r;
+-
+- *rp = getrect(3, mousectl);
+- if(rp->max.x && rp->max.x-rp->min.x<=5 && rp->max.y-rp->min.y<=5){
+- p = rp->min;
+- r = cmd.l[cmd.front].entire;
+- *rp = screen->r;
+- if(cmd.nwin==1){
+- if (p.y <= r.min.y)
+- rp->max.y = r.min.y;
+- else if (p.y >= r.max.y)
+- rp->min.y = r.max.y;
+- if (p.x <= r.min.x)
+- rp->max.x = r.min.x;
+- else if (p.x >= r.max.x)
+- rp->min.x = r.max.x;
+- }
++
++ r = screen->r;
++ c = &cmd.l[cmd.front].entire;
++ if(ptinrect(p, *c))
++ return r;
++ // L
++ if(p.x < c->min.x)
++ r.max.x = c->min.x;
++ // R
++ else if(p.x >= c->max.x)
++ r.min.x = c->max.x;
++ // M
++ else{
++ r.min.x = c->min.x;
++ r.max.x = c->max.x;
++ // A
++ if(p.y <= c->min.y)
++ r.max.y = c->min.y;
++ // B
++ else
++ r.min.y = c->max.y;
+ }
+- return rectclip(rp, screen->r) &&
+- rp->max.x-rp->min.x>100 && rp->max.y-rp->min.y>40;
++ return r;
++}
++
++Rectangle
++defaultrect(void)
++{
++ Rectangle *c;
++ Rectangle L, M, R;
++
++ c = &cmd.l[cmd.front].entire;
++ L = inflatepoint(Pt(c->min.x - 1, c->min.y));
++ M = inflatepoint(Pt(c->min.x, c->max.y));
++ R = inflatepoint(Pt(c->max.x + 1, c->min.y));
++ if(Dx(L) >= Dx(M) && Dx(L) >= Dx(R))
++ return L;
++ else if(Dx(M) > Dx(L) && Dx(M) > Dx(R))
++ return M;
++ return R;
++}
++
++int
++promptrect(Rectangle *r)
++{
++ *r = getrect(3, mousectl);
++ if(eqrect(*r, Rect(0,0,0,0)))
++ return 0;
++ if(Dx(*r) < 5 && Dy(*r) < 5)
++ *r = inflatepoint(r->min);
++ if(rectclip(r, screen->r) == 0)
++ *r = defaultrect();
++ return 1;
+ }
+
+ void
+@@ -298,11 +332,9 @@
+ void
+ paste(Text *t, int w)
+ {
+- if(snarflen){
+- cut(t, w, 0, 0);
+- t->lock++;
+- outTsl(Tpaste, t->tag, t->l[w].p0);
+- }
++ cut(t, w, 0, 0);
++ t->lock++;
++ outTsl(Tpaste, t->tag, t->l[w].p0);
+ }
+
+ void
+diff -Naur a/sys/src/cmd/samterm/menu.c b/sys/src/cmd/samterm/menu.c
+--- a/sys/src/cmd/samterm/menu.c Wed Jan 18 01:12:54 2012
++++ b/sys/src/cmd/samterm/menu.c Fri Feb 21 23:51:07 2020
+@@ -27,7 +27,6 @@
+ Snarf,
+ Plumb,
+ Look,
+- Exch,
+ Search,
+ NMENU2 = Search,
+ Send = Search,
+@@ -50,7 +49,6 @@
+ "snarf",
+ "plumb",
+ "look",
+- "<rio>",
+ 0, /* storage for last pattern */
+ };
+
+@@ -97,12 +95,6 @@
+ outTsll(Tplumb, t->tag, which->p0, which->p1);
+ break;
+
+- case Exch:
+- snarf(t, w);
+- outT0(Tstartsnarf);
+- setlock();
+- break;
+-
+ case Look:
+ outTsll(Tlook, t->tag, which->p0, which->p1);
+ setlock();
+@@ -127,58 +119,43 @@
+ int m, i;
+ Text *t;
+
++ l = flwhich(mousep->xy);
+ mw = -1;
+ switch(m = menuhit(3, mousectl, &menu3, nil)){
+ case -1:
+ break;
+
+ case New:
+- if(!hostlock)
+- sweeptext(1, 0);
++ if(hostlock)
++ break;
++ sweeptext(1, 0);
+ break;
+
+ case Zerox:
+ case Resize:
+- if(!hostlock){
+- setcursor(mousectl, &bullseye);
+- buttons(Down);
+- if((mousep->buttons&4) && (l = flwhich(mousep->xy)) && getr(&r))
+- duplicate(l, r, l->f.font, m==Resize);
+- else
+- setcursor(mousectl, cursor);
+- buttons(Up);
+- }
++ if(hostlock || l == nil)
++ break;
++ if(promptrect(&r))
++ duplicate(l, r, l->f.font, m == Resize);
+ break;
+
+ case Close:
+- if(!hostlock){
+- setcursor(mousectl, &bullseye);
+- buttons(Down);
+- if((mousep->buttons&4) && (l = flwhich(mousep->xy)) && !hostlock){
+- t=(Text *)l->user1;
+- if (t->nwin>1)
+- closeup(l);
+- else if(t!=&cmd) {
+- outTs(Tclose, t->tag);
+- setlock();
+- }
+- }
+- setcursor(mousectl, cursor);
+- buttons(Up);
++ if(hostlock || l == nil)
++ break;
++ t=(Text *)l->user1;
++ if (t->nwin>1)
++ closeup(l);
++ else if(t!=&cmd) {
++ outTs(Tclose, t->tag);
++ setlock();
+ }
+ break;
+
+ case Write:
+- if(!hostlock){
+- setcursor(mousectl, &bullseye);
+- buttons(Down);
+- if((mousep->buttons&4) && (l = flwhich(mousep->xy))){
+- outTs(Twrite, ((Text *)l->user1)->tag);
+- setlock();
+- }else
+- setcursor(mousectl, cursor);
+- buttons(Up);
+- }
++ if(hostlock || l == nil)
++ break;
++ outTs(Twrite, ((Text *)l->user1)->tag);
++ setlock();
+ break;
+
+ default:
+@@ -198,30 +175,31 @@
+ }
+ }
+
+-
+ Text *
+ sweeptext(int new, int tag)
+ {
+ Rectangle r;
+ Text *t;
+
+- if(getr(&r) && (t = malloc(sizeof(Text)))){
+- memset((void*)t, 0, sizeof(Text));
+- current((Flayer *)0);
+- flnew(&t->l[0], gettext, 0, (char *)t);
+- flinit(&t->l[0], r, font, maincols); /*bnl*/
+- t->nwin = 1;
++ if((t = mallocz(sizeof(*t), 1)) == nil)
++ return nil;
++ if(new)
++ r = inflatepoint(mousep->xy);
++ else
++ r = defaultrect();
++ current((Flayer *)0);
++ flnew(&t->l[0], gettext, 0, (char *)t);
++ flinit(&t->l[0], r, font, maincols); /*bnl*/
++ t->nwin = 1;
++ rinit(&t->rasp);
++ if(new)
++ startnewfile(Tstartnewfile, t);
++ else{
+ rinit(&t->rasp);
+- if(new)
+- startnewfile(Tstartnewfile, t);
+- else{
+- rinit(&t->rasp);
+- t->tag = tag;
+- startfile(t);
+- }
+- return t;
++ t->tag = tag;
++ startfile(t);
+ }
+- return 0;
++ return t;
+ }
+
+ int
+diff -Naur a/sys/src/cmd/samterm/samterm.h b/sys/src/cmd/samterm/samterm.h
+--- a/sys/src/cmd/samterm/samterm.h Wed Apr 22 22:51:59 2020
++++ b/sys/src/cmd/samterm/samterm.h Fri Feb 21 23:51:07 2020
+@@ -119,7 +119,6 @@
+ int center(Flayer*, long);
+ int xmenuhit(int, Menu*);
+ void buttons(int);
+-int getr(Rectangle*);
+ void current(Flayer*);
+ void duplicate(Flayer*, Rectangle, Font*, int);
+ void startfile(Text*);
+@@ -163,6 +162,9 @@
+ void dumperrmsg(int, int, int, int);
+ int screensize(int*,int*);
+ void getmouse(void);
++Rectangle inflatepoint(Point);
++Rectangle defaultrect(void);
++int promptrect(Rectangle*);
+
+ #include "mesg.h"
+
+diff -Naur a/sys/src/cmd/samterm/scroll.c b/sys/src/cmd/samterm/scroll.c
+--- a/sys/src/cmd/samterm/scroll.c Wed Apr 22 22:15:05 2020
++++ b/sys/src/cmd/samterm/scroll.c Tue Feb 4 05:48:08 2020
+@@ -111,9 +111,6 @@
+ int x, y, my, oy, h;
+ long p0;
+
+- if(l->visible==None)
+- return;
+-
+ s = l->scroll;
+ x = s.min.x+FLSCROLLWID/2;
+ scr = scrpos(l->scroll, l->origin, l->origin+l->f.nchars, tot);