]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/cmd/ed.c
merge
[plan9front.git] / sys / src / cmd / ed.c
index 52d6c40c100f6bc21c61e19a4a21a9758c5170c2..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;
@@ -127,6 +127,7 @@ main(int argc, char *argv[])
        char *p1, *p2;
 
        Binit(&bcons, 0, OREAD);
+       Blethal(&bcons, nil);
        notify(notifyf);
        ARGBEGIN {
        case 'o':
@@ -156,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();
@@ -322,6 +323,7 @@ commands(void)
                                free(d);
                        }
                        Binit(&iobuf, io, OREAD);
+                       Blethal(&iobuf, nil);
                        setwide();
                        squeeze(0);
                        c = zero != dol;
@@ -735,7 +737,7 @@ gety(void)
                if(c == 0)
                        continue;
                *p++ = c;
-               if(p >= &linebuf[LBSIZE-2])
+               if(p >= &linebuf[LBSIZE-sizeof(Rune)])
                        error(Q);
        }
 }
@@ -988,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;
                }
        }
@@ -1010,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;
@@ -1019,7 +1021,7 @@ putline(void)
                }
                nl -= sizeof(Rune);
                if(nl == 0) {
-                       tl += BLKSIZE/2;
+                       tl += BLKSIZE/sizeof(Rune);
                        bp = getblock(tl, OWRITE);
                        nl = nleft;
                }
@@ -1046,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);
@@ -1160,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;
@@ -1238,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])) {
@@ -1249,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;