From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from feline.systems ([99.23.220.214]) by ewsd; Wed Oct 24 01:28:40 EDT 2018 Date: Wed, 24 Oct 2018 05:27:04 +0000 From: BurnZeZ@feline.systems To: 9front@9front.org Subject: patch: proof(1) runification Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="upas-iktjehhwejbvhnqumiyetswstq" List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: patented realtime table descriptor This is a multi-part message in MIME format. --upas-iktjehhwejbvhnqumiyetswstq Content-Disposition: inline Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit It was already using runes, but in a dumb broken way. Things added: left/right arrow key navigation Kesc to clear the command line Kdel exits --upas-iktjehhwejbvhnqumiyetswstq Content-Disposition: attachment; filename=proof.diff Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit diff -r ff28f1376a7a sys/src/cmd/proof/htroff.c --- a/sys/src/cmd/proof/htroff.c Mon Oct 22 00:16:04 2018 +0200 +++ b/sys/src/cmd/proof/htroff.c Wed Oct 24 05:14:50 2018 +0000 @@ -29,7 +29,7 @@ int curfont, cursize; -char *getcmdstr(void); +Rune *getcmdstr(void); static void initpage(void); static void view_setup(int); @@ -335,8 +335,9 @@ char *p; int i; - if (gotop == curp) +/* if (gotop == curp) return 1; +* is there a case where this works? */ for (i = 0; i < npagenums; i++) if (pagenums[i].num == gotop) { if (seekc(pagenums[i].adr) == Beof) { @@ -484,18 +485,20 @@ static int botpage(int np) /* called at bottom of page np-1 == top of page np */ { - char *p; + char buf[64]; + Rune *r; int n; - while (p = getcmdstr()) { - if (*p == '\0') + while (r = getcmdstr()) { + if (*r == '\0') return 0; - if (*p == 'q') - exits(p); - if (*p == 'c') /* nop */ + if (*r == 'q') + exits(nil); + if (*r == 'c') /* nop */ continue; - if (*p == 'm') { - mag = atof(p+1); + if (*r == 'm') { + snprint(buf, sizeof(buf), "%S", r+1); + mag = atof(buf); if (mag <= .1 || mag >= 10) mag = DEFMAG; allfree(); /* zap fonts */ @@ -505,47 +508,52 @@ mag = res/(100.0*DIV); return skipto(np-1, np); /* reprint the page */ } - if (*p == 'x') { - xyoffset.x += atoi(p+1)*100; + if (*r == 'x') { + snprint(buf, sizeof(buf), "%S", r+1); + xyoffset.x += atoi(buf)*100; skipto(np-1, np); return 1; } - if (*p == 'y') { - xyoffset.y += atoi(p+1)*100; + if (*r == 'y') { + snprint(buf, sizeof(buf), "%S", r+1); + xyoffset.y += atoi(buf)*100; skipto(np-1, np); return 1; } - if (*p == '/') { /* divide into n pieces */ - nview = atoi(p+1); + if (*r == '/') { /* divide into n pieces */ + snprint(buf, sizeof(buf), "%S", r+1); + nview = atoi(buf); if (nview < 1) nview = 1; else if (nview > MAXVIEW) nview = MAXVIEW; return skipto(np-1, np); } - if (*p == 'p') { - if (p[1] == '\0'){ /* bare 'p' */ + if (*r == 'p') { + if (r[1] == '\0'){ /* bare 'p' */ if(skipto(np-1, np)) return 1; continue; } - p++; + r++; } - if ('0'<=*p && *p<='9') { - n = atoi(p); + if ('0'<=*r && *r<='9') { + snprint(buf, sizeof(buf), "%S", r); + n = atoi(buf); if(skipto(n, np)) return 1; continue; } - if (*p == '-' || *p == '+') { - n = atoi(p); + if (*r == '-' || *r == '+') { + snprint(buf, sizeof(buf), "%S", r); + n = atoi(buf); if (n == 0) - n = *p == '-' ? -1 : 1; + n = *r == '-' ? -1 : 1; if(skipto(np - 1 + n, np)) return 1; continue; } - if (*p == 'd') { + if (*r == 'd') { dbg = 1 - dbg; continue; } diff -r ff28f1376a7a sys/src/cmd/proof/proof.h --- a/sys/src/cmd/proof/proof.h Mon Oct 22 00:16:04 2018 +0200 +++ b/sys/src/cmd/proof/proof.h Wed Oct 24 05:14:50 2018 +0000 @@ -22,7 +22,7 @@ void mapscreen(void); void clearscreen(void); -char *getcmdstr(void); +Rune *getcmdstr(void); void readmapfile(char *); void dochar(Rune*); @@ -42,4 +42,4 @@ #define dprint if (dbg) fprint extern int dbg; -extern int resized; \ No newline at end of file +extern int resized; diff -r ff28f1376a7a sys/src/cmd/proof/screen.c --- a/sys/src/cmd/proof/screen.c Mon Oct 22 00:16:04 2018 +0200 +++ b/sys/src/cmd/proof/screen.c Wed Oct 24 05:14:50 2018 +0000 @@ -4,12 +4,13 @@ #include #include #include +#include #include "proof.h" static int checkmouse(void); static int buttondown(void); -static char *getmousestr(void); -static char *getkbdstr(int); +static Rune *getmousestr(void); +static Rune *getkbdstr(Rune); extern Cursor blot; extern char *track; @@ -46,9 +47,7 @@ string(screen, p, display->black, ZP, font, buf); } -#define Viewkey 0xb2 - -char * +Rune * getcmdstr(void) { Event ev; @@ -70,7 +69,7 @@ e = event(&ev); if(resized){ resized = 0; - return "p"; + return L"p"; } if ((e & Emouse) && ev.mouse.buttons) { mouse = ev.mouse; @@ -81,7 +80,7 @@ if((dir = dirstat(track)) != nil){ if(tracktm < dir->mtime){ free(dir); - return "q"; + return L"q"; } free(dir); } @@ -89,28 +88,31 @@ } } -static char * -getkbdstr(int c0) +static Rune * +getkbdstr(Rune r) { - static char buf[100]; - char *p; - int c; + static Rune buf[100]; + int i; - if (c0 == '\n') - return ""; - buf[0] = c0; - buf[1] = 0; - screenprint("%s", buf); - for (p = buf+1; (c = ekbd()) != '\n' && c != '\r' && c != -1 && c != Viewkey; ) { - if (c == '\b' && p > buf) { - *--p = ' '; - } else { - *p++ = c; - *p = 0; + buf[0] = '\0'; + for (i=0; r != '\n'; r=ekbd()) { + switch(r){ + case '\b': + if(i == 0) + continue; + buf[--i] = '\0'; + break; + case Kdel: exits(nil); + case Kesc: return L"p"; + case Kleft: return L"-1"; + case Kright: return L"+1"; + case Runeerror: continue; + default: + buf[i++] = r; + buf[i] = '\0'; } - screenprint("%s", buf); + screenprint("%S", buf); } - *p = 0; return buf; } @@ -148,7 +150,8 @@ int last_hit; int last_but; -char *pan(void) +Rune * +pan(void) { Point dd, xy, lastxy, min, max; @@ -181,45 +184,45 @@ xyoffset = addpt(xyoffset, subpt(mouse.xy, xy)); esetcursor(0); - return "p"; + return L"p"; } -static char * +static Rune * getmousestr(void) { - static char buf[64]; + static Rune buf[64]; checkmouse(); if (last_but == 1) - return "p"; /* repaint after panning */ + return L"p"; /* repaint after panning */ if (last_but == 2) { - return "c"; + return L"c"; } else if (last_but == 3) { switch (last_hit) { case Next: - return ""; + return L""; case Prev: - return "-1"; + return L"-1"; case Page: screenprint("page? "); - return "c"; + return L"c"; case Again: - return "p"; + return L"p"; case Bigger: - snprint(buf, sizeof buf, "m%g", mag * 1.1); + runesnprint(buf, sizeof buf, "m%g", mag * 1.1); return buf; case Smaller: - snprint(buf, sizeof buf, "m%g", mag / 1.1); + runesnprint(buf, sizeof buf, "m%g", mag / 1.1); return buf; case Pan: return pan(); case Quit: - return "q"; + return L"q"; default: - return "c"; + return L"c"; } } else { /* button 1 or bail out */ - return "c"; + return L"c"; } } --upas-iktjehhwejbvhnqumiyetswstq--