tacme: sync against Plan 9, remove -$ option - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 734a96bd1691395765ceae0bf9afa86bda8ab07b
 (DIR) parent 7927fe8f9efb61c7bcdfc63997a4e785c97c53ef
 (HTM) Author: Russ Cox <rsc@swtch.com>
       Date:   Fri,  7 Mar 2008 10:45:59 -0500
       
       acme: sync against Plan 9, remove -$ option
       
       Diffstat:
         M src/cmd/acme/ecmd.c                 |       2 +-
         M src/cmd/acme/edit.c                 |      22 ++++++++++------------
         M src/cmd/acme/edit.h                 |       4 +---
         M src/cmd/acme/fsys.c                 |      15 ---------------
         M src/cmd/acme/look.c                 |      43 ++++++++++---------------------
         M src/cmd/acme/util.c                 |       9 ++-------
         M src/cmd/acme/wind.c                 |     224 ++-----------------------------
       
       7 files changed, 38 insertions(+), 281 deletions(-)
       ---
 (DIR) diff --git a/src/cmd/acme/ecmd.c b/src/cmd/acme/ecmd.c
       t@@ -1322,7 +1322,7 @@ cmdname(File *f, String *str, int set)
                }else{
                        newname = dirname(f->curtext, runestrdup(s), n);
                        n = newname.nr;
       -                r = runemalloc(n+1);
       +                r = runemalloc(n+1);        /* NUL terminate */
                        runemove(r, newname.r, n);
                        free(newname.r);
                }
 (DIR) diff --git a/src/cmd/acme/edit.c b/src/cmd/acme/edit.c
       t@@ -82,8 +82,6 @@ editthread(void *v)
                USED(v);
                threadsetname("editthread");
                while((cmdp=parsecmd(0)) != 0){
       -/*                ocurfile = curfile; */
       -/*                loaded = curfile && !curfile->unread; */
                        if(cmdexec(curtext, cmdp) == 0)
                                break;
                        freecmd();
       t@@ -257,11 +255,11 @@ growlist(List *l)
        {
                if(l->u.listptr==0 || l->nalloc==0){
                        l->nalloc = INCR;
       -                l->u.listptr = emalloc(INCR*sizeof(long));
       +                l->u.listptr = emalloc(INCR*sizeof(void*));
                        l->nused = 0;
                }else if(l->nused == l->nalloc){
       -                l->u.listptr = erealloc(l->u.listptr, (l->nalloc+INCR)*sizeof(long));
       -                memset((void*)(l->u.longptr+l->nalloc), 0, INCR*sizeof(long));
       +                l->u.listptr = erealloc(l->u.listptr, (l->nalloc+INCR)*sizeof(void*));
       +                memset(l->u.ptr+l->nalloc, 0, INCR*sizeof(void*));
                        l->nalloc += INCR;
                }
        }
       t@@ -272,7 +270,7 @@ growlist(List *l)
        void
        dellist(List *l, int i)
        {
       -        memmove(&l->u.longptr[i], &l->u.longptr[i+1], (l->nused-(i+1))*sizeof(long));
       +        memmove(&l->u.ptr[i], &l->u.ptr[i+1], (l->nused-(i+1))*sizeof(void*));
                l->nused--;
        }
        
       t@@ -280,11 +278,11 @@ dellist(List *l, int i)
         * Add a new element, whose position is i, to the list
         */
        void
       -inslist(List *l, int i, long val)
       +inslist(List *l, int i, void *v)
        {
                growlist(l);
       -        memmove(&l->u.longptr[i+1], &l->u.longptr[i], (l->nused-i)*sizeof(long));
       -        l->u.longptr[i] = val;
       +        memmove(&l->u.ptr[i+1], &l->u.ptr[i], (l->nused-i)*sizeof(void*));
       +        l->u.ptr[i] = v;
                l->nused++;
        }
        
       t@@ -320,7 +318,7 @@ newcmd(void){
                Cmd *p;
        
                p = emalloc(sizeof(Cmd));
       -        inslist(&cmdlist, cmdlist.nused, (long)p);
       +        inslist(&cmdlist, cmdlist.nused, p);
                return p;
        }
        
       t@@ -330,7 +328,7 @@ newstring(int n)
                String *p;
        
                p = allocstring(n);
       -        inslist(&stringlist, stringlist.nused, (long)p);
       +        inslist(&stringlist, stringlist.nused, p);
                return p;
        }
        
       t@@ -340,7 +338,7 @@ newaddr(void)
                Addr *p;
        
                p = emalloc(sizeof(Addr));
       -        inslist(&addrlist, addrlist.nused, (long)p);
       +        inslist(&addrlist, addrlist.nused, p);
                return p;
        }
        
 (DIR) diff --git a/src/cmd/acme/edit.h b/src/cmd/acme/edit.h
       t@@ -65,11 +65,9 @@ struct List        /* code depends on a long being able to hold a pointer */
                int        nused;
                union{
                        void        *listptr;
       -                Block        *blkptr;
       -                long        *longptr;
       +                void*        *ptr;
                        uchar*        *ucharptr;
                        String*        *stringptr;
       -                File*        *fileptr;
                } u;
        };
        
 (DIR) diff --git a/src/cmd/acme/fsys.c b/src/cmd/acme/fsys.c
       t@@ -289,11 +289,7 @@ respond(Xfid *x, Fcall *t, char *err)
                        x->buf = emalloc(messagesize);
                n = convS2M(t, x->buf, messagesize);
                if(n <= 0)
       -{
       -fprint(2, "convert error (n=%d, msgsize %d): have %F\n", n, messagesize, &x->fcall);
       -fprint(2, "\tresponse: %F\n", t);
                        error("convert error in convS2M");
       -}
                if(write(sfd, x->buf, n) != n)
                        error("write error in respond");
                free(x->buf);
       t@@ -467,10 +463,6 @@ fsyswalk(Xfid *x, Fid *f)
                                goto Accept;
                
            Regular:
       -/*
       -                        if(FILE(f->qid) == Qacme)        // empty directory
       -                                break;
       -*/
                                if(strcmp(x->fcall.wname[i], "new") == 0){
                                        if(w)
                                                error("w set in walk to new");
       t@@ -732,13 +724,6 @@ newfid(int fid)
        uint
        getclock(void)
        {
       -/*
       -        char buf[32];
       -
       -        buf[0] = '\0';
       -        pread(clockfd, buf, sizeof buf, 0);
       -        return atoi(buf);
       -*/        
                return time(0);
        }
        
 (DIR) diff --git a/src/cmd/acme/look.c b/src/cmd/acme/look.c
       t@@ -16,7 +16,7 @@
        CFid *plumbsendfid;
        CFid *plumbeditfid;
        
       -Window*        openfile(Text*, Expand*, int);
       +Window*        openfile(Text*, Expand*);
        
        int        nuntitled;
        
       t@@ -195,7 +195,7 @@ look3(Text *t, uint q0, uint q1, int external)
                if(expanded == FALSE)
                        return;
                if(e.name || e.u.at)
       -                openfile(t, &e, FALSE);
       +                openfile(t, &e);
                else{
                        if(t->w == nil)
                                return;
       t@@ -225,7 +225,7 @@ plumbgetc(void *a, uint n)
                Rune *r;
        
                r = a;
       -        if(n<0 || n>runestrlen(r))
       +        if(n>runestrlen(r))
                        return 0;
                return r[n];
        }
       t@@ -235,7 +235,6 @@ plumblook(Plumbmsg *m)
        {
                Expand e;
                char *addr;
       -        int newwindow;
        
                if(m->ndata >= BUFSIZE){
                        warning(nil, "insanely long file name (%d bytes) in plumb message (%.32s...)\n", m->ndata, m->data);
       t@@ -256,8 +255,7 @@ plumblook(Plumbmsg *m)
                        e.u.ar = bytetorune(addr, &e.a1);
                        e.agetc = plumbgetc;
                }
       -        newwindow = plumblookup(m->attr, "newwindow") != nil;
       -        openfile(nil, &e, newwindow);
       +        openfile(nil, &e);
                free(e.name);
                free(e.u.at);
                drawtopwindow();
       t@@ -485,8 +483,6 @@ dirname(Text *t, Rune *r, int n)
                b = nil;
                if(t==nil || t->w==nil)
                        goto Rescue;
       -        if(dodollarsigns && n>=1 && r[0]=='$')
       -                expandenv(&r, (uint*)&n);
                nt = t->w->tag.file->b.nc;
                if(nt == 0)
                        goto Rescue;
       t@@ -504,12 +500,9 @@ dirname(Text *t, Rune *r, int n)
                }
                if(slash < 0)
                        goto Rescue;
       -        slash++;
       -        if(dodollarsigns && expandenv(&b, (uint*)&slash))
       -                b = runerealloc(b, slash+n);
       -        runemove(b+slash, r, n);
       +        runemove(b+slash+1, r, n);
                free(r);
       -        return cleanrname(runestr(b, slash+n));
       +        return cleanrname(runestr(b, slash+1+n));
        
            Rescue:
                free(b);
       t@@ -570,7 +563,7 @@ expandfile(Text *t, uint q0, uint q1, Expand *e)
                if(n == 0)
                        return FALSE;
                /* see if it's a file name */
       -        r = runemalloc(n+1);        /* +1 for possible $ below */
       +        r = runemalloc(n);
                bufread(&t->file->b, q0, r, n);
                /* first, does it have bad chars? */
                nname = -1;
       t@@ -586,12 +579,9 @@ expandfile(Text *t, uint q0, uint q1, Expand *e)
                }
                if(nname == -1)
                        nname = n;
       -        for(i=0; i<nname; i++){
       -                if(dodollarsigns && i==0 && r[0]=='$')
       -                        continue;
       +        for(i=0; i<nname; i++)
                        if(!isfilec(r[i]))
                                goto Isntfile;
       -        }
                /*
                 * See if it's a file name in <>, and turn that into an include
                 * file name if so.  Should probably do it for "" too, but that's not
       t@@ -606,13 +596,9 @@ expandfile(Text *t, uint q0, uint q1, Expand *e)
                else if(amin == q0)
                        goto Isfile;
                else{
       -                if(dodollarsigns && r[0] == '$')
       -                        expandenv(&r, (uint*)&nname);
       -                else{
       -                        rs = dirname(t, r, nname);
       -                        r = rs.r;
       -                        nname = rs.nr;
       -                }
       +                rs = dirname(t, r, nname);
       +                r = rs.r;
       +                nname = rs.nr;
                }
                e->bname = runetobyte(r, nname);
                /* if it's already a window name, it's a file */
       t@@ -656,6 +642,7 @@ expand(Text *t, uint q0, uint q1, Expand *e)
        
                if(expandfile(t, q0, q1, e))
                        return TRUE;
       +
                if(q0 == q1){
                        while(q1<t->file->b.nc && isalnum(textreadc(t, q1)))
                                q1++;
       t@@ -718,7 +705,7 @@ lookid(int id, int dump)
        
        
        Window*
       -openfile(Text *t, Expand *e, int newwindow)
       +openfile(Text *t, Expand *e)
        {
                Range r;
                Window *w, *ow;
       t@@ -757,8 +744,6 @@ openfile(Text *t, Expand *e, int newwindow)
                        }
                }
                if(w){
       -                if(newwindow==TRUE && !w->isdir)
       -                        w = coladd(w->col, nil, w, -1);
                        t = &w->body;
                        if(!t->col->safe && t->fr.maxlines==0) /* window is obscured by full-column window */
                                colgrow(t->col, t->col->w[0], 1);
       t@@ -837,7 +822,7 @@ new(Text *et, Text *t, Text *argt, int flag1, int flag2, Rune *arg, int narg)
                        e.nname = rs.nr;
                        e.bname = runetobyte(rs.r, rs.nr);
                        e.jump = TRUE;
       -                openfile(et, &e, FALSE);
       +                openfile(et, &e);
                        free(e.name);
                        free(e.bname);
                        arg = skipbl(a, na, &narg);
 (DIR) diff --git a/src/cmd/acme/util.c b/src/cmd/acme/util.c
       t@@ -415,11 +415,8 @@ emalloc(uint n)
                void *p;
        
                p = malloc(n);
       -        if(p == nil){
       -                fprint(2, "allocating %d from %lux: %r\n", n, getcallerpc(&n));
       -                *(int*)0=0;
       +        if(p == nil)
                        error("malloc failed");
       -        }
                setmalloctag(p, getcallerpc(&n));
                memset(p, 0, n);
                return p;
       t@@ -429,10 +426,8 @@ void*
        erealloc(void *p, uint n)
        {
                p = realloc(p, n);
       -        if(p == nil){
       -                fprint(2, "reallocating %d: %r\n", n);
       +        if(p == nil)
                        error("realloc failed");
       -        }
                setmalloctag(p, getcallerpc(&n));
                return p;
        }
 (DIR) diff --git a/src/cmd/acme/wind.c b/src/cmd/acme/wind.c
       t@@ -414,8 +414,8 @@ wincleartag(Window *w)
        void
        winsettag1(Window *w)
        {
       -        int bar, dirty, i, j, k, n, ntagname, resize;
       -        Rune *new, *old, *r, *tagname;
       +        int i, j, k, n, bar, dirty, resize;
       +        Rune *new, *old, *r;
                uint q0, q1;
                static Rune Ldelsnarf[] = { ' ', 'D', 'e', 'l', ' ',
                        'S', 'n', 'a', 'r', 'f', 0 };
       t@@ -425,6 +425,7 @@ winsettag1(Window *w)
                static Rune Lput[] = { ' ', 'P', 'u', 't', 0 };
                static Rune Llook[] = { ' ', 'L', 'o', 'o', 'k', ' ', 0 };
                static Rune Lpipe[] = { ' ', '|', 0 };
       +
                /* there are races that get us here with stuff in the tag cache, so we take extra care to sync it */
                if(w->tag.ncache!=0 || w->tag.file->mod)
                        wincommit(w, &w->tag);        /* check file name; also guarantees we can modify tag contents */
       t@@ -434,40 +435,20 @@ winsettag1(Window *w)
                for(i=0; i<w->tag.file->b.nc; i++)
                        if(old[i]==' ' || old[i]=='\t')
                                break;
       -        
       -        /* make sure the file name is set correctly in the tag */
       -        ntagname = w->body.file->nname;
       -        tagname = runemalloc(ntagname);
       -        runemove(tagname, w->body.file->name, ntagname);
       -        abbrevenv(&tagname, (uint*)&ntagname);
       -
       -        /*
       -         * XXX Why is this here instead of letting the code
       -         * down below do the work?
       -         */
       -        if(runeeq(old, i, tagname, ntagname) == FALSE){
       -                q0 = w->tag.q0;
       -                q1 = w->tag.q1;
       +        if(runeeq(old, i, w->body.file->name, w->body.file->nname) == FALSE){
                        textdelete(&w->tag, 0, i, TRUE);
       -                textinsert(&w->tag, 0, tagname, ntagname, TRUE);
       +                textinsert(&w->tag, 0, w->body.file->name, w->body.file->nname, TRUE);
                        free(old);
                        old = runemalloc(w->tag.file->b.nc+1);
                        bufread(&w->tag.file->b, 0, old, w->tag.file->b.nc);
                        old[w->tag.file->b.nc] = '\0';
       -                if(q0 >= i){
       -                        /*
       -                         * XXX common case - typing at end of name
       -                         */
       -                        w->tag.q0 = q0+ntagname-i;
       -                        w->tag.q1 = q1+ntagname-i;
       -                }
                }
       -        
       +
                /* compute the text for the whole tag, replacing current only if it differs */
       -        new = runemalloc(ntagname+100);
       +        new = runemalloc(w->body.file->nname+100);
                i = 0;
       -        runemove(new+i, tagname, ntagname);
       -        i += ntagname;
       +        runemove(new+i, w->body.file->name, w->body.file->nname);
       +        i += w->body.file->nname;
                runemove(new+i, Ldelsnarf, 10);
                i += 10;
                if(w->filemenu){
       t@@ -502,10 +483,7 @@ winsettag1(Window *w)
                        }
                }
                new[i] = 0;
       -        if(runestrlen(new) != i)
       -                fprint(2, "s '%S' len not %d\n", new, i);
       -        assert(i==runestrlen(new));
       -        
       +
                /* replace tag if the new one is different */
                resize = 0;
                if(runeeq(new, i, old, k) == FALSE){
       t@@ -531,7 +509,6 @@ winsettag1(Window *w)
                                }
                        }
                }
       -        free(tagname);
                free(old);
                free(new);
                w->tag.file->mod = FALSE;
       t@@ -702,184 +679,3 @@ winevent(Window *w, char *fmt, ...)
                }
        }
        
       -/*
       - * This is here as a first stab at something. 
       - * Run acme with the -'$' flag to enable it.
       - * 
       - * This code isn't quite right, in that it doesn't play well with 
       - * the plumber and with other applications.  For example:
       - *
       - * If the window tag is $home/bin and you execute script, then acme runs
       - * script in $home/bin, via the shell, so everything is fine.  If you do
       - * execute "echo $home", it too goes to the shell so you see the value
       - * of $home.  And if you right-click on script, then acme plumbs "script"
       - * in the directory "/home/you/bin", so that works, but if you right-click
       - * on "$home/bin/script", then what?  It's not correct to expand in acme
       - * since what you're plumbing might be a price tag for all we know.  So the
       - * plumber has to expand it, but in order to do that the plumber should
       - * probably publish (and allow users to change) the set of variables it is
       - * using in expansions.
       - * 
       - * Rob has suggested that a better solution is to make tag lines expand
       - * automatically to fit the necessary number of lines.
       - * 
       - * The best solution, of course, is to use nice short path names, but this
       - * is not always possible.
       - */
       -
       -int
       -expandenv(Rune **rp, uint *np)
       -{
       -        char *s, *t;
       -        Rune *p, *r, *q;
       -        uint n, pref;
       -        int nb, nr, slash;
       -        Runestr rs;
       -
       -        if(!dodollarsigns)
       -                return FALSE;
       -
       -        r = *rp;
       -        n = *np;
       -        if(n == 0 || r[0] != '$')
       -                return FALSE;
       -        for(p=r+1; *p && *p != '/'; p++)
       -                ;
       -        pref = p-r;
       -        s = runetobyte(r+1, pref-1);
       -        if((t = getenv(s)) == nil){
       -                free(s);
       -                return FALSE;
       -        }
       -
       -        q = runemalloc(utflen(t)+(n-pref));
       -        cvttorunes(t, strlen(t), q, &nb, &nr, nil);
       -        assert(nr==utflen(t));
       -        runemove(q+nr, p, n-pref);
       -        free(r);
       -        rs = runestr(q, nr+(n-pref));
       -        slash = rs.nr>0 && q[rs.nr-1] == '/';
       -        rs = cleanrname(rs);
       -        if(slash){
       -                rs.r = runerealloc(rs.r, rs.nr+1);
       -                rs.r[rs.nr++] = '/';
       -        }
       -        *rp = rs.r;
       -        *np = rs.nr;
       -        free(t);
       -        return TRUE;
       -}
       -
       -extern char **environ;
       -Rune **runeenv;
       -
       -/*
       - * Weird sort order -- shorter names first, 
       - * prefer lowercase over uppercase ($home over $HOME),
       - * then do normal string comparison.
       - */
       -int
       -runeenvcmp(const void *va, const void *vb)
       -{
       -        Rune *a, *b;
       -        int na, nb;
       -
       -        a = *(Rune**)va;
       -        b = *(Rune**)vb;
       -        na = runestrchr(a, '=') - a;
       -        nb = runestrchr(b, '=') -  b;
       -        if(na < nb)
       -                return -1;
       -        if(nb > na)
       -                return 1;
       -        if(na == 0)
       -                return 0;
       -        if(islowerrune(a[0]) && !islowerrune(b[0]))
       -                return -1;
       -        if(islowerrune(b[0]) && !islowerrune(a[0]))
       -                return 1;
       -        return runestrncmp(a, b, na);
       -}
       -
       -void
       -mkruneenv(void)
       -{
       -        int i, bad, n, nr;
       -        char *p;
       -        Rune *r, *q;
       -
       -        n = 0;
       -        for(i=0; environ[i]; i++){
       -                /*
       -                 * Ignore some pollution.
       -                 */
       -                if(environ[i][0] == '_')
       -                        continue;
       -                if(strncmp(environ[i], "PWD=", 4) == 0)
       -                        continue;
       -                if(strncmp(environ[i], "OLDPWD=", 7) == 0)
       -                        continue;
       -
       -                /*
       -                 * Must be a rooted path.
       -                 */
       -                if((p = strchr(environ[i], '=')) == nil || *(p+1) != '/')
       -                        continue;
       -
       -                /*
       -                 * Only use the ones that we accept in look - all isfilec
       -                 */
       -                bad = 0;
       -                r = bytetorune(environ[i], &nr);
       -                for(q=r; *q != '='; q++)
       -                        if(!isfilec(*q)){
       -                                free(r);
       -                                bad = 1;
       -                                break;
       -                        }
       -                if(!bad){
       -                        runeenv = erealloc(runeenv, (n+1)*sizeof(runeenv[0]));
       -                        runeenv[n++] = r;
       -                }
       -        }
       -        runeenv = erealloc(runeenv, (n+1)*sizeof(runeenv[0]));
       -        runeenv[n] = nil;
       -        qsort(runeenv, n, sizeof(runeenv[0]), runeenvcmp);
       -}
       -
       -int
       -abbrevenv(Rune **rp, uint *np)
       -{
       -        int i, len, alen;
       -        Rune *r, *p, *q;
       -        uint n;
       -
       -        if(!dodollarsigns)
       -                return FALSE;
       -
       -        r = *rp;
       -        n = *np;
       -        if(n == 0 || r[0] != '/')
       -                return FALSE;
       -
       -        if(runeenv == nil)
       -                mkruneenv();
       -
       -        for(i=0; runeenv[i]; i++){
       -                p = runestrchr(runeenv[i], '=')+1;
       -                len = runestrlen(p);
       -                if(len <= n && (r[len]==0 || r[len]=='/') && runeeq(r, len, p, len)==TRUE){
       -                        alen = (p-1) - runeenv[i];
       -                        q = runemalloc(1+alen+n-len);
       -                        q[0] = '$';
       -                        runemove(q+1, runeenv[i], alen);
       -                        runemove(q+1+alen, r+len, n-len);
       -                        free(r);
       -                        *rp = q;
       -                        *np = 1+alen+n-len;
       -                        return TRUE;
       -                }
       -        }
       -        return FALSE;
       -}
       -