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]
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
27 * Copyright (c) 1997-1999 by Sun Microsystems, Inc.
28 * All rights reserved.
32 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.2 */
34 #include <sys/types.h>
48 puttext(FILE *fp
, char *str
, int lmarg
, int rmarg
)
51 wchar_t *copy
, *lastword
, *lastend
, temp
[MWIDTH
+1];
53 int width
, i
, n
, force
, wordcnt
;
56 char mbtemp
[(MWIDTH
+1) * MB_LEN_MAX
];
58 width
= rmarg
? (rmarg
- lmarg
) : (WIDTH
- lmarg
);
66 wstr
= (wchar_t *)malloc(sizeof (wchar_t) * (len
+ 1));
70 ret
= mbstowcs(wstr
, (const char *)str
, len
+ 1);
71 if (ret
== (size_t)-1) {
81 for (i
= 0; i
< lmarg
; i
++)
85 ++wp
; /* eat leading white space */
97 (void) putc('\n', fp
);
98 for (i
= 0; i
< lmarg
; i
++)
105 * Using putc instead of fputwc here to avoid
106 * mixing up the byte stream and the wide stream
109 mlen
= wctomb(mbs
, *wp
);
113 * nothing will be outputted
117 for (i
= 0; i
< mlen
; i
++)
118 (void) putc(mbs
[i
], fp
);
121 * if wlen is a negative value (*wp is not printable),
122 * add 1 to n. (non-printable char shares 1 column.
133 /* eat multiple tabs/nl after whitespace */
134 while ((*++wp
== L
'\t') || (*wp
== '\n'));
140 } else if (*wp
== L
'\\') {
141 if (*(wp
+ 1) == L
'n') {
147 } else if (*(wp
+ 1) == L
't') {
156 } else if (*(wp
+ 1) == L
' ') {
161 if (iswprint(*wp
) && iswprint(*(wp
+ 1))) {
163 * Only if both *wp and *(wp +1) are printable,
164 * tries to check the binding weight between them.
167 if (n
+ wlen
> width
) {
169 * if (n + wlen) is larger than width, *wp will be
170 * put to the next line.
182 * binding weight between *wp and *(wp + 1) is
183 * enough small to fold the line there.
196 if (n
+ wlen
> width
) {
198 * if (n + wlen) is larger than width, *wp will
199 * be put to the next line.
209 * *wp is not printable, and shares 1 column.
217 if (iswprint(*wp
) && iswprint(*(wp
+ 1))) {
219 * Only if both *wp and *(wp + 1) are printable,
220 * tries to check the binding weight between them.
223 if (n
+ wlen
> width
) {
225 * if (n + wlen) is larger than width, *wp will be
226 * put to the next line.
233 bdg
= wdbindf(*wp
, *(wp
+ 1), 1);
237 * binding weight between *wp and *(wp + 1) is
238 * enough small to fold the line there.
250 if (n
+ wlen
> width
) {
252 * if (n + wlen) is larger than width, *wp will
253 * be put to the next line.
263 * *wp is not printable, and shares 1 column.
277 for (i
= 0; i
< lmarg
; i
++)
278 (void) putc(' ', fp
);
279 mlen
= wcstombs(mbtemp
, temp
, MWIDTH
+1);
280 for (i
= 0; i
< mlen
; i
++)
281 (void) putc(mbtemp
[i
], fp
);
282 (void) putc('\n', fp
);
292 while (iswspace(*wp
))
296 } while (*wp
!= L
'\0');
299 for (i
= 0; i
< lmarg
; i
++)
300 (void) putc(' ', fp
);
301 mlen
= wcstombs(mbtemp
, temp
, MWIDTH
+1);
302 for (i
= 0; i
< mlen
; i
++)
303 (void) putc(mbtemp
[i
], fp
);
306 return (width
- n
- !force
);