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 1990 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #if !defined(lint) && defined(SCCSIDS)
30 static char *sccsid
= "%Z%%M% %I% %E% SMI";
34 #include <sys/types.h>
37 #define MASK 0x0000ffff
38 #define TOP1 0x80000000
39 #define TOP2 0x08000000
43 * mbtowc routines for the Xerox XCCS codeset standard
46 _mbtowc_xccs(pwc
, s
, n
)
51 static unsigned int CSselect
= 0;
52 static int CSlength
= 1;
56 * If length is negative, return error
64 if (*s
== 0 && CSlength
== 1)
66 if (*s
== 0 && *(s
+ 1) == 0 && CSlength
== 2)
72 if ((unsigned char)*s
== CS377
) {
78 * Change characteristics
80 if ((unsigned char)*s
== CS377
) {
95 CSselect
= (unsigned int)*s
++;
101 * Get a character and return
109 twchar
= twchar
<< 8;
110 twchar
= twchar
| *s
;
112 *pwc
= twchar
& MASK
;
114 * Encode additional information
130 unsigned char upper
, lower
;
133 printf ("XCCS- xctomb\n");
140 * Get lower and upper anyway
142 lower
= pwc
& 0x00ff;
143 upper
= (pwc
>> 8) & 0x00ff;
144 if (lower
== CS377
|| upper
== CS377
)
146 if (pwc
& TOP1
) { /* length == 2 */
148 * This was the marker.
149 * Emitt 3 additional characters.
159 * This was the marker.
160 * Emitt 2 additional characters.
174 _mbstowcs_xccs(pwc
, s
, n
)
179 static unsigned int CSselect
= 0;
180 static int CSlength
= 1;
185 * If length is negative, return error
193 if (*s
== 0 && CSlength
== 1)
195 if (*s
== 0 && *(s
+ 1) == 0 && CSlength
== 2)
200 * Check for an end of the string
202 if (((*s
== 0 && CSlength
== 1)) ||
203 ((*s
== 0 && *(s
+ 1) == 0 && CSlength
== 2))) {
212 if ((unsigned char)*s
== CS377
) {
215 * Change characterristics
217 if ((unsigned char)*s
== CS377
) {
232 CSselect
= (unsigned int)*s
++;
238 * Get a character and return
246 twchar
= twchar
<< 8;
247 twchar
= twchar
| *s
++;
248 *pwc
= twchar
& MASK
;
263 _wcstombs_xccs(s
, pwc
, n
)
269 unsigned char lower
, upper
;
281 lower
= *pwc
& 0x00ff;
282 upper
= (*pwc
>> 8) & 0x00ff;
296 if (lower
== CS377
|| upper
== CS377
)
298 if (*pwc
& TOP1
) { /* length == 2 */
301 * This was the marker.
302 * Emitt 3 additional characters.
304 *s
++ = CS377
; ++cnt
; --n
;
305 *s
++ = CS377
; ++cnt
; --n
;
306 *s
++ = 0; ++cnt
; --n
;
310 *s
++ = upper
; ++cnt
; --n
;
313 *s
++ = lower
; ++cnt
; --n
;
318 if ((in_1byte
== 0 && in_2byte
== 1) ||
319 (in_1byte
== 1 && upper
!= current
) ||
320 (in_1byte
== 0 && in_2byte
== 0 && upper
!= 0)) {
322 * This was the marker.
323 * Emitt 2 additional characters.
325 *s
++ = CS377
; ++cnt
; --n
;
328 *s
++ = upper
; ++cnt
; --n
;
335 *s
++ = lower
; ++cnt
; --n
;