4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
76 char mbbuf2
[MB_LEN_MAX
+ 1];
77 char *mbbuf2p
= mbbuf2
;
78 tchar mtbuf
[MB_LEN_MAX
+ 1];
81 wchar_t cwc
, owc
, wceoll
;
101 if (dip
== d
&& numtab
[NL
].val
== -1) {
112 } else if (pendw
&& !brflg
) {
116 *linep
= dip
->nls
= 0;
127 if ((lastl
= ll
- un
) < ne
)
130 if (admod
&& ad
&& (brflg
!= 2)) {
134 un
+= quant(nel
/ 2, HOR
);
140 if (lastl
+ un
> dip
->maxl
)
141 dip
->maxl
= lastl
+ un
;
151 adrem
= (adrem
/ resol
) * resol
;
152 for (i
= line
; nc
> 0; ) {
154 if ((cbits(j
= *i
++)) == ' ') {
157 if ((cbits(j
= *i
++)) == ' ') {
159 if ((cbits(j
= *i
++) & ~MBMASK
) == ' ') {
167 } while ((cbits(j
= *i
++)) == ' ');
170 } while ((cbits(j
= *i
++)) == ' ');
172 } while ((cbits(j
= *i
++) & ~MBMASK
) == ' ');
182 } else if ((totout
& 01) || adrem
/ resol
>= nwd
) {
187 pchar((tchar
) WORDSP
);
195 if ((k
= ll
- un
- lastl
+ ics
) > 0)
208 if (dip
->dnl
> dip
->hnl
)
211 if (numtab
[NL
].val
> dip
->hnl
)
212 dip
->hnl
= numtab
[NL
].val
;
214 for (k
= ls
- 1; k
> 0 && !trap
; k
--)
228 nw
= width('1' | nrbits
);
233 if (numtab
[LN
].val
% ndf
) {
236 un
+= nw
* (3 + nms
+ ni
);
240 if (numtab
[LN
].val
< 100)
242 if (numtab
[LN
].val
< 10)
244 horiz(nw
* (ni
+ i
));
246 fnumb(numtab
[LN
].val
, pchar
);
263 if ((dip
== d
) && (numtab
[NL
].val
== -1)) {
282 while ((cbits(i
= GETCH())) == ' ') {
284 numtab
[HP
].val
+= sps
;
289 nflush
= pendt
= ch
= spcnt
= 0;
324 adsp
= nel
/ (nwd
- 1);
325 adsp
= (adsp
/ HOR
) * HOR
;
326 adrem
= nel
- adsp
*(nwd
-1);
364 while ((j
= (cbits(i
= GETCH()))) != '\n') {
381 if ((i
= quant(nel
/ 2, HOR
)) > 0)
385 storeline((tchar
)FILLER
, 0);
415 if (ul
&& (--ul
== 0)) {
420 if (it
&& (--it
== 0) && itmac
)
431 if (linep
>= line
+ lnsize
- 1) {
434 errprint(gettext("Line overflow."));
473 dip
->blss
= flss
= 0;
476 pchar1((tchar
)dip
->alss
);
478 dip
->dnl
+= dip
->alss
;
481 if (dip
->ditrap
&& !dip
->ditf
&& dip
->dnl
>= dip
->ditrap
&& dip
->dimac
)
482 if (control(dip
->dimac
, 0)) {
491 nlss
= dip
->alss
+ dip
->blss
+ lss
;
492 numtab
[NL
].val
+= nlss
;
495 dip
->alss
= dip
->blss
= 0;
501 if (numtab
[NL
].val
< pl
)
504 ejf
= dip
->hnl
= numtab
[NL
].val
= 0;
507 if ((!nc
&& !wch
) || ndone
)
514 opn
= numtab
[PN
].val
;
517 numtab
[PN
].val
= npn
;
521 if (numtab
[PN
].val
== pfrom
) {
524 } else if (opn
== pto
) {
531 newpage(numtab
[PN
].val
); /* supposedly in a clean state so can pause */
541 if (numtab
[NL
].val
== 0) {
542 if ((j
= findn(0)) != NTRAP
)
543 trap
= control(mlist
[j
], 0);
544 } else if ((i
= findt(numtab
[NL
].val
- nlss
)) <= nlss
) {
545 if ((j
= findn1(numtab
[NL
].val
- nlss
+ i
)) == NTRAP
) {
547 errprint(gettext("Trap botch."));
550 trap
= control(mlist
[j
], 0);
563 for (i
= 0; i
< NTRAP
; i
++) {
565 if ((j
= nlist
[i
]) < 0)
578 pfrom
= pto
>=0 ? pto
: -pto
;
601 if (dip
->dimac
&& (i
= dip
->ditrap
- a
) > 0)
605 for (i
= 0; i
< NTRAP
; i
++) {
607 if ((j
= nlist
[i
]) < 0)
652 lss
= findt(numtab
[NL
].val
);
655 if (numtab
[NL
].val
&& !trap
)
673 while (cbits(i
= *wp
++) == ' ') {
676 while (cbits(i
= *wp
++) == ' ') {
678 while ((cbits(i
= *wp
++) & ~MBMASK
) == ' ') {
686 if (wne
> nel
&& !hyoff
&& hyf
&& (!nwd
|| nel
> 3 * sps
) &&
687 (!(hyf
& 02) || (findt1() > lss
)))
692 while (*hyp
&& *hyp
<= wp
)
695 if (hyoff
!= 1 && *hyp
== wp
) {
697 if (!wdstart
|| (wp
> wdstart
+ 1 && wp
< wdend
&&
698 (!(hyf
& 04) || wp
< wdend
- 1) && /* 04 => last 2 */
699 (!(hyf
& 010) || wp
> wdstart
+ 2))) { /* 010 => 1st 2 */
701 storeline((tchar
)IMP
, 0);
712 return(0); /* line didn't fill up */
715 xbits((tchar
)HYPHEN
, 1);
717 hys
= width((tchar
)HYPHEN
);
735 if ((i
= cbits(*(linep
- 1))) != '-' && i
!= EMDASH
) {
736 *linep
= (*(linep
- 1) & SFMASK
) | HYPHEN
;
746 return(1); /* line filled up */
781 ne
= adsp
= adrem
= 0;
797 char mbbuf3
[MB_LEN_MAX
+ 1];
814 over
= wne
= wch
= 0;
821 switch(*mtbufp
& MBMASK
) {
824 storeword(*mtbufp
++, -1);
828 storeword(*mtbufp
++, 0);
837 while (1) { /* picks up 1st char of word */
838 j
= cbits(i
= GETCH());
852 hyoff
= 1; /* 1 => don't hyphenate */
856 numtab
[HP
].val
+= sps
;
867 if (wddlm
&& iswprint(wceoll
) && iswprint(cwc
) &&
868 (!iswascii(wceoll
) || !iswascii(cwc
)) &&
869 !iswspace(wceoll
) && !iswspace(cwc
)) {
870 wddelim
= (*wddlm
)(wceoll
, cwc
, 1);
872 if (*wddelim
!= ' ') {
874 storeword(((*wdbdg
)(wceoll
, cwc
, 1) < 3) ?
875 ZWDELIM(1) : ZWDELIM(2), 0);
878 if ((n
= wctomb(mbbuf3
, *wddelim
++))
882 mbbuf3p
= mbbuf3
+ n
;
884 m
= *(mbbuf3p
-- - n
--) &
889 m
= *mbbuf3p
& 0xff | LASTOFMB
;
892 storeword(' ' | chbits
, sps
);
904 storeword(' ' | chbits
, sps
);
906 storeword(' ' | chbits
, sps
);
920 if (hyp
> (hyptr
+ NHYP
- 1))
921 hyp
= hyptr
+ NHYP
- 1;
924 if (j
== '-' || j
== EMDASH
)
925 if (wordp
> word
+ 1) {
928 if (hyp
> (hyptr
+ NHYP
- 1))
929 hyp
= hyptr
+ NHYP
- 1;
943 switch(*mtbufp
& MBMASK
) {
946 storeword(*mtbufp
++, j
);
950 storeword(*mtbufp
++, 0);
960 j
= cbits(i
= GETCH());
969 static char *sentchar
= ".?!:"; /* sentence terminators */
980 if (!wdbdg
|| (iswascii(cwc
) && iswascii(owc
)))
982 if ((wbf
= (*wdbdg
)(owc
, cwc
, 1)) < 5) {
984 storeword((wbf
< 3) ? ZWDELIM(1) :
992 wp
= wordp
-1; /* handle extra space at end of sentence */
995 if (j
=='"' || j
=='\'' || j
==')' || j
==']' || j
=='*' || j
==DAGGER
)
997 for (k
= 0; sentchar
[k
]; k
++)
998 if (j
== sentchar
[k
]) {
1011 numtab
[HP
].val
+= sps
;
1013 for (wp
= word
; *wp
; wp
++) {
1017 if (!ischar(j
) || (!isdigit(j
) && j
!= '-'))
1020 if (*wp
== 0) /* all numbers, so don't hyphenate */
1037 if (wordp
>= &word
[WDSIZE
- 3]) {
1040 errprint(gettext("Word overflow."));
1063 extern int c_isalnum
;
1069 if (ismot(i
) || fbits(i
) != ulfont
)
1072 if (trtab
[j
] == ' ') {
1074 setfbits(i
, FT
); /* default */
1078 /* should test here for characters that ought to be underlined */
1079 /* in the old nroff, that was the 200 bit on the width! */
1080 /* for now, just do letters, digits and certain special chars */
1102 *mbbuf2p
++ = i
& BYTEMASK
;
1103 *mtbufp
= *mbbuf2p
= 0;
1111 if ((i
& MBMASK
) == MIDDLEOFMB
) {
1112 if (mtbufp
<= (mtbuf
+ MB_CUR_MAX
)) {
1115 *(mtbufp
- 1) &= ~MBMASK
;
1119 if ((i
& MBMASK
) == LASTOFMB
)
1120 *(mtbufp
- 1) &= ~MBMASK
;
1124 if (mbtowc(&cwc
, mbbuf2
, MB_CUR_MAX
) <= 0) {
1127 setcbits(*mtbufp
, (*mtbufp
& 0x1ff));