casern(){ register i,j; lgf++; skip(); if(((i=getrq())==0) || ((oldmn=findmn(i)) < 0))return; skip(); clrmn(findmn(j=getrq())); if(j)contab[oldmn].rq = (contab[oldmn].rq & MMASK) | j; }
int control(int a, int b) { int j, k; extern Contab *contabp; numerr.type = RQERR; numerr.req = a; if (a == 0 || (j = findmn(a)) == -1) return(0); if (contabp[j].f == 0) { if (trace & TRMAC) fprintf(stderr, "invoke macro %s\n", unpair(a)); if (dip != d) for (k = dilev; k; k--) if (d[k].curd == a) { ERROR "diversion %s invokes itself during diversion", unpair(a) WARN; edone(0100); } nxf->nargs = 0; if (b) collect(); flushi(); return pushi(contabp[j].mx, a); /* BUG??? all that matters is 0/!0 */ } if (b) { if (trace & TRREQ) fprintf(stderr, "invoke request %s\n", unpair(a)); (*contabp[j].f)(); } return(0); }
casern() { register i, j; lgf++; skip(); if ((i = getrq()) == 0 || (oldmn = findmn(i)) < 0) return; skip(); clrmn(findmn(j = getrq())); if (j) { munhash(&contab[oldmn]); contab[oldmn].rq = j; maddhash(&contab[oldmn]); } }
void casern(void) { int i, j, k; lgf++; skip(); if ((i = getrq()) == 0 || (oldmn = findmn(i)) < 0) return; skip(); clrmn(findmn(j = getrq())); if (j) { munhash(&contabp[oldmn]); contabp[oldmn].rq = j; maddhash(&contabp[oldmn]); if (dip != d ) for (k = dilev; k; k--) if (d[k].curd == i) d[k].curd = j; } }
void casegd(void) { int i, j; skip(); if ((i = getrq()) == 0) return; if ((j = findmn(i)) >= 0) { if (contabp[j].divsiz != NULL) { numtabp[DN].val = contabp[j].divsiz->dix; numtabp[DL].val = contabp[j].divsiz->diy; } } }
Offset finds(int mn) { int i; Tchar j = IMP; Offset savip; oldmn = findmn(mn); newmn = 0; apptr = 0; if (app && oldmn >= 0 && contabp[oldmn].mx) { savip = ip; ip = contabp[oldmn].emx; oldmn = -1; apptr = ip; if (!diflg) ip = incoff(ip); nextb = ip; ip = savip; } else { for (i = freeslot; i < nm; i++) { if (contabp[i].rq == 0) break; } if (i == nm) growcontab(); freeslot = i + 1; if ((nextb = alloc()) == -1) { app = 0; if (macerr++ > 1) done2(02); if (nextb == 0) ERROR "Not enough space for string/macro names" WARN; edone(04); return(offset = 0); } contabp[i].mx = nextb; if (!diflg) { newmn = i; if (oldmn == -1) contabp[i].rq = -1; } else { contabp[i].rq = mn; maddhash(&contabp[i]); } } app = 0; return(offset = nextb); }
Offset setstr(void) { int i, j; lgf++; if ((i = getsn()) == 0 || (j = findmn(i)) == -1 || !contabp[j].mx) { lgf--; return(0); } else { SPACETEST(nxf, sizeof(Stack)); nxf->nargs = 0; strflg++; lgf--; return pushi(contabp[j].mx, i); } }
void caserm(void) { int j; int k = 0; lgf++; g0: while (!skip() && (j = getrq()) != 0) { if (dip != d) for (k = dilev; k; k--) if (d[k].curd == j) { ERROR "cannot remove diversion %s during definition", unpair(j) WARN; goto g0; } clrmn(findmn(j)); } lgf--; }
void casede(void) { int i, req; Offset savoff; req = '.'; lgf++; skip(); if ((i = getrq()) == 0) goto de1; if ((offset = finds(i)) == 0) goto de1; if (newmn) savslot = newmn; else savslot = findmn(i); savname = i; if (ds) copys(); else req = copyb(); clrmn(oldmn); if (newmn) { if (contabp[newmn].rq) munhash(&contabp[newmn]); contabp[newmn].rq = i; maddhash(&contabp[newmn]); } if (apptr) { savoff = offset; offset = apptr; wbf((Tchar) IMP); offset = savoff; } offset = dip->op; if (req != '.') control(req, 1); de1: ds = app = 0; }
caserm(){ lgf++; while(!skip()){ clrmn(findmn(getrq())); } }
static void tmtmcwr(int ab, int tmc, int wr, int ep, int tmm) { const char tmtab[] = { 'a',000,000,000,000,000,000,000, 000,000,000,000,000,000,000,000, '{','}','&',000,'%','c','e',' ', '!',000,000,000,000,000,000,'~', 000 }; struct contab *cp; register int i, j; tchar c; char tmbuf[NTM]; filep savip = ip; int discard = 0; lgf++; if (tmm) { if (skip(1) || (i = getrq(0)) == 0) return; if ((cp = findmn(i)) == NULL || !cp->mx) { nosuch(i); return; } savip = ip; ip = (filep)cp->mx; app++; copyf++; } else { copyf++; if (skip(0) && ab) errprint("User Abort"); } loop: for (i = 0; i < NTM - 5 - mb_cur_max; ) { if (tmm) { if ((c = rbf()) == 0) { ip = savip; tmm = 0; app--; break; } } else c = getch(); if (discard) { discard--; continue; } if (c == '\n') { tmbuf[i++] = '\n'; break; } c: j = cbits(c); if (iscopy(c)) { int n; if ((n = wctomb(&tmbuf[i], j)) > 0) { i += n; continue; } } if (xflag == 0) { tmbuf[i++] = c; continue; } if (ismot(c)) continue; tmbuf[i++] = '\\'; if (c == (OHC|BLBIT)) j = ':'; else if (istrans(c)) j = ')'; else if (j >= 0 && j < sizeof tmtab && tmtab[j]) j = tmtab[j]; else if (j == ACUTE) j = '\''; else if (j == GRAVE) j = '`'; else if (j == UNDERLINE) j = '_'; else if (j == MINUS) j = '-'; else { i--; if (c == WORDSP) j = ' '; else if (j == WORDSP) continue; else if (j == FLSS) { discard++; continue; } } if (j == XFUNC) switch (fbits(c)) { case CHAR: c = charout[sbits(c)].ch; goto c; default: continue; } tmbuf[i++] = j; } if (i == NTM - 2) tmbuf[i++] = '\n'; if (tmc) i--; tmbuf[i] = 0; if (ab) /* truncate output */ obufp = obuf; /* should be a function in n2.c */ if (ep) { flusho(); errprint("%s", tmbuf); } else if (wr < 0) { flusho(); fdprintf(stderr, "%s", tmbuf); } else if (i) write(wr, tmbuf, i); if (tmm) goto loop; copyf--; lgf--; }
void caseif(int x) { extern int falsef; register int notflag, true; tchar i, j; enum warn w = warn; int flt = 0; if (x == 3) goto i2; if (x == 2) { notflag = 0; true = iflist ? iflist[ifx] : 0; goto i1; } true = 0; skip(1); if ((cbits(i = getch())) == '!') { notflag = 1; if (xflag == 0) /*EMPTY*/; else if ((cbits(i = getch())) == 'f') flt = 1; else ch = i; } else if (xflag && cbits(i) == 'f') { flt = 1; notflag = 0; } else { notflag = 0; ch = i; } if (flt) i = atof0() > 0; else i = (int)atoi0(); if (!nonumb) { if (i > 0) true++; goto i1; } i = getch(); switch (cbits(i)) { case 'e': if (!(numtab[PN].val & 01)) true++; break; case 'o': if (numtab[PN].val & 01) true++; break; #ifdef NROFF case 'n': true++; case 't': #endif #ifndef NROFF case 't': true++; case 'n': #endif break; case 'c': if (xflag == 0) goto dfl; warn &= ~WARN_CHAR; tryglf++; if (!skip(1)) { j = getch(); true = !ismot(j) && cbits(j) && cbits(j) != ' '; } tryglf--; warn = w; break; case 'r': case 'd': if (xflag == 0) goto dfl; warn &= ~(WARN_MAC|WARN_SPACE|WARN_REG); if (!skip(1)) { j = getrq(2); true = (cbits(i) == 'r' ? usedr(j) != NULL : findmn(j) != NULL); } warn = w; break; case ' ': break; default: dfl: true = cmpstr(i); } i1: true ^= notflag; if (x == 1) { if (ifx >= NIF) growiflist(); iflist[ifx] = !true; } if (true) { if (frame->loopf & LOOP_EVAL) { if (nonumb) goto i3; frame->loopf &= ~LOOP_EVAL; frame->loopf |= LOOP_NEXT; } i2: while ((cbits(i = getch())) == ' ') ; if (cbits(i) == LEFT) goto i2; ch = i; nflush++; } else { i3: if (frame->loopf & LOOP_EVAL) frame->loopf = LOOP_FREE; copyf++; falsef++; eatblk(0); copyf--; falsef--; } }