From 42c3794c5c073b6ef22671ef4aca16428d3894aa Mon Sep 17 00:00:00 2001 From: rsc Date: Sun, 17 Oct 2004 04:06:56 +0000 Subject: fix interrupt handling, add clumsy way to get at text buffer contents --- src/cmd/9term/9term.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 3 deletions(-) (limited to 'src/cmd/9term/9term.c') diff --git a/src/cmd/9term/9term.c b/src/cmd/9term/9term.c index f183f115..5af25469 100644 --- a/src/cmd/9term/9term.c +++ b/src/cmd/9term/9term.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -11,8 +12,17 @@ #include #include "term.h" +enum +{ + STACK = 32768 +}; + int noecho = 0; +void servedevtext(void); +void listenthread(void*); +void textthread(void*); + typedef struct Text Text; typedef struct Readbuf Readbuf; @@ -238,6 +248,8 @@ threadmain(int argc, char *argv[]) initdraw(0, nil, "9term"); notify(hangupnote); + notifyatsig(SIGCHLD, 1); + servedevtext(); mc = initmouse(nil, screen); kc = initkeyboard(nil); @@ -860,6 +872,10 @@ key(Rune r) case 0x05: show(t.nr); return; + + /* + * Non-standard extensions. + */ case CUT: snarf(); cut(); @@ -880,12 +896,12 @@ key(Rune r) } switch(r) { - case 0x03: /* ^C: send interrupt */ + /* case 0x03: can't do this because ^C is COPY */ case 0x7F: /* DEL: send interrupt */ + paste(&r, 1, 1); t.qh = t.q0 = t.q1 = t.nr; show(t.q0); - // postnote(PNGROUP, x, "interrupt"); - write(rcfd, "\x7F", 1); + postnote(PNGROUP, rcpid, "interrupt"); return; } @@ -1820,3 +1836,76 @@ rawon(void) return !cooked && !isecho(sfd); } +/* + * Clumsy hack to make " and "" work. + * Then again, what's not a clumsy hack here in Unix land? + */ + +char adir[100]; +int afd; + +void +servedevtext(void) +{ + char buf[100]; + + snprint(buf, sizeof buf, "unix!/tmp/9term-text.%d", getpid()); + + if((afd = announce(buf, adir)) < 0){ + putenv("text9term", ""); + return; + } + + putenv("text9term", buf); + threadcreate(listenthread, nil, STACK); +} + +void +listenthread(void *arg) +{ + int fd; + char dir[100]; + + USED(arg); + for(;;){ + fd = threadlisten(adir, dir); + if(fd < 0){ + close(afd); + return; + } + threadcreate(textthread, (void*)fd, STACK); + } +} + +void +textthread(void *arg) +{ + int fd, i, x, n, end; + Rune r; + char buf[4096], *p, *ep; + + fd = (int)arg; + p = buf; + ep = buf+sizeof buf; + end = t.org+t.nr; /* avoid possible output loop */ + for(i=t.org;; i++){ + if(i >= end || ep-p < UTFmax){ + for(x=0; x= end) + break; + p = buf; + } + if(i < t.org) + i = t.org; + r = t.r[i-t.org]; + if(r < Runeself) + *p++ = r; + else + p += runetochar(p, &r); + } +break2: + close(fd); +} -- cgit v1.2.3