17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
327c478bd9Sstevel@tonic-gate * The Regents of the University of California
337c478bd9Sstevel@tonic-gate * All Rights Reserved
347c478bd9Sstevel@tonic-gate *
357c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
367c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
377c478bd9Sstevel@tonic-gate * contributors.
387c478bd9Sstevel@tonic-gate */
397c478bd9Sstevel@tonic-gate
40*e5190c10Smuffin #pragma ident "%Z%%M% %I% %E% SMI"
41*e5190c10Smuffin
427c478bd9Sstevel@tonic-gate #ifdef EUC
437c478bd9Sstevel@tonic-gate #ifdef NROFF
447c478bd9Sstevel@tonic-gate #include <stdlib.h>
457c478bd9Sstevel@tonic-gate #include <widec.h>
467c478bd9Sstevel@tonic-gate #include <limits.h>
477c478bd9Sstevel@tonic-gate #endif /* NROFF */
487c478bd9Sstevel@tonic-gate #endif /* EUC */
497c478bd9Sstevel@tonic-gate #include "tdef.h"
507c478bd9Sstevel@tonic-gate #ifdef NROFF
517c478bd9Sstevel@tonic-gate #include "tw.h"
527c478bd9Sstevel@tonic-gate #endif
537c478bd9Sstevel@tonic-gate #ifdef NROFF
547c478bd9Sstevel@tonic-gate #define GETCH gettch
557c478bd9Sstevel@tonic-gate tchar gettch();
567c478bd9Sstevel@tonic-gate #endif
577c478bd9Sstevel@tonic-gate #ifndef NROFF
587c478bd9Sstevel@tonic-gate #define GETCH getch
597c478bd9Sstevel@tonic-gate #endif
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate /*
627c478bd9Sstevel@tonic-gate * troff7.c
637c478bd9Sstevel@tonic-gate *
647c478bd9Sstevel@tonic-gate * text
657c478bd9Sstevel@tonic-gate */
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate #include <ctype.h>
687c478bd9Sstevel@tonic-gate #ifdef EUC
697c478bd9Sstevel@tonic-gate #ifdef NROFF
707c478bd9Sstevel@tonic-gate #include <wctype.h>
717c478bd9Sstevel@tonic-gate #endif /* NROFF */
727c478bd9Sstevel@tonic-gate #endif /* EUC */
737c478bd9Sstevel@tonic-gate #include "ext.h"
747c478bd9Sstevel@tonic-gate #ifdef EUC
757c478bd9Sstevel@tonic-gate #ifdef NROFF
767c478bd9Sstevel@tonic-gate char mbbuf2[MB_LEN_MAX + 1];
777c478bd9Sstevel@tonic-gate char *mbbuf2p = mbbuf2;
787c478bd9Sstevel@tonic-gate tchar mtbuf[MB_LEN_MAX + 1];
797c478bd9Sstevel@tonic-gate tchar *mtbufp;
807c478bd9Sstevel@tonic-gate int pendmb = 0;
817c478bd9Sstevel@tonic-gate wchar_t cwc, owc, wceoll;
827c478bd9Sstevel@tonic-gate #endif /* NROFF */
837c478bd9Sstevel@tonic-gate #endif /* EUC */
847c478bd9Sstevel@tonic-gate int brflg;
857c478bd9Sstevel@tonic-gate
86*e5190c10Smuffin int
tbreak()877c478bd9Sstevel@tonic-gate tbreak()
887c478bd9Sstevel@tonic-gate {
89*e5190c10Smuffin int pad, k;
90*e5190c10Smuffin tchar *i, j;
91*e5190c10Smuffin int resol = 0;
927c478bd9Sstevel@tonic-gate #ifdef EUC
937c478bd9Sstevel@tonic-gate #ifdef NROFF
94*e5190c10Smuffin tchar l;
957c478bd9Sstevel@tonic-gate #endif /* NROFF */
967c478bd9Sstevel@tonic-gate #endif /* EUC */
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate trap = 0;
997c478bd9Sstevel@tonic-gate if (nb)
100*e5190c10Smuffin return (0);
1017c478bd9Sstevel@tonic-gate if (dip == d && numtab[NL].val == -1) {
1027c478bd9Sstevel@tonic-gate newline(1);
103*e5190c10Smuffin return (0);
1047c478bd9Sstevel@tonic-gate }
1057c478bd9Sstevel@tonic-gate if (!nc) {
1067c478bd9Sstevel@tonic-gate setnel();
1077c478bd9Sstevel@tonic-gate if (!wch)
108*e5190c10Smuffin return (0);
1097c478bd9Sstevel@tonic-gate if (pendw)
1107c478bd9Sstevel@tonic-gate getword(1);
1117c478bd9Sstevel@tonic-gate movword();
1127c478bd9Sstevel@tonic-gate } else if (pendw && !brflg) {
1137c478bd9Sstevel@tonic-gate getword(1);
1147c478bd9Sstevel@tonic-gate movword();
1157c478bd9Sstevel@tonic-gate }
1167c478bd9Sstevel@tonic-gate *linep = dip->nls = 0;
1177c478bd9Sstevel@tonic-gate #ifdef NROFF
1187c478bd9Sstevel@tonic-gate if (dip == d)
1197c478bd9Sstevel@tonic-gate horiz(po);
1207c478bd9Sstevel@tonic-gate #endif
1217c478bd9Sstevel@tonic-gate if (lnmod)
1227c478bd9Sstevel@tonic-gate donum();
1237c478bd9Sstevel@tonic-gate lastl = ne;
1247c478bd9Sstevel@tonic-gate if (brflg != 1) {
1257c478bd9Sstevel@tonic-gate totout = 0;
1267c478bd9Sstevel@tonic-gate } else if (ad) {
1277c478bd9Sstevel@tonic-gate if ((lastl = ll - un) < ne)
1287c478bd9Sstevel@tonic-gate lastl = ne;
1297c478bd9Sstevel@tonic-gate }
1307c478bd9Sstevel@tonic-gate if (admod && ad && (brflg != 2)) {
1317c478bd9Sstevel@tonic-gate lastl = ne;
1327c478bd9Sstevel@tonic-gate adsp = adrem = 0;
1337c478bd9Sstevel@tonic-gate if (admod == 1)
1347c478bd9Sstevel@tonic-gate un += quant(nel / 2, HOR);
1357c478bd9Sstevel@tonic-gate else if (admod == 2)
1367c478bd9Sstevel@tonic-gate un += nel;
1377c478bd9Sstevel@tonic-gate }
1387c478bd9Sstevel@tonic-gate totout++;
1397c478bd9Sstevel@tonic-gate brflg = 0;
1407c478bd9Sstevel@tonic-gate if (lastl + un > dip->maxl)
1417c478bd9Sstevel@tonic-gate dip->maxl = lastl + un;
1427c478bd9Sstevel@tonic-gate horiz(un);
1437c478bd9Sstevel@tonic-gate #ifdef NROFF
1447c478bd9Sstevel@tonic-gate if (adrem % t.Adj)
1457c478bd9Sstevel@tonic-gate resol = t.Hor;
1467c478bd9Sstevel@tonic-gate else
1477c478bd9Sstevel@tonic-gate resol = t.Adj;
1487c478bd9Sstevel@tonic-gate #else
1497c478bd9Sstevel@tonic-gate resol = HOR;
1507c478bd9Sstevel@tonic-gate #endif
1517c478bd9Sstevel@tonic-gate adrem = (adrem / resol) * resol;
1527c478bd9Sstevel@tonic-gate for (i = line; nc > 0; ) {
1537c478bd9Sstevel@tonic-gate #ifndef EUC
1547c478bd9Sstevel@tonic-gate if ((cbits(j = *i++)) == ' ') {
1557c478bd9Sstevel@tonic-gate #else
1567c478bd9Sstevel@tonic-gate #ifndef NROFF
1577c478bd9Sstevel@tonic-gate if ((cbits(j = *i++)) == ' ') {
1587c478bd9Sstevel@tonic-gate #else
1597c478bd9Sstevel@tonic-gate if ((cbits(j = *i++) & ~MBMASK) == ' ') {
1607c478bd9Sstevel@tonic-gate #endif /* NROFF */
1617c478bd9Sstevel@tonic-gate #endif /* EUC */
1627c478bd9Sstevel@tonic-gate pad = 0;
1637c478bd9Sstevel@tonic-gate do {
1647c478bd9Sstevel@tonic-gate pad += width(j);
1657c478bd9Sstevel@tonic-gate nc--;
1667c478bd9Sstevel@tonic-gate #ifndef EUC
1677c478bd9Sstevel@tonic-gate } while ((cbits(j = *i++)) == ' ');
1687c478bd9Sstevel@tonic-gate #else
1697c478bd9Sstevel@tonic-gate #ifndef NROFF
1707c478bd9Sstevel@tonic-gate } while ((cbits(j = *i++)) == ' ');
1717c478bd9Sstevel@tonic-gate #else
1727c478bd9Sstevel@tonic-gate } while ((cbits(j = *i++) & ~MBMASK) == ' ');
1737c478bd9Sstevel@tonic-gate #endif /* NROFF */
1747c478bd9Sstevel@tonic-gate #endif /* EUC */
1757c478bd9Sstevel@tonic-gate i--;
1767c478bd9Sstevel@tonic-gate pad += adsp;
1777c478bd9Sstevel@tonic-gate --nwd;
1787c478bd9Sstevel@tonic-gate if (adrem) {
1797c478bd9Sstevel@tonic-gate if (adrem < 0) {
1807c478bd9Sstevel@tonic-gate pad -= resol;
1817c478bd9Sstevel@tonic-gate adrem += resol;
1827c478bd9Sstevel@tonic-gate } else if ((totout & 01) || adrem / resol >= nwd) {
1837c478bd9Sstevel@tonic-gate pad += resol;
1847c478bd9Sstevel@tonic-gate adrem -= resol;
1857c478bd9Sstevel@tonic-gate }
1867c478bd9Sstevel@tonic-gate }
1877c478bd9Sstevel@tonic-gate pchar((tchar) WORDSP);
1887c478bd9Sstevel@tonic-gate horiz(pad);
1897c478bd9Sstevel@tonic-gate } else {
1907c478bd9Sstevel@tonic-gate pchar(j);
1917c478bd9Sstevel@tonic-gate nc--;
1927c478bd9Sstevel@tonic-gate }
1937c478bd9Sstevel@tonic-gate }
1947c478bd9Sstevel@tonic-gate if (ic) {
1957c478bd9Sstevel@tonic-gate if ((k = ll - un - lastl + ics) > 0)
1967c478bd9Sstevel@tonic-gate horiz(k);
1977c478bd9Sstevel@tonic-gate pchar(ic);
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate if (icf)
2007c478bd9Sstevel@tonic-gate icf++;
2017c478bd9Sstevel@tonic-gate else
2027c478bd9Sstevel@tonic-gate ic = 0;
2037c478bd9Sstevel@tonic-gate ne = nwd = 0;
2047c478bd9Sstevel@tonic-gate un = in;
2057c478bd9Sstevel@tonic-gate setnel();
2067c478bd9Sstevel@tonic-gate newline(0);
2077c478bd9Sstevel@tonic-gate if (dip != d) {
2087c478bd9Sstevel@tonic-gate if (dip->dnl > dip->hnl)
2097c478bd9Sstevel@tonic-gate dip->hnl = dip->dnl;
2107c478bd9Sstevel@tonic-gate } else {
2117c478bd9Sstevel@tonic-gate if (numtab[NL].val > dip->hnl)
2127c478bd9Sstevel@tonic-gate dip->hnl = numtab[NL].val;
2137c478bd9Sstevel@tonic-gate }
2147c478bd9Sstevel@tonic-gate for (k = ls - 1; k > 0 && !trap; k--)
2157c478bd9Sstevel@tonic-gate newline(0);
2167c478bd9Sstevel@tonic-gate spread = 0;
217*e5190c10Smuffin
218*e5190c10Smuffin return (0);
2197c478bd9Sstevel@tonic-gate }
2207c478bd9Sstevel@tonic-gate
221*e5190c10Smuffin int
donum()2227c478bd9Sstevel@tonic-gate donum()
2237c478bd9Sstevel@tonic-gate {
224*e5190c10Smuffin int i, nw;
225*e5190c10Smuffin extern int pchar();
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate nrbits = nmbits;
2287c478bd9Sstevel@tonic-gate nw = width('1' | nrbits);
2297c478bd9Sstevel@tonic-gate if (nn) {
2307c478bd9Sstevel@tonic-gate nn--;
2317c478bd9Sstevel@tonic-gate goto d1;
2327c478bd9Sstevel@tonic-gate }
2337c478bd9Sstevel@tonic-gate if (numtab[LN].val % ndf) {
2347c478bd9Sstevel@tonic-gate numtab[LN].val++;
2357c478bd9Sstevel@tonic-gate d1:
2367c478bd9Sstevel@tonic-gate un += nw * (3 + nms + ni);
237*e5190c10Smuffin return (0);
2387c478bd9Sstevel@tonic-gate }
2397c478bd9Sstevel@tonic-gate i = 0;
2407c478bd9Sstevel@tonic-gate if (numtab[LN].val < 100)
2417c478bd9Sstevel@tonic-gate i++;
2427c478bd9Sstevel@tonic-gate if (numtab[LN].val < 10)
2437c478bd9Sstevel@tonic-gate i++;
2447c478bd9Sstevel@tonic-gate horiz(nw * (ni + i));
2457c478bd9Sstevel@tonic-gate nform = 0;
2467c478bd9Sstevel@tonic-gate fnumb(numtab[LN].val, pchar);
2477c478bd9Sstevel@tonic-gate un += nw * nms;
2487c478bd9Sstevel@tonic-gate numtab[LN].val++;
249*e5190c10Smuffin
250*e5190c10Smuffin return (0);
2517c478bd9Sstevel@tonic-gate }
2527c478bd9Sstevel@tonic-gate
2537c478bd9Sstevel@tonic-gate extern int logf;
254*e5190c10Smuffin
255*e5190c10Smuffin int
text()2567c478bd9Sstevel@tonic-gate text()
2577c478bd9Sstevel@tonic-gate {
258*e5190c10Smuffin tchar i;
2597c478bd9Sstevel@tonic-gate static int spcnt;
2607c478bd9Sstevel@tonic-gate
2617c478bd9Sstevel@tonic-gate nflush++;
2627c478bd9Sstevel@tonic-gate numtab[HP].val = 0;
2637c478bd9Sstevel@tonic-gate if ((dip == d) && (numtab[NL].val == -1)) {
2647c478bd9Sstevel@tonic-gate newline(1);
265*e5190c10Smuffin return (0);
2667c478bd9Sstevel@tonic-gate }
2677c478bd9Sstevel@tonic-gate setnel();
2687c478bd9Sstevel@tonic-gate if (ce || !fi) {
2697c478bd9Sstevel@tonic-gate nofill();
270*e5190c10Smuffin return (0);
2717c478bd9Sstevel@tonic-gate }
2727c478bd9Sstevel@tonic-gate if (pendw)
2737c478bd9Sstevel@tonic-gate goto t4;
2747c478bd9Sstevel@tonic-gate if (pendt)
2757c478bd9Sstevel@tonic-gate if (spcnt)
2767c478bd9Sstevel@tonic-gate goto t2;
2777c478bd9Sstevel@tonic-gate else
2787c478bd9Sstevel@tonic-gate goto t3;
2797c478bd9Sstevel@tonic-gate pendt++;
2807c478bd9Sstevel@tonic-gate if (spcnt)
2817c478bd9Sstevel@tonic-gate goto t2;
2827c478bd9Sstevel@tonic-gate while ((cbits(i = GETCH())) == ' ') {
2837c478bd9Sstevel@tonic-gate spcnt++;
2847c478bd9Sstevel@tonic-gate numtab[HP].val += sps;
2857c478bd9Sstevel@tonic-gate widthp = sps;
2867c478bd9Sstevel@tonic-gate }
2877c478bd9Sstevel@tonic-gate if (nlflg) {
2887c478bd9Sstevel@tonic-gate t1:
2897c478bd9Sstevel@tonic-gate nflush = pendt = ch = spcnt = 0;
2907c478bd9Sstevel@tonic-gate callsp();
291*e5190c10Smuffin return (0);
2927c478bd9Sstevel@tonic-gate }
2937c478bd9Sstevel@tonic-gate ch = i;
2947c478bd9Sstevel@tonic-gate if (spcnt) {
2957c478bd9Sstevel@tonic-gate t2:
2967c478bd9Sstevel@tonic-gate tbreak();
2977c478bd9Sstevel@tonic-gate if (nc || wch)
2987c478bd9Sstevel@tonic-gate goto rtn;
2997c478bd9Sstevel@tonic-gate un += spcnt * sps;
3007c478bd9Sstevel@tonic-gate spcnt = 0;
3017c478bd9Sstevel@tonic-gate setnel();
3027c478bd9Sstevel@tonic-gate if (trap)
3037c478bd9Sstevel@tonic-gate goto rtn;
3047c478bd9Sstevel@tonic-gate if (nlflg)
3057c478bd9Sstevel@tonic-gate goto t1;
3067c478bd9Sstevel@tonic-gate }
3077c478bd9Sstevel@tonic-gate t3:
3087c478bd9Sstevel@tonic-gate if (spread)
3097c478bd9Sstevel@tonic-gate goto t5;
3107c478bd9Sstevel@tonic-gate if (pendw || !wch)
3117c478bd9Sstevel@tonic-gate t4:
3127c478bd9Sstevel@tonic-gate if (getword(0))
3137c478bd9Sstevel@tonic-gate goto t6;
3147c478bd9Sstevel@tonic-gate if (!movword())
3157c478bd9Sstevel@tonic-gate goto t3;
3167c478bd9Sstevel@tonic-gate t5:
3177c478bd9Sstevel@tonic-gate if (nlflg)
3187c478bd9Sstevel@tonic-gate pendt = 0;
3197c478bd9Sstevel@tonic-gate adsp = adrem = 0;
3207c478bd9Sstevel@tonic-gate if (ad) {
3217c478bd9Sstevel@tonic-gate if (nwd == 1)
3227c478bd9Sstevel@tonic-gate adsp = nel;
3237c478bd9Sstevel@tonic-gate else
3247c478bd9Sstevel@tonic-gate adsp = nel / (nwd - 1);
3257c478bd9Sstevel@tonic-gate adsp = (adsp / HOR) * HOR;
3267c478bd9Sstevel@tonic-gate adrem = nel - adsp*(nwd-1);
3277c478bd9Sstevel@tonic-gate }
3287c478bd9Sstevel@tonic-gate brflg = 1;
3297c478bd9Sstevel@tonic-gate tbreak();
3307c478bd9Sstevel@tonic-gate spread = 0;
3317c478bd9Sstevel@tonic-gate if (!trap)
3327c478bd9Sstevel@tonic-gate goto t3;
3337c478bd9Sstevel@tonic-gate if (!nlflg)
3347c478bd9Sstevel@tonic-gate goto rtn;
3357c478bd9Sstevel@tonic-gate t6:
3367c478bd9Sstevel@tonic-gate pendt = 0;
3377c478bd9Sstevel@tonic-gate ckul();
3387c478bd9Sstevel@tonic-gate rtn:
3397c478bd9Sstevel@tonic-gate nflush = 0;
340*e5190c10Smuffin
341*e5190c10Smuffin return (0);
3427c478bd9Sstevel@tonic-gate }
3437c478bd9Sstevel@tonic-gate
3447c478bd9Sstevel@tonic-gate
345*e5190c10Smuffin int
nofill()3467c478bd9Sstevel@tonic-gate nofill()
3477c478bd9Sstevel@tonic-gate {
348*e5190c10Smuffin int j;
349*e5190c10Smuffin tchar i;
3507c478bd9Sstevel@tonic-gate
3517c478bd9Sstevel@tonic-gate if (!pendnf) {
3527c478bd9Sstevel@tonic-gate over = 0;
3537c478bd9Sstevel@tonic-gate tbreak();
3547c478bd9Sstevel@tonic-gate if (trap)
3557c478bd9Sstevel@tonic-gate goto rtn;
3567c478bd9Sstevel@tonic-gate if (nlflg) {
3577c478bd9Sstevel@tonic-gate ch = nflush = 0;
3587c478bd9Sstevel@tonic-gate callsp();
359*e5190c10Smuffin return (0);
3607c478bd9Sstevel@tonic-gate }
3617c478bd9Sstevel@tonic-gate adsp = adrem = 0;
3627c478bd9Sstevel@tonic-gate nwd = 10000;
3637c478bd9Sstevel@tonic-gate }
3647c478bd9Sstevel@tonic-gate while ((j = (cbits(i = GETCH()))) != '\n') {
3657c478bd9Sstevel@tonic-gate if (j == ohc)
3667c478bd9Sstevel@tonic-gate continue;
3677c478bd9Sstevel@tonic-gate if (j == CONT) {
3687c478bd9Sstevel@tonic-gate pendnf++;
3697c478bd9Sstevel@tonic-gate nflush = 0;
3707c478bd9Sstevel@tonic-gate flushi();
3717c478bd9Sstevel@tonic-gate ckul();
372*e5190c10Smuffin return (0);
3737c478bd9Sstevel@tonic-gate }
3747c478bd9Sstevel@tonic-gate j = width(i);
3757c478bd9Sstevel@tonic-gate widthp = j;
3767c478bd9Sstevel@tonic-gate numtab[HP].val += j;
3777c478bd9Sstevel@tonic-gate storeline(i, j);
3787c478bd9Sstevel@tonic-gate }
3797c478bd9Sstevel@tonic-gate if (ce) {
3807c478bd9Sstevel@tonic-gate ce--;
3817c478bd9Sstevel@tonic-gate if ((i = quant(nel / 2, HOR)) > 0)
3827c478bd9Sstevel@tonic-gate un += i;
3837c478bd9Sstevel@tonic-gate }
3847c478bd9Sstevel@tonic-gate if (!nc)
3857c478bd9Sstevel@tonic-gate storeline((tchar)FILLER, 0);
3867c478bd9Sstevel@tonic-gate brflg = 2;
3877c478bd9Sstevel@tonic-gate tbreak();
3887c478bd9Sstevel@tonic-gate ckul();
3897c478bd9Sstevel@tonic-gate rtn:
3907c478bd9Sstevel@tonic-gate pendnf = nflush = 0;
391*e5190c10Smuffin
392*e5190c10Smuffin return (0);
3937c478bd9Sstevel@tonic-gate }
3947c478bd9Sstevel@tonic-gate
3957c478bd9Sstevel@tonic-gate
396*e5190c10Smuffin int
callsp()3977c478bd9Sstevel@tonic-gate callsp()
3987c478bd9Sstevel@tonic-gate {
399*e5190c10Smuffin int i;
4007c478bd9Sstevel@tonic-gate
4017c478bd9Sstevel@tonic-gate if (flss)
4027c478bd9Sstevel@tonic-gate i = flss;
4037c478bd9Sstevel@tonic-gate else
4047c478bd9Sstevel@tonic-gate i = lss;
4057c478bd9Sstevel@tonic-gate flss = 0;
4067c478bd9Sstevel@tonic-gate casesp(i);
407*e5190c10Smuffin
408*e5190c10Smuffin return (0);
4097c478bd9Sstevel@tonic-gate }
4107c478bd9Sstevel@tonic-gate
4117c478bd9Sstevel@tonic-gate
412*e5190c10Smuffin int
ckul()4137c478bd9Sstevel@tonic-gate ckul()
4147c478bd9Sstevel@tonic-gate {
4157c478bd9Sstevel@tonic-gate if (ul && (--ul == 0)) {
4167c478bd9Sstevel@tonic-gate cu = 0;
4177c478bd9Sstevel@tonic-gate font = sfont;
4187c478bd9Sstevel@tonic-gate mchbits();
4197c478bd9Sstevel@tonic-gate }
4207c478bd9Sstevel@tonic-gate if (it && (--it == 0) && itmac)
4217c478bd9Sstevel@tonic-gate control(itmac, 0);
422*e5190c10Smuffin
423*e5190c10Smuffin return (0);
4247c478bd9Sstevel@tonic-gate }
4257c478bd9Sstevel@tonic-gate
4267c478bd9Sstevel@tonic-gate
427*e5190c10Smuffin int
storeline(c,w)4287c478bd9Sstevel@tonic-gate storeline(c, w)
429*e5190c10Smuffin tchar c;
4307c478bd9Sstevel@tonic-gate {
4317c478bd9Sstevel@tonic-gate if (linep >= line + lnsize - 1) {
4327c478bd9Sstevel@tonic-gate if (!over) {
4337c478bd9Sstevel@tonic-gate flusho();
4347c478bd9Sstevel@tonic-gate errprint(gettext("Line overflow."));
4357c478bd9Sstevel@tonic-gate over++;
4367c478bd9Sstevel@tonic-gate c = LEFTHAND;
4377c478bd9Sstevel@tonic-gate w = -1;
4387c478bd9Sstevel@tonic-gate goto s1;
4397c478bd9Sstevel@tonic-gate }
440*e5190c10Smuffin return (0);
4417c478bd9Sstevel@tonic-gate }
4427c478bd9Sstevel@tonic-gate s1:
4437c478bd9Sstevel@tonic-gate if (w == -1)
4447c478bd9Sstevel@tonic-gate w = width(c);
4457c478bd9Sstevel@tonic-gate ne += w;
4467c478bd9Sstevel@tonic-gate nel -= w;
4477c478bd9Sstevel@tonic-gate *linep++ = c;
4487c478bd9Sstevel@tonic-gate nc++;
449*e5190c10Smuffin
450*e5190c10Smuffin return (0);
4517c478bd9Sstevel@tonic-gate }
4527c478bd9Sstevel@tonic-gate
4537c478bd9Sstevel@tonic-gate
454*e5190c10Smuffin int
newline(a)4557c478bd9Sstevel@tonic-gate newline(a)
4567c478bd9Sstevel@tonic-gate int a;
4577c478bd9Sstevel@tonic-gate {
458*e5190c10Smuffin int i, j, nlss;
4597c478bd9Sstevel@tonic-gate int opn;
4607c478bd9Sstevel@tonic-gate
4617c478bd9Sstevel@tonic-gate if (a)
4627c478bd9Sstevel@tonic-gate goto nl1;
4637c478bd9Sstevel@tonic-gate if (dip != d) {
4647c478bd9Sstevel@tonic-gate j = lss;
4657c478bd9Sstevel@tonic-gate pchar1((tchar)FLSS);
4667c478bd9Sstevel@tonic-gate if (flss)
4677c478bd9Sstevel@tonic-gate lss = flss;
4687c478bd9Sstevel@tonic-gate i = lss + dip->blss;
4697c478bd9Sstevel@tonic-gate dip->dnl += i;
4707c478bd9Sstevel@tonic-gate pchar1((tchar)i);
4717c478bd9Sstevel@tonic-gate pchar1((tchar)'\n');
4727c478bd9Sstevel@tonic-gate lss = j;
4737c478bd9Sstevel@tonic-gate dip->blss = flss = 0;
4747c478bd9Sstevel@tonic-gate if (dip->alss) {
4757c478bd9Sstevel@tonic-gate pchar1((tchar)FLSS);
4767c478bd9Sstevel@tonic-gate pchar1((tchar)dip->alss);
4777c478bd9Sstevel@tonic-gate pchar1((tchar)'\n');
4787c478bd9Sstevel@tonic-gate dip->dnl += dip->alss;
4797c478bd9Sstevel@tonic-gate dip->alss = 0;
4807c478bd9Sstevel@tonic-gate }
4817c478bd9Sstevel@tonic-gate if (dip->ditrap && !dip->ditf && dip->dnl >= dip->ditrap && dip->dimac)
4827c478bd9Sstevel@tonic-gate if (control(dip->dimac, 0)) {
4837c478bd9Sstevel@tonic-gate trap++;
4847c478bd9Sstevel@tonic-gate dip->ditf++;
4857c478bd9Sstevel@tonic-gate }
486*e5190c10Smuffin return (0);
4877c478bd9Sstevel@tonic-gate }
4887c478bd9Sstevel@tonic-gate j = lss;
4897c478bd9Sstevel@tonic-gate if (flss)
4907c478bd9Sstevel@tonic-gate lss = flss;
4917c478bd9Sstevel@tonic-gate nlss = dip->alss + dip->blss + lss;
4927c478bd9Sstevel@tonic-gate numtab[NL].val += nlss;
4937c478bd9Sstevel@tonic-gate #ifndef NROFF
4947c478bd9Sstevel@tonic-gate if (ascii) {
4957c478bd9Sstevel@tonic-gate dip->alss = dip->blss = 0;
4967c478bd9Sstevel@tonic-gate }
4977c478bd9Sstevel@tonic-gate #endif
4987c478bd9Sstevel@tonic-gate pchar1((tchar)'\n');
4997c478bd9Sstevel@tonic-gate flss = 0;
5007c478bd9Sstevel@tonic-gate lss = j;
5017c478bd9Sstevel@tonic-gate if (numtab[NL].val < pl)
5027c478bd9Sstevel@tonic-gate goto nl2;
5037c478bd9Sstevel@tonic-gate nl1:
5047c478bd9Sstevel@tonic-gate ejf = dip->hnl = numtab[NL].val = 0;
5057c478bd9Sstevel@tonic-gate ejl = frame;
5067c478bd9Sstevel@tonic-gate if (donef) {
5077c478bd9Sstevel@tonic-gate if ((!nc && !wch) || ndone)
5087c478bd9Sstevel@tonic-gate done1(0);
5097c478bd9Sstevel@tonic-gate ndone++;
5107c478bd9Sstevel@tonic-gate donef = 0;
5117c478bd9Sstevel@tonic-gate if (frame == stk)
5127c478bd9Sstevel@tonic-gate nflush++;
5137c478bd9Sstevel@tonic-gate }
5147c478bd9Sstevel@tonic-gate opn = numtab[PN].val;
5157c478bd9Sstevel@tonic-gate numtab[PN].val++;
5167c478bd9Sstevel@tonic-gate if (npnflg) {
5177c478bd9Sstevel@tonic-gate numtab[PN].val = npn;
5187c478bd9Sstevel@tonic-gate npn = npnflg = 0;
5197c478bd9Sstevel@tonic-gate }
5207c478bd9Sstevel@tonic-gate nlpn:
5217c478bd9Sstevel@tonic-gate if (numtab[PN].val == pfrom) {
5227c478bd9Sstevel@tonic-gate print++;
5237c478bd9Sstevel@tonic-gate pfrom = -1;
5247c478bd9Sstevel@tonic-gate } else if (opn == pto) {
5257c478bd9Sstevel@tonic-gate print = 0;
5267c478bd9Sstevel@tonic-gate opn = -1;
5277c478bd9Sstevel@tonic-gate chkpn();
5287c478bd9Sstevel@tonic-gate goto nlpn;
5297c478bd9Sstevel@tonic-gate }
5307c478bd9Sstevel@tonic-gate if (print)
5317c478bd9Sstevel@tonic-gate newpage(numtab[PN].val); /* supposedly in a clean state so can pause */
5327c478bd9Sstevel@tonic-gate if (stop && print) {
5337c478bd9Sstevel@tonic-gate dpn++;
5347c478bd9Sstevel@tonic-gate if (dpn >= stop) {
5357c478bd9Sstevel@tonic-gate dpn = 0;
5367c478bd9Sstevel@tonic-gate dostop();
5377c478bd9Sstevel@tonic-gate }
5387c478bd9Sstevel@tonic-gate }
5397c478bd9Sstevel@tonic-gate nl2:
5407c478bd9Sstevel@tonic-gate trap = 0;
5417c478bd9Sstevel@tonic-gate if (numtab[NL].val == 0) {
5427c478bd9Sstevel@tonic-gate if ((j = findn(0)) != NTRAP)
5437c478bd9Sstevel@tonic-gate trap = control(mlist[j], 0);
5447c478bd9Sstevel@tonic-gate } else if ((i = findt(numtab[NL].val - nlss)) <= nlss) {
5457c478bd9Sstevel@tonic-gate if ((j = findn1(numtab[NL].val - nlss + i)) == NTRAP) {
5467c478bd9Sstevel@tonic-gate flusho();
5477c478bd9Sstevel@tonic-gate errprint(gettext("Trap botch."));
5487c478bd9Sstevel@tonic-gate done2(-5);
5497c478bd9Sstevel@tonic-gate }
5507c478bd9Sstevel@tonic-gate trap = control(mlist[j], 0);
5517c478bd9Sstevel@tonic-gate }
552*e5190c10Smuffin
553*e5190c10Smuffin return (0);
5547c478bd9Sstevel@tonic-gate }
5557c478bd9Sstevel@tonic-gate
5567c478bd9Sstevel@tonic-gate
557*e5190c10Smuffin int
findn1(a)5587c478bd9Sstevel@tonic-gate findn1(a)
5597c478bd9Sstevel@tonic-gate int a;
5607c478bd9Sstevel@tonic-gate {
561*e5190c10Smuffin int i, j;
5627c478bd9Sstevel@tonic-gate
5637c478bd9Sstevel@tonic-gate for (i = 0; i < NTRAP; i++) {
5647c478bd9Sstevel@tonic-gate if (mlist[i]) {
5657c478bd9Sstevel@tonic-gate if ((j = nlist[i]) < 0)
5667c478bd9Sstevel@tonic-gate j += pl;
5677c478bd9Sstevel@tonic-gate if (j == a)
5687c478bd9Sstevel@tonic-gate break;
5697c478bd9Sstevel@tonic-gate }
5707c478bd9Sstevel@tonic-gate }
5717c478bd9Sstevel@tonic-gate return(i);
5727c478bd9Sstevel@tonic-gate }
5737c478bd9Sstevel@tonic-gate
574*e5190c10Smuffin int
chkpn()5757c478bd9Sstevel@tonic-gate chkpn()
5767c478bd9Sstevel@tonic-gate {
5777c478bd9Sstevel@tonic-gate pto = *(pnp++);
5787c478bd9Sstevel@tonic-gate pfrom = pto>=0 ? pto : -pto;
5797c478bd9Sstevel@tonic-gate if (pto == -32767) {
5807c478bd9Sstevel@tonic-gate flusho();
5817c478bd9Sstevel@tonic-gate done1(0);
5827c478bd9Sstevel@tonic-gate }
5837c478bd9Sstevel@tonic-gate if (pto < 0) {
5847c478bd9Sstevel@tonic-gate pto = -pto;
5857c478bd9Sstevel@tonic-gate print++;
5867c478bd9Sstevel@tonic-gate pfrom = 0;
5877c478bd9Sstevel@tonic-gate }
588*e5190c10Smuffin
589*e5190c10Smuffin return (0);
5907c478bd9Sstevel@tonic-gate }
5917c478bd9Sstevel@tonic-gate
5927c478bd9Sstevel@tonic-gate
593*e5190c10Smuffin int
findt(a)5947c478bd9Sstevel@tonic-gate findt(a)
5957c478bd9Sstevel@tonic-gate int a;
5967c478bd9Sstevel@tonic-gate {
597*e5190c10Smuffin int i, j, k;
5987c478bd9Sstevel@tonic-gate
5997c478bd9Sstevel@tonic-gate k = 32767;
6007c478bd9Sstevel@tonic-gate if (dip != d) {
6017c478bd9Sstevel@tonic-gate if (dip->dimac && (i = dip->ditrap - a) > 0)
6027c478bd9Sstevel@tonic-gate k = i;
6037c478bd9Sstevel@tonic-gate return(k);
6047c478bd9Sstevel@tonic-gate }
6057c478bd9Sstevel@tonic-gate for (i = 0; i < NTRAP; i++) {
6067c478bd9Sstevel@tonic-gate if (mlist[i]) {
6077c478bd9Sstevel@tonic-gate if ((j = nlist[i]) < 0)
6087c478bd9Sstevel@tonic-gate j += pl;
6097c478bd9Sstevel@tonic-gate if ((j -= a) <= 0)
6107c478bd9Sstevel@tonic-gate continue;
6117c478bd9Sstevel@tonic-gate if (j < k)
6127c478bd9Sstevel@tonic-gate k = j;
6137c478bd9Sstevel@tonic-gate }
6147c478bd9Sstevel@tonic-gate }
6157c478bd9Sstevel@tonic-gate i = pl - a;
6167c478bd9Sstevel@tonic-gate if (k > i)
6177c478bd9Sstevel@tonic-gate k = i;
6187c478bd9Sstevel@tonic-gate return(k);
6197c478bd9Sstevel@tonic-gate }
6207c478bd9Sstevel@tonic-gate
6217c478bd9Sstevel@tonic-gate
622*e5190c10Smuffin int
findt1()6237c478bd9Sstevel@tonic-gate findt1()
6247c478bd9Sstevel@tonic-gate {
625*e5190c10Smuffin int i;
6267c478bd9Sstevel@tonic-gate
6277c478bd9Sstevel@tonic-gate if (dip != d)
6287c478bd9Sstevel@tonic-gate i = dip->dnl;
6297c478bd9Sstevel@tonic-gate else
6307c478bd9Sstevel@tonic-gate i = numtab[NL].val;
6317c478bd9Sstevel@tonic-gate return(findt(i));
6327c478bd9Sstevel@tonic-gate }
6337c478bd9Sstevel@tonic-gate
6347c478bd9Sstevel@tonic-gate
635*e5190c10Smuffin int
eject(a)6367c478bd9Sstevel@tonic-gate eject(a)
6377c478bd9Sstevel@tonic-gate struct s *a;
6387c478bd9Sstevel@tonic-gate {
639*e5190c10Smuffin int savlss;
6407c478bd9Sstevel@tonic-gate
6417c478bd9Sstevel@tonic-gate if (dip != d)
642*e5190c10Smuffin return (0);
6437c478bd9Sstevel@tonic-gate ejf++;
6447c478bd9Sstevel@tonic-gate if (a)
6457c478bd9Sstevel@tonic-gate ejl = a;
6467c478bd9Sstevel@tonic-gate else
6477c478bd9Sstevel@tonic-gate ejl = frame;
6487c478bd9Sstevel@tonic-gate if (trap)
649*e5190c10Smuffin return (0);
6507c478bd9Sstevel@tonic-gate e1:
6517c478bd9Sstevel@tonic-gate savlss = lss;
6527c478bd9Sstevel@tonic-gate lss = findt(numtab[NL].val);
6537c478bd9Sstevel@tonic-gate newline(0);
6547c478bd9Sstevel@tonic-gate lss = savlss;
6557c478bd9Sstevel@tonic-gate if (numtab[NL].val && !trap)
6567c478bd9Sstevel@tonic-gate goto e1;
657*e5190c10Smuffin
658*e5190c10Smuffin return (0);
6597c478bd9Sstevel@tonic-gate }
6607c478bd9Sstevel@tonic-gate
6617c478bd9Sstevel@tonic-gate
662*e5190c10Smuffin int
movword()6637c478bd9Sstevel@tonic-gate movword()
6647c478bd9Sstevel@tonic-gate {
665*e5190c10Smuffin int w;
666*e5190c10Smuffin tchar i, *wp;
6677c478bd9Sstevel@tonic-gate int savwch, hys;
6687c478bd9Sstevel@tonic-gate
6697c478bd9Sstevel@tonic-gate over = 0;
6707c478bd9Sstevel@tonic-gate wp = wordp;
6717c478bd9Sstevel@tonic-gate if (!nwd) {
6727c478bd9Sstevel@tonic-gate #ifndef EUC
6737c478bd9Sstevel@tonic-gate while (cbits(i = *wp++) == ' ') {
6747c478bd9Sstevel@tonic-gate #else
6757c478bd9Sstevel@tonic-gate #ifndef NROFF
6767c478bd9Sstevel@tonic-gate while (cbits(i = *wp++) == ' ') {
6777c478bd9Sstevel@tonic-gate #else
6787c478bd9Sstevel@tonic-gate while ((cbits(i = *wp++) & ~MBMASK) == ' ') {
6797c478bd9Sstevel@tonic-gate #endif /* NROFF */
6807c478bd9Sstevel@tonic-gate #endif /* EUC */
6817c478bd9Sstevel@tonic-gate wch--;
6827c478bd9Sstevel@tonic-gate wne -= sps;
6837c478bd9Sstevel@tonic-gate }
6847c478bd9Sstevel@tonic-gate wp--;
6857c478bd9Sstevel@tonic-gate }
6867c478bd9Sstevel@tonic-gate if (wne > nel && !hyoff && hyf && (!nwd || nel > 3 * sps) &&
6877c478bd9Sstevel@tonic-gate (!(hyf & 02) || (findt1() > lss)))
6887c478bd9Sstevel@tonic-gate hyphen(wp);
6897c478bd9Sstevel@tonic-gate savwch = wch;
6907c478bd9Sstevel@tonic-gate hyp = hyptr;
6917c478bd9Sstevel@tonic-gate nhyp = 0;
6927c478bd9Sstevel@tonic-gate while (*hyp && *hyp <= wp)
6937c478bd9Sstevel@tonic-gate hyp++;
6947c478bd9Sstevel@tonic-gate while (wch) {
6957c478bd9Sstevel@tonic-gate if (hyoff != 1 && *hyp == wp) {
6967c478bd9Sstevel@tonic-gate hyp++;
6977c478bd9Sstevel@tonic-gate if (!wdstart || (wp > wdstart + 1 && wp < wdend &&
6987c478bd9Sstevel@tonic-gate (!(hyf & 04) || wp < wdend - 1) && /* 04 => last 2 */
6997c478bd9Sstevel@tonic-gate (!(hyf & 010) || wp > wdstart + 2))) { /* 010 => 1st 2 */
7007c478bd9Sstevel@tonic-gate nhyp++;
7017c478bd9Sstevel@tonic-gate storeline((tchar)IMP, 0);
7027c478bd9Sstevel@tonic-gate }
7037c478bd9Sstevel@tonic-gate }
7047c478bd9Sstevel@tonic-gate i = *wp++;
7057c478bd9Sstevel@tonic-gate w = width(i);
7067c478bd9Sstevel@tonic-gate wne -= w;
7077c478bd9Sstevel@tonic-gate wch--;
7087c478bd9Sstevel@tonic-gate storeline(i, w);
7097c478bd9Sstevel@tonic-gate }
7107c478bd9Sstevel@tonic-gate if (nel >= 0) {
7117c478bd9Sstevel@tonic-gate nwd++;
7127c478bd9Sstevel@tonic-gate return(0); /* line didn't fill up */
7137c478bd9Sstevel@tonic-gate }
7147c478bd9Sstevel@tonic-gate #ifndef NROFF
7157c478bd9Sstevel@tonic-gate xbits((tchar)HYPHEN, 1);
7167c478bd9Sstevel@tonic-gate #endif
7177c478bd9Sstevel@tonic-gate hys = width((tchar)HYPHEN);
7187c478bd9Sstevel@tonic-gate m1:
7197c478bd9Sstevel@tonic-gate if (!nhyp) {
7207c478bd9Sstevel@tonic-gate if (!nwd)
7217c478bd9Sstevel@tonic-gate goto m3;
7227c478bd9Sstevel@tonic-gate if (wch == savwch)
7237c478bd9Sstevel@tonic-gate goto m4;
7247c478bd9Sstevel@tonic-gate }
7257c478bd9Sstevel@tonic-gate if (*--linep != IMP)
7267c478bd9Sstevel@tonic-gate goto m5;
7277c478bd9Sstevel@tonic-gate if (!(--nhyp))
7287c478bd9Sstevel@tonic-gate if (!nwd)
7297c478bd9Sstevel@tonic-gate goto m2;
7307c478bd9Sstevel@tonic-gate if (nel < hys) {
7317c478bd9Sstevel@tonic-gate nc--;
7327c478bd9Sstevel@tonic-gate goto m1;
7337c478bd9Sstevel@tonic-gate }
7347c478bd9Sstevel@tonic-gate m2:
7357c478bd9Sstevel@tonic-gate if ((i = cbits(*(linep - 1))) != '-' && i != EMDASH) {
7367c478bd9Sstevel@tonic-gate *linep = (*(linep - 1) & SFMASK) | HYPHEN;
7377c478bd9Sstevel@tonic-gate w = width(*linep);
7387c478bd9Sstevel@tonic-gate nel -= w;
7397c478bd9Sstevel@tonic-gate ne += w;
7407c478bd9Sstevel@tonic-gate linep++;
7417c478bd9Sstevel@tonic-gate }
7427c478bd9Sstevel@tonic-gate m3:
7437c478bd9Sstevel@tonic-gate nwd++;
7447c478bd9Sstevel@tonic-gate m4:
7457c478bd9Sstevel@tonic-gate wordp = wp;
7467c478bd9Sstevel@tonic-gate return(1); /* line filled up */
7477c478bd9Sstevel@tonic-gate m5:
7487c478bd9Sstevel@tonic-gate nc--;
7497c478bd9Sstevel@tonic-gate w = width(*linep);
7507c478bd9Sstevel@tonic-gate ne -= w;
7517c478bd9Sstevel@tonic-gate nel += w;
7527c478bd9Sstevel@tonic-gate wne += w;
7537c478bd9Sstevel@tonic-gate wch++;
7547c478bd9Sstevel@tonic-gate wp--;
7557c478bd9Sstevel@tonic-gate goto m1;
7567c478bd9Sstevel@tonic-gate }
7577c478bd9Sstevel@tonic-gate
7587c478bd9Sstevel@tonic-gate
759*e5190c10Smuffin int
7607c478bd9Sstevel@tonic-gate horiz(i)
7617c478bd9Sstevel@tonic-gate int i;
7627c478bd9Sstevel@tonic-gate {
7637c478bd9Sstevel@tonic-gate vflag = 0;
7647c478bd9Sstevel@tonic-gate if (i)
7657c478bd9Sstevel@tonic-gate pchar(makem(i));
766*e5190c10Smuffin
767*e5190c10Smuffin return (0);
7687c478bd9Sstevel@tonic-gate }
7697c478bd9Sstevel@tonic-gate
7707c478bd9Sstevel@tonic-gate
771*e5190c10Smuffin int
7727c478bd9Sstevel@tonic-gate setnel()
7737c478bd9Sstevel@tonic-gate {
7747c478bd9Sstevel@tonic-gate if (!nc) {
7757c478bd9Sstevel@tonic-gate linep = line;
7767c478bd9Sstevel@tonic-gate if (un1 >= 0) {
7777c478bd9Sstevel@tonic-gate un = un1;
7787c478bd9Sstevel@tonic-gate un1 = -1;
7797c478bd9Sstevel@tonic-gate }
7807c478bd9Sstevel@tonic-gate nel = ll - un;
7817c478bd9Sstevel@tonic-gate ne = adsp = adrem = 0;
7827c478bd9Sstevel@tonic-gate }
783*e5190c10Smuffin
784*e5190c10Smuffin return (0);
7857c478bd9Sstevel@tonic-gate }
7867c478bd9Sstevel@tonic-gate
787*e5190c10Smuffin int
7887c478bd9Sstevel@tonic-gate getword(x)
7897c478bd9Sstevel@tonic-gate int x;
7907c478bd9Sstevel@tonic-gate {
791*e5190c10Smuffin int j, k;
792*e5190c10Smuffin tchar i, *wp;
7937c478bd9Sstevel@tonic-gate int noword;
7947c478bd9Sstevel@tonic-gate #ifdef EUC
7957c478bd9Sstevel@tonic-gate #ifdef NROFF
7967c478bd9Sstevel@tonic-gate wchar_t *wddelim;
7977c478bd9Sstevel@tonic-gate char mbbuf3[MB_LEN_MAX + 1];
7987c478bd9Sstevel@tonic-gate char *mbbuf3p;
7997c478bd9Sstevel@tonic-gate int wbf, n;
8007c478bd9Sstevel@tonic-gate tchar m;
8017c478bd9Sstevel@tonic-gate #endif /* NROFF */
8027c478bd9Sstevel@tonic-gate #endif /* EUC */
8037c478bd9Sstevel@tonic-gate
8047c478bd9Sstevel@tonic-gate noword = 0;
8057c478bd9Sstevel@tonic-gate if (x)
8067c478bd9Sstevel@tonic-gate if (pendw) {
8077c478bd9Sstevel@tonic-gate *pendw = 0;
8087c478bd9Sstevel@tonic-gate goto rtn;
8097c478bd9Sstevel@tonic-gate }
8107c478bd9Sstevel@tonic-gate if (wordp = pendw)
8117c478bd9Sstevel@tonic-gate goto g1;
8127c478bd9Sstevel@tonic-gate hyp = hyptr;
8137c478bd9Sstevel@tonic-gate wordp = word;
8147c478bd9Sstevel@tonic-gate over = wne = wch = 0;
8157c478bd9Sstevel@tonic-gate hyoff = 0;
8167c478bd9Sstevel@tonic-gate #ifdef EUC
8177c478bd9Sstevel@tonic-gate #ifdef NROFF
8187c478bd9Sstevel@tonic-gate mtbufp = mtbuf;
8197c478bd9Sstevel@tonic-gate if (pendmb) {
8207c478bd9Sstevel@tonic-gate while(*mtbufp) {
8217c478bd9Sstevel@tonic-gate switch(*mtbufp & MBMASK) {
8227c478bd9Sstevel@tonic-gate case LASTOFMB:
8237c478bd9Sstevel@tonic-gate case BYTE_CHR:
8247c478bd9Sstevel@tonic-gate storeword(*mtbufp++, -1);
8257c478bd9Sstevel@tonic-gate break;
8267c478bd9Sstevel@tonic-gate
8277c478bd9Sstevel@tonic-gate default:
8287c478bd9Sstevel@tonic-gate storeword(*mtbufp++, 0);
8297c478bd9Sstevel@tonic-gate }
8307c478bd9Sstevel@tonic-gate }
8317c478bd9Sstevel@tonic-gate mtbufp = mtbuf;
8327c478bd9Sstevel@tonic-gate pendmb = 0;
8337c478bd9Sstevel@tonic-gate goto g1;
8347c478bd9Sstevel@tonic-gate }
8357c478bd9Sstevel@tonic-gate #endif /* NROFF */
8367c478bd9Sstevel@tonic-gate #endif /* EUC */
8377c478bd9Sstevel@tonic-gate while (1) { /* picks up 1st char of word */
8387c478bd9Sstevel@tonic-gate j = cbits(i = GETCH());
8397c478bd9Sstevel@tonic-gate #ifdef EUC
8407c478bd9Sstevel@tonic-gate #ifdef NROFF
8417c478bd9Sstevel@tonic-gate if (multi_locale)
8427c478bd9Sstevel@tonic-gate if (collectmb(i))
8437c478bd9Sstevel@tonic-gate continue;
8447c478bd9Sstevel@tonic-gate #endif /* NROFF */
8457c478bd9Sstevel@tonic-gate #endif /* EUC */
8467c478bd9Sstevel@tonic-gate if (j == '\n') {
8477c478bd9Sstevel@tonic-gate wne = wch = 0;
8487c478bd9Sstevel@tonic-gate noword = 1;
8497c478bd9Sstevel@tonic-gate goto rtn;
8507c478bd9Sstevel@tonic-gate }
8517c478bd9Sstevel@tonic-gate if (j == ohc) {
8527c478bd9Sstevel@tonic-gate hyoff = 1; /* 1 => don't hyphenate */
8537c478bd9Sstevel@tonic-gate continue;
8547c478bd9Sstevel@tonic-gate }
8557c478bd9Sstevel@tonic-gate if (j == ' ') {
8567c478bd9Sstevel@tonic-gate numtab[HP].val += sps;
8577c478bd9Sstevel@tonic-gate widthp = sps;
8587c478bd9Sstevel@tonic-gate storeword(i, sps);
8597c478bd9Sstevel@tonic-gate continue;
8607c478bd9Sstevel@tonic-gate }
8617c478bd9Sstevel@tonic-gate break;
8627c478bd9Sstevel@tonic-gate }
8637c478bd9Sstevel@tonic-gate #ifdef EUC
8647c478bd9Sstevel@tonic-gate #ifdef NROFF
8657c478bd9Sstevel@tonic-gate if (!multi_locale)
8667c478bd9Sstevel@tonic-gate goto a0;
8677c478bd9Sstevel@tonic-gate if (wddlm && iswprint(wceoll) && iswprint(cwc) &&
8687c478bd9Sstevel@tonic-gate (!iswascii(wceoll) || !iswascii(cwc)) &&
8697c478bd9Sstevel@tonic-gate !iswspace(wceoll) && !iswspace(cwc)) {
8707c478bd9Sstevel@tonic-gate wddelim = (*wddlm)(wceoll, cwc, 1);
8717c478bd9Sstevel@tonic-gate wceoll = 0;
8727c478bd9Sstevel@tonic-gate if (*wddelim != ' ') {
8737c478bd9Sstevel@tonic-gate if (!*wddelim) {
8747c478bd9Sstevel@tonic-gate storeword(((*wdbdg)(wceoll, cwc, 1) < 3) ?
8757c478bd9Sstevel@tonic-gate ZWDELIM(1) : ZWDELIM(2), 0);
8767c478bd9Sstevel@tonic-gate } else {
8777c478bd9Sstevel@tonic-gate while (*wddelim) {
8787c478bd9Sstevel@tonic-gate if ((n = wctomb(mbbuf3, *wddelim++))
8797c478bd9Sstevel@tonic-gate > 0) {
8807c478bd9Sstevel@tonic-gate mbbuf3[n] = 0;
8817c478bd9Sstevel@tonic-gate n--;
8827c478bd9Sstevel@tonic-gate mbbuf3p = mbbuf3 + n;
8837c478bd9Sstevel@tonic-gate while(n) {
8847c478bd9Sstevel@tonic-gate m = *(mbbuf3p-- - n--) &
8857c478bd9Sstevel@tonic-gate 0xff | MIDDLEOFMB |
8867c478bd9Sstevel@tonic-gate ZBIT;
8877c478bd9Sstevel@tonic-gate storeword(m, 0);
8887c478bd9Sstevel@tonic-gate }
8897c478bd9Sstevel@tonic-gate m = *mbbuf3p & 0xff | LASTOFMB;
8907c478bd9Sstevel@tonic-gate storeword(m, -1);
8917c478bd9Sstevel@tonic-gate } else {
8927c478bd9Sstevel@tonic-gate storeword(' ' | chbits, sps);
8937c478bd9Sstevel@tonic-gate break;
8947c478bd9Sstevel@tonic-gate }
8957c478bd9Sstevel@tonic-gate }
8967c478bd9Sstevel@tonic-gate }
8977c478bd9Sstevel@tonic-gate spflg = 0;
8987c478bd9Sstevel@tonic-gate goto g0;
8997c478bd9Sstevel@tonic-gate }
9007c478bd9Sstevel@tonic-gate }
9017c478bd9Sstevel@tonic-gate a0:
9027c478bd9Sstevel@tonic-gate #endif /* NROFF */
9037c478bd9Sstevel@tonic-gate #endif /* EUC */
9047c478bd9Sstevel@tonic-gate storeword(' ' | chbits, sps);
9057c478bd9Sstevel@tonic-gate if (spflg) {
9067c478bd9Sstevel@tonic-gate storeword(' ' | chbits, sps);
9077c478bd9Sstevel@tonic-gate spflg = 0;
9087c478bd9Sstevel@tonic-gate }
9097c478bd9Sstevel@tonic-gate g0:
9107c478bd9Sstevel@tonic-gate if (j == CONT) {
9117c478bd9Sstevel@tonic-gate pendw = wordp;
9127c478bd9Sstevel@tonic-gate nflush = 0;
9137c478bd9Sstevel@tonic-gate flushi();
9147c478bd9Sstevel@tonic-gate return(1);
9157c478bd9Sstevel@tonic-gate }
9167c478bd9Sstevel@tonic-gate if (hyoff != 1) {
9177c478bd9Sstevel@tonic-gate if (j == ohc) {
9187c478bd9Sstevel@tonic-gate hyoff = 2;
9197c478bd9Sstevel@tonic-gate *hyp++ = wordp;
9207c478bd9Sstevel@tonic-gate if (hyp > (hyptr + NHYP - 1))
9217c478bd9Sstevel@tonic-gate hyp = hyptr + NHYP - 1;
9227c478bd9Sstevel@tonic-gate goto g1;
9237c478bd9Sstevel@tonic-gate }
9247c478bd9Sstevel@tonic-gate if (j == '-' || j == EMDASH)
9257c478bd9Sstevel@tonic-gate if (wordp > word + 1) {
9267c478bd9Sstevel@tonic-gate hyoff = 2;
9277c478bd9Sstevel@tonic-gate *hyp++ = wordp + 1;
9287c478bd9Sstevel@tonic-gate if (hyp > (hyptr + NHYP - 1))
9297c478bd9Sstevel@tonic-gate hyp = hyptr + NHYP - 1;
9307c478bd9Sstevel@tonic-gate }
9317c478bd9Sstevel@tonic-gate }
9327c478bd9Sstevel@tonic-gate j = width(i);
9337c478bd9Sstevel@tonic-gate numtab[HP].val += j;
9347c478bd9Sstevel@tonic-gate #ifndef EUC
9357c478bd9Sstevel@tonic-gate storeword(i, j);
9367c478bd9Sstevel@tonic-gate #else
9377c478bd9Sstevel@tonic-gate #ifndef NROFF
9387c478bd9Sstevel@tonic-gate storeword(i, j);
9397c478bd9Sstevel@tonic-gate #else
9407c478bd9Sstevel@tonic-gate if (multi_locale) {
9417c478bd9Sstevel@tonic-gate mtbufp = mtbuf;
9427c478bd9Sstevel@tonic-gate while(*mtbufp) {
9437c478bd9Sstevel@tonic-gate switch(*mtbufp & MBMASK) {
9447c478bd9Sstevel@tonic-gate case LASTOFMB:
9457c478bd9Sstevel@tonic-gate case BYTE_CHR:
9467c478bd9Sstevel@tonic-gate storeword(*mtbufp++, j);
9477c478bd9Sstevel@tonic-gate break;
9487c478bd9Sstevel@tonic-gate
9497c478bd9Sstevel@tonic-gate default:
9507c478bd9Sstevel@tonic-gate storeword(*mtbufp++, 0);
9517c478bd9Sstevel@tonic-gate }
9527c478bd9Sstevel@tonic-gate }
9537c478bd9Sstevel@tonic-gate mtbufp = mtbuf;
9547c478bd9Sstevel@tonic-gate } else {
9557c478bd9Sstevel@tonic-gate storeword(i, j);
9567c478bd9Sstevel@tonic-gate }
9577c478bd9Sstevel@tonic-gate #endif /* NROFF */
9587c478bd9Sstevel@tonic-gate #endif /* EUC */
9597c478bd9Sstevel@tonic-gate g1:
9607c478bd9Sstevel@tonic-gate j = cbits(i = GETCH());
9617c478bd9Sstevel@tonic-gate #ifdef EUC
9627c478bd9Sstevel@tonic-gate #ifdef NROFF
9637c478bd9Sstevel@tonic-gate if (multi_locale)
9647c478bd9Sstevel@tonic-gate if (collectmb(i))
9657c478bd9Sstevel@tonic-gate goto g1;
9667c478bd9Sstevel@tonic-gate #endif /* NROFF */
9677c478bd9Sstevel@tonic-gate #endif /* EUC */
9687c478bd9Sstevel@tonic-gate if (j != ' ') {
9697c478bd9Sstevel@tonic-gate static char *sentchar = ".?!:"; /* sentence terminators */
9707c478bd9Sstevel@tonic-gate if (j != '\n')
9717c478bd9Sstevel@tonic-gate #ifdef EUC
9727c478bd9Sstevel@tonic-gate #ifdef NROFF
9737c478bd9Sstevel@tonic-gate if (!multi_locale)
9747c478bd9Sstevel@tonic-gate #endif /* NROFF */
9757c478bd9Sstevel@tonic-gate #endif /* EUC */
9767c478bd9Sstevel@tonic-gate goto g0;
9777c478bd9Sstevel@tonic-gate #ifdef EUC
9787c478bd9Sstevel@tonic-gate #ifdef NROFF
9797c478bd9Sstevel@tonic-gate else {
9807c478bd9Sstevel@tonic-gate if (!wdbdg || (iswascii(cwc) && iswascii(owc)))
9817c478bd9Sstevel@tonic-gate goto g0;
9827c478bd9Sstevel@tonic-gate if ((wbf = (*wdbdg)(owc, cwc, 1)) < 5) {
9837c478bd9Sstevel@tonic-gate pendmb++;
9847c478bd9Sstevel@tonic-gate storeword((wbf < 3) ? ZWDELIM(1) :
9857c478bd9Sstevel@tonic-gate ZWDELIM(2), 0);
9867c478bd9Sstevel@tonic-gate *wordp = 0;
9877c478bd9Sstevel@tonic-gate goto rtn;
9887c478bd9Sstevel@tonic-gate } else goto g0;
9897c478bd9Sstevel@tonic-gate }
9907c478bd9Sstevel@tonic-gate #endif /* NROFF */
9917c478bd9Sstevel@tonic-gate #endif /* EUC */
9927c478bd9Sstevel@tonic-gate wp = wordp-1; /* handle extra space at end of sentence */
9937c478bd9Sstevel@tonic-gate while (wp >= word) {
9947c478bd9Sstevel@tonic-gate j = cbits(*wp--);
9957c478bd9Sstevel@tonic-gate if (j=='"' || j=='\'' || j==')' || j==']' || j=='*' || j==DAGGER)
9967c478bd9Sstevel@tonic-gate continue;
9977c478bd9Sstevel@tonic-gate for (k = 0; sentchar[k]; k++)
9987c478bd9Sstevel@tonic-gate if (j == sentchar[k]) {
9997c478bd9Sstevel@tonic-gate spflg++;
10007c478bd9Sstevel@tonic-gate break;
10017c478bd9Sstevel@tonic-gate }
10027c478bd9Sstevel@tonic-gate break;
10037c478bd9Sstevel@tonic-gate }
10047c478bd9Sstevel@tonic-gate }
10057c478bd9Sstevel@tonic-gate #ifdef EUC
10067c478bd9Sstevel@tonic-gate #ifdef NROFF
10077c478bd9Sstevel@tonic-gate wceoll = owc;
10087c478bd9Sstevel@tonic-gate #endif /* NROFF */
10097c478bd9Sstevel@tonic-gate #endif /* EUC */
10107c478bd9Sstevel@tonic-gate *wordp = 0;
10117c478bd9Sstevel@tonic-gate numtab[HP].val += sps;
10127c478bd9Sstevel@tonic-gate rtn:
10137c478bd9Sstevel@tonic-gate for (wp = word; *wp; wp++) {
10147c478bd9Sstevel@tonic-gate j = cbits(*wp);
10157c478bd9Sstevel@tonic-gate if (j == ' ')
10167c478bd9Sstevel@tonic-gate continue;
10177c478bd9Sstevel@tonic-gate if (!ischar(j) || (!isdigit(j) && j != '-'))
10187c478bd9Sstevel@tonic-gate break;
10197c478bd9Sstevel@tonic-gate }
10207c478bd9Sstevel@tonic-gate if (*wp == 0) /* all numbers, so don't hyphenate */
10217c478bd9Sstevel@tonic-gate hyoff = 1;
10227c478bd9Sstevel@tonic-gate wdstart = 0;
10237c478bd9Sstevel@tonic-gate wordp = word;
10247c478bd9Sstevel@tonic-gate pendw = 0;
10257c478bd9Sstevel@tonic-gate *hyp++ = 0;
10267c478bd9Sstevel@tonic-gate setnel();
10277c478bd9Sstevel@tonic-gate return(noword);
10287c478bd9Sstevel@tonic-gate }
10297c478bd9Sstevel@tonic-gate
10307c478bd9Sstevel@tonic-gate
1031*e5190c10Smuffin int
10327c478bd9Sstevel@tonic-gate storeword(c, w)
1033*e5190c10Smuffin tchar c;
1034*e5190c10Smuffin int w;
10357c478bd9Sstevel@tonic-gate {
10367c478bd9Sstevel@tonic-gate
10377c478bd9Sstevel@tonic-gate if (wordp >= &word[WDSIZE - 3]) {
10387c478bd9Sstevel@tonic-gate if (!over) {
10397c478bd9Sstevel@tonic-gate flusho();
10407c478bd9Sstevel@tonic-gate errprint(gettext("Word overflow."));
10417c478bd9Sstevel@tonic-gate over++;
10427c478bd9Sstevel@tonic-gate c = LEFTHAND;
10437c478bd9Sstevel@tonic-gate w = -1;
10447c478bd9Sstevel@tonic-gate goto s1;
10457c478bd9Sstevel@tonic-gate }
1046*e5190c10Smuffin return (0);
10477c478bd9Sstevel@tonic-gate }
10487c478bd9Sstevel@tonic-gate s1:
10497c478bd9Sstevel@tonic-gate if (w == -1)
10507c478bd9Sstevel@tonic-gate w = width(c);
10517c478bd9Sstevel@tonic-gate widthp = w;
10527c478bd9Sstevel@tonic-gate wne += w;
10537c478bd9Sstevel@tonic-gate *wordp++ = c;
10547c478bd9Sstevel@tonic-gate wch++;
1055*e5190c10Smuffin
1056*e5190c10Smuffin return (0);
10577c478bd9Sstevel@tonic-gate }
10587c478bd9Sstevel@tonic-gate
10597c478bd9Sstevel@tonic-gate
10607c478bd9Sstevel@tonic-gate #ifdef NROFF
10617c478bd9Sstevel@tonic-gate tchar gettch()
10627c478bd9Sstevel@tonic-gate {
10637c478bd9Sstevel@tonic-gate extern int c_isalnum;
10647c478bd9Sstevel@tonic-gate tchar i;
10657c478bd9Sstevel@tonic-gate int j;
10667c478bd9Sstevel@tonic-gate
10677c478bd9Sstevel@tonic-gate i = getch();
10687c478bd9Sstevel@tonic-gate j = cbits(i);
10697c478bd9Sstevel@tonic-gate if (ismot(i) || fbits(i) != ulfont)
10707c478bd9Sstevel@tonic-gate return(i);
10717c478bd9Sstevel@tonic-gate if (cu) {
10727c478bd9Sstevel@tonic-gate if (trtab[j] == ' ') {
10737c478bd9Sstevel@tonic-gate setcbits(i, '_');
10747c478bd9Sstevel@tonic-gate setfbits(i, FT); /* default */
10757c478bd9Sstevel@tonic-gate }
10767c478bd9Sstevel@tonic-gate return(i);
10777c478bd9Sstevel@tonic-gate }
10787c478bd9Sstevel@tonic-gate /* should test here for characters that ought to be underlined */
10797c478bd9Sstevel@tonic-gate /* in the old nroff, that was the 200 bit on the width! */
10807c478bd9Sstevel@tonic-gate /* for now, just do letters, digits and certain special chars */
10817c478bd9Sstevel@tonic-gate if (j <= 127) {
10827c478bd9Sstevel@tonic-gate if (!isalnum(j))
10837c478bd9Sstevel@tonic-gate setfbits(i, FT);
10847c478bd9Sstevel@tonic-gate } else {
10857c478bd9Sstevel@tonic-gate if (j < c_isalnum)
10867c478bd9Sstevel@tonic-gate setfbits(i, FT);
10877c478bd9Sstevel@tonic-gate }
10887c478bd9Sstevel@tonic-gate return(i);
10897c478bd9Sstevel@tonic-gate }
10907c478bd9Sstevel@tonic-gate
10917c478bd9Sstevel@tonic-gate
10927c478bd9Sstevel@tonic-gate #endif
10937c478bd9Sstevel@tonic-gate #ifdef EUC
10947c478bd9Sstevel@tonic-gate #ifdef NROFF
1095*e5190c10Smuffin int
10967c478bd9Sstevel@tonic-gate collectmb(i)
10977c478bd9Sstevel@tonic-gate tchar i;
10987c478bd9Sstevel@tonic-gate {
10997c478bd9Sstevel@tonic-gate int busy;
11007c478bd9Sstevel@tonic-gate
11017c478bd9Sstevel@tonic-gate *mtbufp++ = i;
11027c478bd9Sstevel@tonic-gate *mbbuf2p++ = i & BYTEMASK;
11037c478bd9Sstevel@tonic-gate *mtbufp = *mbbuf2p = 0;
11047c478bd9Sstevel@tonic-gate if (ismot(i)) {
11057c478bd9Sstevel@tonic-gate mtbufp = mtbuf;
11067c478bd9Sstevel@tonic-gate mbbuf2p = mbbuf2;
11077c478bd9Sstevel@tonic-gate owc = 0;
11087c478bd9Sstevel@tonic-gate cwc = 0;
11097c478bd9Sstevel@tonic-gate return(busy = 0);
11107c478bd9Sstevel@tonic-gate }
11117c478bd9Sstevel@tonic-gate if ((i & MBMASK) == MIDDLEOFMB) {
11127c478bd9Sstevel@tonic-gate if (mtbufp <= (mtbuf + MB_CUR_MAX)) {
11137c478bd9Sstevel@tonic-gate busy = 1;
11147c478bd9Sstevel@tonic-gate } else {
11157c478bd9Sstevel@tonic-gate *(mtbufp - 1) &= ~MBMASK;
11167c478bd9Sstevel@tonic-gate goto gotmb;
11177c478bd9Sstevel@tonic-gate }
11187c478bd9Sstevel@tonic-gate } else {
11197c478bd9Sstevel@tonic-gate if ((i & MBMASK) == LASTOFMB)
11207c478bd9Sstevel@tonic-gate *(mtbufp - 1) &= ~MBMASK;
11217c478bd9Sstevel@tonic-gate gotmb:
11227c478bd9Sstevel@tonic-gate mtbufp = mtbuf;
11237c478bd9Sstevel@tonic-gate owc = cwc;
11247c478bd9Sstevel@tonic-gate if (mbtowc(&cwc, mbbuf2, MB_CUR_MAX) <= 0) {
11257c478bd9Sstevel@tonic-gate mtbufp = mtbuf;
11267c478bd9Sstevel@tonic-gate while (*mtbufp) {
11277c478bd9Sstevel@tonic-gate setcbits(*mtbufp, (*mtbufp & 0x1ff));
11287c478bd9Sstevel@tonic-gate mtbufp++;
11297c478bd9Sstevel@tonic-gate }
11307c478bd9Sstevel@tonic-gate mtbufp = mtbuf;
11317c478bd9Sstevel@tonic-gate }
11327c478bd9Sstevel@tonic-gate mbbuf2p = mbbuf2;
11337c478bd9Sstevel@tonic-gate busy = 0;
11347c478bd9Sstevel@tonic-gate }
11357c478bd9Sstevel@tonic-gate return(busy);
11367c478bd9Sstevel@tonic-gate }
11377c478bd9Sstevel@tonic-gate
11387c478bd9Sstevel@tonic-gate
11397c478bd9Sstevel@tonic-gate #endif /* NROFF */
11407c478bd9Sstevel@tonic-gate #endif /* EUC */
1141