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.
37 #define LC_NAMELEN 255
46 static unsigned int cpl
; /* current characters per line */
47 static unsigned int cplmax
; /* maximum characters per line */
48 static unsigned char codestr
[MB_LEN_MAX
+ 1];
49 static char linebuf
[SCRWID
/ 2 * (MB_LEN_MAX
+ 1)];
50 static int pinline
; /* any printable to be listed in the line? */
51 static int omitting
; /* omitting blank lines under no vflag? */
70 char titlebar
[LC_NAMELEN
+ 14];
72 (void) setlocale(LC_ALL
, "");
73 #if !defined(TEXT_DOMAIN)
74 #define TEXT_DOMAIN "SYS_TEST"
76 (void) textdomain(TEXT_DOMAIN
);
77 lc_ctype
= setlocale(LC_CTYPE
, NULL
);
80 eucw
[1] = eucwidth
._eucw1
;
81 eucw
[2] = eucwidth
._eucw2
;
82 eucw
[3] = eucwidth
._eucw3
;
84 scrw
[1] = eucwidth
._scrw1
;
85 scrw
[2] = eucwidth
._scrw2
;
86 scrw
[3] = eucwidth
._scrw3
;
87 for (i
= 0; i
<= 3; i
++)
89 for (i
= 1; i
< ac
; i
++)
92 while ((c
= getopt(ac
, av
, "0123vw")) != -1) {
108 (void) printf(gettext("usage: %s [-0123vw]\n"), av
[0]);
112 if ((csflag
[0] + csflag
[1] + csflag
[2] + csflag
[3]) == 0) {
113 for (i
= 0; i
<= 3; i
++)
116 (void) strcpy(titlebar
, "");
117 for (i
= strlen(lc_ctype
) + 14; i
; i
--)
118 (void) strcat(titlebar
, ":");
119 for (cs
= 0; cs
<= 3; cs
++) {
120 if (csflag
[cs
] && eucw
[cs
] && scrw
[cs
]) {
121 (void) printf("%s\n", titlebar
);
122 (void) printf("LC_CTYPE:%s", lc_ctype
);
123 (void) printf(" CS:%d\n", cs
);
124 (void) printf("%s", titlebar
);
125 (void) csprint(cs
, (int) eucw
[cs
], (int) scrw
[cs
]);
133 csprint(cs
, bytes
, columns
)
134 int cs
, bytes
, columns
;
136 int col
, i
, position
;
141 col
= SCRWID
- bytes
* 2 - 1;
143 for (i
= columns
+ 1; i
<= col
; i
*= 2) cplmax
*= 2;
154 codestr
[position
++] = SS2
;
158 codestr
[position
++] = SS3
;
161 codestr
[position
] = '\0';
163 (void) strcpy(linebuf
, "");
164 (void) prcode(bytelen
, position
, minvalue
, maxvalue
, columns
);
165 if (pinline
|| vflag
) {
166 (void) printf("\n%s", linebuf
);
167 } else if (!omitting
) {
168 (void) printf("\n*");
175 * prcode() prints series of len-byte codes, of which each byte can
176 * have a code value between min and max, in incremental code order.
179 prcode(len
, pos
, min
, max
, col
)
180 int len
, pos
, min
, max
, col
;
182 int byte
, i
, nextpos
;
183 unsigned long widechar
; /* limitting wchar_t width - not good */
189 for (byte
= min
; byte
<= max
; byte
++) {
190 codestr
[pos
] = (unsigned char) byte
;
192 codestr
[nextpos
] = '\0';
193 (void) prcode(len
, nextpos
, min
, max
, col
);
196 for (byte
= min
; byte
<= max
; byte
++) {
197 codestr
[pos
] = (unsigned char) byte
;
199 codestr
[nextpos
] = '\0';
203 while (codestr
[i
] != '\0') {
204 widechar
= (widechar
<< 8) |
205 (unsigned long) codestr
[i
++];
208 if (pinline
|| vflag
) {
209 (void) printf("\n%s", linebuf
);
211 } else if (!omitting
) {
212 (void) printf("\n*");
217 (void) sprintf(linebuf
, "%lx ",
220 (void) mbtowc(&wc
, (char *) codestr
,
222 (void) sprintf(linebuf
, "%lx ", wc
);
227 if ((mbl
= mbtowc(&wc
, (char *) codestr
,
231 if (!(isprint(codestr
[0]))) prep
= "*";
232 } else if (!(iswprint(wc
)))
234 if (prep
[0] == '*') {
235 (void) strcat(linebuf
, prep
);
236 for (i
= 1; i
<= col
; i
++)
237 (void) strcat(linebuf
, " ");
239 (void) strcat(linebuf
, prep
);
240 (void) strcat(linebuf
, (char *) codestr
);