void cmdloop(void) { Cmd *cmdp; File *ocurfile; int loaded; for(;;){ if(!downloaded && curfile && curfile->unread) load(curfile); if((cmdp = parsecmd(0))==0){ if(downloaded){ rescue(); exits("eof"); } break; } ocurfile = curfile; loaded = curfile && !curfile->unread; if(cmdexec(curfile, cmdp) == 0) break; freecmd(); cmdupdate(); update(); if(downloaded && curfile && (ocurfile!=curfile || (!loaded && !curfile->unread))) outTs(Hcurrent, curfile->tag); /* don't allow type ahead on files that aren't bound */ if(downloaded && curfile && curfile->rasp == 0) terminp = termoutp; } }
int inputc(void) { int n, nbuf; char buf[UTFmax]; Rune r; Again: nbuf = 0; 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) tellpat(); while(termlocked > 0){ outT0(Hunlock); termlocked--; } if(rcv() == 0) return -1; } r = *termoutp++; if(termoutp == terminp) terminp = termoutp = termline; }else{ do{ n = read(0, buf+nbuf, 1); if(n <= 0) return -1; nbuf += n; }while(!fullrune(buf, nbuf)); chartorune(&r, buf); } if(r == 0){ warn(Wnulls); goto Again; } return r; }