diff options
author | rsc <devnull@localhost> | 2003-09-30 19:05:50 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2003-09-30 19:05:50 +0000 |
commit | 522b0689c340d26feeac360640bf7e2e0582353c (patch) | |
tree | ba3a550c28684be3b3997899528a110c4e9cd91a /src/cmd/sam | |
parent | 2df2758496b2ab508d349208449f04d85ae2eb2c (diff) | |
download | plan9port-522b0689c340d26feeac360640bf7e2e0582353c.tar.gz plan9port-522b0689c340d26feeac360640bf7e2e0582353c.tar.bz2 plan9port-522b0689c340d26feeac360640bf7e2e0582353c.zip |
Reorg
Diffstat (limited to 'src/cmd/sam')
-rw-r--r-- | src/cmd/sam/Makefile | 48 | ||||
-rw-r--r-- | src/cmd/sam/address.c | 22 | ||||
-rw-r--r-- | src/cmd/sam/buff.c | 8 | ||||
-rw-r--r-- | src/cmd/sam/cmd.c | 6 | ||||
-rw-r--r-- | src/cmd/sam/disk.c | 20 | ||||
-rw-r--r-- | src/cmd/sam/file.c | 24 | ||||
-rw-r--r-- | src/cmd/sam/io.c | 9 | ||||
-rw-r--r-- | src/cmd/sam/mesg.c | 44 | ||||
-rw-r--r-- | src/cmd/sam/mkfile | 40 | ||||
-rw-r--r-- | src/cmd/sam/moveto.c | 14 | ||||
-rw-r--r-- | src/cmd/sam/rasp.c | 22 | ||||
-rw-r--r-- | src/cmd/sam/regexp.c | 4 | ||||
-rwxr-xr-x | src/cmd/sam/sam | bin | 267893 -> 0 bytes | |||
-rw-r--r-- | src/cmd/sam/sam.c | 26 | ||||
-rw-r--r-- | src/cmd/sam/sam.h | 7 | ||||
-rw-r--r-- | src/cmd/sam/xec.c | 12 |
16 files changed, 140 insertions, 166 deletions
diff --git a/src/cmd/sam/Makefile b/src/cmd/sam/Makefile index f5e91463..bf2917dc 100644 --- a/src/cmd/sam/Makefile +++ b/src/cmd/sam/Makefile @@ -1,18 +1,34 @@ -H=errors.h mesg.h parse.h plumb.h sam.h -SRC= address.c buff.c cmd.c disk.c error.c file.c io.c\ - list.c mesg.c moveto.c multi.c unix.c rasp.c regexp.c\ - sam.c shell.c string.c sys.c util.c xec.c plumb.c +9SRC=.. +include $(9SRC)/Makehdr -CC=gcc -PREFIX=$(HOME) -#PREFIX=/usr/local -CFLAGS=-I. -I$(PREFIX)/include -O -g -LDFLAGS=-L$(PREFIX)/lib -LDLIBS=-l9 -lfmt -lutf +TARG=sam +OFILES=sam.$O\ + address.$O\ + buff.$O\ + cmd.$O\ + disk.$O\ + error.$O\ + file.$O\ + io.$O\ + list.$O\ + mesg.$O\ + moveto.$O\ + multi.$O\ + plumb.$O\ + rasp.$O\ + regexp.$O\ + shell.$O\ + string.$O\ + sys.$O\ + unix.$O\ + util.$O\ + xec.$O\ + +HFILES=sam.h\ + errors.h\ + mesg.h\ + +LDFLAGS+=-l9 -lfmt -lutf + +include $(9SRC)/Makeone -all: sam -sam: $(SRC) $(H) - $(CC) -o $@ $(CFLAGS) $(SRC) $(LDFLAGS) $(LDLIBS) -clean: - rm -f *.o *~ - rm -f sam diff --git a/src/cmd/sam/address.c b/src/cmd/sam/address.c index 85cca170..c59b0136 100644 --- a/src/cmd/sam/address.c +++ b/src/cmd/sam/address.c @@ -27,7 +27,7 @@ address(Addr *ap, Address a, int sign) break; case '$': - a.r.p1 = a.r.p2 = f->_.nc; + a.r.p1 = a.r.p2 = f->b.nc; break; case '\'': @@ -52,7 +52,7 @@ address(Addr *ap, Address a, int sign) break; case '*': - a.r.p1 = 0, a.r.p2 = f->_.nc; + a.r.p1 = 0, a.r.p2 = f->b.nc; return a; case ',': @@ -69,7 +69,7 @@ address(Addr *ap, Address a, int sign) if(ap->next) a2 = address(ap->next, a, 0); else - a2.f = a.f, a2.r.p1 = a2.r.p2 = f->_.nc; + a2.f = a.f, a2.r.p1 = a2.r.p2 = f->b.nc; if(a1.f != a2.f) error(Eorder); a.f = a1.f, a.r.p1 = a1.r.p1, a.r.p2 = a2.r.p2; @@ -101,7 +101,7 @@ nextmatch(File *f, String *r, Posn p, int sign) if(!execute(f, p, INFINITY)) error(Esearch); if(sel.p[0].p1==sel.p[0].p2 && sel.p[0].p1==p){ - if(++p>f->_.nc) + if(++p>f->b.nc) p = 0; if(!execute(f, p, INFINITY)) panic("address"); @@ -111,7 +111,7 @@ nextmatch(File *f, String *r, Posn p, int sign) error(Esearch); if(sel.p[0].p1==sel.p[0].p2 && sel.p[0].p2==p){ if(--p<0) - p = f->_.nc; + p = f->b.nc; if(!bexecute(f, p)) panic("address"); } @@ -156,10 +156,10 @@ filematch(File *f, String *r) /* A little dirty... */ if(menu == 0) menu = fileopen(); - bufreset(menu); - bufinsert(menu, 0, genstr.s, genstr.n); + bufreset(&menu->b); + bufinsert(&menu->b, 0, genstr.s, genstr.n); compile(r); - return execute(menu, 0, menu->_.nc); + return execute(menu, 0, menu->b.nc); } Address @@ -171,7 +171,7 @@ charaddr(Posn l, Address addr, int sign) addr.r.p2 = addr.r.p1-=l; else if(sign > 0) addr.r.p1 = addr.r.p2+=l; - if(addr.r.p1<0 || addr.r.p2>addr.f->_.nc) + if(addr.r.p1<0 || addr.r.p2>addr.f->b.nc) error(Erange); return addr; } @@ -203,14 +203,14 @@ lineaddr(Posn l, Address addr, int sign) n = filereadc(f, p++)=='\n'; } while(n < l){ - if(p >= f->_.nc) + if(p >= f->b.nc) error(Erange); if(filereadc(f, p++) == '\n') n++; } a.r.p1 = p; } - while(p < f->_.nc && filereadc(f, p++)!='\n') + while(p < f->b.nc && filereadc(f, p++)!='\n') ; a.r.p2 = p; }else{ diff --git a/src/cmd/sam/buff.c b/src/cmd/sam/buff.c index 30493c3e..9a525b66 100644 --- a/src/cmd/sam/buff.c +++ b/src/cmd/sam/buff.c @@ -91,8 +91,8 @@ setcache(Buffer *b, uint q0) i = b->cbi; } blp = &b->bl[i]; - while(q+(*blp)->_.n <= q0 && q+(*blp)->_.n < b->nc){ - q += (*blp)->_.n; + while(q+(*blp)->u.n <= q0 && q+(*blp)->u.n < b->nc){ + q += (*blp)->u.n; i++; blp++; if(i >= b->nbl) @@ -102,8 +102,8 @@ setcache(Buffer *b, uint q0) /* remember position */ b->cbi = i; b->cq = q; - sizecache(b, bl->_.n); - b->cnc = bl->_.n; + sizecache(b, bl->u.n); + b->cnc = bl->u.n; /*read block*/ diskread(disk, bl, b->c, b->cnc); } diff --git a/src/cmd/sam/cmd.c b/src/cmd/sam/cmd.c index 8c152f94..6b773f8d 100644 --- a/src/cmd/sam/cmd.c +++ b/src/cmd/sam/cmd.c @@ -185,14 +185,14 @@ termcommand(void) { Posn p; - for(p=cmdpt; p<cmd->_.nc; p++){ + for(p=cmdpt; p<cmd->b.nc; p++){ if(terminp >= &termline[BLOCKSIZE]){ - cmdpt = cmd->_.nc; + cmdpt = cmd->b.nc; error(Etoolong); } *terminp++ = filereadc(cmd, p); } - cmdpt = cmd->_.nc; + cmdpt = cmd->b.nc; } void diff --git a/src/cmd/sam/disk.c b/src/cmd/sam/disk.c index 83b2553d..f27e94ba 100644 --- a/src/cmd/sam/disk.c +++ b/src/cmd/sam/disk.c @@ -64,20 +64,20 @@ disknewblock(Disk *d, uint n) size = ntosize(n, &i); b = d->free[i]; if(b) - d->free[i] = b->_.next; + d->free[i] = b->u.next; else{ /* allocate in chunks to reduce malloc overhead */ if(blist == nil){ blist = emalloc(100*sizeof(Block)); for(j=0; j<100-1; j++) - blist[j]._.next = &blist[j+1]; + blist[j].u.next = &blist[j+1]; } b = blist; - blist = b->_.next; + blist = b->u.next; b->addr = d->addr; d->addr += size; } - b->_.n = n; + b->u.n = n; return b; } @@ -86,8 +86,8 @@ diskrelease(Disk *d, Block *b) { uint i; - ntosize(b->_.n, &i); - b->_.next = d->free[i]; + ntosize(b->u.n, &i); + b->u.next = d->free[i]; d->free[i] = b; } @@ -98,7 +98,7 @@ diskwrite(Disk *d, Block **bp, Rune *r, uint n) Block *b; b = *bp; - size = ntosize(b->_.n, nil); + size = ntosize(b->u.n, nil); nsize = ntosize(n, nil); if(size != nsize){ diskrelease(d, b); @@ -107,16 +107,16 @@ diskwrite(Disk *d, Block **bp, Rune *r, uint n) } if(pwrite(d->fd, r, n*sizeof(Rune), b->addr) != n*sizeof(Rune)) panic("write error to temp file"); - b->_.n = n; + b->u.n = n; } void diskread(Disk *d, Block *b, Rune *r, uint n) { - if(n > b->_.n) + if(n > b->u.n) panic("internal error: diskread"); - ntosize(b->_.n, nil); /* called only for sanity check on Maxblock */ + ntosize(b->u.n, nil); /* called only for sanity check on Maxblock */ if(pread(d->fd, r, n*sizeof(Rune), b->addr) != n*sizeof(Rune)) panic("read error from temp file"); } diff --git a/src/cmd/sam/file.c b/src/cmd/sam/file.c index 0428379d..bc3c0f4a 100644 --- a/src/cmd/sam/file.c +++ b/src/cmd/sam/file.c @@ -114,7 +114,7 @@ mergeextend(File *f, uint p0) mp0n = merge.p0+merge.n; if(mp0n != p0){ - bufread(f, mp0n, merge.buf+merge.nbuf, p0-mp0n); + bufread(&f->b, mp0n, merge.buf+merge.nbuf, p0-mp0n); merge.nbuf += p0-mp0n; merge.n = p0-merge.p0; } @@ -268,11 +268,11 @@ filedeltext(File *f, Text *t) void fileinsert(File *f, uint p0, Rune *s, uint ns) { - if(p0 > f->_.nc) + if(p0 > f->b.nc) panic("internal error: fileinsert"); if(f->seq > 0) fileuninsert(f, &f->delta, p0, ns); - bufinsert(f, p0, s, ns); + bufinsert(&f->b, p0, s, ns); if(ns) f->mod = TRUE; } @@ -294,11 +294,11 @@ fileuninsert(File *f, Buffer *delta, uint p0, uint ns) void filedelete(File *f, uint p0, uint p1) { - if(!(p0<=p1 && p0<=f->_.nc && p1<=f->_.nc)) + if(!(p0<=p1 && p0<=f->b.nc && p1<=f->b.nc)) panic("internal error: filedelete"); if(f->seq > 0) fileundelete(f, &f->delta, p0, p1); - bufdelete(f, p0, p1); + bufdelete(&f->b, p0, p1); if(p1 > p0) f->mod = TRUE; } @@ -321,7 +321,7 @@ fileundelete(File *f, Buffer *delta, uint p0, uint p1) n = p1 - i; if(n > RBUFSIZE) n = RBUFSIZE; - bufread(f, i, buf, n); + bufread(&f->b, i, buf, n); bufinsert(delta, delta->nc, buf, n); } fbuffree(buf); @@ -334,9 +334,9 @@ filereadc(File *f, uint q) { Rune r; - if(q >= f->_.nc) + if(q >= f->b.nc) return -1; - bufread(f, q, &r, 1); + bufread(&f->b, q, &r, 1); return r; } @@ -402,7 +402,7 @@ fileload(File *f, uint p0, int fd, int *nulls) { if(f->seq > 0) panic("undo in file.load unimplemented"); - return bufload(f, p0, fd, nulls); + return bufload(&f->b, p0, fd, nulls); } int @@ -525,7 +525,7 @@ fileundo(File *f, int isundo, int canredo, uint *q0p, uint *q1p, int flag) if(canredo) fileundelete(f, epsilon, u.p0, u.p0+u.n); f->mod = u.mod; - bufdelete(f, u.p0, u.p0+u.n); + bufdelete(&f->b, u.p0, u.p0+u.n); raspdelete(f, u.p0, u.p0+u.n, flag); *q0p = u.p0; *q1p = u.p0; @@ -543,7 +543,7 @@ fileundo(File *f, int isundo, int canredo, uint *q0p, uint *q1p, int flag) if(n > RBUFSIZE) n = RBUFSIZE; bufread(delta, up+i, buf, n); - bufinsert(f, u.p0+i, buf, n); + bufinsert(&f->b, u.p0+i, buf, n); raspinsert(f, u.p0+i, buf, n, flag); } fbuffree(buf); @@ -601,7 +601,7 @@ void fileclose(File *f) { Strclose(&f->name); - bufclose(f); + bufclose(&f->b); bufclose(&f->delta); bufclose(&f->epsilon); if(f->rasp) diff --git a/src/cmd/sam/io.c b/src/cmd/sam/io.c index 236090a0..c0669631 100644 --- a/src/cmd/sam/io.c +++ b/src/cmd/sam/io.c @@ -53,7 +53,7 @@ writef(File *f) error(Eappend); n = writeio(f); if(f->name.s[0]==0 || samename){ - if(addr.r.p1==0 && addr.r.p2==f->_.nc) + if(addr.r.p1==0 && addr.r.p2==f->b.nc) f->cleanseq = f->seq; state(f, f->cleanseq==f->seq? Clean : Dirty); } @@ -87,7 +87,7 @@ readio(File *f, int *nulls, int setdate, int toterm) *nulls = FALSE; b = 0; if(f->unread){ - nt = bufload(f, 0, io, nulls); + nt = bufload(&f->b, 0, io, nulls); if(toterm) raspload(f); }else @@ -149,7 +149,7 @@ writeio(File *f) n = BLOCKSIZE; else n = addr.r.p2-p; - bufread(f, p, genbuf, n); + bufread(&f->b, p, genbuf, n); c = Strtoc(tmprstr(genbuf, n)); m = strlen(c); if(Write(io, c, m) != m){ @@ -188,8 +188,7 @@ bootterm(char *machine, char **argv, char **end) argv[0] = "samterm"; *end = 0; exec(samterm, argv); - fprint(2, "can't exec: "); - perror(samterm); + fprint(2, "can't exec %s: %r\n", samterm); _exits("damn"); } if(pipe(ph2t)==-1 || pipe(pt2h)==-1) diff --git a/src/cmd/sam/mesg.c b/src/cmd/sam/mesg.c index 189c11ac..ec0aa858 100644 --- a/src/cmd/sam/mesg.c +++ b/src/cmd/sam/mesg.c @@ -101,7 +101,7 @@ journaln(int out, long n) int rcvchar(void){ static uchar buf[64]; - static i, nleft = 0; + static int i, nleft = 0; if(nleft <= 0){ nleft = read(0, (char *)buf, sizeof buf); @@ -116,9 +116,9 @@ rcvchar(void){ int rcv(void){ int c; - static state = 0; - static count = 0; - static i = 0; + static int state = 0; + static int count = 0; + static int i = 0; while((c=rcvchar()) != -1) switch(state){ @@ -235,17 +235,17 @@ inmesg(Tmesg type) journaln(0, p1-p0); if(f->unread) panic("Trequest: unread"); - if(p1>f->_.nc) - p1 = f->_.nc; - if(p0>f->_.nc) /* can happen e.g. scrolling during command */ - p0 = f->_.nc; + if(p1>f->b.nc) + p1 = f->b.nc; + if(p0>f->b.nc) /* can happen e.g. scrolling during command */ + p0 = f->b.nc; if(p0 == p1){ i = 0; r.p1 = r.p2 = p0; }else{ r = rdata(f->rasp, p0, p1-p0); i = r.p2-r.p1; - bufread(f, r.p1, buf, i); + bufread(&f->b, r.p1, buf, i); } buf[i]=0; outTslS(Hdata, f->tag, r.p1, tmprstr(buf, i+1)); @@ -271,9 +271,9 @@ inmesg(Tmesg type) if(f->unread) load(f); else{ - if(f->_.nc>0){ - rgrow(f->rasp, 0L, f->_.nc); - outTsll(Hgrow, f->tag, 0L, f->_.nc); + if(f->b.nc>0){ + rgrow(f->rasp, 0L, f->b.nc); + outTsll(Hgrow, f->tag, 0L, f->b.nc); } outTs(Hcheck0, f->tag); moveto(f, f->dot.r); @@ -302,7 +302,7 @@ inmesg(Tmesg type) loginsert(f, p0, str->s, str->n); if(fileupdate(f, FALSE, FALSE)) seq++; - if(f==cmd && p0==f->_.nc-i && i>0 && str->s[i-1]=='\n'){ + if(f==cmd && p0==f->b.nc-i && i>0 && str->s[i-1]=='\n'){ freetmpstr(str); termlocked++; termcommand(); @@ -370,7 +370,7 @@ inmesg(Tmesg type) journaln(0, i); f = whichfile(i); addr.r.p1 = 0; - addr.r.p2 = f->_.nc; + addr.r.p2 = f->b.nc; if(f->name.s[0] == 0) error(Enoname); Strduplstr(&genstr, &f->name); @@ -427,9 +427,9 @@ inmesg(Tmesg type) outTl(Hsnarflen, genstr.n); if(genstr.s[genstr.n-1] != '\n') Straddc(&genstr, '\n'); - loginsert(cmd, cmd->_.nc, genstr.s, genstr.n); + loginsert(cmd, cmd->b.nc, genstr.s, genstr.n); fileupdate(cmd, FALSE, TRUE); - cmd->dot.r.p1 = cmd->dot.r.p2 = cmd->_.nc; + cmd->dot.r.p1 = cmd->dot.r.p2 = cmd->b.nc; telldot(cmd); termcommand(); break; @@ -522,7 +522,7 @@ inmesg(Tmesg type) p = p0; while(p0>0 && (i=filereadc(f, p0 - 1))!=' ' && i!='\t' && i!='\n') p0--; - while(p1<f->_.nc && (i=filereadc(f, p1))!=' ' && i!='\t' && i!='\n') + while(p1<f->b.nc && (i=filereadc(f, p1))!=' ' && i!='\t' && i!='\n') p1++; sprint(cbuf, "click=%ld", p-p0); pm->attr = plumbunpackattr(cbuf); @@ -559,13 +559,13 @@ snarf(File *f, Posn p1, Posn p2, Buffer *buf, int emptyok) return; bufreset(buf); /* Stage through genbuf to avoid compaction problems (vestigial) */ - if(p2 > f->_.nc){ - fprint(2, "bad snarf addr p1=%ld p2=%ld f->_.nc=%d\n", p1, p2, f->_.nc); /*ZZZ should never happen, can remove */ - p2 = f->_.nc; + if(p2 > f->b.nc){ + fprint(2, "bad snarf addr p1=%ld p2=%ld f->b.nc=%d\n", p1, p2, f->b.nc); /*ZZZ should never happen, can remove */ + p2 = f->b.nc; } for(l=p1; l<p2; l+=i){ i = p2-l>BLOCKSIZE? BLOCKSIZE : p2-l; - bufread(f, l, genbuf, i); + bufread(&f->b, l, genbuf, i); bufinsert(buf, buf->nc, tmprstr(genbuf, i)->s, i); } } @@ -609,7 +609,7 @@ setgenstr(File *f, Posn p0, Posn p1) if(p1-p0 >= TBLOCKSIZE) error(Etoolong); Strinsure(&genstr, p1-p0); - bufread(f, p0, genbuf, p1-p0); + bufread(&f->b, p0, genbuf, p1-p0); memmove(genstr.s, genbuf, RUNESIZE*(p1-p0)); genstr.n = p1-p0; }else{ diff --git a/src/cmd/sam/mkfile b/src/cmd/sam/mkfile deleted file mode 100644 index cb604976..00000000 --- a/src/cmd/sam/mkfile +++ /dev/null @@ -1,40 +0,0 @@ -</$objtype/mkfile - -TARG=sam -OFILES=sam.$O\ - address.$O\ - buff.$O\ - cmd.$O\ - disk.$O\ - error.$O\ - file.$O\ - io.$O\ - list.$O\ - mesg.$O\ - moveto.$O\ - multi.$O\ - plan9.$O\ - rasp.$O\ - regexp.$O\ - shell.$O\ - string.$O\ - sys.$O\ - util.$O\ - xec.$O\ - -HFILES=sam.h\ - errors.h\ - mesg.h\ - -BIN=/$objtype/bin -</sys/src/cmd/mkone - -address.$O cmd.$O parse.$O xec.$O unix.$O: parse.h - -safeinstall: $O.out - mv $BIN/$TARG $BIN/o$TARG - cp $prereq $BIN/$TARG - -safeinstallall:V: - for (objtype in $CPUS) - mk safeinstall diff --git a/src/cmd/sam/moveto.c b/src/cmd/sam/moveto.c index a84578c7..94fad3e7 100644 --- a/src/cmd/sam/moveto.c +++ b/src/cmd/sam/moveto.c @@ -39,8 +39,8 @@ lookorigin(File *f, Posn p0, Posn ls) int nl, nc, c; Posn p, oldp0; - if(p0 > f->_.nc) - p0 = f->_.nc; + if(p0 > f->b.nc) + p0 = f->b.nc; oldp0 = p0; p = p0; for(nl=nc=c=0; c!=-1 && nl<ls && nc<ls*CHARSHIFT; nc++) @@ -85,7 +85,7 @@ clickmatch(File *f, int cl, int cr, int dir, Posn *p) for(;;){ if(dir > 0){ - if(*p >= f->_.nc) + if(*p >= f->b.nc) break; c = filereadc(f, (*p)++); }else{ @@ -126,7 +126,7 @@ doubleclick(File *f, Posn p1) Rune *r, *l; Posn p; - if(p1 > f->_.nc) + if(p1 > f->b.nc) return; f->dot.r.p1 = f->dot.r.p2 = p1; for(i=0; left[i]; i++){ @@ -147,7 +147,7 @@ doubleclick(File *f, Posn p1) } /* try right match */ p = p1; - if(p1 == f->_.nc) + if(p1 == f->b.nc) c = '\n'; else c = filereadc(f, p); @@ -156,14 +156,14 @@ doubleclick(File *f, Posn p1) f->dot.r.p1 = p; if(c!='\n' || p!=0 || filereadc(f, 0)=='\n') f->dot.r.p1++; - f->dot.r.p2 = p1+(p1<f->_.nc && c=='\n'); + f->dot.r.p2 = p1+(p1<f->b.nc && c=='\n'); } return; } } /* try filling out word to right */ p = p1; - while(p < f->_.nc && alnum(filereadc(f, p++))) + while(p < f->b.nc && alnum(filereadc(f, p++))) f->dot.r.p2++; /* try filling out word to left */ p = p1; diff --git a/src/cmd/sam/rasp.c b/src/cmd/sam/rasp.c index 45ac8206..c5cc5701 100644 --- a/src/cmd/sam/rasp.c +++ b/src/cmd/sam/rasp.c @@ -35,10 +35,10 @@ raspload(File *f) { if(f->rasp == nil) return; - grown = f->_.nc; + grown = f->b.nc; growpos = 0; - if(f->_.nc) - rgrow(f->rasp, 0, f->_.nc); + if(f->b.nc) + rgrow(f->rasp, 0, f->b.nc); raspdone(f, 1); } @@ -55,14 +55,14 @@ raspstart(File *f) void raspdone(File *f, int toterm) { - if(f->dot.r.p1 > f->_.nc) - f->dot.r.p1 = f->_.nc; - if(f->dot.r.p2 > f->_.nc) - f->dot.r.p2 = f->_.nc; - if(f->mark.p1 > f->_.nc) - f->mark.p1 = f->_.nc; - if(f->mark.p2 > f->_.nc) - f->mark.p2 = f->_.nc; + if(f->dot.r.p1 > f->b.nc) + f->dot.r.p1 = f->b.nc; + if(f->dot.r.p2 > f->b.nc) + f->dot.r.p2 = f->b.nc; + if(f->mark.p1 > f->b.nc) + f->mark.p1 = f->b.nc; + if(f->mark.p2 > f->b.nc) + f->mark.p2 = f->b.nc; if(f->rasp == nil) return; if(grown) diff --git a/src/cmd/sam/regexp.c b/src/cmd/sam/regexp.c index dee4377d..d4c85050 100644 --- a/src/cmd/sam/regexp.c +++ b/src/cmd/sam/regexp.c @@ -700,7 +700,7 @@ bexecute(File *f, Posn startp) case 3: goto Return; list[0][0].inst = list[1][0].inst = 0; - p = f->_.nc; + p = f->b.nc; goto doloop; default: goto Return; @@ -758,7 +758,7 @@ bexecute(File *f, Posn startp) } break; case EOL: - if(p==f->_.nc || filereadc(f, p)=='\n') + if(p==f->b.nc || filereadc(f, p)=='\n') goto Step; break; case CCLASS: diff --git a/src/cmd/sam/sam b/src/cmd/sam/sam Binary files differdeleted file mode 100755 index 733b555c..00000000 --- a/src/cmd/sam/sam +++ /dev/null diff --git a/src/cmd/sam/sam.c b/src/cmd/sam/sam.c index 81ccaf78..864faec6 100644 --- a/src/cmd/sam/sam.c +++ b/src/cmd/sam/sam.c @@ -148,7 +148,7 @@ rescue(void) io = -1; for(i=0; i<file.nused; i++){ f = file.filepptr[i]; - if(f==cmd || f->_.nc==0 || !fileisdirty(f)) + if(f==cmd || f->b.nc==0 || !fileisdirty(f)) continue; if(io == -1){ sprint(buf, "%s/sam.save", home); @@ -164,7 +164,7 @@ rescue(void) }else sprint(buf, "nameless.%d", nblank++); fprint(io, "#!%s '%s' $* <<'---%s'\n", SAMSAVECMD, buf, buf); - addr.r.p1 = 0, addr.r.p2 = f->_.nc; + addr.r.p1 = 0, addr.r.p2 = f->b.nc; writeio(f); fprint(io, "\n---%s\n", (char *)buf); } @@ -299,7 +299,7 @@ cmdupdate(void) { if(cmd && cmd->seq!=0){ fileupdate(cmd, FALSE, downloaded); - cmd->dot.r.p1 = cmd->dot.r.p2 = cmd->_.nc; + cmd->dot.r.p1 = cmd->dot.r.p2 = cmd->b.nc; telldot(cmd); } } @@ -354,9 +354,9 @@ edit(File *f, int cmd) if(cmd == 'r') logdelete(f, addr.r.p1, addr.r.p2); if(cmd=='e' || cmd=='I'){ - logdelete(f, (Posn)0, f->_.nc); - addr.r.p2 = f->_.nc; - }else if(f->_.nc!=0 || (f->name.s[0] && Strcmp(&genstr, &f->name)!=0)) + logdelete(f, (Posn)0, f->b.nc); + addr.r.p2 = f->b.nc; + }else if(f->b.nc!=0 || (f->name.s[0] && Strcmp(&genstr, &f->name)!=0)) empty = FALSE; if((io = open(genc, OREAD))<0) { if (curfile && curfile->unread) @@ -485,17 +485,17 @@ readcmd(String *s) fileclose(flist); flist = fileopen(); - addr.r.p1 = 0, addr.r.p2 = flist->_.nc; + addr.r.p1 = 0, addr.r.p2 = flist->b.nc; retcode = plan9(flist, '<', s, FALSE); fileupdate(flist, FALSE, FALSE); flist->seq = 0; - if (flist->_.nc > BLOCKSIZE) + if (flist->b.nc > BLOCKSIZE) error(Etoolong); Strzero(&genstr); - Strinsure(&genstr, flist->_.nc); - bufread(flist, (Posn)0, genbuf, flist->_.nc); - memmove(genstr.s, genbuf, flist->_.nc*RUNESIZE); - genstr.n = flist->_.nc; + Strinsure(&genstr, flist->b.nc); + bufread(&flist->b, (Posn)0, genbuf, flist->b.nc); + memmove(genstr.s, genbuf, flist->b.nc*RUNESIZE); + genstr.n = flist->b.nc; Straddc(&genstr, '\0'); return retcode; } @@ -673,7 +673,7 @@ copy(File *f, Address addr2) ni = addr.r.p2-p; if(ni > BLOCKSIZE) ni = BLOCKSIZE; - bufread(f, p, genbuf, ni); + bufread(&f->b, p, genbuf, ni); loginsert(addr2.f, addr2.r.p2, tmprstr(genbuf, ni)->s, ni); } addr2.f->ndot.r.p2 = addr2.r.p2+(f->dot.r.p2-f->dot.r.p1); diff --git a/src/cmd/sam/sam.h b/src/cmd/sam/sam.h index 6a2708c1..c6b6873f 100644 --- a/src/cmd/sam/sam.h +++ b/src/cmd/sam/sam.h @@ -110,11 +110,10 @@ enum struct Block { uint addr; /* disk address in bytes */ - union - { + union { uint n; /* number of used runes in block */ Block *next; /* pointer to next in free list */ - } _; + } u; }; struct Disk @@ -151,7 +150,7 @@ void bufreset(Buffer*); struct File { - Buffer _; /* the data */ + Buffer b; /* the data */ Buffer delta; /* transcript of changes */ Buffer epsilon; /* inversion of delta for redo */ String name; /* name of associated file */ diff --git a/src/cmd/sam/xec.c b/src/cmd/sam/xec.c index 42acab0e..b4c68bdb 100644 --- a/src/cmd/sam/xec.c +++ b/src/cmd/sam/xec.c @@ -231,7 +231,7 @@ s_cmd(File *f, Cmd *cp) j = c-'0'; if(sel.p[j].p2-sel.p[j].p1>BLOCKSIZE) error(Elongtag); - bufread(f, sel.p[j].p1, genbuf, sel.p[j].p2-sel.p[j].p1); + bufread(&f->b, sel.p[j].p1, genbuf, sel.p[j].p2-sel.p[j].p1); Strinsert(&genstr, tmprstr(genbuf, (sel.p[j].p2-sel.p[j].p1)), genstr.n); }else Straddc(&genstr, c); @@ -240,7 +240,7 @@ s_cmd(File *f, Cmd *cp) else{ if(sel.p[0].p2-sel.p[0].p1>BLOCKSIZE) error(Elongrhs); - bufread(f, sel.p[0].p1, genbuf, sel.p[0].p2-sel.p[0].p1); + bufread(&f->b, sel.p[0].p1, genbuf, sel.p[0].p2-sel.p[0].p1); Strinsert(&genstr, tmprstr(genbuf, (int)(sel.p[0].p2-sel.p[0].p1)), genstr.n); @@ -390,15 +390,15 @@ display(File *f) p1 = addr.r.p1; p2 = addr.r.p2; - if(p2 > f->_.nc){ - fprint(2, "bad display addr p1=%ld p2=%ld f->_.nc=%d\n", p1, p2, f->_.nc); /*ZZZ should never happen, can remove */ - p2 = f->_.nc; + if(p2 > f->b.nc){ + fprint(2, "bad display addr p1=%ld p2=%ld f->b.nc=%d\n", p1, p2, f->b.nc); /*ZZZ should never happen, can remove */ + p2 = f->b.nc; } while(p1 < p2){ np = p2-p1; if(np>BLOCKSIZE-1) np = BLOCKSIZE-1; - bufread(f, p1, genbuf, np); + bufread(&f->b, p1, genbuf, np); genbuf[np] = 0; c = Strtoc(tmprstr(genbuf, np+1)); if(downloaded) |