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 (c) 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
48 static char *severity_names
[MAX_SEVERITY
-MIN_SEVERITY
+1] = {
55 static const char *TOFIX
= "TO FIX";
57 static int wrap(wchar_t *, wchar_t *, int, wchar_t *);
64 fmtmsg(char *label
, int severity
, char *text
, char *action
)
66 int tofix_len
, indent_len
;
67 wchar_t wtofix
[SHORT_S
], wlabel
[SHORT_S
], wsev
[SHORT_S
], wtext
[LONG_S
],
71 * Return if the severity isn't recognized.
73 if (severity
< MIN_SEVERITY
|| MAX_SEVERITY
< severity
)
76 mbstowcs(wtofix
, gettext(TOFIX
), SHORT_S
);
77 mbstowcs(wlabel
, label
, SHORT_S
);
78 mbstowcs(wsev
, gettext(severity_names
[severity
]), SHORT_S
);
79 mbstowcs(wtext
, text
, LONG_S
);
81 tofix_len
= wscol(wtofix
),
82 indent_len
= wscol(wlabel
) + wscol(wsev
) + 2;
83 if (indent_len
< tofix_len
)
84 indent_len
= tofix_len
;
86 if (wrap(wlabel
, wsev
, indent_len
, wtext
) <= 0)
89 if (action
&& *action
) {
90 if (fputc('\n', stderr
) == EOF
)
93 mbstowcs(wtext
, action
, LONG_S
);
94 if (wrap(wtofix
, null
, indent_len
, wtext
) <= 0)
98 if (fputc('\n', stderr
) == EOF
)
105 ** wrap() - PUT OUT "STUFF: string", WRAPPING string AS REQUIRED
109 wrap(wchar_t *prefix
, wchar_t *suffix
, int indent_len
, wchar_t *str
)
113 wchar_t *p
, *pw
, *ppw
;
114 static const wchar_t eol
[] = {L
'\r', L
'\n', L
'\0'};
117 * Display the initial stuff followed by a colon.
119 if ((len
= wscol(suffix
)))
120 n
= fprintf(stderr
, gettext("%*ws: %ws: "),
121 indent_len
- len
- 2, prefix
, suffix
);
123 n
= fprintf(stderr
, gettext("%*ws: "), indent_len
, prefix
);
127 maxlen
= LINE_LEN
- indent_len
- 1;
129 /* Check for bogus indent_len */
135 * Loop once for each line of the string to display.
137 for (p
= str
; *p
; ) {
140 * Display the next "len" bytes of the string, where
141 * "len" is the smallest of:
144 * - # bytes before control character
145 * - # bytes left in string
149 len
= wcscspn(p
, eol
);
150 /* calc how many columns the string will take */
151 col
= wcswidth(p
, len
);
154 * How many characters fit into our desired line length
160 tmpcol
+= wcwidth(*pw
);
167 * At this point, pw may point to:
168 * A null character: EOL found (should never happen, though)
169 * The character that just overruns the maxlen.
174 * This should never happen.
183 * Bugid 4202307 - liblpoam in lp internal library doesn't
184 * handle multibyte character.
188 (wdbindf(*(pw
- 1), *pw
, 1) < 5)) {
198 * Failed to find the best place to fold.
199 * So, prints as much characters as maxlen allows
206 for (n
= 0; n
< len
; n
++, p
++) {
208 if (fputwc(*p
, stderr
) == WEOF
) {
215 * If we displayed up to a control character,
216 * put out the control character now; otherwise,
217 * put out a newline unless we've put out all
221 if (*p
== L
'\r' || *p
== L
'\n') {
222 while (*p
== L
'\r' || *p
== L
'\n') {
223 if (fputwc(*p
, stderr
) == WEOF
)
228 if (fputwc(L
'\n', stderr
) == WEOF
)
236 * If the loop won't end this time (because we
237 * have more stuff to display) put out leading
238 * blanks to align the next line with the previous
242 for (n
= 0; n
< indent_len
+ 2; n
++)
243 (void) fputwc(L
' ', stderr
);