URI: 
       tacme: add -m option and avoid looking in the mirror - 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 cd5a73785d8f7533f1438a955daf23159d09a352
   DIR parent e63025d09486aea0f644578b5e05a093c130b7d2
  HTML Author: Russ Cox <rsc@swtch.com>
       Date:   Thu, 17 Apr 2008 16:04:19 -0400
       
       acme: add -m option and avoid looking in the mirror
       
       Diffstat:
         M src/cmd/acme/acme.c                 |      16 ++++++++++++++++
         M src/cmd/acme/dat.h                  |       1 +
         M src/cmd/acme/fns.h                  |       2 ++
         M src/cmd/acme/fsys.c                 |       2 +-
         M src/cmd/acme/look.c                 |       2 +-
         M src/cmd/acme/text.c                 |       4 ++++
       
       6 files changed, 25 insertions(+), 2 deletions(-)
       ---
   DIR diff --git a/src/cmd/acme/acme.c b/src/cmd/acme/acme.c
       t@@ -28,6 +28,7 @@ Reffont        *reffonts[2];
        int                snarffd = -1;
        int                mainpid;
        int                swapscrollbuttons = FALSE;
       +char                *mtpt;
        
        enum{
                NSnarf = 1000        /* less than 1024, I/O buffer size */
       t@@ -106,6 +107,11 @@ threadmain(int argc, char *argv[])
                        if(loadfile == nil)
                                goto Usage;
                        break;
       +        case 'm':
       +                mtpt = ARGF();
       +                if(mtpt == nil)
       +                        goto Usage;
       +                break;
                case 'r':
                        swapscrollbuttons = TRUE;
                        break;
       t@@ -1056,3 +1062,13 @@ acmegetsnarf(void)
                free(r);
                free(s);
        }
       +
       +int
       +ismtpt(char *file)
       +{
       +        int n;
       +
       +        /* This is not foolproof, but it will stop a lot of them. */
       +        n = strlen(mtpt);
       +        return strncmp(file, mtpt, n) == 0 && ((n > 0 && mtpt[n-1] == '/') || file[n] == '/' || file[n] == 0);
       +}
   DIR diff --git a/src/cmd/acme/dat.h b/src/cmd/acme/dat.h
       t@@ -542,6 +542,7 @@ int                        erroutfd;
        int                        messagesize;                /* negotiated in 9P version setup */
        int                        globalautoindent;
        int                        dodollarsigns;
       +char*                mtpt;
        
        enum
        {
   DIR diff --git a/src/cmd/acme/fns.h b/src/cmd/acme/fns.h
       t@@ -102,3 +102,5 @@ int        abbrevenv(Rune**, uint*);
        #define        runemalloc(a)                (Rune*)emalloc((a)*sizeof(Rune))
        #define        runerealloc(a, b)        (Rune*)erealloc((a), (b)*sizeof(Rune))
        #define        runemove(a, b, c)        memmove((a), (b), (c)*sizeof(Rune))
       +
       +int        ismtpt(char*);
   DIR diff --git a/src/cmd/acme/fsys.c b/src/cmd/acme/fsys.c
       t@@ -121,7 +121,7 @@ fsysinit(void)
                initfcall();
                if(pipe(p) < 0)
                        error("can't create pipe");
       -        if(post9pservice(p[0], "acme") < 0)
       +        if(post9pservice(p[0], "acme", mtpt) < 0)
                        error("can't post service");
                sfd = p[1];
                fmtinstall('F', fcallfmt);
   DIR diff --git a/src/cmd/acme/look.c b/src/cmd/acme/look.c
       t@@ -620,7 +620,7 @@ expandfile(Text *t, uint q0, uint q1, Expand *e)
                if(w != nil)
                        goto Isfile;
                /* if it's the name of a file, it's a file */
       -        if(access(e->bname, 0) < 0){
       +        if(ismtpt(e->bname) || access(e->bname, 0) < 0){
                        free(e->bname);
                        e->bname = nil;
                        goto Isntfile;
   DIR diff --git a/src/cmd/acme/text.c b/src/cmd/acme/text.c
       t@@ -200,6 +200,10 @@ textload(Text *t, uint q0, char *file, int setqid)
                        warning(nil, "empty directory name");
                        return 0;
                }
       +        if(ismtpt(file)){
       +                warning(nil, "will not open self mount point %s\n", file);
       +                return 0;
       +        }
                fd = open(file, OREAD);
                if(fd < 0){
                        warning(nil, "can't open %s: %r\n", file);