]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/cmd/ed.c
make bind(2) error handling consistent
[plan9front.git] / sys / src / cmd / ed.c
index 5e81c7aee47207300579bd188a92f2171997499f..fcd1d4f54ce17c1ee84637201351c21b76906045 100644 (file)
@@ -15,7 +15,7 @@ enum
        ESIZE   = 256,          /* max size of reg exp */
        GBSIZE  = 256,          /* max size of global command */
        MAXSUB  = 9,            /* max number of sub reg exp */
-       ESCFLG  = 0xFFFF,       /* escape Rune - user defined code */
+       ESCFLG  = Runemax,      /* escape Rune - user defined code */
        EOF     = -1,
 };
 
@@ -54,7 +54,7 @@ Reprog        *pattern;
 int    peekc;
 int    pflag;
 int    rescuing;
-Rune   rhsbuf[LBSIZE/2];
+Rune   rhsbuf[LBSIZE/sizeof(Rune)];
 char   savedfile[FNSIZE];
 jmp_buf        savej;
 int    subnewa;
@@ -157,7 +157,7 @@ main(int argc, char *argv[])
                globp = L"r";
        }
        zero = malloc((nlall+5)*sizeof(int*));
-       tfname = mktemp("/tmp/eXXXXX");
+       tfname = mktemp(strdup("/tmp/eXXXXX"));
        init();
        setjmp(savej);
        commands();
@@ -372,7 +372,6 @@ commands(void)
                                if((io = create(file, OWRITE, 0666)) < 0)
                                        error(file);
                        Binit(&iobuf, io, OWRITE);
-                       Blethal(&iobuf, nil);
                        wrapp = 0;
                        if(dol > zero)
                                putfile();
@@ -672,7 +671,6 @@ rescue(void)
                io = create("ed.hup", OWRITE, 0666);
                if(io > 0){
                        Binit(&iobuf, io, OWRITE);
-                       Blethal(&iobuf, nil);
                        putfile();
                }
        }
@@ -739,7 +737,7 @@ gety(void)
                if(c == 0)
                        continue;
                *p++ = c;
-               if(p >= &linebuf[LBSIZE-2])
+               if(p >= &linebuf[LBSIZE-sizeof(Rune)])
                        error(Q);
        }
 }
@@ -992,11 +990,11 @@ getline(int tl)
        lp = linebuf;
        bp = getblock(tl, OREAD);
        nl = nleft;
-       tl &= ~((BLKSIZE/2) - 1);
+       tl &= ~((BLKSIZE/sizeof(Rune)) - 1);
        while(*lp++ = *bp++) {
                nl -= sizeof(Rune);
                if(nl == 0) {
-                       bp = getblock(tl += BLKSIZE/2, OREAD);
+                       bp = getblock(tl += BLKSIZE/sizeof(Rune), OREAD);
                        nl = nleft;
                }
        }
@@ -1014,7 +1012,7 @@ putline(void)
        tl = tline;
        bp = getblock(tl, OWRITE);
        nl = nleft;
-       tl &= ~((BLKSIZE/2)-1);
+       tl &= ~((BLKSIZE/sizeof(Rune))-1);
        while(*bp = *lp++) {
                if(*bp++ == '\n') {
                        bp[-1] = 0;
@@ -1023,7 +1021,7 @@ putline(void)
                }
                nl -= sizeof(Rune);
                if(nl == 0) {
-                       tl += BLKSIZE/2;
+                       tl += BLKSIZE/sizeof(Rune);
                        bp = getblock(tl, OWRITE);
                        nl = nleft;
                }
@@ -1050,8 +1048,8 @@ getblock(int atl, int iof)
        static uchar ibuff[BLKSIZE];
        static uchar obuff[BLKSIZE];
 
-       bno = atl / (BLKSIZE/2);
-       off = (atl<<1) & (BLKSIZE-1) & ~03;
+       bno = atl / (BLKSIZE/sizeof(Rune));
+       off = (atl*sizeof(Rune)) & (BLKSIZE-1) & ~03;
        if(bno >= NBLK) {
                lastc = '\n';
                error(T);
@@ -1164,7 +1162,7 @@ join(void)
        for(a1=addr1; a1<=addr2; a1++) {
                lp = getline(*a1);
                while(*gp = *lp++)
-                       if(gp++ >= &genbuf[LBSIZE-2])
+                       if(gp++ >= &genbuf[LBSIZE-sizeof(Rune)])
                                error(Q);
        }
        lp = linebuf;
@@ -1242,7 +1240,7 @@ compsub(void)
                if(c == '\\') {
                        c = getchr();
                        *p++ = ESCFLG;
-                       if(p >= &rhsbuf[LBSIZE/2])
+                       if(p >= &rhsbuf[nelem(rhsbuf)])
                                error(Q);
                } else
                if(c == '\n' && (!globp || !globp[0])) {
@@ -1253,7 +1251,7 @@ compsub(void)
                if(c == seof)
                        break;
                *p++ = c;
-               if(p >= &rhsbuf[LBSIZE/2])
+               if(p >= &rhsbuf[nelem(rhsbuf)])
                        error(Q);
        }
        *p = 0;