void ex_rd() { /* note: * an empty line is converted to NULL. * no '\n' chars are returned. */ char buf[200]; struct item* p; int fd, i; SECURITY_CHECK; fd = topfix(); i = 0; while ((read(fd, &buf[i], 1) == 1) && i < 200 && buf[i] != '\n') i++; if (i == 200) error(ERR_limit, "input buffer overflow"); if (i > 0) { p = newdat(CH, 1, i); copy(CH, (char*)buf, (char*)p->datap, i); } else p = newdat(CH, 1, 0); *sp++ = p; }
ex_gddk() { int k; k = topfix() - thread.iorg; fetch1(); gd0(k, gdd); }
void ex_comk() { int k; k = topfix() - iorigin; fetch2(); comk(k); }
ex_revk() { int k; k = topfix() - thread.iorg; fetch1(); revk(k); }
ex_miot() { struct item *p; data *dp; int i; i = topfix(); if(i < 0) { /* must allocate something to ")reset" properly */ *sp++ = newdat(DA, 1, 0); error("miot D"); } p = newdat(DA, 1, i); dp = p->datap; datum = thread.iorg; for(; i; i--) { *dp++ = datum; datum += one; } *sp++ = p; }
ex_immed() { int i, *ip, j; struct item *p; struct nlist *n; double f; char fname[64]; /* Array for filename */ char *cp, *vfname(); i = *pcp++; switch(i) { default: error("immed B"); case SCRIPT: if(protofile > 0) close(protofile); protofile = 0; cp = vfname(fname); if(equal(cp, "off")) return; if((protofile = open(cp, 1)) > 0){ lseek(protofile, 0L, 2); /* append to existing file */ printf("[appending]\n"); } else { /* * create new file */ protofile = opn(cp, 0644); printf("[new file]\n"); } write(protofile, "\t)script on\n", 12); return; case DEBUG: debug = ~debug; return; case MEMORY: memoryCheck(); return; case DIGITS: i = topfix(); if(i < 1 || i > 20) error("digits D"); printf("was %d\n",thread.digits); thread.digits = i; return; case TRACE: funtrace = 1; return; case UNTRACE: funtrace = 0; return; case WRITE: funwrite(0); return; case DEL: case EDITF: sp[0] = sp[-1]; /* duplicate top of stack */ sp++; funwrite(scr_file); funedit(scr_file, i); unlink(scr_file); return; case EDIT: funedit(0, i); return; case FUZZ: i = topfix(); if(i <= 0) { thread.fuzz = 0.; return; } f = i; thread.fuzz = exp(-f*2.3025851); return; case ORIGIN: printf("was %d\n",thread.iorg); thread.iorg = topfix(); return; case WIDTH: i = topfix(); if(i < 1) error("width D"); printf("was %d\n",thread.width); thread.width = i; return; case READ: funread(0); return; case ERASE: p = sp[-1]; sp--; erase(p); return; case CONTIN: i = opn("continue", 0644); wssave(i, 0); printf(" continue"); case OFF: term(0); case VARS: for(n=nlist; n->namep; n++) { if(n->itemp && n->use == DA && n->namep[0] != 'L') { if(column+8 >= thread.width) printf("\n\t"); printf(n->namep); putchar('\t'); } } putchar('\n'); return; case FNS: for(n=nlist; n->namep; n++) { if(n->use == DF || n->use == MF || n->use == NF) { if(column+8 >= thread.width) printf("\n\t"); printf(n->namep); putchar('\t'); } } putchar('\n'); return; case CODE: n = (struct nlist *)sp[-1]; sp--; switch(n->use){ default: error("not a fn"); case NF: case MF: case DF: if(n->itemp == 0) funcomp(n); ip = (int *)n->itemp; for(i=0; i <= *ip; i++){ printf(" [%d] ", i); dump(ip[i+1], 0); } putchar('\n'); } return; case RESET: while(gsip) ex_ibr0(); longjmp(reset_env, 0); case SICOM: tback(1); return; case CLEAR: clear(); printf("clear ws\n"); goto warp1; /* four lines down, or so... */ case LOAD: case PLOAD: j = opn(vfname(fname), 0); clear(); if (i == LOAD) wsload(j, 0); if (i == PLOAD) wsload(j, 1); printf(" %s\n", fname); evLlx(); /* possible latent expr evaluation */ warp1: /* * this garbage is necessary because clear() * does a brk(&end), and the normal return & cleanup * procedures are guaranteed to fail (miserably). * --jjb 1/78 */ sp = stack; longjmp(reset_env, 0); case LIB: listdir(); return; case COPY: if(gsip) error("si damage -- type ')reset'"); wsload(opn(vfname(fname),0), 0); printf(" copy %s\n", fname); return; case DROPC: cp = vfname(fname); if(unlink(cp) == -1) printf("[can't remove %s]\n", cp); return; case SAVE: case PSAVE: j = opn(vfname(fname), 0644); if (i == SAVE) wssave(j, 0); if (i == PSAVE) wssave(j, 1); printf(" saved %s\n", fname); return; case VSAVE: i = opn(vfname(fname), 0644); vsave(i); putchar('\n'); return; case SHELL: ex_shell(); return; case LIST: ex_list(); return; case PRWS: ex_prws(); return; } }
void ex_close() { SECURITY_CHECK; iodone(close(topfix())); }