aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2007-01-12 15:57:34 +0000
committerrsc <devnull@localhost>2007-01-12 15:57:34 +0000
commit78439d25f8b2f6f2289e9f4e4400e0f7cdb5fa70 (patch)
tree52eeabba50ee6446174e9228a5e27f68c4fd631e /src/cmd
parentad2922ef28f026b8bbd0aee30d92f703613c1486 (diff)
downloadplan9port-78439d25f8b2f6f2289e9f4e4400e0f7cdb5fa70.tar.gz
plan9port-78439d25f8b2f6f2289e9f4e4400e0f7cdb5fa70.tar.bz2
plan9port-78439d25f8b2f6f2289e9f4e4400e0f7cdb5fa70.zip
Fix 15-year-old sam protocol bug.
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/sam/file.c27
-rw-r--r--src/cmd/sam/mesg.c21
-rw-r--r--src/cmd/sam/rasp.c17
-rw-r--r--src/cmd/sam/sam.h3
4 files changed, 34 insertions, 34 deletions
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
@@ -266,18 +266,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)
{
Undo u;
@@ -292,18 +280,6 @@ fileuninsert(File *f, Buffer *delta, uint p0, uint ns)
}
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)
{
Undo u;
@@ -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);
@@ -80,6 +80,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)
{
long n;
@@ -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);