6 /* not in ANSI or POSIX */
7 #define isascii(a) ((a) >= 0 && (a) <= 127)
32 if (dip == d && numtabp[NL].val == -1) {
43 } else if (pendw && !brflg) {
47 *linep = dip->nls = 0;
48 if (NROFF && dip == d)
56 if ((lastl = ll - un) < ne)
59 if (admod && ad && (brflg != 2)) {
63 un += quant(nel / 2, HOR);
69 if (lastl + un > dip->maxl)
70 dip->maxl = lastl + un;
80 lastl = ne + (nwd-1) * adsp + adrem;
81 for (i = line; nc > 0; ) {
82 if ((cbits(j = *i++)) == ' ') {
87 } while ((cbits(j = *i++)) == ' ');
95 } else if ((totout & 01) || adrem / resol >= nwd) {
100 pchar((Tchar) WORDSP);
108 if ((k = ll - un0 - lastl + ics) > 0)
121 if (dip->dnl > dip->hnl)
124 if (numtabp[NL].val > dip->hnl)
125 dip->hnl = numtabp[NL].val;
127 for (k = ls - 1; k > 0 && !trap; k--)
135 int lnv = numtabp[LN].val;
138 nw = width('1' | nrbits);
146 un += nw * (nmwid + nms + ni);
150 do { /* count digits in numtabp[LN].val */
152 } while ((lnv /= 10) > 0);
153 horiz(nw * (ni + max(nmwid-i, 0)));
155 fnumb(numtabp[LN].val, pchar);
168 if ((dip == d) && (numtabp[NL].val == -1)) {
187 while ((cbits(i = GETCH())) == ' ') {
189 numtabp[HP].val += sps;
194 nflush = pendt = ch = spcnt = 0;
229 adsp = nel / (nwd - 1);
230 adsp = (adsp / HOR) * HOR;
231 adrem = nel - adsp*(nwd-1);
266 while ((j = (cbits(i = GETCH()))) != '\n') {
278 numtabp[HP].val += j;
283 if ((i = quant(nel / 2, HOR)) > 0)
287 storeline((Tchar)FILLER, 0);
311 if (ul && (--ul == 0)) {
316 if (it && --it == 0 && itmac)
321 void storeline(Tchar c, int w)
325 if (linep >= line + lnsize - 2) {
328 if (( line = (Tchar *)realloc((char *)line, lnsize * sizeof(Tchar))) != NULL) {
336 ERROR "Line overflow." WARN;
369 dip->blss = flss = 0;
372 pchar1((Tchar)dip->alss);
374 dip->dnl += dip->alss;
377 if (dip->ditrap && !dip->ditf && dip->dnl >= dip->ditrap && dip->dimac)
378 if (control(dip->dimac, 0)) {
387 nlss = dip->alss + dip->blss + lss;
388 numtabp[NL].val += nlss;
389 if (TROFF && ascii) {
390 dip->alss = dip->blss = 0;
395 if (numtabp[NL].val < pl)
398 ejf = dip->hnl = numtabp[NL].val = 0;
401 if ((!nc && !wch) || ndone)
408 opn = numtabp[PN].val;
411 numtabp[PN].val = npn;
415 if (numtabp[PN].val == pfrom) {
418 } else if (opn == pto) {
425 ptpage(numtabp[PN].val); /* supposedly in a clean state so can pause */
435 if (numtabp[NL].val == 0) {
436 if ((j = findn(0)) != NTRAP)
437 trap = control(mlist[j], 0);
438 } else if ((i = findt(numtabp[NL].val - nlss)) <= nlss) {
439 if ((j = findn1(numtabp[NL].val - nlss + i)) == NTRAP) {
441 ERROR "Trap botch." WARN;
444 trap = control(mlist[j], 0);
453 for (i = 0; i < NTRAP; i++) {
455 if ((j = nlist[i]) < 0)
468 pfrom = pto>=0 ? pto : -pto;
469 if (pto == -INT_MAX) {
487 if (dip->dimac && (i = dip->ditrap - a) > 0)
491 for (i = 0; i < NTRAP; i++) {
493 if ((j = nlist[i]) < 0)
535 lss = findt(numtabp[NL].val);
538 if (numtabp[NL].val && !trap)
552 while (cbits(*wp++) == ' ') {
558 if (wne > nel && !hyoff && hyf && (!nwd || nel > 3 * sps) &&
559 (!(hyf & 02) || (findt1() > lss)))
564 while (*hyp && *hyp <= wp)
567 if (hyoff != 1 && *hyp == wp) {
569 if (!wdstart || (wp > wdstart + 1 && wp < wdend &&
570 (!(hyf & 04) || wp < wdend - 1) && /* 04 => last 2 */
571 (!(hyf & 010) || wp > wdstart + 2))) { /* 010 => 1st 2 */
573 storeline((Tchar)IMP, 0);
584 return(0); /* line didn't fill up */
587 xbits((Tchar)HYPHEN, 1);
588 hys = width((Tchar)HYPHEN);
606 if ((i = cbits(*(linep - 1))) != '-' && i != EMDASH) {
607 *linep = (*(linep - 1) & SFMASK) | HYPHEN;
617 return(1); /* line filled up */
647 ne = adsp = adrem = 0;
669 over = wne = wch = 0;
672 while (1) { /* picks up 1st char of word */
673 j = cbits(i = GETCH());
680 hyoff = 1; /* 1 => don't hyphenate */
684 numtabp[HP].val += sps;
691 storeword(' ' | obits, sps);
693 storeword(' ' | obits, sps);
707 if (hyp > hyptr + NHYP - 1)
708 hyp = hyptr + NHYP - 1;
711 if (((j == '-' || j == EMDASH)) && !(i & ZBIT)) /* zbit avoids \X */
712 if (wordp > word + 1) {
715 if (hyp > hyptr + NHYP - 1)
716 hyp = hyptr + NHYP - 1;
720 numtabp[HP].val += j;
723 j = cbits(i = GETCH());
725 static char *sentchar = ".?!"; /* sentence terminators */
728 wp = wordp-1; /* handle extra space at end of sentence */
731 if (j=='"' || j=='\'' || j==')' || j==']' || j=='*' || j==DAGGER)
733 for (k = 0; sentchar[k]; k++)
734 if (j == sentchar[k]) {
742 numtabp[HP].val += sps;
744 for (wp = word; *wp; wp++) {
746 break; /* drechsler */
750 if (!(isascii(j) && isdigit(j)) && j != '-')
753 if (*wp == 0) /* all numbers, so don't hyphenate */
764 void storeword(Tchar c, int w)
769 if (wordp >= word + wdsize - 2) {
772 if (( word = (Tchar *)realloc((char *)word, wdsize * sizeof(Tchar))) != NULL) {
774 wordp = word + (wordp - savp);
776 pendw = word + (pendw - savp);
778 wdstart = word + (wdstart - savp);
780 wdend = word + (wdend - savp);
781 for (i = 0; i < NHYP; i++)
783 hyptr[i] = word + (hyptr[i] - savp);
789 ERROR "Word overflow." WARN;
805 extern int c_isalnum;
814 if (ismot(i) || fbits(i) != ulfont)
817 if (trtab[j] == ' ') {
819 setfbits(i, FT); /* default */
823 /* should test here for characters that ought to be underlined */
824 /* in the old nroff, that was the 200 bit on the width! */
825 /* for now, just do letters, digits and certain special chars */