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 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
39 #define LC_NAMELEN 255
48 static unsigned int cpl
; /* current characters per line */
49 static unsigned int cplmax
; /* maximum characters per line */
50 static unsigned char codestr
[MB_LEN_MAX
+ 1];
51 static char linebuf
[SCRWID
/ 2 * (MB_LEN_MAX
+ 1)];
52 static int pinline
; /* any printable to be listed in the line? */
53 static int omitting
; /* omitting blank lines under no vflag? */
72 char titlebar
[LC_NAMELEN
+ 14];
74 (void) setlocale(LC_ALL
, "");
75 #if !defined(TEXT_DOMAIN)
76 #define TEXT_DOMAIN "SYS_TEST"
78 (void) textdomain(TEXT_DOMAIN
);
79 lc_ctype
= setlocale(LC_CTYPE
, NULL
);
82 eucw
[1] = eucwidth
._eucw1
;
83 eucw
[2] = eucwidth
._eucw2
;
84 eucw
[3] = eucwidth
._eucw3
;
86 scrw
[1] = eucwidth
._scrw1
;
87 scrw
[2] = eucwidth
._scrw2
;
88 scrw
[3] = eucwidth
._scrw3
;
89 for (i
= 0; i
<= 3; i
++)
91 for (i
= 1; i
< ac
; i
++)
94 while ((c
= getopt(ac
, av
, "0123vw")) != -1) {
110 (void) printf(gettext("usage: %s [-0123vw]\n"), av
[0]);
114 if ((csflag
[0] + csflag
[1] + csflag
[2] + csflag
[3]) == 0) {
115 for (i
= 0; i
<= 3; i
++)
118 (void) strcpy(titlebar
, "");
119 for (i
= strlen(lc_ctype
) + 14; i
; i
--)
120 (void) strcat(titlebar
, ":");
121 for (cs
= 0; cs
<= 3; cs
++) {
122 if (csflag
[cs
] && eucw
[cs
] && scrw
[cs
]) {
123 (void) printf("%s\n", titlebar
);
124 (void) printf("LC_CTYPE:%s", lc_ctype
);
125 (void) printf(" CS:%d\n", cs
);
126 (void) printf("%s", titlebar
);
127 (void) csprint(cs
, (int) eucw
[cs
], (int) scrw
[cs
]);
135 csprint(cs
, bytes
, columns
)
136 int cs
, bytes
, columns
;
138 int col
, i
, position
;
143 col
= SCRWID
- bytes
* 2 - 1;
145 for (i
= columns
+ 1; i
<= col
; i
*= 2) cplmax
*= 2;
156 codestr
[position
++] = SS2
;
160 codestr
[position
++] = SS3
;
163 codestr
[position
] = '\0';
165 (void) strcpy(linebuf
, "");
166 (void) prcode(bytelen
, position
, minvalue
, maxvalue
, columns
);
167 if (pinline
|| vflag
) {
168 (void) printf("\n%s", linebuf
);
169 } else if (!omitting
) {
170 (void) printf("\n*");
177 * prcode() prints series of len-byte codes, of which each byte can
178 * have a code value between min and max, in incremental code order.
181 prcode(len
, pos
, min
, max
, col
)
182 int len
, pos
, min
, max
, col
;
184 int byte
, i
, nextpos
;
185 unsigned long widechar
; /* limitting wchar_t width - not good */
191 for (byte
= min
; byte
<= max
; byte
++) {
192 codestr
[pos
] = (unsigned char) byte
;
194 codestr
[nextpos
] = '\0';
195 (void) prcode(len
, nextpos
, min
, max
, col
);
198 for (byte
= min
; byte
<= max
; byte
++) {
199 codestr
[pos
] = (unsigned char) byte
;
201 codestr
[nextpos
] = '\0';
205 while (codestr
[i
] != '\0') {
206 widechar
= (widechar
<< 8) |
207 (unsigned long) codestr
[i
++];
210 if (pinline
|| vflag
) {
211 (void) printf("\n%s", linebuf
);
213 } else if (!omitting
) {
214 (void) printf("\n*");
219 (void) sprintf(linebuf
, "%lx ",
222 (void) mbtowc(&wc
, (char *) codestr
,
224 (void) sprintf(linebuf
, "%lx ", wc
);
229 if ((mbl
= mbtowc(&wc
, (char *) codestr
,
233 if (!(isprint(codestr
[0]))) prep
= "*";
234 } else if (!(iswprint(wc
)))
236 if (prep
[0] == '*') {
237 (void) strcat(linebuf
, prep
);
238 for (i
= 1; i
<= col
; i
++)
239 (void) strcat(linebuf
, " ");
241 (void) strcat(linebuf
, prep
);
242 (void) strcat(linebuf
, (char *) codestr
);