- int ds,fk,lcl,x;
- char *p,b[600];
- for (;;) {
- p=b;
- while (rdc(0) == 1) {
- if (p == b) lcl=(c == cmdchar);
- if (p == b+1 && b[0] == cmdchar) lcl=(c!=cmdchar);
- if (!lcl) {
- c = oc;
- if (wrc(rem) == 0) {
- prf("line gone"); return;
- }
- if (eight == 0)
- c &= 0177;
- }
- if (lcl) {
- if (c == 0177) c=tkill;
- if (c == '\r' || c == '\n') goto A;
- wrc(0);
- }
- *p++=c;
- if (c == terase) {
- p=p-2;
- if (p<b) p=b;
- }
- if (c == tkill || c == 0177 || c == '\4' || c == '\r' || c == '\n') p=b;
- }
- return;
-A:
- echo("");
- *p=0;
- switch (b[1]) {
- case '.':
- case '\004':
- return;
- case '!':
- case '$':
- fk = fork();
- signal(SIGCHLD, SIG_DFL);
- if (fk == 0) {
- char *shell = getenv("SHELL");
- if (shell == 0) shell = "/bin/sh";
- close(1);
- dup(b[1] == '$'? rem:2);
- close(rem);
- mode(0);
- if (!nhup) signal(SIGINT, SIG_DFL);
- if (b[2] == 0) execl(shell,shell,0);
- /* if (b[2] == 0) execl(shell,"-",0); */
- else execl(shell,"sh","-c",b+2,0);
- prf("Can't execute shell");
- exit(~0);
- }
- if (fk!=(-1)) {
- while (wait(&x)!=fk);
- }
- signal(SIGCHLD, done);
- mode(1);
- if (b[1] == '!') echo("!");
- break;
- case '<':
- if (b[2] == 0) break;
- if ((ds=open(b+2,0))<0) {
- prf("Can't divert %s",b+1);
- break;
- }
- intr=x=0;
- mode(2);
- if (!nhup) signal(SIGINT, sig2);
- while (!intr && rdc(ds) == 1) {
- if (wrc(rem) == 0) {
- x=1;
- break;
- }
- }
- signal(SIGINT, SIG_IGN);
- close(ds);
- mode(1);
- if (x) return;
- break;
- case '>':
- case ':':
- {
- register char *q;