4 * misc processing requests
13 int ifnum = 0; /* trying numeric expression for .if or .ie condition */
20 /* leave admod alone */
23 switch (i = cbits(getch())) {
24 case 'r': /* right adj, left ragged */
27 case 'l': /* left adj, right ragged */
28 admod = ad = 0; /* same as casena */
30 case 'c': /*centered adj*/
44 admod = (i - '0') / 2;
86 if (skip() || ismot(i = getch()) || cbits(i) == ' ' || cbits(i) == '\n') {
90 return cbits(i); /* was (i & BYTEMASK) */
177 i = max(hnumb(&in), 0);
198 i = max(hnumb(&ll), INCH / 10);
215 i = max(hnumb(<), 0);
230 i = max(hnumb(&in), 0);
245 i = max(inumb(&ls), 1);
262 i = max(hnumb(&po), 0);
278 if ((i = vnumb(&pl)) == 0)
279 pl = 11 * INCH; /*11in*/
282 if (numtabp[NL].val > pl)
283 numtabp[NL].val = pl;
298 if ((k = findn(i)) != NTRAP) {
302 for (k = 0; k < NTRAP; k++)
307 ERROR "cannot plant trap." WARN;
324 for (k = 0; k < NTRAP; k++)
341 for (k = 0; k < NTRAP; k++)
342 if ((nlist[k] == i) && (mlist[k] != 0))
354 i = max(inumb(&numtabp[PN].val), 0);
372 if ((i = inumb(&numtabp[PN].val)) < 0)
391 static struct fcache {
397 if ( skip() || !getname()) {
398 ERROR "fm: missing filename" WARN;
402 for (i = 0; i < 15 && fcache[i].fp != NULL; i++) {
403 if (strcmp(nextf, fcache[i].name) == 0)
407 ERROR "fm: too many streams" WARN;
410 if (fcache[i].fp == NULL) {
411 if( (fcache[i].fp = fopen(nextf, "w")) == NULL) {
412 ERROR "fm: cannot open %s", nextf WARN;
415 fcache[i].name = strdupl(nextf);
417 casetm1(0, fcache[i].fp);
420 void casetm1(int ab, FILE *out)
430 ERROR "User Abort" WARN;
441 ERROR "User Abort, exit code %d", i WARN;
447 for (i = 0; i < NTM - 2; ) {
448 if ((c = cbits(getch())) == '\n' || c == RIGHT)
450 else if (c == MINUS) { /* special pleading for strange encodings */
453 } else if (c == PRESC) {
456 } else if (c == FILLER) {
459 } else if (c == UNPAD) {
462 } else if (c == OHC) {
465 } else if (c >= ALPHABET) {
469 sprintf(&tmbuf[i], p+1);
472 sprintf(&tmbuf[i], "\\N'%s'", p+1);
475 if ((j = strlen(p+1)) == 2)
476 sprintf(&tmbuf[i], "\\(%s", p+1);
478 sprintf(&tmbuf[i], "\\C'%s'", p+1);
481 sprintf(&tmbuf[i]," %s? ", p);
484 j = strlen(&tmbuf[i]);
490 if (ab) /* truncate output */
491 obufp = obuf; /* should be a function in n2.c */
494 fprintf(out, "%s\n", tmbuf);
511 if (dip->nls || trap)
546 p = &numtabp[NL].val;
550 if ((a < 0) || (a >= *p))
582 nxev = evlist[--evi];
591 if (nxev >= NEV || nxev < 0 || evi >= EVLSZ) {
593 ERROR "cannot do .ev %d", nxev WARN;
608 void envcopy(Env *e1, Env *e2) /* copy env e2 to e1 */
610 *e1 = *e2; /* rumor hath that this fails on some machines */
627 ERROR "if-else overflow." WARN;
654 if ((cbits(i = getch())) == '!') {
671 if (!(numtabp[PN].val & 01))
675 if (numtabp[PN].val & 01)
697 while ((cbits(i = getch())) == ' ')
699 if (cbits(i) == LEFT)
714 void eatblk(int inblk)
730 case '{': i = LEFT; break;
731 case '}': i = RIGHT; break;
732 case '\n': i = 'x'; break;
736 if (i == LEFT) eatblk(1);
737 } while ((!inblk && (i != '\n')) || (inblk && (i != RIGHT)));
751 int savapts, savapts1, savfont, savfont1, savpts, savpts1;
765 while ((j = cbits(i = getch()))!=delim && j!='\n' && sp<&string[1280-1])
767 if (sp >= string + 1280) {
768 ERROR "too-long string compare." WARN;
785 while ((j = cbits(i = getch())) != delim && j != '\n') {
819 fprintf(stderr, "\007"); /*bell*/
822 fprintf(stderr, "%s:", nextf);
824 fprintf(stderr, "\007"); /*bell*/
830 pushi(RD_OFFSET, PAIR('r','d'));
839 if (read(0, &onechar, 1) == 1) {
856 eschar = chget('\\');
870 tabtab[0] = nonumb = 0;
871 for (i = 0; ((i < (NTAB - 1)) && !nonumb); i++) {
874 k = tabtab[max(i-1, 0)] & TABMASK;
875 if ((j = max(hnumb(&k), 0)) > TABMASK) {
876 ERROR "Tab too far away" WARN;
879 tabtab[i] = j & TABMASK;
888 default: /*includes L*/
894 ERROR "Too many tab stops" WARN;
907 if (dip == d && numtabp[NL].val == -1) {
911 if (i > (j = findt1())) {
928 while ((i = cbits(k=getch())) != '\n') {
931 if (ismot(k = getch()))
933 if ((j = cbits(k)) == '\n')
956 if (ul && (i == 0)) {
976 if (skip() || !(i = getrq()) || i == 'S' || (j = findft(i)) == -1)
977 ulfont = ULFONT; /*default underline position*/
980 if (NROFF && ulfont == FT)
995 if (!nonumb && (itmac = getrq()))
1013 i = max(hnumb((int *)0), 0);
1026 j = numtabp[NL].val;
1031 if ((i = getrq()) == 0)
1033 numtabp[findr(i)].val = j;
1042 if ((i = vnumb((int *)0)) < 0)
1055 if (sv <= findt1()) {
1074 i = inumb(&numtabp[LN].val);
1076 numtabp[LN].val = max(i, 0);
1080 getnm(&nmwid, 3); /* really kludgy! */
1086 * .nm relies on the fact that illegal args are skipped; don't warn
1087 * for illegality of these
1089 void getnm(int *p, int min)
1110 nn = max(atoi0(), 1);
1122 /* nroff terminal handling has been pretty well excised */
1123 /* as part of the merge with troff. these are ghostly remnants, */
1124 /* called, but doing nothing. restore them at your peril. */
1127 void save_tty(void) /*save any tty settings that may be changed*/
1132 void restore_tty(void) /*restore tty settings from beginning*/
1142 void echo_off(void) /*turn off ECHO for .rd in "-q" mode*/
1147 void echo_on(void) /*restore ECHO after .rd in "-q" mode*/