aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuss Cox <rsc@swtch.com>2020-01-13 18:15:57 -0500
committerRuss Cox <rsc@swtch.com>2020-01-13 18:15:57 -0500
commitd2df5d6cbd345e101732fe7d22bb5b3baa5fb61a (patch)
tree420d1c6afdd5e8d3d2768955324f61e82207e0e1 /src
parent59b460f845ee7d2e0156a4ba43fbe75c2531489b (diff)
downloadplan9port-d2df5d6cbd345e101732fe7d22bb5b3baa5fb61a.tar.gz
plan9port-d2df5d6cbd345e101732fe7d22bb5b3baa5fb61a.tar.bz2
plan9port-d2df5d6cbd345e101732fe7d22bb5b3baa5fb61a.zip
acme: fix crash in X |cat with multiple windows
Fixes #9. Fixes #219. Fixes #222. Fixes #330.
Diffstat (limited to 'src')
-rw-r--r--src/cmd/acme/ecmd.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/cmd/acme/ecmd.c b/src/cmd/acme/ecmd.c
index 75cf710f..f7613172 100644
--- a/src/cmd/acme/ecmd.c
+++ b/src/cmd/acme/ecmd.c
@@ -28,7 +28,7 @@ int append(File*, Cmd*, long);
int pdisplay(File*);
void pfilename(File*);
void looper(File*, Cmd*, int);
-void filelooper(Cmd*, int);
+void filelooper(Text*, Cmd*, int);
void linelooper(File*, Cmd*);
Address lineaddr(long, Address, int);
int filematch(File*, String*);
@@ -584,7 +584,7 @@ X_cmd(Text *t, Cmd *cp)
{
USED(t);
- filelooper(cp, cp->cmdc=='X');
+ filelooper(t, cp, cp->cmdc=='X');
return TRUE;
}
@@ -978,9 +978,10 @@ alllocker(Window *w, void *v)
}
void
-filelooper(Cmd *cp, int XY)
+filelooper(Text *t, Cmd *cp, int XY)
{
int i;
+ Text *targ;
if(Glooping++)
editerror("can't nest %c command", "YX"[XY]);
@@ -1001,8 +1002,26 @@ filelooper(Cmd *cp, int XY)
*/
allwindows(alllocker, (void*)1);
globalincref = 1;
- for(i=0; i<loopstruct.nw; i++)
- cmdexec(&loopstruct.w[i]->body, cp->u.cmd);
+
+ /*
+ * Unlock the window running the X command.
+ * We'll need to lock and unlock each target window in turn.
+ */
+ if(t && t->w)
+ winunlock(t->w);
+
+ for(i=0; i<loopstruct.nw; i++) {
+ targ = &loopstruct.w[i]->body;
+ if(targ && targ->w)
+ winlock(targ->w, cp->cmdc);
+ cmdexec(targ, cp->u.cmd);
+ if(targ && targ->w)
+ winunlock(targ->w);
+ }
+
+ if(t && t->w)
+ winlock(t->w, cp->cmdc);
+
allwindows(alllocker, (void*)0);
globalincref = 0;
free(loopstruct.w);