static int menu(Conn *c) { char buf[1024]; int32_t n; int done; int wasraw; wasraw = raw; if(wasraw) rawoff(); buf[0] = '?'; fprint(2, ">>> "); for(done = 0; !done; ){ n = read(0, buf, sizeof(buf)-1); if(n <= 0) return -1; buf[n] = 0; switch(buf[0]){ case '!': print(buf); system(c, buf+1); print("!\n"); done = 1; break; case 'i': buf[0] = 0x1c; sendwritemsg(c, buf, 1); done = 1; break; case '.': case 'q': done = 1; break; case 'r': crstrip = 1-crstrip; done = 1; break; default: fprint(2, STDHELP); break; } if(!done) fprint(2, ">>> "); } if(wasraw) rawon(); else rawoff(); return buf[0]; }
/* * two processes pass bytes back and forth between the * terminal and the network. */ void telnet(int net) { int pid; int p[2]; char *svc; rawoff(); svc = nil; if (srv) { if(pipe(p) < 0) sysfatal("pipe: %r"); if (srv[0] != '/') svc = smprint("/srv/%s", srv); else svc = srv; post(svc, p[0]); close(p[0]); dup(p[1], 0); dup(p[1], 1); /* pipe is now std in & out */ } ttypid = getpid(); switch(pid = rfork(RFPROC|RFFDG|RFMEM)){ case -1: perror("con"); exits("fork"); case 0: rawoff(); notify(notifyf); fromnet(net); if (svc) remove(svc); sendnote(ttypid, "die"); exits(0); default: netpid = pid; notify(notifyf); fromkbd(net); if(notkbd) for(;;) sleep(0); if (svc) remove(svc); sendnote(netpid, "die"); exits(0); } }
int menu(Biobuf *bp, int net) { char *cp; int done; comm->stopped = 1; rawoff(); fprint(2, ">>> "); for(done = 0; !done; ){ cp = Brdline(bp, '\n'); if(cp == 0){ comm->stopped = 0; return -1; } cp[Blinelen(bp)-1] = 0; switch(*cp){ case '!': system(Bfildes(bp), cp+1); done = 1; break; case '.': done = 1; break; case 'q': comm->stopped = 0; return -1; case 'o': switch(*(cp+1)){ case 'd': send3(net, Iac, Do, atoi(cp+2)); break; case 'w': send3(net, Iac, Will, atoi(cp+2)); break; } break; case 'r': comm->returns = !comm->returns; done = 1; break; case 'i': send2(net, Iac, Interrupt); break; case 'b': send2(net, Iac, Break); break; default: fprint(2, STDHELP); break; } if(!done) fprint(2, ">>> "); } rawon(); comm->stopped = 0; return 0; }
/* * suppress local echo if the remote side is doing it */ int echochange(Biobuf *bp, int cmd) { USED(bp); switch(cmd){ case Will: rawon(); break; case Wont: rawoff(); break; } return 0; }