2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* lcStd.c 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:41 */
24 /* $XConsortium: _fallcStd.c /main/1 1996/04/08 15:19:02 cde-fuj $ */
26 * Copyright 1992, 1993 by TOSHIBA Corp.
28 * Permission to use, copy, modify, and distribute this software and its
29 * documentation for any purpose and without fee is hereby granted, provided
30 * that the above copyright notice appear in all copies and that both that
31 * copyright notice and this permission notice appear in supporting
32 * documentation, and that the name of TOSHIBA not be used in advertising
33 * or publicity pertaining to distribution of the software without specific,
34 * written prior permission. TOSHIBA make no representations about the
35 * suitability of this software for any purpose. It is provided "as is"
36 * without express or implied warranty.
38 * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40 * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
46 * Author: Katsuhisa Yano TOSHIBA Corp.
47 * mopi@osa.ilab.toshiba.co.jp
50 #include "_fallibint.h"
51 #include "_fallcPubI.h"
54 _fallcmbtowc(lcd, wstr, str, len)
60 static XLCd last_lcd = NULL;
61 static XlcConv conv = NULL;
63 int from_left, to_left;
67 lcd = _fallcCurrentLC();
72 return XLC_PUBLIC(lcd, is_state_depend);
74 if (conv && lcd != last_lcd) {
75 _fallcCloseConverter(conv);
82 conv = _fallcOpenConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar);
87 from = (XPointer) str;
89 to = (XPointer) (wstr ? wstr : &tmp_wc);
92 if (_fallcConvert(conv, &from, &from_left, &to, &to_left, NULL, 0) < 0)
95 return (len - from_left);
99 _fallcwctomb(lcd, str, wc)
104 static XLCd last_lcd = NULL;
105 static XlcConv conv = NULL;
107 int from_left, to_left, length;
110 lcd = _fallcCurrentLC();
115 return XLC_PUBLIC(lcd, is_state_depend);
117 if (conv && lcd != last_lcd) {
118 _fallcCloseConverter(conv);
125 conv = _fallcOpenConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte);
130 from = (XPointer) &wc;
133 length = to_left = XLC_PUBLIC(lcd, mb_cur_max);
135 if (_fallcConvert(conv, &from, &from_left, &to, &to_left, NULL, 0) < 0)
138 return (length - to_left);
142 _fallcmbstowcs(lcd, wstr, str, len)
150 int from_left, to_left, ret;
153 lcd = _fallcCurrentLC();
158 conv = _fallcOpenConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar);
162 from = (XPointer) str;
163 from_left = strlen(str);
164 to = (XPointer) wstr;
167 if (_fallcConvert(conv, &from, &from_left, &to, &to_left, NULL, 0) < 0)
171 if (wstr && to_left > 0)
172 wstr[ret] = (wchar_t) 0;
175 _fallcCloseConverter(conv);
181 _fallcwcstombs(lcd, str, wstr, len)
189 int from_left, to_left, ret;
192 lcd = _fallcCurrentLC();
197 conv = _fallcOpenConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte);
201 from = (XPointer) wstr;
202 from_left = _falwcslen(wstr);
206 if (_fallcConvert(conv, &from, &from_left, &to, &to_left, NULL, 0) < 0)
210 if (str && to_left > 0)
214 _fallcCloseConverter(conv);
221 _falmbtowc(wstr, str, len)
226 return _fallcmbtowc((XLCd) NULL, wstr, str, len);
234 return _falmbtowc((wchar_t *) NULL, str, len);
242 return _fallcwctomb((XLCd) NULL, str, wc);
246 _falmbstowcs(wstr, str, len)
251 return _fallcmbstowcs((XLCd) NULL, wstr, str, len);
255 _falwcstombs(str, wstr, len)
260 return _fallcwcstombs((XLCd) NULL, str, wstr, len);
264 _falwcscpy(wstr1, wstr2)
265 register wchar_t *wstr1, *wstr2;
267 wchar_t *wstr_tmp = wstr1;
269 while (*wstr1++ = *wstr2++)
276 _falwcsncpy(wstr1, wstr2, len)
277 register wchar_t *wstr1, *wstr2;
280 wchar_t *wstr_tmp = wstr1;
283 if (!(*wstr1++ = *wstr2++))
287 *wstr1++ = (wchar_t) 0;
294 register wchar_t *wstr;
296 register wchar_t *wstr_ptr = wstr;
301 return wstr_ptr - wstr;
305 _falwcscmp(wstr1, wstr2)
306 register wchar_t *wstr1, *wstr2;
308 for ( ; *wstr1 && *wstr2; wstr1++, wstr2++)
309 if (*wstr1 != *wstr2)
312 return *wstr1 - *wstr2;
316 _falwcsncmp(wstr1, wstr2, len)
317 register wchar_t *wstr1, *wstr2;
320 for ( ; *wstr1 && *wstr2 && len > 0; wstr1++, wstr2++, len--)
321 if (*wstr1 != *wstr2)
327 return *wstr1 - *wstr2;