From 78439d25f8b2f6f2289e9f4e4400e0f7cdb5fa70 Mon Sep 17 00:00:00 2001 From: rsc Date: Fri, 12 Jan 2007 15:57:34 +0000 Subject: Fix 15-year-old sam protocol bug. --- src/cmd/sam/file.c | 27 +++------------------------ src/cmd/sam/mesg.c | 21 +++++++++++++-------- src/cmd/sam/rasp.c | 17 ++++++++++++++++- src/cmd/sam/sam.h | 3 ++- 4 files changed, 34 insertions(+), 34 deletions(-) (limited to 'src/cmd/sam') diff --git a/src/cmd/sam/file.c b/src/cmd/sam/file.c index 875a26c7..c0771e05 100644 --- a/src/cmd/sam/file.c +++ b/src/cmd/sam/file.c @@ -265,18 +265,6 @@ filedeltext(File *f, Text *t) } #endif -void -fileinsert(File *f, uint p0, Rune *s, uint ns) -{ - if(p0 > f->b.nc) - panic("internal error: fileinsert"); - if(f->seq > 0) - fileuninsert(f, &f->delta, p0, ns); - bufinsert(&f->b, p0, s, ns); - if(ns) - f->mod = TRUE; -} - void fileuninsert(File *f, Buffer *delta, uint p0, uint ns) { @@ -291,18 +279,6 @@ fileuninsert(File *f, Buffer *delta, uint p0, uint ns) bufinsert(delta, delta->nc, (Rune*)&u, Undosize); } -void -filedelete(File *f, uint p0, uint p1) -{ - 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->b, p0, p1); - if(p1 > p0) - f->mod = TRUE; -} - void fileundelete(File *f, Buffer *delta, uint p0, uint p1) { @@ -499,6 +475,9 @@ fileundo(File *f, int isundo, int canredo, uint *q0p, uint *q1p, int flag) raspstart(f); while(delta->nc > 0){ + /* rasp and buffer are in sync; sync with wire if needed */ + if(needoutflush()) + raspflush(f); up = delta->nc-Undosize; bufread(delta, up, (Rune*)&u, Undosize); if(isundo){ diff --git a/src/cmd/sam/mesg.c b/src/cmd/sam/mesg.c index 8250336f..52983703 100644 --- a/src/cmd/sam/mesg.c +++ b/src/cmd/sam/mesg.c @@ -1,5 +1,5 @@ #include "sam.h" - +#define DEBUG Header h; uchar indata[DATASIZE]; uchar outdata[2*DATASIZE+3]; /* room for overflow message */ @@ -10,7 +10,7 @@ Posn cmdpt; Posn cmdptadv; Buffer snarfbuf; int waitack; -int noflush; +int outbuffered; int tversion; int inshort(void); @@ -807,21 +807,26 @@ outsend(void) { int outcount; + if(outp >= outdata+nelem(outdata)) + panic("outsend"); outcount = outp-outmsg; outcount -= 3; outmsg[1] = outcount; outmsg[2] = outcount>>8; outmsg = outp; - if(!noflush){ + if(!outbuffered){ outcount = outmsg-outdata; if (write(1, (char*) outdata, outcount) != outcount) rescue(); outmsg = outdata; return; } - if(outmsg < outdata+DATASIZE) - return; - outflush(); +} + +int +needoutflush(void) +{ + return 1; } void @@ -829,7 +834,7 @@ outflush(void) { if(outmsg == outdata) return; - noflush = 0; + outbuffered = 0; outT0(Hack); waitack = 1; do @@ -839,5 +844,5 @@ outflush(void) } while(waitack); outmsg = outdata; - noflush = 1; + outbuffered = 1; } diff --git a/src/cmd/sam/rasp.c b/src/cmd/sam/rasp.c index 829a7b49..5a691129 100644 --- a/src/cmd/sam/rasp.c +++ b/src/cmd/sam/rasp.c @@ -3,7 +3,7 @@ * GROWDATASIZE must be big enough that all errors go out as Hgrowdata's, * so they will be scrolled into visibility in the ~~sam~~ window (yuck!). */ -#define GROWDATASIZE 50 /* if size is > this, send data with grow */ +#define GROWDATASIZE 50 /* if size is <= this, send data with grow */ void rcut(List*, Posn, Posn); int rterm(List*, Posn); @@ -79,6 +79,20 @@ raspdone(File *f, int toterm) } } +void +raspflush(File *f) +{ + if(grown){ + outTsll(Hgrow, f->tag, growpos, grown); + grown = 0; + } + else if(shrunk){ + outTsll(Hcut, f->tag, shrinkpos, shrunk); + shrunk = 0; + } + outflush(); +} + void raspdelete(File *f, uint p1, uint p2, int toterm) { @@ -323,3 +337,4 @@ rdata(List *r, Posn p1, Posn n) } return rg; } + diff --git a/src/cmd/sam/sam.h b/src/cmd/sam/sam.h index ca92c48d..4f2f2cfd 100644 --- a/src/cmd/sam/sam.h +++ b/src/cmd/sam/sam.h @@ -218,6 +218,7 @@ void raspstart(File*); void raspdelete(File*, uint, uint, int); void raspinsert(File*, uint, Rune*, uint, int); void raspdone(File*, int); +void raspflush(File*); /* * acme fns @@ -404,4 +405,4 @@ void outTsll(Hmesg, int, long, long); void outTsl(Hmesg, int, long); void outTsv(Hmesg, int, vlong); void outflush(void); - +int needoutflush(void); -- cgit v1.2.3