void casehcode(void) { tchar c, d; int k; lgf++; if (skip(1)) return; do { c = getch(); if (skip(1)) break; d = getch(); if (c && d && !ismot(c) && !ismot(d)) { if ((k = cbits(c)) >= nhcode) { hcode = realloc(hcode, (k+1) * sizeof *hcode); memset(&hcode[nhcode], 0, (k+1-nhcode) * sizeof *hcode); nhcode = k+1; } hcode[k] = cbits(d); } } while (!skip(0)); }
void n_setps(void ) { int i, j; i = cbits(getch()); if (isdigit(i)) { /* \sd or \sdd */ i -= '0'; if (i == 0) /* \s0 */ ; else if (i <= 3 && (ch=getch()) && isdigit(cbits(ch))) { /* \sdd */ ch = 0; } } else if (i == '(') { /* \s(dd */ getch(); getch(); } else if (i == '+' || i == '-') { /* \s+, \s- */ j = cbits(getch()); if (isdigit(j)) { /* \s+d, \s-d */ ; } else if (j == '(') { /* \s+(dd, \s-(dd */ getch(); getch(); } } }
void setbra(void) { int k; Tchar i, *j, dwn; int cnt, delim; Tchar brabuf[NC]; if (ismot(i = getch())) return; delim = cbits(i); j = brabuf + 1; cnt = 0; if (NROFF) dwn = (2 * t.Halfline) | MOT | VMOT; else dwn = EM | MOT | VMOT; while ((k = cbits(i = getch())) != delim && k != '\n' && j <= brabuf + NC - 4) { *j++ = i | ZBIT; *j++ = dwn; cnt++; } if (--cnt < 0) return; else if (!cnt) { ch = *(j - 2); return; } *j = 0; if (NROFF) *--j = *brabuf = (cnt * t.Halfline) | MOT | NMOT | VMOT; else *--j = *brabuf = (cnt * EM) / 2 | MOT | NMOT | VMOT; *--j &= ~ZBIT; pushback(brabuf); }
int setvline(void) { int i; tchar c, rem, ver, neg; int cnt, delim, v; tchar vlbuf[NC]; tchar *vlp; if (ismot(c = getch())) return (0); delim = cbits(c); dfact = lss; vflag++; i = quant(atoi(), VERT); dfact = 1; if (!i) { eat(delim); vflag = 0; return (0); } if ((cbits(c = getch())) == delim) { c = BOXRULE | chbits; /* default box rule */ } else getch(); c |= ZBIT; neg = 0; if (i < 0) { i = -i; neg = NMOT; } #ifdef NROFF v = 2 * t.Halfline; #endif #ifndef NROFF v = EM; #endif cnt = i / v; rem = makem(i % v) | neg; ver = makem(v) | neg; vlp = vlbuf; if (!neg) *vlp++ = ver; if (absmot(rem) != 0) { *vlp++ = c; *vlp++ = rem; } while ((vlp < (vlbuf + NC - 3)) && cnt--) { *vlp++ = c; *vlp++ = ver; } *(vlp - 2) &= ~ZBIT; if (!neg) vlp--; *vlp++ = 0; pushback(vlbuf); vflag = 0; return (0); }
void casetr(int flag) { register int i, j; tchar k; lgf++; skip(1); while ((i = cbits(k=getch())) != '\n') { if (ismot(k)) return; if (ismot(k = getch())) return; if ((j = cbits(k)) == '\n') j = ' '; trtab[i] = j; if (flag & 1) trintab[j] = i; else trintab[j] = 0; if (flag & 2) trnttab[i] = i; else trnttab[i] = j; } }
void eatblk(int inblk) { register int cnt, i; tchar ii; cnt = 0; do { if (ch) { i = cbits(ii = ch); ch = 0; } else i = cbits(ii = getch0()); if (i == ESC) cnt++; else { if (cnt == 1) switch (i) { case '{': i = LEFT; break; case '}': i = RIGHT; break; case '\n': i = 'x'; break; } cnt = 0; } if (i == LEFT) eatblk(1); } while ((!inblk && (i != '\n')) || (inblk && (i != RIGHT))); if (i == '\n') { nlflg++; tailflg = istail(ii); } }
void setvline(void) { int i; Tchar c, rem, ver, neg; int cnt, delim, v; Tchar vlbuf[NC]; Tchar *vlp; if (ismot(c = getch())) return; delim = cbits(c); dfact = lss; vflag++; i = quant(atoi0(), VERT); dfact = 1; if (!i) { eat(delim); vflag = 0; return; } if ((cbits(c = getch())) == delim) { c = BOXRULE | chbits; /*default box rule*/ } else getch(); c |= ZBIT; neg = 0; if (i < 0) { i = -i; neg = NMOT; } if (NROFF) v = 2 * t.Halfline; else { v = EM; if (v < VERT) /* ATT EVK hack: Erik van Konijnenburg, */ v = VERT; /* hvlpb!evkonij, ATT NSI Hilversum, Holland */ } cnt = i / v; rem = makem(i % v) | neg; ver = makem(v) | neg; vlp = vlbuf; if (!neg) *vlp++ = ver; if (absmot(rem) != 0) { *vlp++ = c; *vlp++ = rem; } while (vlp < vlbuf + NC - 3 && cnt--) { *vlp++ = c; *vlp++ = ver; } *(vlp - 2) &= ~ZBIT; if (!neg) vlp--; *vlp = 0; pushback(vlbuf); vflag = 0; }
static int warn1(void) { char name[NC]; int n, sign; size_t i; tchar c; switch (cbits(c = getch())) { case '-': c = getch(); sign = -1; break; case '+': c = getch(); sign = 1; break; default: sign = 0; break; case 0: return 1; } ch = c; n = atoi0(); if ((i = cbits(ch)) != 0 && i != ' ' && i != '\n') { if (c != ch) { while (getach()); errprint("illegal number, char %c", i); return 1; } for (i = 0; i < sizeof name - 2; i++) { if ((c = getach()) == 0) break; name[i] = c; } name[i] = 0; for (i = 0; warnnames[i].s; i++) if (strcmp(name, warnnames[i].s) == 0) { n = warnnames[i].n; break; } if (warnnames[i].s == NULL) { errprint("unknown warning category %s", name); return 1; } } switch (sign) { case 1: warn |= n; break; case -1: warn &= ~n; break; default: warn = n; } return 0; }
tchar eat(tchar c) { register tchar i; while (i = getch(), !issame(i, c) && (cbits(i) != '\n')) ; if (cbits(c) != ' ' && !issame(i, c)) nodelim(c); return(i); }
int chget(int c) { tchar i = 0; charf++; if (skip(0) || ismot(i = getch()) || cbits(i) == ' ' || cbits(i) == '\n') { ch = i; return(c); } else return(cbits(i)); }
void n_setwd(void) { int base, wid; Tchar i; int delim, emsz, k; int savhp, savapts, savapts1, savfont, savfont1, savpts, savpts1; base = numtabp[ST].val = wid = numtabp[CT].val = 0; if (ismot(i = getch())) return; delim = cbits(i); savhp = numtabp[HP].val; numtabp[HP].val = 0; savapts = apts; savapts1 = apts1; savfont = font; savfont1 = font1; savpts = pts; savpts1 = pts1; setwdf++; while (cbits(i = getch()) != delim && !nlflg) { k = width(i); wid += k; numtabp[HP].val += k; if (!ismot(i)) { emsz = (INCH * pts + 36) / 72; } else if (isvmot(i)) { k = absmot(i); if (isnmot(i)) k = -k; base -= k; emsz = 0; } else continue; if (base < numtabp[SB].val) numtabp[SB].val = base; if ((k = base + emsz) > numtabp[ST].val) numtabp[ST].val = k; } setn1(wid, 0, (Tchar) 0); numtabp[HP].val = savhp; apts = savapts; apts1 = savapts1; font = savfont; font1 = savfont1; pts = savpts; pts1 = savpts1; mchbits(); setwdf = 0; }
void copys(void) { Tchar i; copyf++; if (skip()) goto c0; if (cbits(i = getch()) != '"') wbf(i); while (cbits(i = getch()) != '\n') wbf(i); c0: wbf((Tchar)0); copyf--; }
int n_width(Tchar j) { int i, k; if (iszbit(j)) return 0; if (ismot(j)) { if (isvmot(j)) return(0); k = absmot(j); if (isnmot(j)) k = -k; return(k); } i = cbits(j); if (i < ' ') { if (i == '\b') return(-widthp); if (i == PRESC) i = eschar; else if (i == HX) return(0); } if (i == ohc) return(0); i = trtab[i]; if (i < ' ') return(0); k = t.width[i] * t.Char; widthp = k; return(k); }
void caselpfx(void) { int n; tchar c; if (skip(0)) { free(lpfx); lpfx = NULL; nlpfx = 0; } else { for (n = 0; ; n++) { if (n+1 >= nlpfx) { nlpfx += 10; lpfx = realloc(lpfx, nlpfx * sizeof *lpfx); } c = getch(); if (nlflg) break; if (n == 0 && cbits(c) == '"') continue; lpfx[n] = c; } lpfx[n] = 0; } }
Tchar gettch(void) { extern int c_isalnum; Tchar i; int j; if (TROFF) return getch(); i = getch(); j = cbits(i); if (ismot(i) || fbits(i) != ulfont) return(i); if (cu) { if (trtab[j] == ' ') { setcbits(i, '_'); setfbits(i, FT); /* default */ } return(i); } /* should test here for characters that ought to be underlined */ /* in the old nroff, that was the 200 bit on the width! */ /* for now, just do letters, digits and certain special chars */ if (j <= 127) { if (!isalnum(j)) setfbits(i, FT); } else { if (j < c_isalnum) setfbits(i, FT); } return(i); }
void casefc(void) { int i; Tchar j; gchtab[fc] &= ~FCBIT; fc = IMP; padc = ' '; if (skip() || ismot(j = getch()) || (i = cbits(j)) == '\n') return; fc = i; gchtab[fc] |= FCBIT; if (skip() || ismot(ch) || (ch = cbits(ch)) == fc) return; padc = ch; }
casead() { register i; ad = 1; /*leave admod alone*/ if (skip()) return; switch (i = cbits(getch())) { case 'r': /*right adj, left ragged*/ admod = 2; break; case 'l': /*left adj, right ragged*/ admod = ad = 0; /*same as casena*/ break; case 'c': /*centered adj*/ admod = 1; break; case 'b': case 'n': admod = 0; break; case '0': case '2': case '4': ad = 0; case '1': case '3': case '5': admod = (i - '0') / 2; } }
int setov(void) { int j, k; tchar i, o[NOV]; int delim, w[NOV]; if (ismot(i = getch())) return (0); delim = cbits(i); for (k = 0; (k < NOV) && ((j = cbits(i = getch())) != delim) && (j != '\n'); k++) { o[k] = i; w[k] = width(i); } if (k >= NOV) { k = NOV - 1; } o[k] = w[k] = 0; if (o[0]) for (j = 1; j; ) { j = 0; for (k = 1; o[k]; k++) { if (w[k-1] < w[k]) { j++; i = w[k]; w[k] = w[k-1]; w[k-1] = i; i = o[k]; o[k] = o[k-1]; o[k-1] = i; } } } else return (0); *pbp++ = makem(w[0] / 2); for (k = 0; o[k]; k++) ; while (k > 0) { k--; *pbp++ = makem(-((w[k] + w[k+1]) / 2)); *pbp++ = o[k]; } return (0); }
static void chkcoord(uint64_t xy) { unsigned long e = 0; int i, c = 0; int x = KEY2X(xy); int y = KEY2Y(xy); for (i = 0; i < 9; i++) { struct bst_node *n; int xi = x + HOR * (i % 3 - 1); int yi = y + VERT * (i / 3 - 1); if (i != 4) e <<= 4; if (xi >= 0 && yi >= 0 && !bst_srch(&coords, XY2KEY(yi, xi), &n)) { long s = cbits(n->data.l); if (s == BAR ) { if (i == 4) c = 1; else e |= 1; } else if (s == DASH) { if (i == 4) c = 2; else e |= 2; } else { if (i == 4) return; } } } switch (e) { case 0x00002010: drawat(x, y, DOWN_RIGHT); break; case 0x00020010: drawat(x, y, DOWN_LEFT ); break; case 0x00022010: drawat(x, y, DOWN_HOR ); break; case 0x11012220: case 0x22202000: case 0x01002200: case 0x01002220: case 0x01002000: drawat(x, y, UP_RIGHT ); break; case 0x01121222: case 0x01020000: drawat(x, y, UP_LEFT ); break; case 0x11022000: case 0x01122000: case 0x01022000: drawat(x, y, UP_HOR ); break; case 0x00020001: /* empty upper right */ case 0x02220001: case 0x00120001: case 0x01220001: case 0x11220001: case 0x10020001: case 0x10010001: if (c == 2) drawat(x + HOR, y, DOWN_LEFT); break; case 0x01020001: drawat(x , y, UP_HOR ); drawat(x + HOR, y, DOWN_LEFT); break; case 0x00002100: /* empty upper left */ case 0x00102100: case 0x00101100: if (c == 2) drawat(x - HOR, y, DOWN_RIGHT); break; } }
void seta(void) { int i; i = cbits(getch()) - '0'; if (i > 0 && i <= APERMAC && i <= frame->nargs) pushback(*(((Tchar **)(frame + 1)) + i - 1)); }
/* * print error about illegal numeric argument; */ void prnumerr(void) { char err_buf[40]; static char warn[] = "Numeric argument expected"; int savcd = numtabp[CD].val; if (numerr.type == RQERR) sprintf(err_buf, "%c%s: %s", nb ? cbits(c2) : cbits(cc), unpair(numerr.req), warn); else sprintf(err_buf, "\\%c'%s': %s", numerr.esc, &numerr.escarg, warn); if (frame != stk) /* uncertainty correction */ numtabp[CD].val--; ERROR err_buf WARN; numtabp[CD].val = savcd; }
tchar setz(void) { tchar i; if (!ismot(i = getch()) && cbits(i) != ohc) i |= ZBIT; return(i); }
void caseoutput(void) { tchar i; copyf++; if (!skip(0)) { if (cbits(i = getch()) == '"') i = getch(); while (i != 0) { outtp(i); if (cbits(i) == '\n') break; i = getch(); } } copyf--; }
int skip(void) { Tchar i; while (cbits(i = getch()) == ' ' || ismot(i)) ; ch = i; return(nlflg); }
int eat(int c) { int i; while ((i = cbits(getch())) != c && (i != '\n')) ; return (i); }
void storechar(tchar c, int row, int col) { long s = cbits(c); if (s != DASH && s != BAR) return; if (bst_srch(&coords, XY2KEY(row, col), NULL)) if (avl_add(&coords, XY2KEY(row, col), BST_VAL(c))) fprintf(stderr, "BST: Unexpected internal error\n"); }
void caseaf(void) { int i, k; Tchar j; lgf++; if (skip() || !(i = getrq()) || skip()) return; k = 0; j = getch(); if (!isalpha(cbits(j))) { ch = j; while ((j = cbits(getch())) >= '0' && j <= '9') k++; } if (!k) k = j; numtabp[findr(i)].fmt = k; /* was k & BYTEMASK */ }
int setbra(void) { int k; tchar i, *j, dwn; int cnt, delim; tchar brabuf[NC]; if (ismot(i = getch())) return (0); delim = cbits(i); j = brabuf + 1; cnt = 0; #ifdef NROFF dwn = (2 * t.Halfline) | MOT | VMOT; #endif #ifndef NROFF dwn = EM | MOT | VMOT; #endif while (((k = cbits(i = getch())) != delim) && (k != '\n') && (j <= (brabuf + NC - 4))) { *j++ = i | ZBIT; *j++ = dwn; cnt++; } if (--cnt < 0) return (0); else if (!cnt) { ch = *(j - 2); return (0); } *j = 0; #ifdef NROFF *--j = *brabuf = (cnt * t.Halfline) | MOT | NMOT | VMOT; #endif #ifndef NROFF *--j = *brabuf = (cnt * EM) / 2 | MOT | NMOT | VMOT; #endif *--j &= ~ZBIT; pushback(brabuf); return (0); }
void n_casefp(void) { int i, j; skip(); if ((i = cbits(getch()) - '0') < 0 || i > nfonts) return; if (skip() || !(j = getrq())) return; fontlab[i] = j; }
void setxon(void) /* \X'...' for copy through */ { Tchar xbuf[NC]; Tchar *i; Tchar c; int delim, k; if (ismot(c = getch())) return; delim = cbits(c); i = xbuf; *i++ = XON | chbits; while ((k = cbits(c = getch())) != delim && k != '\n' && i < xbuf+NC-1) { if (k == ' ') setcbits(c, WORDSP); *i++ = c | ZBIT; } *i++ = XOFF | chbits; *i = 0; pushback(xbuf); }