summaryrefslogtreecommitdiff
path: root/sys/src/cmd/sam
diff options
context:
space:
mode:
authorftrvxmtrx <ftrvxmtrx@gmail.com>2014-12-21 01:28:14 +0100
committerftrvxmtrx <ftrvxmtrx@gmail.com>2014-12-21 01:28:14 +0100
commit758496ecaa42b5f6c17c0bd1e0f43189e50e0745 (patch)
tree160edba01a6f720d146b811c134a137d855a9846 /sys/src/cmd/sam
parent476a47b15c152e72aa8a6d9f9eb363931cbfd50f (diff)
sam: '^' and '_' cmds; same as '<' and '|' except that stdout goes to the command window
Diffstat (limited to 'sys/src/cmd/sam')
-rw-r--r--sys/src/cmd/sam/cmd.c10
-rw-r--r--sys/src/cmd/sam/sam.h2
-rw-r--r--sys/src/cmd/sam/shell.c21
3 files changed, 25 insertions, 8 deletions
diff --git a/sys/src/cmd/sam/cmd.c b/sys/src/cmd/sam/cmd.c
index a0e336f01..6e8efa094 100644
--- a/sys/src/cmd/sam/cmd.c
+++ b/sys/src/cmd/sam/cmd.c
@@ -35,6 +35,8 @@ Cmdtab cmdtab[]={
'>', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd,
'<', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd,
'|', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd,
+ '^', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd,
+ '_', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd,
'=', 0, 0, 0, 0, aDot, 0, linex, eq_cmd,
'c'|0x100,0, 0, 0, 0, aNo, 0, wordx, cd_cmd,
0, 0, 0, 0, 0, 0, 0, 0,
@@ -76,7 +78,13 @@ inputc(void)
Again:
nbuf = 0;
- if(downloaded){
+ if(cmdbufpos > cmdbuf.nc && cmdbuf.nc > 0){
+ cmdbufpos = 0;
+ bufreset(&cmdbuf);
+ }
+ if(cmdbufpos < cmdbuf.nc && cmdbuf.nc > 0)
+ bufread(&cmdbuf, cmdbufpos++, &r, 1);
+ else if(downloaded){
while(termoutp == terminp){
cmdupdate();
if(patset)
diff --git a/sys/src/cmd/sam/sam.h b/sys/src/cmd/sam/sam.h
index a5ff1b9a2..f1cbd8ac0 100644
--- a/sys/src/cmd/sam/sam.h
+++ b/sys/src/cmd/sam/sam.h
@@ -361,6 +361,8 @@ extern int quitok;
extern Address addr;
extern Buffer snarfbuf;
extern Buffer plan9buf;
+extern Buffer cmdbuf;
+extern int cmdbufpos;
extern List file;
extern List tempfile;
extern File *cmd;
diff --git a/sys/src/cmd/sam/shell.c b/sys/src/cmd/sam/shell.c
index fe9162fc6..c0eced359 100644
--- a/sys/src/cmd/sam/shell.c
+++ b/sys/src/cmd/sam/shell.c
@@ -7,6 +7,8 @@ char errfile[64];
String plan9cmd; /* null terminated */
Buffer plan9buf;
void checkerrs(void);
+Buffer cmdbuf;
+int cmdbufpos;
int
plan9(File *f, int type, String *s, int nest)
@@ -28,7 +30,7 @@ plan9(File *f, int type, String *s, int nest)
}
if(type!='!' && pipe(pipe1)==-1)
error(Epipe);
- if(type=='|')
+ if(type=='|' || type=='_')
snarf(f, addr.r.p1, addr.r.p2, &plan9buf, 1);
if((pid=fork()) == 0){
if(downloaded){ /* also put nasty fd's into errfile */
@@ -48,14 +50,14 @@ plan9(File *f, int type, String *s, int nest)
}
}
if(type != '!') {
- if(type=='<' || type=='|')
- dup(pipe1[1], 1);
- else if(type == '>')
+ if(type == '>')
dup(pipe1[0], 0);
+ else
+ dup(pipe1[1], 1);
close(pipe1[0]);
close(pipe1[1]);
}
- if(type == '|'){
+ if(type == '|' || type == '_'){
if(pipe(pipe2) == -1)
exits("pipe");
if((pid = fork())==0){
@@ -87,7 +89,7 @@ plan9(File *f, int type, String *s, int nest)
close(pipe2[0]);
close(pipe2[1]);
}
- if(type=='<'){
+ if(type=='<' || type=='^'){
close(0); /* so it won't read from terminal */
open("/dev/null", 0);
}
@@ -115,9 +117,14 @@ plan9(File *f, int type, String *s, int nest)
writeio(f);
bpipeok = 0;
closeio((Posn)-1);
+ }else if(type == '^' || type == '_'){
+ int nulls;
+ close(pipe1[1]);
+ bufload(&cmdbuf, cmdbufpos, pipe1[0], &nulls);
+ close(pipe1[0]);
}
retmsg = waitfor(pid);
- if(type=='|' || type=='<')
+ if(type=='|' || type=='<' || type=='_' || type=='^')
if(retmsg[0]!=0)
warn_s(Wbadstatus, retmsg);
if(downloaded)