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) 1988 AT&T */
23 /* All Rights Reserved */
27 * Copyright (c) 1997, by Sun Microsystems, Inc.
28 * All rights reserved.
31 #pragma ident "%Z%%M% %I% %E% SMI"
34 #include <sys/types.h>
35 #include "curses_inc.h"
39 * Translate process code to byte-equivalent
40 * Return the length of the byte-equivalent string
44 * use _curs_wctomb() instead of _code2byte(code, bytes)
49 * Translate a set of byte to a single process code
53 * use _curs_mbtowc() instead of wchar_t _byte2code(bytes)
58 * Translate a string of wchar_t to a byte string.
59 * code: the input code string
60 * byte: if not NULL, space to store the output string
61 * n: maximum number of codes to be translated.
64 *_strcode2byte(wchar_t *code
, char *byte
, int n
)
71 /* compute the length of the code string */
73 for (n
= 0; code
[n
] != 0; ++n
)
76 /* get space to store the translated string */
77 if (!byte
&& (n
*CSMAX
+1) > bufsize
) {
80 bufsize
= n
* CSMAX
+ 1;
81 if ((buf
= malloc(bufsize
* sizeof (char))) == NULL
)
85 /* no space to do it */
89 /* start the translation */
90 bufp
= byte
? byte
: buf
;
92 while (code
< endcode
&& *code
) {
93 bufp
+= _curs_wctomb(bufp
, *code
& TRIM
);
98 return (byte
? byte
: buf
);
104 * Translate a byte-string to a wchar_t string.
107 *_strbyte2code(char *byte
, wchar_t *code
, int n
)
115 for (n
= 0; byte
[n
] != '\0'; ++n
)
118 if (!code
&& (n
+ 1) > bufsize
) {
122 if ((buf
= (wchar_t *)malloc(bufsize
* sizeof (wchar_t))) ==
130 bufp
= code
? code
: buf
;
133 while (byte
< endbyte
&& *byte
) {
137 type
= TYPE(*byte
& 0377);
138 width
= cswidth
[type
];
139 if (type
== 1 || type
== 2)
142 if (byte
+ width
<= endbyte
) {
143 (void) _curs_mbtowc(&wchar
, byte
, width
);
151 return (code
? code
: buf
);