URI: 
       tmore - plan9port - [fork] Plan 9 from user space
  HTML git clone git://src.adamsgaard.dk/plan9port
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit c935adc6a2b4bcaa1729edf50ed91bfce9c0df91
   DIR parent f535642f304ebfec5182ab97be53e1fbf23056dc
  HTML Author: rsc <devnull@localhost>
       Date:   Thu, 10 Nov 2005 23:21:06 +0000
       
       more
       
       Diffstat:
         M src/cmd/9term/9term.c               |     103 ++++++++++++++++++++++++++++++-
       
       1 file changed, 101 insertions(+), 2 deletions(-)
       ---
   DIR diff --git a/src/cmd/9term/9term.c b/src/cmd/9term/9term.c
       t@@ -34,6 +34,7 @@ void rcoutputproc(void*);
        void        rcinputproc(void*);
        void hangupnote(void*, char*);
        void resizethread(void*);
       +void        servedevtext(void);
        
        int errorshouldabort = 0;
        
       t@@ -89,7 +90,6 @@ threadmain(int argc, char *argv[])
                initdraw(derror, nil, "9term");
                notify(hangupnote);
                noteenable("sys: child");
       -//        servedevtext();
                
                mousectl = initmouse(nil, screen);
                if(mousectl == nil)
       t@@ -109,7 +109,8 @@ threadmain(int argc, char *argv[])
                threadcreate(keyboardthread, nil, STACK);
                threadcreate(mousethread, nil, STACK);
                threadcreate(resizethread, nil, STACK);
       -        
       +        servedevtext();
       +
                proccreate(rcoutputproc, nil, STACK);
                proccreate(rcinputproc, nil, STACK);
        }
       t@@ -169,12 +170,18 @@ keyboardthread(void *v)
        void
        resizethread(void *v)
        {
       +        Point p;
       +        
                USED(v);
                
                while(recv(mousectl->resizec, nil) == 1){
                        if(getwindow(display, Refnone) < 0)
                                sysfatal("can't reattach to window");
                        wresize(w, screen, 0);
       +                p = stringsize(display->defaultfont, "0");
       +                if(p.x && p.y)
       +                        updatewinsize(Dy(screen->r)/p.y, Dx(screen->r)/p.x, 
       +                                Dx(screen->r), Dy(screen->r));
                }
        }
                                
       t@@ -503,6 +510,9 @@ rcinputproc(void *arg)
                }
        }
        
       +/*
       + * Snarf buffer - rio uses runes internally
       + */
        void
        rioputsnarf(void)
        {
       t@@ -530,3 +540,92 @@ riogetsnarf(void)
                cvttorunes(s, n, snarf, &nb, &nsnarf, &nulls);
                free(s);
        }
       +
       +/*
       + * Clumsy hack to make " and "" work.
       + * Then again, what's not a clumsy hack here in Unix land?
       + */
       +
       +char adir[100];
       +char thesocket[100];
       +int afd;
       +
       +void listenproc(void*);
       +void textproc(void*);
       +
       +void
       +removethesocket(void)
       +{
       +        if(thesocket[0])
       +                if(remove(thesocket) < 0)
       +                        fprint(2, "remove %s: %r\n", thesocket);
       +}
       +
       +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);
       +        proccreate(listenproc, nil, STACK);
       +        strcpy(thesocket, buf+5);
       +        atexit(removethesocket);
       +}
       +
       +void
       +listenproc(void *arg)
       +{
       +        int fd;
       +        char dir[100];
       +
       +        USED(arg);
       +        for(;;){
       +                fd = listen(adir, dir);
       +                if(fd < 0){
       +                        close(afd);
       +                        return;
       +                }
       +                proccreate(textproc, (void*)fd, STACK);
       +        }
       +}
       +
       +void
       +textproc(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 = w->org+w->nr;        /* avoid possible output loop */
       +        for(i=w->org;; i++){
       +                if(i >= end || ep-p < UTFmax){
       +                        for(x=0; x<p-buf; x+=n)
       +                                if((n = write(fd, buf+x, (p-x)-buf)) <= 0)
       +                                        goto break2;
       +                        
       +                        if(i >= end)
       +                                break;
       +                        p = buf;
       +                }
       +                if(i < w->org)
       +                        i = w->org;
       +                r = w->r[i-w->org];
       +                if(r < Runeself)
       +                        *p++ = r;
       +                else
       +                        p += runetochar(p, &r);
       +        }
       +break2:
       +        close(fd);
       +}
       +