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 /* lcTxtPr.c 1.1 - Fujitsu source for CDEnext 95/11/06 20:32:41 */
24 /* $XConsortium: _fallcTxtPr.c /main/1 1996/04/08 15:19:12 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"
53 #include <X11/Xatom.h>
57 get_buf_size(is_wide_char, list, count)
63 register char **mb_list;
64 register wchar_t **wc_list;
70 wc_list = (wchar_t **) list;
71 for ( ; count-- > 0; wc_list++) {
73 length += _falwcslen(*wc_list) + 1;
75 length *= 5; /* XXX */
77 mb_list = (char **) list;
78 for ( ; count-- > 0; mb_list++) {
80 length += strlen(*mb_list) + 1;
82 length *= 3; /* XXX */
84 length = (length / BUFSIZ + 1) * BUFSIZ; /* XXX */
90 _XTextListToTextProperty(lcd, dpy, from_type, list, count, style, text_prop)
96 XICCEncodingStyle style;
97 XTextProperty *text_prop;
105 char *to, *buf, *value;
106 int from_left, to_left, buf_len, nitems, unconv_num, ret, i;
107 Bool is_wide_char = False;
109 if (strcmp(XlcNWideChar, from_type) == 0)
112 buf_len = get_buf_size(is_wide_char, list, count);
113 if ((buf = (char *) Xmalloc(buf_len)) == NULL)
118 case XStdICCTextStyle:
119 encoding = XA_STRING;
120 to_type = XlcNString;
122 case XCompoundTextStyle:
123 encoding = falInternAtom(dpy, "COMPOUND_TEXT", False);
124 to_type = XlcNCompoundText;
127 encoding = falInternAtom(dpy, XLC_PUBLIC(lcd, encoding_name), False);
128 to_type = XlcNMultiByte;
129 if (is_wide_char == False) {
131 mb_list = (char **) list;
133 for (i = 0; i < count; i++) {
134 strcpy(to, *mb_list);
135 from_left = strlen(*mb_list) + 1;
146 return XConverterNotFound;
155 conv = _fallcOpenConverter(lcd, from_type, lcd, to_type);
158 return XConverterNotFound;
162 wc_list = (wchar_t **) list;
164 mb_list = (char **) list;
171 for (i = 1; to_left > 0; i++) {
173 from = (XPointer) *wc_list;
174 from_left = _falwcslen(*wc_list);
177 from = (XPointer) *mb_list;
178 from_left = strlen(*mb_list);
182 ret = _fallcConvert(conv, &from, &from_left, (XPointer *) &to, &to_left,
188 if (ret > 0 && style == XStdICCTextStyle && encoding == XA_STRING) {
189 _fallcCloseConverter(conv);
190 encoding = falInternAtom(dpy, "COMPOUND_TEXT", False);
191 to_type = XlcNCompoundText;
202 _fallcResetConverter(conv);
205 _fallcCloseConverter(conv);
211 value = (char *) Xmalloc(nitems);
219 memcpy(value, buf, nitems);
223 text_prop->value = (unsigned char *) value;
224 text_prop->encoding = encoding;
225 text_prop->format = 8;
226 text_prop->nitems = nitems;
232 _falmbTextListToTextProperty(lcd, dpy, list, count, style, text_prop)
237 XICCEncodingStyle style;
238 XTextProperty *text_prop;
240 return _XTextListToTextProperty(lcd, dpy, XlcNMultiByte, (XPointer) list,
241 count, style, text_prop);
245 _falwcTextListToTextProperty(lcd, dpy, list, count, style, text_prop)
250 XICCEncodingStyle style;
251 XTextProperty *text_prop;
253 return _XTextListToTextProperty(lcd, dpy, XlcNWideChar, (XPointer) list,
254 count, style, text_prop);