aboutsummaryrefslogtreecommitdiff
path: root/libX11
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-04-27 15:56:59 +0000
committermarha <marha@users.sourceforge.net>2011-04-27 15:56:59 +0000
commit100633b3e7619842f345cb7603b0db6b5761dd11 (patch)
tree3c3af754c7e801c07263269837d6a05072ff834c /libX11
parent205a4bdae76f287126db9f45a4f0ba631e3efca1 (diff)
parent96d6df5da9cddedf4931bf8e17f96e242467c661 (diff)
downloadvcxsrv-100633b3e7619842f345cb7603b0db6b5761dd11.tar.gz
vcxsrv-100633b3e7619842f345cb7603b0db6b5761dd11.tar.bz2
vcxsrv-100633b3e7619842f345cb7603b0db6b5761dd11.zip
svn merge ^/branches/released .
Diffstat (limited to 'libX11')
-rw-r--r--libX11/modules/im/ximcp/imDefIc.c3
-rw-r--r--libX11/modules/im/ximcp/imInt.c529
-rw-r--r--libX11/modules/im/ximcp/imLcIc.c3
-rw-r--r--libX11/modules/im/ximcp/imRm.c6405
-rw-r--r--libX11/modules/im/ximcp/imRmAttr.c15
-rw-r--r--libX11/modules/im/ximcp/imThaiIc.c455
-rw-r--r--libX11/modules/im/ximcp/imTrX.c1037
-rw-r--r--libX11/modules/im/ximcp/imTrans.c7
-rw-r--r--libX11/modules/lc/gen/lcGenConv.c6297
-rw-r--r--libX11/modules/lc/xlocale/lcJis.c1889
-rw-r--r--libX11/modules/om/generic/omGeneric.c59
-rw-r--r--libX11/specs/libX11/CH02.xml17
-rw-r--r--libX11/src/FSWrap.c3
-rw-r--r--libX11/src/InitExt.c819
-rw-r--r--libX11/src/Quarks.c827
-rw-r--r--libX11/src/SetLocale.c507
-rw-r--r--libX11/src/Xrm.c6
-rw-r--r--libX11/src/xcms/PrOfId.c201
-rw-r--r--libX11/src/xkb/XKBGAlloc.c13
-rw-r--r--libX11/src/xlibi18n/XDefaultIMIF.c6
-rw-r--r--libX11/src/xlibi18n/XDefaultOMIF.c2539
-rw-r--r--libX11/src/xlibi18n/XlcDL.c40
-rw-r--r--libX11/src/xlibi18n/lcCharSet.c451
-rw-r--r--libX11/src/xlibi18n/lcDB.c2688
-rw-r--r--libX11/src/xlibi18n/lcFile.c1664
-rw-r--r--libX11/src/xlibi18n/lcGeneric.c2371
-rw-r--r--libX11/src/xlibi18n/lcPublic.c631
27 files changed, 14661 insertions, 14821 deletions
diff --git a/libX11/modules/im/ximcp/imDefIc.c b/libX11/modules/im/ximcp/imDefIc.c
index 27e04e11c..cd3ed5854 100644
--- a/libX11/modules/im/ximcp/imDefIc.c
+++ b/libX11/modules/im/ximcp/imDefIc.c
@@ -1425,10 +1425,9 @@ _XimProtoCreateIC(
if (!(_XimGetInputStyle(arg, &input_style)))
return (XIC)NULL;
- if ((ic = (Xic)Xmalloc(sizeof(XicRec))) == (Xic)NULL)
+ if ((ic = Xcalloc(1, sizeof(XicRec))) == (Xic)NULL)
return (XIC)NULL;
- bzero((char *)ic, sizeof(XicRec));
ic->methods = &ic_methods;
ic->core.im = (XIM)im;
ic->core.input_style = input_style;
diff --git a/libX11/modules/im/ximcp/imInt.c b/libX11/modules/im/ximcp/imInt.c
index b19809237..f4ce9cea0 100644
--- a/libX11/modules/im/ximcp/imInt.c
+++ b/libX11/modules/im/ximcp/imInt.c
@@ -1,266 +1,263 @@
-/******************************************************************
-
- Copyright 1992, 1993, 1994 by FUJITSU LIMITED
-
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of FUJITSU LIMITED
-not be used in advertising or publicity pertaining to distribution
-of the software without specific, written prior permission.
-FUJITSU LIMITED makes no representations about the suitability of
-this software for any purpose.
-It is provided "as is" without express or implied warranty.
-
-FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
-EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
-CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
-USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
-
- Author: Takashi Fujiwara FUJITSU LIMITED
- fujiwara@a80.tech.yk.fujitsu.co.jp
-
-******************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/Xatom.h>
-#include <X11/Xlib.h>
-#include <X11/Xmd.h>
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "Ximint.h"
-#include "XimImSw.h"
-
-Private Xim *_XimCurrentIMlist = (Xim *)NULL;
-Private int _XimCurrentIMcount = 0;
-
-Private Bool
-_XimSetIMStructureList(
- Xim im)
-{
- register int i;
- Xim *xim;
-
- if(!(_XimCurrentIMlist)) {
- if(!(_XimCurrentIMlist = (Xim *)Xmalloc(sizeof(Xim))))
- return False;
- _XimCurrentIMlist[0] = im;
- _XimCurrentIMcount = 1;
- }
- else {
- for(i = 0; i < _XimCurrentIMcount; i++) {
- if(!( _XimCurrentIMlist[i])) {
- _XimCurrentIMlist[i] = im;
- break;
- }
- }
- if(i >= _XimCurrentIMcount) {
- if(!(xim = (Xim *)Xrealloc(_XimCurrentIMlist,
- ((i + 1) * sizeof(Xim)))))
- return False;
- _XimCurrentIMlist = xim;
- _XimCurrentIMlist[_XimCurrentIMcount] = im;
- _XimCurrentIMcount++;
- }
- }
- return True;
-}
-
-Public void
-_XimDestroyIMStructureList(Xim im)
-{
- register int i;
-
- for(i = 0; i < _XimCurrentIMcount; i++) {
- if(_XimCurrentIMlist[i] == im) {
- _XimCurrentIMlist[i] = NULL;
- break;
- }
- }
- return;
-}
-
-Public void
-_XimServerDestroy(Xim im_2_destroy)
-{
- register int i;
- Xim im;
- XIC ic;
-
- for(i = 0; i < _XimCurrentIMcount; i++) {
- if(!(im = _XimCurrentIMlist[i]))
- continue;
- /*
- * Only continue if this im is the one to be destroyed.
- */
- if (im != im_2_destroy)
- continue;
-
- if (im->core.destroy_callback.callback)
- (*im->core.destroy_callback.callback)((XIM)im,
- im->core.destroy_callback.client_data, NULL);
- for (ic = im->core.ic_chain; ic; ic = ic->core.next) {
- if (ic->core.destroy_callback.callback) {
- (*ic->core.destroy_callback.callback)(ic,
- ic->core.destroy_callback.client_data, NULL);
- }
- }
- _XimResetIMInstantiateCallback( im );
- (void)im->methods->close((XIM)im);
- Xfree(im);
- _XimCurrentIMlist[i] = NULL;
- return;
- }
-}
-
-#ifdef XIM_CONNECTABLE
-Public void
-_XimServerReconectableDestroy(void)
-{
- register int i;
- Xim im;
- XIC ic;
-
- for(i = 0; i < _XimCurrentIMcount; i++) {
- if(!(im = _XimCurrentIMlist[i]))
- continue;
-
- if (im->core.destroy_callback.callback)
- (*im->core.destroy_callback.callback)(im,
- im->core.destroy_callback.client_data, NULL);
- for (ic = im->core.ic_chain; ic; ic = ic->core.next) {
- if (ic->core.destroy_callback.callback) {
- (*ic->core.destroy_callback.callback)(ic,
- ic->core.destroy_callback.client_data, NULL);
- }
- }
- _XimResetIMInstantiateCallback( im );
- (void)im->methods->close((XIM)im);
- }
- return;
-}
-#endif /* XIM_CONNECTABLE */
-
-Private const char *
-_XimStrstr(
- register const char *src,
- register const char *dest)
-{
- int len;
-
- len = strlen(dest);
- while((src = strchr(src, *dest))) {
- if(!strncmp(src, dest, len))
- return src;
- src++;
- }
- return NULL;
-}
-
-Private char *
-_XimMakeImName(
- XLCd lcd)
-{
- const char* begin = NULL;
- const char* end = NULL;
- char* ret = NULL;
- const char* ximmodifier = XIMMODIFIER;
-
- if(lcd->core->modifiers != NULL && *lcd->core->modifiers != '\0') {
- begin = _XimStrstr(lcd->core->modifiers, ximmodifier);
- if (begin != NULL) {
- end = begin += strlen(ximmodifier);
- while (*end && *end != '@')
- end++;
- }
- }
- ret = Xmalloc(end - begin + 1);
- if (ret != NULL) {
- if (begin != NULL && end != NULL) {
- (void)strncpy(ret, begin, end - begin);
- ret[end - begin] = '\0';
- } else {
- ret[0] = '\0';
- }
- }
-
- return ret;
-}
-
-Public XIM
-_XimOpenIM(
- XLCd lcd,
- Display *dpy,
- XrmDatabase rdb,
- char *res_name,
- char *res_class)
-{
- Xim im;
- register int i;
-
- if (!(im = (Xim)Xmalloc(sizeof(XimRec))))
- return (XIM)NULL;
- bzero(im, sizeof(XimRec));
-
- im->core.lcd = lcd;
- im->core.ic_chain = (XIC)NULL;
- im->core.display = dpy;
- im->core.rdb = rdb;
- im->core.res_name = NULL;
- im->core.res_class = NULL;
- if((res_name != NULL) && (*res_name != '\0')){
- if(!(im->core.res_name = (char *)Xmalloc(strlen(res_name)+1)))
- goto Error1;
- strcpy(im->core.res_name,res_name);
- }
- if((res_class != NULL) && (*res_class != '\0')){
- if(!(im->core.res_class = (char *)Xmalloc(strlen(res_class)+1)))
- goto Error2;
- strcpy(im->core.res_class,res_class);
- }
- if(!(im->core.im_name = _XimMakeImName(lcd)))
- goto Error3;
-
- for(i= 0; ; i++) {
- if(_XimImSportRec[i].checkprocessing(im)) {
- if(!(_XimImSportRec[i].im_open(im)))
- goto Error4;
- if(!_XimSetIMStructureList(im))
- goto Error4;
- return (XIM)im;
- }
- }
-
-Error4 :
- _XimImSportRec[i].im_free(im);
- Xfree(im);
- return NULL;
-Error3 :
- if(im->core.im_name)
- Xfree(im->core.im_name);
-Error2:
- if(im->core.res_class)
- Xfree(im->core.res_class);
-Error1:
- if(im->core.res_name)
- Xfree(im->core.res_name);
- Xfree(im);
- return NULL;
-}
-
-Public Bool
-_XInitIM(XLCd lcd)
-{
- if(lcd == (XLCd)NULL)
- return False;
- lcd->methods->open_im = _XimOpenIM;
- lcd->methods->register_callback = _XimRegisterIMInstantiateCallback;
- lcd->methods->unregister_callback = _XimUnRegisterIMInstantiateCallback;
- return True;
-}
+/******************************************************************
+
+ Copyright 1992, 1993, 1994 by FUJITSU LIMITED
+
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of FUJITSU LIMITED
+not be used in advertising or publicity pertaining to distribution
+of the software without specific, written prior permission.
+FUJITSU LIMITED makes no representations about the suitability of
+this software for any purpose.
+It is provided "as is" without express or implied warranty.
+
+FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+ Author: Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+
+******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xatom.h>
+#include <X11/Xlib.h>
+#include <X11/Xmd.h>
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "Ximint.h"
+#include "XimImSw.h"
+
+Private Xim *_XimCurrentIMlist = (Xim *)NULL;
+Private int _XimCurrentIMcount = 0;
+
+Private Bool
+_XimSetIMStructureList(
+ Xim im)
+{
+ register int i;
+ Xim *xim;
+
+ if(!(_XimCurrentIMlist)) {
+ if(!(_XimCurrentIMlist = (Xim *)Xmalloc(sizeof(Xim))))
+ return False;
+ _XimCurrentIMlist[0] = im;
+ _XimCurrentIMcount = 1;
+ }
+ else {
+ for(i = 0; i < _XimCurrentIMcount; i++) {
+ if(!( _XimCurrentIMlist[i])) {
+ _XimCurrentIMlist[i] = im;
+ break;
+ }
+ }
+ if(i >= _XimCurrentIMcount) {
+ if(!(xim = (Xim *)Xrealloc(_XimCurrentIMlist,
+ ((i + 1) * sizeof(Xim)))))
+ return False;
+ _XimCurrentIMlist = xim;
+ _XimCurrentIMlist[_XimCurrentIMcount] = im;
+ _XimCurrentIMcount++;
+ }
+ }
+ return True;
+}
+
+Public void
+_XimDestroyIMStructureList(Xim im)
+{
+ register int i;
+
+ for(i = 0; i < _XimCurrentIMcount; i++) {
+ if(_XimCurrentIMlist[i] == im) {
+ _XimCurrentIMlist[i] = NULL;
+ break;
+ }
+ }
+ return;
+}
+
+Public void
+_XimServerDestroy(Xim im_2_destroy)
+{
+ register int i;
+ Xim im;
+ XIC ic;
+
+ for(i = 0; i < _XimCurrentIMcount; i++) {
+ if(!(im = _XimCurrentIMlist[i]))
+ continue;
+ /*
+ * Only continue if this im is the one to be destroyed.
+ */
+ if (im != im_2_destroy)
+ continue;
+
+ if (im->core.destroy_callback.callback)
+ (*im->core.destroy_callback.callback)((XIM)im,
+ im->core.destroy_callback.client_data, NULL);
+ for (ic = im->core.ic_chain; ic; ic = ic->core.next) {
+ if (ic->core.destroy_callback.callback) {
+ (*ic->core.destroy_callback.callback)(ic,
+ ic->core.destroy_callback.client_data, NULL);
+ }
+ }
+ _XimResetIMInstantiateCallback( im );
+ (void)im->methods->close((XIM)im);
+ Xfree(im);
+ _XimCurrentIMlist[i] = NULL;
+ return;
+ }
+}
+
+#ifdef XIM_CONNECTABLE
+Public void
+_XimServerReconectableDestroy(void)
+{
+ register int i;
+ Xim im;
+ XIC ic;
+
+ for(i = 0; i < _XimCurrentIMcount; i++) {
+ if(!(im = _XimCurrentIMlist[i]))
+ continue;
+
+ if (im->core.destroy_callback.callback)
+ (*im->core.destroy_callback.callback)(im,
+ im->core.destroy_callback.client_data, NULL);
+ for (ic = im->core.ic_chain; ic; ic = ic->core.next) {
+ if (ic->core.destroy_callback.callback) {
+ (*ic->core.destroy_callback.callback)(ic,
+ ic->core.destroy_callback.client_data, NULL);
+ }
+ }
+ _XimResetIMInstantiateCallback( im );
+ (void)im->methods->close((XIM)im);
+ }
+ return;
+}
+#endif /* XIM_CONNECTABLE */
+
+Private const char *
+_XimStrstr(
+ register const char *src,
+ register const char *dest)
+{
+ int len;
+
+ len = strlen(dest);
+ while((src = strchr(src, *dest))) {
+ if(!strncmp(src, dest, len))
+ return src;
+ src++;
+ }
+ return NULL;
+}
+
+Private char *
+_XimMakeImName(
+ XLCd lcd)
+{
+ const char* begin = NULL;
+ const char* end = NULL;
+ char* ret = NULL;
+ const char* ximmodifier = XIMMODIFIER;
+
+ if(lcd->core->modifiers != NULL && *lcd->core->modifiers != '\0') {
+ begin = _XimStrstr(lcd->core->modifiers, ximmodifier);
+ if (begin != NULL) {
+ end = begin += strlen(ximmodifier);
+ while (*end && *end != '@')
+ end++;
+ }
+ }
+ ret = Xmalloc(end - begin + 1);
+ if (ret != NULL) {
+ if (begin != NULL && end != NULL) {
+ (void)strncpy(ret, begin, end - begin);
+ ret[end - begin] = '\0';
+ } else {
+ ret[0] = '\0';
+ }
+ }
+
+ return ret;
+}
+
+Public XIM
+_XimOpenIM(
+ XLCd lcd,
+ Display *dpy,
+ XrmDatabase rdb,
+ char *res_name,
+ char *res_class)
+{
+ Xim im;
+ register int i;
+
+ if (!(im = Xcalloc(1, sizeof(XimRec))))
+ return (XIM)NULL;
+
+ im->core.lcd = lcd;
+ im->core.ic_chain = (XIC)NULL;
+ im->core.display = dpy;
+ im->core.rdb = rdb;
+ im->core.res_name = NULL;
+ im->core.res_class = NULL;
+ if((res_name != NULL) && (*res_name != '\0')){
+ if(!(im->core.res_name = strdup(res_name)))
+ goto Error1;
+ }
+ if((res_class != NULL) && (*res_class != '\0')){
+ if(!(im->core.res_class = strdup(res_class)))
+ goto Error2;
+ }
+ if(!(im->core.im_name = _XimMakeImName(lcd)))
+ goto Error3;
+
+ for(i= 0; ; i++) {
+ if(_XimImSportRec[i].checkprocessing(im)) {
+ if(!(_XimImSportRec[i].im_open(im)))
+ goto Error4;
+ if(!_XimSetIMStructureList(im))
+ goto Error4;
+ return (XIM)im;
+ }
+ }
+
+Error4 :
+ _XimImSportRec[i].im_free(im);
+ Xfree(im);
+ return NULL;
+Error3 :
+ if(im->core.im_name)
+ Xfree(im->core.im_name);
+Error2:
+ if(im->core.res_class)
+ Xfree(im->core.res_class);
+Error1:
+ if(im->core.res_name)
+ Xfree(im->core.res_name);
+ Xfree(im);
+ return NULL;
+}
+
+Public Bool
+_XInitIM(XLCd lcd)
+{
+ if(lcd == (XLCd)NULL)
+ return False;
+ lcd->methods->open_im = _XimOpenIM;
+ lcd->methods->register_callback = _XimRegisterIMInstantiateCallback;
+ lcd->methods->unregister_callback = _XimUnRegisterIMInstantiateCallback;
+ return True;
+}
diff --git a/libX11/modules/im/ximcp/imLcIc.c b/libX11/modules/im/ximcp/imLcIc.c
index 04de3c1bd..5cdd7d59d 100644
--- a/libX11/modules/im/ximcp/imLcIc.c
+++ b/libX11/modules/im/ximcp/imLcIc.c
@@ -143,10 +143,9 @@ _XimLocalCreateIC(
unsigned int num;
int len;
- if((ic = (Xic)Xmalloc(sizeof(XicRec))) == (Xic)NULL) {
+ if((ic = Xcalloc(1, sizeof(XicRec))) == (Xic)NULL) {
return ((XIC)NULL);
}
- bzero((char *)ic, sizeof(XicRec));
ic->methods = &Local_ic_methods;
ic->core.im = im;
diff --git a/libX11/modules/im/ximcp/imRm.c b/libX11/modules/im/ximcp/imRm.c
index 3d09b8136..a20c23787 100644
--- a/libX11/modules/im/ximcp/imRm.c
+++ b/libX11/modules/im/ximcp/imRm.c
@@ -1,3209 +1,3196 @@
-/******************************************************************
-
- Copyright 1990, 1991, 1992,1993, 1994 by FUJITSU LIMITED
- Copyright 1994 by Sony Corporation
-
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of FUJITSU LIMITED
-and Sony Corporation not be used in advertising or publicity
-pertaining to distribution of the software without specific,
-written prior permission. FUJITSU LIMITED and Sony Corporation make
-no representations about the suitability of this software for any
-purpose. It is provided "as is" without express or implied warranty.
-
-FUJITSU LIMITED AND SONY CORPORATION DISCLAIM ALL WARRANTIES WITH
-REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJITSU LIMITED AND
-SONY CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
-DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
-PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
-TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
-
- Author: Takashi Fujiwara FUJITSU LIMITED
- fujiwara@a80.tech.yk.fujitsu.co.jp
- Modifier: Makoto Wakamatsu Sony Corporation
- makoto@sm.sony.co.jp
-
-******************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include <X11/Xlib.h>
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "Ximint.h"
-#include "Xresource.h"
-
-#define GET_NAME(x) name_table + x.name_offset
-
-typedef struct _XimValueOffsetInfo {
- unsigned short name_offset;
- XrmQuark quark;
- unsigned int offset;
- Bool (*defaults)(
- struct _XimValueOffsetInfo *, XPointer, XPointer, unsigned long
- );
- Bool (*encode)(
- struct _XimValueOffsetInfo *, XPointer, XPointer
- );
- Bool (*decode)(
- struct _XimValueOffsetInfo *, XPointer, XPointer
- );
-} XimValueOffsetInfoRec, *XimValueOffsetInfo;
-
-#ifdef XIM_CONNECTABLE
-Private Bool
-_XimCheckBool(str)
- char *str;
-{
- if(!strcmp(str, "True") || !strcmp(str, "true") ||
- !strcmp(str, "Yes") || !strcmp(str, "yes") ||
- !strcmp(str, "ON") || !strcmp(str, "on"))
- return True;
- return False;
-}
-
-Public void
-_XimSetProtoResource(im)
- Xim im;
-{
- char res_name_buf[256];
- char* res_name;
- char res_class_buf[256];
- char* res_class;
- char* str_type;
- XrmValue value;
- XIMStyle preedit_style = 0;
- XIMStyle status_style = 0;
- XIMStyles* imstyles;
- char* dotximdot = ".xim.";
- char* ximdot = "xim.";
- char* dotXimdot = ".Xim.";
- char* Ximdot = "Xim.";
-
- if (!im->core.rdb)
- return;
-
- if (strlen (im->core.res_name) < 200) res_name = res_name_buf;
- else res_name = Xmalloc (strlen (im->core.res_name) + 50);
- if (strlen (im->core.res_class) < 200) res_class = res_class_buf;
- else res_class = Xmalloc (strlen (im->core.res_class) + 50);
- /* pretend malloc always works */
-
- (void) sprintf (res_name, "%s%s%s",
- im->core.res_name != NULL ? im->core.res_name : "*",
- im->core.res_name != NULL ? dotximdot : ximdot,
- "useAuth");
- (void) sprintf (res_class, "%s%s%s",
- im->core.res_class != NULL ? im->core.res_class : "*",
- im->core.res_class != NULL ? dotXimdot : Ximdot,
- "UseAuth");
- bzero(&value, sizeof(XrmValue));
- if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
- if(_XimCheckBool(value.addr)) {
- MARK_USE_AUTHORIZATION_FUNC(im);
- }
- }
-
- (void) sprintf (res_name, "%s%s%s",
- im->core.res_name != NULL ? im->core.res_name : "*",
- im->core.res_name != NULL ? dotximdot : ximdot,
- "delaybinding");
- (void) sprintf (res_class, "%s%s%s",
- im->core.res_class != NULL ? im->core.res_class : "*",
- im->core.res_class != NULL ? dotXimdot : Ximdot,
- "Delaybinding");
- bzero(&value, sizeof(XrmValue));
- if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
- if(_XimCheckBool(value.addr)) {
- MARK_DELAYBINDABLE(im);
- }
- }
-
- (void) sprintf (res_name, "%s%s%s",
- im->core.res_name != NULL ? im->core.res_name : "*",
- im->core.res_name != NULL ? dotximdot : ximdot,
- "reconnect");
- (void) sprintf (res_class, "%s%s%s",
- im->core.res_class != NULL ? im->core.res_class : "*",
- im->core.res_class != NULL ? dotXimdot : Ximdot,
- "Reconnect");
- bzero(&value, sizeof(XrmValue));
- if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
- if(_XimCheckBool(value.addr)) {
- MARK_RECONNECTABLE(im);
- }
- }
-
- if(!IS_CONNECTABLE(im)) {
- if (res_name != res_name_buf) Xfree (res_name);
- if (res_class != res_class_buf) Xfree (res_class);
- return;
- }
-
- (void) sprintf (res_name, "%s%s%s",
- im->core.res_name != NULL ? im->core.res_name : "*",
- im->core.res_name != NULL ? dotximdot : ximdot,
- "preeditDefaultStyle");
- (void) sprintf (res_class, "%s%s%s",
- im->core.res_class != NULL ? im->core.res_class : "*",
- im->core.res_class != NULL ? dotXimdot : Ximdot,
- "PreeditDefaultStyle");
- if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
- if(!strcmp(value.addr, "XIMPreeditArea"))
- preedit_style = XIMPreeditArea;
- else if(!strcmp(value.addr, "XIMPreeditCallbacks"))
- preedit_style = XIMPreeditCallbacks;
- else if(!strcmp(value.addr, "XIMPreeditPosition"))
- preedit_style = XIMPreeditPosition;
- else if(!strcmp(value.addr, "XIMPreeditNothing"))
- preedit_style = XIMPreeditNothing;
- else if(!strcmp(value.addr, "XIMPreeditNone"))
- preedit_style = XIMPreeditNone;
- }
- if(!preedit_style)
- preedit_style = XIMPreeditNothing;
-
- (void) sprintf (res_name, "%s%s%s",
- im->core.res_name != NULL ? im->core.res_name : "*",
- im->core.res_name != NULL ? dotximdot : ximdot,
- "statusDefaultStyle");
- (void) sprintf (res_class, "%s%s%s",
- im->core.res_class != NULL ? im->core.res_class : "*",
- im->core.res_class != NULL ? dotXimdot : Ximdot,
- "StatusDefaultStyle");
- if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
- if(!strcmp(value.addr, "XIMStatusArea"))
- status_style = XIMStatusArea;
- else if(!strcmp(value.addr, "XIMStatusCallbacks"))
- status_style = XIMStatusCallbacks;
- else if(!strcmp(value.addr, "XIMStatusNothing"))
- status_style = XIMStatusNothing;
- else if(!strcmp(value.addr, "XIMStatusNone"))
- status_style = XIMStatusNone;
- }
- if(!status_style)
- status_style = XIMStatusNothing;
-
- if(!(imstyles = (XIMStyles *)Xmalloc(sizeof(XIMStyles) + sizeof(XIMStyle)))){
- if (res_name != res_name_buf) Xfree (res_name);
- if (res_class != res_class_buf) Xfree (res_class);
- return;
- }
- imstyles->count_styles = 1;
- imstyles->supported_styles =
- (XIMStyle *)((char *)imstyles + sizeof(XIMStyles));
- imstyles->supported_styles[0] = preedit_style | status_style;
- im->private.proto.default_styles = imstyles;
- if (res_name != res_name_buf) Xfree (res_name);
- if (res_class != res_class_buf) Xfree (res_class);
-}
-#endif /* XIM_CONNECTABLE */
-
-static const char name_table[] =
- /* 0 */ XNQueryInputStyle"\0"
- /* 16 */ XNClientWindow"\0"
- /* 29 */ XNInputStyle"\0"
- /* 40 */ XNFocusWindow"\0"
- /* 52 */ XNResourceName"\0"
- /* 65 */ XNResourceClass"\0"
- /* 79 */ XNGeometryCallback"\0"
- /* 96 */ XNDestroyCallback"\0"
- /* 112 */ XNFilterEvents"\0"
- /* 125 */ XNPreeditStartCallback"\0"
- /* 146 */ XNPreeditDoneCallback"\0"
- /* 166 */ XNPreeditDrawCallback"\0"
- /* 186 */ XNPreeditCaretCallback"\0"
- /* 207 */ XNPreeditStateNotifyCallback"\0"
- /* 234 */ XNPreeditAttributes"\0"
- /* 252 */ XNStatusStartCallback"\0"
- /* 272 */ XNStatusDoneCallback"\0"
- /* 291 */ XNStatusDrawCallback"\0"
- /* 310 */ XNStatusAttributes"\0"
- /* 327 */ XNArea"\0"
- /* 332 */ XNAreaNeeded"\0"
- /* 343 */ XNSpotLocation"\0"
- /* 356 */ XNColormap"\0"
- /* 365 */ XNStdColormap"\0"
- /* 377 */ XNForeground"\0"
- /* 388 */ XNBackground"\0"
- /* 399 */ XNBackgroundPixmap"\0"
- /* 416 */ XNFontSet"\0"
- /* 424 */ XNLineSpace"\0"
- /* 434 */ XNCursor"\0"
- /* 441 */ XNQueryIMValuesList"\0"
- /* 459 */ XNQueryICValuesList"\0"
- /* 477 */ XNVisiblePosition"\0"
- /* 493 */ XNStringConversionCallback"\0"
- /* 518 */ XNStringConversion"\0"
- /* 535 */ XNResetState"\0"
- /* 546 */ XNHotKey"\0"
- /* 553 */ XNHotKeyState"\0"
- /* 565 */ XNPreeditState
-;
-
-#define OFFSET_XNQUERYINPUTSTYLE 0
-#define OFFSET_XNCLIENTWINDOW 16
-#define OFFSET_XNINPUTSTYLE 29
-#define OFFSET_XNFOCUSWINDOW 40
-#define OFFSET_XNRESOURCENAME 52
-#define OFFSET_XNRESOURCECLASS 65
-#define OFFSET_XNGEOMETRYCALLBACK 79
-#define OFFSET_XNDESTROYCALLBACK 96
-#define OFFSET_XNFILTEREVENTS 112
-#define OFFSET_XNPREEDITSTARTCALLBACK 125
-#define OFFSET_XNPREEDITDONECALLBACK 146
-#define OFFSET_XNPREEDITDRAWCALLBACK 166
-#define OFFSET_XNPREEDITCARETCALLBACK 186
-#define OFFSET_XNPREEDITSTATENOTIFYCALLBACK 207
-#define OFFSET_XNPREEDITATTRIBUTES 234
-#define OFFSET_XNSTATUSSTARTCALLBACK 252
-#define OFFSET_XNSTATUSDONECALLBACK 272
-#define OFFSET_XNSTATUSDRAWCALLBACK 291
-#define OFFSET_XNSTATUSATTRIBUTES 310
-#define OFFSET_XNAREA 327
-#define OFFSET_XNAREANEEDED 332
-#define OFFSET_XNSPOTLOCATION 343
-#define OFFSET_XNCOLORMAP 356
-#define OFFSET_XNSTDCOLORMAP 365
-#define OFFSET_XNFOREGROUND 377
-#define OFFSET_XNBACKGROUND 388
-#define OFFSET_XNBACKGROUNDPIXMAP 399
-#define OFFSET_XNFONTSET 416
-#define OFFSET_XNLINESPACE 424
-#define OFFSET_XNCURSOR 434
-#define OFFSET_XNQUERYIMVALUESLIST 441
-#define OFFSET_XNQUERYICVALUESLIST 459
-#define OFFSET_XNVISIBLEPOSITION 477
-#define OFFSET_XNSTRINGCONVERSIONCALLBACK 493
-#define OFFSET_XNSTRINGCONVERSION 518
-#define OFFSET_XNRESETSTATE 535
-#define OFFSET_XNHOTKEY 546
-#define OFFSET_XNHOTKEYSTATE 553
-#define OFFSET_XNPREEDITSTATE 565
-
-/* offsets into name_table */
-static const unsigned short supported_local_im_values_list[] = {
- OFFSET_XNQUERYINPUTSTYLE,
- OFFSET_XNRESOURCENAME,
- OFFSET_XNRESOURCECLASS,
- OFFSET_XNDESTROYCALLBACK,
- OFFSET_XNQUERYIMVALUESLIST,
- OFFSET_XNQUERYICVALUESLIST,
- OFFSET_XNVISIBLEPOSITION
-};
-
-/* offsets into name_table */
-static const unsigned short supported_local_ic_values_list[] = {
- OFFSET_XNINPUTSTYLE,
- OFFSET_XNCLIENTWINDOW,
- OFFSET_XNFOCUSWINDOW,
- OFFSET_XNRESOURCENAME,
- OFFSET_XNRESOURCECLASS,
- OFFSET_XNGEOMETRYCALLBACK,
- OFFSET_XNFILTEREVENTS,
- OFFSET_XNDESTROYCALLBACK,
- OFFSET_XNSTRINGCONVERSIONCALLBACK,
- OFFSET_XNSTRINGCONVERSIONCALLBACK,
- OFFSET_XNRESETSTATE,
- OFFSET_XNHOTKEY,
- OFFSET_XNHOTKEYSTATE,
- OFFSET_XNPREEDITATTRIBUTES,
- OFFSET_XNSTATUSATTRIBUTES,
- OFFSET_XNAREA,
- OFFSET_XNAREANEEDED,
- OFFSET_XNSPOTLOCATION,
- OFFSET_XNCOLORMAP,
- OFFSET_XNSTDCOLORMAP,
- OFFSET_XNFOREGROUND,
- OFFSET_XNBACKGROUND,
- OFFSET_XNBACKGROUNDPIXMAP,
- OFFSET_XNFONTSET,
- OFFSET_XNLINESPACE,
- OFFSET_XNCURSOR,
- OFFSET_XNPREEDITSTARTCALLBACK,
- OFFSET_XNPREEDITDONECALLBACK,
- OFFSET_XNPREEDITDRAWCALLBACK,
- OFFSET_XNPREEDITCARETCALLBACK,
- OFFSET_XNSTATUSSTARTCALLBACK,
- OFFSET_XNSTATUSDONECALLBACK,
- OFFSET_XNSTATUSDRAWCALLBACK,
- OFFSET_XNPREEDITSTATE,
- OFFSET_XNPREEDITSTATENOTIFYCALLBACK
-};
-
-static XIMStyle const supported_local_styles[] = {
- XIMPreeditNone | XIMStatusNone,
- XIMPreeditNothing | XIMStatusNothing,
- 0 /* dummy */
-};
-
-Private Bool
-_XimDefaultStyles(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm, /* unused */
- unsigned long mode) /* unused */
-{
- XIMStyles *styles;
- XIMStyles **out;
- register int i;
- unsigned int n;
- int len;
- XPointer tmp;
-
- n = XIMNumber(supported_local_styles) - 1;
- len = sizeof(XIMStyles) + sizeof(XIMStyle) * n;
- if(!(tmp = (XPointer)Xmalloc(len))) {
- return False;
- }
- bzero(tmp, len);
-
- styles = (XIMStyles *)tmp;
- if (n > 0) {
- styles->count_styles = (unsigned short)n;
- styles->supported_styles =
- (XIMStyle *)((char *)tmp + sizeof(XIMStyles));
- for(i = 0; i < n; i++) {
- styles->supported_styles[i] = supported_local_styles[i];
- }
- }
-
- out = (XIMStyles **)((char *)top + info->offset);
- *out = styles;
- return True;
-}
-
-Private Bool
-_XimDefaultIMValues(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm, /* unused */
- unsigned long mode) /* unused */
-{
- XIMValuesList *values_list;
- XIMValuesList **out;
- register int i;
- unsigned int n;
- int len;
- XPointer tmp;
-
- n = XIMNumber(supported_local_im_values_list);
- len = sizeof(XIMValuesList) + sizeof(char **) * n;
- if(!(tmp = (XPointer)Xmalloc(len))) {
- return False;
- }
- bzero(tmp, len);
-
- values_list = (XIMValuesList *)tmp;
- if (n > 0) {
- values_list->count_values = (unsigned short)n;
- values_list->supported_values
- = (char **)((char *)tmp + sizeof(XIMValuesList));
- for(i = 0; i < n; i++) {
- values_list->supported_values[i] =
- (char *)name_table + supported_local_im_values_list[i];
- }
- }
-
- out = (XIMValuesList **)((char *)top + info->offset);
- *out = values_list;
- return True;
-}
-
-Private Bool
-_XimDefaultICValues(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm, /* unused */
- unsigned long mode) /* unused */
-{
- XIMValuesList *values_list;
- XIMValuesList **out;
- register int i;
- unsigned int n;
- int len;
- XPointer tmp;
-
- n = XIMNumber(supported_local_ic_values_list);
- len = sizeof(XIMValuesList) + sizeof(char **) * n;
- if(!(tmp = (XPointer)Xmalloc(len))) {
- return False;
- }
- bzero(tmp, len);
-
- values_list = (XIMValuesList *)tmp;
- if (n > 0) {
- values_list->count_values = (unsigned short)n;
- values_list->supported_values
- = (char **)((char *)tmp + sizeof(XIMValuesList));
- for(i = 0; i < n; i++) {
- values_list->supported_values[i] =
- (char *)name_table + supported_local_ic_values_list[i];
- }
- }
-
- out = (XIMValuesList **)((char *)top + info->offset);
- *out = values_list;
- return True;
-}
-
-Private Bool
-_XimDefaultVisiblePos(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm, /* unused */
- unsigned long mode) /* unused */
-{
- Bool *out;
-
- out = (Bool *)((char *)top + info->offset);
- *out = False;
- return True;
-}
-
-Private Bool
-_XimDefaultFocusWindow(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Xic ic = (Xic)parm;
- Window *out;
-
- if(ic->core.client_window == (Window)NULL) {
- return True;
- }
-
- out = (Window *)((char *)top + info->offset);
- *out = ic->core.client_window;
- return True;
-}
-
-Private Bool
-_XimDefaultResName(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Xic ic = (Xic)parm;
- Xim im = (Xim)ic->core.im;
- char **out;
-
- if(im->core.res_name == (char *)NULL) {
- return True;
- }
-
- out = (char **)((char *)top + info->offset);
- *out = im->core.res_name;
- return True;
-}
-
-Private Bool
-_XimDefaultResClass(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Xic ic = (Xic)parm;
- Xim im = (Xim)ic->core.im;
- char **out;
-
- if(im->core.res_class == (char *)NULL) {
- return True;
- }
-
- out = (char **)((char *)top + info->offset);
- *out = im->core.res_class;
- return True;
-}
-
-Private Bool
-_XimDefaultDestroyCB(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Xic ic = (Xic)parm;
- Xim im = (Xim)ic->core.im;
- XIMCallback *out;
-
- out = (XIMCallback *)((char *)top + info->offset);
- *out = im->core.destroy_callback;
- return True;
-}
-
-Private Bool
-_XimDefaultResetState(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- XIMResetState *out;
-
- out = (XIMResetState *)((char *)top + info->offset);
- *out = XIMInitialState;
- return True;
-}
-
-Private Bool
-_XimDefaultHotKeyState(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- XIMHotKeyState *out;
-
- out = (XIMHotKeyState *)((char *)top + info->offset);
- *out = XIMHotKeyStateOFF;
- return True;
-}
-
-Private Bool
-_XimDefaultArea(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Xic ic = (Xic)parm;
- Xim im = (Xim)ic->core.im;
- Window root_return;
- int x_return, y_return;
- unsigned int width_return, height_return;
- unsigned int border_width_return;
- unsigned int depth_return;
- XRectangle area;
- XRectangle *out;
-
- if(ic->core.focus_window == (Window)NULL) {
- return True;
- }
- if(XGetGeometry(im->core.display, (Drawable)ic->core.focus_window,
- &root_return, &x_return, &y_return, &width_return,
- &height_return, &border_width_return, &depth_return)
- == (Status)Success) {
- return True;
- }
- area.x = 0;
- area.y = 0;
- area.width = width_return;
- area.height = height_return;
-
- out = (XRectangle *)((char *)top + info->offset);
- *out = area;
- return True;
-}
-
-Private Bool
-_XimDefaultColormap(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Xic ic = (Xic)parm;
- Xim im = (Xim)ic->core.im;
- XWindowAttributes win_attr;
- Colormap *out;
-
- if(ic->core.client_window == (Window)NULL) {
- return True;
- }
- if(XGetWindowAttributes(im->core.display, ic->core.client_window,
- &win_attr) == (Status)Success) {
- return True;
- }
-
- out = (Colormap *)((char *)top + info->offset);
- *out = win_attr.colormap;
- return True;
-}
-
-Private Bool
-_XimDefaultStdColormap(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Atom *out;
-
- out = (Atom *)((char *)top + info->offset);
- *out = (Atom)0;
- return True;
-}
-
-Private Bool
-_XimDefaultFg(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Xic ic = (Xic)parm;
- Xim im = (Xim)ic->core.im;
- unsigned long fg;
- unsigned long *out;
-
- fg = WhitePixel(im->core.display, DefaultScreen(im->core.display));
- out = (unsigned long *)((char *)top + info->offset);
- *out = fg;
- return True;
-}
-
-Private Bool
-_XimDefaultBg(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Xic ic = (Xic)parm;
- Xim im = (Xim)ic->core.im;
- unsigned long bg;
- unsigned long *out;
-
- bg = BlackPixel(im->core.display, DefaultScreen(im->core.display));
- out = (unsigned long *)((char *)top + info->offset);
- *out = bg;
- return True;
-}
-
-Private Bool
-_XimDefaultBgPixmap(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Pixmap *out;
-
- out = (Pixmap *)((char *)top + info->offset);
- *out = (Pixmap)0;
- return True;
-}
-
-Private Bool
-_XimDefaultFontSet(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- XFontSet *out;
-
- out = (XFontSet *)((char *)top + info->offset);
- *out = 0;
- return True;
-}
-
-Private Bool
-_XimDefaultLineSpace(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Xic ic = (Xic)parm;
- XFontSet fontset;
- XFontSetExtents *fset_extents;
- int line_space = 0;
- int *out;
-
- if(mode & XIM_PREEDIT_ATTR) {
- fontset = ic->core.preedit_attr.fontset;
- } else if(mode & XIM_STATUS_ATTR) {
- fontset = ic->core.status_attr.fontset;
- } else {
- return True;
- }
- if (fontset) {
- fset_extents = XExtentsOfFontSet(fontset);
- line_space = fset_extents->max_logical_extent.height;
- }
- out = (int *)((char *)top + info->offset);
- *out = line_space;
- return True;
-}
-
-Private Bool
-_XimDefaultCursor(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- Cursor *out;
-
- out = (Cursor *)((char *)top + info->offset);
- *out = (Cursor)0;
- return True;
-}
-
-Private Bool
-_XimDefaultPreeditState(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- XIMPreeditState *out;
-
- out = (XIMPreeditState *)((char *)top + info->offset);
- *out = XIMPreeditDisable;
- return True;
-}
-
-Private Bool
-_XimDefaultNest(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer parm,
- unsigned long mode)
-{
- return True;
-}
-
-Private Bool
-_XimEncodeCallback(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMCallback *out;
-
- out = (XIMCallback *)((char *)top + info->offset);
- *out = *((XIMCallback *)val);
- return True;
-}
-
-Private Bool
-_XimEncodeString(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- int len;
- char *string;
- char **out;
-
- if(val == (XPointer)NULL) {
- return False;
- }
- len = strlen((char *)val);
- if(!(string = (char *)Xmalloc(len + 1))) {
- return False;
- }
- (void)strcpy(string, (char *)val);
- string[len] = '\0';
-
- out = (char **)((char *)top + info->offset);
- if(*out) {
- Xfree(*out);
- }
- *out = string;
- return True;
-}
-
-Private Bool
-_XimEncodeStyle(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMStyle *out;
-
- out = (XIMStyle *)((char *)top + info->offset);
- *out = (XIMStyle)val;
- return True;
-}
-
-Private Bool
-_XimEncodeWindow(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- Window *out;
-
- out = (Window *)((char *)top + info->offset);
- *out = (Window)val;
- return True;
-}
-
-Private Bool
-_XimEncodeStringConv(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- /*
- * Not yet
- */
- return True;
-}
-
-Private Bool
-_XimEncodeResetState(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMResetState *out;
-
- out = (XIMResetState *)((char *)top + info->offset);
- *out = (XIMResetState)val;
- return True;
-}
-
-Private Bool
-_XimEncodeHotKey(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMHotKeyTriggers *hotkey = (XIMHotKeyTriggers *)val;
- XIMHotKeyTriggers **out;
- XIMHotKeyTriggers *key_list;
- XIMHotKeyTrigger *key;
- XPointer tmp;
- int num;
- int len;
- register int i;
-
- if(hotkey == (XIMHotKeyTriggers *)NULL) {
- return True;
- }
-
- if((num = hotkey->num_hot_key) == 0) {
- return True;
- }
-
- len = sizeof(XIMHotKeyTriggers) + sizeof(XIMHotKeyTrigger) * num;
- if(!(tmp = (XPointer)Xmalloc(len))) {
- return False;
- }
-
- key_list = (XIMHotKeyTriggers *)tmp;
- key = (XIMHotKeyTrigger *)((char *)tmp + sizeof(XIMHotKeyTriggers));
-
- for(i = 0; i < num; i++) {
- key[i] = hotkey->key[i];
- }
-
- key_list->num_hot_key = num;
- key_list->key = key;
-
- out = (XIMHotKeyTriggers **)((char *)top + info->offset);
- *out = key_list;
- return True;
-}
-
-Private Bool
-_XimEncodeHotKetState(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMHotKeyState *out;
-
- out = (XIMHotKeyState *)((char *)top + info->offset);
- *out = (XIMHotKeyState)val;
- return True;
-}
-
-Private Bool
-_XimEncodeRectangle(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XRectangle *out;
-
- out = (XRectangle *)((char *)top + info->offset);
- *out = *((XRectangle *)val);
- return True;
-}
-
-Private Bool
-_XimEncodeSpot(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XPoint *out;
-
- out = (XPoint *)((char *)top + info->offset);
- *out = *((XPoint *)val);
- return True;
-}
-
-Private Bool
-_XimEncodeColormap(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- Colormap *out;
-
- out = (Colormap *)((char *)top + info->offset);
- *out = (Colormap)val;
- return True;
-}
-
-Private Bool
-_XimEncodeStdColormap(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- Atom *out;
-
- out = (Atom *)((char *)top + info->offset);
- *out = (Atom)val;
- return True;
-}
-
-Private Bool
-_XimEncodeLong(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- unsigned long *out;
-
- out = (unsigned long *)((char *)top + info->offset);
- *out = (unsigned long)val;
- return True;
-}
-
-Private Bool
-_XimEncodeBgPixmap(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- Pixmap *out;
-
- out = (Pixmap *)((char *)top + info->offset);
- *out = (Pixmap)val;
- return True;
-}
-
-Private Bool
-_XimEncodeFontSet(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XFontSet *out;
-
- out = (XFontSet *)((char *)top + info->offset);
- *out = (XFontSet)val;
- return True;
-}
-
-Private Bool
-_XimEncodeLineSpace(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- int *out;
-
- out = (int *)((char *)top + info->offset);
- *out = (long)val;
- return True;
-}
-
-Private Bool
-_XimEncodeCursor(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- Cursor *out;
-
- out = (Cursor *)((char *)top + info->offset);
- *out = (Cursor)val;
- return True;
-}
-
-Private Bool
-_XimEncodePreeditState(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMPreeditState *out;
-
- out = (XIMPreeditState *)((char *)top + info->offset);
- *out = (XIMPreeditState)val;
- return True;
-}
-
-Private Bool
-_XimEncodeNest(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- return True;
-}
-
-Private Bool
-_XimDecodeStyles(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMStyles *styles;
- XIMStyles *out;
- register int i;
- unsigned int num;
- int len;
- XPointer tmp;
-
- if(val == (XPointer)NULL) {
- return False;
- }
-
- styles = *((XIMStyles **)((char *)top + info->offset));
- num = styles->count_styles;
-
- len = sizeof(XIMStyles) + sizeof(XIMStyle) * num;
- if(!(tmp = (XPointer)Xmalloc(len))) {
- return False;
- }
- bzero(tmp, len);
-
- out = (XIMStyles *)tmp;
- if(num >0) {
- out->count_styles = (unsigned short)num;
- out->supported_styles = (XIMStyle *)((char *)tmp + sizeof(XIMStyles));
-
- for(i = 0; i < num; i++) {
- out->supported_styles[i] = styles->supported_styles[i];
- }
- }
- *((XIMStyles **)val) = out;
- return True;
-}
-
-Private Bool
-_XimDecodeValues(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMValuesList *values_list;
- XIMValuesList *out;
- register int i;
- unsigned int num;
- int len;
- XPointer tmp;
-
- if(val == (XPointer)NULL) {
- return False;
- }
-
- values_list = *((XIMValuesList **)((char *)top + info->offset));
- num = values_list->count_values;
-
- len = sizeof(XIMValuesList) + sizeof(char **) * num;
- if(!(tmp = (char *)Xmalloc(len))) {
- return False;
- }
- bzero(tmp, len);
-
- out = (XIMValuesList *)tmp;
- if(num) {
- out->count_values = (unsigned short)num;
- out->supported_values = (char **)((char *)tmp + sizeof(XIMValuesList));
-
- for(i = 0; i < num; i++) {
- out->supported_values[i] = values_list->supported_values[i];
- }
- }
- *((XIMValuesList **)val) = out;
- return True;
-}
-
-Private Bool
-_XimDecodeCallback(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMCallback *in;
- XIMCallback *callback;
-
- in = (XIMCallback *)((char *)top + info->offset);
- if(!(callback = (XIMCallback *)Xmalloc(sizeof(XIMCallback)))) {
- return False;
- }
- callback->client_data = in->client_data;
- callback->callback = in->callback;
-
- *((XIMCallback **)val) = callback;
- return True;
-}
-
-Private Bool
-_XimDecodeString(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- int len = 0;
- char *in;
- char *string;
-
- in = *((char **)((char *)top + info->offset));
- if(in != (char *)NULL) {
- len = strlen(in);
- }
- if(!(string = (char *)Xmalloc(len + 1))) {
- return False;
- }
- if(in != (char *)NULL) {
- (void)strcpy(string, in);
- }
- string[len] = '\0';
- *((char **)val) = string;
- return True;
-}
-
-Private Bool
-_XimDecodeBool(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- Bool *in;
-
- in = (Bool *)((char *)top + info->offset);
- *((Bool *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeStyle(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMStyle *in;
-
- in = (XIMStyle *)((char *)top + info->offset);
- *((XIMStyle *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeWindow(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- Window *in;
-
- in = (Window *)((char *)top + info->offset);
- *((Window *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeStringConv(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- /*
- * Not yet
- */
- return True;
-}
-
-Private Bool
-_XimDecodeResetState(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMResetState *in;
-
- in = (XIMResetState *)((char *)top + info->offset);
- *((XIMResetState *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeHotKey(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMHotKeyTriggers *in;
- XIMHotKeyTriggers *hotkey;
- XIMHotKeyTrigger *key;
- XPointer tmp;
- int num;
- int len;
- register int i;
-
- in = *((XIMHotKeyTriggers **)((char *)top + info->offset));
- num = in->num_hot_key;
- len = sizeof(XIMHotKeyTriggers) + sizeof(XIMHotKeyTrigger) * num;
- if(!(tmp = (XPointer)Xmalloc(len))) {
- return False;
- }
-
- hotkey = (XIMHotKeyTriggers *)tmp;
- key = (XIMHotKeyTrigger *)((char *)tmp + sizeof(XIMHotKeyTriggers));
-
- for(i = 0; i < num; i++) {
- key[i] = in->key[i];
- }
- hotkey->num_hot_key = num;
- hotkey->key = key;
-
- *((XIMHotKeyTriggers **)val) = hotkey;
- return True;
-}
-
-Private Bool
-_XimDecodeHotKetState(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMHotKeyState *in;
-
- in = (XIMHotKeyState *)((char *)top + info->offset);
- *((XIMHotKeyState *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeRectangle(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XRectangle *in;
- XRectangle *rect;
-
- in = (XRectangle *)((char *)top + info->offset);
- if(!(rect = (XRectangle *)Xmalloc(sizeof(XRectangle)))) {
- return False;
- }
- *rect = *in;
- *((XRectangle **)val) = rect;
- return True;
-}
-
-Private Bool
-_XimDecodeSpot(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XPoint *in;
- XPoint *spot;
-
- in = (XPoint *)((char *)top + info->offset);
- if(!(spot = (XPoint *)Xmalloc(sizeof(XPoint)))) {
- return False;
- }
- *spot = *in;
- *((XPoint **)val) = spot;
- return True;
-}
-
-Private Bool
-_XimDecodeColormap(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- Colormap *in;
-
- in = (Colormap *)((char *)top + info->offset);
- *((Colormap *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeStdColormap(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- Atom *in;
-
- in = (Atom *)((char *)top + info->offset);
- *((Atom *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeLong(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- unsigned long *in;
-
- in = (unsigned long *)((char *)top + info->offset);
- *((unsigned long *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeBgPixmap(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- Pixmap *in;
-
- in = (Pixmap *)((char *)top + info->offset);
- *((Pixmap *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeFontSet(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XFontSet *in;
-
- in = (XFontSet *)((char *)top + info->offset);
- *((XFontSet *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeLineSpace(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- int *in;
-
- in = (int *)((char *)top + info->offset);
- *((int *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeCursor(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- Cursor *in;
-
- in = (Cursor *)((char *)top + info->offset);
- *((Cursor *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodePreeditState(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- XIMPreeditState *in;
-
- in = (XIMPreeditState *)((char *)top + info->offset);
- *((XIMPreeditState *)val) = *in;
- return True;
-}
-
-Private Bool
-_XimDecodeNest(
- XimValueOffsetInfo info,
- XPointer top,
- XPointer val)
-{
- return True;
-}
-
-static XIMResource im_resources[] = {
- {XNQueryInputStyle, 0, XimType_XIMStyles, 0, 0, 0},
- {XNDestroyCallback, 0, 0, 0, 0, 0},
- {XNResourceName, 0, XimType_STRING8, 0, 0, 0},
- {XNResourceClass, 0, XimType_STRING8, 0, 0, 0},
- {XNQueryIMValuesList, 0, 0, 0, 0, 0},
- {XNQueryICValuesList, 0, 0, 0, 0, 0},
- {XNVisiblePosition, 0, 0, 0, 0, 0}
-};
-
-static XIMResource im_inner_resources[] = {
- {XNDestroyCallback, 0, 0, 0, 0, 0},
- {XNResourceName, 0, XimType_STRING8, 0, 0, 0},
- {XNResourceClass, 0, XimType_STRING8, 0, 0, 0},
- {XNQueryIMValuesList, 0, 0, 0, 0, 0},
- {XNQueryICValuesList, 0, 0, 0, 0, 0},
- {XNVisiblePosition, 0, 0, 0, 0, 0}
-};
-
-static XIMResource ic_resources[] = {
- {XNInputStyle, 0, XimType_CARD32, 0, 0, 0},
- {XNClientWindow, 0, XimType_Window, 0, 0, 0},
- {XNFocusWindow, 0, XimType_Window, 0, 0, 0},
- {XNResourceName, 0, XimType_STRING8, 0, 0, 0},
- {XNResourceClass, 0, XimType_STRING8, 0, 0, 0},
- {XNGeometryCallback, 0, 0, 0, 0, 0},
- {XNFilterEvents, 0, XimType_CARD32, 0, 0, 0},
- {XNDestroyCallback, 0, 0, 0, 0, 0},
- {XNStringConversionCallback, 0, 0, 0, 0, 0},
- {XNStringConversion, 0, XimType_XIMStringConversion,0, 0, 0},
- {XNResetState, 0, 0, 0, 0, 0},
- {XNHotKey, 0, XimType_XIMHotKeyTriggers,0, 0, 0},
- {XNHotKeyState, 0, XimType_XIMHotKeyState, 0, 0, 0},
- {XNPreeditAttributes, 0, XimType_NEST, 0, 0, 0},
- {XNStatusAttributes, 0, XimType_NEST, 0, 0, 0},
- {XNArea, 0, XimType_XRectangle, 0, 0, 0},
- {XNAreaNeeded, 0, XimType_XRectangle, 0, 0, 0},
- {XNSpotLocation, 0, XimType_XPoint, 0, 0, 0},
- {XNColormap, 0, XimType_CARD32, 0, 0, 0},
- {XNStdColormap, 0, XimType_CARD32, 0, 0, 0},
- {XNForeground, 0, XimType_CARD32, 0, 0, 0},
- {XNBackground, 0, XimType_CARD32, 0, 0, 0},
- {XNBackgroundPixmap, 0, XimType_CARD32, 0, 0, 0},
- {XNFontSet, 0, XimType_XFontSet, 0, 0, 0},
- {XNLineSpace, 0, XimType_CARD32, 0, 0, 0},
- {XNCursor, 0, XimType_CARD32, 0, 0, 0},
- {XNPreeditStartCallback, 0, 0, 0, 0, 0},
- {XNPreeditDoneCallback, 0, 0, 0, 0, 0},
- {XNPreeditDrawCallback, 0, 0, 0, 0, 0},
- {XNPreeditCaretCallback, 0, 0, 0, 0, 0},
- {XNStatusStartCallback, 0, 0, 0, 0, 0},
- {XNStatusDoneCallback, 0, 0, 0, 0, 0},
- {XNStatusDrawCallback, 0, 0, 0, 0, 0},
- {XNPreeditState, 0, 0, 0, 0, 0},
- {XNPreeditStateNotifyCallback, 0, 0, 0, 0, 0},
-};
-
-static XIMResource ic_inner_resources[] = {
- {XNResourceName, 0, XimType_STRING8, 0, 0, 0},
- {XNResourceClass, 0, XimType_STRING8, 0, 0, 0},
- {XNGeometryCallback, 0, 0, 0, 0, 0},
- {XNDestroyCallback, 0, 0, 0, 0, 0},
- {XNStringConversionCallback, 0, 0, 0, 0, 0},
- {XNPreeditStartCallback, 0, 0, 0, 0, 0},
- {XNPreeditDoneCallback, 0, 0, 0, 0, 0},
- {XNPreeditDrawCallback, 0, 0, 0, 0, 0},
- {XNPreeditCaretCallback, 0, 0, 0, 0, 0},
- {XNStatusStartCallback, 0, 0, 0, 0, 0},
- {XNStatusDoneCallback, 0, 0, 0, 0, 0},
- {XNStatusDrawCallback, 0, 0, 0, 0, 0},
- {XNPreeditStateNotifyCallback, 0, 0, 0, 0, 0},
-};
-
-static XimValueOffsetInfoRec im_attr_info[] = {
- {OFFSET_XNQUERYINPUTSTYLE, 0,
- XOffsetOf(XimDefIMValues, styles),
- _XimDefaultStyles, NULL, _XimDecodeStyles},
-
- {OFFSET_XNDESTROYCALLBACK, 0,
- XOffsetOf(XimDefIMValues, destroy_callback),
- NULL, _XimEncodeCallback, _XimDecodeCallback},
-
- {OFFSET_XNRESOURCENAME, 0,
- XOffsetOf(XimDefIMValues, res_name),
- NULL, _XimEncodeString, _XimDecodeString},
-
- {OFFSET_XNRESOURCECLASS, 0,
- XOffsetOf(XimDefIMValues, res_class),
- NULL, _XimEncodeString, _XimDecodeString},
-
- {OFFSET_XNQUERYIMVALUESLIST, 0,
- XOffsetOf(XimDefIMValues, im_values_list),
- _XimDefaultIMValues, NULL, _XimDecodeValues},
-
- {OFFSET_XNQUERYICVALUESLIST, 0,
- XOffsetOf(XimDefIMValues, ic_values_list),
- _XimDefaultICValues, NULL, _XimDecodeValues},
-
- {OFFSET_XNVISIBLEPOSITION, 0,
- XOffsetOf(XimDefIMValues, visible_position),
- _XimDefaultVisiblePos, NULL, _XimDecodeBool}
-};
-
-static XimValueOffsetInfoRec ic_attr_info[] = {
- {OFFSET_XNINPUTSTYLE, 0,
- XOffsetOf(XimDefICValues, input_style),
- NULL, _XimEncodeStyle, _XimDecodeStyle},
-
- {OFFSET_XNCLIENTWINDOW, 0,
- XOffsetOf(XimDefICValues, client_window),
- NULL, _XimEncodeWindow, _XimDecodeWindow},
-
- {OFFSET_XNFOCUSWINDOW, 0,
- XOffsetOf(XimDefICValues, focus_window),
- _XimDefaultFocusWindow, _XimEncodeWindow, _XimDecodeWindow},
-
- {OFFSET_XNRESOURCENAME, 0,
- XOffsetOf(XimDefICValues, res_name),
- _XimDefaultResName, _XimEncodeString, _XimDecodeString},
-
- {OFFSET_XNRESOURCECLASS, 0,
- XOffsetOf(XimDefICValues, res_class),
- _XimDefaultResClass, _XimEncodeString, _XimDecodeString},
-
- {OFFSET_XNGEOMETRYCALLBACK, 0,
- XOffsetOf(XimDefICValues, geometry_callback),
- NULL, _XimEncodeCallback, _XimDecodeCallback},
-
- {OFFSET_XNFILTEREVENTS, 0,
- XOffsetOf(XimDefICValues, filter_events),
- NULL, NULL, _XimDecodeLong},
-
- {OFFSET_XNDESTROYCALLBACK, 0,
- XOffsetOf(XimDefICValues, destroy_callback),
- _XimDefaultDestroyCB, _XimEncodeCallback, _XimDecodeCallback},
-
- {OFFSET_XNSTRINGCONVERSIONCALLBACK, 0,
- XOffsetOf(XimDefICValues, string_conversion_callback),
- NULL, _XimEncodeCallback, _XimDecodeCallback},
-
- {OFFSET_XNSTRINGCONVERSION, 0,
- XOffsetOf(XimDefICValues, string_conversion),
- NULL, _XimEncodeStringConv, _XimDecodeStringConv},
-
- {OFFSET_XNRESETSTATE, 0,
- XOffsetOf(XimDefICValues, reset_state),
- _XimDefaultResetState, _XimEncodeResetState, _XimDecodeResetState},
-
- {OFFSET_XNHOTKEY, 0,
- XOffsetOf(XimDefICValues, hotkey),
- NULL, _XimEncodeHotKey, _XimDecodeHotKey},
-
- {OFFSET_XNHOTKEYSTATE, 0,
- XOffsetOf(XimDefICValues, hotkey_state),
- _XimDefaultHotKeyState, _XimEncodeHotKetState, _XimDecodeHotKetState},
-
- {OFFSET_XNPREEDITATTRIBUTES, 0,
- XOffsetOf(XimDefICValues, preedit_attr),
- _XimDefaultNest, _XimEncodeNest, _XimDecodeNest},
-
- {OFFSET_XNSTATUSATTRIBUTES, 0,
- XOffsetOf(XimDefICValues, status_attr),
- _XimDefaultNest, _XimEncodeNest, _XimDecodeNest},
-};
-
-static XimValueOffsetInfoRec ic_pre_attr_info[] = {
- {OFFSET_XNAREA, 0,
- XOffsetOf(ICPreeditAttributes, area),
- _XimDefaultArea, _XimEncodeRectangle, _XimDecodeRectangle},
-
- {OFFSET_XNAREANEEDED, 0,
- XOffsetOf(ICPreeditAttributes, area_needed),
- NULL, _XimEncodeRectangle, _XimDecodeRectangle},
-
- {OFFSET_XNSPOTLOCATION, 0,
- XOffsetOf(ICPreeditAttributes, spot_location),
- NULL, _XimEncodeSpot, _XimDecodeSpot},
-
- {OFFSET_XNCOLORMAP, 0,
- XOffsetOf(ICPreeditAttributes, colormap),
- _XimDefaultColormap, _XimEncodeColormap, _XimDecodeColormap},
-
- {OFFSET_XNSTDCOLORMAP, 0,
- XOffsetOf(ICPreeditAttributes, std_colormap),
- _XimDefaultStdColormap, _XimEncodeStdColormap, _XimDecodeStdColormap},
-
- {OFFSET_XNFOREGROUND, 0,
- XOffsetOf(ICPreeditAttributes, foreground),
- _XimDefaultFg, _XimEncodeLong, _XimDecodeLong},
-
- {OFFSET_XNBACKGROUND, 0,
- XOffsetOf(ICPreeditAttributes, background),
- _XimDefaultBg, _XimEncodeLong, _XimDecodeLong},
-
- {OFFSET_XNBACKGROUNDPIXMAP, 0,
- XOffsetOf(ICPreeditAttributes, background_pixmap),
- _XimDefaultBgPixmap, _XimEncodeBgPixmap, _XimDecodeBgPixmap},
-
- {OFFSET_XNFONTSET, 0,
- XOffsetOf(ICPreeditAttributes, fontset),
- _XimDefaultFontSet, _XimEncodeFontSet, _XimDecodeFontSet},
-
- {OFFSET_XNLINESPACE, 0,
- XOffsetOf(ICPreeditAttributes, line_spacing),
- _XimDefaultLineSpace, _XimEncodeLineSpace, _XimDecodeLineSpace},
-
- {OFFSET_XNCURSOR, 0,
- XOffsetOf(ICPreeditAttributes, cursor),
- _XimDefaultCursor, _XimEncodeCursor, _XimDecodeCursor},
-
- {OFFSET_XNPREEDITSTARTCALLBACK, 0,
- XOffsetOf(ICPreeditAttributes, start_callback),
- NULL, _XimEncodeCallback, _XimDecodeCallback},
-
- {OFFSET_XNPREEDITDONECALLBACK, 0,
- XOffsetOf(ICPreeditAttributes, done_callback),
- NULL, _XimEncodeCallback, _XimDecodeCallback},
-
- {OFFSET_XNPREEDITDRAWCALLBACK, 0,
- XOffsetOf(ICPreeditAttributes, draw_callback),
- NULL, _XimEncodeCallback, _XimDecodeCallback},
-
- {OFFSET_XNPREEDITCARETCALLBACK, 0,
- XOffsetOf(ICPreeditAttributes, caret_callback),
- NULL, _XimEncodeCallback, _XimDecodeCallback},
-
- {OFFSET_XNPREEDITSTATE, 0,
- XOffsetOf(ICPreeditAttributes, preedit_state),
- _XimDefaultPreeditState, _XimEncodePreeditState,_XimDecodePreeditState},
-
- {OFFSET_XNPREEDITSTATENOTIFYCALLBACK, 0,
- XOffsetOf(ICPreeditAttributes, state_notify_callback),
- NULL, _XimEncodeCallback, _XimDecodeCallback},
-};
-
-static XimValueOffsetInfoRec ic_sts_attr_info[] = {
- {OFFSET_XNAREA, 0,
- XOffsetOf(ICStatusAttributes, area),
- _XimDefaultArea, _XimEncodeRectangle, _XimDecodeRectangle},
-
- {OFFSET_XNAREANEEDED, 0,
- XOffsetOf(ICStatusAttributes, area_needed),
- NULL, _XimEncodeRectangle, _XimDecodeRectangle},
-
- {OFFSET_XNCOLORMAP, 0,
- XOffsetOf(ICStatusAttributes, colormap),
- _XimDefaultColormap, _XimEncodeColormap, _XimDecodeColormap},
-
- {OFFSET_XNSTDCOLORMAP, 0,
- XOffsetOf(ICStatusAttributes, std_colormap),
- _XimDefaultStdColormap, _XimEncodeStdColormap, _XimDecodeStdColormap},
-
- {OFFSET_XNFOREGROUND, 0,
- XOffsetOf(ICStatusAttributes, foreground),
- _XimDefaultFg, _XimEncodeLong, _XimDecodeLong},
-
- {OFFSET_XNBACKGROUND, 0,
- XOffsetOf(ICStatusAttributes, background),
- _XimDefaultBg, _XimEncodeLong, _XimDecodeLong},
-
- {OFFSET_XNBACKGROUNDPIXMAP, 0,
- XOffsetOf(ICStatusAttributes, background_pixmap),
- _XimDefaultBgPixmap, _XimEncodeBgPixmap, _XimDecodeBgPixmap},
-
- {OFFSET_XNFONTSET, 0,
- XOffsetOf(ICStatusAttributes, fontset),
- _XimDefaultFontSet, _XimEncodeFontSet, _XimDecodeFontSet},
-
- {OFFSET_XNLINESPACE, 0,
- XOffsetOf(ICStatusAttributes, line_spacing),
- _XimDefaultLineSpace, _XimEncodeLineSpace, _XimDecodeLineSpace},
-
- {OFFSET_XNCURSOR, 0,
- XOffsetOf(ICStatusAttributes, cursor),
- _XimDefaultCursor, _XimEncodeCursor, _XimDecodeCursor},
-
- {OFFSET_XNSTATUSSTARTCALLBACK, 0,
- XOffsetOf(ICStatusAttributes, start_callback),
- NULL, _XimEncodeCallback, _XimDecodeCallback},
-
- {OFFSET_XNSTATUSDONECALLBACK, 0,
- XOffsetOf(ICStatusAttributes, done_callback),
- NULL, _XimEncodeCallback, _XimDecodeCallback},
-
- {OFFSET_XNSTATUSDRAWCALLBACK, 0,
- XOffsetOf(ICStatusAttributes, draw_callback),
- NULL, _XimEncodeCallback, _XimDecodeCallback}
-};
-
-typedef struct _XimIMMode {
- unsigned short name_offset;
- unsigned short mode;
-} XimIMMode;
-
-static const XimIMMode im_mode[] = {
- {OFFSET_XNQUERYINPUTSTYLE,
- (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)},
- {OFFSET_XNDESTROYCALLBACK,
- (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_SET | XIM_MODE_IM_GET)},
- {OFFSET_XNRESOURCENAME,
- (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_SET | XIM_MODE_IM_GET)},
- {OFFSET_XNRESOURCECLASS,
- (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_SET | XIM_MODE_IM_GET)},
- {OFFSET_XNQUERYIMVALUESLIST,
- (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)},
- {OFFSET_XNQUERYICVALUESLIST,
- (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)},
- {OFFSET_XNVISIBLEPOSITION,
- (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)}
-};
-
-typedef struct _XimICMode {
- unsigned short name_offset;
- unsigned short preedit_callback_mode;
- unsigned short preedit_position_mode;
- unsigned short preedit_area_mode;
- unsigned short preedit_nothing_mode;
- unsigned short preedit_none_mode;
- unsigned short status_callback_mode;
- unsigned short status_area_mode;
- unsigned short status_nothing_mode;
- unsigned short status_none_mode;
-} XimICMode;
-
-static const XimICMode ic_mode[] = {
- {OFFSET_XNINPUTSTYLE,
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
- (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET),
- (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET),
- (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET),
- (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET)},
- {OFFSET_XNCLIENTWINDOW,
- (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET),
- 0,
- (XIM_MODE_STS_ONCE | XIM_MODE_STS_GET),
- (XIM_MODE_STS_ONCE | XIM_MODE_STS_GET),
- (XIM_MODE_STS_ONCE | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNFOCUSWINDOW,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNRESOURCENAME,
- 0,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNRESOURCECLASS,
- 0,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNGEOMETRYCALLBACK,
- 0,
- 0,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0,
- 0},
- {OFFSET_XNFILTEREVENTS,
- XIM_MODE_PRE_GET,
- XIM_MODE_PRE_GET,
- XIM_MODE_PRE_GET,
- XIM_MODE_PRE_GET,
- 0,
- XIM_MODE_STS_GET,
- XIM_MODE_STS_GET,
- XIM_MODE_STS_GET,
- XIM_MODE_STS_GET},
- {OFFSET_XNDESTROYCALLBACK,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNSTRINGCONVERSIONCALLBACK,
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNSTRINGCONVERSION,
- XIM_MODE_PRE_SET,
- XIM_MODE_PRE_SET,
- XIM_MODE_PRE_SET,
- XIM_MODE_PRE_SET,
- XIM_MODE_PRE_SET,
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNRESETSTATE,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNHOTKEY,
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNHOTKEYSTATE,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNPREEDITATTRIBUTES,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNSTATUSATTRIBUTES,
- 0,
- 0,
- 0,
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNAREA,
- 0,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0,
- 0},
- {OFFSET_XNAREANEEDED,
- 0,
- 0,
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- (XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0,
- 0},
- {OFFSET_XNSPOTLOCATION,
- 0, /*(XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),*/
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNCOLORMAP,
- 0,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNSTDCOLORMAP,
- 0,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNFOREGROUND,
- 0,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNBACKGROUND,
- 0,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNBACKGROUNDPIXMAP,
- 0,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNFONTSET,
- 0,
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNLINESPACE,
- 0,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNCURSOR,
- 0,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0},
- {OFFSET_XNPREEDITSTARTCALLBACK,
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNPREEDITDONECALLBACK,
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNPREEDITDRAWCALLBACK,
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNPREEDITCARETCALLBACK,
- (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNPREEDITSTATE,
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNPREEDITSTATENOTIFYCALLBACK,
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
- 0,
- 0,
- 0,
- 0,
- 0},
- {OFFSET_XNSTATUSSTARTCALLBACK,
- 0,
- 0,
- 0,
- 0,
- 0,
- (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0,
- 0,
- 0},
- {OFFSET_XNSTATUSDONECALLBACK,
- 0,
- 0,
- 0,
- 0,
- 0,
- (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0,
- 0,
- 0},
- {OFFSET_XNSTATUSDRAWCALLBACK,
- 0,
- 0,
- 0,
- 0,
- 0,
- (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
- 0,
- 0,
- 0}
-};
-
-/* the quarks are separated from im_mode/ic_mode so those arrays
- * can be const.
- */
-static XrmQuark im_mode_quark[sizeof(im_mode) / sizeof(im_mode[0])];
-static XrmQuark ic_mode_quark[sizeof(ic_mode) / sizeof(ic_mode[0])];
-
-Private Bool
-_XimSetResourceList(
- XIMResourceList *res_list,
- unsigned int *list_num,
- XIMResourceList resource,
- unsigned int num_resource,
- unsigned short id)
-{
- register int i;
- int len;
- XIMResourceList res;
-
- len = sizeof(XIMResource) * num_resource;
- if(!(res = (XIMResourceList)Xmalloc(len))) {
- return False;
- }
- bzero((char *)res, len);
-
- for(i = 0; i < num_resource; i++, id++) {
- res[i] = resource[i];
- res[i].id = id;
- }
-
- _XIMCompileResourceList(res, num_resource);
- *res_list = res;
- *list_num = num_resource;
- return True;
-}
-
-Public Bool
-_XimSetIMResourceList(
- XIMResourceList *res_list,
- unsigned int *list_num)
-{
- return _XimSetResourceList(res_list, list_num,
- im_resources, XIMNumber(im_resources), 100);
-}
-
-Public Bool
-_XimSetICResourceList(
- XIMResourceList *res_list,
- unsigned int *list_num)
-{
- return _XimSetResourceList(res_list, list_num,
- ic_resources, XIMNumber(ic_resources), 200);
-}
-
-Public Bool
-_XimSetInnerIMResourceList(
- XIMResourceList *res_list,
- unsigned int *list_num)
-{
- return _XimSetResourceList(res_list, list_num,
- im_inner_resources, XIMNumber(im_inner_resources), 100);
-}
-
-Public Bool
-_XimSetInnerICResourceList(
- XIMResourceList *res_list,
- unsigned int *list_num)
-{
- return _XimSetResourceList(res_list, list_num,
- ic_inner_resources, XIMNumber(ic_inner_resources), 200);
-}
-
-Private XIMResourceList
-_XimGetResourceListRecByMode(
- XIMResourceList res_list,
- unsigned int list_num,
- unsigned short mode)
-{
- register int i;
-
- for(i = 0; i < list_num; i++) {
- if (res_list[i].mode & mode) {
- return (XIMResourceList)&res_list[i];
- }
- }
- return (XIMResourceList)NULL;
-}
-
-Public Bool
-_XimCheckCreateICValues(
- XIMResourceList res_list,
- unsigned int list_num)
-{
- if (!_XimGetResourceListRecByMode(res_list, list_num, XIM_MODE_IC_CREATE)) {
- return True;
- }
- return False;
-}
-
-Public XIMResourceList
-_XimGetResourceListRecByQuark(
- XIMResourceList res_list,
- unsigned int list_num,
- XrmQuark quark)
-{
- register int i;
-
- for(i = 0; i < list_num; i++) {
- if (res_list[i].xrm_name == quark) {
- return (XIMResourceList)&res_list[i];
- }
- }
- return (XIMResourceList)NULL;
-}
-
-Public XIMResourceList
-_XimGetResourceListRec(
- XIMResourceList res_list,
- unsigned int list_num,
- const char *name)
-{
- XrmQuark quark = XrmStringToQuark(name);
-
- return _XimGetResourceListRecByQuark(res_list, list_num, quark);
-}
-
-Public char *
-_XimSetIMValueData(
- Xim im,
- XPointer top,
- XIMArg *values,
- XIMResourceList res_list,
- unsigned int list_num)
-{
- register XIMArg *p;
- XIMResourceList res;
- int check;
-
- for(p = values; p->name != NULL; p++) {
- if(!(res = _XimGetResourceListRec(res_list, list_num, p->name))) {
- return p->value;
- }
- check = _XimCheckIMMode(res, XIM_SETIMVALUES);
- if(check == XIM_CHECK_INVALID) {
- continue;
- } else if (check == XIM_CHECK_ERROR) {
- return p->value;
- }
-
- if(!_XimEncodeLocalIMAttr(res, top, p->value)) {
- return p->value;
- }
- }
- return NULL;
-}
-
-Public char *
-_XimGetIMValueData(
- Xim im,
- XPointer top,
- XIMArg *values,
- XIMResourceList res_list,
- unsigned int list_num)
-{
- register XIMArg *p;
- XIMResourceList res;
- int check;
-
- for(p = values; p->name != NULL; p++) {
- if(!(res = _XimGetResourceListRec(res_list, list_num, p->name))) {
- return p->value;
- }
- check = _XimCheckIMMode(res, XIM_GETIMVALUES);
- if(check == XIM_CHECK_INVALID) {
- continue;
- } else if (check == XIM_CHECK_ERROR) {
- return p->value;
- }
-
- if(!_XimDecodeLocalIMAttr(res, top, p->value)) {
- return p->value;
- }
- }
- return NULL;
-}
-
-Public void
-_XimSetIMMode(
- XIMResourceList res_list,
- unsigned int list_num)
-{
- XIMResourceList res;
- unsigned int n = XIMNumber(im_mode);
- register int i;
-
- for(i = 0; i < n; i++) {
- if(!(res = _XimGetResourceListRecByQuark(res_list,
- list_num, im_mode_quark[i]))) {
- continue;
- }
- res->mode = im_mode[i].mode;
- }
- return;
-}
-
-Private int
-_XimCheckSetIMDefaultsMode(
- XIMResourceList res)
-{
- if(res->mode & XIM_MODE_IM_DEFAULT) {
- return XIM_CHECK_VALID;
- }
- return XIM_CHECK_INVALID;
-}
-
-Private int
-_XimCheckSetIMValuesMode(
- XIMResourceList res)
-{
- if(res->mode & XIM_MODE_IM_SET) {
- return XIM_CHECK_VALID;
- }
- return XIM_CHECK_INVALID;
-}
-
-Private int
- _XimCheckGetIMValuesMode(
- XIMResourceList res)
-{
- if(res->mode & XIM_MODE_IM_GET) {
- return XIM_CHECK_VALID;
- }
- return XIM_CHECK_INVALID;
-}
-
-Public int
- _XimCheckIMMode(
- XIMResourceList res,
- unsigned long mode)
-{
- if(res->mode == 0) {
- return XIM_CHECK_INVALID;
- }
- if(mode & XIM_SETIMDEFAULTS) {
- return _XimCheckSetIMDefaultsMode(res);
- } else if (mode & XIM_SETIMVALUES) {
- return _XimCheckSetIMValuesMode(res);
- } else if (mode & XIM_GETIMVALUES) {
- return _XimCheckGetIMValuesMode(res);
- } else {
- return XIM_CHECK_ERROR;
- }
-}
-
-Public void
-_XimSetICMode(XIMResourceList res_list, unsigned int list_num, XIMStyle style)
-{
- XIMResourceList res;
- unsigned int n = XIMNumber(ic_mode);
- register int i;
- unsigned int pre_offset;
- unsigned int sts_offset;
-
- if(style & XIMPreeditArea) {
- pre_offset = XOffsetOf(XimICMode, preedit_area_mode);
- } else if(style & XIMPreeditCallbacks) {
- pre_offset = XOffsetOf(XimICMode, preedit_callback_mode);
- } else if(style & XIMPreeditPosition) {
- pre_offset = XOffsetOf(XimICMode, preedit_position_mode);
- } else if(style & XIMPreeditNothing) {
- pre_offset = XOffsetOf(XimICMode, preedit_nothing_mode);
- } else {
- pre_offset = XOffsetOf(XimICMode, preedit_none_mode);
- }
-
- if(style & XIMStatusArea) {
- sts_offset = XOffsetOf(XimICMode, status_area_mode);
- } else if(style & XIMStatusCallbacks) {
- sts_offset = XOffsetOf(XimICMode, status_callback_mode);
- } else if(style & XIMStatusNothing) {
- sts_offset = XOffsetOf(XimICMode, status_nothing_mode);
- } else {
- sts_offset = XOffsetOf(XimICMode, status_none_mode);
- }
-
- for(i = 0; i < n; i++) {
- if(!(res = _XimGetResourceListRecByQuark(res_list,
- list_num, ic_mode_quark[i]))) {
- continue;
- }
- res->mode = ( (*(unsigned short *)((char *)&ic_mode[i] + pre_offset))
- | (*(unsigned short *)((char *)&ic_mode[i] + sts_offset)));
- }
- return;
-}
-
-Private int
-_XimCheckSetICDefaultsMode(
- XIMResourceList res,
- unsigned long mode)
-{
- if(mode & XIM_PREEDIT_ATTR) {
- if(!(res->mode & XIM_MODE_PRE_MASK)) {
- return XIM_CHECK_INVALID;
- }
-
- if(res->mode & XIM_MODE_PRE_CREATE) {
- return XIM_CHECK_ERROR;
- } else if (!(res->mode & XIM_MODE_PRE_DEFAULT)) {
- return XIM_CHECK_INVALID;
- }
-
- } else if(mode & XIM_STATUS_ATTR) {
- if(!(res->mode & XIM_MODE_STS_MASK)) {
- return XIM_CHECK_INVALID;
- }
-
- if(res->mode & XIM_MODE_STS_CREATE) {
- return XIM_CHECK_ERROR;
- }
- if(!(res->mode & XIM_MODE_STS_DEFAULT)) {
- return XIM_CHECK_INVALID;
- }
-
- } else {
- if(!res->mode) {
- return XIM_CHECK_INVALID;
- }
-
- if(res->mode & XIM_MODE_IC_CREATE) {
- return XIM_CHECK_ERROR;
- }
- if(!(res->mode & XIM_MODE_IC_DEFAULT)) {
- return XIM_CHECK_INVALID;
- }
- }
- return XIM_CHECK_VALID;
-}
-
-Private int
-_XimCheckCreateICMode(
- XIMResourceList res,
- unsigned long mode)
-{
- if(mode & XIM_PREEDIT_ATTR) {
- if(!(res->mode & XIM_MODE_PRE_MASK)) {
- return XIM_CHECK_INVALID;
- }
-
- if(res->mode & XIM_MODE_PRE_CREATE) {
- res->mode &= ~XIM_MODE_PRE_CREATE;
- } else if(res->mode & XIM_MODE_PRE_ONCE) {
- res->mode &= ~XIM_MODE_PRE_ONCE;
- } else if(res->mode & XIM_MODE_PRE_DEFAULT) {
- res->mode &= ~XIM_MODE_PRE_DEFAULT;
- } else if (!(res->mode & XIM_MODE_PRE_SET)) {
- return XIM_CHECK_ERROR;
- }
-
- } else if(mode & XIM_STATUS_ATTR) {
- if(!(res->mode & XIM_MODE_STS_MASK)) {
- return XIM_CHECK_INVALID;
- }
-
- if(res->mode & XIM_MODE_STS_CREATE) {
- res->mode &= ~XIM_MODE_STS_CREATE;
- } else if(res->mode & XIM_MODE_STS_ONCE) {
- res->mode &= ~XIM_MODE_STS_ONCE;
- } else if(res->mode & XIM_MODE_STS_DEFAULT) {
- res->mode &= ~XIM_MODE_STS_DEFAULT;
- } else if (!(res->mode & XIM_MODE_STS_SET)) {
- return XIM_CHECK_ERROR;
- }
-
- } else {
- if(!res->mode) {
- return XIM_CHECK_INVALID;
- }
-
- if(res->mode & XIM_MODE_IC_CREATE) {
- res->mode &= ~XIM_MODE_IC_CREATE;
- } else if(res->mode & XIM_MODE_IC_ONCE) {
- res->mode &= ~XIM_MODE_IC_ONCE;
- } else if(res->mode & XIM_MODE_IC_DEFAULT) {
- res->mode &= ~XIM_MODE_IC_DEFAULT;
- } else if (!(res->mode & XIM_MODE_IC_SET)) {
- return XIM_CHECK_ERROR;
- }
- }
- return XIM_CHECK_VALID;
-}
-
-Private int
-_XimCheckSetICValuesMode(
- XIMResourceList res,
- unsigned long mode)
-{
- if(mode & XIM_PREEDIT_ATTR) {
- if(!(res->mode & XIM_MODE_PRE_MASK)) {
- return XIM_CHECK_INVALID;
- }
-
- if(res->mode & XIM_MODE_PRE_ONCE) {
- res->mode &= ~XIM_MODE_PRE_ONCE;
- } else if(!(res->mode & XIM_MODE_PRE_SET)) {
- return XIM_CHECK_ERROR;
- }
-
- } else if(mode & XIM_STATUS_ATTR) {
- if(!(res->mode & XIM_MODE_STS_MASK)) {
- return XIM_CHECK_INVALID;
- }
-
- if(res->mode & XIM_MODE_STS_ONCE) {
- res->mode &= ~XIM_MODE_STS_ONCE;
- } else if(!(res->mode & XIM_MODE_STS_SET)) {
- return XIM_CHECK_ERROR;
- }
-
- } else {
- if(!res->mode) {
- return XIM_CHECK_INVALID;
- }
-
- if(res->mode & XIM_MODE_IC_ONCE) {
- res->mode &= ~XIM_MODE_IC_ONCE;
- } else if(!(res->mode & XIM_MODE_IC_SET)) {
- return XIM_CHECK_ERROR;
- }
- }
- return XIM_CHECK_VALID;
-}
-
-Private int
-_XimCheckGetICValuesMode(
- XIMResourceList res,
- unsigned long mode)
-{
- if(mode & XIM_PREEDIT_ATTR) {
- if(!(res->mode & XIM_MODE_PRE_MASK)) {
- return XIM_CHECK_INVALID;
- }
-
- if(!(res->mode & XIM_MODE_PRE_GET)) {
- return XIM_CHECK_ERROR;
- }
-
- } else if(mode & XIM_STATUS_ATTR) {
- if(!(res->mode & XIM_MODE_STS_MASK)) {
- return XIM_CHECK_INVALID;
- }
-
- if(!(res->mode & XIM_MODE_STS_GET)) {
- return XIM_CHECK_ERROR;
- }
-
- } else {
- if(!res->mode) {
- return XIM_CHECK_INVALID;
- }
-
- if(!(res->mode & XIM_MODE_IC_GET)) {
- return XIM_CHECK_ERROR;
- }
- }
- return XIM_CHECK_VALID;
-}
-
-Public int
- _XimCheckICMode(
- XIMResourceList res,
- unsigned long mode)
-{
- if(mode &XIM_SETICDEFAULTS) {
- return _XimCheckSetICDefaultsMode(res, mode);
- } else if (mode & XIM_CREATEIC) {
- return _XimCheckCreateICMode(res, mode);
- } else if (mode & XIM_SETICVALUES) {
- return _XimCheckSetICValuesMode(res, mode);
- } else if (mode & XIM_GETICVALUES) {
- return _XimCheckGetICValuesMode(res, mode);
- } else {
- return XIM_CHECK_ERROR;
- }
-}
-
-Public Bool
-_XimSetLocalIMDefaults(
- Xim im,
- XPointer top,
- XIMResourceList res_list,
- unsigned int list_num)
-{
- XimValueOffsetInfo info;
- unsigned int num;
- register int i;
- XIMResourceList res;
- int check;
-
- info = im_attr_info;
- num = XIMNumber(im_attr_info);
-
- for(i = 0; i < num; i++) {
- if((res = _XimGetResourceListRecByQuark( res_list, list_num,
- info[i].quark)) == (XIMResourceList)NULL) {
- return False;
- }
-
- check = _XimCheckIMMode(res, XIM_SETIMDEFAULTS);
- if(check == XIM_CHECK_INVALID) {
- continue;
- } else if (check == XIM_CHECK_ERROR) {
- return False;
- }
-
- if(!info[i].defaults) {
- continue;
- }
- if(!(info[i].defaults(&info[i], top, (XPointer)NULL, 0))) {
- return False;
- }
- }
- return True;
-}
-
-Public Bool
-_XimSetICDefaults(
- Xic ic,
- XPointer top,
- unsigned long mode,
- XIMResourceList res_list,
- unsigned int list_num)
-{
- unsigned int num;
- XimValueOffsetInfo info;
- register int i;
- XIMResourceList res;
- int check;
- XrmQuark pre_quark;
- XrmQuark sts_quark;
-
- pre_quark = XrmStringToQuark(XNPreeditAttributes);
- sts_quark = XrmStringToQuark(XNStatusAttributes);
-
- if(mode & XIM_PREEDIT_ATTR) {
- info = ic_pre_attr_info;
- num = XIMNumber(ic_pre_attr_info);
- } else if(mode & XIM_STATUS_ATTR) {
- info = ic_sts_attr_info;
- num = XIMNumber(ic_sts_attr_info);
- } else {
- info = ic_attr_info;
- num = XIMNumber(ic_attr_info);
- }
-
- for(i = 0; i < num; i++) {
- if(info[i].quark == pre_quark) {
- if(!_XimSetICDefaults(ic, (XPointer)((char *)top + info[i].offset),
- (mode | XIM_PREEDIT_ATTR), res_list, list_num)) {
- return False;
- }
- } else if (info[i].quark == sts_quark) {
- if(!_XimSetICDefaults(ic, (XPointer)((char *)top + info[i].offset),
- (mode | XIM_STATUS_ATTR), res_list, list_num)) {
- return False;
- }
- } else {
- if(!(res = _XimGetResourceListRecByQuark(res_list, list_num,
- info[i].quark))) {
- return False;
- }
-
- check = _XimCheckICMode(res, mode);
- if (check == XIM_CHECK_INVALID) {
- continue;
- } else if (check == XIM_CHECK_ERROR) {
- return False;
- }
-
- if (!info[i].defaults) {
- continue;
- }
- if (!(info[i].defaults(&info[i], top, (XPointer)ic, mode))) {
- return False;
- }
- }
- }
- return True;
-}
-
-Private Bool
-_XimEncodeAttr(
- XimValueOffsetInfo info,
- unsigned int num,
- XIMResourceList res,
- XPointer top,
- XPointer val)
-{
- register int i;
-
- for(i = 0; i < num; i++ ) {
- if(info[i].quark == res->xrm_name) {
- if(!info[i].encode) {
- return False;
- }
- return (*info[i].encode)(&info[i], top, val);
- }
- }
- return False;
-}
-
-Public Bool
-_XimEncodeLocalIMAttr(
- XIMResourceList res,
- XPointer top,
- XPointer val)
-{
- return _XimEncodeAttr(im_attr_info, XIMNumber(im_attr_info),
- res, top, val);
-}
-
-Public Bool
-_XimEncodeLocalICAttr(
- Xic ic,
- XIMResourceList res,
- XPointer top,
- XIMArg *arg,
- unsigned long mode)
-{
- unsigned int num;
- XimValueOffsetInfo info;
-
- if(mode & XIM_PREEDIT_ATTR) {
- info = ic_pre_attr_info;
- num = XIMNumber(ic_pre_attr_info);
- } else if(mode & XIM_STATUS_ATTR) {
- info = ic_sts_attr_info;
- num = XIMNumber(ic_sts_attr_info);
- } else {
- info = ic_attr_info;
- num = XIMNumber(ic_attr_info);
- }
-
- return _XimEncodeAttr(info, num, res, top, arg->value);
-}
-
-Private Bool
-_XimEncodeLocalTopValue(
- Xic ic,
- XIMResourceList res,
- XPointer val,
- Bool flag)
-{
- XIMArg *p = (XIMArg *)val;
-
- if (res->xrm_name == XrmStringToQuark(XNClientWindow)) {
- ic->core.client_window = (Window)p->value;
- if (ic->core.focus_window == (Window)0)
- ic->core.focus_window = ic->core.client_window;
- if (flag) {
- _XRegisterFilterByType(ic->core.im->core.display,
- ic->core.focus_window,
- KeyPress, KeyRelease, _XimLocalFilter, (XPointer)ic);
- }
- } else if (res->xrm_name == XrmStringToQuark(XNFocusWindow)) {
- if (ic->core.client_window) {
- if (flag) {
- _XUnregisterFilter(ic->core.im->core.display,
- ic->core.focus_window, _XimLocalFilter, (XPointer)ic);
- }
- ic->core.focus_window = (Window)p->value;
- if (flag) {
- _XRegisterFilterByType(ic->core.im->core.display,
- ic->core.focus_window, KeyPress, KeyRelease,
- _XimLocalFilter, (XPointer)ic);
- }
- } else
- ic->core.focus_window = (Window)p->value;
- }
- return True;
-}
-
-Private Bool
-_XimEncodeLocalPreeditValue(
- Xic ic,
- XIMResourceList res,
- XPointer val)
-{
- XIMArg *p = (XIMArg *)val;
-
- if (res->xrm_name == XrmStringToQuark(XNStdColormap)) {
- XStandardColormap *colormap_ret;
- int count;
-
- if (!(XGetRGBColormaps(ic->core.im->core.display,
- ic->core.focus_window, &colormap_ret,
- &count, (Atom)p->value)))
- return False;
-
- Xfree(colormap_ret);
- }
- return True;
-}
-
-Private Bool
-_XimEncodeLocalStatusValue(
- Xic ic,
- XIMResourceList res,
- XPointer val)
-{
- XIMArg *p = (XIMArg *)val;
-
- if (res->xrm_name == XrmStringToQuark(XNStdColormap)) {
- XStandardColormap *colormap_ret;
- int count;
-
- if (!(XGetRGBColormaps(ic->core.im->core.display,
- ic->core.focus_window, &colormap_ret,
- &count, (Atom)p->value)))
- return False;
-
- Xfree(colormap_ret);
- }
- return True;
-}
-
-Public char *
-_XimSetICValueData(
- Xic ic,
- XPointer top,
- XIMResourceList res_list,
- unsigned int list_num,
- XIMArg *values,
- unsigned long mode,
- Bool flag)
-{
- register XIMArg *p;
- XIMResourceList res;
- char *name;
- int check;
- XrmQuark pre_quark;
- XrmQuark sts_quark;
-
- pre_quark = XrmStringToQuark(XNPreeditAttributes);
- sts_quark = XrmStringToQuark(XNStatusAttributes);
-
- for(p = values; p->name != NULL; p++) {
- if((res = _XimGetResourceListRec(res_list, list_num,
- p->name)) == (XIMResourceList)NULL) {
- return p->name;
- }
- if(res->xrm_name == pre_quark) {
- if(((name = _XimSetICValueData(ic,
- (XPointer)(&((XimDefICValues *)top)->preedit_attr),
- res_list, list_num, (XIMArg *)p->value,
- (mode | XIM_PREEDIT_ATTR), flag)))) {
- return name;
- }
- } else if(res->xrm_name == sts_quark) {
- if(((name = _XimSetICValueData(ic,
- (XPointer)(&((XimDefICValues *)top)->status_attr),
- res_list, list_num, (XIMArg *)p->value,
- (mode | XIM_STATUS_ATTR), flag)))) {
- return name;
- }
- } else {
- check = _XimCheckICMode(res, mode);
- if(check == XIM_CHECK_INVALID) {
- continue;
- } else if(check == XIM_CHECK_ERROR) {
- return p->name;
- }
-
- if(mode & XIM_PREEDIT_ATTR) {
- if (!_XimEncodeLocalPreeditValue(ic, res, (XPointer)p))
- return False;
- } else if(mode & XIM_STATUS_ATTR) {
- if (!_XimEncodeLocalStatusValue(ic, res, (XPointer)p))
- return False;
- } else {
- if (!_XimEncodeLocalTopValue(ic, res, (XPointer)p, flag))
- return False;
- }
- if(_XimEncodeLocalICAttr(ic, res, top, p, mode) == False) {
- return p->name;
- }
- }
- }
- return NULL;
-}
-
-Private Bool
-_XimCheckInputStyle(
- XIMStyles *styles,
- XIMStyle style)
-{
- int num = styles->count_styles;
- register int i;
-
- for(i = 0; i < num; i++) {
- if(styles->supported_styles[i] == style) {
- return True;
- }
- }
- return False;
-}
-
-Public Bool
-_XimCheckLocalInputStyle(
- Xic ic,
- XPointer top,
- XIMArg *values,
- XIMStyles *styles,
- XIMResourceList res_list,
- unsigned int list_num)
-{
- XrmQuark quark = XrmStringToQuark(XNInputStyle);
- register XIMArg *p;
- XIMResourceList res;
-
- for(p = values; p && p->name != NULL; p++) {
- if(quark == XrmStringToQuark(p->name)) {
- if(!(res = _XimGetResourceListRec(res_list, list_num, p->name))) {
- return False;
- }
- if(!_XimEncodeLocalICAttr(ic, res, top, p, 0)) {
- return False;
- }
- if (_XimCheckInputStyle(styles,
- ((XimDefICValues *)top)->input_style)) {
- return True;
- }
- return False;
- }
- }
- return False;
-}
-
-Private Bool
-_XimDecodeAttr(
- XimValueOffsetInfo info,
- unsigned int num,
- XIMResourceList res,
- XPointer top,
- XPointer val)
-{
- register int i;
-
- for(i = 0; i < num; i++ ) {
- if(info[i].quark == res->xrm_name) {
- if(!info[i].decode) {
- return False;
- }
- return (*info[i].decode)(&info[i], top, val);
- }
- }
- return False;
-}
-
-Public Bool
-_XimDecodeLocalIMAttr(
- XIMResourceList res,
- XPointer top,
- XPointer val)
-{
- return _XimDecodeAttr(im_attr_info, XIMNumber(im_attr_info),
- res, top, val);
-}
-
-Public Bool
-_XimDecodeLocalICAttr(
- XIMResourceList res,
- XPointer top,
- XPointer val,
- unsigned long mode)
-{
- unsigned int num;
- XimValueOffsetInfo info;
-
- if(mode & XIM_PREEDIT_ATTR) {
- info = ic_pre_attr_info;
- num = XIMNumber(ic_pre_attr_info);
- } else if(mode & XIM_STATUS_ATTR) {
- info = ic_sts_attr_info;
- num = XIMNumber(ic_sts_attr_info);
- } else {
- info = ic_attr_info;
- num = XIMNumber(ic_attr_info);
- }
-
- return _XimDecodeAttr(info, num, res, top, val);
-}
-
-Public char *
-_XimGetICValueData(Xic ic, XPointer top, XIMResourceList res_list,
- unsigned int list_num, XIMArg *values, unsigned long mode)
-{
- register XIMArg *p;
- XIMResourceList res;
- char *name;
- int check;
- XrmQuark pre_quark;
- XrmQuark sts_quark;
-
- pre_quark = XrmStringToQuark(XNPreeditAttributes);
- sts_quark = XrmStringToQuark(XNStatusAttributes);
-
- for(p = values; p->name != NULL; p++) {
- if((res = _XimGetResourceListRec(res_list, list_num,
- p->name)) == (XIMResourceList)NULL) {
- return p->name;
- }
- if(res->xrm_name == pre_quark) {
- if((name = _XimGetICValueData(ic,
- (XPointer)(&((XimDefICValues *)top)->preedit_attr),
- res_list, list_num, (XIMArg *)p->value,
- (mode | XIM_PREEDIT_ATTR)))) {
- return name;
- }
- } else if(res->xrm_name == sts_quark) {
- if((name = _XimGetICValueData(ic,
- (XPointer)(&((XimDefICValues *)top)->status_attr),
- res_list, list_num, (XIMArg *)p->value,
- (mode | XIM_STATUS_ATTR)))) {
- return name;
- }
- } else {
- check = _XimCheckICMode(res, mode);
- if(check == XIM_CHECK_INVALID) {
- continue;
- } else if(check == XIM_CHECK_ERROR) {
- return p->name;
- }
-
- if(_XimDecodeLocalICAttr(res, top, p->value, mode) == False) {
- return p->name;
- }
- }
- }
- return NULL;
-}
-
-Public void
-_XimGetCurrentIMValues(Xim im, XimDefIMValues *im_values)
-{
- bzero((char *)im_values, sizeof(XimDefIMValues));
-
- im_values->styles = im->core.styles;
- im_values->im_values_list = im->core.im_values_list;
- im_values->ic_values_list = im->core.ic_values_list;
- im_values->destroy_callback = im->core.destroy_callback;
- im_values->res_name = im->core.res_name;
- im_values->res_class = im->core.res_class;
- im_values->visible_position = im->core.visible_position;
-}
-
-Public void
-_XimSetCurrentIMValues(Xim im, XimDefIMValues *im_values)
-{
- im->core.styles = im_values->styles;
- im->core.im_values_list = im_values->im_values_list;
- im->core.ic_values_list = im_values->ic_values_list;
- im->core.destroy_callback = im_values->destroy_callback;
- im->core.res_name = im_values->res_name;
- im->core.res_class = im_values->res_class;
- im->core.visible_position = im_values->visible_position;
-}
-
-Public void
-_XimGetCurrentICValues(Xic ic, XimDefICValues *ic_values)
-{
- bzero((char *)ic_values, sizeof(XimDefICValues));
-
- ic_values->input_style = ic->core.input_style;
- ic_values->client_window = ic->core.client_window;
- ic_values->focus_window = ic->core.focus_window;
- ic_values->filter_events = ic->core.filter_events;
- ic_values->geometry_callback = ic->core.geometry_callback;
- ic_values->res_name = ic->core.res_name;
- ic_values->res_class = ic->core.res_class;
- ic_values->destroy_callback = ic->core.destroy_callback;
- ic_values->string_conversion_callback
- = ic->core.string_conversion_callback;
- ic_values->string_conversion = ic->core.string_conversion;
- ic_values->reset_state = ic->core.reset_state;
- ic_values->hotkey = ic->core.hotkey;
- ic_values->hotkey_state = ic->core.hotkey_state;
- ic_values->preedit_attr = ic->core.preedit_attr;
- ic_values->status_attr = ic->core.status_attr;
-}
-
-Public void
-_XimSetCurrentICValues(
- Xic ic,
- XimDefICValues *ic_values)
-{
- ic->core.input_style = ic_values->input_style;
- ic->core.client_window = ic_values->client_window;
- if (ic_values->focus_window)
- ic->core.focus_window = ic_values->focus_window;
- ic->core.filter_events = ic_values->filter_events;
- ic->core.geometry_callback = ic_values->geometry_callback;
- ic->core.res_name = ic_values->res_name;
- ic->core.res_class = ic_values->res_class;
- ic->core.destroy_callback = ic_values->destroy_callback;
- ic->core.string_conversion_callback
- = ic_values->string_conversion_callback;
- ic->core.string_conversion = ic_values->string_conversion;
- ic->core.reset_state = ic_values->reset_state;
- ic->core.hotkey = ic_values->hotkey;
- ic->core.hotkey_state = ic_values->hotkey_state;
- ic->core.preedit_attr = ic_values->preedit_attr;
- ic->core.status_attr = ic_values->status_attr;
-}
-
-Private void
-_XimInitialIMOffsetInfo(void)
-{
- unsigned int n = XIMNumber(im_attr_info);
- register int i;
-
- for(i = 0; i < n; i++) {
- im_attr_info[i].quark = XrmStringToQuark(GET_NAME(im_attr_info[i]));
- }
-}
-
-Private void
-_XimInitialICOffsetInfo(void)
-{
- unsigned int n;
- register int i;
-
- n = XIMNumber(ic_attr_info);
- for(i = 0; i < n; i++) {
- ic_attr_info[i].quark = XrmStringToQuark(GET_NAME(ic_attr_info[i]));
- }
-
- n = XIMNumber(ic_pre_attr_info);
- for(i = 0; i < n; i++) {
- ic_pre_attr_info[i].quark = XrmStringToQuark(GET_NAME(ic_pre_attr_info[i]));
- }
-
- n = XIMNumber(ic_sts_attr_info);
- for(i = 0; i < n; i++) {
- ic_sts_attr_info[i].quark = XrmStringToQuark(GET_NAME(ic_sts_attr_info[i]));
- }
-}
-
-Private void
-_XimInitialIMMode(void)
-{
- unsigned int n = XIMNumber(im_mode);
- register int i;
-
- for(i = 0; i < n; i++) {
- im_mode_quark[i] = XrmStringToQuark(GET_NAME(im_mode[i]));
- }
-}
-
-Private void
-_XimInitialICMode(void)
-{
- unsigned int n = XIMNumber(ic_mode);
- register int i;
-
- for(i = 0; i < n; i++) {
- ic_mode_quark[i] = XrmStringToQuark(GET_NAME(ic_mode[i]));
- }
-}
-
-Public void
-_XimInitialResourceInfo(void)
-{
- static Bool init_flag = False;
-
- if(init_flag == True) {
- return;
- }
- _XimInitialIMOffsetInfo();
- _XimInitialICOffsetInfo();
- _XimInitialIMMode();
- _XimInitialICMode();
- init_flag = True;
-}
+/******************************************************************
+
+ Copyright 1990, 1991, 1992,1993, 1994 by FUJITSU LIMITED
+ Copyright 1994 by Sony Corporation
+
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of FUJITSU LIMITED
+and Sony Corporation not be used in advertising or publicity
+pertaining to distribution of the software without specific,
+written prior permission. FUJITSU LIMITED and Sony Corporation make
+no representations about the suitability of this software for any
+purpose. It is provided "as is" without express or implied warranty.
+
+FUJITSU LIMITED AND SONY CORPORATION DISCLAIM ALL WARRANTIES WITH
+REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJITSU LIMITED AND
+SONY CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+ Author: Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+ Modifier: Makoto Wakamatsu Sony Corporation
+ makoto@sm.sony.co.jp
+
+******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include <X11/Xlib.h>
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "Ximint.h"
+#include "Xresource.h"
+
+#define GET_NAME(x) name_table + x.name_offset
+
+typedef struct _XimValueOffsetInfo {
+ unsigned short name_offset;
+ XrmQuark quark;
+ unsigned int offset;
+ Bool (*defaults)(
+ struct _XimValueOffsetInfo *, XPointer, XPointer, unsigned long
+ );
+ Bool (*encode)(
+ struct _XimValueOffsetInfo *, XPointer, XPointer
+ );
+ Bool (*decode)(
+ struct _XimValueOffsetInfo *, XPointer, XPointer
+ );
+} XimValueOffsetInfoRec, *XimValueOffsetInfo;
+
+#ifdef XIM_CONNECTABLE
+Private Bool
+_XimCheckBool(str)
+ char *str;
+{
+ if(!strcmp(str, "True") || !strcmp(str, "true") ||
+ !strcmp(str, "Yes") || !strcmp(str, "yes") ||
+ !strcmp(str, "ON") || !strcmp(str, "on"))
+ return True;
+ return False;
+}
+
+Public void
+_XimSetProtoResource(im)
+ Xim im;
+{
+ char res_name_buf[256];
+ char* res_name;
+ char res_class_buf[256];
+ char* res_class;
+ char* str_type;
+ XrmValue value;
+ XIMStyle preedit_style = 0;
+ XIMStyle status_style = 0;
+ XIMStyles* imstyles;
+ char* dotximdot = ".xim.";
+ char* ximdot = "xim.";
+ char* dotXimdot = ".Xim.";
+ char* Ximdot = "Xim.";
+
+ if (!im->core.rdb)
+ return;
+
+ if (strlen (im->core.res_name) < 200) res_name = res_name_buf;
+ else res_name = Xmalloc (strlen (im->core.res_name) + 50);
+ if (strlen (im->core.res_class) < 200) res_class = res_class_buf;
+ else res_class = Xmalloc (strlen (im->core.res_class) + 50);
+ /* pretend malloc always works */
+
+ (void) sprintf (res_name, "%s%s%s",
+ im->core.res_name != NULL ? im->core.res_name : "*",
+ im->core.res_name != NULL ? dotximdot : ximdot,
+ "useAuth");
+ (void) sprintf (res_class, "%s%s%s",
+ im->core.res_class != NULL ? im->core.res_class : "*",
+ im->core.res_class != NULL ? dotXimdot : Ximdot,
+ "UseAuth");
+ bzero(&value, sizeof(XrmValue));
+ if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
+ if(_XimCheckBool(value.addr)) {
+ MARK_USE_AUTHORIZATION_FUNC(im);
+ }
+ }
+
+ (void) sprintf (res_name, "%s%s%s",
+ im->core.res_name != NULL ? im->core.res_name : "*",
+ im->core.res_name != NULL ? dotximdot : ximdot,
+ "delaybinding");
+ (void) sprintf (res_class, "%s%s%s",
+ im->core.res_class != NULL ? im->core.res_class : "*",
+ im->core.res_class != NULL ? dotXimdot : Ximdot,
+ "Delaybinding");
+ bzero(&value, sizeof(XrmValue));
+ if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
+ if(_XimCheckBool(value.addr)) {
+ MARK_DELAYBINDABLE(im);
+ }
+ }
+
+ (void) sprintf (res_name, "%s%s%s",
+ im->core.res_name != NULL ? im->core.res_name : "*",
+ im->core.res_name != NULL ? dotximdot : ximdot,
+ "reconnect");
+ (void) sprintf (res_class, "%s%s%s",
+ im->core.res_class != NULL ? im->core.res_class : "*",
+ im->core.res_class != NULL ? dotXimdot : Ximdot,
+ "Reconnect");
+ bzero(&value, sizeof(XrmValue));
+ if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
+ if(_XimCheckBool(value.addr)) {
+ MARK_RECONNECTABLE(im);
+ }
+ }
+
+ if(!IS_CONNECTABLE(im)) {
+ if (res_name != res_name_buf) Xfree (res_name);
+ if (res_class != res_class_buf) Xfree (res_class);
+ return;
+ }
+
+ (void) sprintf (res_name, "%s%s%s",
+ im->core.res_name != NULL ? im->core.res_name : "*",
+ im->core.res_name != NULL ? dotximdot : ximdot,
+ "preeditDefaultStyle");
+ (void) sprintf (res_class, "%s%s%s",
+ im->core.res_class != NULL ? im->core.res_class : "*",
+ im->core.res_class != NULL ? dotXimdot : Ximdot,
+ "PreeditDefaultStyle");
+ if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
+ if(!strcmp(value.addr, "XIMPreeditArea"))
+ preedit_style = XIMPreeditArea;
+ else if(!strcmp(value.addr, "XIMPreeditCallbacks"))
+ preedit_style = XIMPreeditCallbacks;
+ else if(!strcmp(value.addr, "XIMPreeditPosition"))
+ preedit_style = XIMPreeditPosition;
+ else if(!strcmp(value.addr, "XIMPreeditNothing"))
+ preedit_style = XIMPreeditNothing;
+ else if(!strcmp(value.addr, "XIMPreeditNone"))
+ preedit_style = XIMPreeditNone;
+ }
+ if(!preedit_style)
+ preedit_style = XIMPreeditNothing;
+
+ (void) sprintf (res_name, "%s%s%s",
+ im->core.res_name != NULL ? im->core.res_name : "*",
+ im->core.res_name != NULL ? dotximdot : ximdot,
+ "statusDefaultStyle");
+ (void) sprintf (res_class, "%s%s%s",
+ im->core.res_class != NULL ? im->core.res_class : "*",
+ im->core.res_class != NULL ? dotXimdot : Ximdot,
+ "StatusDefaultStyle");
+ if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
+ if(!strcmp(value.addr, "XIMStatusArea"))
+ status_style = XIMStatusArea;
+ else if(!strcmp(value.addr, "XIMStatusCallbacks"))
+ status_style = XIMStatusCallbacks;
+ else if(!strcmp(value.addr, "XIMStatusNothing"))
+ status_style = XIMStatusNothing;
+ else if(!strcmp(value.addr, "XIMStatusNone"))
+ status_style = XIMStatusNone;
+ }
+ if(!status_style)
+ status_style = XIMStatusNothing;
+
+ if(!(imstyles = (XIMStyles *)Xmalloc(sizeof(XIMStyles) + sizeof(XIMStyle)))){
+ if (res_name != res_name_buf) Xfree (res_name);
+ if (res_class != res_class_buf) Xfree (res_class);
+ return;
+ }
+ imstyles->count_styles = 1;
+ imstyles->supported_styles =
+ (XIMStyle *)((char *)imstyles + sizeof(XIMStyles));
+ imstyles->supported_styles[0] = preedit_style | status_style;
+ im->private.proto.default_styles = imstyles;
+ if (res_name != res_name_buf) Xfree (res_name);
+ if (res_class != res_class_buf) Xfree (res_class);
+}
+#endif /* XIM_CONNECTABLE */
+
+static const char name_table[] =
+ /* 0 */ XNQueryInputStyle"\0"
+ /* 16 */ XNClientWindow"\0"
+ /* 29 */ XNInputStyle"\0"
+ /* 40 */ XNFocusWindow"\0"
+ /* 52 */ XNResourceName"\0"
+ /* 65 */ XNResourceClass"\0"
+ /* 79 */ XNGeometryCallback"\0"
+ /* 96 */ XNDestroyCallback"\0"
+ /* 112 */ XNFilterEvents"\0"
+ /* 125 */ XNPreeditStartCallback"\0"
+ /* 146 */ XNPreeditDoneCallback"\0"
+ /* 166 */ XNPreeditDrawCallback"\0"
+ /* 186 */ XNPreeditCaretCallback"\0"
+ /* 207 */ XNPreeditStateNotifyCallback"\0"
+ /* 234 */ XNPreeditAttributes"\0"
+ /* 252 */ XNStatusStartCallback"\0"
+ /* 272 */ XNStatusDoneCallback"\0"
+ /* 291 */ XNStatusDrawCallback"\0"
+ /* 310 */ XNStatusAttributes"\0"
+ /* 327 */ XNArea"\0"
+ /* 332 */ XNAreaNeeded"\0"
+ /* 343 */ XNSpotLocation"\0"
+ /* 356 */ XNColormap"\0"
+ /* 365 */ XNStdColormap"\0"
+ /* 377 */ XNForeground"\0"
+ /* 388 */ XNBackground"\0"
+ /* 399 */ XNBackgroundPixmap"\0"
+ /* 416 */ XNFontSet"\0"
+ /* 424 */ XNLineSpace"\0"
+ /* 434 */ XNCursor"\0"
+ /* 441 */ XNQueryIMValuesList"\0"
+ /* 459 */ XNQueryICValuesList"\0"
+ /* 477 */ XNVisiblePosition"\0"
+ /* 493 */ XNStringConversionCallback"\0"
+ /* 518 */ XNStringConversion"\0"
+ /* 535 */ XNResetState"\0"
+ /* 546 */ XNHotKey"\0"
+ /* 553 */ XNHotKeyState"\0"
+ /* 565 */ XNPreeditState
+;
+
+#define OFFSET_XNQUERYINPUTSTYLE 0
+#define OFFSET_XNCLIENTWINDOW 16
+#define OFFSET_XNINPUTSTYLE 29
+#define OFFSET_XNFOCUSWINDOW 40
+#define OFFSET_XNRESOURCENAME 52
+#define OFFSET_XNRESOURCECLASS 65
+#define OFFSET_XNGEOMETRYCALLBACK 79
+#define OFFSET_XNDESTROYCALLBACK 96
+#define OFFSET_XNFILTEREVENTS 112
+#define OFFSET_XNPREEDITSTARTCALLBACK 125
+#define OFFSET_XNPREEDITDONECALLBACK 146
+#define OFFSET_XNPREEDITDRAWCALLBACK 166
+#define OFFSET_XNPREEDITCARETCALLBACK 186
+#define OFFSET_XNPREEDITSTATENOTIFYCALLBACK 207
+#define OFFSET_XNPREEDITATTRIBUTES 234
+#define OFFSET_XNSTATUSSTARTCALLBACK 252
+#define OFFSET_XNSTATUSDONECALLBACK 272
+#define OFFSET_XNSTATUSDRAWCALLBACK 291
+#define OFFSET_XNSTATUSATTRIBUTES 310
+#define OFFSET_XNAREA 327
+#define OFFSET_XNAREANEEDED 332
+#define OFFSET_XNSPOTLOCATION 343
+#define OFFSET_XNCOLORMAP 356
+#define OFFSET_XNSTDCOLORMAP 365
+#define OFFSET_XNFOREGROUND 377
+#define OFFSET_XNBACKGROUND 388
+#define OFFSET_XNBACKGROUNDPIXMAP 399
+#define OFFSET_XNFONTSET 416
+#define OFFSET_XNLINESPACE 424
+#define OFFSET_XNCURSOR 434
+#define OFFSET_XNQUERYIMVALUESLIST 441
+#define OFFSET_XNQUERYICVALUESLIST 459
+#define OFFSET_XNVISIBLEPOSITION 477
+#define OFFSET_XNSTRINGCONVERSIONCALLBACK 493
+#define OFFSET_XNSTRINGCONVERSION 518
+#define OFFSET_XNRESETSTATE 535
+#define OFFSET_XNHOTKEY 546
+#define OFFSET_XNHOTKEYSTATE 553
+#define OFFSET_XNPREEDITSTATE 565
+
+/* offsets into name_table */
+static const unsigned short supported_local_im_values_list[] = {
+ OFFSET_XNQUERYINPUTSTYLE,
+ OFFSET_XNRESOURCENAME,
+ OFFSET_XNRESOURCECLASS,
+ OFFSET_XNDESTROYCALLBACK,
+ OFFSET_XNQUERYIMVALUESLIST,
+ OFFSET_XNQUERYICVALUESLIST,
+ OFFSET_XNVISIBLEPOSITION
+};
+
+/* offsets into name_table */
+static const unsigned short supported_local_ic_values_list[] = {
+ OFFSET_XNINPUTSTYLE,
+ OFFSET_XNCLIENTWINDOW,
+ OFFSET_XNFOCUSWINDOW,
+ OFFSET_XNRESOURCENAME,
+ OFFSET_XNRESOURCECLASS,
+ OFFSET_XNGEOMETRYCALLBACK,
+ OFFSET_XNFILTEREVENTS,
+ OFFSET_XNDESTROYCALLBACK,
+ OFFSET_XNSTRINGCONVERSIONCALLBACK,
+ OFFSET_XNSTRINGCONVERSIONCALLBACK,
+ OFFSET_XNRESETSTATE,
+ OFFSET_XNHOTKEY,
+ OFFSET_XNHOTKEYSTATE,
+ OFFSET_XNPREEDITATTRIBUTES,
+ OFFSET_XNSTATUSATTRIBUTES,
+ OFFSET_XNAREA,
+ OFFSET_XNAREANEEDED,
+ OFFSET_XNSPOTLOCATION,
+ OFFSET_XNCOLORMAP,
+ OFFSET_XNSTDCOLORMAP,
+ OFFSET_XNFOREGROUND,
+ OFFSET_XNBACKGROUND,
+ OFFSET_XNBACKGROUNDPIXMAP,
+ OFFSET_XNFONTSET,
+ OFFSET_XNLINESPACE,
+ OFFSET_XNCURSOR,
+ OFFSET_XNPREEDITSTARTCALLBACK,
+ OFFSET_XNPREEDITDONECALLBACK,
+ OFFSET_XNPREEDITDRAWCALLBACK,
+ OFFSET_XNPREEDITCARETCALLBACK,
+ OFFSET_XNSTATUSSTARTCALLBACK,
+ OFFSET_XNSTATUSDONECALLBACK,
+ OFFSET_XNSTATUSDRAWCALLBACK,
+ OFFSET_XNPREEDITSTATE,
+ OFFSET_XNPREEDITSTATENOTIFYCALLBACK
+};
+
+static XIMStyle const supported_local_styles[] = {
+ XIMPreeditNone | XIMStatusNone,
+ XIMPreeditNothing | XIMStatusNothing,
+ 0 /* dummy */
+};
+
+Private Bool
+_XimDefaultStyles(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm, /* unused */
+ unsigned long mode) /* unused */
+{
+ XIMStyles *styles;
+ XIMStyles **out;
+ register int i;
+ unsigned int n;
+ int len;
+ XPointer tmp;
+
+ n = XIMNumber(supported_local_styles) - 1;
+ len = sizeof(XIMStyles) + sizeof(XIMStyle) * n;
+ if(!(tmp = Xcalloc(1, len))) {
+ return False;
+ }
+
+ styles = (XIMStyles *)tmp;
+ if (n > 0) {
+ styles->count_styles = (unsigned short)n;
+ styles->supported_styles =
+ (XIMStyle *)((char *)tmp + sizeof(XIMStyles));
+ for(i = 0; i < n; i++) {
+ styles->supported_styles[i] = supported_local_styles[i];
+ }
+ }
+
+ out = (XIMStyles **)((char *)top + info->offset);
+ *out = styles;
+ return True;
+}
+
+Private Bool
+_XimDefaultIMValues(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm, /* unused */
+ unsigned long mode) /* unused */
+{
+ XIMValuesList *values_list;
+ XIMValuesList **out;
+ register int i;
+ unsigned int n;
+ int len;
+ XPointer tmp;
+
+ n = XIMNumber(supported_local_im_values_list);
+ len = sizeof(XIMValuesList) + sizeof(char **) * n;
+ if(!(tmp = Xcalloc(1, len))) {
+ return False;
+ }
+
+ values_list = (XIMValuesList *)tmp;
+ if (n > 0) {
+ values_list->count_values = (unsigned short)n;
+ values_list->supported_values
+ = (char **)((char *)tmp + sizeof(XIMValuesList));
+ for(i = 0; i < n; i++) {
+ values_list->supported_values[i] =
+ (char *)name_table + supported_local_im_values_list[i];
+ }
+ }
+
+ out = (XIMValuesList **)((char *)top + info->offset);
+ *out = values_list;
+ return True;
+}
+
+Private Bool
+_XimDefaultICValues(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm, /* unused */
+ unsigned long mode) /* unused */
+{
+ XIMValuesList *values_list;
+ XIMValuesList **out;
+ register int i;
+ unsigned int n;
+ int len;
+ XPointer tmp;
+
+ n = XIMNumber(supported_local_ic_values_list);
+ len = sizeof(XIMValuesList) + sizeof(char **) * n;
+ if(!(tmp = Xcalloc(1, len))) {
+ return False;
+ }
+
+ values_list = (XIMValuesList *)tmp;
+ if (n > 0) {
+ values_list->count_values = (unsigned short)n;
+ values_list->supported_values
+ = (char **)((char *)tmp + sizeof(XIMValuesList));
+ for(i = 0; i < n; i++) {
+ values_list->supported_values[i] =
+ (char *)name_table + supported_local_ic_values_list[i];
+ }
+ }
+
+ out = (XIMValuesList **)((char *)top + info->offset);
+ *out = values_list;
+ return True;
+}
+
+Private Bool
+_XimDefaultVisiblePos(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm, /* unused */
+ unsigned long mode) /* unused */
+{
+ Bool *out;
+
+ out = (Bool *)((char *)top + info->offset);
+ *out = False;
+ return True;
+}
+
+Private Bool
+_XimDefaultFocusWindow(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Xic ic = (Xic)parm;
+ Window *out;
+
+ if(ic->core.client_window == (Window)NULL) {
+ return True;
+ }
+
+ out = (Window *)((char *)top + info->offset);
+ *out = ic->core.client_window;
+ return True;
+}
+
+Private Bool
+_XimDefaultResName(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Xic ic = (Xic)parm;
+ Xim im = (Xim)ic->core.im;
+ char **out;
+
+ if(im->core.res_name == (char *)NULL) {
+ return True;
+ }
+
+ out = (char **)((char *)top + info->offset);
+ *out = im->core.res_name;
+ return True;
+}
+
+Private Bool
+_XimDefaultResClass(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Xic ic = (Xic)parm;
+ Xim im = (Xim)ic->core.im;
+ char **out;
+
+ if(im->core.res_class == (char *)NULL) {
+ return True;
+ }
+
+ out = (char **)((char *)top + info->offset);
+ *out = im->core.res_class;
+ return True;
+}
+
+Private Bool
+_XimDefaultDestroyCB(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Xic ic = (Xic)parm;
+ Xim im = (Xim)ic->core.im;
+ XIMCallback *out;
+
+ out = (XIMCallback *)((char *)top + info->offset);
+ *out = im->core.destroy_callback;
+ return True;
+}
+
+Private Bool
+_XimDefaultResetState(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ XIMResetState *out;
+
+ out = (XIMResetState *)((char *)top + info->offset);
+ *out = XIMInitialState;
+ return True;
+}
+
+Private Bool
+_XimDefaultHotKeyState(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ XIMHotKeyState *out;
+
+ out = (XIMHotKeyState *)((char *)top + info->offset);
+ *out = XIMHotKeyStateOFF;
+ return True;
+}
+
+Private Bool
+_XimDefaultArea(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Xic ic = (Xic)parm;
+ Xim im = (Xim)ic->core.im;
+ Window root_return;
+ int x_return, y_return;
+ unsigned int width_return, height_return;
+ unsigned int border_width_return;
+ unsigned int depth_return;
+ XRectangle area;
+ XRectangle *out;
+
+ if(ic->core.focus_window == (Window)NULL) {
+ return True;
+ }
+ if(XGetGeometry(im->core.display, (Drawable)ic->core.focus_window,
+ &root_return, &x_return, &y_return, &width_return,
+ &height_return, &border_width_return, &depth_return)
+ == (Status)Success) {
+ return True;
+ }
+ area.x = 0;
+ area.y = 0;
+ area.width = width_return;
+ area.height = height_return;
+
+ out = (XRectangle *)((char *)top + info->offset);
+ *out = area;
+ return True;
+}
+
+Private Bool
+_XimDefaultColormap(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Xic ic = (Xic)parm;
+ Xim im = (Xim)ic->core.im;
+ XWindowAttributes win_attr;
+ Colormap *out;
+
+ if(ic->core.client_window == (Window)NULL) {
+ return True;
+ }
+ if(XGetWindowAttributes(im->core.display, ic->core.client_window,
+ &win_attr) == (Status)Success) {
+ return True;
+ }
+
+ out = (Colormap *)((char *)top + info->offset);
+ *out = win_attr.colormap;
+ return True;
+}
+
+Private Bool
+_XimDefaultStdColormap(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Atom *out;
+
+ out = (Atom *)((char *)top + info->offset);
+ *out = (Atom)0;
+ return True;
+}
+
+Private Bool
+_XimDefaultFg(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Xic ic = (Xic)parm;
+ Xim im = (Xim)ic->core.im;
+ unsigned long fg;
+ unsigned long *out;
+
+ fg = WhitePixel(im->core.display, DefaultScreen(im->core.display));
+ out = (unsigned long *)((char *)top + info->offset);
+ *out = fg;
+ return True;
+}
+
+Private Bool
+_XimDefaultBg(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Xic ic = (Xic)parm;
+ Xim im = (Xim)ic->core.im;
+ unsigned long bg;
+ unsigned long *out;
+
+ bg = BlackPixel(im->core.display, DefaultScreen(im->core.display));
+ out = (unsigned long *)((char *)top + info->offset);
+ *out = bg;
+ return True;
+}
+
+Private Bool
+_XimDefaultBgPixmap(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Pixmap *out;
+
+ out = (Pixmap *)((char *)top + info->offset);
+ *out = (Pixmap)0;
+ return True;
+}
+
+Private Bool
+_XimDefaultFontSet(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ XFontSet *out;
+
+ out = (XFontSet *)((char *)top + info->offset);
+ *out = 0;
+ return True;
+}
+
+Private Bool
+_XimDefaultLineSpace(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Xic ic = (Xic)parm;
+ XFontSet fontset;
+ XFontSetExtents *fset_extents;
+ int line_space = 0;
+ int *out;
+
+ if(mode & XIM_PREEDIT_ATTR) {
+ fontset = ic->core.preedit_attr.fontset;
+ } else if(mode & XIM_STATUS_ATTR) {
+ fontset = ic->core.status_attr.fontset;
+ } else {
+ return True;
+ }
+ if (fontset) {
+ fset_extents = XExtentsOfFontSet(fontset);
+ line_space = fset_extents->max_logical_extent.height;
+ }
+ out = (int *)((char *)top + info->offset);
+ *out = line_space;
+ return True;
+}
+
+Private Bool
+_XimDefaultCursor(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ Cursor *out;
+
+ out = (Cursor *)((char *)top + info->offset);
+ *out = (Cursor)0;
+ return True;
+}
+
+Private Bool
+_XimDefaultPreeditState(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ XIMPreeditState *out;
+
+ out = (XIMPreeditState *)((char *)top + info->offset);
+ *out = XIMPreeditDisable;
+ return True;
+}
+
+Private Bool
+_XimDefaultNest(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer parm,
+ unsigned long mode)
+{
+ return True;
+}
+
+Private Bool
+_XimEncodeCallback(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMCallback *out;
+
+ out = (XIMCallback *)((char *)top + info->offset);
+ *out = *((XIMCallback *)val);
+ return True;
+}
+
+Private Bool
+_XimEncodeString(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ char *string;
+ char **out;
+
+ if(val == (XPointer)NULL) {
+ return False;
+ }
+ if (!(string = strdup((char *)val))) {
+ return False;
+ }
+
+ out = (char **)((char *)top + info->offset);
+ if(*out) {
+ Xfree(*out);
+ }
+ *out = string;
+ return True;
+}
+
+Private Bool
+_XimEncodeStyle(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMStyle *out;
+
+ out = (XIMStyle *)((char *)top + info->offset);
+ *out = (XIMStyle)val;
+ return True;
+}
+
+Private Bool
+_XimEncodeWindow(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ Window *out;
+
+ out = (Window *)((char *)top + info->offset);
+ *out = (Window)val;
+ return True;
+}
+
+Private Bool
+_XimEncodeStringConv(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ /*
+ * Not yet
+ */
+ return True;
+}
+
+Private Bool
+_XimEncodeResetState(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMResetState *out;
+
+ out = (XIMResetState *)((char *)top + info->offset);
+ *out = (XIMResetState)val;
+ return True;
+}
+
+Private Bool
+_XimEncodeHotKey(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMHotKeyTriggers *hotkey = (XIMHotKeyTriggers *)val;
+ XIMHotKeyTriggers **out;
+ XIMHotKeyTriggers *key_list;
+ XIMHotKeyTrigger *key;
+ XPointer tmp;
+ int num;
+ int len;
+ register int i;
+
+ if(hotkey == (XIMHotKeyTriggers *)NULL) {
+ return True;
+ }
+
+ if((num = hotkey->num_hot_key) == 0) {
+ return True;
+ }
+
+ len = sizeof(XIMHotKeyTriggers) + sizeof(XIMHotKeyTrigger) * num;
+ if(!(tmp = (XPointer)Xmalloc(len))) {
+ return False;
+ }
+
+ key_list = (XIMHotKeyTriggers *)tmp;
+ key = (XIMHotKeyTrigger *)((char *)tmp + sizeof(XIMHotKeyTriggers));
+
+ for(i = 0; i < num; i++) {
+ key[i] = hotkey->key[i];
+ }
+
+ key_list->num_hot_key = num;
+ key_list->key = key;
+
+ out = (XIMHotKeyTriggers **)((char *)top + info->offset);
+ *out = key_list;
+ return True;
+}
+
+Private Bool
+_XimEncodeHotKetState(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMHotKeyState *out;
+
+ out = (XIMHotKeyState *)((char *)top + info->offset);
+ *out = (XIMHotKeyState)val;
+ return True;
+}
+
+Private Bool
+_XimEncodeRectangle(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XRectangle *out;
+
+ out = (XRectangle *)((char *)top + info->offset);
+ *out = *((XRectangle *)val);
+ return True;
+}
+
+Private Bool
+_XimEncodeSpot(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XPoint *out;
+
+ out = (XPoint *)((char *)top + info->offset);
+ *out = *((XPoint *)val);
+ return True;
+}
+
+Private Bool
+_XimEncodeColormap(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ Colormap *out;
+
+ out = (Colormap *)((char *)top + info->offset);
+ *out = (Colormap)val;
+ return True;
+}
+
+Private Bool
+_XimEncodeStdColormap(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ Atom *out;
+
+ out = (Atom *)((char *)top + info->offset);
+ *out = (Atom)val;
+ return True;
+}
+
+Private Bool
+_XimEncodeLong(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ unsigned long *out;
+
+ out = (unsigned long *)((char *)top + info->offset);
+ *out = (unsigned long)val;
+ return True;
+}
+
+Private Bool
+_XimEncodeBgPixmap(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ Pixmap *out;
+
+ out = (Pixmap *)((char *)top + info->offset);
+ *out = (Pixmap)val;
+ return True;
+}
+
+Private Bool
+_XimEncodeFontSet(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XFontSet *out;
+
+ out = (XFontSet *)((char *)top + info->offset);
+ *out = (XFontSet)val;
+ return True;
+}
+
+Private Bool
+_XimEncodeLineSpace(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ int *out;
+
+ out = (int *)((char *)top + info->offset);
+ *out = (long)val;
+ return True;
+}
+
+Private Bool
+_XimEncodeCursor(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ Cursor *out;
+
+ out = (Cursor *)((char *)top + info->offset);
+ *out = (Cursor)val;
+ return True;
+}
+
+Private Bool
+_XimEncodePreeditState(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMPreeditState *out;
+
+ out = (XIMPreeditState *)((char *)top + info->offset);
+ *out = (XIMPreeditState)val;
+ return True;
+}
+
+Private Bool
+_XimEncodeNest(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ return True;
+}
+
+Private Bool
+_XimDecodeStyles(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMStyles *styles;
+ XIMStyles *out;
+ register int i;
+ unsigned int num;
+ int len;
+ XPointer tmp;
+
+ if(val == (XPointer)NULL) {
+ return False;
+ }
+
+ styles = *((XIMStyles **)((char *)top + info->offset));
+ num = styles->count_styles;
+
+ len = sizeof(XIMStyles) + sizeof(XIMStyle) * num;
+ if(!(tmp = Xcalloc(1, len))) {
+ return False;
+ }
+
+ out = (XIMStyles *)tmp;
+ if(num >0) {
+ out->count_styles = (unsigned short)num;
+ out->supported_styles = (XIMStyle *)((char *)tmp + sizeof(XIMStyles));
+
+ for(i = 0; i < num; i++) {
+ out->supported_styles[i] = styles->supported_styles[i];
+ }
+ }
+ *((XIMStyles **)val) = out;
+ return True;
+}
+
+Private Bool
+_XimDecodeValues(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMValuesList *values_list;
+ XIMValuesList *out;
+ register int i;
+ unsigned int num;
+ int len;
+ XPointer tmp;
+
+ if(val == (XPointer)NULL) {
+ return False;
+ }
+
+ values_list = *((XIMValuesList **)((char *)top + info->offset));
+ num = values_list->count_values;
+
+ len = sizeof(XIMValuesList) + sizeof(char **) * num;
+ if(!(tmp = Xcalloc(1, len))) {
+ return False;
+ }
+
+ out = (XIMValuesList *)tmp;
+ if(num) {
+ out->count_values = (unsigned short)num;
+ out->supported_values = (char **)((char *)tmp + sizeof(XIMValuesList));
+
+ for(i = 0; i < num; i++) {
+ out->supported_values[i] = values_list->supported_values[i];
+ }
+ }
+ *((XIMValuesList **)val) = out;
+ return True;
+}
+
+Private Bool
+_XimDecodeCallback(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMCallback *in;
+ XIMCallback *callback;
+
+ in = (XIMCallback *)((char *)top + info->offset);
+ if(!(callback = (XIMCallback *)Xmalloc(sizeof(XIMCallback)))) {
+ return False;
+ }
+ callback->client_data = in->client_data;
+ callback->callback = in->callback;
+
+ *((XIMCallback **)val) = callback;
+ return True;
+}
+
+Private Bool
+_XimDecodeString(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ char *in;
+ char *string;
+
+ in = *((char **)((char *)top + info->offset));
+ if (in != NULL) {
+ string = strdup(in);
+ } else {
+ string = Xcalloc(1, 1); /* strdup("") */
+ }
+ if (string == NULL) {
+ return False;
+ }
+ *((char **)val) = string;
+ return True;
+}
+
+Private Bool
+_XimDecodeBool(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ Bool *in;
+
+ in = (Bool *)((char *)top + info->offset);
+ *((Bool *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeStyle(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMStyle *in;
+
+ in = (XIMStyle *)((char *)top + info->offset);
+ *((XIMStyle *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeWindow(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ Window *in;
+
+ in = (Window *)((char *)top + info->offset);
+ *((Window *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeStringConv(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ /*
+ * Not yet
+ */
+ return True;
+}
+
+Private Bool
+_XimDecodeResetState(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMResetState *in;
+
+ in = (XIMResetState *)((char *)top + info->offset);
+ *((XIMResetState *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeHotKey(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMHotKeyTriggers *in;
+ XIMHotKeyTriggers *hotkey;
+ XIMHotKeyTrigger *key;
+ XPointer tmp;
+ int num;
+ int len;
+ register int i;
+
+ in = *((XIMHotKeyTriggers **)((char *)top + info->offset));
+ num = in->num_hot_key;
+ len = sizeof(XIMHotKeyTriggers) + sizeof(XIMHotKeyTrigger) * num;
+ if(!(tmp = (XPointer)Xmalloc(len))) {
+ return False;
+ }
+
+ hotkey = (XIMHotKeyTriggers *)tmp;
+ key = (XIMHotKeyTrigger *)((char *)tmp + sizeof(XIMHotKeyTriggers));
+
+ for(i = 0; i < num; i++) {
+ key[i] = in->key[i];
+ }
+ hotkey->num_hot_key = num;
+ hotkey->key = key;
+
+ *((XIMHotKeyTriggers **)val) = hotkey;
+ return True;
+}
+
+Private Bool
+_XimDecodeHotKetState(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMHotKeyState *in;
+
+ in = (XIMHotKeyState *)((char *)top + info->offset);
+ *((XIMHotKeyState *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeRectangle(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XRectangle *in;
+ XRectangle *rect;
+
+ in = (XRectangle *)((char *)top + info->offset);
+ if(!(rect = (XRectangle *)Xmalloc(sizeof(XRectangle)))) {
+ return False;
+ }
+ *rect = *in;
+ *((XRectangle **)val) = rect;
+ return True;
+}
+
+Private Bool
+_XimDecodeSpot(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XPoint *in;
+ XPoint *spot;
+
+ in = (XPoint *)((char *)top + info->offset);
+ if(!(spot = (XPoint *)Xmalloc(sizeof(XPoint)))) {
+ return False;
+ }
+ *spot = *in;
+ *((XPoint **)val) = spot;
+ return True;
+}
+
+Private Bool
+_XimDecodeColormap(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ Colormap *in;
+
+ in = (Colormap *)((char *)top + info->offset);
+ *((Colormap *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeStdColormap(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ Atom *in;
+
+ in = (Atom *)((char *)top + info->offset);
+ *((Atom *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeLong(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ unsigned long *in;
+
+ in = (unsigned long *)((char *)top + info->offset);
+ *((unsigned long *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeBgPixmap(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ Pixmap *in;
+
+ in = (Pixmap *)((char *)top + info->offset);
+ *((Pixmap *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeFontSet(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XFontSet *in;
+
+ in = (XFontSet *)((char *)top + info->offset);
+ *((XFontSet *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeLineSpace(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ int *in;
+
+ in = (int *)((char *)top + info->offset);
+ *((int *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeCursor(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ Cursor *in;
+
+ in = (Cursor *)((char *)top + info->offset);
+ *((Cursor *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodePreeditState(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ XIMPreeditState *in;
+
+ in = (XIMPreeditState *)((char *)top + info->offset);
+ *((XIMPreeditState *)val) = *in;
+ return True;
+}
+
+Private Bool
+_XimDecodeNest(
+ XimValueOffsetInfo info,
+ XPointer top,
+ XPointer val)
+{
+ return True;
+}
+
+static XIMResource im_resources[] = {
+ {XNQueryInputStyle, 0, XimType_XIMStyles, 0, 0, 0},
+ {XNDestroyCallback, 0, 0, 0, 0, 0},
+ {XNResourceName, 0, XimType_STRING8, 0, 0, 0},
+ {XNResourceClass, 0, XimType_STRING8, 0, 0, 0},
+ {XNQueryIMValuesList, 0, 0, 0, 0, 0},
+ {XNQueryICValuesList, 0, 0, 0, 0, 0},
+ {XNVisiblePosition, 0, 0, 0, 0, 0}
+};
+
+static XIMResource im_inner_resources[] = {
+ {XNDestroyCallback, 0, 0, 0, 0, 0},
+ {XNResourceName, 0, XimType_STRING8, 0, 0, 0},
+ {XNResourceClass, 0, XimType_STRING8, 0, 0, 0},
+ {XNQueryIMValuesList, 0, 0, 0, 0, 0},
+ {XNQueryICValuesList, 0, 0, 0, 0, 0},
+ {XNVisiblePosition, 0, 0, 0, 0, 0}
+};
+
+static XIMResource ic_resources[] = {
+ {XNInputStyle, 0, XimType_CARD32, 0, 0, 0},
+ {XNClientWindow, 0, XimType_Window, 0, 0, 0},
+ {XNFocusWindow, 0, XimType_Window, 0, 0, 0},
+ {XNResourceName, 0, XimType_STRING8, 0, 0, 0},
+ {XNResourceClass, 0, XimType_STRING8, 0, 0, 0},
+ {XNGeometryCallback, 0, 0, 0, 0, 0},
+ {XNFilterEvents, 0, XimType_CARD32, 0, 0, 0},
+ {XNDestroyCallback, 0, 0, 0, 0, 0},
+ {XNStringConversionCallback, 0, 0, 0, 0, 0},
+ {XNStringConversion, 0, XimType_XIMStringConversion,0, 0, 0},
+ {XNResetState, 0, 0, 0, 0, 0},
+ {XNHotKey, 0, XimType_XIMHotKeyTriggers,0, 0, 0},
+ {XNHotKeyState, 0, XimType_XIMHotKeyState, 0, 0, 0},
+ {XNPreeditAttributes, 0, XimType_NEST, 0, 0, 0},
+ {XNStatusAttributes, 0, XimType_NEST, 0, 0, 0},
+ {XNArea, 0, XimType_XRectangle, 0, 0, 0},
+ {XNAreaNeeded, 0, XimType_XRectangle, 0, 0, 0},
+ {XNSpotLocation, 0, XimType_XPoint, 0, 0, 0},
+ {XNColormap, 0, XimType_CARD32, 0, 0, 0},
+ {XNStdColormap, 0, XimType_CARD32, 0, 0, 0},
+ {XNForeground, 0, XimType_CARD32, 0, 0, 0},
+ {XNBackground, 0, XimType_CARD32, 0, 0, 0},
+ {XNBackgroundPixmap, 0, XimType_CARD32, 0, 0, 0},
+ {XNFontSet, 0, XimType_XFontSet, 0, 0, 0},
+ {XNLineSpace, 0, XimType_CARD32, 0, 0, 0},
+ {XNCursor, 0, XimType_CARD32, 0, 0, 0},
+ {XNPreeditStartCallback, 0, 0, 0, 0, 0},
+ {XNPreeditDoneCallback, 0, 0, 0, 0, 0},
+ {XNPreeditDrawCallback, 0, 0, 0, 0, 0},
+ {XNPreeditCaretCallback, 0, 0, 0, 0, 0},
+ {XNStatusStartCallback, 0, 0, 0, 0, 0},
+ {XNStatusDoneCallback, 0, 0, 0, 0, 0},
+ {XNStatusDrawCallback, 0, 0, 0, 0, 0},
+ {XNPreeditState, 0, 0, 0, 0, 0},
+ {XNPreeditStateNotifyCallback, 0, 0, 0, 0, 0},
+};
+
+static XIMResource ic_inner_resources[] = {
+ {XNResourceName, 0, XimType_STRING8, 0, 0, 0},
+ {XNResourceClass, 0, XimType_STRING8, 0, 0, 0},
+ {XNGeometryCallback, 0, 0, 0, 0, 0},
+ {XNDestroyCallback, 0, 0, 0, 0, 0},
+ {XNStringConversionCallback, 0, 0, 0, 0, 0},
+ {XNPreeditStartCallback, 0, 0, 0, 0, 0},
+ {XNPreeditDoneCallback, 0, 0, 0, 0, 0},
+ {XNPreeditDrawCallback, 0, 0, 0, 0, 0},
+ {XNPreeditCaretCallback, 0, 0, 0, 0, 0},
+ {XNStatusStartCallback, 0, 0, 0, 0, 0},
+ {XNStatusDoneCallback, 0, 0, 0, 0, 0},
+ {XNStatusDrawCallback, 0, 0, 0, 0, 0},
+ {XNPreeditStateNotifyCallback, 0, 0, 0, 0, 0},
+};
+
+static XimValueOffsetInfoRec im_attr_info[] = {
+ {OFFSET_XNQUERYINPUTSTYLE, 0,
+ XOffsetOf(XimDefIMValues, styles),
+ _XimDefaultStyles, NULL, _XimDecodeStyles},
+
+ {OFFSET_XNDESTROYCALLBACK, 0,
+ XOffsetOf(XimDefIMValues, destroy_callback),
+ NULL, _XimEncodeCallback, _XimDecodeCallback},
+
+ {OFFSET_XNRESOURCENAME, 0,
+ XOffsetOf(XimDefIMValues, res_name),
+ NULL, _XimEncodeString, _XimDecodeString},
+
+ {OFFSET_XNRESOURCECLASS, 0,
+ XOffsetOf(XimDefIMValues, res_class),
+ NULL, _XimEncodeString, _XimDecodeString},
+
+ {OFFSET_XNQUERYIMVALUESLIST, 0,
+ XOffsetOf(XimDefIMValues, im_values_list),
+ _XimDefaultIMValues, NULL, _XimDecodeValues},
+
+ {OFFSET_XNQUERYICVALUESLIST, 0,
+ XOffsetOf(XimDefIMValues, ic_values_list),
+ _XimDefaultICValues, NULL, _XimDecodeValues},
+
+ {OFFSET_XNVISIBLEPOSITION, 0,
+ XOffsetOf(XimDefIMValues, visible_position),
+ _XimDefaultVisiblePos, NULL, _XimDecodeBool}
+};
+
+static XimValueOffsetInfoRec ic_attr_info[] = {
+ {OFFSET_XNINPUTSTYLE, 0,
+ XOffsetOf(XimDefICValues, input_style),
+ NULL, _XimEncodeStyle, _XimDecodeStyle},
+
+ {OFFSET_XNCLIENTWINDOW, 0,
+ XOffsetOf(XimDefICValues, client_window),
+ NULL, _XimEncodeWindow, _XimDecodeWindow},
+
+ {OFFSET_XNFOCUSWINDOW, 0,
+ XOffsetOf(XimDefICValues, focus_window),
+ _XimDefaultFocusWindow, _XimEncodeWindow, _XimDecodeWindow},
+
+ {OFFSET_XNRESOURCENAME, 0,
+ XOffsetOf(XimDefICValues, res_name),
+ _XimDefaultResName, _XimEncodeString, _XimDecodeString},
+
+ {OFFSET_XNRESOURCECLASS, 0,
+ XOffsetOf(XimDefICValues, res_class),
+ _XimDefaultResClass, _XimEncodeString, _XimDecodeString},
+
+ {OFFSET_XNGEOMETRYCALLBACK, 0,
+ XOffsetOf(XimDefICValues, geometry_callback),
+ NULL, _XimEncodeCallback, _XimDecodeCallback},
+
+ {OFFSET_XNFILTEREVENTS, 0,
+ XOffsetOf(XimDefICValues, filter_events),
+ NULL, NULL, _XimDecodeLong},
+
+ {OFFSET_XNDESTROYCALLBACK, 0,
+ XOffsetOf(XimDefICValues, destroy_callback),
+ _XimDefaultDestroyCB, _XimEncodeCallback, _XimDecodeCallback},
+
+ {OFFSET_XNSTRINGCONVERSIONCALLBACK, 0,
+ XOffsetOf(XimDefICValues, string_conversion_callback),
+ NULL, _XimEncodeCallback, _XimDecodeCallback},
+
+ {OFFSET_XNSTRINGCONVERSION, 0,
+ XOffsetOf(XimDefICValues, string_conversion),
+ NULL, _XimEncodeStringConv, _XimDecodeStringConv},
+
+ {OFFSET_XNRESETSTATE, 0,
+ XOffsetOf(XimDefICValues, reset_state),
+ _XimDefaultResetState, _XimEncodeResetState, _XimDecodeResetState},
+
+ {OFFSET_XNHOTKEY, 0,
+ XOffsetOf(XimDefICValues, hotkey),
+ NULL, _XimEncodeHotKey, _XimDecodeHotKey},
+
+ {OFFSET_XNHOTKEYSTATE, 0,
+ XOffsetOf(XimDefICValues, hotkey_state),
+ _XimDefaultHotKeyState, _XimEncodeHotKetState, _XimDecodeHotKetState},
+
+ {OFFSET_XNPREEDITATTRIBUTES, 0,
+ XOffsetOf(XimDefICValues, preedit_attr),
+ _XimDefaultNest, _XimEncodeNest, _XimDecodeNest},
+
+ {OFFSET_XNSTATUSATTRIBUTES, 0,
+ XOffsetOf(XimDefICValues, status_attr),
+ _XimDefaultNest, _XimEncodeNest, _XimDecodeNest},
+};
+
+static XimValueOffsetInfoRec ic_pre_attr_info[] = {
+ {OFFSET_XNAREA, 0,
+ XOffsetOf(ICPreeditAttributes, area),
+ _XimDefaultArea, _XimEncodeRectangle, _XimDecodeRectangle},
+
+ {OFFSET_XNAREANEEDED, 0,
+ XOffsetOf(ICPreeditAttributes, area_needed),
+ NULL, _XimEncodeRectangle, _XimDecodeRectangle},
+
+ {OFFSET_XNSPOTLOCATION, 0,
+ XOffsetOf(ICPreeditAttributes, spot_location),
+ NULL, _XimEncodeSpot, _XimDecodeSpot},
+
+ {OFFSET_XNCOLORMAP, 0,
+ XOffsetOf(ICPreeditAttributes, colormap),
+ _XimDefaultColormap, _XimEncodeColormap, _XimDecodeColormap},
+
+ {OFFSET_XNSTDCOLORMAP, 0,
+ XOffsetOf(ICPreeditAttributes, std_colormap),
+ _XimDefaultStdColormap, _XimEncodeStdColormap, _XimDecodeStdColormap},
+
+ {OFFSET_XNFOREGROUND, 0,
+ XOffsetOf(ICPreeditAttributes, foreground),
+ _XimDefaultFg, _XimEncodeLong, _XimDecodeLong},
+
+ {OFFSET_XNBACKGROUND, 0,
+ XOffsetOf(ICPreeditAttributes, background),
+ _XimDefaultBg, _XimEncodeLong, _XimDecodeLong},
+
+ {OFFSET_XNBACKGROUNDPIXMAP, 0,
+ XOffsetOf(ICPreeditAttributes, background_pixmap),
+ _XimDefaultBgPixmap, _XimEncodeBgPixmap, _XimDecodeBgPixmap},
+
+ {OFFSET_XNFONTSET, 0,
+ XOffsetOf(ICPreeditAttributes, fontset),
+ _XimDefaultFontSet, _XimEncodeFontSet, _XimDecodeFontSet},
+
+ {OFFSET_XNLINESPACE, 0,
+ XOffsetOf(ICPreeditAttributes, line_spacing),
+ _XimDefaultLineSpace, _XimEncodeLineSpace, _XimDecodeLineSpace},
+
+ {OFFSET_XNCURSOR, 0,
+ XOffsetOf(ICPreeditAttributes, cursor),
+ _XimDefaultCursor, _XimEncodeCursor, _XimDecodeCursor},
+
+ {OFFSET_XNPREEDITSTARTCALLBACK, 0,
+ XOffsetOf(ICPreeditAttributes, start_callback),
+ NULL, _XimEncodeCallback, _XimDecodeCallback},
+
+ {OFFSET_XNPREEDITDONECALLBACK, 0,
+ XOffsetOf(ICPreeditAttributes, done_callback),
+ NULL, _XimEncodeCallback, _XimDecodeCallback},
+
+ {OFFSET_XNPREEDITDRAWCALLBACK, 0,
+ XOffsetOf(ICPreeditAttributes, draw_callback),
+ NULL, _XimEncodeCallback, _XimDecodeCallback},
+
+ {OFFSET_XNPREEDITCARETCALLBACK, 0,
+ XOffsetOf(ICPreeditAttributes, caret_callback),
+ NULL, _XimEncodeCallback, _XimDecodeCallback},
+
+ {OFFSET_XNPREEDITSTATE, 0,
+ XOffsetOf(ICPreeditAttributes, preedit_state),
+ _XimDefaultPreeditState, _XimEncodePreeditState,_XimDecodePreeditState},
+
+ {OFFSET_XNPREEDITSTATENOTIFYCALLBACK, 0,
+ XOffsetOf(ICPreeditAttributes, state_notify_callback),
+ NULL, _XimEncodeCallback, _XimDecodeCallback},
+};
+
+static XimValueOffsetInfoRec ic_sts_attr_info[] = {
+ {OFFSET_XNAREA, 0,
+ XOffsetOf(ICStatusAttributes, area),
+ _XimDefaultArea, _XimEncodeRectangle, _XimDecodeRectangle},
+
+ {OFFSET_XNAREANEEDED, 0,
+ XOffsetOf(ICStatusAttributes, area_needed),
+ NULL, _XimEncodeRectangle, _XimDecodeRectangle},
+
+ {OFFSET_XNCOLORMAP, 0,
+ XOffsetOf(ICStatusAttributes, colormap),
+ _XimDefaultColormap, _XimEncodeColormap, _XimDecodeColormap},
+
+ {OFFSET_XNSTDCOLORMAP, 0,
+ XOffsetOf(ICStatusAttributes, std_colormap),
+ _XimDefaultStdColormap, _XimEncodeStdColormap, _XimDecodeStdColormap},
+
+ {OFFSET_XNFOREGROUND, 0,
+ XOffsetOf(ICStatusAttributes, foreground),
+ _XimDefaultFg, _XimEncodeLong, _XimDecodeLong},
+
+ {OFFSET_XNBACKGROUND, 0,
+ XOffsetOf(ICStatusAttributes, background),
+ _XimDefaultBg, _XimEncodeLong, _XimDecodeLong},
+
+ {OFFSET_XNBACKGROUNDPIXMAP, 0,
+ XOffsetOf(ICStatusAttributes, background_pixmap),
+ _XimDefaultBgPixmap, _XimEncodeBgPixmap, _XimDecodeBgPixmap},
+
+ {OFFSET_XNFONTSET, 0,
+ XOffsetOf(ICStatusAttributes, fontset),
+ _XimDefaultFontSet, _XimEncodeFontSet, _XimDecodeFontSet},
+
+ {OFFSET_XNLINESPACE, 0,
+ XOffsetOf(ICStatusAttributes, line_spacing),
+ _XimDefaultLineSpace, _XimEncodeLineSpace, _XimDecodeLineSpace},
+
+ {OFFSET_XNCURSOR, 0,
+ XOffsetOf(ICStatusAttributes, cursor),
+ _XimDefaultCursor, _XimEncodeCursor, _XimDecodeCursor},
+
+ {OFFSET_XNSTATUSSTARTCALLBACK, 0,
+ XOffsetOf(ICStatusAttributes, start_callback),
+ NULL, _XimEncodeCallback, _XimDecodeCallback},
+
+ {OFFSET_XNSTATUSDONECALLBACK, 0,
+ XOffsetOf(ICStatusAttributes, done_callback),
+ NULL, _XimEncodeCallback, _XimDecodeCallback},
+
+ {OFFSET_XNSTATUSDRAWCALLBACK, 0,
+ XOffsetOf(ICStatusAttributes, draw_callback),
+ NULL, _XimEncodeCallback, _XimDecodeCallback}
+};
+
+typedef struct _XimIMMode {
+ unsigned short name_offset;
+ unsigned short mode;
+} XimIMMode;
+
+static const XimIMMode im_mode[] = {
+ {OFFSET_XNQUERYINPUTSTYLE,
+ (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)},
+ {OFFSET_XNDESTROYCALLBACK,
+ (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_SET | XIM_MODE_IM_GET)},
+ {OFFSET_XNRESOURCENAME,
+ (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_SET | XIM_MODE_IM_GET)},
+ {OFFSET_XNRESOURCECLASS,
+ (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_SET | XIM_MODE_IM_GET)},
+ {OFFSET_XNQUERYIMVALUESLIST,
+ (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)},
+ {OFFSET_XNQUERYICVALUESLIST,
+ (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)},
+ {OFFSET_XNVISIBLEPOSITION,
+ (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)}
+};
+
+typedef struct _XimICMode {
+ unsigned short name_offset;
+ unsigned short preedit_callback_mode;
+ unsigned short preedit_position_mode;
+ unsigned short preedit_area_mode;
+ unsigned short preedit_nothing_mode;
+ unsigned short preedit_none_mode;
+ unsigned short status_callback_mode;
+ unsigned short status_area_mode;
+ unsigned short status_nothing_mode;
+ unsigned short status_none_mode;
+} XimICMode;
+
+static const XimICMode ic_mode[] = {
+ {OFFSET_XNINPUTSTYLE,
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
+ (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET)},
+ {OFFSET_XNCLIENTWINDOW,
+ (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET),
+ 0,
+ (XIM_MODE_STS_ONCE | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_ONCE | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_ONCE | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNFOCUSWINDOW,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNRESOURCENAME,
+ 0,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNRESOURCECLASS,
+ 0,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNGEOMETRYCALLBACK,
+ 0,
+ 0,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0,
+ 0},
+ {OFFSET_XNFILTEREVENTS,
+ XIM_MODE_PRE_GET,
+ XIM_MODE_PRE_GET,
+ XIM_MODE_PRE_GET,
+ XIM_MODE_PRE_GET,
+ 0,
+ XIM_MODE_STS_GET,
+ XIM_MODE_STS_GET,
+ XIM_MODE_STS_GET,
+ XIM_MODE_STS_GET},
+ {OFFSET_XNDESTROYCALLBACK,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNSTRINGCONVERSIONCALLBACK,
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNSTRINGCONVERSION,
+ XIM_MODE_PRE_SET,
+ XIM_MODE_PRE_SET,
+ XIM_MODE_PRE_SET,
+ XIM_MODE_PRE_SET,
+ XIM_MODE_PRE_SET,
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNRESETSTATE,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNHOTKEY,
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNHOTKEYSTATE,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNPREEDITATTRIBUTES,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNSTATUSATTRIBUTES,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNAREA,
+ 0,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0,
+ 0},
+ {OFFSET_XNAREANEEDED,
+ 0,
+ 0,
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ (XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0,
+ 0},
+ {OFFSET_XNSPOTLOCATION,
+ 0, /*(XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),*/
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNCOLORMAP,
+ 0,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNSTDCOLORMAP,
+ 0,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNFOREGROUND,
+ 0,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNBACKGROUND,
+ 0,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNBACKGROUNDPIXMAP,
+ 0,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNFONTSET,
+ 0,
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNLINESPACE,
+ 0,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNCURSOR,
+ 0,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0},
+ {OFFSET_XNPREEDITSTARTCALLBACK,
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNPREEDITDONECALLBACK,
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNPREEDITDRAWCALLBACK,
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNPREEDITCARETCALLBACK,
+ (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNPREEDITSTATE,
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNPREEDITSTATENOTIFYCALLBACK,
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNSTATUSSTARTCALLBACK,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNSTATUSDONECALLBACK,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0,
+ 0,
+ 0},
+ {OFFSET_XNSTATUSDRAWCALLBACK,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
+ 0,
+ 0,
+ 0}
+};
+
+/* the quarks are separated from im_mode/ic_mode so those arrays
+ * can be const.
+ */
+static XrmQuark im_mode_quark[sizeof(im_mode) / sizeof(im_mode[0])];
+static XrmQuark ic_mode_quark[sizeof(ic_mode) / sizeof(ic_mode[0])];
+
+Private Bool
+_XimSetResourceList(
+ XIMResourceList *res_list,
+ unsigned int *list_num,
+ XIMResourceList resource,
+ unsigned int num_resource,
+ unsigned short id)
+{
+ register int i;
+ int len;
+ XIMResourceList res;
+
+ len = sizeof(XIMResource) * num_resource;
+ if(!(res = Xcalloc(1, len))) {
+ return False;
+ }
+
+ for(i = 0; i < num_resource; i++, id++) {
+ res[i] = resource[i];
+ res[i].id = id;
+ }
+
+ _XIMCompileResourceList(res, num_resource);
+ *res_list = res;
+ *list_num = num_resource;
+ return True;
+}
+
+Public Bool
+_XimSetIMResourceList(
+ XIMResourceList *res_list,
+ unsigned int *list_num)
+{
+ return _XimSetResourceList(res_list, list_num,
+ im_resources, XIMNumber(im_resources), 100);
+}
+
+Public Bool
+_XimSetICResourceList(
+ XIMResourceList *res_list,
+ unsigned int *list_num)
+{
+ return _XimSetResourceList(res_list, list_num,
+ ic_resources, XIMNumber(ic_resources), 200);
+}
+
+Public Bool
+_XimSetInnerIMResourceList(
+ XIMResourceList *res_list,
+ unsigned int *list_num)
+{
+ return _XimSetResourceList(res_list, list_num,
+ im_inner_resources, XIMNumber(im_inner_resources), 100);
+}
+
+Public Bool
+_XimSetInnerICResourceList(
+ XIMResourceList *res_list,
+ unsigned int *list_num)
+{
+ return _XimSetResourceList(res_list, list_num,
+ ic_inner_resources, XIMNumber(ic_inner_resources), 200);
+}
+
+Private XIMResourceList
+_XimGetResourceListRecByMode(
+ XIMResourceList res_list,
+ unsigned int list_num,
+ unsigned short mode)
+{
+ register int i;
+
+ for(i = 0; i < list_num; i++) {
+ if (res_list[i].mode & mode) {
+ return (XIMResourceList)&res_list[i];
+ }
+ }
+ return (XIMResourceList)NULL;
+}
+
+Public Bool
+_XimCheckCreateICValues(
+ XIMResourceList res_list,
+ unsigned int list_num)
+{
+ if (!_XimGetResourceListRecByMode(res_list, list_num, XIM_MODE_IC_CREATE)) {
+ return True;
+ }
+ return False;
+}
+
+Public XIMResourceList
+_XimGetResourceListRecByQuark(
+ XIMResourceList res_list,
+ unsigned int list_num,
+ XrmQuark quark)
+{
+ register int i;
+
+ for(i = 0; i < list_num; i++) {
+ if (res_list[i].xrm_name == quark) {
+ return (XIMResourceList)&res_list[i];
+ }
+ }
+ return (XIMResourceList)NULL;
+}
+
+Public XIMResourceList
+_XimGetResourceListRec(
+ XIMResourceList res_list,
+ unsigned int list_num,
+ const char *name)
+{
+ XrmQuark quark = XrmStringToQuark(name);
+
+ return _XimGetResourceListRecByQuark(res_list, list_num, quark);
+}
+
+Public char *
+_XimSetIMValueData(
+ Xim im,
+ XPointer top,
+ XIMArg *values,
+ XIMResourceList res_list,
+ unsigned int list_num)
+{
+ register XIMArg *p;
+ XIMResourceList res;
+ int check;
+
+ for(p = values; p->name != NULL; p++) {
+ if(!(res = _XimGetResourceListRec(res_list, list_num, p->name))) {
+ return p->value;
+ }
+ check = _XimCheckIMMode(res, XIM_SETIMVALUES);
+ if(check == XIM_CHECK_INVALID) {
+ continue;
+ } else if (check == XIM_CHECK_ERROR) {
+ return p->value;
+ }
+
+ if(!_XimEncodeLocalIMAttr(res, top, p->value)) {
+ return p->value;
+ }
+ }
+ return NULL;
+}
+
+Public char *
+_XimGetIMValueData(
+ Xim im,
+ XPointer top,
+ XIMArg *values,
+ XIMResourceList res_list,
+ unsigned int list_num)
+{
+ register XIMArg *p;
+ XIMResourceList res;
+ int check;
+
+ for(p = values; p->name != NULL; p++) {
+ if(!(res = _XimGetResourceListRec(res_list, list_num, p->name))) {
+ return p->value;
+ }
+ check = _XimCheckIMMode(res, XIM_GETIMVALUES);
+ if(check == XIM_CHECK_INVALID) {
+ continue;
+ } else if (check == XIM_CHECK_ERROR) {
+ return p->value;
+ }
+
+ if(!_XimDecodeLocalIMAttr(res, top, p->value)) {
+ return p->value;
+ }
+ }
+ return NULL;
+}
+
+Public void
+_XimSetIMMode(
+ XIMResourceList res_list,
+ unsigned int list_num)
+{
+ XIMResourceList res;
+ unsigned int n = XIMNumber(im_mode);
+ register int i;
+
+ for(i = 0; i < n; i++) {
+ if(!(res = _XimGetResourceListRecByQuark(res_list,
+ list_num, im_mode_quark[i]))) {
+ continue;
+ }
+ res->mode = im_mode[i].mode;
+ }
+ return;
+}
+
+Private int
+_XimCheckSetIMDefaultsMode(
+ XIMResourceList res)
+{
+ if(res->mode & XIM_MODE_IM_DEFAULT) {
+ return XIM_CHECK_VALID;
+ }
+ return XIM_CHECK_INVALID;
+}
+
+Private int
+_XimCheckSetIMValuesMode(
+ XIMResourceList res)
+{
+ if(res->mode & XIM_MODE_IM_SET) {
+ return XIM_CHECK_VALID;
+ }
+ return XIM_CHECK_INVALID;
+}
+
+Private int
+ _XimCheckGetIMValuesMode(
+ XIMResourceList res)
+{
+ if(res->mode & XIM_MODE_IM_GET) {
+ return XIM_CHECK_VALID;
+ }
+ return XIM_CHECK_INVALID;
+}
+
+Public int
+ _XimCheckIMMode(
+ XIMResourceList res,
+ unsigned long mode)
+{
+ if(res->mode == 0) {
+ return XIM_CHECK_INVALID;
+ }
+ if(mode & XIM_SETIMDEFAULTS) {
+ return _XimCheckSetIMDefaultsMode(res);
+ } else if (mode & XIM_SETIMVALUES) {
+ return _XimCheckSetIMValuesMode(res);
+ } else if (mode & XIM_GETIMVALUES) {
+ return _XimCheckGetIMValuesMode(res);
+ } else {
+ return XIM_CHECK_ERROR;
+ }
+}
+
+Public void
+_XimSetICMode(XIMResourceList res_list, unsigned int list_num, XIMStyle style)
+{
+ XIMResourceList res;
+ unsigned int n = XIMNumber(ic_mode);
+ register int i;
+ unsigned int pre_offset;
+ unsigned int sts_offset;
+
+ if(style & XIMPreeditArea) {
+ pre_offset = XOffsetOf(XimICMode, preedit_area_mode);
+ } else if(style & XIMPreeditCallbacks) {
+ pre_offset = XOffsetOf(XimICMode, preedit_callback_mode);
+ } else if(style & XIMPreeditPosition) {
+ pre_offset = XOffsetOf(XimICMode, preedit_position_mode);
+ } else if(style & XIMPreeditNothing) {
+ pre_offset = XOffsetOf(XimICMode, preedit_nothing_mode);
+ } else {
+ pre_offset = XOffsetOf(XimICMode, preedit_none_mode);
+ }
+
+ if(style & XIMStatusArea) {
+ sts_offset = XOffsetOf(XimICMode, status_area_mode);
+ } else if(style & XIMStatusCallbacks) {
+ sts_offset = XOffsetOf(XimICMode, status_callback_mode);
+ } else if(style & XIMStatusNothing) {
+ sts_offset = XOffsetOf(XimICMode, status_nothing_mode);
+ } else {
+ sts_offset = XOffsetOf(XimICMode, status_none_mode);
+ }
+
+ for(i = 0; i < n; i++) {
+ if(!(res = _XimGetResourceListRecByQuark(res_list,
+ list_num, ic_mode_quark[i]))) {
+ continue;
+ }
+ res->mode = ( (*(unsigned short *)((char *)&ic_mode[i] + pre_offset))
+ | (*(unsigned short *)((char *)&ic_mode[i] + sts_offset)));
+ }
+ return;
+}
+
+Private int
+_XimCheckSetICDefaultsMode(
+ XIMResourceList res,
+ unsigned long mode)
+{
+ if(mode & XIM_PREEDIT_ATTR) {
+ if(!(res->mode & XIM_MODE_PRE_MASK)) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(res->mode & XIM_MODE_PRE_CREATE) {
+ return XIM_CHECK_ERROR;
+ } else if (!(res->mode & XIM_MODE_PRE_DEFAULT)) {
+ return XIM_CHECK_INVALID;
+ }
+
+ } else if(mode & XIM_STATUS_ATTR) {
+ if(!(res->mode & XIM_MODE_STS_MASK)) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(res->mode & XIM_MODE_STS_CREATE) {
+ return XIM_CHECK_ERROR;
+ }
+ if(!(res->mode & XIM_MODE_STS_DEFAULT)) {
+ return XIM_CHECK_INVALID;
+ }
+
+ } else {
+ if(!res->mode) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(res->mode & XIM_MODE_IC_CREATE) {
+ return XIM_CHECK_ERROR;
+ }
+ if(!(res->mode & XIM_MODE_IC_DEFAULT)) {
+ return XIM_CHECK_INVALID;
+ }
+ }
+ return XIM_CHECK_VALID;
+}
+
+Private int
+_XimCheckCreateICMode(
+ XIMResourceList res,
+ unsigned long mode)
+{
+ if(mode & XIM_PREEDIT_ATTR) {
+ if(!(res->mode & XIM_MODE_PRE_MASK)) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(res->mode & XIM_MODE_PRE_CREATE) {
+ res->mode &= ~XIM_MODE_PRE_CREATE;
+ } else if(res->mode & XIM_MODE_PRE_ONCE) {
+ res->mode &= ~XIM_MODE_PRE_ONCE;
+ } else if(res->mode & XIM_MODE_PRE_DEFAULT) {
+ res->mode &= ~XIM_MODE_PRE_DEFAULT;
+ } else if (!(res->mode & XIM_MODE_PRE_SET)) {
+ return XIM_CHECK_ERROR;
+ }
+
+ } else if(mode & XIM_STATUS_ATTR) {
+ if(!(res->mode & XIM_MODE_STS_MASK)) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(res->mode & XIM_MODE_STS_CREATE) {
+ res->mode &= ~XIM_MODE_STS_CREATE;
+ } else if(res->mode & XIM_MODE_STS_ONCE) {
+ res->mode &= ~XIM_MODE_STS_ONCE;
+ } else if(res->mode & XIM_MODE_STS_DEFAULT) {
+ res->mode &= ~XIM_MODE_STS_DEFAULT;
+ } else if (!(res->mode & XIM_MODE_STS_SET)) {
+ return XIM_CHECK_ERROR;
+ }
+
+ } else {
+ if(!res->mode) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(res->mode & XIM_MODE_IC_CREATE) {
+ res->mode &= ~XIM_MODE_IC_CREATE;
+ } else if(res->mode & XIM_MODE_IC_ONCE) {
+ res->mode &= ~XIM_MODE_IC_ONCE;
+ } else if(res->mode & XIM_MODE_IC_DEFAULT) {
+ res->mode &= ~XIM_MODE_IC_DEFAULT;
+ } else if (!(res->mode & XIM_MODE_IC_SET)) {
+ return XIM_CHECK_ERROR;
+ }
+ }
+ return XIM_CHECK_VALID;
+}
+
+Private int
+_XimCheckSetICValuesMode(
+ XIMResourceList res,
+ unsigned long mode)
+{
+ if(mode & XIM_PREEDIT_ATTR) {
+ if(!(res->mode & XIM_MODE_PRE_MASK)) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(res->mode & XIM_MODE_PRE_ONCE) {
+ res->mode &= ~XIM_MODE_PRE_ONCE;
+ } else if(!(res->mode & XIM_MODE_PRE_SET)) {
+ return XIM_CHECK_ERROR;
+ }
+
+ } else if(mode & XIM_STATUS_ATTR) {
+ if(!(res->mode & XIM_MODE_STS_MASK)) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(res->mode & XIM_MODE_STS_ONCE) {
+ res->mode &= ~XIM_MODE_STS_ONCE;
+ } else if(!(res->mode & XIM_MODE_STS_SET)) {
+ return XIM_CHECK_ERROR;
+ }
+
+ } else {
+ if(!res->mode) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(res->mode & XIM_MODE_IC_ONCE) {
+ res->mode &= ~XIM_MODE_IC_ONCE;
+ } else if(!(res->mode & XIM_MODE_IC_SET)) {
+ return XIM_CHECK_ERROR;
+ }
+ }
+ return XIM_CHECK_VALID;
+}
+
+Private int
+_XimCheckGetICValuesMode(
+ XIMResourceList res,
+ unsigned long mode)
+{
+ if(mode & XIM_PREEDIT_ATTR) {
+ if(!(res->mode & XIM_MODE_PRE_MASK)) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(!(res->mode & XIM_MODE_PRE_GET)) {
+ return XIM_CHECK_ERROR;
+ }
+
+ } else if(mode & XIM_STATUS_ATTR) {
+ if(!(res->mode & XIM_MODE_STS_MASK)) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(!(res->mode & XIM_MODE_STS_GET)) {
+ return XIM_CHECK_ERROR;
+ }
+
+ } else {
+ if(!res->mode) {
+ return XIM_CHECK_INVALID;
+ }
+
+ if(!(res->mode & XIM_MODE_IC_GET)) {
+ return XIM_CHECK_ERROR;
+ }
+ }
+ return XIM_CHECK_VALID;
+}
+
+Public int
+ _XimCheckICMode(
+ XIMResourceList res,
+ unsigned long mode)
+{
+ if(mode &XIM_SETICDEFAULTS) {
+ return _XimCheckSetICDefaultsMode(res, mode);
+ } else if (mode & XIM_CREATEIC) {
+ return _XimCheckCreateICMode(res, mode);
+ } else if (mode & XIM_SETICVALUES) {
+ return _XimCheckSetICValuesMode(res, mode);
+ } else if (mode & XIM_GETICVALUES) {
+ return _XimCheckGetICValuesMode(res, mode);
+ } else {
+ return XIM_CHECK_ERROR;
+ }
+}
+
+Public Bool
+_XimSetLocalIMDefaults(
+ Xim im,
+ XPointer top,
+ XIMResourceList res_list,
+ unsigned int list_num)
+{
+ XimValueOffsetInfo info;
+ unsigned int num;
+ register int i;
+ XIMResourceList res;
+ int check;
+
+ info = im_attr_info;
+ num = XIMNumber(im_attr_info);
+
+ for(i = 0; i < num; i++) {
+ if((res = _XimGetResourceListRecByQuark( res_list, list_num,
+ info[i].quark)) == (XIMResourceList)NULL) {
+ return False;
+ }
+
+ check = _XimCheckIMMode(res, XIM_SETIMDEFAULTS);
+ if(check == XIM_CHECK_INVALID) {
+ continue;
+ } else if (check == XIM_CHECK_ERROR) {
+ return False;
+ }
+
+ if(!info[i].defaults) {
+ continue;
+ }
+ if(!(info[i].defaults(&info[i], top, (XPointer)NULL, 0))) {
+ return False;
+ }
+ }
+ return True;
+}
+
+Public Bool
+_XimSetICDefaults(
+ Xic ic,
+ XPointer top,
+ unsigned long mode,
+ XIMResourceList res_list,
+ unsigned int list_num)
+{
+ unsigned int num;
+ XimValueOffsetInfo info;
+ register int i;
+ XIMResourceList res;
+ int check;
+ XrmQuark pre_quark;
+ XrmQuark sts_quark;
+
+ pre_quark = XrmStringToQuark(XNPreeditAttributes);
+ sts_quark = XrmStringToQuark(XNStatusAttributes);
+
+ if(mode & XIM_PREEDIT_ATTR) {
+ info = ic_pre_attr_info;
+ num = XIMNumber(ic_pre_attr_info);
+ } else if(mode & XIM_STATUS_ATTR) {
+ info = ic_sts_attr_info;
+ num = XIMNumber(ic_sts_attr_info);
+ } else {
+ info = ic_attr_info;
+ num = XIMNumber(ic_attr_info);
+ }
+
+ for(i = 0; i < num; i++) {
+ if(info[i].quark == pre_quark) {
+ if(!_XimSetICDefaults(ic, (XPointer)((char *)top + info[i].offset),
+ (mode | XIM_PREEDIT_ATTR), res_list, list_num)) {
+ return False;
+ }
+ } else if (info[i].quark == sts_quark) {
+ if(!_XimSetICDefaults(ic, (XPointer)((char *)top + info[i].offset),
+ (mode | XIM_STATUS_ATTR), res_list, list_num)) {
+ return False;
+ }
+ } else {
+ if(!(res = _XimGetResourceListRecByQuark(res_list, list_num,
+ info[i].quark))) {
+ return False;
+ }
+
+ check = _XimCheckICMode(res, mode);
+ if (check == XIM_CHECK_INVALID) {
+ continue;
+ } else if (check == XIM_CHECK_ERROR) {
+ return False;
+ }
+
+ if (!info[i].defaults) {
+ continue;
+ }
+ if (!(info[i].defaults(&info[i], top, (XPointer)ic, mode))) {
+ return False;
+ }
+ }
+ }
+ return True;
+}
+
+Private Bool
+_XimEncodeAttr(
+ XimValueOffsetInfo info,
+ unsigned int num,
+ XIMResourceList res,
+ XPointer top,
+ XPointer val)
+{
+ register int i;
+
+ for(i = 0; i < num; i++ ) {
+ if(info[i].quark == res->xrm_name) {
+ if(!info[i].encode) {
+ return False;
+ }
+ return (*info[i].encode)(&info[i], top, val);
+ }
+ }
+ return False;
+}
+
+Public Bool
+_XimEncodeLocalIMAttr(
+ XIMResourceList res,
+ XPointer top,
+ XPointer val)
+{
+ return _XimEncodeAttr(im_attr_info, XIMNumber(im_attr_info),
+ res, top, val);
+}
+
+Public Bool
+_XimEncodeLocalICAttr(
+ Xic ic,
+ XIMResourceList res,
+ XPointer top,
+ XIMArg *arg,
+ unsigned long mode)
+{
+ unsigned int num;
+ XimValueOffsetInfo info;
+
+ if(mode & XIM_PREEDIT_ATTR) {
+ info = ic_pre_attr_info;
+ num = XIMNumber(ic_pre_attr_info);
+ } else if(mode & XIM_STATUS_ATTR) {
+ info = ic_sts_attr_info;
+ num = XIMNumber(ic_sts_attr_info);
+ } else {
+ info = ic_attr_info;
+ num = XIMNumber(ic_attr_info);
+ }
+
+ return _XimEncodeAttr(info, num, res, top, arg->value);
+}
+
+Private Bool
+_XimEncodeLocalTopValue(
+ Xic ic,
+ XIMResourceList res,
+ XPointer val,
+ Bool flag)
+{
+ XIMArg *p = (XIMArg *)val;
+
+ if (res->xrm_name == XrmStringToQuark(XNClientWindow)) {
+ ic->core.client_window = (Window)p->value;
+ if (ic->core.focus_window == (Window)0)
+ ic->core.focus_window = ic->core.client_window;
+ if (flag) {
+ _XRegisterFilterByType(ic->core.im->core.display,
+ ic->core.focus_window,
+ KeyPress, KeyRelease, _XimLocalFilter, (XPointer)ic);
+ }
+ } else if (res->xrm_name == XrmStringToQuark(XNFocusWindow)) {
+ if (ic->core.client_window) {
+ if (flag) {
+ _XUnregisterFilter(ic->core.im->core.display,
+ ic->core.focus_window, _XimLocalFilter, (XPointer)ic);
+ }
+ ic->core.focus_window = (Window)p->value;
+ if (flag) {
+ _XRegisterFilterByType(ic->core.im->core.display,
+ ic->core.focus_window, KeyPress, KeyRelease,
+ _XimLocalFilter, (XPointer)ic);
+ }
+ } else
+ ic->core.focus_window = (Window)p->value;
+ }
+ return True;
+}
+
+Private Bool
+_XimEncodeLocalPreeditValue(
+ Xic ic,
+ XIMResourceList res,
+ XPointer val)
+{
+ XIMArg *p = (XIMArg *)val;
+
+ if (res->xrm_name == XrmStringToQuark(XNStdColormap)) {
+ XStandardColormap *colormap_ret;
+ int count;
+
+ if (!(XGetRGBColormaps(ic->core.im->core.display,
+ ic->core.focus_window, &colormap_ret,
+ &count, (Atom)p->value)))
+ return False;
+
+ Xfree(colormap_ret);
+ }
+ return True;
+}
+
+Private Bool
+_XimEncodeLocalStatusValue(
+ Xic ic,
+ XIMResourceList res,
+ XPointer val)
+{
+ XIMArg *p = (XIMArg *)val;
+
+ if (res->xrm_name == XrmStringToQuark(XNStdColormap)) {
+ XStandardColormap *colormap_ret;
+ int count;
+
+ if (!(XGetRGBColormaps(ic->core.im->core.display,
+ ic->core.focus_window, &colormap_ret,
+ &count, (Atom)p->value)))
+ return False;
+
+ Xfree(colormap_ret);
+ }
+ return True;
+}
+
+Public char *
+_XimSetICValueData(
+ Xic ic,
+ XPointer top,
+ XIMResourceList res_list,
+ unsigned int list_num,
+ XIMArg *values,
+ unsigned long mode,
+ Bool flag)
+{
+ register XIMArg *p;
+ XIMResourceList res;
+ char *name;
+ int check;
+ XrmQuark pre_quark;
+ XrmQuark sts_quark;
+
+ pre_quark = XrmStringToQuark(XNPreeditAttributes);
+ sts_quark = XrmStringToQuark(XNStatusAttributes);
+
+ for(p = values; p->name != NULL; p++) {
+ if((res = _XimGetResourceListRec(res_list, list_num,
+ p->name)) == (XIMResourceList)NULL) {
+ return p->name;
+ }
+ if(res->xrm_name == pre_quark) {
+ if(((name = _XimSetICValueData(ic,
+ (XPointer)(&((XimDefICValues *)top)->preedit_attr),
+ res_list, list_num, (XIMArg *)p->value,
+ (mode | XIM_PREEDIT_ATTR), flag)))) {
+ return name;
+ }
+ } else if(res->xrm_name == sts_quark) {
+ if(((name = _XimSetICValueData(ic,
+ (XPointer)(&((XimDefICValues *)top)->status_attr),
+ res_list, list_num, (XIMArg *)p->value,
+ (mode | XIM_STATUS_ATTR), flag)))) {
+ return name;
+ }
+ } else {
+ check = _XimCheckICMode(res, mode);
+ if(check == XIM_CHECK_INVALID) {
+ continue;
+ } else if(check == XIM_CHECK_ERROR) {
+ return p->name;
+ }
+
+ if(mode & XIM_PREEDIT_ATTR) {
+ if (!_XimEncodeLocalPreeditValue(ic, res, (XPointer)p))
+ return False;
+ } else if(mode & XIM_STATUS_ATTR) {
+ if (!_XimEncodeLocalStatusValue(ic, res, (XPointer)p))
+ return False;
+ } else {
+ if (!_XimEncodeLocalTopValue(ic, res, (XPointer)p, flag))
+ return False;
+ }
+ if(_XimEncodeLocalICAttr(ic, res, top, p, mode) == False) {
+ return p->name;
+ }
+ }
+ }
+ return NULL;
+}
+
+Private Bool
+_XimCheckInputStyle(
+ XIMStyles *styles,
+ XIMStyle style)
+{
+ int num = styles->count_styles;
+ register int i;
+
+ for(i = 0; i < num; i++) {
+ if(styles->supported_styles[i] == style) {
+ return True;
+ }
+ }
+ return False;
+}
+
+Public Bool
+_XimCheckLocalInputStyle(
+ Xic ic,
+ XPointer top,
+ XIMArg *values,
+ XIMStyles *styles,
+ XIMResourceList res_list,
+ unsigned int list_num)
+{
+ XrmQuark quark = XrmStringToQuark(XNInputStyle);
+ register XIMArg *p;
+ XIMResourceList res;
+
+ for(p = values; p && p->name != NULL; p++) {
+ if(quark == XrmStringToQuark(p->name)) {
+ if(!(res = _XimGetResourceListRec(res_list, list_num, p->name))) {
+ return False;
+ }
+ if(!_XimEncodeLocalICAttr(ic, res, top, p, 0)) {
+ return False;
+ }
+ if (_XimCheckInputStyle(styles,
+ ((XimDefICValues *)top)->input_style)) {
+ return True;
+ }
+ return False;
+ }
+ }
+ return False;
+}
+
+Private Bool
+_XimDecodeAttr(
+ XimValueOffsetInfo info,
+ unsigned int num,
+ XIMResourceList res,
+ XPointer top,
+ XPointer val)
+{
+ register int i;
+
+ for(i = 0; i < num; i++ ) {
+ if(info[i].quark == res->xrm_name) {
+ if(!info[i].decode) {
+ return False;
+ }
+ return (*info[i].decode)(&info[i], top, val);
+ }
+ }
+ return False;
+}
+
+Public Bool
+_XimDecodeLocalIMAttr(
+ XIMResourceList res,
+ XPointer top,
+ XPointer val)
+{
+ return _XimDecodeAttr(im_attr_info, XIMNumber(im_attr_info),
+ res, top, val);
+}
+
+Public Bool
+_XimDecodeLocalICAttr(
+ XIMResourceList res,
+ XPointer top,
+ XPointer val,
+ unsigned long mode)
+{
+ unsigned int num;
+ XimValueOffsetInfo info;
+
+ if(mode & XIM_PREEDIT_ATTR) {
+ info = ic_pre_attr_info;
+ num = XIMNumber(ic_pre_attr_info);
+ } else if(mode & XIM_STATUS_ATTR) {
+ info = ic_sts_attr_info;
+ num = XIMNumber(ic_sts_attr_info);
+ } else {
+ info = ic_attr_info;
+ num = XIMNumber(ic_attr_info);
+ }
+
+ return _XimDecodeAttr(info, num, res, top, val);
+}
+
+Public char *
+_XimGetICValueData(Xic ic, XPointer top, XIMResourceList res_list,
+ unsigned int list_num, XIMArg *values, unsigned long mode)
+{
+ register XIMArg *p;
+ XIMResourceList res;
+ char *name;
+ int check;
+ XrmQuark pre_quark;
+ XrmQuark sts_quark;
+
+ pre_quark = XrmStringToQuark(XNPreeditAttributes);
+ sts_quark = XrmStringToQuark(XNStatusAttributes);
+
+ for(p = values; p->name != NULL; p++) {
+ if((res = _XimGetResourceListRec(res_list, list_num,
+ p->name)) == (XIMResourceList)NULL) {
+ return p->name;
+ }
+ if(res->xrm_name == pre_quark) {
+ if((name = _XimGetICValueData(ic,
+ (XPointer)(&((XimDefICValues *)top)->preedit_attr),
+ res_list, list_num, (XIMArg *)p->value,
+ (mode | XIM_PREEDIT_ATTR)))) {
+ return name;
+ }
+ } else if(res->xrm_name == sts_quark) {
+ if((name = _XimGetICValueData(ic,
+ (XPointer)(&((XimDefICValues *)top)->status_attr),
+ res_list, list_num, (XIMArg *)p->value,
+ (mode | XIM_STATUS_ATTR)))) {
+ return name;
+ }
+ } else {
+ check = _XimCheckICMode(res, mode);
+ if(check == XIM_CHECK_INVALID) {
+ continue;
+ } else if(check == XIM_CHECK_ERROR) {
+ return p->name;
+ }
+
+ if(_XimDecodeLocalICAttr(res, top, p->value, mode) == False) {
+ return p->name;
+ }
+ }
+ }
+ return NULL;
+}
+
+Public void
+_XimGetCurrentIMValues(Xim im, XimDefIMValues *im_values)
+{
+ bzero((char *)im_values, sizeof(XimDefIMValues));
+
+ im_values->styles = im->core.styles;
+ im_values->im_values_list = im->core.im_values_list;
+ im_values->ic_values_list = im->core.ic_values_list;
+ im_values->destroy_callback = im->core.destroy_callback;
+ im_values->res_name = im->core.res_name;
+ im_values->res_class = im->core.res_class;
+ im_values->visible_position = im->core.visible_position;
+}
+
+Public void
+_XimSetCurrentIMValues(Xim im, XimDefIMValues *im_values)
+{
+ im->core.styles = im_values->styles;
+ im->core.im_values_list = im_values->im_values_list;
+ im->core.ic_values_list = im_values->ic_values_list;
+ im->core.destroy_callback = im_values->destroy_callback;
+ im->core.res_name = im_values->res_name;
+ im->core.res_class = im_values->res_class;
+ im->core.visible_position = im_values->visible_position;
+}
+
+Public void
+_XimGetCurrentICValues(Xic ic, XimDefICValues *ic_values)
+{
+ bzero((char *)ic_values, sizeof(XimDefICValues));
+
+ ic_values->input_style = ic->core.input_style;
+ ic_values->client_window = ic->core.client_window;
+ ic_values->focus_window = ic->core.focus_window;
+ ic_values->filter_events = ic->core.filter_events;
+ ic_values->geometry_callback = ic->core.geometry_callback;
+ ic_values->res_name = ic->core.res_name;
+ ic_values->res_class = ic->core.res_class;
+ ic_values->destroy_callback = ic->core.destroy_callback;
+ ic_values->string_conversion_callback
+ = ic->core.string_conversion_callback;
+ ic_values->string_conversion = ic->core.string_conversion;
+ ic_values->reset_state = ic->core.reset_state;
+ ic_values->hotkey = ic->core.hotkey;
+ ic_values->hotkey_state = ic->core.hotkey_state;
+ ic_values->preedit_attr = ic->core.preedit_attr;
+ ic_values->status_attr = ic->core.status_attr;
+}
+
+Public void
+_XimSetCurrentICValues(
+ Xic ic,
+ XimDefICValues *ic_values)
+{
+ ic->core.input_style = ic_values->input_style;
+ ic->core.client_window = ic_values->client_window;
+ if (ic_values->focus_window)
+ ic->core.focus_window = ic_values->focus_window;
+ ic->core.filter_events = ic_values->filter_events;
+ ic->core.geometry_callback = ic_values->geometry_callback;
+ ic->core.res_name = ic_values->res_name;
+ ic->core.res_class = ic_values->res_class;
+ ic->core.destroy_callback = ic_values->destroy_callback;
+ ic->core.string_conversion_callback
+ = ic_values->string_conversion_callback;
+ ic->core.string_conversion = ic_values->string_conversion;
+ ic->core.reset_state = ic_values->reset_state;
+ ic->core.hotkey = ic_values->hotkey;
+ ic->core.hotkey_state = ic_values->hotkey_state;
+ ic->core.preedit_attr = ic_values->preedit_attr;
+ ic->core.status_attr = ic_values->status_attr;
+}
+
+Private void
+_XimInitialIMOffsetInfo(void)
+{
+ unsigned int n = XIMNumber(im_attr_info);
+ register int i;
+
+ for(i = 0; i < n; i++) {
+ im_attr_info[i].quark = XrmStringToQuark(GET_NAME(im_attr_info[i]));
+ }
+}
+
+Private void
+_XimInitialICOffsetInfo(void)
+{
+ unsigned int n;
+ register int i;
+
+ n = XIMNumber(ic_attr_info);
+ for(i = 0; i < n; i++) {
+ ic_attr_info[i].quark = XrmStringToQuark(GET_NAME(ic_attr_info[i]));
+ }
+
+ n = XIMNumber(ic_pre_attr_info);
+ for(i = 0; i < n; i++) {
+ ic_pre_attr_info[i].quark = XrmStringToQuark(GET_NAME(ic_pre_attr_info[i]));
+ }
+
+ n = XIMNumber(ic_sts_attr_info);
+ for(i = 0; i < n; i++) {
+ ic_sts_attr_info[i].quark = XrmStringToQuark(GET_NAME(ic_sts_attr_info[i]));
+ }
+}
+
+Private void
+_XimInitialIMMode(void)
+{
+ unsigned int n = XIMNumber(im_mode);
+ register int i;
+
+ for(i = 0; i < n; i++) {
+ im_mode_quark[i] = XrmStringToQuark(GET_NAME(im_mode[i]));
+ }
+}
+
+Private void
+_XimInitialICMode(void)
+{
+ unsigned int n = XIMNumber(ic_mode);
+ register int i;
+
+ for(i = 0; i < n; i++) {
+ ic_mode_quark[i] = XrmStringToQuark(GET_NAME(ic_mode[i]));
+ }
+}
+
+Public void
+_XimInitialResourceInfo(void)
+{
+ static Bool init_flag = False;
+
+ if(init_flag == True) {
+ return;
+ }
+ _XimInitialIMOffsetInfo();
+ _XimInitialICOffsetInfo();
+ _XimInitialIMMode();
+ _XimInitialICMode();
+ init_flag = True;
+}
diff --git a/libX11/modules/im/ximcp/imRmAttr.c b/libX11/modules/im/ximcp/imRmAttr.c
index 3183a6005..ac47f3bbe 100644
--- a/libX11/modules/im/ximcp/imRmAttr.c
+++ b/libX11/modules/im/ximcp/imRmAttr.c
@@ -1408,7 +1408,6 @@ _XimGetAttributeID(
{
unsigned int n;
XIMResourceList res;
- int res_len;
char *names;
int names_len;
XPointer tmp;
@@ -1426,18 +1425,15 @@ _XimGetAttributeID(
if (!(n = _XimCountNumberOfAttr(buf[0], &buf[1], &names_len)))
return False;
- res_len = sizeof(XIMResource) * n;
- if (!(res = (XIMResourceList)Xmalloc(res_len)))
+ if (!(res = Xcalloc(n, sizeof(XIMResource))))
return False;
- bzero((char *)res, res_len);
values_len = sizeof(XIMValuesList) + (sizeof(char **) * n) + names_len;
- if (!(tmp = (XPointer)Xmalloc(values_len))) {
+ if (!(tmp = Xcalloc(1, values_len))) {
Xfree(res);
return False;
}
- bzero(tmp, values_len);
values_list = (XIMValuesList *)tmp;
values = (char **)((char *)tmp + sizeof(XIMValuesList));
@@ -1475,18 +1471,15 @@ _XimGetAttributeID(
if (!(n = _XimCountNumberOfAttr(buf[0], &buf[2], &names_len)))
return False;
- res_len = sizeof(XIMResource) * n;
- if (!(res = (XIMResourceList)Xmalloc(res_len)))
+ if (!(res = Xcalloc(n, sizeof(XIMResource))))
return False;
- bzero((char *)res, res_len);
values_len = sizeof(XIMValuesList) + (sizeof(char **) * n) + names_len;
- if (!(tmp = (XPointer)Xmalloc(values_len))) {
+ if (!(tmp = Xcalloc(1, values_len))) {
Xfree(res);
return False;
}
- bzero(tmp, values_len);
values_list = (XIMValuesList *)tmp;
values = (char **)((char *)tmp + sizeof(XIMValuesList));
diff --git a/libX11/modules/im/ximcp/imThaiIc.c b/libX11/modules/im/ximcp/imThaiIc.c
index d1cb22a5e..6b8784387 100644
--- a/libX11/modules/im/ximcp/imThaiIc.c
+++ b/libX11/modules/im/ximcp/imThaiIc.c
@@ -1,228 +1,227 @@
-/******************************************************************
-
- Copyright 1992, 1993, 1994 by FUJITSU LIMITED
- Copyright 1993 by Digital Equipment Corporation
-
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in
-supporting documentation, and that the name of FUJITSU LIMITED and
-Digital Equipment Corporation not be used in advertising or publicity
-pertaining to distribution of the software without specific, written
-prior permission. FUJITSU LIMITED and Digital Equipment Corporation
-makes no representations about the suitability of this software for
-any purpose. It is provided "as is" without express or implied
-warranty.
-
-FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION DISCLAIM ALL
-WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR
-ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
- Author: Takashi Fujiwara FUJITSU LIMITED
- fujiwara@a80.tech.yk.fujitsu.co.jp
- Modifier: Franky Ling Digital Equipment Corporation
- frankyling@hgrd01.enet.dec.com
-
-******************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include <X11/Xlib.h>
-#include <X11/Xmd.h>
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "Ximint.h"
-
-Private void
-_XimThaiUnSetFocus(
- XIC xic)
-{
- Xic ic = (Xic)xic;
- ((Xim)ic->core.im)->private.local.current_ic = (XIC)NULL;
-
- if (ic->core.focus_window)
- _XUnregisterFilter(ic->core.im->core.display, ic->core.focus_window,
- _XimThaiFilter, (XPointer)ic);
- return;
-}
-
-Private void
-_XimThaiDestroyIC(
- XIC xic)
-{
- Xic ic = (Xic)xic;
- DefTreeBase *b = &ic->private.local.base;
-
- if(((Xim)ic->core.im)->private.local.current_ic == (XIC)ic) {
- _XimThaiUnSetFocus(xic);
- }
- if(ic->private.local.ic_resources) {
- Xfree(ic->private.local.ic_resources);
- ic->private.local.ic_resources = NULL;
- }
-
- if (b->tree) Xfree (b->tree);
- if (b->mb) Xfree (b->mb);
- if (b->wc) Xfree (b->wc);
- if (b->utf8) Xfree (b->utf8);
- b->tree = NULL;
- b->mb = NULL;
- b->wc = NULL;
- b->utf8 = NULL;
- return;
-}
-
-Private void
-_XimThaiSetFocus(
- XIC xic)
-{
- Xic ic = (Xic)xic;
- XIC current_ic = ((Xim)ic->core.im)->private.local.current_ic;
-
- if (current_ic == (XIC)ic)
- return;
-
- if (current_ic != (XIC)NULL) {
- _XimThaiUnSetFocus(current_ic);
- }
- ((Xim)ic->core.im)->private.local.current_ic = (XIC)ic;
-
- if (ic->core.focus_window)
- _XRegisterFilterByType(ic->core.im->core.display, ic->core.focus_window,
- KeyPress, KeyPress, _XimThaiFilter, (XPointer)ic);
- return;
-}
-
-Private void
-_XimThaiReset(
- XIC xic)
-{
- Xic ic = (Xic)xic;
- DefTreeBase *b = &ic->private.local.base;
- ic->private.local.thai.comp_state = 0;
- ic->private.local.thai.keysym = 0;
- b->mb[b->tree[ic->private.local.composed].mb] = '\0';
- b->wc[b->tree[ic->private.local.composed].wc] = '\0';
- b->utf8[b->tree[ic->private.local.composed].utf8] = '\0';
-}
-
-Private char *
-_XimThaiMbReset(
- XIC xic)
-{
- _XimThaiReset(xic);
- return (char *)NULL;
-}
-
-Private wchar_t *
-_XimThaiWcReset(
- XIC xic)
-{
- _XimThaiReset(xic);
- return (wchar_t *)NULL;
-}
-
-Private XICMethodsRec Thai_ic_methods = {
- _XimThaiDestroyIC, /* destroy */
- _XimThaiSetFocus, /* set_focus */
- _XimThaiUnSetFocus, /* unset_focus */
- _XimLocalSetICValues, /* set_values */
- _XimLocalGetICValues, /* get_values */
- _XimThaiMbReset, /* mb_reset */
- _XimThaiWcReset, /* wc_reset */
- _XimThaiMbReset, /* utf8_reset */
- _XimLocalMbLookupString, /* mb_lookup_string */
- _XimLocalWcLookupString, /* wc_lookup_string */
- _XimLocalUtf8LookupString /* utf8_lookup_string */
-};
-
-XIC
-_XimThaiCreateIC(
- XIM im,
- XIMArg *values)
-{
- Xic ic;
- XimDefICValues ic_values;
- XIMResourceList res;
- unsigned int num;
- int len;
- DefTree *tree;
-
- if((ic = (Xic)Xmalloc(sizeof(XicRec))) == (Xic)NULL) {
- return ((XIC)NULL);
- }
- bzero((char *)ic, sizeof(XicRec));
-
- ic->methods = &Thai_ic_methods;
- ic->core.im = im;
- ic->core.filter_events = KeyPressMask;
-
- if (! (ic->private.local.base.tree = tree = (DefTree *)Xmalloc(sizeof(DefTree)*3)) )
- goto Set_Error;
- if (! (ic->private.local.base.mb = (char *)Xmalloc(21)) )
- goto Set_Error;
- if (! (ic->private.local.base.wc = (wchar_t*)Xmalloc(sizeof(wchar_t)*21)) )
- goto Set_Error;
- if (! (ic->private.local.base.utf8 = (char *)Xmalloc(21)) )
- goto Set_Error;
- ic->private.local.context = 1;
- tree[1].mb = 1;
- tree[1].wc = 1;
- tree[1].utf8 = 1;
- ic->private.local.composed = 2;
- tree[2].mb = 11;
- tree[2].wc = 11;
- tree[2].utf8 = 11;
-
- ic->private.local.thai.comp_state = 0;
- ic->private.local.thai.keysym = 0;
- ic->private.local.thai.input_mode = 0;
-
- num = im->core.ic_num_resources;
- len = sizeof(XIMResource) * num;
- if((res = (XIMResourceList)Xmalloc(len)) == (XIMResourceList)NULL) {
- goto Set_Error;
- }
- (void)memcpy((char *)res, (char *)im->core.ic_resources, len);
- ic->private.local.ic_resources = res;
- ic->private.local.ic_num_resources = num;
-
- bzero((char *)&ic_values, sizeof(XimDefICValues));
- if(_XimCheckLocalInputStyle(ic, (XPointer)&ic_values, values,
- im->core.styles, res, num) == False) {
- goto Set_Error;
- }
-
- _XimSetICMode(res, num, ic_values.input_style);
-
- if(_XimSetICValueData(ic, (XPointer)&ic_values,
- ic->private.local.ic_resources,
- ic->private.local.ic_num_resources,
- values, XIM_CREATEIC, True)) {
- goto Set_Error;
- }
- if(_XimSetICDefaults(ic, (XPointer)&ic_values,
- XIM_SETICDEFAULTS, res, num) == False) {
- goto Set_Error;
- }
- ic_values.filter_events = KeyPressMask;
- _XimSetCurrentICValues(ic, &ic_values);
-
- return ((XIC)ic);
-
-Set_Error :
- if (ic->private.local.ic_resources) {
- Xfree(ic->private.local.ic_resources);
- }
- Xfree(ic);
- return((XIC)NULL);
-}
+/******************************************************************
+
+ Copyright 1992, 1993, 1994 by FUJITSU LIMITED
+ Copyright 1993 by Digital Equipment Corporation
+
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of FUJITSU LIMITED and
+Digital Equipment Corporation not be used in advertising or publicity
+pertaining to distribution of the software without specific, written
+prior permission. FUJITSU LIMITED and Digital Equipment Corporation
+makes no representations about the suitability of this software for
+any purpose. It is provided "as is" without express or implied
+warranty.
+
+FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION DISCLAIM ALL
+WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR
+ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
+IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+THIS SOFTWARE.
+
+ Author: Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+ Modifier: Franky Ling Digital Equipment Corporation
+ frankyling@hgrd01.enet.dec.com
+
+******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include <X11/Xlib.h>
+#include <X11/Xmd.h>
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "Ximint.h"
+
+Private void
+_XimThaiUnSetFocus(
+ XIC xic)
+{
+ Xic ic = (Xic)xic;
+ ((Xim)ic->core.im)->private.local.current_ic = (XIC)NULL;
+
+ if (ic->core.focus_window)
+ _XUnregisterFilter(ic->core.im->core.display, ic->core.focus_window,
+ _XimThaiFilter, (XPointer)ic);
+ return;
+}
+
+Private void
+_XimThaiDestroyIC(
+ XIC xic)
+{
+ Xic ic = (Xic)xic;
+ DefTreeBase *b = &ic->private.local.base;
+
+ if(((Xim)ic->core.im)->private.local.current_ic == (XIC)ic) {
+ _XimThaiUnSetFocus(xic);
+ }
+ if(ic->private.local.ic_resources) {
+ Xfree(ic->private.local.ic_resources);
+ ic->private.local.ic_resources = NULL;
+ }
+
+ if (b->tree) Xfree (b->tree);
+ if (b->mb) Xfree (b->mb);
+ if (b->wc) Xfree (b->wc);
+ if (b->utf8) Xfree (b->utf8);
+ b->tree = NULL;
+ b->mb = NULL;
+ b->wc = NULL;
+ b->utf8 = NULL;
+ return;
+}
+
+Private void
+_XimThaiSetFocus(
+ XIC xic)
+{
+ Xic ic = (Xic)xic;
+ XIC current_ic = ((Xim)ic->core.im)->private.local.current_ic;
+
+ if (current_ic == (XIC)ic)
+ return;
+
+ if (current_ic != (XIC)NULL) {
+ _XimThaiUnSetFocus(current_ic);
+ }
+ ((Xim)ic->core.im)->private.local.current_ic = (XIC)ic;
+
+ if (ic->core.focus_window)
+ _XRegisterFilterByType(ic->core.im->core.display, ic->core.focus_window,
+ KeyPress, KeyPress, _XimThaiFilter, (XPointer)ic);
+ return;
+}
+
+Private void
+_XimThaiReset(
+ XIC xic)
+{
+ Xic ic = (Xic)xic;
+ DefTreeBase *b = &ic->private.local.base;
+ ic->private.local.thai.comp_state = 0;
+ ic->private.local.thai.keysym = 0;
+ b->mb[b->tree[ic->private.local.composed].mb] = '\0';
+ b->wc[b->tree[ic->private.local.composed].wc] = '\0';
+ b->utf8[b->tree[ic->private.local.composed].utf8] = '\0';
+}
+
+Private char *
+_XimThaiMbReset(
+ XIC xic)
+{
+ _XimThaiReset(xic);
+ return (char *)NULL;
+}
+
+Private wchar_t *
+_XimThaiWcReset(
+ XIC xic)
+{
+ _XimThaiReset(xic);
+ return (wchar_t *)NULL;
+}
+
+Private XICMethodsRec Thai_ic_methods = {
+ _XimThaiDestroyIC, /* destroy */
+ _XimThaiSetFocus, /* set_focus */
+ _XimThaiUnSetFocus, /* unset_focus */
+ _XimLocalSetICValues, /* set_values */
+ _XimLocalGetICValues, /* get_values */
+ _XimThaiMbReset, /* mb_reset */
+ _XimThaiWcReset, /* wc_reset */
+ _XimThaiMbReset, /* utf8_reset */
+ _XimLocalMbLookupString, /* mb_lookup_string */
+ _XimLocalWcLookupString, /* wc_lookup_string */
+ _XimLocalUtf8LookupString /* utf8_lookup_string */
+};
+
+XIC
+_XimThaiCreateIC(
+ XIM im,
+ XIMArg *values)
+{
+ Xic ic;
+ XimDefICValues ic_values;
+ XIMResourceList res;
+ unsigned int num;
+ int len;
+ DefTree *tree;
+
+ if((ic = Xcalloc(1, sizeof(XicRec))) == (Xic)NULL) {
+ return ((XIC)NULL);
+ }
+
+ ic->methods = &Thai_ic_methods;
+ ic->core.im = im;
+ ic->core.filter_events = KeyPressMask;
+
+ if (! (ic->private.local.base.tree = tree = (DefTree *)Xmalloc(sizeof(DefTree)*3)) )
+ goto Set_Error;
+ if (! (ic->private.local.base.mb = (char *)Xmalloc(21)) )
+ goto Set_Error;
+ if (! (ic->private.local.base.wc = (wchar_t*)Xmalloc(sizeof(wchar_t)*21)) )
+ goto Set_Error;
+ if (! (ic->private.local.base.utf8 = (char *)Xmalloc(21)) )
+ goto Set_Error;
+ ic->private.local.context = 1;
+ tree[1].mb = 1;
+ tree[1].wc = 1;
+ tree[1].utf8 = 1;
+ ic->private.local.composed = 2;
+ tree[2].mb = 11;
+ tree[2].wc = 11;
+ tree[2].utf8 = 11;
+
+ ic->private.local.thai.comp_state = 0;
+ ic->private.local.thai.keysym = 0;
+ ic->private.local.thai.input_mode = 0;
+
+ num = im->core.ic_num_resources;
+ len = sizeof(XIMResource) * num;
+ if((res = (XIMResourceList)Xmalloc(len)) == (XIMResourceList)NULL) {
+ goto Set_Error;
+ }
+ (void)memcpy((char *)res, (char *)im->core.ic_resources, len);
+ ic->private.local.ic_resources = res;
+ ic->private.local.ic_num_resources = num;
+
+ bzero((char *)&ic_values, sizeof(XimDefICValues));
+ if(_XimCheckLocalInputStyle(ic, (XPointer)&ic_values, values,
+ im->core.styles, res, num) == False) {
+ goto Set_Error;
+ }
+
+ _XimSetICMode(res, num, ic_values.input_style);
+
+ if(_XimSetICValueData(ic, (XPointer)&ic_values,
+ ic->private.local.ic_resources,
+ ic->private.local.ic_num_resources,
+ values, XIM_CREATEIC, True)) {
+ goto Set_Error;
+ }
+ if(_XimSetICDefaults(ic, (XPointer)&ic_values,
+ XIM_SETICDEFAULTS, res, num) == False) {
+ goto Set_Error;
+ }
+ ic_values.filter_events = KeyPressMask;
+ _XimSetCurrentICValues(ic, &ic_values);
+
+ return ((XIC)ic);
+
+Set_Error :
+ if (ic->private.local.ic_resources) {
+ Xfree(ic->private.local.ic_resources);
+ }
+ Xfree(ic);
+ return((XIC)NULL);
+}
diff --git a/libX11/modules/im/ximcp/imTrX.c b/libX11/modules/im/ximcp/imTrX.c
index edcaf0852..27ef03e21 100644
--- a/libX11/modules/im/ximcp/imTrX.c
+++ b/libX11/modules/im/ximcp/imTrX.c
@@ -1,519 +1,518 @@
-/*
- * Copyright 1992 Oracle and/or its affiliates. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-/******************************************************************
-
- Copyright 1992, 1993, 1994 by FUJITSU LIMITED
-
-Permission to use, copy, modify, distribute, and sell this software
-and its documentation for any purpose is hereby granted without fee,
-provided that the above copyright notice appear in all copies and
-that both that copyright notice and this permission notice appear
-in supporting documentation, and that the name of FUJITSU LIMITED
-not be used in advertising or publicity pertaining to distribution
-of the software without specific, written prior permission.
-FUJITSU LIMITED makes no representations about the suitability of
-this software for any purpose.
-It is provided "as is" without express or implied warranty.
-
-FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
-EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
-CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
-USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
-
- Author: Hideki Hiura (hhiura@Sun.COM) Sun Microsystems, Inc.
- Takashi Fujiwara FUJITSU LIMITED
- fujiwara@a80.tech.yk.fujitsu.co.jp
-
-******************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <string.h>
-#include <X11/Xatom.h>
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "Ximint.h"
-#include "XimTrInt.h"
-#include "XimTrX.h"
-
-Private Bool
-_XimXRegisterDispatcher(
- Xim im,
- Bool (*callback)(
- Xim, INT16, XPointer, XPointer
- ),
- XPointer call_data)
-{
- XIntrCallbackPtr rec;
- XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
-
- if (!(rec = (XIntrCallbackPtr)Xmalloc(sizeof(XIntrCallbackRec))))
- return False;
-
- rec->func = callback;
- rec->call_data = call_data;
- rec->next = spec->intr_cb;
- spec->intr_cb = rec;
- return True;
-}
-
-Private void
-_XimXFreeIntrCallback(
- Xim im)
-{
- XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
- register XIntrCallbackPtr rec, next;
-
- for (rec = spec->intr_cb; rec;) {
- next = rec->next;
- Xfree(rec);
- rec = next;
- }
- return;
-}
-
-Private Bool
-_XimXCallDispatcher(Xim im, INT16 len, XPointer data)
-{
- register XIntrCallbackRec *rec;
- XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
-
- for (rec = spec->intr_cb; rec; rec = rec->next) {
- if ((*rec->func)(im, len, data, rec->call_data))
- return True;
- }
- return False;
-}
-
-Private Bool
-_XimXFilterWaitEvent(
- Display *d,
- Window w,
- XEvent *ev,
- XPointer arg)
-{
- Xim im = (Xim)arg;
- XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
- Bool ret;
-
- spec->ev = (XPointer)ev;
- ret = _XimFilterWaitEvent(im);
-
- /*
- * If ev is a pointer to a stack variable, there could be
- * a coredump later on if the pointer is dereferenced.
- * Therefore, reset to NULL to force reinitialization in
- * _XimXRead().
- *
- * Keep in mind _XimXRead may be called again when the stack
- * is very different.
- */
- spec->ev = (XPointer)NULL;
-
- return ret;
-}
-
-Private Bool
-_CheckConnect(
- Display *display,
- XEvent *event,
- XPointer xim)
-{
- Xim im = (Xim)xim;
- XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
-
- if ((event->type == ClientMessage)
- && (event->xclient.message_type == spec->imconnectid)) {
- return True;
- }
- return False;
-}
-
-Private Bool
-_XimXConnect(Xim im)
-{
- XEvent event;
- XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
- CARD32 major_code;
- CARD32 minor_code;
-
- if (!(spec->lib_connect_wid = XCreateSimpleWindow(im->core.display,
- DefaultRootWindow(im->core.display), 0, 0, 1, 1, 1, 0, 0))) {
- return False;
- }
-
- event.xclient.type = ClientMessage;
- event.xclient.display = im->core.display;
- event.xclient.window = im->private.proto.im_window;
- event.xclient.message_type = spec->imconnectid;
- event.xclient.format = 32;
- event.xclient.data.l[0] = (CARD32)spec->lib_connect_wid;
- event.xclient.data.l[1] = spec->major_code;
- event.xclient.data.l[2] = spec->minor_code;
- event.xclient.data.l[3] = 0;
- event.xclient.data.l[4] = 0;
-
- if(event.xclient.data.l[1] == 1 || event.xclient.data.l[1] == 2) {
- XWindowAttributes atr;
- long event_mask;
-
- XGetWindowAttributes(im->core.display, spec->lib_connect_wid, &atr);
- event_mask = atr.your_event_mask | PropertyChangeMask;
- XSelectInput(im->core.display, spec->lib_connect_wid, event_mask);
- _XRegisterFilterByType(im->core.display, spec->lib_connect_wid,
- PropertyNotify, PropertyNotify,
- _XimXFilterWaitEvent, (XPointer)im);
- }
-
- XSendEvent(im->core.display, im->private.proto.im_window,
- False, NoEventMask, &event);
- XFlush(im->core.display);
-
- for (;;) {
- XIfEvent(im->core.display, &event, _CheckConnect, (XPointer)im);
- if (event.xclient.type != ClientMessage) {
- return False;
- }
- if (event.xclient.message_type == spec->imconnectid)
- break;
- }
-
- spec->ims_connect_wid = (Window)event.xclient.data.l[0];
- major_code = (CARD32)event.xclient.data.l[1];
- minor_code = (CARD32)event.xclient.data.l[2];
-
- if (((major_code == 0) && (minor_code <= 2)) ||
- ((major_code == 1) && (minor_code == 0)) ||
- ((major_code == 2) && (minor_code <= 1))) {
- spec->major_code = major_code;
- spec->minor_code = minor_code;
- }
- if (((major_code == 0) && (minor_code == 2)) ||
- ((major_code == 2) && (minor_code == 1))) {
- spec->BoundarySize = (CARD32)event.xclient.data.l[3];
- }
-
- /* ClientMessage Event Filter */
- _XRegisterFilterByType(im->core.display, spec->lib_connect_wid,
- ClientMessage, ClientMessage,
- _XimXFilterWaitEvent, (XPointer)im);
- return True;
-}
-
-Private Bool
-_XimXShutdown(Xim im)
-{
- XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
-
- if (!spec)
- return True;
-
- /* ClientMessage Event Filter */
- _XUnregisterFilter(im->core.display,
- ((XSpecRec *)im->private.proto.spec)->lib_connect_wid,
- _XimXFilterWaitEvent, (XPointer)im);
- XDestroyWindow(im->core.display,
- ((XSpecRec *)im->private.proto.spec)->lib_connect_wid);
- _XimXFreeIntrCallback(im);
- Xfree(spec);
- im->private.proto.spec = 0;
- return True;
-}
-
-Private char *
-_NewAtom(
- char *atomName)
-{
- static int sequence = 0;
-
- (void)sprintf(atomName, "_client%d", sequence);
- sequence = ((sequence < 20) ? sequence + 1 : 0);
- return atomName;
-}
-
-Private Bool
-_XimXWrite(Xim im, INT16 len, XPointer data)
-{
- Atom atom;
- char atomName[16];
- XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
- XEvent event;
- CARD8 *p;
- CARD32 major_code = spec->major_code;
- CARD32 minor_code = spec->minor_code;
- int BoundSize;
-
- bzero(&event,sizeof(XEvent));
- event.xclient.type = ClientMessage;
- event.xclient.display = im->core.display;
- event.xclient.window = spec->ims_connect_wid;
- if(major_code == 1 && minor_code == 0) {
- BoundSize = 0;
- } else if((major_code == 0 && minor_code == 2) ||
- (major_code == 2 && minor_code == 1)) {
- BoundSize = spec->BoundarySize;
- } else if(major_code == 0 && minor_code == 1) {
- BoundSize = len;
- } else {
- BoundSize = XIM_CM_DATA_SIZE;
- }
- if (len > BoundSize) {
- event.xclient.message_type = spec->improtocolid;
- atom = XInternAtom(im->core.display, _NewAtom(atomName), False);
- XChangeProperty(im->core.display, spec->ims_connect_wid,
- atom, XA_STRING, 8, PropModeAppend,
- (unsigned char *)data, len);
- if(major_code == 0) {
- event.xclient.format = 32;
- event.xclient.data.l[0] = (long)len;
- event.xclient.data.l[1] = (long)atom;
- XSendEvent(im->core.display, spec->ims_connect_wid,
- False, NoEventMask, &event);
- }
- } else {
- int length;
-
- event.xclient.format = 8;
- for(length = 0 ; length < len ; length += XIM_CM_DATA_SIZE) {
- p = (CARD8 *)&event.xclient.data.b[0];
- if((length + XIM_CM_DATA_SIZE) >= len) {
- event.xclient.message_type = spec->improtocolid;
- bzero(p, XIM_CM_DATA_SIZE);
- memcpy((char *)p, (data + length), (len - length));
- } else {
- event.xclient.message_type = spec->immoredataid;
- memcpy((char *)p, (data + length), XIM_CM_DATA_SIZE);
- }
- XSendEvent(im->core.display, spec->ims_connect_wid,
- False, NoEventMask, &event);
- }
- }
-
- return True;
-}
-
-Private Bool
-_XimXGetReadData(
- Xim im,
- char *buf,
- int buf_len,
- int *ret_len,
- XEvent *event)
-{
- char *data;
- int len;
-
- char tmp_buf[XIM_CM_DATA_SIZE];
- XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
- unsigned long length;
- Atom prop;
- int return_code;
- Atom type_ret;
- int format_ret;
- unsigned long nitems;
- unsigned long bytes_after_ret;
- unsigned char *prop_ret;
-
- if ((event->type == ClientMessage) &&
- !((event->xclient.message_type == spec->improtocolid) ||
- (event->xclient.message_type == spec->immoredataid))) {
- /* This event has nothing to do with us,
- * FIXME should not have gotten here then...
- */
- return False;
- } else if ((event->type == ClientMessage) && (event->xclient.format == 8)) {
- data = event->xclient.data.b;
- if (buf_len >= XIM_CM_DATA_SIZE) {
- (void)memcpy(buf, data, XIM_CM_DATA_SIZE);
- *ret_len = XIM_CM_DATA_SIZE;
- } else {
- (void)memcpy(buf, data, buf_len);
- len = XIM_CM_DATA_SIZE - buf_len;
- (void)memcpy(tmp_buf, &data[buf_len], len);
- bzero(data, XIM_CM_DATA_SIZE);
- (void)memcpy(data, tmp_buf, len);
- XPutBackEvent(im->core.display, event);
- *ret_len = buf_len;
- }
- } else if ((event->type == ClientMessage)
- && (event->xclient.format == 32)) {
- length = (unsigned long)event->xclient.data.l[0];
- prop = (Atom)event->xclient.data.l[1];
- return_code = XGetWindowProperty(im->core.display,
- spec->lib_connect_wid, prop, 0L,
- (long)((length + 3)/ 4), True, AnyPropertyType,
- &type_ret, &format_ret, &nitems, &bytes_after_ret, &prop_ret);
- if (return_code != Success || format_ret == 0 || nitems == 0) {
- if (return_code == Success)
- XFree(prop_ret);
- return False;
- }
- if (buf_len >= length) {
- (void)memcpy(buf, prop_ret, (int)nitems);
- *ret_len = (int)nitems;
- if (bytes_after_ret > 0) {
- XFree(prop_ret);
- if (XGetWindowProperty(im->core.display,
- spec->lib_connect_wid, prop, 0L,
- ((length + bytes_after_ret + 3)/ 4),
- True, AnyPropertyType,
- &type_ret, &format_ret, &nitems,
- &bytes_after_ret,
- &prop_ret) == Success) {
- XChangeProperty(im->core.display, spec->lib_connect_wid, prop,
- XA_STRING, 8, PropModePrepend, &prop_ret[length],
- (nitems - length));
- } else {
- return False;
- }
- }
- } else {
- (void)memcpy(buf, prop_ret, buf_len);
- *ret_len = buf_len;
- len = nitems - buf_len;
-
- if (bytes_after_ret > 0) {
- XFree(prop_ret);
- if (XGetWindowProperty(im->core.display,
- spec->lib_connect_wid, prop, 0L,
- ((length + bytes_after_ret + 3)/ 4),
- True, AnyPropertyType,
- &type_ret, &format_ret, &nitems,
- &bytes_after_ret, &prop_ret) != Success) {
- return False;
- }
- }
- XChangeProperty(im->core.display, spec->lib_connect_wid, prop,
- XA_STRING, 8, PropModePrepend, &prop_ret[buf_len], len);
- event->xclient.data.l[0] = (long)len;
- event->xclient.data.l[1] = (long)prop;
- XPutBackEvent(im->core.display, event);
- }
- XFree(prop_ret);
- } else if (event->type == PropertyNotify) {
- prop = event->xproperty.atom;
- return_code = XGetWindowProperty(im->core.display,
- spec->lib_connect_wid, prop, 0L,
- 1000000L, True, AnyPropertyType,
- &type_ret, &format_ret, &nitems, &bytes_after_ret, &prop_ret);
- if (return_code != Success || format_ret == 0 || nitems == 0) {
- if (return_code == Success)
- XFree(prop_ret);
- return False;
- }
- if (buf_len >= nitems) {
- (void)memcpy(buf, prop_ret, (int)nitems);
- *ret_len = (int)nitems;
- } else {
- (void)memcpy(buf, prop_ret, buf_len);
- *ret_len = buf_len;
- len = nitems - buf_len;
- XChangeProperty(im->core.display, spec->lib_connect_wid, prop,
- XA_STRING, 8, PropModePrepend, &prop_ret[buf_len], len);
- }
- XFree(prop_ret);
- }
- return True;
-}
-
-Private Bool
-_CheckCMEvent(
- Display *display,
- XEvent *event,
- XPointer xim)
-{
- Xim im = (Xim)xim;
- XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
- CARD32 major_code = spec->major_code;
-
- if ((event->type == ClientMessage)
- &&((event->xclient.message_type == spec->improtocolid) ||
- (event->xclient.message_type == spec->immoredataid)))
- return True;
- if((major_code == 1 || major_code == 2) &&
- (event->type == PropertyNotify) &&
- (event->xproperty.state == PropertyNewValue))
- return True;
- return False;
-}
-
-Private Bool
-_XimXRead(Xim im, XPointer recv_buf, int buf_len, int *ret_len)
-{
- XEvent *ev;
- XEvent event;
- int len = 0;
- XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
- XPointer arg = spec->ev;
-
- if (!arg) {
- bzero(&event, sizeof(XEvent));
- ev = &event;
- XIfEvent(im->core.display, ev, _CheckCMEvent, (XPointer)im);
- } else {
- ev = (XEvent *)arg;
- spec->ev = (XPointer)NULL;
- }
- if (!(_XimXGetReadData(im, recv_buf, buf_len, &len, ev)))
- return False;
- *ret_len = len;
- return True;
-}
-
-Private void
-_XimXFlush(Xim im)
-{
- XFlush(im->core.display);
- return;
-}
-
-Public Bool
-_XimXConf(Xim im, char *address)
-{
- XSpecRec *spec;
-
- if (!(spec = (XSpecRec *)Xmalloc(sizeof(XSpecRec))))
- return False;
- bzero(spec, sizeof(XSpecRec));
-
- spec->improtocolid = XInternAtom(im->core.display, _XIM_PROTOCOL, False);
- spec->imconnectid = XInternAtom(im->core.display, _XIM_XCONNECT, False);
- spec->immoredataid = XInternAtom(im->core.display, _XIM_MOREDATA, False);
- spec->major_code = MAJOR_TRANSPORT_VERSION;
- spec->minor_code = MINOR_TRANSPORT_VERSION;
-
- im->private.proto.spec = (XPointer)spec;
- im->private.proto.connect = _XimXConnect;
- im->private.proto.shutdown = _XimXShutdown;
- im->private.proto.write = _XimXWrite;
- im->private.proto.read = _XimXRead;
- im->private.proto.flush = _XimXFlush;
- im->private.proto.register_dispatcher = _XimXRegisterDispatcher;
- im->private.proto.call_dispatcher = _XimXCallDispatcher;
-
- return True;
-}
+/*
+ * Copyright 1992 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+/******************************************************************
+
+ Copyright 1992, 1993, 1994 by FUJITSU LIMITED
+
+Permission to use, copy, modify, distribute, and sell this software
+and its documentation for any purpose is hereby granted without fee,
+provided that the above copyright notice appear in all copies and
+that both that copyright notice and this permission notice appear
+in supporting documentation, and that the name of FUJITSU LIMITED
+not be used in advertising or publicity pertaining to distribution
+of the software without specific, written prior permission.
+FUJITSU LIMITED makes no representations about the suitability of
+this software for any purpose.
+It is provided "as is" without express or implied warranty.
+
+FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+ Author: Hideki Hiura (hhiura@Sun.COM) Sun Microsystems, Inc.
+ Takashi Fujiwara FUJITSU LIMITED
+ fujiwara@a80.tech.yk.fujitsu.co.jp
+
+******************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <string.h>
+#include <X11/Xatom.h>
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "Ximint.h"
+#include "XimTrInt.h"
+#include "XimTrX.h"
+
+Private Bool
+_XimXRegisterDispatcher(
+ Xim im,
+ Bool (*callback)(
+ Xim, INT16, XPointer, XPointer
+ ),
+ XPointer call_data)
+{
+ XIntrCallbackPtr rec;
+ XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
+
+ if (!(rec = (XIntrCallbackPtr)Xmalloc(sizeof(XIntrCallbackRec))))
+ return False;
+
+ rec->func = callback;
+ rec->call_data = call_data;
+ rec->next = spec->intr_cb;
+ spec->intr_cb = rec;
+ return True;
+}
+
+Private void
+_XimXFreeIntrCallback(
+ Xim im)
+{
+ XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
+ register XIntrCallbackPtr rec, next;
+
+ for (rec = spec->intr_cb; rec;) {
+ next = rec->next;
+ Xfree(rec);
+ rec = next;
+ }
+ return;
+}
+
+Private Bool
+_XimXCallDispatcher(Xim im, INT16 len, XPointer data)
+{
+ register XIntrCallbackRec *rec;
+ XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
+
+ for (rec = spec->intr_cb; rec; rec = rec->next) {
+ if ((*rec->func)(im, len, data, rec->call_data))
+ return True;
+ }
+ return False;
+}
+
+Private Bool
+_XimXFilterWaitEvent(
+ Display *d,
+ Window w,
+ XEvent *ev,
+ XPointer arg)
+{
+ Xim im = (Xim)arg;
+ XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
+ Bool ret;
+
+ spec->ev = (XPointer)ev;
+ ret = _XimFilterWaitEvent(im);
+
+ /*
+ * If ev is a pointer to a stack variable, there could be
+ * a coredump later on if the pointer is dereferenced.
+ * Therefore, reset to NULL to force reinitialization in
+ * _XimXRead().
+ *
+ * Keep in mind _XimXRead may be called again when the stack
+ * is very different.
+ */
+ spec->ev = (XPointer)NULL;
+
+ return ret;
+}
+
+Private Bool
+_CheckConnect(
+ Display *display,
+ XEvent *event,
+ XPointer xim)
+{
+ Xim im = (Xim)xim;
+ XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
+
+ if ((event->type == ClientMessage)
+ && (event->xclient.message_type == spec->imconnectid)) {
+ return True;
+ }
+ return False;
+}
+
+Private Bool
+_XimXConnect(Xim im)
+{
+ XEvent event;
+ XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
+ CARD32 major_code;
+ CARD32 minor_code;
+
+ if (!(spec->lib_connect_wid = XCreateSimpleWindow(im->core.display,
+ DefaultRootWindow(im->core.display), 0, 0, 1, 1, 1, 0, 0))) {
+ return False;
+ }
+
+ event.xclient.type = ClientMessage;
+ event.xclient.display = im->core.display;
+ event.xclient.window = im->private.proto.im_window;
+ event.xclient.message_type = spec->imconnectid;
+ event.xclient.format = 32;
+ event.xclient.data.l[0] = (CARD32)spec->lib_connect_wid;
+ event.xclient.data.l[1] = spec->major_code;
+ event.xclient.data.l[2] = spec->minor_code;
+ event.xclient.data.l[3] = 0;
+ event.xclient.data.l[4] = 0;
+
+ if(event.xclient.data.l[1] == 1 || event.xclient.data.l[1] == 2) {
+ XWindowAttributes atr;
+ long event_mask;
+
+ XGetWindowAttributes(im->core.display, spec->lib_connect_wid, &atr);
+ event_mask = atr.your_event_mask | PropertyChangeMask;
+ XSelectInput(im->core.display, spec->lib_connect_wid, event_mask);
+ _XRegisterFilterByType(im->core.display, spec->lib_connect_wid,
+ PropertyNotify, PropertyNotify,
+ _XimXFilterWaitEvent, (XPointer)im);
+ }
+
+ XSendEvent(im->core.display, im->private.proto.im_window,
+ False, NoEventMask, &event);
+ XFlush(im->core.display);
+
+ for (;;) {
+ XIfEvent(im->core.display, &event, _CheckConnect, (XPointer)im);
+ if (event.xclient.type != ClientMessage) {
+ return False;
+ }
+ if (event.xclient.message_type == spec->imconnectid)
+ break;
+ }
+
+ spec->ims_connect_wid = (Window)event.xclient.data.l[0];
+ major_code = (CARD32)event.xclient.data.l[1];
+ minor_code = (CARD32)event.xclient.data.l[2];
+
+ if (((major_code == 0) && (minor_code <= 2)) ||
+ ((major_code == 1) && (minor_code == 0)) ||
+ ((major_code == 2) && (minor_code <= 1))) {
+ spec->major_code = major_code;
+ spec->minor_code = minor_code;
+ }
+ if (((major_code == 0) && (minor_code == 2)) ||
+ ((major_code == 2) && (minor_code == 1))) {
+ spec->BoundarySize = (CARD32)event.xclient.data.l[3];
+ }
+
+ /* ClientMessage Event Filter */
+ _XRegisterFilterByType(im->core.display, spec->lib_connect_wid,
+ ClientMessage, ClientMessage,
+ _XimXFilterWaitEvent, (XPointer)im);
+ return True;
+}
+
+Private Bool
+_XimXShutdown(Xim im)
+{
+ XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
+
+ if (!spec)
+ return True;
+
+ /* ClientMessage Event Filter */
+ _XUnregisterFilter(im->core.display,
+ ((XSpecRec *)im->private.proto.spec)->lib_connect_wid,
+ _XimXFilterWaitEvent, (XPointer)im);
+ XDestroyWindow(im->core.display,
+ ((XSpecRec *)im->private.proto.spec)->lib_connect_wid);
+ _XimXFreeIntrCallback(im);
+ Xfree(spec);
+ im->private.proto.spec = 0;
+ return True;
+}
+
+Private char *
+_NewAtom(
+ char *atomName)
+{
+ static int sequence = 0;
+
+ (void)sprintf(atomName, "_client%d", sequence);
+ sequence = ((sequence < 20) ? sequence + 1 : 0);
+ return atomName;
+}
+
+Private Bool
+_XimXWrite(Xim im, INT16 len, XPointer data)
+{
+ Atom atom;
+ char atomName[16];
+ XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
+ XEvent event;
+ CARD8 *p;
+ CARD32 major_code = spec->major_code;
+ CARD32 minor_code = spec->minor_code;
+ int BoundSize;
+
+ bzero(&event,sizeof(XEvent));
+ event.xclient.type = ClientMessage;
+ event.xclient.display = im->core.display;
+ event.xclient.window = spec->ims_connect_wid;
+ if(major_code == 1 && minor_code == 0) {
+ BoundSize = 0;
+ } else if((major_code == 0 && minor_code == 2) ||
+ (major_code == 2 && minor_code == 1)) {
+ BoundSize = spec->BoundarySize;
+ } else if(major_code == 0 && minor_code == 1) {
+ BoundSize = len;
+ } else {
+ BoundSize = XIM_CM_DATA_SIZE;
+ }
+ if (len > BoundSize) {
+ event.xclient.message_type = spec->improtocolid;
+ atom = XInternAtom(im->core.display, _NewAtom(atomName), False);
+ XChangeProperty(im->core.display, spec->ims_connect_wid,
+ atom, XA_STRING, 8, PropModeAppend,
+ (unsigned char *)data, len);
+ if(major_code == 0) {
+ event.xclient.format = 32;
+ event.xclient.data.l[0] = (long)len;
+ event.xclient.data.l[1] = (long)atom;
+ XSendEvent(im->core.display, spec->ims_connect_wid,
+ False, NoEventMask, &event);
+ }
+ } else {
+ int length;
+
+ event.xclient.format = 8;
+ for(length = 0 ; length < len ; length += XIM_CM_DATA_SIZE) {
+ p = (CARD8 *)&event.xclient.data.b[0];
+ if((length + XIM_CM_DATA_SIZE) >= len) {
+ event.xclient.message_type = spec->improtocolid;
+ bzero(p, XIM_CM_DATA_SIZE);
+ memcpy((char *)p, (data + length), (len - length));
+ } else {
+ event.xclient.message_type = spec->immoredataid;
+ memcpy((char *)p, (data + length), XIM_CM_DATA_SIZE);
+ }
+ XSendEvent(im->core.display, spec->ims_connect_wid,
+ False, NoEventMask, &event);
+ }
+ }
+
+ return True;
+}
+
+Private Bool
+_XimXGetReadData(
+ Xim im,
+ char *buf,
+ int buf_len,
+ int *ret_len,
+ XEvent *event)
+{
+ char *data;
+ int len;
+
+ char tmp_buf[XIM_CM_DATA_SIZE];
+ XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
+ unsigned long length;
+ Atom prop;
+ int return_code;
+ Atom type_ret;
+ int format_ret;
+ unsigned long nitems;
+ unsigned long bytes_after_ret;
+ unsigned char *prop_ret;
+
+ if ((event->type == ClientMessage) &&
+ !((event->xclient.message_type == spec->improtocolid) ||
+ (event->xclient.message_type == spec->immoredataid))) {
+ /* This event has nothing to do with us,
+ * FIXME should not have gotten here then...
+ */
+ return False;
+ } else if ((event->type == ClientMessage) && (event->xclient.format == 8)) {
+ data = event->xclient.data.b;
+ if (buf_len >= XIM_CM_DATA_SIZE) {
+ (void)memcpy(buf, data, XIM_CM_DATA_SIZE);
+ *ret_len = XIM_CM_DATA_SIZE;
+ } else {
+ (void)memcpy(buf, data, buf_len);
+ len = XIM_CM_DATA_SIZE - buf_len;
+ (void)memcpy(tmp_buf, &data[buf_len], len);
+ bzero(data, XIM_CM_DATA_SIZE);
+ (void)memcpy(data, tmp_buf, len);
+ XPutBackEvent(im->core.display, event);
+ *ret_len = buf_len;
+ }
+ } else if ((event->type == ClientMessage)
+ && (event->xclient.format == 32)) {
+ length = (unsigned long)event->xclient.data.l[0];
+ prop = (Atom)event->xclient.data.l[1];
+ return_code = XGetWindowProperty(im->core.display,
+ spec->lib_connect_wid, prop, 0L,
+ (long)((length + 3)/ 4), True, AnyPropertyType,
+ &type_ret, &format_ret, &nitems, &bytes_after_ret, &prop_ret);
+ if (return_code != Success || format_ret == 0 || nitems == 0) {
+ if (return_code == Success)
+ XFree(prop_ret);
+ return False;
+ }
+ if (buf_len >= length) {
+ (void)memcpy(buf, prop_ret, (int)nitems);
+ *ret_len = (int)nitems;
+ if (bytes_after_ret > 0) {
+ XFree(prop_ret);
+ if (XGetWindowProperty(im->core.display,
+ spec->lib_connect_wid, prop, 0L,
+ ((length + bytes_after_ret + 3)/ 4),
+ True, AnyPropertyType,
+ &type_ret, &format_ret, &nitems,
+ &bytes_after_ret,
+ &prop_ret) == Success) {
+ XChangeProperty(im->core.display, spec->lib_connect_wid, prop,
+ XA_STRING, 8, PropModePrepend, &prop_ret[length],
+ (nitems - length));
+ } else {
+ return False;
+ }
+ }
+ } else {
+ (void)memcpy(buf, prop_ret, buf_len);
+ *ret_len = buf_len;
+ len = nitems - buf_len;
+
+ if (bytes_after_ret > 0) {
+ XFree(prop_ret);
+ if (XGetWindowProperty(im->core.display,
+ spec->lib_connect_wid, prop, 0L,
+ ((length + bytes_after_ret + 3)/ 4),
+ True, AnyPropertyType,
+ &type_ret, &format_ret, &nitems,
+ &bytes_after_ret, &prop_ret) != Success) {
+ return False;
+ }
+ }
+ XChangeProperty(im->core.display, spec->lib_connect_wid, prop,
+ XA_STRING, 8, PropModePrepend, &prop_ret[buf_len], len);
+ event->xclient.data.l[0] = (long)len;
+ event->xclient.data.l[1] = (long)prop;
+ XPutBackEvent(im->core.display, event);
+ }
+ XFree(prop_ret);
+ } else if (event->type == PropertyNotify) {
+ prop = event->xproperty.atom;
+ return_code = XGetWindowProperty(im->core.display,
+ spec->lib_connect_wid, prop, 0L,
+ 1000000L, True, AnyPropertyType,
+ &type_ret, &format_ret, &nitems, &bytes_after_ret, &prop_ret);
+ if (return_code != Success || format_ret == 0 || nitems == 0) {
+ if (return_code == Success)
+ XFree(prop_ret);
+ return False;
+ }
+ if (buf_len >= nitems) {
+ (void)memcpy(buf, prop_ret, (int)nitems);
+ *ret_len = (int)nitems;
+ } else {
+ (void)memcpy(buf, prop_ret, buf_len);
+ *ret_len = buf_len;
+ len = nitems - buf_len;
+ XChangeProperty(im->core.display, spec->lib_connect_wid, prop,
+ XA_STRING, 8, PropModePrepend, &prop_ret[buf_len], len);
+ }
+ XFree(prop_ret);
+ }
+ return True;
+}
+
+Private Bool
+_CheckCMEvent(
+ Display *display,
+ XEvent *event,
+ XPointer xim)
+{
+ Xim im = (Xim)xim;
+ XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
+ CARD32 major_code = spec->major_code;
+
+ if ((event->type == ClientMessage)
+ &&((event->xclient.message_type == spec->improtocolid) ||
+ (event->xclient.message_type == spec->immoredataid)))
+ return True;
+ if((major_code == 1 || major_code == 2) &&
+ (event->type == PropertyNotify) &&
+ (event->xproperty.state == PropertyNewValue))
+ return True;
+ return False;
+}
+
+Private Bool
+_XimXRead(Xim im, XPointer recv_buf, int buf_len, int *ret_len)
+{
+ XEvent *ev;
+ XEvent event;
+ int len = 0;
+ XSpecRec *spec = (XSpecRec *)im->private.proto.spec;
+ XPointer arg = spec->ev;
+
+ if (!arg) {
+ bzero(&event, sizeof(XEvent));
+ ev = &event;
+ XIfEvent(im->core.display, ev, _CheckCMEvent, (XPointer)im);
+ } else {
+ ev = (XEvent *)arg;
+ spec->ev = (XPointer)NULL;
+ }
+ if (!(_XimXGetReadData(im, recv_buf, buf_len, &len, ev)))
+ return False;
+ *ret_len = len;
+ return True;
+}
+
+Private void
+_XimXFlush(Xim im)
+{
+ XFlush(im->core.display);
+ return;
+}
+
+Public Bool
+_XimXConf(Xim im, char *address)
+{
+ XSpecRec *spec;
+
+ if (!(spec = Xcalloc(1, sizeof(XSpecRec))))
+ return False;
+
+ spec->improtocolid = XInternAtom(im->core.display, _XIM_PROTOCOL, False);
+ spec->imconnectid = XInternAtom(im->core.display, _XIM_XCONNECT, False);
+ spec->immoredataid = XInternAtom(im->core.display, _XIM_MOREDATA, False);
+ spec->major_code = MAJOR_TRANSPORT_VERSION;
+ spec->minor_code = MINOR_TRANSPORT_VERSION;
+
+ im->private.proto.spec = (XPointer)spec;
+ im->private.proto.connect = _XimXConnect;
+ im->private.proto.shutdown = _XimXShutdown;
+ im->private.proto.write = _XimXWrite;
+ im->private.proto.read = _XimXRead;
+ im->private.proto.flush = _XimXFlush;
+ im->private.proto.register_dispatcher = _XimXRegisterDispatcher;
+ im->private.proto.call_dispatcher = _XimXCallDispatcher;
+
+ return True;
+}
diff --git a/libX11/modules/im/ximcp/imTrans.c b/libX11/modules/im/ximcp/imTrans.c
index d6c5fc6ad..6d3daee67 100644
--- a/libX11/modules/im/ximcp/imTrans.c
+++ b/libX11/modules/im/ximcp/imTrans.c
@@ -291,17 +291,14 @@ _XimTransConf(
char *paddr;
TransSpecRec *spec;
- if (!(paddr = (char *)Xmalloc(strlen(address) + 1)))
+ if (!(paddr = strdup(address)))
return False;
- if (!(spec = (TransSpecRec *) Xmalloc(sizeof(TransSpecRec)))) {
+ if (!(spec = Xcalloc(1, sizeof(TransSpecRec)))) {
Xfree(paddr);
return False;
}
- bzero(spec, sizeof(TransSpecRec));
-
- (void)strcpy(paddr, address);
spec->address = paddr;
im->private.proto.spec = (XPointer)spec;
diff --git a/libX11/modules/lc/gen/lcGenConv.c b/libX11/modules/lc/gen/lcGenConv.c
index baac73a39..c222c1f2a 100644
--- a/libX11/modules/lc/gen/lcGenConv.c
+++ b/libX11/modules/lc/gen/lcGenConv.c
@@ -1,3149 +1,3148 @@
-/*
- * Copyright 1992, 1993 by TOSHIBA Corp.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of TOSHIBA not be used in advertising
- * or publicity pertaining to distribution of the software without specific,
- * written prior permission. TOSHIBA make no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
- * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- *
- * Author: Katsuhisa Yano TOSHIBA Corp.
- * mopi@osa.ilab.toshiba.co.jp
- */
-/*
- * (c) Copyright 1995 FUJITSU LIMITED
- * This is source code modified by FUJITSU LIMITED under the Joint
- * Development Agreement for the CDE/Motif PST.
- *
- * Modifier: Masayoshi Shimamura FUJITSU LIMITED
- *
- */
-/*
- * 2000
- * Modifier: Ivan Pascal The XFree86 Project
- */
-
-/*
- * A generic locale loader for all kinds of ISO-2022 based codesets.
- * Supports: all locales.
- * How: Provides generic converters for ISO-2022 based codesets. Extensible as
- * far as ISO-2022 is extensible: codesets can be given by name in the
- * stream. Overall distinction between GL (0x00..0x7f) and GR (0x80..0xff).
- * In every chunk between escape sequences, the number of bytes per
- * character (char_size) is constant.
- * Platforms: all systems.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include "XlcGeneric.h"
-#include <stdio.h>
-
-#if !defined(Lynx_22) && !defined(X_LOCALE)
-#define STDCVT
-#endif
-
-typedef struct _CTDataRec {
- const char *name;
- const char *encoding; /* Compound Text encoding */
-} CTDataRec, *CTData;
-
-static CTDataRec directionality_data[] =
-{
- { "BEGIN_LEFT-TO-RIGHT_TEXT", "\2331]" },
- { "BEGIN_RIGHT-TO-LEFT_TEXT", "\2332]" },
- { "END_OF_STRING", "\233]" },
-};
-
-typedef struct _StateRec {
- XLCd lcd;
- /* CT state */
- XlcCharSet charset; /* charset of current state */
- XlcCharSet GL_charset; /* charset of initial state in GL */
- XlcCharSet GR_charset; /* charset of initial state in GR */
- /* MB shift state */
- CodeSet GL_codeset;
- CodeSet GR_codeset;
-} StateRec, *State;
-
-#define GR 0x80 /* begins right-side (non-ascii) region */
-#define GL 0x7f /* ends left-side (ascii) region */
-#define ESC 0x1b
-#define CSI 0x9b
-#define STX 0x02
-
-#define isrightside(c) ((c) & GR)
-#define isleftside(c) (!isrightside(c))
-
-/* Forward declarations for local routines. */
-static int mbstocts (XlcConv conv, XPointer *from, int *from_left,
- XPointer *to, int *to_left, XPointer *args, int num_args);
-static int ctstombs (XlcConv conv, XPointer *from, int *from_left,
- XPointer *to, int *to_left, XPointer *args, int num_args);
-static int cstombs (XlcConv conv, XPointer *from, int *from_left,
- XPointer *to, int *to_left, XPointer *args, int num_args);
-
-/* ------------------------------------------------------------------------- */
-/* Misc */
-/* ------------------------------------------------------------------------- */
-
-static int
-compare(
- const char *src,
- const char *encoding,
- int length)
-{
- const char *start = src;
-
- while (length-- > 0) {
- if (*src++ != *encoding++)
- return 0;
- if (*encoding == '\0')
- return src - start;
- }
-
- return 0;
-}
-
-static unsigned long
-conv_to_dest(
- Conversion conv,
- unsigned long code)
-{
- int i;
- int conv_num = conv->conv_num;
- FontScope convlist = conv->convlist;
-
- for (i = 0; i < conv_num; i++) {
- if (convlist[i].start <= code && code <= convlist[i].end) {
- switch (convlist[i].shift_direction) {
- case '+':
- return(code + convlist[i].shift);
- case '-':
- return(code - convlist[i].shift);
- default:
- return(code);
- }
- }
- }
-
- return(code);
-}
-
-static unsigned long
-conv_to_source(
- Conversion conv,
- unsigned long code)
-{
- int i;
- int conv_num;
- FontScope convlist;
- unsigned long start_p;
- unsigned long start_m;
- unsigned long end_p;
- unsigned long end_m;
-
- if (!conv)
- return(code);
-
- conv_num = conv->conv_num;
- convlist = conv->convlist;
-
- for (i = 0; i < conv_num; i++) {
- switch (convlist[i].shift_direction) {
- case '+':
- start_p = convlist[i].start + convlist[i].shift;
- end_p = convlist[i].end + convlist[i].shift;
- if (start_p <= code && code <= end_p)
- return(code - convlist[i].shift);
- break;
- case '-':
- start_m = convlist[i].start - convlist[i].shift;
- end_m = convlist[i].end - convlist[i].shift;
- if (start_m <= code && code <= end_m)
- return(code + convlist[i].shift);
- break;
- default:
- continue;
- }
- }
-
- return(code);
-}
-
-static unsigned long
-mb_to_gi(
- unsigned long mb,
- CodeSet codeset)
-{
- int i;
- unsigned long mb_tmp, mask = 0;
-
- if (codeset->mbconv) {
- mb_tmp = conv_to_dest(codeset->mbconv, mb);
- if (mb_tmp != mb)
- return(mb_tmp);
- }
-
- if (codeset->side == XlcC0 || codeset->side == XlcGL ||
- codeset->side == XlcC1 || codeset->side == XlcGR) {
-
- for (i = 0; i < codeset->length; i++)
- mask = (mask << 8) | GL;
- mb = mb & mask;
- }
-
- return(mb);
-}
-
-static unsigned long
-gi_to_mb(
- unsigned long glyph_index,
- CodeSet codeset)
-{
- int i;
- unsigned long mask = 0;
-
- if (codeset->side == XlcC1 || codeset->side == XlcGR) {
- for (i = 0; i < codeset->length; i++)
- mask = (mask << 8) | GR;
- glyph_index = glyph_index | mask;
- }
-
- if (codeset->mbconv)
- return( conv_to_source(codeset->mbconv, glyph_index) );
-
- return(glyph_index);
-}
-
-static Bool
-gi_to_wc(
- XLCd lcd,
- unsigned long glyph_index,
- CodeSet codeset,
- wchar_t *wc)
-{
- unsigned char mask = 0;
- unsigned long wc_encoding = codeset->wc_encoding;
- int length = codeset->length;
- unsigned long wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits);
-
- mask = (1 << wc_shift_bits) - 1 ;
-
- for (*wc = 0, length--; length >= 0; length--)
- *wc = (*wc << wc_shift_bits) | ((glyph_index >> (length * 8 )) & mask);
-
- *wc = *wc | wc_encoding;
-
- return(True);
-}
-
-static Bool
-wc_to_gi(
- XLCd lcd,
- wchar_t wc,
- unsigned long *glyph_index,
- CodeSet *codeset)
-{
- int i;
- unsigned char mask = 0;
- unsigned long wc_encoding;
- unsigned long wc_encode_mask = XLC_GENERIC(lcd, wc_encode_mask);
- unsigned long wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits);
- int codeset_num = XLC_GENERIC(lcd, codeset_num);
- CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
-
- wc_encoding = wc & wc_encode_mask;
- for (*codeset = NULL, i = 0; i < codeset_num; i++) {
- if (wc_encoding == codeset_list[i]->wc_encoding) {
- *codeset = codeset_list[i];
- break;
- }
- }
- if (*codeset == NULL)
- return(False);
-
- mask = (1 << wc_shift_bits) - 1 ;
-
- wc = wc & ~wc_encode_mask;
- for (*glyph_index = 0, i = (*codeset)->length - 1; i >= 0; i--)
- *glyph_index = (*glyph_index << 8) |
- ( ((unsigned long)wc >> (i * wc_shift_bits)) & mask );
-
- return(True);
-}
-
-static CodeSet
-mb_parse_codeset(
- State state,
- int num,
- const char **inbufptr,
- int *from_left)
-{
- int len;
- int from_len = (*from_left) + 1;
- const char *src = (*inbufptr) - 1;
- ParseInfo *mb_parse_list = XLC_GENERIC(state->lcd, mb_parse_list);
- ParseInfo parse_info;
- CodeSet codeset;
-
- for (--num ; (parse_info = mb_parse_list[num]) != NULL; num++) {
- len = compare(src, parse_info->encoding, from_len);
- if (len > 0) {
- codeset = parse_info->codeset;
- if (parse_info->type == E_LSL)
- state->GL_codeset = codeset;
- else if (parse_info->type == E_LSR)
- state->GR_codeset = codeset;
- --len;
- *inbufptr += len;
- *from_left -= len;
- return codeset;
- }
- }
- return (CodeSet) NULL;
-}
-
-static CodeSet
-byteM_parse_codeset(
- XLCd lcd,
- const char *inbufptr)
-{
- unsigned char ch;
- CodeSet codeset;
- ByteInfoList byteM;
- ByteInfoListRec byteM_rec;
- ByteInfo byteinfo;
- ByteInfoRec byteinfo_rec;
- Bool hit = False;
- int i, j, k;
-
- int codeset_num = XLC_GENERIC(lcd, codeset_num);
- CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
-
- for (i = 0; i < codeset_num; i++) {
- codeset = codeset_list[i];
- byteM = codeset->byteM;
- if (codeset->side != XlcNONE || byteM == NULL)
- continue;
-
- for (j = 0; j < codeset->length; j++) {
- ch = *((unsigned char *)(inbufptr + j));
- byteM_rec = byteM[j];
- byteinfo = byteM_rec.byteinfo;
-
- for (hit = False, k = 0; k < byteM_rec.byteinfo_num; k++) {
- byteinfo_rec = byteinfo[k];
- if (byteinfo_rec.start <= ch && ch <= byteinfo_rec.end) {
- hit = True;
- break;
- }
- }
-
- if (!hit)
- break;
- }
-
- if (hit)
- return(codeset);
- }
-
- return(NULL);
-}
-
-#define GLGR_parse_codeset(ch) \
- (isrightside(ch) ? (state->GR_codeset) : \
- (state->GL_codeset) )
-
-static XlcCharSet
-gi_parse_charset(
- unsigned long glyph_index,
- CodeSet codeset)
-{
- int i;
- XlcCharSet *charset_list = codeset->charset_list;
- int num_charsets = codeset->num_charsets;
- ExtdSegment ctextseg = codeset->ctextseg;
- XlcCharSet charset = NULL;
- int area_num;
- FontScope area;
-
- /* lockup ct sequence */
- for (i = 0; i < num_charsets; i++) {
- charset = charset_list[i];
- if (*charset->ct_sequence != '\0')
- break;
- }
- if (i >= num_charsets)
- return(NULL);
-
- if (charset->source != CSsrcStd)
- return (charset);
-
- if (!ctextseg)
- return(charset);
-
- area = ctextseg->area;
- area_num = ctextseg->area_num;
-
- for (i = 0; i < area_num; i++) {
-
- if (area[i].start <= glyph_index && glyph_index <= area[i].end) {
-
- charset = ctextseg->charset;
-
- if (*charset->ct_sequence == '\0')
- return(NULL);
-
- break;
- }
- }
-
- return(charset);
-}
-
-static Bool
-ct_parse_csi(
- const char *inbufptr,
- int *ctr_seq_len)
-{
- int i;
- int num = sizeof(directionality_data) / sizeof(directionality_data[0]);
-
- for (i = 0; i < num; i++) {
- if ( !(*ctr_seq_len = strlen(directionality_data[i].encoding)) )
- continue;
-
- if ( strncmp(inbufptr, directionality_data[i].encoding,
- *ctr_seq_len) == 0)
- return(True);
- }
-
- return(False);
-}
-
-static int
-cmp_esc_sequence(
- const char *inbufptr,
- XlcCharSet charset)
-{
- int seq_len, name_len, total_len;
- unsigned char byte_m, byte_l;
- const char *ct_sequence = charset->ct_sequence;
- const char *encoding_name = charset->encoding_name;
-
- /* check esc sequence */
- if ( !(seq_len = strlen(ct_sequence) ) )
- return(0);
- if ( strncmp(inbufptr, ct_sequence, seq_len) != 0)
- return(0);
-
- /* Standard Character Set Encoding ? */
- if (charset->source == CSsrcStd)
- return(seq_len);
-
- /*
- * Non-Standard Character Set Encoding
- *
- * +--- ---+-----+-----+-----+---- ----+-----+-----+------- ------+
- * | ctseq | M | L | encoding name | STX | contents |
- * +--- ---+-----+-----+-----+---- ----+-----+-----+------- ------+
- * 4bytes 1byte 1byte variable length 1byte variable length
- * | |
- * +----------------------------------------------+
- * rest length = ((M - 128) * 128) + (L - 128)
- */
-
- /* get length of encoding name */
- inbufptr += seq_len;
- byte_m = *inbufptr++;
- byte_l = *inbufptr++;
- name_len = strlen(encoding_name);
-
- if (((byte_m - 128) * 128 + (byte_l - 128) - 1) < name_len)
- return(0);
-
- if ( _XlcNCompareISOLatin1(inbufptr, encoding_name, name_len) != 0 )
- return(0);
-
- /* check STX (Start of Text) */
- inbufptr = inbufptr + name_len;
- if ( *inbufptr != STX )
- return(0);
-
- total_len = seq_len + name_len + 3;
- return(total_len);
-}
-
-static Bool
-ct_parse_charset(
- XLCd lcd,
- const char *inbufptr,
- XlcCharSet *charset,
- int *ctr_seq_len)
-{
- int i, j;
- ExtdSegment ctextseg;
- int num_charsets;
- XlcCharSet *charset_list;
- CodeSet codeset;
- int codeset_num = XLC_GENERIC(lcd, codeset_num);
- CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
- int segment_conv_num = XLC_GENERIC(lcd, segment_conv_num);
- SegConv segment_conv = XLC_GENERIC(lcd, segment_conv);
-
- /* get charset from XLC_XLOCALE by escape sequence */
-
- for (i = 0; i < codeset_num; i++) {
- codeset = codeset_list[i];
-
- num_charsets = codeset->num_charsets;
- charset_list = codeset->charset_list;
- ctextseg = codeset->ctextseg;
-
- for (j = 0; j < num_charsets; j++) {
- *charset = charset_list[j];
- if ((*ctr_seq_len = cmp_esc_sequence(inbufptr, *charset)))
- return(True);
- }
-
- if (ctextseg) {
- *charset = ctextseg->charset;
- if ((*ctr_seq_len = cmp_esc_sequence(inbufptr, *charset)))
- return(True);
- }
- }
-
- /* get charset from XLC_SEGMENTCONVERSION by escape sequence */
-
- if (!segment_conv)
- return(False);
-
- for (i = 0; i < segment_conv_num; i++) {
- *charset = segment_conv[i].source;
- if ((*ctr_seq_len = cmp_esc_sequence(inbufptr, *charset)))
- return(True);
- *charset = segment_conv[i].dest;
- if ((*ctr_seq_len = cmp_esc_sequence(inbufptr, *charset)))
- return(True);
- }
-
- return(False);
-}
-
-static Bool
-segment_conversion(
- XLCd lcd,
- XlcCharSet *charset,
- unsigned long *glyph_index)
-{
- int i;
- int segment_conv_num = XLC_GENERIC(lcd, segment_conv_num);
- SegConv segment_conv = XLC_GENERIC(lcd, segment_conv);
- FontScopeRec range;
- ConversionRec conv_rec;
-
- if (!segment_conv)
- return(True);
-
- for (i = 0; i < segment_conv_num; i++) {
- if (segment_conv[i].source == *charset)
- break;
- }
-
- if (i >= segment_conv_num)
- return(True);
-
- range = segment_conv[i].range;
- if (*glyph_index < range.start || range.end < *glyph_index)
- return(True);
-
- *charset = segment_conv[i].dest;
- conv_rec.conv_num = segment_conv[i].conv_num;
- conv_rec.convlist = segment_conv[i].conv;
- *glyph_index = conv_to_dest(&conv_rec, *glyph_index);
-
- return(True);
-}
-
-static CodeSet
-_XlcGetCodeSetFromName(
- XLCd lcd,
- const char *name)
-{
- int i, j;
- XlcCharSet charset;
- int num_charsets;
- XlcCharSet *charset_list;
- CodeSet codeset;
-
- int codeset_num = XLC_GENERIC(lcd, codeset_num);
- CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
-
- for (i = 0; i < codeset_num; i++) {
- codeset = codeset_list[i];
-
- num_charsets = codeset->num_charsets;
- charset_list = codeset->charset_list;
-
- for (j = 0; j < num_charsets; j++) {
- charset = charset_list[j];
-
- if (!strlen(charset->name))
- continue;
- if ( strcmp(charset->name, name) == 0)
- return(codeset);
- }
- }
-
- return(NULL);
-}
-
-static Bool
-_XlcGetCodeSetFromCharSet(
- XLCd lcd,
- XlcCharSet charset,
- CodeSet *codeset,
- unsigned long *glyph_index)
-{
- int j, num;
- CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
- XlcCharSet *charset_list;
- int codeset_num, num_charsets;
- Conversion ctconv;
- unsigned long glyph_index_tmp = 0;
- ExtdSegment ctextseg;
-
- codeset_num = XLC_GENERIC(lcd, codeset_num);
-
- for (num = 0 ; num < codeset_num; num++) {
- *codeset = codeset_list[num];
- ctconv = (*codeset)->ctconv;
- ctextseg = (*codeset)->ctextseg;
-
- num_charsets = (*codeset)->num_charsets;
- charset_list = (*codeset)->charset_list;
-
- glyph_index_tmp = conv_to_source(ctconv, *glyph_index);
-
- if (charset->source == CSsrcStd) {
-
- /* Standard Character Set Encoding */
- if (glyph_index_tmp == *glyph_index) {
- for (j = 0; j < num_charsets; j++) {
- if (charset_list[j] == charset) {
- goto end_loop;
- }
- }
- }
-
- } else {
-
- /* Non-Standard Character Set Encoding */
- for (j = 0; j < num_charsets; j++) {
- if (charset_list[j] == charset) {
- goto end_loop;
- }
- }
-
- if (glyph_index_tmp != *glyph_index) {
- if (ctextseg && ctextseg->charset == charset) {
- goto end_loop;
- }
- }
-
- }
-
- }
-
-end_loop:
- if (num < codeset_num) {
- *glyph_index = glyph_index_tmp;
- return(True);
- }
-
- return(False);
-}
-
-#define check_string_encoding(codeset) (codeset->string_encoding)
-
-static void
-output_ulong_value(
- char *outbufptr,
- unsigned long code,
- int length,
- XlcSide side)
-{
- int i;
-
- for (i = (length - 1) * 8; i >= 0; i -= 8) {
- *outbufptr = ( code >> i) & 0xff;
-
- if (side == XlcC0 || side == XlcGL) {
- *outbufptr = *outbufptr & GL;
- } else if (side == XlcC1 || side == XlcGR) {
- *outbufptr = *outbufptr | GR;
- }
-
- outbufptr++;
- }
-}
-
-/* -------------------------------------------------------------------------- */
-/* Init */
-/* -------------------------------------------------------------------------- */
-
-static XlcCharSet default_GL_charset = 0;
-static XlcCharSet default_GR_charset = 0;
-
-static void
-init_state(
- XlcConv conv)
-{
- State state = (State) conv->state;
-
- /* for CT */
- state->charset = NULL;
- state->GL_charset = default_GL_charset;
- state->GR_charset = default_GR_charset;
-
- /* for MB shift state */
- state->GL_codeset = XLC_GENERIC(state->lcd, initial_state_GL);
- state->GR_codeset = XLC_GENERIC(state->lcd, initial_state_GR);
-}
-
-/* -------------------------------------------------------------------------- */
-/* Convert */
-/* -------------------------------------------------------------------------- */
-
-static int
-mbstowcs_org(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
-
- unsigned char ch;
- unsigned long mb = 0;
- wchar_t wc;
-
- int length = 0, len_left = 0;
- int unconv_num = 0;
- int num;
-
- CodeSet codeset = NULL;
-
- const char *inbufptr = *from;
- wchar_t *outbufptr = (wchar_t *) *to;
- int from_size = *from_left;
-
- unsigned char *mb_parse_table = XLC_GENERIC(lcd, mb_parse_table);
-
- if (from == NULL || *from == NULL) {
- _XlcResetConverter(conv);
- return( 0 );
- }
-
- if (*from_left > *to_left)
- *from_left = *to_left;
-
- while (*from_left && *to_left) {
-
- ch = *inbufptr++;
- (*from_left)--;
-
- /* null ? */
- if (!ch) {
- if (outbufptr) {*outbufptr++ = L'\0';}
- (*to_left)--;
-
- /* error check */
- if (len_left) {
- unconv_num += (length - len_left);
- len_left = 0;
- }
-
- continue;
- }
-
- /* same mb char data */
- if (len_left)
- goto output_one_wc;
-
- /* next mb char data for single shift ? */
- if (mb_parse_table && (num = mb_parse_table[ch]) ) {
- codeset = mb_parse_codeset(state, num, &inbufptr, from_left);
- if (codeset != NULL) {
- length = len_left = codeset->length;
- mb = 0;
- continue;
- }
- }
-
- /* next mb char data for byteM ? */
- if ((codeset = byteM_parse_codeset(lcd, (inbufptr - 1))))
- goto next_mb_char;
-
- /* next mb char data for GL or GR side ? */
- if ((codeset = GLGR_parse_codeset(ch)))
- goto next_mb_char;
-
- /* can't find codeset for the ch */
- unconv_num++;
- continue;
-
-next_mb_char:
- length = len_left = codeset->length;
- mb = 0;
-
-output_one_wc:
- mb = (mb << 8) | ch; /* 1 byte left shift */
- len_left--;
-
- /* last of one mb char data */
- if (!len_left) {
- gi_to_wc(lcd, mb_to_gi(mb, codeset), codeset, &wc);
- if (outbufptr) {*outbufptr++ = wc;}
- (*to_left)--;
- }
-
- } /* end of while */
-
- /* error check on last char */
- if (len_left) {
- inbufptr -= (length - len_left);
- (*from_left) += (length - len_left);
- unconv_num += (length - len_left);
- }
-
- *from = (XPointer) ((const char *) *from + from_size);
- *from_left = 0;
- *to = (XPointer) outbufptr;
-
- return unconv_num;
-}
-
-static int
-stdc_mbstowcs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- const char *src = *((const char **) from);
- wchar_t *dst = *((wchar_t **) to);
- int src_left = *from_left;
- int dst_left = *to_left;
- int length, unconv_num = 0;
-
- while (src_left > 0 && dst_left > 0) {
- length = mbtowc(dst, src, src_left);
-
- if (length > 0) {
- src += length;
- src_left -= length;
- if (dst)
- dst++;
- dst_left--;
- } else if (length < 0) {
- src++;
- src_left--;
- unconv_num++;
- } else {
- /* null ? */
- src++;
- src_left--;
- if (dst)
- *dst++ = L'\0';
- dst_left--;
- }
- }
-
- *from = (XPointer) src;
- if (dst)
- *to = (XPointer) dst;
- *from_left = src_left;
- *to_left = dst_left;
-
- return unconv_num;
-}
-
-static int
-wcstombs_org(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
-
- char *encoding;
- unsigned long mb, glyph_index;
- wchar_t wc;
-
- int length;
- int unconv_num = 0;
-
- CodeSet codeset;
-
- const wchar_t *inbufptr = (const wchar_t *) *from;
- char *outbufptr = *to;
- int from_size = *from_left;
-
- const char *default_string = XLC_PUBLIC(lcd, default_string);
- int defstr_len = strlen(default_string);
-
-
- if (*from_left > *to_left)
- *from_left = *to_left;
-
- while (*from_left && *to_left) {
-
- wc = *inbufptr++;
- (*from_left)--;
-
- /* null ? */
- if (!wc) {
- if (outbufptr) {*outbufptr++ = '\0';}
- (*to_left)--;
-
- continue;
- }
-
- /* convert */
- if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) {
-
- /* output default_string of XDefaultString() */
- if (*to_left < defstr_len)
- break;
- if (outbufptr) {
- strncpy((char *)outbufptr, default_string, defstr_len);
- outbufptr += defstr_len;
- }
- (*to_left) -= defstr_len;
-
- unconv_num++;
-
- } else {
- mb = gi_to_mb(glyph_index, codeset);
- if (codeset->parse_info) {
- Bool need_shift = False;
- switch (codeset->parse_info->type) {
- case E_LSL :
- if (codeset != state->GL_codeset) {
- need_shift = True;
- state->GL_codeset = codeset;
- }
- break;
- case E_LSR :
- if (codeset != state->GR_codeset) {
- need_shift = True;
- state->GR_codeset = codeset;
- }
- break;
- /* case E_SS */
- default:
- need_shift = True;
- }
-
- /* output shift sequence */
- if (need_shift) {
- encoding = codeset->parse_info->encoding;
- length = strlen(encoding);
- if (*to_left < length)
- break;
- if (outbufptr) {
- strncpy((char *)outbufptr, encoding, length);
- outbufptr += length;
- }
- (*to_left) -= length;
- }
- }
-
- /* output characters */
- length = codeset->length;
- if (*to_left < length)
- break;
-
- if (outbufptr) {
- output_ulong_value(outbufptr, mb, length, XlcNONE);
- outbufptr += length;
- }
-
- (*to_left) -= length;
- }
-
- } /* end of while */
-
- *from = (XPointer) ((const wchar_t *) *from + from_size);
- *from_left = 0;
- *to = (XPointer) outbufptr;
-
- return unconv_num;
-}
-
-static int
-stdc_wcstombs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- const wchar_t *src = *((const wchar_t **) from);
- char *dst = *((char **) to);
- int src_left = *from_left;
- int dst_left = *to_left;
- int length, unconv_num = 0;
-
- while (src_left > 0 && dst_left >= MB_CUR_MAX) {
- length = wctomb(dst, *src); /* XXX */
-
- if (length > 0) {
- src++;
- src_left--;
- if (dst)
- dst += length;
- dst_left -= length;
- } else if (length < 0) {
- src++;
- src_left--;
- unconv_num++;
- }
- }
-
- *from = (XPointer) src;
- if (dst)
- *to = (XPointer) dst;
- *from_left = src_left;
- *to_left = dst_left;
-
- return unconv_num;
-}
-
-static int
-wcstocts(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
-
- unsigned long glyph_index;
- wchar_t wc;
-
- int total_len, seq_len, name_len;
- int unconv_num = 0;
- Bool first_flag = True, standard_flag;
- XlcSide side;
-
- CodeSet codeset;
- XlcCharSet charset, old_charset = NULL;
- const char *ct_sequence;
-
- const wchar_t *inbufptr = (const wchar_t *) *from;
- char *outbufptr = *to;
- int from_size = *from_left;
- char *ext_seg_len = NULL;
-
- if (*from_left > *to_left)
- *from_left = *to_left;
-
- while (*from_left && *to_left) {
-
- wc = *inbufptr++;
- (*from_left)--;
-
- /* null ? */
- if (!wc) {
- if (outbufptr) {*outbufptr++ = '\0';}
- (*to_left)--;
-
- continue;
- }
-
- /* convert */
- if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) {
- unconv_num++;
- continue;
- }
-
- /* parse charset */
- if ( !(charset = gi_parse_charset(glyph_index, codeset)) ) {
- unconv_num++;
- continue;
- }
-
- /* Standard Character Set Encoding ? */
- standard_flag = charset->source == CSsrcStd ? True : False;
-
- /*
- * Non-Standard Character Set Encoding
- *
- * +-----+-----+-----+-----+-----+-----+-----+---- ----+-----+-----+
- * | esc sequence | M | L | encoding name | STX |
- * +-----+-----+-----+-----+-----+-----+-----+---- ----+-----+-----+
- * 4bytes 1byte 1byte variable length 1byte
- * | |
- * +-----------------------------------------+
- * name length = ((M - 128) * 128) + (L - 128)
- */
-
- /* make encoding data */
- ct_sequence = charset->ct_sequence;
- side = charset->side;
- seq_len = strlen(ct_sequence);
- if (standard_flag) {
- name_len = 0;
- total_len = seq_len;
- } else {
- name_len = strlen(charset->encoding_name) + 1;
- total_len = seq_len + name_len + 2;
- }
-
- /* output escape sequence of CT */
- if ( (charset != old_charset) &&
- !(first_flag && charset->string_encoding) ){
-
- if ( (ext_seg_len != NULL) && outbufptr) {
- int i = (outbufptr - ext_seg_len) - 2;
- *ext_seg_len++ = i / 128 + 128;
- *ext_seg_len = i % 128 + 128;
- ext_seg_len = NULL;
- }
-
- if (*to_left < total_len + 1) {
- unconv_num++;
- break;
- }
-
- if (outbufptr) {
- strcpy((char *)outbufptr, ct_sequence);
- outbufptr += seq_len;
-
- if (!standard_flag) {
- const char *i = charset->encoding_name;
- ext_seg_len = outbufptr;
- outbufptr += 2;
- for (; *i ; i++)
- *outbufptr++ = ((*i >= 'A') && (*i <= 'Z')) ?
- *i - 'A' + 'a' : *i;
- *outbufptr++ = STX;
- }
- }
-
- (*to_left) -= total_len;
-
- first_flag = False;
- old_charset = charset;
- }
-
- /* output glyph index */
- if (codeset->ctconv)
- glyph_index = conv_to_dest(codeset->ctconv, glyph_index);
- if (*to_left < charset->char_size) {
- unconv_num++;
- break;
- }
-
- if (outbufptr) {
- output_ulong_value(outbufptr, glyph_index, charset->char_size, side);
- outbufptr += charset->char_size;
- }
-
- (*to_left) -= charset->char_size;
-
- } /* end of while */
-
- if ( (ext_seg_len != NULL) && outbufptr) {
- int i = (outbufptr - ext_seg_len) - 2;
- *ext_seg_len++ = i / 128 + 128;
- *ext_seg_len = i % 128 + 128;
- }
-
- *from = (XPointer) ((const wchar_t *) *from + from_size);
- *from_left = 0;
- *to = (XPointer) outbufptr;
-
- return unconv_num;
-}
-
-static int
-stdc_wcstocts(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX);
- char *buf_ptr1 = buf;
- int buf_left1 = (*from_left) * MB_CUR_MAX;
- char *buf_ptr2 = buf_ptr1;
- int buf_left2;
- int unconv_num1 = 0, unconv_num2 = 0;
-
- unconv_num1 = stdc_wcstombs(conv,
- from, from_left, &buf_ptr1, &buf_left1, args, num_args);
- if (unconv_num1 < 0)
- goto ret;
-
- buf_left2 = buf_ptr1 - buf_ptr2;
-
- unconv_num2 = mbstocts(conv,
- &buf_ptr2, &buf_left2, to, to_left, args, num_args);
- if (unconv_num2 < 0)
- goto ret;
-
-ret:
- if (buf)
- Xfree((char *)buf);
-
- return (unconv_num1 + unconv_num2);
-}
-
-static int
-ctstowcs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
-
- unsigned char ch;
- unsigned long glyph_index = 0;
- wchar_t wc;
-
- int ctr_seq_len = 0, gi_len_left = 0, gi_len = 0;
- int unconv_num = 0;
-
- CodeSet codeset = NULL;
- XlcCharSet charset_tmp;
-
- const char *inbufptr = *from;
- wchar_t *outbufptr = (wchar_t *) *to;
- int from_size = *from_left;
-
- _XlcResetConverter(conv); /* ??? */
-
- if (from == NULL || *from == NULL) {
- _XlcResetConverter(conv);
- return( 0 );
- }
-
- if (*from_left > *to_left)
- *from_left = *to_left;
-
- while (*from_left && *to_left) {
-
- ch = *inbufptr++;
- (*from_left)--;
-
- /* null ? */
- if (!ch) {
- if (outbufptr) {*outbufptr++ = L'\0';}
- (*to_left)--;
-
- /* error check */
- if (gi_len_left) {
- unconv_num += (gi_len - gi_len_left);
- gi_len_left = 0;
- }
-
- continue;
- }
-
- /* same glyph_index data */
- if (gi_len_left)
- goto output_one_wc;
-
- /* control sequence ? */
- if (ch == CSI) {
- if ( !ct_parse_csi(inbufptr - 1, &ctr_seq_len) )
- goto skip_the_seg;
-
- if (*from_left + 1 < ctr_seq_len) {
- inbufptr--;
- (*from_left)++;
- unconv_num += *from_left;
- break;
- }
-
- /* skip the control sequence */
- inbufptr += (ctr_seq_len - 1);
- *from_left -= (ctr_seq_len - 1);
-
- continue;
- }
-
- /* escape sequence ? */
- if (ch == ESC) {
- if ( !ct_parse_charset(lcd,
- inbufptr - 1, &state->charset, &ctr_seq_len) )
- goto skip_the_seg;
-
- if (state->charset->side == XlcC0 ||
- state->charset->side == XlcGL)
- {
- state->GL_charset = state->charset;
- }
- else if (state->charset->side == XlcC1 ||
- state->charset->side == XlcGR)
- {
- state->GR_charset = state->charset;
- }
- else if (state->charset->side == XlcGLGR)
- {
- state->GL_charset = state->charset;
- state->GR_charset = state->charset;
- }
-
- if (*from_left + 1 < ctr_seq_len) {
- inbufptr--;
- (*from_left)++;
- unconv_num += *from_left;
- break;
- }
-
- /* skip the escape sequence */
- inbufptr += (ctr_seq_len - 1);
- *from_left -= (ctr_seq_len - 1);
-
- continue;
- }
-
- /* check current state */
- if (isleftside(ch))
- state->charset = state->GL_charset;
- else
- state->charset = state->GR_charset;
-
- gi_len = gi_len_left = state->charset->char_size;
- glyph_index = 0;
-
-output_one_wc:
- if (state->charset->side == XlcC1 || state->charset->side == XlcGR)
- glyph_index = (glyph_index << 8) | (ch & GL);
- else
- glyph_index = (glyph_index << 8) | ch;
-
- gi_len_left--;
-
- /* last of one glyph_index data */
- if (!gi_len_left) {
-
- /* segment conversion */
- charset_tmp = state->charset;
- segment_conversion(lcd, &charset_tmp, &glyph_index);
-
- /* get codeset */
- if ( !_XlcGetCodeSetFromCharSet(lcd, charset_tmp,
- &codeset, &glyph_index) ) {
- unconv_num += gi_len;
- continue;
- }
-
- /* convert glyph index to wicd char */
- gi_to_wc(lcd, glyph_index, codeset, &wc);
- if (outbufptr) {*outbufptr++ = wc;}
- (*to_left)--;
- }
-
- continue;
-
-skip_the_seg:
- /* skip until next escape or control sequence */
- while ( *from_left ) {
- ch = *inbufptr++;
- (*from_left)--;
- unconv_num++;
-
- if (ch == ESC || ch == CSI) {
- inbufptr--;
- (*from_left)++;
- unconv_num--;
- break;
- }
- }
-
- if ( !(*from_left) )
- break;
-
- } /* end of while */
-
- /* error check on last char */
- if (gi_len_left) {
- inbufptr -= (gi_len - gi_len_left);
- (*from_left) += (gi_len - gi_len_left);
- unconv_num += (gi_len - gi_len_left);
- }
-
- *from = (XPointer) ((const char *) *from + from_size);
- *from_left = 0;
- *to = (XPointer) outbufptr;
-
- return unconv_num;
-}
-
-static int
-cstowcs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
-
- unsigned char ch;
- unsigned long glyph_index = 0;
- wchar_t wc;
- int gi_len_left = 0, gi_len = 0;
-
- int unconv_num = 0;
-
- CodeSet codeset = NULL;
- XlcCharSet charset, charset_tmp;
-
- const char *inbufptr = *from;
- wchar_t *outbufptr = (wchar_t *) *to;
- int from_size = *from_left;
-
- if (from == NULL || *from == NULL) {
- return( 0 );
- }
-
- charset = (XlcCharSet) args[0];
-
- while (*from_left && *to_left) {
-
- if (!gi_len_left) {
- gi_len_left = gi_len = charset->char_size;
- glyph_index = 0;
- }
-
- ch = *inbufptr++;
- (*from_left)--;
-
- /* null ? */
- if (!ch) {
- if (outbufptr) {*outbufptr++ = L'\0';}
- (*to_left)--;
-
- /* error check */
- if (gi_len_left) {
- unconv_num += (gi_len - gi_len_left);
- gi_len_left = 0;
- }
- continue;
- }
-
- if (charset->side == XlcC1 || charset->side == XlcGR)
- glyph_index = (glyph_index << 8) | (ch & GL);
- else
- glyph_index = (glyph_index << 8) | ch;
-
- gi_len_left--;
-
- /* last of one glyph_index data */
- if (!gi_len_left) {
-
- /* segment conversion */
- charset_tmp = charset;
- segment_conversion(lcd, &charset_tmp, &glyph_index);
-
- /* get codeset */
- if ( !_XlcGetCodeSetFromCharSet(lcd, charset_tmp,
- &codeset, &glyph_index) ) {
- unconv_num += gi_len;
- continue;
- }
-
- /* convert glyph index to wicd char */
- gi_to_wc(lcd, glyph_index, codeset, &wc);
- if (outbufptr) {*outbufptr++ = wc;}
- (*to_left)--;
- }
-
- } /* end of while */
-
- /* error check on last char */
- if (gi_len_left) {
- inbufptr -= (gi_len - gi_len_left);
- (*from_left) += (gi_len - gi_len_left);
- unconv_num += (gi_len - gi_len_left);
- }
-
- *from = (XPointer) ((const char *) *from + from_size);
- *from_left = 0;
- *to = (XPointer) outbufptr;
-
- return unconv_num;
-}
-
-static int
-stdc_ctstowcs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX);
- char *buf_ptr1 = buf;
- int buf_left1 = (*from_left) * MB_CUR_MAX;
- char *buf_ptr2 = buf_ptr1;
- int buf_left2;
- int unconv_num1 = 0, unconv_num2 = 0;
-
- unconv_num1 = ctstombs(conv,
- from, from_left, &buf_ptr1, &buf_left1, args, num_args);
- if (unconv_num1 < 0)
- goto ret;
-
- buf_left2 = buf_ptr1 - buf_ptr2;
-
- unconv_num2 = stdc_mbstowcs(conv,
- &buf_ptr2, &buf_left2, to, to_left, args, num_args);
- if (unconv_num2 < 0)
- goto ret;
-
-ret:
- if (buf)
- Xfree((char *)buf);
-
- return (unconv_num1 + unconv_num2);
-}
-
-static int
-stdc_cstowcs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX);
- char *buf_ptr1 = buf;
- int buf_left1 = (*from_left) * MB_CUR_MAX;
- char *buf_ptr2 = buf_ptr1;
- int buf_left2;
- int unconv_num1 = 0, unconv_num2 = 0;
-
- unconv_num1 = cstombs(conv,
- from, from_left, &buf_ptr1, &buf_left1, args, num_args);
- if (unconv_num1 < 0)
- goto ret;
-
- buf_left2 = buf_ptr1 - buf_ptr2;
-
- unconv_num2 = stdc_mbstowcs(conv,
- &buf_ptr2, &buf_left2, to, to_left, args, num_args);
- if (unconv_num2 < 0)
- goto ret;
-
-ret:
- if (buf)
- Xfree((char *)buf);
-
- return (unconv_num1 + unconv_num2);
-}
-
-static int
-mbstocts(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- XPointer buf = Xmalloc((*from_left) * sizeof(wchar_t));
- char *buf_ptr1 = buf;
- int buf_left1 = (*from_left);
- char *buf_ptr2 = buf_ptr1;
- int buf_left2;
- int unconv_num1 = 0, unconv_num2 = 0;
-
- unconv_num1 = mbstowcs_org(conv,
- from, from_left, &buf_ptr1, &buf_left1, args, num_args);
- if (unconv_num1 < 0)
- goto ret;
-
- buf_left2 = (buf_ptr1 - buf_ptr2) / sizeof(wchar_t);
-
- unconv_num2 += wcstocts(conv,
- &buf_ptr2, &buf_left2, to, to_left, args, num_args);
- if (unconv_num2 < 0)
- goto ret;
-
-ret:
- if (buf)
- Xfree((char *)buf);
-
- return (unconv_num1 + unconv_num2);
-}
-
-static int
-mbstostr(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
-
- unsigned char ch;
- unsigned long mb = 0;
-
- int length = 0, len_left = 0;
- int unconv_num = 0;
- int num;
-
- CodeSet codeset = NULL;
-
- const char *inbufptr = *from;
- char *outbufptr = *to;
- int from_size = *from_left;
-
- unsigned char *mb_parse_table = XLC_GENERIC(lcd, mb_parse_table);
-
- if (from == NULL || *from == NULL) {
- _XlcResetConverter(conv);
- return( 0 );
- }
-
- if (*from_left > *to_left)
- *from_left = *to_left;
-
- while (*from_left && *to_left) {
-
- ch = *inbufptr++;
- (*from_left)--;
-
- /* null ? */
- if (!ch) {
- if (outbufptr) {*outbufptr++ = '\0';}
- (*to_left)--;
-
- /* error check */
- if (len_left) {
- unconv_num += (length - len_left);
- len_left = 0;
- }
-
- continue;
- }
-
- /* same mb char data */
- if (len_left)
- goto output_one_mb;
-
- /* next mb char data for single shift ? */
- if (mb_parse_table && (num = mb_parse_table[ch]) ) {
- codeset = mb_parse_codeset(state, num, &inbufptr, from_left);
- if (codeset != NULL) {
- length = len_left = codeset->length;
- mb = 0;
- continue;
- }
- }
-
- /* next char data : byteM ? */
- if ((codeset = byteM_parse_codeset(lcd, (inbufptr - 1))))
- goto next_mb_char;
-
- /* next char data : GL or GR side ? */
- if ((codeset = GLGR_parse_codeset(ch)))
- goto next_mb_char;
-
- /* can't find codeset for the ch */
- unconv_num++;
- continue;
-
-next_mb_char:
- length = len_left = codeset->length;
- mb = 0;
-
-output_one_mb:
- mb = (mb << 8) | ch; /* 1 byte left shift */
- len_left--;
-
- /* last of one mb char data */
- if (!len_left) {
- if (check_string_encoding(codeset)) {
- if (outbufptr) {*outbufptr++ = mb & 0xff;}
- (*to_left)--;
- } else {
- unconv_num++;
- }
- }
-
- } /* end of while */
-
- /* error check on last char */
- if (len_left) {
- inbufptr -= (length - len_left);
- (*from_left) += (length - len_left);
- unconv_num += (length - len_left);
- }
-
- *from = (XPointer) ((const char *) *from + from_size);
- *from_left = 0;
- *to = (XPointer) outbufptr;
-
- return unconv_num;
-}
-
-static int
-mbtocs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
-
- unsigned char ch;
- unsigned long mb = 0;
- unsigned long glyph_index;
-
- int length = 0, len_left = 0, char_len;
- int unconv_num = 0;
- int num;
- XlcSide side;
-
- CodeSet codeset = NULL;
- XlcCharSet charset = NULL;
-
- const char *inbufptr = *from;
- char *outbufptr = *to;
- int from_size = *from_left;
-
- unsigned char *mb_parse_table = XLC_GENERIC(lcd, mb_parse_table);
-
- if (from == NULL || *from == NULL) {
- _XlcResetConverter(conv);
- return( 0 );
- }
-
- if (*from_left > *to_left)
- *from_left = *to_left;
-
- while (*from_left && *to_left) {
-
- ch = *inbufptr++;
- (*from_left)--;
-
- /* null ? */
- if (!ch) {
- unconv_num = 1;
- if (len_left)
- unconv_num += (length - len_left);
- break;
- }
-
- /* same mb char data */
- if (len_left)
- goto output;
-
- /* next mb char data for single shift ? */
- if (mb_parse_table && (num = mb_parse_table[ch]) ) {
- codeset = mb_parse_codeset(state, num, &inbufptr, from_left);
- if (codeset != NULL) {
- length = len_left = codeset->length;
- mb = 0;
- continue;
- }
- }
-
- /* next mb char data for byteM ? */
- if ((codeset = byteM_parse_codeset(lcd, (inbufptr - 1))))
- goto next_mb_char;
-
- /* next mb char data for GL or GR side ? */
- if ((codeset = GLGR_parse_codeset(ch)))
- goto next_mb_char;
-
- /* can't find codeset for the ch */
- unconv_num = 1;
- break;
-
-next_mb_char:
- length = len_left = codeset->length;
- mb = 0;
-
-output:
- mb = (mb << 8) | ch; /* 1 byte left shift */
- len_left--;
-
- /* last of one mb char data */
- if (!len_left) {
- glyph_index = mb_to_gi(mb, codeset);
- if (!(charset = gi_parse_charset(glyph_index, codeset))) {
- unconv_num = length;
- break;
- }
- char_len = charset->char_size;
- side = charset->side;
-
- /* output glyph index */
- if (codeset->ctconv)
- glyph_index = conv_to_dest(codeset->ctconv, glyph_index);
- if (*to_left < char_len) {
- unconv_num = length;
- break;
- }
-
- if (outbufptr) {
- output_ulong_value(outbufptr, glyph_index, char_len, side);
- outbufptr += char_len;
- }
-
- (*to_left) -= char_len;
-
- break;
- }
-
- } /* end of while */
-
- /* error end */
- if (unconv_num) {
- *from = (XPointer) ((const char *) *from + from_size);
- *from_left = 0;
- *to = (XPointer) outbufptr;
- return -1;
- }
-
- /* nomal end */
- *from = (XPointer) inbufptr;
- *to = (XPointer) outbufptr;
-
- if (num_args > 0)
- *((XlcCharSet *) args[0]) = charset;
-
- return 0;
-}
-
-static int
-mbstocs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- int ret;
- XlcCharSet charset_old, charset = NULL;
- XPointer tmp_args[1];
-
- const char *inbufptr;
- int in_left;
- char *outbufptr;
- int out_left;
- tmp_args[0] = (XPointer) &charset;
-
- ret = mbtocs(conv, from, from_left, to, to_left, tmp_args, 1);
- charset_old = charset;
-
- while ( ret == 0 && *from_left && *to_left) {
- inbufptr = *from;
- in_left = *from_left;
- outbufptr = *to;
- out_left = *to_left;
- ret = mbtocs(conv, from, from_left, to, to_left, tmp_args, 1);
- if (charset_old != charset) {
- *from = (XPointer) inbufptr;
- *from_left = in_left;
- *to = (XPointer) outbufptr;
- *to_left = out_left;
- break;
- }
- }
-
- if (num_args > 0)
- *((XlcCharSet *) args[0]) = charset_old;
-
- /* error end */
- if (ret != 0)
- return( -1 );
-
- return(0);
-}
-
-static int
-wcstostr(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
-
- char *encoding;
- unsigned long mb, glyph_index;
- wchar_t wc;
-
- int length;
- int unconv_num = 0;
-
- CodeSet codeset;
-
- const wchar_t *inbufptr = (const wchar_t *) *from;
- char *outbufptr = *to;
- int from_size = *from_left;
-
- const char *default_string = XLC_PUBLIC(lcd, default_string);
- int defstr_len = strlen(default_string);
-
-
- if (*from_left > *to_left)
- *from_left = *to_left;
-
- while (*from_left && *to_left) {
-
- wc = *inbufptr++;
- (*from_left)--;
-
- /* null ? */
- if (!wc) {
- if (outbufptr) {*outbufptr++ = '\0';}
- (*to_left)--;
-
- continue;
- }
-
- /* convert */
- if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) {
-
- /* output default_string of XDefaultString() */
- if (*to_left < defstr_len)
- break;
- if (outbufptr) {
- strncpy((char *)outbufptr, default_string, defstr_len);
- outbufptr += defstr_len;
- }
- (*to_left) -= defstr_len;
-
- unconv_num++;
-
- } else {
- mb = gi_to_mb(glyph_index, codeset);
-
- if (check_string_encoding(codeset)) {
- if (codeset->parse_info) {
- Bool need_shift = False;
- switch (codeset->parse_info->type) {
- case E_LSL :
- if (codeset != state->GL_codeset) {
- need_shift = True;
- state->GL_codeset = codeset;
- }
- break;
- case E_LSR :
- if (codeset != state->GR_codeset) {
- need_shift = True;
- state->GR_codeset = codeset;
- }
- break;
- /* case E_SS */
- default:
- need_shift = True;
- }
-
- /* output shift sequence */
- if (need_shift) {
- encoding = codeset->parse_info->encoding;
- length = strlen(encoding);
- if (*to_left < length)
- break;
-
- if (outbufptr) {
- strncpy((char *)outbufptr, encoding, length);
- outbufptr += length;
- }
- (*to_left) -= length;
- }
- }
-
- /* output characters */
- length = codeset->length;
- if (*to_left < length)
- break;
-
- if (outbufptr) {
- output_ulong_value(outbufptr, mb, length, XlcNONE);
- outbufptr += length;
- }
-
- (*to_left) -= length;
- } else {
- unconv_num++;
- }
- }
-
- } /* end of while */
-
- *from = (XPointer) ((const wchar_t *) *from + from_size);
- *from_left = 0;
- *to = (XPointer) outbufptr;
-
- return unconv_num;
-}
-
-static int
-stdc_wcstostr(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX);
- char *buf_ptr1 = buf;
- int buf_left1 = (*from_left) * MB_CUR_MAX;
- char *buf_ptr2 = buf_ptr1;
- int buf_left2;
- int unconv_num1 = 0, unconv_num2 = 0;
-
- unconv_num1 = stdc_wcstombs(conv,
- from, from_left, &buf_ptr1, &buf_left1, args, num_args);
- if (unconv_num1 < 0)
- goto ret;
-
- buf_left2 = buf_ptr1 - buf_ptr2;
-
- unconv_num2 = mbstostr(conv,
- &buf_ptr2, &buf_left2, to, to_left, args, num_args);
- if (unconv_num2 < 0)
- goto ret;
-
-ret:
- if (buf)
- Xfree((char *)buf);
-
- return (unconv_num1 + unconv_num2);
-}
-
-static int
-wctocs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
-
- wchar_t wc;
- unsigned long glyph_index;
-
- int char_len;
- int unconv_num = 0;
- XlcSide side;
-
- CodeSet codeset;
- XlcCharSet charset = NULL;
-
- const wchar_t *inbufptr = (const wchar_t *) *from;
- char *outbufptr = *to;
- int from_size = *from_left;
-
- if (*from_left > *to_left)
- *from_left = *to_left;
-
- if (*from_left && *to_left) {
-
- wc = *inbufptr++;
- (*from_left)--;
-
- /* null ? */
- if (!wc) {
- unconv_num = 1;
- goto end;
- }
-
- /* convert */
- if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) {
- unconv_num = 1;
- goto end;
- }
-
- if ( !(charset = gi_parse_charset(glyph_index, codeset)) ) {
- unconv_num = 1;
- goto end;
- }
- char_len = charset->char_size;
- side = charset->side;
-
- /* output glyph index */
- if (codeset->ctconv)
- glyph_index = conv_to_dest(codeset->ctconv, glyph_index);
- if (*to_left < char_len) {
- unconv_num++;
- goto end;
- }
-
- if (outbufptr) {
- output_ulong_value(outbufptr, glyph_index, char_len, side);
- outbufptr += char_len;
- }
-
- (*to_left) -= char_len;
-
- }
-
-end:
-
- /* error end */
- if (unconv_num) {
- *from = (XPointer) ((const wchar_t *) *from + from_size);
- *from_left = 0;
- *to = (XPointer) outbufptr;
- return -1;
- }
-
- /* nomal end */
- *from = (XPointer) inbufptr;
- *to = (XPointer) outbufptr;
-
- if (num_args > 0)
- *((XlcCharSet *) args[0]) = charset;
-
- return 0;
-}
-
-static int
-stdc_wctocs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- const wchar_t *src = *((const wchar_t **) from);
- wchar_t wch;
- XPointer tmp_from, save_from = *from;
- char tmp[32];
- int length, ret, src_left = *from_left;
- int from_size = *from_left;
-
- if (src_left > 0 && *to_left > 0) {
- if ((wch = *src)) {
- length = wctomb(tmp, wch);
- } else {
- goto end;
- }
-
- if (length < 0)
- goto end;
-
- tmp_from = (XPointer) tmp;
- ret = mbtocs(conv, &tmp_from, &length, to, to_left, args, num_args);
- if (ret < 0)
- goto end;
-
- src++;
- src_left--;
- }
-
-end:
- /* error end */
- if (save_from == (XPointer) src) {
- *from = (XPointer) ((const wchar_t *) *from + from_size);
- *from_left = 0;
- return -1;
- }
-
- /* nomal end */
- *from = (XPointer) src;
- *from_left = src_left;
-
- return 0;
-}
-
-static int
-wcstocs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- int ret;
- XlcCharSet charset_old, charset = NULL;
- XPointer tmp_args[1];
-
- const wchar_t *inbufptr;
- int in_left;
- XPointer outbufptr;
- int out_left;
- tmp_args[0] = (XPointer) &charset;
-
- ret = wctocs(conv, from, from_left, to, to_left, tmp_args, 1);
- charset_old = charset;
-
- while ( ret == 0 && *from_left && *to_left) {
- inbufptr = (const wchar_t *) *from;
- in_left = *from_left;
- outbufptr = *to;
- out_left = *to_left;
- ret = wctocs(conv, from, from_left, to, to_left, tmp_args, 1);
- if (charset_old != charset) {
- *from = (XPointer) inbufptr;
- *from_left = in_left;
- *to = (XPointer) outbufptr;
- *to_left = out_left;
- break;
- }
- }
-
- if (num_args > 0)
- *((XlcCharSet *) args[0]) = charset_old;
-
- /* error end */
- if (ret != 0)
- return( -1 );
-
- return(0);
-}
-
-#ifdef STDCVT
-
-static int
-stdc_wcstocs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- int ret;
- XlcCharSet charset_old, charset = NULL;
- XPointer tmp_args[1];
-
- const wchar_t *inbufptr;
- int in_left;
- XPointer outbufptr;
- int out_left;
- tmp_args[0] = (XPointer) &charset;
-
- ret = stdc_wctocs(conv, from, from_left, to, to_left, tmp_args, 1);
- charset_old = charset;
-
- while ( ret == 0 && *from_left && *to_left ) {
- inbufptr = (const wchar_t *) *from;
- in_left = *from_left;
- outbufptr = *to;
- out_left = *to_left;
- ret = stdc_wctocs(conv, from, from_left, to, to_left, tmp_args, 1);
- if (charset_old != charset) {
- *from = (XPointer) inbufptr;
- *from_left = in_left;
- *to = (XPointer) outbufptr;
- *to_left = out_left;
- break;
- }
- }
-
- if (num_args > 0)
- *((XlcCharSet *) args[0]) = charset_old;
-
- /* error end */
- if (ret != 0)
- return( -1 );
-
- return(0);
-}
-
-#endif
-
-static int
-ctstombs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- XPointer buf = Xmalloc((*from_left) * sizeof(wchar_t));
- char *buf_ptr1 = buf;
- int buf_left1 = (*from_left);
- char *buf_ptr2 = buf_ptr1;
- int buf_left2;
- int unconv_num1 = 0, unconv_num2 = 0;
-
- unconv_num1 = ctstowcs(conv,
- from, from_left, &buf_ptr1, &buf_left1, args, num_args);
- if (unconv_num1 < 0)
- goto ret;
-
- buf_left2 = (buf_ptr1 - buf_ptr2) / sizeof(wchar_t);
-
- unconv_num2 += wcstombs_org(conv,
- &buf_ptr2, &buf_left2, to, to_left, args, num_args);
- if (unconv_num2 < 0)
- goto ret;
-
-ret:
- if (buf)
- Xfree((char *)buf);
-
- return (unconv_num1 + unconv_num2);
-}
-
-static int
-cstombs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- XPointer buf = Xmalloc((*from_left) * sizeof(wchar_t));
- char *buf_ptr1 = buf;
- int buf_left1 = (*from_left);
- char *buf_ptr2 = buf_ptr1;
- int buf_left2;
- int unconv_num1 = 0, unconv_num2 = 0;
-
- unconv_num1 = cstowcs(conv,
- from, from_left, &buf_ptr1, &buf_left1, args, num_args);
- if (unconv_num1 < 0)
- goto ret;
-
- buf_left2 = (buf_ptr1 - buf_ptr2) / sizeof(wchar_t);
-
- unconv_num2 += wcstombs_org(conv,
- &buf_ptr2, &buf_left2, to, to_left, args, num_args);
- if (unconv_num2 < 0)
- goto ret;
-
-ret:
- if (buf)
- Xfree((char *)buf);
-
- return (unconv_num1 + unconv_num2);
-}
-
-static int
-strtombs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
-
- char *encoding;
- unsigned long mb, glyph_index;
- unsigned char ch;
-
- int length;
- int unconv_num = 0;
-
- CodeSet codeset;
-
- const char *inbufptr = *from;
- char *outbufptr = *to;
- int from_size = *from_left;
-
- if (*from_left > *to_left)
- *from_left = *to_left;
-
- while (*from_left && *to_left) {
-
- ch = *inbufptr++;
- (*from_left)--;
-
- /* null ? */
- if (!ch) {
- if (outbufptr) {*outbufptr++ = '\0';}
- (*to_left)--;
-
- continue;
- }
-
- /* convert */
- if (isleftside(ch)) {
- glyph_index = ch;
- codeset = _XlcGetCodeSetFromName(lcd, "ISO8859-1:GL");
- } else {
- glyph_index = ch & GL;
- codeset = _XlcGetCodeSetFromName(lcd, "ISO8859-1:GR");
- }
-
- if (!codeset) {
- unconv_num++;
- continue;
- }
-
- mb = gi_to_mb(glyph_index, codeset);
- if (codeset->parse_info) {
- Bool need_shift = False;
- switch (codeset->parse_info->type) {
- case E_LSL :
- if (codeset != state->GL_codeset) {
- need_shift = True;
- state->GL_codeset = codeset;
- }
- break;
- case E_LSR :
- if (codeset != state->GR_codeset) {
- need_shift = True;
- state->GR_codeset = codeset;
- }
- break;
- /* case E_SS */
- default:
- need_shift = True;
- }
-
- /* output shift sequence */
- if (need_shift) {
- encoding = codeset->parse_info->encoding;
- length = strlen(encoding);
- if (*to_left < length)
- break;
- if (outbufptr) {
- strncpy((char *)outbufptr, encoding, length);
- outbufptr += length;
- }
- (*to_left) -= length;
- }
- }
-
- /* output characters */
- length = codeset->length;
- if (*to_left < length)
- break;
-
- if (outbufptr) {
- output_ulong_value(outbufptr, mb, length, XlcNONE);
- outbufptr += length;
- }
-
- (*to_left) -= length;
-
- } /* end of while */
-
- *from = (XPointer) ((const char *) *from + from_size);
- *from_left = 0;
- *to = (XPointer) outbufptr;
-
- return unconv_num;
-}
-
-static int
-strtowcs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
-
- unsigned char ch;
- unsigned long glyph_index;
- wchar_t wc;
-
- int unconv_num = 0;
- CodeSet codeset;
-
- const char *inbufptr = *from;
- wchar_t *outbufptr = (wchar_t *)*to;
- int from_size = *from_left;
-
- if (*from_left > *to_left)
- *from_left = *to_left;
-
- while (*from_left && *to_left) {
-
- ch = *inbufptr++;
- (*from_left)--;
-
- /* null ? */
- if (!ch) {
- if (outbufptr) {*outbufptr++ = L'\0';}
- (*to_left)--;
-
- continue;
- }
-
- /* convert */
- if (isleftside(ch)) {
- glyph_index = ch;
- codeset = _XlcGetCodeSetFromName(lcd, "ISO8859-1:GL");
- } else {
- glyph_index = ch & GL;
- codeset = _XlcGetCodeSetFromName(lcd, "ISO8859-1:GR");
- }
-
- if (!codeset) {
- unconv_num++;
- continue;
- }
-
- gi_to_wc(lcd, glyph_index, codeset, &wc);
- if (outbufptr) {*outbufptr++ = wc;}
- (*to_left)--;
-
- } /* end of while */
-
- *from = (XPointer) ((const char *) *from + from_size);
- *from_left = 0;
- *to = (XPointer) outbufptr;
-
- return unconv_num;
-}
-
-static int
-stdc_strtowcs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX);
- char *buf_ptr1 = buf;
- int buf_left1 = (*from_left) * MB_CUR_MAX;
- char *buf_ptr2 = buf_ptr1;
- int buf_left2;
- int unconv_num1 = 0, unconv_num2 = 0;
-
- unconv_num1 = strtombs(conv,
- from, from_left, &buf_ptr1, &buf_left1, args, num_args);
- if (unconv_num1 < 0)
- goto ret;
-
- buf_left2 = buf_ptr1 - buf_ptr2;
-
- unconv_num2 = stdc_mbstowcs(conv,
- &buf_ptr2, &buf_left2, to, to_left, args, num_args);
- if (unconv_num2 < 0)
- goto ret;
-
-ret:
- if (buf)
- Xfree((char *)buf);
-
- return (unconv_num1 + unconv_num2);
-}
-
-/* -------------------------------------------------------------------------- */
-/* Close */
-/* -------------------------------------------------------------------------- */
-
-static void
-close_converter(
- XlcConv conv)
-{
- if (conv->state) {
- Xfree((char *) conv->state);
- }
-
- if (conv->methods) {
- Xfree((char *) conv->methods);
- }
-
- Xfree((char *) conv);
-}
-
-/* -------------------------------------------------------------------------- */
-/* Open */
-/* -------------------------------------------------------------------------- */
-
-static XlcConv
-create_conv(
- XLCd lcd,
- XlcConvMethods methods)
-{
- XlcConv conv;
- State state;
-
- conv = (XlcConv) Xcalloc(1, sizeof(XlcConvRec));
- if (conv == NULL)
- return (XlcConv) NULL;
-
- conv->methods = (XlcConvMethods) Xmalloc(sizeof(XlcConvMethodsRec));
- if (conv->methods == NULL)
- goto err;
- *conv->methods = *methods;
- conv->methods->reset = init_state;
-
- conv->state = (XPointer) Xmalloc(sizeof(StateRec));
- if (conv->state == NULL)
- goto err;
- bzero((char *) conv->state, sizeof(StateRec));
-
- state = (State) conv->state;
- state->lcd = lcd;
-
- _XlcResetConverter(conv);
-
- return conv;
-
-err:
- close_converter(conv);
-
- return (XlcConv) NULL;
-}
-
-static XlcConvMethodsRec mbstocts_methods = {
- close_converter,
- mbstocts,
- NULL
-};
-
-static XlcConv
-open_mbstocts(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &mbstocts_methods);
-}
-
-static XlcConvMethodsRec mbstostr_methods = {
- close_converter,
- mbstostr,
- NULL
-};
-
-static XlcConv
-open_mbstostr(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &mbstostr_methods);
-}
-
-static XlcConvMethodsRec mbstocs_methods = {
- close_converter,
- mbstocs,
- NULL
-};
-
-static XlcConv
-open_mbstocs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &mbstocs_methods);
-}
-
-static XlcConvMethodsRec mbtocs_methods = {
- close_converter,
- mbtocs,
- NULL
-};
-
-static XlcConv
-open_mbtocs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &mbtocs_methods);
-}
-
-static XlcConvMethodsRec ctstombs_methods = {
- close_converter,
- ctstombs,
- NULL
-};
-
-static XlcConv
-open_ctstombs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &ctstombs_methods);
-}
-
-static XlcConvMethodsRec cstombs_methods = {
- close_converter,
- cstombs,
- NULL
-};
-
-static XlcConv
-open_cstombs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &cstombs_methods);
-}
-
-static XlcConvMethodsRec strtombs_methods = {
- close_converter,
- strtombs,
- NULL
-};
-
-static XlcConv
-open_strtombs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &strtombs_methods);
-}
-
-#ifdef STDCVT
-
-static XlcConvMethodsRec stdc_mbstowcs_methods = {
- close_converter,
- stdc_mbstowcs,
- NULL
-};
-
-static XlcConv
-open_stdc_mbstowcs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_mbstowcs_methods);
-}
-
-static XlcConvMethodsRec stdc_wcstombs_methods = {
- close_converter,
- stdc_wcstombs,
- NULL
-};
-
-static XlcConv
-open_stdc_wcstombs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_wcstombs_methods);
-}
-
-static XlcConvMethodsRec stdc_wcstocts_methods = {
- close_converter,
- stdc_wcstocts,
- NULL
-};
-
-static XlcConv
-open_stdc_wcstocts(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_wcstocts_methods);
-}
-
-static XlcConvMethodsRec stdc_wcstostr_methods = {
- close_converter,
- stdc_wcstostr,
- NULL
-};
-
-static XlcConv
-open_stdc_wcstostr(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_wcstostr_methods);
-}
-
-static XlcConvMethodsRec stdc_wcstocs_methods = {
- close_converter,
- stdc_wcstocs,
- NULL
-};
-
-static XlcConv
-open_stdc_wcstocs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_wcstocs_methods);
-}
-
-static XlcConvMethodsRec stdc_wctocs_methods = {
- close_converter,
- stdc_wctocs,
- NULL
-};
-
-static XlcConv
-open_stdc_wctocs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_wctocs_methods);
-}
-
-static XlcConvMethodsRec stdc_ctstowcs_methods = {
- close_converter,
- stdc_ctstowcs,
- NULL
-};
-
-static XlcConv
-open_stdc_ctstowcs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_ctstowcs_methods);
-}
-
-static XlcConvMethodsRec stdc_cstowcs_methods = {
- close_converter,
- stdc_cstowcs,
- NULL
-};
-
-static XlcConv
-open_stdc_cstowcs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_cstowcs_methods);
-}
-
-static XlcConvMethodsRec stdc_strtowcs_methods = {
- close_converter,
- stdc_strtowcs,
- NULL
-};
-
-static XlcConv
-open_stdc_strtowcs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_strtowcs_methods);
-}
-
-#endif /* STDCVT */
-
-static XlcConvMethodsRec mbstowcs_methods = {
- close_converter,
- mbstowcs_org,
- NULL
-};
-
-static XlcConv
-open_mbstowcs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &mbstowcs_methods);
-}
-
-static XlcConvMethodsRec wcstombs_methods = {
- close_converter,
- wcstombs_org,
- NULL
-};
-
-static XlcConv
-open_wcstombs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &wcstombs_methods);
-}
-
-static XlcConvMethodsRec wcstocts_methods = {
- close_converter,
- wcstocts,
- NULL
-};
-
-static XlcConv
-open_wcstocts(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &wcstocts_methods);
-}
-
-static XlcConvMethodsRec wcstostr_methods = {
- close_converter,
- wcstostr,
- NULL
-};
-
-static XlcConv
-open_wcstostr(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &wcstostr_methods);
-}
-
-static XlcConvMethodsRec wcstocs_methods = {
- close_converter,
- wcstocs,
- NULL
-};
-
-static XlcConv
-open_wcstocs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &wcstocs_methods);
-}
-
-static XlcConvMethodsRec wctocs_methods = {
- close_converter,
- wctocs,
- NULL
-};
-
-static XlcConv
-open_wctocs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &wctocs_methods);
-}
-
-static XlcConvMethodsRec ctstowcs_methods = {
- close_converter,
- ctstowcs,
- NULL
-};
-
-static XlcConv
-open_ctstowcs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &ctstowcs_methods);
-}
-
-static XlcConvMethodsRec cstowcs_methods = {
- close_converter,
- cstowcs,
- NULL
-};
-
-static XlcConv
-open_cstowcs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &cstowcs_methods);
-}
-
-static XlcConvMethodsRec strtowcs_methods = {
- close_converter,
- strtowcs,
- NULL
-};
-
-static XlcConv
-open_strtowcs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &strtowcs_methods);
-}
-
-/* -------------------------------------------------------------------------- */
-/* Loader */
-/* -------------------------------------------------------------------------- */
-
-XLCd
-_XlcGenericLoader(
- const char *name)
-{
- XLCd lcd;
-#ifdef STDCVT
- XLCdGenericPart *gen;
-#endif
-
- lcd = _XlcCreateLC(name, _XlcGenericMethods);
-
- if (lcd == NULL)
- return lcd;
-
- default_GL_charset = _XlcGetCharSet("ISO8859-1:GL");
- default_GR_charset = _XlcGetCharSet("ISO8859-1:GR");
-
- _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCompoundText, open_mbstocts);
- _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNString, open_mbstostr);
- _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCharSet, open_mbstocs);
- _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNChar, open_mbtocs);
- _XlcSetConverter(lcd, XlcNCompoundText, lcd, XlcNMultiByte, open_ctstombs);
- _XlcSetConverter(lcd, XlcNString, lcd, XlcNMultiByte, open_strtombs);
- _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte, open_cstombs);
-
-#ifdef STDCVT
- gen = XLC_GENERIC_PART(lcd);
-
- if (gen->use_stdc_env != True) {
-#endif
- _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar, open_mbstowcs);
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte, open_wcstombs);
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCompoundText, open_wcstocts);
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNString, open_wcstostr);
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet, open_wcstocs);
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNChar, open_wctocs);
- _XlcSetConverter(lcd, XlcNCompoundText, lcd, XlcNWideChar, open_ctstowcs);
- _XlcSetConverter(lcd, XlcNString, lcd, XlcNWideChar, open_strtowcs);
- _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar, open_cstowcs);
-#ifdef STDCVT
- }
-#endif
-
-#ifdef STDCVT
- if (gen->use_stdc_env == True) {
- _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar, open_stdc_mbstowcs);
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte, open_stdc_wcstombs);
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCompoundText, open_stdc_wcstocts);
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNString, open_stdc_wcstostr);
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet, open_stdc_wcstocs);
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNChar, open_stdc_wctocs);
- _XlcSetConverter(lcd, XlcNCompoundText, lcd, XlcNWideChar, open_stdc_ctstowcs);
- _XlcSetConverter(lcd, XlcNString, lcd, XlcNWideChar, open_stdc_strtowcs);
- _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar, open_stdc_cstowcs);
- }
-#endif
-
- _XlcAddUtf8Converters(lcd);
-
- return lcd;
-}
+/*
+ * Copyright 1992, 1993 by TOSHIBA Corp.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of TOSHIBA not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission. TOSHIBA make no representations about the
+ * suitability of this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+ * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Author: Katsuhisa Yano TOSHIBA Corp.
+ * mopi@osa.ilab.toshiba.co.jp
+ */
+/*
+ * (c) Copyright 1995 FUJITSU LIMITED
+ * This is source code modified by FUJITSU LIMITED under the Joint
+ * Development Agreement for the CDE/Motif PST.
+ *
+ * Modifier: Masayoshi Shimamura FUJITSU LIMITED
+ *
+ */
+/*
+ * 2000
+ * Modifier: Ivan Pascal The XFree86 Project
+ */
+
+/*
+ * A generic locale loader for all kinds of ISO-2022 based codesets.
+ * Supports: all locales.
+ * How: Provides generic converters for ISO-2022 based codesets. Extensible as
+ * far as ISO-2022 is extensible: codesets can be given by name in the
+ * stream. Overall distinction between GL (0x00..0x7f) and GR (0x80..0xff).
+ * In every chunk between escape sequences, the number of bytes per
+ * character (char_size) is constant.
+ * Platforms: all systems.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "XlcGeneric.h"
+#include <stdio.h>
+
+#if !defined(Lynx_22) && !defined(X_LOCALE)
+#define STDCVT
+#endif
+
+typedef struct _CTDataRec {
+ const char *name;
+ const char *encoding; /* Compound Text encoding */
+} CTDataRec, *CTData;
+
+static CTDataRec directionality_data[] =
+{
+ { "BEGIN_LEFT-TO-RIGHT_TEXT", "\2331]" },
+ { "BEGIN_RIGHT-TO-LEFT_TEXT", "\2332]" },
+ { "END_OF_STRING", "\233]" },
+};
+
+typedef struct _StateRec {
+ XLCd lcd;
+ /* CT state */
+ XlcCharSet charset; /* charset of current state */
+ XlcCharSet GL_charset; /* charset of initial state in GL */
+ XlcCharSet GR_charset; /* charset of initial state in GR */
+ /* MB shift state */
+ CodeSet GL_codeset;
+ CodeSet GR_codeset;
+} StateRec, *State;
+
+#define GR 0x80 /* begins right-side (non-ascii) region */
+#define GL 0x7f /* ends left-side (ascii) region */
+#define ESC 0x1b
+#define CSI 0x9b
+#define STX 0x02
+
+#define isrightside(c) ((c) & GR)
+#define isleftside(c) (!isrightside(c))
+
+/* Forward declarations for local routines. */
+static int mbstocts (XlcConv conv, XPointer *from, int *from_left,
+ XPointer *to, int *to_left, XPointer *args, int num_args);
+static int ctstombs (XlcConv conv, XPointer *from, int *from_left,
+ XPointer *to, int *to_left, XPointer *args, int num_args);
+static int cstombs (XlcConv conv, XPointer *from, int *from_left,
+ XPointer *to, int *to_left, XPointer *args, int num_args);
+
+/* ------------------------------------------------------------------------- */
+/* Misc */
+/* ------------------------------------------------------------------------- */
+
+static int
+compare(
+ const char *src,
+ const char *encoding,
+ int length)
+{
+ const char *start = src;
+
+ while (length-- > 0) {
+ if (*src++ != *encoding++)
+ return 0;
+ if (*encoding == '\0')
+ return src - start;
+ }
+
+ return 0;
+}
+
+static unsigned long
+conv_to_dest(
+ Conversion conv,
+ unsigned long code)
+{
+ int i;
+ int conv_num = conv->conv_num;
+ FontScope convlist = conv->convlist;
+
+ for (i = 0; i < conv_num; i++) {
+ if (convlist[i].start <= code && code <= convlist[i].end) {
+ switch (convlist[i].shift_direction) {
+ case '+':
+ return(code + convlist[i].shift);
+ case '-':
+ return(code - convlist[i].shift);
+ default:
+ return(code);
+ }
+ }
+ }
+
+ return(code);
+}
+
+static unsigned long
+conv_to_source(
+ Conversion conv,
+ unsigned long code)
+{
+ int i;
+ int conv_num;
+ FontScope convlist;
+ unsigned long start_p;
+ unsigned long start_m;
+ unsigned long end_p;
+ unsigned long end_m;
+
+ if (!conv)
+ return(code);
+
+ conv_num = conv->conv_num;
+ convlist = conv->convlist;
+
+ for (i = 0; i < conv_num; i++) {
+ switch (convlist[i].shift_direction) {
+ case '+':
+ start_p = convlist[i].start + convlist[i].shift;
+ end_p = convlist[i].end + convlist[i].shift;
+ if (start_p <= code && code <= end_p)
+ return(code - convlist[i].shift);
+ break;
+ case '-':
+ start_m = convlist[i].start - convlist[i].shift;
+ end_m = convlist[i].end - convlist[i].shift;
+ if (start_m <= code && code <= end_m)
+ return(code + convlist[i].shift);
+ break;
+ default:
+ continue;
+ }
+ }
+
+ return(code);
+}
+
+static unsigned long
+mb_to_gi(
+ unsigned long mb,
+ CodeSet codeset)
+{
+ int i;
+ unsigned long mb_tmp, mask = 0;
+
+ if (codeset->mbconv) {
+ mb_tmp = conv_to_dest(codeset->mbconv, mb);
+ if (mb_tmp != mb)
+ return(mb_tmp);
+ }
+
+ if (codeset->side == XlcC0 || codeset->side == XlcGL ||
+ codeset->side == XlcC1 || codeset->side == XlcGR) {
+
+ for (i = 0; i < codeset->length; i++)
+ mask = (mask << 8) | GL;
+ mb = mb & mask;
+ }
+
+ return(mb);
+}
+
+static unsigned long
+gi_to_mb(
+ unsigned long glyph_index,
+ CodeSet codeset)
+{
+ int i;
+ unsigned long mask = 0;
+
+ if (codeset->side == XlcC1 || codeset->side == XlcGR) {
+ for (i = 0; i < codeset->length; i++)
+ mask = (mask << 8) | GR;
+ glyph_index = glyph_index | mask;
+ }
+
+ if (codeset->mbconv)
+ return( conv_to_source(codeset->mbconv, glyph_index) );
+
+ return(glyph_index);
+}
+
+static Bool
+gi_to_wc(
+ XLCd lcd,
+ unsigned long glyph_index,
+ CodeSet codeset,
+ wchar_t *wc)
+{
+ unsigned char mask = 0;
+ unsigned long wc_encoding = codeset->wc_encoding;
+ int length = codeset->length;
+ unsigned long wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits);
+
+ mask = (1 << wc_shift_bits) - 1 ;
+
+ for (*wc = 0, length--; length >= 0; length--)
+ *wc = (*wc << wc_shift_bits) | ((glyph_index >> (length * 8 )) & mask);
+
+ *wc = *wc | wc_encoding;
+
+ return(True);
+}
+
+static Bool
+wc_to_gi(
+ XLCd lcd,
+ wchar_t wc,
+ unsigned long *glyph_index,
+ CodeSet *codeset)
+{
+ int i;
+ unsigned char mask = 0;
+ unsigned long wc_encoding;
+ unsigned long wc_encode_mask = XLC_GENERIC(lcd, wc_encode_mask);
+ unsigned long wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits);
+ int codeset_num = XLC_GENERIC(lcd, codeset_num);
+ CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
+
+ wc_encoding = wc & wc_encode_mask;
+ for (*codeset = NULL, i = 0; i < codeset_num; i++) {
+ if (wc_encoding == codeset_list[i]->wc_encoding) {
+ *codeset = codeset_list[i];
+ break;
+ }
+ }
+ if (*codeset == NULL)
+ return(False);
+
+ mask = (1 << wc_shift_bits) - 1 ;
+
+ wc = wc & ~wc_encode_mask;
+ for (*glyph_index = 0, i = (*codeset)->length - 1; i >= 0; i--)
+ *glyph_index = (*glyph_index << 8) |
+ ( ((unsigned long)wc >> (i * wc_shift_bits)) & mask );
+
+ return(True);
+}
+
+static CodeSet
+mb_parse_codeset(
+ State state,
+ int num,
+ const char **inbufptr,
+ int *from_left)
+{
+ int len;
+ int from_len = (*from_left) + 1;
+ const char *src = (*inbufptr) - 1;
+ ParseInfo *mb_parse_list = XLC_GENERIC(state->lcd, mb_parse_list);
+ ParseInfo parse_info;
+ CodeSet codeset;
+
+ for (--num ; (parse_info = mb_parse_list[num]) != NULL; num++) {
+ len = compare(src, parse_info->encoding, from_len);
+ if (len > 0) {
+ codeset = parse_info->codeset;
+ if (parse_info->type == E_LSL)
+ state->GL_codeset = codeset;
+ else if (parse_info->type == E_LSR)
+ state->GR_codeset = codeset;
+ --len;
+ *inbufptr += len;
+ *from_left -= len;
+ return codeset;
+ }
+ }
+ return (CodeSet) NULL;
+}
+
+static CodeSet
+byteM_parse_codeset(
+ XLCd lcd,
+ const char *inbufptr)
+{
+ unsigned char ch;
+ CodeSet codeset;
+ ByteInfoList byteM;
+ ByteInfoListRec byteM_rec;
+ ByteInfo byteinfo;
+ ByteInfoRec byteinfo_rec;
+ Bool hit = False;
+ int i, j, k;
+
+ int codeset_num = XLC_GENERIC(lcd, codeset_num);
+ CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
+
+ for (i = 0; i < codeset_num; i++) {
+ codeset = codeset_list[i];
+ byteM = codeset->byteM;
+ if (codeset->side != XlcNONE || byteM == NULL)
+ continue;
+
+ for (j = 0; j < codeset->length; j++) {
+ ch = *((unsigned char *)(inbufptr + j));
+ byteM_rec = byteM[j];
+ byteinfo = byteM_rec.byteinfo;
+
+ for (hit = False, k = 0; k < byteM_rec.byteinfo_num; k++) {
+ byteinfo_rec = byteinfo[k];
+ if (byteinfo_rec.start <= ch && ch <= byteinfo_rec.end) {
+ hit = True;
+ break;
+ }
+ }
+
+ if (!hit)
+ break;
+ }
+
+ if (hit)
+ return(codeset);
+ }
+
+ return(NULL);
+}
+
+#define GLGR_parse_codeset(ch) \
+ (isrightside(ch) ? (state->GR_codeset) : \
+ (state->GL_codeset) )
+
+static XlcCharSet
+gi_parse_charset(
+ unsigned long glyph_index,
+ CodeSet codeset)
+{
+ int i;
+ XlcCharSet *charset_list = codeset->charset_list;
+ int num_charsets = codeset->num_charsets;
+ ExtdSegment ctextseg = codeset->ctextseg;
+ XlcCharSet charset = NULL;
+ int area_num;
+ FontScope area;
+
+ /* lockup ct sequence */
+ for (i = 0; i < num_charsets; i++) {
+ charset = charset_list[i];
+ if (*charset->ct_sequence != '\0')
+ break;
+ }
+ if (i >= num_charsets)
+ return(NULL);
+
+ if (charset->source != CSsrcStd)
+ return (charset);
+
+ if (!ctextseg)
+ return(charset);
+
+ area = ctextseg->area;
+ area_num = ctextseg->area_num;
+
+ for (i = 0; i < area_num; i++) {
+
+ if (area[i].start <= glyph_index && glyph_index <= area[i].end) {
+
+ charset = ctextseg->charset;
+
+ if (*charset->ct_sequence == '\0')
+ return(NULL);
+
+ break;
+ }
+ }
+
+ return(charset);
+}
+
+static Bool
+ct_parse_csi(
+ const char *inbufptr,
+ int *ctr_seq_len)
+{
+ int i;
+ int num = sizeof(directionality_data) / sizeof(directionality_data[0]);
+
+ for (i = 0; i < num; i++) {
+ if ( !(*ctr_seq_len = strlen(directionality_data[i].encoding)) )
+ continue;
+
+ if ( strncmp(inbufptr, directionality_data[i].encoding,
+ *ctr_seq_len) == 0)
+ return(True);
+ }
+
+ return(False);
+}
+
+static int
+cmp_esc_sequence(
+ const char *inbufptr,
+ XlcCharSet charset)
+{
+ int seq_len, name_len, total_len;
+ unsigned char byte_m, byte_l;
+ const char *ct_sequence = charset->ct_sequence;
+ const char *encoding_name = charset->encoding_name;
+
+ /* check esc sequence */
+ if ( !(seq_len = strlen(ct_sequence) ) )
+ return(0);
+ if ( strncmp(inbufptr, ct_sequence, seq_len) != 0)
+ return(0);
+
+ /* Standard Character Set Encoding ? */
+ if (charset->source == CSsrcStd)
+ return(seq_len);
+
+ /*
+ * Non-Standard Character Set Encoding
+ *
+ * +--- ---+-----+-----+-----+---- ----+-----+-----+------- ------+
+ * | ctseq | M | L | encoding name | STX | contents |
+ * +--- ---+-----+-----+-----+---- ----+-----+-----+------- ------+
+ * 4bytes 1byte 1byte variable length 1byte variable length
+ * | |
+ * +----------------------------------------------+
+ * rest length = ((M - 128) * 128) + (L - 128)
+ */
+
+ /* get length of encoding name */
+ inbufptr += seq_len;
+ byte_m = *inbufptr++;
+ byte_l = *inbufptr++;
+ name_len = strlen(encoding_name);
+
+ if (((byte_m - 128) * 128 + (byte_l - 128) - 1) < name_len)
+ return(0);
+
+ if ( _XlcNCompareISOLatin1(inbufptr, encoding_name, name_len) != 0 )
+ return(0);
+
+ /* check STX (Start of Text) */
+ inbufptr = inbufptr + name_len;
+ if ( *inbufptr != STX )
+ return(0);
+
+ total_len = seq_len + name_len + 3;
+ return(total_len);
+}
+
+static Bool
+ct_parse_charset(
+ XLCd lcd,
+ const char *inbufptr,
+ XlcCharSet *charset,
+ int *ctr_seq_len)
+{
+ int i, j;
+ ExtdSegment ctextseg;
+ int num_charsets;
+ XlcCharSet *charset_list;
+ CodeSet codeset;
+ int codeset_num = XLC_GENERIC(lcd, codeset_num);
+ CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
+ int segment_conv_num = XLC_GENERIC(lcd, segment_conv_num);
+ SegConv segment_conv = XLC_GENERIC(lcd, segment_conv);
+
+ /* get charset from XLC_XLOCALE by escape sequence */
+
+ for (i = 0; i < codeset_num; i++) {
+ codeset = codeset_list[i];
+
+ num_charsets = codeset->num_charsets;
+ charset_list = codeset->charset_list;
+ ctextseg = codeset->ctextseg;
+
+ for (j = 0; j < num_charsets; j++) {
+ *charset = charset_list[j];
+ if ((*ctr_seq_len = cmp_esc_sequence(inbufptr, *charset)))
+ return(True);
+ }
+
+ if (ctextseg) {
+ *charset = ctextseg->charset;
+ if ((*ctr_seq_len = cmp_esc_sequence(inbufptr, *charset)))
+ return(True);
+ }
+ }
+
+ /* get charset from XLC_SEGMENTCONVERSION by escape sequence */
+
+ if (!segment_conv)
+ return(False);
+
+ for (i = 0; i < segment_conv_num; i++) {
+ *charset = segment_conv[i].source;
+ if ((*ctr_seq_len = cmp_esc_sequence(inbufptr, *charset)))
+ return(True);
+ *charset = segment_conv[i].dest;
+ if ((*ctr_seq_len = cmp_esc_sequence(inbufptr, *charset)))
+ return(True);
+ }
+
+ return(False);
+}
+
+static Bool
+segment_conversion(
+ XLCd lcd,
+ XlcCharSet *charset,
+ unsigned long *glyph_index)
+{
+ int i;
+ int segment_conv_num = XLC_GENERIC(lcd, segment_conv_num);
+ SegConv segment_conv = XLC_GENERIC(lcd, segment_conv);
+ FontScopeRec range;
+ ConversionRec conv_rec;
+
+ if (!segment_conv)
+ return(True);
+
+ for (i = 0; i < segment_conv_num; i++) {
+ if (segment_conv[i].source == *charset)
+ break;
+ }
+
+ if (i >= segment_conv_num)
+ return(True);
+
+ range = segment_conv[i].range;
+ if (*glyph_index < range.start || range.end < *glyph_index)
+ return(True);
+
+ *charset = segment_conv[i].dest;
+ conv_rec.conv_num = segment_conv[i].conv_num;
+ conv_rec.convlist = segment_conv[i].conv;
+ *glyph_index = conv_to_dest(&conv_rec, *glyph_index);
+
+ return(True);
+}
+
+static CodeSet
+_XlcGetCodeSetFromName(
+ XLCd lcd,
+ const char *name)
+{
+ int i, j;
+ XlcCharSet charset;
+ int num_charsets;
+ XlcCharSet *charset_list;
+ CodeSet codeset;
+
+ int codeset_num = XLC_GENERIC(lcd, codeset_num);
+ CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
+
+ for (i = 0; i < codeset_num; i++) {
+ codeset = codeset_list[i];
+
+ num_charsets = codeset->num_charsets;
+ charset_list = codeset->charset_list;
+
+ for (j = 0; j < num_charsets; j++) {
+ charset = charset_list[j];
+
+ if (!strlen(charset->name))
+ continue;
+ if ( strcmp(charset->name, name) == 0)
+ return(codeset);
+ }
+ }
+
+ return(NULL);
+}
+
+static Bool
+_XlcGetCodeSetFromCharSet(
+ XLCd lcd,
+ XlcCharSet charset,
+ CodeSet *codeset,
+ unsigned long *glyph_index)
+{
+ int j, num;
+ CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list);
+ XlcCharSet *charset_list;
+ int codeset_num, num_charsets;
+ Conversion ctconv;
+ unsigned long glyph_index_tmp = 0;
+ ExtdSegment ctextseg;
+
+ codeset_num = XLC_GENERIC(lcd, codeset_num);
+
+ for (num = 0 ; num < codeset_num; num++) {
+ *codeset = codeset_list[num];
+ ctconv = (*codeset)->ctconv;
+ ctextseg = (*codeset)->ctextseg;
+
+ num_charsets = (*codeset)->num_charsets;
+ charset_list = (*codeset)->charset_list;
+
+ glyph_index_tmp = conv_to_source(ctconv, *glyph_index);
+
+ if (charset->source == CSsrcStd) {
+
+ /* Standard Character Set Encoding */
+ if (glyph_index_tmp == *glyph_index) {
+ for (j = 0; j < num_charsets; j++) {
+ if (charset_list[j] == charset) {
+ goto end_loop;
+ }
+ }
+ }
+
+ } else {
+
+ /* Non-Standard Character Set Encoding */
+ for (j = 0; j < num_charsets; j++) {
+ if (charset_list[j] == charset) {
+ goto end_loop;
+ }
+ }
+
+ if (glyph_index_tmp != *glyph_index) {
+ if (ctextseg && ctextseg->charset == charset) {
+ goto end_loop;
+ }
+ }
+
+ }
+
+ }
+
+end_loop:
+ if (num < codeset_num) {
+ *glyph_index = glyph_index_tmp;
+ return(True);
+ }
+
+ return(False);
+}
+
+#define check_string_encoding(codeset) (codeset->string_encoding)
+
+static void
+output_ulong_value(
+ char *outbufptr,
+ unsigned long code,
+ int length,
+ XlcSide side)
+{
+ int i;
+
+ for (i = (length - 1) * 8; i >= 0; i -= 8) {
+ *outbufptr = ( code >> i) & 0xff;
+
+ if (side == XlcC0 || side == XlcGL) {
+ *outbufptr = *outbufptr & GL;
+ } else if (side == XlcC1 || side == XlcGR) {
+ *outbufptr = *outbufptr | GR;
+ }
+
+ outbufptr++;
+ }
+}
+
+/* -------------------------------------------------------------------------- */
+/* Init */
+/* -------------------------------------------------------------------------- */
+
+static XlcCharSet default_GL_charset = 0;
+static XlcCharSet default_GR_charset = 0;
+
+static void
+init_state(
+ XlcConv conv)
+{
+ State state = (State) conv->state;
+
+ /* for CT */
+ state->charset = NULL;
+ state->GL_charset = default_GL_charset;
+ state->GR_charset = default_GR_charset;
+
+ /* for MB shift state */
+ state->GL_codeset = XLC_GENERIC(state->lcd, initial_state_GL);
+ state->GR_codeset = XLC_GENERIC(state->lcd, initial_state_GR);
+}
+
+/* -------------------------------------------------------------------------- */
+/* Convert */
+/* -------------------------------------------------------------------------- */
+
+static int
+mbstowcs_org(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+
+ unsigned char ch;
+ unsigned long mb = 0;
+ wchar_t wc;
+
+ int length = 0, len_left = 0;
+ int unconv_num = 0;
+ int num;
+
+ CodeSet codeset = NULL;
+
+ const char *inbufptr = *from;
+ wchar_t *outbufptr = (wchar_t *) *to;
+ int from_size = *from_left;
+
+ unsigned char *mb_parse_table = XLC_GENERIC(lcd, mb_parse_table);
+
+ if (from == NULL || *from == NULL) {
+ _XlcResetConverter(conv);
+ return( 0 );
+ }
+
+ if (*from_left > *to_left)
+ *from_left = *to_left;
+
+ while (*from_left && *to_left) {
+
+ ch = *inbufptr++;
+ (*from_left)--;
+
+ /* null ? */
+ if (!ch) {
+ if (outbufptr) {*outbufptr++ = L'\0';}
+ (*to_left)--;
+
+ /* error check */
+ if (len_left) {
+ unconv_num += (length - len_left);
+ len_left = 0;
+ }
+
+ continue;
+ }
+
+ /* same mb char data */
+ if (len_left)
+ goto output_one_wc;
+
+ /* next mb char data for single shift ? */
+ if (mb_parse_table && (num = mb_parse_table[ch]) ) {
+ codeset = mb_parse_codeset(state, num, &inbufptr, from_left);
+ if (codeset != NULL) {
+ length = len_left = codeset->length;
+ mb = 0;
+ continue;
+ }
+ }
+
+ /* next mb char data for byteM ? */
+ if ((codeset = byteM_parse_codeset(lcd, (inbufptr - 1))))
+ goto next_mb_char;
+
+ /* next mb char data for GL or GR side ? */
+ if ((codeset = GLGR_parse_codeset(ch)))
+ goto next_mb_char;
+
+ /* can't find codeset for the ch */
+ unconv_num++;
+ continue;
+
+next_mb_char:
+ length = len_left = codeset->length;
+ mb = 0;
+
+output_one_wc:
+ mb = (mb << 8) | ch; /* 1 byte left shift */
+ len_left--;
+
+ /* last of one mb char data */
+ if (!len_left) {
+ gi_to_wc(lcd, mb_to_gi(mb, codeset), codeset, &wc);
+ if (outbufptr) {*outbufptr++ = wc;}
+ (*to_left)--;
+ }
+
+ } /* end of while */
+
+ /* error check on last char */
+ if (len_left) {
+ inbufptr -= (length - len_left);
+ (*from_left) += (length - len_left);
+ unconv_num += (length - len_left);
+ }
+
+ *from = (XPointer) ((const char *) *from + from_size);
+ *from_left = 0;
+ *to = (XPointer) outbufptr;
+
+ return unconv_num;
+}
+
+static int
+stdc_mbstowcs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ const char *src = *((const char **) from);
+ wchar_t *dst = *((wchar_t **) to);
+ int src_left = *from_left;
+ int dst_left = *to_left;
+ int length, unconv_num = 0;
+
+ while (src_left > 0 && dst_left > 0) {
+ length = mbtowc(dst, src, src_left);
+
+ if (length > 0) {
+ src += length;
+ src_left -= length;
+ if (dst)
+ dst++;
+ dst_left--;
+ } else if (length < 0) {
+ src++;
+ src_left--;
+ unconv_num++;
+ } else {
+ /* null ? */
+ src++;
+ src_left--;
+ if (dst)
+ *dst++ = L'\0';
+ dst_left--;
+ }
+ }
+
+ *from = (XPointer) src;
+ if (dst)
+ *to = (XPointer) dst;
+ *from_left = src_left;
+ *to_left = dst_left;
+
+ return unconv_num;
+}
+
+static int
+wcstombs_org(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+
+ char *encoding;
+ unsigned long mb, glyph_index;
+ wchar_t wc;
+
+ int length;
+ int unconv_num = 0;
+
+ CodeSet codeset;
+
+ const wchar_t *inbufptr = (const wchar_t *) *from;
+ char *outbufptr = *to;
+ int from_size = *from_left;
+
+ const char *default_string = XLC_PUBLIC(lcd, default_string);
+ int defstr_len = strlen(default_string);
+
+
+ if (*from_left > *to_left)
+ *from_left = *to_left;
+
+ while (*from_left && *to_left) {
+
+ wc = *inbufptr++;
+ (*from_left)--;
+
+ /* null ? */
+ if (!wc) {
+ if (outbufptr) {*outbufptr++ = '\0';}
+ (*to_left)--;
+
+ continue;
+ }
+
+ /* convert */
+ if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) {
+
+ /* output default_string of XDefaultString() */
+ if (*to_left < defstr_len)
+ break;
+ if (outbufptr) {
+ strncpy((char *)outbufptr, default_string, defstr_len);
+ outbufptr += defstr_len;
+ }
+ (*to_left) -= defstr_len;
+
+ unconv_num++;
+
+ } else {
+ mb = gi_to_mb(glyph_index, codeset);
+ if (codeset->parse_info) {
+ Bool need_shift = False;
+ switch (codeset->parse_info->type) {
+ case E_LSL :
+ if (codeset != state->GL_codeset) {
+ need_shift = True;
+ state->GL_codeset = codeset;
+ }
+ break;
+ case E_LSR :
+ if (codeset != state->GR_codeset) {
+ need_shift = True;
+ state->GR_codeset = codeset;
+ }
+ break;
+ /* case E_SS */
+ default:
+ need_shift = True;
+ }
+
+ /* output shift sequence */
+ if (need_shift) {
+ encoding = codeset->parse_info->encoding;
+ length = strlen(encoding);
+ if (*to_left < length)
+ break;
+ if (outbufptr) {
+ strncpy((char *)outbufptr, encoding, length);
+ outbufptr += length;
+ }
+ (*to_left) -= length;
+ }
+ }
+
+ /* output characters */
+ length = codeset->length;
+ if (*to_left < length)
+ break;
+
+ if (outbufptr) {
+ output_ulong_value(outbufptr, mb, length, XlcNONE);
+ outbufptr += length;
+ }
+
+ (*to_left) -= length;
+ }
+
+ } /* end of while */
+
+ *from = (XPointer) ((const wchar_t *) *from + from_size);
+ *from_left = 0;
+ *to = (XPointer) outbufptr;
+
+ return unconv_num;
+}
+
+static int
+stdc_wcstombs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ const wchar_t *src = *((const wchar_t **) from);
+ char *dst = *((char **) to);
+ int src_left = *from_left;
+ int dst_left = *to_left;
+ int length, unconv_num = 0;
+
+ while (src_left > 0 && dst_left >= MB_CUR_MAX) {
+ length = wctomb(dst, *src); /* XXX */
+
+ if (length > 0) {
+ src++;
+ src_left--;
+ if (dst)
+ dst += length;
+ dst_left -= length;
+ } else if (length < 0) {
+ src++;
+ src_left--;
+ unconv_num++;
+ }
+ }
+
+ *from = (XPointer) src;
+ if (dst)
+ *to = (XPointer) dst;
+ *from_left = src_left;
+ *to_left = dst_left;
+
+ return unconv_num;
+}
+
+static int
+wcstocts(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+
+ unsigned long glyph_index;
+ wchar_t wc;
+
+ int total_len, seq_len, name_len;
+ int unconv_num = 0;
+ Bool first_flag = True, standard_flag;
+ XlcSide side;
+
+ CodeSet codeset;
+ XlcCharSet charset, old_charset = NULL;
+ const char *ct_sequence;
+
+ const wchar_t *inbufptr = (const wchar_t *) *from;
+ char *outbufptr = *to;
+ int from_size = *from_left;
+ char *ext_seg_len = NULL;
+
+ if (*from_left > *to_left)
+ *from_left = *to_left;
+
+ while (*from_left && *to_left) {
+
+ wc = *inbufptr++;
+ (*from_left)--;
+
+ /* null ? */
+ if (!wc) {
+ if (outbufptr) {*outbufptr++ = '\0';}
+ (*to_left)--;
+
+ continue;
+ }
+
+ /* convert */
+ if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) {
+ unconv_num++;
+ continue;
+ }
+
+ /* parse charset */
+ if ( !(charset = gi_parse_charset(glyph_index, codeset)) ) {
+ unconv_num++;
+ continue;
+ }
+
+ /* Standard Character Set Encoding ? */
+ standard_flag = charset->source == CSsrcStd ? True : False;
+
+ /*
+ * Non-Standard Character Set Encoding
+ *
+ * +-----+-----+-----+-----+-----+-----+-----+---- ----+-----+-----+
+ * | esc sequence | M | L | encoding name | STX |
+ * +-----+-----+-----+-----+-----+-----+-----+---- ----+-----+-----+
+ * 4bytes 1byte 1byte variable length 1byte
+ * | |
+ * +-----------------------------------------+
+ * name length = ((M - 128) * 128) + (L - 128)
+ */
+
+ /* make encoding data */
+ ct_sequence = charset->ct_sequence;
+ side = charset->side;
+ seq_len = strlen(ct_sequence);
+ if (standard_flag) {
+ name_len = 0;
+ total_len = seq_len;
+ } else {
+ name_len = strlen(charset->encoding_name) + 1;
+ total_len = seq_len + name_len + 2;
+ }
+
+ /* output escape sequence of CT */
+ if ( (charset != old_charset) &&
+ !(first_flag && charset->string_encoding) ){
+
+ if ( (ext_seg_len != NULL) && outbufptr) {
+ int i = (outbufptr - ext_seg_len) - 2;
+ *ext_seg_len++ = i / 128 + 128;
+ *ext_seg_len = i % 128 + 128;
+ ext_seg_len = NULL;
+ }
+
+ if (*to_left < total_len + 1) {
+ unconv_num++;
+ break;
+ }
+
+ if (outbufptr) {
+ strcpy((char *)outbufptr, ct_sequence);
+ outbufptr += seq_len;
+
+ if (!standard_flag) {
+ const char *i = charset->encoding_name;
+ ext_seg_len = outbufptr;
+ outbufptr += 2;
+ for (; *i ; i++)
+ *outbufptr++ = ((*i >= 'A') && (*i <= 'Z')) ?
+ *i - 'A' + 'a' : *i;
+ *outbufptr++ = STX;
+ }
+ }
+
+ (*to_left) -= total_len;
+
+ first_flag = False;
+ old_charset = charset;
+ }
+
+ /* output glyph index */
+ if (codeset->ctconv)
+ glyph_index = conv_to_dest(codeset->ctconv, glyph_index);
+ if (*to_left < charset->char_size) {
+ unconv_num++;
+ break;
+ }
+
+ if (outbufptr) {
+ output_ulong_value(outbufptr, glyph_index, charset->char_size, side);
+ outbufptr += charset->char_size;
+ }
+
+ (*to_left) -= charset->char_size;
+
+ } /* end of while */
+
+ if ( (ext_seg_len != NULL) && outbufptr) {
+ int i = (outbufptr - ext_seg_len) - 2;
+ *ext_seg_len++ = i / 128 + 128;
+ *ext_seg_len = i % 128 + 128;
+ }
+
+ *from = (XPointer) ((const wchar_t *) *from + from_size);
+ *from_left = 0;
+ *to = (XPointer) outbufptr;
+
+ return unconv_num;
+}
+
+static int
+stdc_wcstocts(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX);
+ char *buf_ptr1 = buf;
+ int buf_left1 = (*from_left) * MB_CUR_MAX;
+ char *buf_ptr2 = buf_ptr1;
+ int buf_left2;
+ int unconv_num1 = 0, unconv_num2 = 0;
+
+ unconv_num1 = stdc_wcstombs(conv,
+ from, from_left, &buf_ptr1, &buf_left1, args, num_args);
+ if (unconv_num1 < 0)
+ goto ret;
+
+ buf_left2 = buf_ptr1 - buf_ptr2;
+
+ unconv_num2 = mbstocts(conv,
+ &buf_ptr2, &buf_left2, to, to_left, args, num_args);
+ if (unconv_num2 < 0)
+ goto ret;
+
+ret:
+ if (buf)
+ Xfree((char *)buf);
+
+ return (unconv_num1 + unconv_num2);
+}
+
+static int
+ctstowcs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+
+ unsigned char ch;
+ unsigned long glyph_index = 0;
+ wchar_t wc;
+
+ int ctr_seq_len = 0, gi_len_left = 0, gi_len = 0;
+ int unconv_num = 0;
+
+ CodeSet codeset = NULL;
+ XlcCharSet charset_tmp;
+
+ const char *inbufptr = *from;
+ wchar_t *outbufptr = (wchar_t *) *to;
+ int from_size = *from_left;
+
+ _XlcResetConverter(conv); /* ??? */
+
+ if (from == NULL || *from == NULL) {
+ _XlcResetConverter(conv);
+ return( 0 );
+ }
+
+ if (*from_left > *to_left)
+ *from_left = *to_left;
+
+ while (*from_left && *to_left) {
+
+ ch = *inbufptr++;
+ (*from_left)--;
+
+ /* null ? */
+ if (!ch) {
+ if (outbufptr) {*outbufptr++ = L'\0';}
+ (*to_left)--;
+
+ /* error check */
+ if (gi_len_left) {
+ unconv_num += (gi_len - gi_len_left);
+ gi_len_left = 0;
+ }
+
+ continue;
+ }
+
+ /* same glyph_index data */
+ if (gi_len_left)
+ goto output_one_wc;
+
+ /* control sequence ? */
+ if (ch == CSI) {
+ if ( !ct_parse_csi(inbufptr - 1, &ctr_seq_len) )
+ goto skip_the_seg;
+
+ if (*from_left + 1 < ctr_seq_len) {
+ inbufptr--;
+ (*from_left)++;
+ unconv_num += *from_left;
+ break;
+ }
+
+ /* skip the control sequence */
+ inbufptr += (ctr_seq_len - 1);
+ *from_left -= (ctr_seq_len - 1);
+
+ continue;
+ }
+
+ /* escape sequence ? */
+ if (ch == ESC) {
+ if ( !ct_parse_charset(lcd,
+ inbufptr - 1, &state->charset, &ctr_seq_len) )
+ goto skip_the_seg;
+
+ if (state->charset->side == XlcC0 ||
+ state->charset->side == XlcGL)
+ {
+ state->GL_charset = state->charset;
+ }
+ else if (state->charset->side == XlcC1 ||
+ state->charset->side == XlcGR)
+ {
+ state->GR_charset = state->charset;
+ }
+ else if (state->charset->side == XlcGLGR)
+ {
+ state->GL_charset = state->charset;
+ state->GR_charset = state->charset;
+ }
+
+ if (*from_left + 1 < ctr_seq_len) {
+ inbufptr--;
+ (*from_left)++;
+ unconv_num += *from_left;
+ break;
+ }
+
+ /* skip the escape sequence */
+ inbufptr += (ctr_seq_len - 1);
+ *from_left -= (ctr_seq_len - 1);
+
+ continue;
+ }
+
+ /* check current state */
+ if (isleftside(ch))
+ state->charset = state->GL_charset;
+ else
+ state->charset = state->GR_charset;
+
+ gi_len = gi_len_left = state->charset->char_size;
+ glyph_index = 0;
+
+output_one_wc:
+ if (state->charset->side == XlcC1 || state->charset->side == XlcGR)
+ glyph_index = (glyph_index << 8) | (ch & GL);
+ else
+ glyph_index = (glyph_index << 8) | ch;
+
+ gi_len_left--;
+
+ /* last of one glyph_index data */
+ if (!gi_len_left) {
+
+ /* segment conversion */
+ charset_tmp = state->charset;
+ segment_conversion(lcd, &charset_tmp, &glyph_index);
+
+ /* get codeset */
+ if ( !_XlcGetCodeSetFromCharSet(lcd, charset_tmp,
+ &codeset, &glyph_index) ) {
+ unconv_num += gi_len;
+ continue;
+ }
+
+ /* convert glyph index to wicd char */
+ gi_to_wc(lcd, glyph_index, codeset, &wc);
+ if (outbufptr) {*outbufptr++ = wc;}
+ (*to_left)--;
+ }
+
+ continue;
+
+skip_the_seg:
+ /* skip until next escape or control sequence */
+ while ( *from_left ) {
+ ch = *inbufptr++;
+ (*from_left)--;
+ unconv_num++;
+
+ if (ch == ESC || ch == CSI) {
+ inbufptr--;
+ (*from_left)++;
+ unconv_num--;
+ break;
+ }
+ }
+
+ if ( !(*from_left) )
+ break;
+
+ } /* end of while */
+
+ /* error check on last char */
+ if (gi_len_left) {
+ inbufptr -= (gi_len - gi_len_left);
+ (*from_left) += (gi_len - gi_len_left);
+ unconv_num += (gi_len - gi_len_left);
+ }
+
+ *from = (XPointer) ((const char *) *from + from_size);
+ *from_left = 0;
+ *to = (XPointer) outbufptr;
+
+ return unconv_num;
+}
+
+static int
+cstowcs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+
+ unsigned char ch;
+ unsigned long glyph_index = 0;
+ wchar_t wc;
+ int gi_len_left = 0, gi_len = 0;
+
+ int unconv_num = 0;
+
+ CodeSet codeset = NULL;
+ XlcCharSet charset, charset_tmp;
+
+ const char *inbufptr = *from;
+ wchar_t *outbufptr = (wchar_t *) *to;
+ int from_size = *from_left;
+
+ if (from == NULL || *from == NULL) {
+ return( 0 );
+ }
+
+ charset = (XlcCharSet) args[0];
+
+ while (*from_left && *to_left) {
+
+ if (!gi_len_left) {
+ gi_len_left = gi_len = charset->char_size;
+ glyph_index = 0;
+ }
+
+ ch = *inbufptr++;
+ (*from_left)--;
+
+ /* null ? */
+ if (!ch) {
+ if (outbufptr) {*outbufptr++ = L'\0';}
+ (*to_left)--;
+
+ /* error check */
+ if (gi_len_left) {
+ unconv_num += (gi_len - gi_len_left);
+ gi_len_left = 0;
+ }
+ continue;
+ }
+
+ if (charset->side == XlcC1 || charset->side == XlcGR)
+ glyph_index = (glyph_index << 8) | (ch & GL);
+ else
+ glyph_index = (glyph_index << 8) | ch;
+
+ gi_len_left--;
+
+ /* last of one glyph_index data */
+ if (!gi_len_left) {
+
+ /* segment conversion */
+ charset_tmp = charset;
+ segment_conversion(lcd, &charset_tmp, &glyph_index);
+
+ /* get codeset */
+ if ( !_XlcGetCodeSetFromCharSet(lcd, charset_tmp,
+ &codeset, &glyph_index) ) {
+ unconv_num += gi_len;
+ continue;
+ }
+
+ /* convert glyph index to wicd char */
+ gi_to_wc(lcd, glyph_index, codeset, &wc);
+ if (outbufptr) {*outbufptr++ = wc;}
+ (*to_left)--;
+ }
+
+ } /* end of while */
+
+ /* error check on last char */
+ if (gi_len_left) {
+ inbufptr -= (gi_len - gi_len_left);
+ (*from_left) += (gi_len - gi_len_left);
+ unconv_num += (gi_len - gi_len_left);
+ }
+
+ *from = (XPointer) ((const char *) *from + from_size);
+ *from_left = 0;
+ *to = (XPointer) outbufptr;
+
+ return unconv_num;
+}
+
+static int
+stdc_ctstowcs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX);
+ char *buf_ptr1 = buf;
+ int buf_left1 = (*from_left) * MB_CUR_MAX;
+ char *buf_ptr2 = buf_ptr1;
+ int buf_left2;
+ int unconv_num1 = 0, unconv_num2 = 0;
+
+ unconv_num1 = ctstombs(conv,
+ from, from_left, &buf_ptr1, &buf_left1, args, num_args);
+ if (unconv_num1 < 0)
+ goto ret;
+
+ buf_left2 = buf_ptr1 - buf_ptr2;
+
+ unconv_num2 = stdc_mbstowcs(conv,
+ &buf_ptr2, &buf_left2, to, to_left, args, num_args);
+ if (unconv_num2 < 0)
+ goto ret;
+
+ret:
+ if (buf)
+ Xfree((char *)buf);
+
+ return (unconv_num1 + unconv_num2);
+}
+
+static int
+stdc_cstowcs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX);
+ char *buf_ptr1 = buf;
+ int buf_left1 = (*from_left) * MB_CUR_MAX;
+ char *buf_ptr2 = buf_ptr1;
+ int buf_left2;
+ int unconv_num1 = 0, unconv_num2 = 0;
+
+ unconv_num1 = cstombs(conv,
+ from, from_left, &buf_ptr1, &buf_left1, args, num_args);
+ if (unconv_num1 < 0)
+ goto ret;
+
+ buf_left2 = buf_ptr1 - buf_ptr2;
+
+ unconv_num2 = stdc_mbstowcs(conv,
+ &buf_ptr2, &buf_left2, to, to_left, args, num_args);
+ if (unconv_num2 < 0)
+ goto ret;
+
+ret:
+ if (buf)
+ Xfree((char *)buf);
+
+ return (unconv_num1 + unconv_num2);
+}
+
+static int
+mbstocts(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ XPointer buf = Xmalloc((*from_left) * sizeof(wchar_t));
+ char *buf_ptr1 = buf;
+ int buf_left1 = (*from_left);
+ char *buf_ptr2 = buf_ptr1;
+ int buf_left2;
+ int unconv_num1 = 0, unconv_num2 = 0;
+
+ unconv_num1 = mbstowcs_org(conv,
+ from, from_left, &buf_ptr1, &buf_left1, args, num_args);
+ if (unconv_num1 < 0)
+ goto ret;
+
+ buf_left2 = (buf_ptr1 - buf_ptr2) / sizeof(wchar_t);
+
+ unconv_num2 += wcstocts(conv,
+ &buf_ptr2, &buf_left2, to, to_left, args, num_args);
+ if (unconv_num2 < 0)
+ goto ret;
+
+ret:
+ if (buf)
+ Xfree((char *)buf);
+
+ return (unconv_num1 + unconv_num2);
+}
+
+static int
+mbstostr(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+
+ unsigned char ch;
+ unsigned long mb = 0;
+
+ int length = 0, len_left = 0;
+ int unconv_num = 0;
+ int num;
+
+ CodeSet codeset = NULL;
+
+ const char *inbufptr = *from;
+ char *outbufptr = *to;
+ int from_size = *from_left;
+
+ unsigned char *mb_parse_table = XLC_GENERIC(lcd, mb_parse_table);
+
+ if (from == NULL || *from == NULL) {
+ _XlcResetConverter(conv);
+ return( 0 );
+ }
+
+ if (*from_left > *to_left)
+ *from_left = *to_left;
+
+ while (*from_left && *to_left) {
+
+ ch = *inbufptr++;
+ (*from_left)--;
+
+ /* null ? */
+ if (!ch) {
+ if (outbufptr) {*outbufptr++ = '\0';}
+ (*to_left)--;
+
+ /* error check */
+ if (len_left) {
+ unconv_num += (length - len_left);
+ len_left = 0;
+ }
+
+ continue;
+ }
+
+ /* same mb char data */
+ if (len_left)
+ goto output_one_mb;
+
+ /* next mb char data for single shift ? */
+ if (mb_parse_table && (num = mb_parse_table[ch]) ) {
+ codeset = mb_parse_codeset(state, num, &inbufptr, from_left);
+ if (codeset != NULL) {
+ length = len_left = codeset->length;
+ mb = 0;
+ continue;
+ }
+ }
+
+ /* next char data : byteM ? */
+ if ((codeset = byteM_parse_codeset(lcd, (inbufptr - 1))))
+ goto next_mb_char;
+
+ /* next char data : GL or GR side ? */
+ if ((codeset = GLGR_parse_codeset(ch)))
+ goto next_mb_char;
+
+ /* can't find codeset for the ch */
+ unconv_num++;
+ continue;
+
+next_mb_char:
+ length = len_left = codeset->length;
+ mb = 0;
+
+output_one_mb:
+ mb = (mb << 8) | ch; /* 1 byte left shift */
+ len_left--;
+
+ /* last of one mb char data */
+ if (!len_left) {
+ if (check_string_encoding(codeset)) {
+ if (outbufptr) {*outbufptr++ = mb & 0xff;}
+ (*to_left)--;
+ } else {
+ unconv_num++;
+ }
+ }
+
+ } /* end of while */
+
+ /* error check on last char */
+ if (len_left) {
+ inbufptr -= (length - len_left);
+ (*from_left) += (length - len_left);
+ unconv_num += (length - len_left);
+ }
+
+ *from = (XPointer) ((const char *) *from + from_size);
+ *from_left = 0;
+ *to = (XPointer) outbufptr;
+
+ return unconv_num;
+}
+
+static int
+mbtocs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+
+ unsigned char ch;
+ unsigned long mb = 0;
+ unsigned long glyph_index;
+
+ int length = 0, len_left = 0, char_len;
+ int unconv_num = 0;
+ int num;
+ XlcSide side;
+
+ CodeSet codeset = NULL;
+ XlcCharSet charset = NULL;
+
+ const char *inbufptr = *from;
+ char *outbufptr = *to;
+ int from_size = *from_left;
+
+ unsigned char *mb_parse_table = XLC_GENERIC(lcd, mb_parse_table);
+
+ if (from == NULL || *from == NULL) {
+ _XlcResetConverter(conv);
+ return( 0 );
+ }
+
+ if (*from_left > *to_left)
+ *from_left = *to_left;
+
+ while (*from_left && *to_left) {
+
+ ch = *inbufptr++;
+ (*from_left)--;
+
+ /* null ? */
+ if (!ch) {
+ unconv_num = 1;
+ if (len_left)
+ unconv_num += (length - len_left);
+ break;
+ }
+
+ /* same mb char data */
+ if (len_left)
+ goto output;
+
+ /* next mb char data for single shift ? */
+ if (mb_parse_table && (num = mb_parse_table[ch]) ) {
+ codeset = mb_parse_codeset(state, num, &inbufptr, from_left);
+ if (codeset != NULL) {
+ length = len_left = codeset->length;
+ mb = 0;
+ continue;
+ }
+ }
+
+ /* next mb char data for byteM ? */
+ if ((codeset = byteM_parse_codeset(lcd, (inbufptr - 1))))
+ goto next_mb_char;
+
+ /* next mb char data for GL or GR side ? */
+ if ((codeset = GLGR_parse_codeset(ch)))
+ goto next_mb_char;
+
+ /* can't find codeset for the ch */
+ unconv_num = 1;
+ break;
+
+next_mb_char:
+ length = len_left = codeset->length;
+ mb = 0;
+
+output:
+ mb = (mb << 8) | ch; /* 1 byte left shift */
+ len_left--;
+
+ /* last of one mb char data */
+ if (!len_left) {
+ glyph_index = mb_to_gi(mb, codeset);
+ if (!(charset = gi_parse_charset(glyph_index, codeset))) {
+ unconv_num = length;
+ break;
+ }
+ char_len = charset->char_size;
+ side = charset->side;
+
+ /* output glyph index */
+ if (codeset->ctconv)
+ glyph_index = conv_to_dest(codeset->ctconv, glyph_index);
+ if (*to_left < char_len) {
+ unconv_num = length;
+ break;
+ }
+
+ if (outbufptr) {
+ output_ulong_value(outbufptr, glyph_index, char_len, side);
+ outbufptr += char_len;
+ }
+
+ (*to_left) -= char_len;
+
+ break;
+ }
+
+ } /* end of while */
+
+ /* error end */
+ if (unconv_num) {
+ *from = (XPointer) ((const char *) *from + from_size);
+ *from_left = 0;
+ *to = (XPointer) outbufptr;
+ return -1;
+ }
+
+ /* nomal end */
+ *from = (XPointer) inbufptr;
+ *to = (XPointer) outbufptr;
+
+ if (num_args > 0)
+ *((XlcCharSet *) args[0]) = charset;
+
+ return 0;
+}
+
+static int
+mbstocs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ int ret;
+ XlcCharSet charset_old, charset = NULL;
+ XPointer tmp_args[1];
+
+ const char *inbufptr;
+ int in_left;
+ char *outbufptr;
+ int out_left;
+ tmp_args[0] = (XPointer) &charset;
+
+ ret = mbtocs(conv, from, from_left, to, to_left, tmp_args, 1);
+ charset_old = charset;
+
+ while ( ret == 0 && *from_left && *to_left) {
+ inbufptr = *from;
+ in_left = *from_left;
+ outbufptr = *to;
+ out_left = *to_left;
+ ret = mbtocs(conv, from, from_left, to, to_left, tmp_args, 1);
+ if (charset_old != charset) {
+ *from = (XPointer) inbufptr;
+ *from_left = in_left;
+ *to = (XPointer) outbufptr;
+ *to_left = out_left;
+ break;
+ }
+ }
+
+ if (num_args > 0)
+ *((XlcCharSet *) args[0]) = charset_old;
+
+ /* error end */
+ if (ret != 0)
+ return( -1 );
+
+ return(0);
+}
+
+static int
+wcstostr(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+
+ char *encoding;
+ unsigned long mb, glyph_index;
+ wchar_t wc;
+
+ int length;
+ int unconv_num = 0;
+
+ CodeSet codeset;
+
+ const wchar_t *inbufptr = (const wchar_t *) *from;
+ char *outbufptr = *to;
+ int from_size = *from_left;
+
+ const char *default_string = XLC_PUBLIC(lcd, default_string);
+ int defstr_len = strlen(default_string);
+
+
+ if (*from_left > *to_left)
+ *from_left = *to_left;
+
+ while (*from_left && *to_left) {
+
+ wc = *inbufptr++;
+ (*from_left)--;
+
+ /* null ? */
+ if (!wc) {
+ if (outbufptr) {*outbufptr++ = '\0';}
+ (*to_left)--;
+
+ continue;
+ }
+
+ /* convert */
+ if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) {
+
+ /* output default_string of XDefaultString() */
+ if (*to_left < defstr_len)
+ break;
+ if (outbufptr) {
+ strncpy((char *)outbufptr, default_string, defstr_len);
+ outbufptr += defstr_len;
+ }
+ (*to_left) -= defstr_len;
+
+ unconv_num++;
+
+ } else {
+ mb = gi_to_mb(glyph_index, codeset);
+
+ if (check_string_encoding(codeset)) {
+ if (codeset->parse_info) {
+ Bool need_shift = False;
+ switch (codeset->parse_info->type) {
+ case E_LSL :
+ if (codeset != state->GL_codeset) {
+ need_shift = True;
+ state->GL_codeset = codeset;
+ }
+ break;
+ case E_LSR :
+ if (codeset != state->GR_codeset) {
+ need_shift = True;
+ state->GR_codeset = codeset;
+ }
+ break;
+ /* case E_SS */
+ default:
+ need_shift = True;
+ }
+
+ /* output shift sequence */
+ if (need_shift) {
+ encoding = codeset->parse_info->encoding;
+ length = strlen(encoding);
+ if (*to_left < length)
+ break;
+
+ if (outbufptr) {
+ strncpy((char *)outbufptr, encoding, length);
+ outbufptr += length;
+ }
+ (*to_left) -= length;
+ }
+ }
+
+ /* output characters */
+ length = codeset->length;
+ if (*to_left < length)
+ break;
+
+ if (outbufptr) {
+ output_ulong_value(outbufptr, mb, length, XlcNONE);
+ outbufptr += length;
+ }
+
+ (*to_left) -= length;
+ } else {
+ unconv_num++;
+ }
+ }
+
+ } /* end of while */
+
+ *from = (XPointer) ((const wchar_t *) *from + from_size);
+ *from_left = 0;
+ *to = (XPointer) outbufptr;
+
+ return unconv_num;
+}
+
+static int
+stdc_wcstostr(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX);
+ char *buf_ptr1 = buf;
+ int buf_left1 = (*from_left) * MB_CUR_MAX;
+ char *buf_ptr2 = buf_ptr1;
+ int buf_left2;
+ int unconv_num1 = 0, unconv_num2 = 0;
+
+ unconv_num1 = stdc_wcstombs(conv,
+ from, from_left, &buf_ptr1, &buf_left1, args, num_args);
+ if (unconv_num1 < 0)
+ goto ret;
+
+ buf_left2 = buf_ptr1 - buf_ptr2;
+
+ unconv_num2 = mbstostr(conv,
+ &buf_ptr2, &buf_left2, to, to_left, args, num_args);
+ if (unconv_num2 < 0)
+ goto ret;
+
+ret:
+ if (buf)
+ Xfree((char *)buf);
+
+ return (unconv_num1 + unconv_num2);
+}
+
+static int
+wctocs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+
+ wchar_t wc;
+ unsigned long glyph_index;
+
+ int char_len;
+ int unconv_num = 0;
+ XlcSide side;
+
+ CodeSet codeset;
+ XlcCharSet charset = NULL;
+
+ const wchar_t *inbufptr = (const wchar_t *) *from;
+ char *outbufptr = *to;
+ int from_size = *from_left;
+
+ if (*from_left > *to_left)
+ *from_left = *to_left;
+
+ if (*from_left && *to_left) {
+
+ wc = *inbufptr++;
+ (*from_left)--;
+
+ /* null ? */
+ if (!wc) {
+ unconv_num = 1;
+ goto end;
+ }
+
+ /* convert */
+ if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) {
+ unconv_num = 1;
+ goto end;
+ }
+
+ if ( !(charset = gi_parse_charset(glyph_index, codeset)) ) {
+ unconv_num = 1;
+ goto end;
+ }
+ char_len = charset->char_size;
+ side = charset->side;
+
+ /* output glyph index */
+ if (codeset->ctconv)
+ glyph_index = conv_to_dest(codeset->ctconv, glyph_index);
+ if (*to_left < char_len) {
+ unconv_num++;
+ goto end;
+ }
+
+ if (outbufptr) {
+ output_ulong_value(outbufptr, glyph_index, char_len, side);
+ outbufptr += char_len;
+ }
+
+ (*to_left) -= char_len;
+
+ }
+
+end:
+
+ /* error end */
+ if (unconv_num) {
+ *from = (XPointer) ((const wchar_t *) *from + from_size);
+ *from_left = 0;
+ *to = (XPointer) outbufptr;
+ return -1;
+ }
+
+ /* nomal end */
+ *from = (XPointer) inbufptr;
+ *to = (XPointer) outbufptr;
+
+ if (num_args > 0)
+ *((XlcCharSet *) args[0]) = charset;
+
+ return 0;
+}
+
+static int
+stdc_wctocs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ const wchar_t *src = *((const wchar_t **) from);
+ wchar_t wch;
+ XPointer tmp_from, save_from = *from;
+ char tmp[32];
+ int length, ret, src_left = *from_left;
+ int from_size = *from_left;
+
+ if (src_left > 0 && *to_left > 0) {
+ if ((wch = *src)) {
+ length = wctomb(tmp, wch);
+ } else {
+ goto end;
+ }
+
+ if (length < 0)
+ goto end;
+
+ tmp_from = (XPointer) tmp;
+ ret = mbtocs(conv, &tmp_from, &length, to, to_left, args, num_args);
+ if (ret < 0)
+ goto end;
+
+ src++;
+ src_left--;
+ }
+
+end:
+ /* error end */
+ if (save_from == (XPointer) src) {
+ *from = (XPointer) ((const wchar_t *) *from + from_size);
+ *from_left = 0;
+ return -1;
+ }
+
+ /* nomal end */
+ *from = (XPointer) src;
+ *from_left = src_left;
+
+ return 0;
+}
+
+static int
+wcstocs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ int ret;
+ XlcCharSet charset_old, charset = NULL;
+ XPointer tmp_args[1];
+
+ const wchar_t *inbufptr;
+ int in_left;
+ XPointer outbufptr;
+ int out_left;
+ tmp_args[0] = (XPointer) &charset;
+
+ ret = wctocs(conv, from, from_left, to, to_left, tmp_args, 1);
+ charset_old = charset;
+
+ while ( ret == 0 && *from_left && *to_left) {
+ inbufptr = (const wchar_t *) *from;
+ in_left = *from_left;
+ outbufptr = *to;
+ out_left = *to_left;
+ ret = wctocs(conv, from, from_left, to, to_left, tmp_args, 1);
+ if (charset_old != charset) {
+ *from = (XPointer) inbufptr;
+ *from_left = in_left;
+ *to = (XPointer) outbufptr;
+ *to_left = out_left;
+ break;
+ }
+ }
+
+ if (num_args > 0)
+ *((XlcCharSet *) args[0]) = charset_old;
+
+ /* error end */
+ if (ret != 0)
+ return( -1 );
+
+ return(0);
+}
+
+#ifdef STDCVT
+
+static int
+stdc_wcstocs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ int ret;
+ XlcCharSet charset_old, charset = NULL;
+ XPointer tmp_args[1];
+
+ const wchar_t *inbufptr;
+ int in_left;
+ XPointer outbufptr;
+ int out_left;
+ tmp_args[0] = (XPointer) &charset;
+
+ ret = stdc_wctocs(conv, from, from_left, to, to_left, tmp_args, 1);
+ charset_old = charset;
+
+ while ( ret == 0 && *from_left && *to_left ) {
+ inbufptr = (const wchar_t *) *from;
+ in_left = *from_left;
+ outbufptr = *to;
+ out_left = *to_left;
+ ret = stdc_wctocs(conv, from, from_left, to, to_left, tmp_args, 1);
+ if (charset_old != charset) {
+ *from = (XPointer) inbufptr;
+ *from_left = in_left;
+ *to = (XPointer) outbufptr;
+ *to_left = out_left;
+ break;
+ }
+ }
+
+ if (num_args > 0)
+ *((XlcCharSet *) args[0]) = charset_old;
+
+ /* error end */
+ if (ret != 0)
+ return( -1 );
+
+ return(0);
+}
+
+#endif
+
+static int
+ctstombs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ XPointer buf = Xmalloc((*from_left) * sizeof(wchar_t));
+ char *buf_ptr1 = buf;
+ int buf_left1 = (*from_left);
+ char *buf_ptr2 = buf_ptr1;
+ int buf_left2;
+ int unconv_num1 = 0, unconv_num2 = 0;
+
+ unconv_num1 = ctstowcs(conv,
+ from, from_left, &buf_ptr1, &buf_left1, args, num_args);
+ if (unconv_num1 < 0)
+ goto ret;
+
+ buf_left2 = (buf_ptr1 - buf_ptr2) / sizeof(wchar_t);
+
+ unconv_num2 += wcstombs_org(conv,
+ &buf_ptr2, &buf_left2, to, to_left, args, num_args);
+ if (unconv_num2 < 0)
+ goto ret;
+
+ret:
+ if (buf)
+ Xfree((char *)buf);
+
+ return (unconv_num1 + unconv_num2);
+}
+
+static int
+cstombs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ XPointer buf = Xmalloc((*from_left) * sizeof(wchar_t));
+ char *buf_ptr1 = buf;
+ int buf_left1 = (*from_left);
+ char *buf_ptr2 = buf_ptr1;
+ int buf_left2;
+ int unconv_num1 = 0, unconv_num2 = 0;
+
+ unconv_num1 = cstowcs(conv,
+ from, from_left, &buf_ptr1, &buf_left1, args, num_args);
+ if (unconv_num1 < 0)
+ goto ret;
+
+ buf_left2 = (buf_ptr1 - buf_ptr2) / sizeof(wchar_t);
+
+ unconv_num2 += wcstombs_org(conv,
+ &buf_ptr2, &buf_left2, to, to_left, args, num_args);
+ if (unconv_num2 < 0)
+ goto ret;
+
+ret:
+ if (buf)
+ Xfree((char *)buf);
+
+ return (unconv_num1 + unconv_num2);
+}
+
+static int
+strtombs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+
+ char *encoding;
+ unsigned long mb, glyph_index;
+ unsigned char ch;
+
+ int length;
+ int unconv_num = 0;
+
+ CodeSet codeset;
+
+ const char *inbufptr = *from;
+ char *outbufptr = *to;
+ int from_size = *from_left;
+
+ if (*from_left > *to_left)
+ *from_left = *to_left;
+
+ while (*from_left && *to_left) {
+
+ ch = *inbufptr++;
+ (*from_left)--;
+
+ /* null ? */
+ if (!ch) {
+ if (outbufptr) {*outbufptr++ = '\0';}
+ (*to_left)--;
+
+ continue;
+ }
+
+ /* convert */
+ if (isleftside(ch)) {
+ glyph_index = ch;
+ codeset = _XlcGetCodeSetFromName(lcd, "ISO8859-1:GL");
+ } else {
+ glyph_index = ch & GL;
+ codeset = _XlcGetCodeSetFromName(lcd, "ISO8859-1:GR");
+ }
+
+ if (!codeset) {
+ unconv_num++;
+ continue;
+ }
+
+ mb = gi_to_mb(glyph_index, codeset);
+ if (codeset->parse_info) {
+ Bool need_shift = False;
+ switch (codeset->parse_info->type) {
+ case E_LSL :
+ if (codeset != state->GL_codeset) {
+ need_shift = True;
+ state->GL_codeset = codeset;
+ }
+ break;
+ case E_LSR :
+ if (codeset != state->GR_codeset) {
+ need_shift = True;
+ state->GR_codeset = codeset;
+ }
+ break;
+ /* case E_SS */
+ default:
+ need_shift = True;
+ }
+
+ /* output shift sequence */
+ if (need_shift) {
+ encoding = codeset->parse_info->encoding;
+ length = strlen(encoding);
+ if (*to_left < length)
+ break;
+ if (outbufptr) {
+ strncpy((char *)outbufptr, encoding, length);
+ outbufptr += length;
+ }
+ (*to_left) -= length;
+ }
+ }
+
+ /* output characters */
+ length = codeset->length;
+ if (*to_left < length)
+ break;
+
+ if (outbufptr) {
+ output_ulong_value(outbufptr, mb, length, XlcNONE);
+ outbufptr += length;
+ }
+
+ (*to_left) -= length;
+
+ } /* end of while */
+
+ *from = (XPointer) ((const char *) *from + from_size);
+ *from_left = 0;
+ *to = (XPointer) outbufptr;
+
+ return unconv_num;
+}
+
+static int
+strtowcs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+
+ unsigned char ch;
+ unsigned long glyph_index;
+ wchar_t wc;
+
+ int unconv_num = 0;
+ CodeSet codeset;
+
+ const char *inbufptr = *from;
+ wchar_t *outbufptr = (wchar_t *)*to;
+ int from_size = *from_left;
+
+ if (*from_left > *to_left)
+ *from_left = *to_left;
+
+ while (*from_left && *to_left) {
+
+ ch = *inbufptr++;
+ (*from_left)--;
+
+ /* null ? */
+ if (!ch) {
+ if (outbufptr) {*outbufptr++ = L'\0';}
+ (*to_left)--;
+
+ continue;
+ }
+
+ /* convert */
+ if (isleftside(ch)) {
+ glyph_index = ch;
+ codeset = _XlcGetCodeSetFromName(lcd, "ISO8859-1:GL");
+ } else {
+ glyph_index = ch & GL;
+ codeset = _XlcGetCodeSetFromName(lcd, "ISO8859-1:GR");
+ }
+
+ if (!codeset) {
+ unconv_num++;
+ continue;
+ }
+
+ gi_to_wc(lcd, glyph_index, codeset, &wc);
+ if (outbufptr) {*outbufptr++ = wc;}
+ (*to_left)--;
+
+ } /* end of while */
+
+ *from = (XPointer) ((const char *) *from + from_size);
+ *from_left = 0;
+ *to = (XPointer) outbufptr;
+
+ return unconv_num;
+}
+
+static int
+stdc_strtowcs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX);
+ char *buf_ptr1 = buf;
+ int buf_left1 = (*from_left) * MB_CUR_MAX;
+ char *buf_ptr2 = buf_ptr1;
+ int buf_left2;
+ int unconv_num1 = 0, unconv_num2 = 0;
+
+ unconv_num1 = strtombs(conv,
+ from, from_left, &buf_ptr1, &buf_left1, args, num_args);
+ if (unconv_num1 < 0)
+ goto ret;
+
+ buf_left2 = buf_ptr1 - buf_ptr2;
+
+ unconv_num2 = stdc_mbstowcs(conv,
+ &buf_ptr2, &buf_left2, to, to_left, args, num_args);
+ if (unconv_num2 < 0)
+ goto ret;
+
+ret:
+ if (buf)
+ Xfree((char *)buf);
+
+ return (unconv_num1 + unconv_num2);
+}
+
+/* -------------------------------------------------------------------------- */
+/* Close */
+/* -------------------------------------------------------------------------- */
+
+static void
+close_converter(
+ XlcConv conv)
+{
+ if (conv->state) {
+ Xfree((char *) conv->state);
+ }
+
+ if (conv->methods) {
+ Xfree((char *) conv->methods);
+ }
+
+ Xfree((char *) conv);
+}
+
+/* -------------------------------------------------------------------------- */
+/* Open */
+/* -------------------------------------------------------------------------- */
+
+static XlcConv
+create_conv(
+ XLCd lcd,
+ XlcConvMethods methods)
+{
+ XlcConv conv;
+ State state;
+
+ conv = (XlcConv) Xcalloc(1, sizeof(XlcConvRec));
+ if (conv == NULL)
+ return (XlcConv) NULL;
+
+ conv->methods = (XlcConvMethods) Xmalloc(sizeof(XlcConvMethodsRec));
+ if (conv->methods == NULL)
+ goto err;
+ *conv->methods = *methods;
+ conv->methods->reset = init_state;
+
+ conv->state = Xcalloc(1, sizeof(StateRec));
+ if (conv->state == NULL)
+ goto err;
+
+ state = (State) conv->state;
+ state->lcd = lcd;
+
+ _XlcResetConverter(conv);
+
+ return conv;
+
+err:
+ close_converter(conv);
+
+ return (XlcConv) NULL;
+}
+
+static XlcConvMethodsRec mbstocts_methods = {
+ close_converter,
+ mbstocts,
+ NULL
+};
+
+static XlcConv
+open_mbstocts(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &mbstocts_methods);
+}
+
+static XlcConvMethodsRec mbstostr_methods = {
+ close_converter,
+ mbstostr,
+ NULL
+};
+
+static XlcConv
+open_mbstostr(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &mbstostr_methods);
+}
+
+static XlcConvMethodsRec mbstocs_methods = {
+ close_converter,
+ mbstocs,
+ NULL
+};
+
+static XlcConv
+open_mbstocs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &mbstocs_methods);
+}
+
+static XlcConvMethodsRec mbtocs_methods = {
+ close_converter,
+ mbtocs,
+ NULL
+};
+
+static XlcConv
+open_mbtocs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &mbtocs_methods);
+}
+
+static XlcConvMethodsRec ctstombs_methods = {
+ close_converter,
+ ctstombs,
+ NULL
+};
+
+static XlcConv
+open_ctstombs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &ctstombs_methods);
+}
+
+static XlcConvMethodsRec cstombs_methods = {
+ close_converter,
+ cstombs,
+ NULL
+};
+
+static XlcConv
+open_cstombs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &cstombs_methods);
+}
+
+static XlcConvMethodsRec strtombs_methods = {
+ close_converter,
+ strtombs,
+ NULL
+};
+
+static XlcConv
+open_strtombs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &strtombs_methods);
+}
+
+#ifdef STDCVT
+
+static XlcConvMethodsRec stdc_mbstowcs_methods = {
+ close_converter,
+ stdc_mbstowcs,
+ NULL
+};
+
+static XlcConv
+open_stdc_mbstowcs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_mbstowcs_methods);
+}
+
+static XlcConvMethodsRec stdc_wcstombs_methods = {
+ close_converter,
+ stdc_wcstombs,
+ NULL
+};
+
+static XlcConv
+open_stdc_wcstombs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_wcstombs_methods);
+}
+
+static XlcConvMethodsRec stdc_wcstocts_methods = {
+ close_converter,
+ stdc_wcstocts,
+ NULL
+};
+
+static XlcConv
+open_stdc_wcstocts(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_wcstocts_methods);
+}
+
+static XlcConvMethodsRec stdc_wcstostr_methods = {
+ close_converter,
+ stdc_wcstostr,
+ NULL
+};
+
+static XlcConv
+open_stdc_wcstostr(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_wcstostr_methods);
+}
+
+static XlcConvMethodsRec stdc_wcstocs_methods = {
+ close_converter,
+ stdc_wcstocs,
+ NULL
+};
+
+static XlcConv
+open_stdc_wcstocs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_wcstocs_methods);
+}
+
+static XlcConvMethodsRec stdc_wctocs_methods = {
+ close_converter,
+ stdc_wctocs,
+ NULL
+};
+
+static XlcConv
+open_stdc_wctocs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_wctocs_methods);
+}
+
+static XlcConvMethodsRec stdc_ctstowcs_methods = {
+ close_converter,
+ stdc_ctstowcs,
+ NULL
+};
+
+static XlcConv
+open_stdc_ctstowcs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_ctstowcs_methods);
+}
+
+static XlcConvMethodsRec stdc_cstowcs_methods = {
+ close_converter,
+ stdc_cstowcs,
+ NULL
+};
+
+static XlcConv
+open_stdc_cstowcs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_cstowcs_methods);
+}
+
+static XlcConvMethodsRec stdc_strtowcs_methods = {
+ close_converter,
+ stdc_strtowcs,
+ NULL
+};
+
+static XlcConv
+open_stdc_strtowcs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_strtowcs_methods);
+}
+
+#endif /* STDCVT */
+
+static XlcConvMethodsRec mbstowcs_methods = {
+ close_converter,
+ mbstowcs_org,
+ NULL
+};
+
+static XlcConv
+open_mbstowcs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &mbstowcs_methods);
+}
+
+static XlcConvMethodsRec wcstombs_methods = {
+ close_converter,
+ wcstombs_org,
+ NULL
+};
+
+static XlcConv
+open_wcstombs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &wcstombs_methods);
+}
+
+static XlcConvMethodsRec wcstocts_methods = {
+ close_converter,
+ wcstocts,
+ NULL
+};
+
+static XlcConv
+open_wcstocts(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &wcstocts_methods);
+}
+
+static XlcConvMethodsRec wcstostr_methods = {
+ close_converter,
+ wcstostr,
+ NULL
+};
+
+static XlcConv
+open_wcstostr(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &wcstostr_methods);
+}
+
+static XlcConvMethodsRec wcstocs_methods = {
+ close_converter,
+ wcstocs,
+ NULL
+};
+
+static XlcConv
+open_wcstocs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &wcstocs_methods);
+}
+
+static XlcConvMethodsRec wctocs_methods = {
+ close_converter,
+ wctocs,
+ NULL
+};
+
+static XlcConv
+open_wctocs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &wctocs_methods);
+}
+
+static XlcConvMethodsRec ctstowcs_methods = {
+ close_converter,
+ ctstowcs,
+ NULL
+};
+
+static XlcConv
+open_ctstowcs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &ctstowcs_methods);
+}
+
+static XlcConvMethodsRec cstowcs_methods = {
+ close_converter,
+ cstowcs,
+ NULL
+};
+
+static XlcConv
+open_cstowcs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &cstowcs_methods);
+}
+
+static XlcConvMethodsRec strtowcs_methods = {
+ close_converter,
+ strtowcs,
+ NULL
+};
+
+static XlcConv
+open_strtowcs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &strtowcs_methods);
+}
+
+/* -------------------------------------------------------------------------- */
+/* Loader */
+/* -------------------------------------------------------------------------- */
+
+XLCd
+_XlcGenericLoader(
+ const char *name)
+{
+ XLCd lcd;
+#ifdef STDCVT
+ XLCdGenericPart *gen;
+#endif
+
+ lcd = _XlcCreateLC(name, _XlcGenericMethods);
+
+ if (lcd == NULL)
+ return lcd;
+
+ default_GL_charset = _XlcGetCharSet("ISO8859-1:GL");
+ default_GR_charset = _XlcGetCharSet("ISO8859-1:GR");
+
+ _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCompoundText, open_mbstocts);
+ _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNString, open_mbstostr);
+ _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCharSet, open_mbstocs);
+ _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNChar, open_mbtocs);
+ _XlcSetConverter(lcd, XlcNCompoundText, lcd, XlcNMultiByte, open_ctstombs);
+ _XlcSetConverter(lcd, XlcNString, lcd, XlcNMultiByte, open_strtombs);
+ _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte, open_cstombs);
+
+#ifdef STDCVT
+ gen = XLC_GENERIC_PART(lcd);
+
+ if (gen->use_stdc_env != True) {
+#endif
+ _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar, open_mbstowcs);
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte, open_wcstombs);
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCompoundText, open_wcstocts);
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNString, open_wcstostr);
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet, open_wcstocs);
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNChar, open_wctocs);
+ _XlcSetConverter(lcd, XlcNCompoundText, lcd, XlcNWideChar, open_ctstowcs);
+ _XlcSetConverter(lcd, XlcNString, lcd, XlcNWideChar, open_strtowcs);
+ _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar, open_cstowcs);
+#ifdef STDCVT
+ }
+#endif
+
+#ifdef STDCVT
+ if (gen->use_stdc_env == True) {
+ _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNWideChar, open_stdc_mbstowcs);
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte, open_stdc_wcstombs);
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCompoundText, open_stdc_wcstocts);
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNString, open_stdc_wcstostr);
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet, open_stdc_wcstocs);
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNChar, open_stdc_wctocs);
+ _XlcSetConverter(lcd, XlcNCompoundText, lcd, XlcNWideChar, open_stdc_ctstowcs);
+ _XlcSetConverter(lcd, XlcNString, lcd, XlcNWideChar, open_stdc_strtowcs);
+ _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar, open_stdc_cstowcs);
+ }
+#endif
+
+ _XlcAddUtf8Converters(lcd);
+
+ return lcd;
+}
diff --git a/libX11/modules/lc/xlocale/lcJis.c b/libX11/modules/lc/xlocale/lcJis.c
index 594e6363c..c2ca2f560 100644
--- a/libX11/modules/lc/xlocale/lcJis.c
+++ b/libX11/modules/lc/xlocale/lcJis.c
@@ -1,945 +1,944 @@
-/*
- * Copyright 1992, 1993 by TOSHIBA Corp.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of TOSHIBA not be used in advertising
- * or publicity pertaining to distribution of the software without specific,
- * written prior permission. TOSHIBA make no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
- * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- *
- * Author: Katsuhisa Yano TOSHIBA Corp.
- * mopi@osa.ilab.toshiba.co.jp
- */
-
-/*
- * A Japanese JIS locale.
- * Supports: all locales with codeset JIS7.
- * How: Provides converters for JIS.
- * Platforms: Only those defining X_LOCALE (only Lynx, Linux-libc5, OS/2).
- */
-
-#ifdef X_LOCALE
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include "XlcGeneric.h"
-#include <stdio.h>
-
-#if !defined(X_LOCALE)
-#define STDCVT
-#endif
-
-typedef struct _StateRec {
- XLCd lcd;
- XlcCharSet charset;
- XlcCharSet GL_charset;
- XlcCharSet GR_charset;
-} StateRec, *State;
-
-static void
-init_state(
- XlcConv conv)
-{
- State state = (State) conv->state;
- XLCdGenericPart *gen = XLC_GENERIC_PART(state->lcd);
- CodeSet codeset;
-
- codeset = gen->initial_state_GL;
- if (codeset && codeset->charset_list)
- state->GL_charset = *codeset->charset_list;
- codeset = gen->initial_state_GR;
- if (codeset && codeset->charset_list)
- state->GR_charset = *codeset->charset_list;
-
- if (state->GL_charset == NULL)
- if ((codeset = *gen->codeset_list) != NULL)
- state->GL_charset = *codeset->charset_list;
-}
-
-static int
-compare(
- const char *src,
- const char *encoding,
- int length)
-{
- const char *start = src;
-
- while (length-- > 0) {
- if (*src++ != *encoding++)
- return 0;
- if (*encoding == '\0')
- return src - start;
- }
-
- return 0;
-}
-
-static int
-mbtocs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
- const char *src;
- char *dst;
- unsigned char *mb_parse_table;
- ParseInfo *parse_list, parse_info;
- XlcCharSet charset;
- int length, number, encoding_len = 0;
- int i;
-
- src = *((const char **) from);
- dst = *((char **) to);
-
- mb_parse_table = XLC_GENERIC(lcd, mb_parse_table);
- if (mb_parse_table != NULL) {
- number = mb_parse_table[(unsigned char) *src];
- if (number > 0) {
- parse_list = XLC_GENERIC(lcd, mb_parse_list) + number - 1;
- for ( ; (parse_info = *parse_list) != NULL; parse_list++) {
- encoding_len = compare(src, parse_info->encoding, *from_left);
- if (encoding_len > 0) {
- switch (parse_info->type) {
- case E_SS:
- src += encoding_len;
- charset = *parse_info->codeset->charset_list;
- goto found;
- case E_LSL:
- case E_LSR:
- src += encoding_len;
- charset = *parse_info->codeset->charset_list;
- if (parse_info->type == E_LSL)
- state->GL_charset = charset;
- else
- state->GR_charset = charset;
- length = 0;
- goto end;
- case E_GL:
- charset = state->GL_charset;
- goto found;
- case E_GR:
- charset = state->GR_charset;
- goto found;
- default:
- break;
- }
- }
- }
- }
- }
-
- if ((*src & 0x80) && state->GR_charset)
- charset = state->GR_charset;
- else
- charset = state->GL_charset;
-
-found:
- if (charset == NULL ||
- (num_args == 2 && (XlcCharSet) args[1] != charset))
- return -1;
-
- length = charset->char_size;
- if (length > *from_left - encoding_len)
- return -1;
-
- if (dst) {
- if (length > *to_left)
- return -1;
- if (charset->side == XlcGL) {
- for (i = 0; i < length; i++)
- *dst++ = *src++ & 0x7f;
- } else if (charset->side == XlcGR) {
- for (i = 0; i < length; i++)
- *dst++ = *src++ | 0x80;
- } else {
- for (i = 0; i < length; i++)
- *dst++ = *src++;
- }
- *to = (XPointer) dst;
- *to_left -= length;
- }
-end:
- *from = (XPointer) src;
- *from_left -= encoding_len + length;
- state->charset = charset;
- if (num_args == 1)
- *((XlcCharSet *) args[0]) = charset;
-
- return 0;
-}
-
-static int
-mbstocs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- XlcCharSet charset = NULL;
- XPointer tmp_args[2], save_from = *from;
- int ret, unconv_num = 0, tmp_num = 1;
-
- tmp_args[0] = (XPointer) &charset;
-
- while (*from_left > 0 && *to_left > 0) {
- ret = mbtocs(conv, from, from_left, to, to_left, tmp_args, tmp_num);
- if (ret < 0)
- break;
- unconv_num += ret;
- if (tmp_num == 1 && charset) {
- tmp_args[1] = (XPointer) charset;
- tmp_num = 2;
- }
- }
-
- if (save_from == *from)
- return -1;
-
- if (num_args > 0)
- *((XlcCharSet *) args[0]) = charset;
-
- return unconv_num;
-}
-
-static CodeSet
-wc_parse_codeset(
- XLCd lcd,
- const wchar_t *wcstr)
-{
- CodeSet *codeset;
- unsigned long wc_encoding;
- int num;
-
- wc_encoding = *wcstr & XLC_GENERIC(lcd, wc_encode_mask);
- num = XLC_GENERIC(lcd, codeset_num);
- codeset = XLC_GENERIC(lcd, codeset_list);
- while (num-- > 0) {
- if (wc_encoding == (*codeset)->wc_encoding)
- return *codeset;
- codeset++;
- }
-
- return NULL;
-}
-
-static int
-wcstocs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
- const wchar_t *wcptr;
- char *bufptr;
- wchar_t wch;
- char *tmpptr;
- int length;
- CodeSet codeset;
- unsigned long wc_encoding;
- int wcstr_len, buf_len;
-
- if (from == NULL || *from == NULL)
- return 0;
-
- wcptr = *((const wchar_t **) from);
- bufptr = *((char **) to);
- wcstr_len = *from_left;
- buf_len = *to_left;
-
- codeset = wc_parse_codeset(lcd, wcptr);
- if (codeset == NULL)
- return -1;
- wc_encoding = codeset->wc_encoding;
-
- if (wcstr_len < buf_len / codeset->length)
- buf_len = wcstr_len * codeset->length;
-
- for ( ; wcstr_len > 0 && buf_len > 0; wcptr++, wcstr_len--) {
- wch = *wcptr;
- if ((wch & XLC_GENERIC(lcd, wc_encode_mask)) != wc_encoding)
- break;
- length = codeset->length;
- buf_len -= length;
- bufptr += length;
-
- tmpptr = bufptr - 1;
- if ((*codeset->charset_list)->side == XlcGL) {
- while (length--) {
- *tmpptr-- = (unsigned char) (wch & 0x7f);
- wch >>= (wchar_t)XLC_GENERIC(lcd, wc_shift_bits);
- }
- } else if ((*codeset->charset_list)->side == XlcGR) {
- while (length--) {
- *tmpptr-- = (unsigned char) (wch | 0x80);
- wch >>= (wchar_t)XLC_GENERIC(lcd, wc_shift_bits);
- }
- } else {
- while (length--) {
- *tmpptr-- = (unsigned char) wch;
- wch >>= (wchar_t)XLC_GENERIC(lcd, wc_shift_bits);
- }
- }
- }
-
- if (num_args > 0)
- *((XlcCharSet *) args[0]) = *codeset->charset_list;
-
- *from_left -= wcptr - *((wchar_t **) from);
- *from = (XPointer) wcptr;
-
- *to_left -= bufptr - *((char **) to);
- *to = bufptr;
-
- return 0;
-}
-
-static CodeSet
-GetCodeSetFromCharSet(
- XLCd lcd,
- XlcCharSet charset)
-{
- CodeSet *codeset = XLC_GENERIC(lcd, codeset_list);
- XlcCharSet *charset_list;
- int codeset_num, num_charsets;
-
- codeset_num = XLC_GENERIC(lcd, codeset_num);
-
- for ( ; codeset_num-- > 0; codeset++) {
- num_charsets = (*codeset)->num_charsets;
- charset_list = (*codeset)->charset_list;
-
- for ( ; num_charsets-- > 0; charset_list++)
- if (*charset_list == charset)
- return *codeset;
- }
-
- return (CodeSet) NULL;
-}
-
-static int
-cstombs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- const char *csptr;
- char *bufptr;
- int csstr_len;
- int buf_len;
- int num, encoding_len = 0;
- CodeSet codeset;
- XlcCharSet charset;
- EncodingType type;
- int cvt_length;
-
- csptr = *((const char **) from);
- bufptr = *((char **) to);
- csstr_len = *from_left;
- buf_len = *to_left;
-
- if (num_args < 1)
- return -1;
-
- charset = (XlcCharSet) args[0];
-
- codeset = GetCodeSetFromCharSet(state->lcd, charset);
- if (codeset == NULL)
- return -1;
-
- cvt_length = 0;
- if (codeset->parse_info) {
- switch (type = codeset->parse_info->type) {
- case E_SS:
- encoding_len = strlen(codeset->parse_info->encoding);
- break;
- case E_LSL:
- case E_LSR:
- if (type == E_LSL) {
- if (charset == state->GL_charset)
- break;
- } else {
- if (charset == state->GR_charset)
- break;
- }
- encoding_len = strlen(codeset->parse_info->encoding);
- if (encoding_len > buf_len)
- return -1;
- cvt_length += encoding_len;
- if (bufptr) {
- strcpy(bufptr, codeset->parse_info->encoding);
- bufptr += encoding_len;
- }
- buf_len -= encoding_len;
- encoding_len = 0;
- if (type == E_LSL)
- state->GL_charset = charset;
- else
- state->GR_charset = charset;
- break;
- default:
- break;
- }
- }
-
- csstr_len /= codeset->length;
- buf_len /= codeset->length + encoding_len;
- if (csstr_len < buf_len)
- buf_len = csstr_len;
-
- cvt_length += buf_len * (encoding_len + codeset->length);
- if (bufptr) {
- while (buf_len--) {
- if (encoding_len) {
- strcpy(bufptr, codeset->parse_info->encoding);
- bufptr += encoding_len;
- }
- num = codeset->length;
- if (codeset->side == XlcGL) {
- while (num--)
- *bufptr++ = *csptr++ & 0x7f;
- } else if (codeset->side == XlcGR) {
- while (num--)
- *bufptr++ = *csptr++ | 0x80;
- } else {
- while (num--)
- *bufptr++ = *csptr++;
- }
- }
- }
-
- *from_left -= csptr - *((char **) from);
- *from = (XPointer) csptr;
-
- if (bufptr)
- *to = (XPointer) bufptr;
- *to_left -= cvt_length;
-
- return 0;
-}
-
-static int
-cstowcs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- State state = (State) conv->state;
- XLCd lcd = state->lcd;
- const char *csptr;
- wchar_t *bufptr;
- int csstr_len;
- int buf_len;
- wchar_t wch;
- unsigned long code_mask, wc_encoding;
- int num, length, wc_shift_bits;
- CodeSet codeset;
-
- csptr = *((const char **) from);
- bufptr = *((wchar_t **) to);
- csstr_len = *from_left;
- buf_len = *to_left;
-
- if (num_args < 1)
- return -1;
-
- codeset = GetCodeSetFromCharSet(lcd, (XlcCharSet) args[0]);
- if (codeset == NULL)
- return -1;
-
- length = codeset->length;
- csstr_len /= length;
- if (csstr_len < buf_len)
- buf_len = csstr_len;
-
- code_mask = ~XLC_GENERIC(lcd, wc_encode_mask);
- wc_encoding = codeset->wc_encoding;
- wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits);
-
- *to_left -= buf_len;
-
- if (bufptr) {
- while (buf_len--) {
- wch = (wchar_t) (*csptr++ & 0x7f);
- num = length - 1;
- while (num--)
- wch = (wch << wc_shift_bits) | (*csptr++ & 0x7f);
-
- *bufptr++ = (wch & code_mask) | wc_encoding;
- }
- }
-
- *from_left -= csptr - *((char **) from);
- *from = (XPointer) csptr;
-
- if (bufptr)
- *to = (XPointer) bufptr;
-
- return 0;
-}
-
-
-static void
-close_converter(
- XlcConv conv)
-{
- if (conv->state) {
- Xfree((char *) conv->state);
- }
-
- Xfree((char *) conv);
-}
-
-static XlcConv
-create_conv(
- XLCd lcd,
- XlcConvMethods methods)
-{
- XlcConv conv;
- State state;
-
- conv = (XlcConv) Xmalloc(sizeof(XlcConvRec));
- if (conv == NULL)
- return (XlcConv) NULL;
-
- conv->methods = (XlcConvMethods) Xmalloc(sizeof(XlcConvMethodsRec));
- if (conv->methods == NULL)
- goto err;
- *conv->methods = *methods;
- if (XLC_PUBLIC(lcd, is_state_depend))
- conv->methods->reset = init_state;
-
- conv->state = (XPointer) Xmalloc(sizeof(StateRec));
- if (conv->state == NULL)
- goto err;
- bzero((char *) conv->state, sizeof(StateRec));
-
- state = (State) conv->state;
- state->lcd = lcd;
- init_state(conv);
-
- return conv;
-
-err:
- close_converter(conv);
-
- return (XlcConv) NULL;
-}
-
-static XlcConvMethodsRec mbstocs_methods = {
- close_converter,
- mbstocs,
- NULL
-};
-
-static XlcConv
-open_mbstocs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &mbstocs_methods);
-}
-
-static XlcConvMethodsRec wcstocs_methods = {
- close_converter,
- wcstocs,
- NULL
-};
-
-static XlcConv
-open_wcstocs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &wcstocs_methods);
-}
-
-static XlcConvMethodsRec mbtocs_methods = {
- close_converter,
- mbtocs,
- NULL
-};
-
-static XlcConv
-open_mbtocs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &mbtocs_methods);
-}
-
-static XlcConvMethodsRec cstombs_methods = {
- close_converter,
- cstombs,
- NULL
-};
-
-static XlcConv
-open_cstombs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &cstombs_methods);
-}
-
-static XlcConvMethodsRec cstowcs_methods = {
- close_converter,
- cstowcs,
- NULL
-};
-
-static XlcConv
-open_cstowcs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &cstowcs_methods);
-}
-
-#ifdef STDCVT
-static int
-stdc_mbstowcs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- const char *src = *((const char **) from);
- wchar_t *dst = *((wchar_t **) to);
- int src_left = *from_left;
- int dst_left = *to_left;
- int length;
-
- while (src_left > 0 && dst_left > 0) {
- length = mbtowc(dst, src, src_left);
- if (length < 0)
- break;
-
- src += length;
- src_left -= length;
- if (dst)
- dst++;
- dst_left--;
-
- if (length == 0) {
- src++;
- src_left--;
- break;
- }
- }
-
- if (*from_left == src_left)
- return -1;
-
- *from = (XPointer) src;
- if (dst)
- *to = (XPointer) dst;
- *from_left = src_left;
- *to_left = dst_left;
-
- return 0;
-}
-
-static int
-stdc_wcstombs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- const wchar_t *src = *((const wchar_t **) from);
- char *dst = *((char **) to);
- int src_left = *from_left;
- int dst_left = *to_left;
- int length;
-
- while (src_left > 0 && dst_left > 0) {
- length = wctomb(dst, *src); /* XXX */
- if (length < 0 || dst_left < length)
- break;
-
- src++;
- src_left--;
- dst += length;
- dst_left -= length;
-
- if (length == 0) {
- dst++;
- dst_left--;
- break;
- }
- }
-
- if (*from_left == src_left)
- return -1;
-
- *from = (XPointer) src;
- *to = (XPointer) dst;
- *from_left = src_left;
- *to_left = dst_left;
-
- return 0;
-}
-
-static int
-stdc_wcstocs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- const wchar_t *src = *((const wchar_t **) from);
- wchar_t wch;
- XlcCharSet charset = NULL;
- XPointer tmp_args[2], tmp_from, save_from = *from;
- char tmp[32];
- int length, ret, src_left = *from_left;
- int unconv_num = 0, tmp_num = 1;
-
- tmp_args[0] = (XPointer) &charset;
-
- while (src_left > 0 && *to_left > 0) {
- if (wch = *src) {
- length = wctomb(tmp, wch);
- } else {
- length = 1;
- *tmp = '\0';
- }
-
- if (length < 0)
- break;
-
- tmp_from = (XPointer) tmp;
- ret = mbtocs(conv, &tmp_from, &length, to, to_left, tmp_args, tmp_num);
- if (ret < 0)
- break;
- unconv_num += ret;
- if (tmp_num == 1 && charset) {
- tmp_args[1] = (XPointer) charset;
- tmp_num = 2;
- }
-
- src++;
- src_left--;
- }
-
- if (save_from == (XPointer) src)
- return -1;
-
- *from = (XPointer) src;
- *from_left = src_left;
-
- if (num_args > 0)
- *((XlcCharSet *) args[0]) = charset;
-
- return unconv_num;
-}
-
-#define DefineLocalBuf char local_buf[BUFSIZ]
-#define AllocLocalBuf(length) (length > BUFSIZ ? (char*) Xmalloc(length) : local_buf)
-#define FreeLocalBuf(ptr) if (ptr != local_buf) Xfree(ptr)
-
-static int
-stdc_cstowcs(
- XlcConv conv,
- XPointer *from,
- int *from_left,
- XPointer *to,
- int *to_left,
- XPointer *args,
- int num_args)
-{
- XLCd lcd = ((State) conv->state)->lcd;
- DefineLocalBuf;
- XPointer buf, save_buf;
- int length, left, ret;
-
- left = length = *to_left * XLC_PUBLIC(lcd, mb_cur_max);
- buf = save_buf = (XPointer) AllocLocalBuf(length);
- if (buf == NULL)
- return -1;
-
- ret = cstombs(conv, from, from_left, &buf, &left, args, num_args);
- if (ret < 0)
- goto err;
-
- buf = save_buf;
- length -= left;
- if (stdc_mbstowcs(conv, &buf, &length, to, to_left, args, num_args) < 0)
- ret = -1;
-
-err:
- FreeLocalBuf(save_buf);
-
- return ret;
-}
-
-static XlcConvMethodsRec stdc_mbstowcs_methods = {
- close_converter,
- stdc_mbstowcs,
- NULL
-};
-
-static XlcConv
-open_stdc_mbstowcs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_mbstowcs_methods);
-}
-
-static XlcConvMethodsRec stdc_wcstombs_methods = {
- close_converter,
- stdc_wcstombs,
- NULL
-};
-
-static XlcConv
-open_stdc_wcstombs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_wcstombs_methods);
-}
-
-static XlcConvMethodsRec stdc_wcstocs_methods = {
- close_converter,
- stdc_wcstocs,
- NULL
-};
-
-static XlcConv
-open_stdc_wcstocs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_wcstocs_methods);
-}
-
-static XlcConvMethodsRec stdc_cstowcs_methods = {
- close_converter,
- stdc_cstowcs,
- NULL
-};
-
-static XlcConv
-open_stdc_cstowcs(
- XLCd from_lcd,
- const char *from_type,
- XLCd to_lcd,
- const char *to_type)
-{
- return create_conv(from_lcd, &stdc_cstowcs_methods);
-}
-#endif /* STDCVT */
-
-XLCd
-_XlcJisLoader(
- const char *name)
-{
- XLCd lcd;
-#ifdef STDCVT
- XLCdGenericPart *gen;
-#endif
-
- lcd = _XlcCreateLC(name, _XlcGenericMethods);
- if (lcd == NULL)
- return lcd;
-
- if (!XLC_PUBLIC_PART(lcd)->codeset ||
- (_XlcCompareISOLatin1(XLC_PUBLIC_PART(lcd)->codeset, "JIS7"))) {
- _XlcDestroyLC(lcd);
- return (XLCd) NULL;
- }
-
- _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNChar, open_mbtocs);
- _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCharSet, open_mbstocs);
- _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte, open_cstombs);
-
-#ifdef STDCVT
- gen = XLC_GENERIC_PART(lcd);
-
- if (gen->use_stdc_env == True) {
- _XlcSetConverter(lcd,XlcNMultiByte,lcd,XlcNWideChar,open_stdc_mbstowcs);
- _XlcSetConverter(lcd,XlcNWideChar,lcd,XlcNMultiByte,open_stdc_wcstombs);
- }
- if (gen->force_convert_to_mb == True) {
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet,open_stdc_wcstocs);
- _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar,open_stdc_cstowcs);
- } else {
-#endif
- _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet, open_wcstocs);
- _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar, open_cstowcs);
-#ifdef STDCVT
- }
-#endif
-
- _XlcAddUtf8Converters(lcd);
-
- return lcd;
-}
-
-#else
-typedef int dummy;
-#endif /* X_LOCALE */
+/*
+ * Copyright 1992, 1993 by TOSHIBA Corp.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of TOSHIBA not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission. TOSHIBA make no representations about the
+ * suitability of this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+ * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Author: Katsuhisa Yano TOSHIBA Corp.
+ * mopi@osa.ilab.toshiba.co.jp
+ */
+
+/*
+ * A Japanese JIS locale.
+ * Supports: all locales with codeset JIS7.
+ * How: Provides converters for JIS.
+ * Platforms: Only those defining X_LOCALE (only Lynx, Linux-libc5, OS/2).
+ */
+
+#ifdef X_LOCALE
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "XlcGeneric.h"
+#include <stdio.h>
+
+#if !defined(X_LOCALE)
+#define STDCVT
+#endif
+
+typedef struct _StateRec {
+ XLCd lcd;
+ XlcCharSet charset;
+ XlcCharSet GL_charset;
+ XlcCharSet GR_charset;
+} StateRec, *State;
+
+static void
+init_state(
+ XlcConv conv)
+{
+ State state = (State) conv->state;
+ XLCdGenericPart *gen = XLC_GENERIC_PART(state->lcd);
+ CodeSet codeset;
+
+ codeset = gen->initial_state_GL;
+ if (codeset && codeset->charset_list)
+ state->GL_charset = *codeset->charset_list;
+ codeset = gen->initial_state_GR;
+ if (codeset && codeset->charset_list)
+ state->GR_charset = *codeset->charset_list;
+
+ if (state->GL_charset == NULL)
+ if ((codeset = *gen->codeset_list) != NULL)
+ state->GL_charset = *codeset->charset_list;
+}
+
+static int
+compare(
+ const char *src,
+ const char *encoding,
+ int length)
+{
+ const char *start = src;
+
+ while (length-- > 0) {
+ if (*src++ != *encoding++)
+ return 0;
+ if (*encoding == '\0')
+ return src - start;
+ }
+
+ return 0;
+}
+
+static int
+mbtocs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+ const char *src;
+ char *dst;
+ unsigned char *mb_parse_table;
+ ParseInfo *parse_list, parse_info;
+ XlcCharSet charset;
+ int length, number, encoding_len = 0;
+ int i;
+
+ src = *((const char **) from);
+ dst = *((char **) to);
+
+ mb_parse_table = XLC_GENERIC(lcd, mb_parse_table);
+ if (mb_parse_table != NULL) {
+ number = mb_parse_table[(unsigned char) *src];
+ if (number > 0) {
+ parse_list = XLC_GENERIC(lcd, mb_parse_list) + number - 1;
+ for ( ; (parse_info = *parse_list) != NULL; parse_list++) {
+ encoding_len = compare(src, parse_info->encoding, *from_left);
+ if (encoding_len > 0) {
+ switch (parse_info->type) {
+ case E_SS:
+ src += encoding_len;
+ charset = *parse_info->codeset->charset_list;
+ goto found;
+ case E_LSL:
+ case E_LSR:
+ src += encoding_len;
+ charset = *parse_info->codeset->charset_list;
+ if (parse_info->type == E_LSL)
+ state->GL_charset = charset;
+ else
+ state->GR_charset = charset;
+ length = 0;
+ goto end;
+ case E_GL:
+ charset = state->GL_charset;
+ goto found;
+ case E_GR:
+ charset = state->GR_charset;
+ goto found;
+ default:
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ if ((*src & 0x80) && state->GR_charset)
+ charset = state->GR_charset;
+ else
+ charset = state->GL_charset;
+
+found:
+ if (charset == NULL ||
+ (num_args == 2 && (XlcCharSet) args[1] != charset))
+ return -1;
+
+ length = charset->char_size;
+ if (length > *from_left - encoding_len)
+ return -1;
+
+ if (dst) {
+ if (length > *to_left)
+ return -1;
+ if (charset->side == XlcGL) {
+ for (i = 0; i < length; i++)
+ *dst++ = *src++ & 0x7f;
+ } else if (charset->side == XlcGR) {
+ for (i = 0; i < length; i++)
+ *dst++ = *src++ | 0x80;
+ } else {
+ for (i = 0; i < length; i++)
+ *dst++ = *src++;
+ }
+ *to = (XPointer) dst;
+ *to_left -= length;
+ }
+end:
+ *from = (XPointer) src;
+ *from_left -= encoding_len + length;
+ state->charset = charset;
+ if (num_args == 1)
+ *((XlcCharSet *) args[0]) = charset;
+
+ return 0;
+}
+
+static int
+mbstocs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ XlcCharSet charset = NULL;
+ XPointer tmp_args[2], save_from = *from;
+ int ret, unconv_num = 0, tmp_num = 1;
+
+ tmp_args[0] = (XPointer) &charset;
+
+ while (*from_left > 0 && *to_left > 0) {
+ ret = mbtocs(conv, from, from_left, to, to_left, tmp_args, tmp_num);
+ if (ret < 0)
+ break;
+ unconv_num += ret;
+ if (tmp_num == 1 && charset) {
+ tmp_args[1] = (XPointer) charset;
+ tmp_num = 2;
+ }
+ }
+
+ if (save_from == *from)
+ return -1;
+
+ if (num_args > 0)
+ *((XlcCharSet *) args[0]) = charset;
+
+ return unconv_num;
+}
+
+static CodeSet
+wc_parse_codeset(
+ XLCd lcd,
+ const wchar_t *wcstr)
+{
+ CodeSet *codeset;
+ unsigned long wc_encoding;
+ int num;
+
+ wc_encoding = *wcstr & XLC_GENERIC(lcd, wc_encode_mask);
+ num = XLC_GENERIC(lcd, codeset_num);
+ codeset = XLC_GENERIC(lcd, codeset_list);
+ while (num-- > 0) {
+ if (wc_encoding == (*codeset)->wc_encoding)
+ return *codeset;
+ codeset++;
+ }
+
+ return NULL;
+}
+
+static int
+wcstocs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+ const wchar_t *wcptr;
+ char *bufptr;
+ wchar_t wch;
+ char *tmpptr;
+ int length;
+ CodeSet codeset;
+ unsigned long wc_encoding;
+ int wcstr_len, buf_len;
+
+ if (from == NULL || *from == NULL)
+ return 0;
+
+ wcptr = *((const wchar_t **) from);
+ bufptr = *((char **) to);
+ wcstr_len = *from_left;
+ buf_len = *to_left;
+
+ codeset = wc_parse_codeset(lcd, wcptr);
+ if (codeset == NULL)
+ return -1;
+ wc_encoding = codeset->wc_encoding;
+
+ if (wcstr_len < buf_len / codeset->length)
+ buf_len = wcstr_len * codeset->length;
+
+ for ( ; wcstr_len > 0 && buf_len > 0; wcptr++, wcstr_len--) {
+ wch = *wcptr;
+ if ((wch & XLC_GENERIC(lcd, wc_encode_mask)) != wc_encoding)
+ break;
+ length = codeset->length;
+ buf_len -= length;
+ bufptr += length;
+
+ tmpptr = bufptr - 1;
+ if ((*codeset->charset_list)->side == XlcGL) {
+ while (length--) {
+ *tmpptr-- = (unsigned char) (wch & 0x7f);
+ wch >>= (wchar_t)XLC_GENERIC(lcd, wc_shift_bits);
+ }
+ } else if ((*codeset->charset_list)->side == XlcGR) {
+ while (length--) {
+ *tmpptr-- = (unsigned char) (wch | 0x80);
+ wch >>= (wchar_t)XLC_GENERIC(lcd, wc_shift_bits);
+ }
+ } else {
+ while (length--) {
+ *tmpptr-- = (unsigned char) wch;
+ wch >>= (wchar_t)XLC_GENERIC(lcd, wc_shift_bits);
+ }
+ }
+ }
+
+ if (num_args > 0)
+ *((XlcCharSet *) args[0]) = *codeset->charset_list;
+
+ *from_left -= wcptr - *((wchar_t **) from);
+ *from = (XPointer) wcptr;
+
+ *to_left -= bufptr - *((char **) to);
+ *to = bufptr;
+
+ return 0;
+}
+
+static CodeSet
+GetCodeSetFromCharSet(
+ XLCd lcd,
+ XlcCharSet charset)
+{
+ CodeSet *codeset = XLC_GENERIC(lcd, codeset_list);
+ XlcCharSet *charset_list;
+ int codeset_num, num_charsets;
+
+ codeset_num = XLC_GENERIC(lcd, codeset_num);
+
+ for ( ; codeset_num-- > 0; codeset++) {
+ num_charsets = (*codeset)->num_charsets;
+ charset_list = (*codeset)->charset_list;
+
+ for ( ; num_charsets-- > 0; charset_list++)
+ if (*charset_list == charset)
+ return *codeset;
+ }
+
+ return (CodeSet) NULL;
+}
+
+static int
+cstombs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ const char *csptr;
+ char *bufptr;
+ int csstr_len;
+ int buf_len;
+ int num, encoding_len = 0;
+ CodeSet codeset;
+ XlcCharSet charset;
+ EncodingType type;
+ int cvt_length;
+
+ csptr = *((const char **) from);
+ bufptr = *((char **) to);
+ csstr_len = *from_left;
+ buf_len = *to_left;
+
+ if (num_args < 1)
+ return -1;
+
+ charset = (XlcCharSet) args[0];
+
+ codeset = GetCodeSetFromCharSet(state->lcd, charset);
+ if (codeset == NULL)
+ return -1;
+
+ cvt_length = 0;
+ if (codeset->parse_info) {
+ switch (type = codeset->parse_info->type) {
+ case E_SS:
+ encoding_len = strlen(codeset->parse_info->encoding);
+ break;
+ case E_LSL:
+ case E_LSR:
+ if (type == E_LSL) {
+ if (charset == state->GL_charset)
+ break;
+ } else {
+ if (charset == state->GR_charset)
+ break;
+ }
+ encoding_len = strlen(codeset->parse_info->encoding);
+ if (encoding_len > buf_len)
+ return -1;
+ cvt_length += encoding_len;
+ if (bufptr) {
+ strcpy(bufptr, codeset->parse_info->encoding);
+ bufptr += encoding_len;
+ }
+ buf_len -= encoding_len;
+ encoding_len = 0;
+ if (type == E_LSL)
+ state->GL_charset = charset;
+ else
+ state->GR_charset = charset;
+ break;
+ default:
+ break;
+ }
+ }
+
+ csstr_len /= codeset->length;
+ buf_len /= codeset->length + encoding_len;
+ if (csstr_len < buf_len)
+ buf_len = csstr_len;
+
+ cvt_length += buf_len * (encoding_len + codeset->length);
+ if (bufptr) {
+ while (buf_len--) {
+ if (encoding_len) {
+ strcpy(bufptr, codeset->parse_info->encoding);
+ bufptr += encoding_len;
+ }
+ num = codeset->length;
+ if (codeset->side == XlcGL) {
+ while (num--)
+ *bufptr++ = *csptr++ & 0x7f;
+ } else if (codeset->side == XlcGR) {
+ while (num--)
+ *bufptr++ = *csptr++ | 0x80;
+ } else {
+ while (num--)
+ *bufptr++ = *csptr++;
+ }
+ }
+ }
+
+ *from_left -= csptr - *((char **) from);
+ *from = (XPointer) csptr;
+
+ if (bufptr)
+ *to = (XPointer) bufptr;
+ *to_left -= cvt_length;
+
+ return 0;
+}
+
+static int
+cstowcs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ State state = (State) conv->state;
+ XLCd lcd = state->lcd;
+ const char *csptr;
+ wchar_t *bufptr;
+ int csstr_len;
+ int buf_len;
+ wchar_t wch;
+ unsigned long code_mask, wc_encoding;
+ int num, length, wc_shift_bits;
+ CodeSet codeset;
+
+ csptr = *((const char **) from);
+ bufptr = *((wchar_t **) to);
+ csstr_len = *from_left;
+ buf_len = *to_left;
+
+ if (num_args < 1)
+ return -1;
+
+ codeset = GetCodeSetFromCharSet(lcd, (XlcCharSet) args[0]);
+ if (codeset == NULL)
+ return -1;
+
+ length = codeset->length;
+ csstr_len /= length;
+ if (csstr_len < buf_len)
+ buf_len = csstr_len;
+
+ code_mask = ~XLC_GENERIC(lcd, wc_encode_mask);
+ wc_encoding = codeset->wc_encoding;
+ wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits);
+
+ *to_left -= buf_len;
+
+ if (bufptr) {
+ while (buf_len--) {
+ wch = (wchar_t) (*csptr++ & 0x7f);
+ num = length - 1;
+ while (num--)
+ wch = (wch << wc_shift_bits) | (*csptr++ & 0x7f);
+
+ *bufptr++ = (wch & code_mask) | wc_encoding;
+ }
+ }
+
+ *from_left -= csptr - *((char **) from);
+ *from = (XPointer) csptr;
+
+ if (bufptr)
+ *to = (XPointer) bufptr;
+
+ return 0;
+}
+
+
+static void
+close_converter(
+ XlcConv conv)
+{
+ if (conv->state) {
+ Xfree((char *) conv->state);
+ }
+
+ Xfree((char *) conv);
+}
+
+static XlcConv
+create_conv(
+ XLCd lcd,
+ XlcConvMethods methods)
+{
+ XlcConv conv;
+ State state;
+
+ conv = (XlcConv) Xmalloc(sizeof(XlcConvRec));
+ if (conv == NULL)
+ return (XlcConv) NULL;
+
+ conv->methods = (XlcConvMethods) Xmalloc(sizeof(XlcConvMethodsRec));
+ if (conv->methods == NULL)
+ goto err;
+ *conv->methods = *methods;
+ if (XLC_PUBLIC(lcd, is_state_depend))
+ conv->methods->reset = init_state;
+
+ conv->state = Xcalloc(1, sizeof(StateRec));
+ if (conv->state == NULL)
+ goto err;
+
+ state = (State) conv->state;
+ state->lcd = lcd;
+ init_state(conv);
+
+ return conv;
+
+err:
+ close_converter(conv);
+
+ return (XlcConv) NULL;
+}
+
+static XlcConvMethodsRec mbstocs_methods = {
+ close_converter,
+ mbstocs,
+ NULL
+};
+
+static XlcConv
+open_mbstocs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &mbstocs_methods);
+}
+
+static XlcConvMethodsRec wcstocs_methods = {
+ close_converter,
+ wcstocs,
+ NULL
+};
+
+static XlcConv
+open_wcstocs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &wcstocs_methods);
+}
+
+static XlcConvMethodsRec mbtocs_methods = {
+ close_converter,
+ mbtocs,
+ NULL
+};
+
+static XlcConv
+open_mbtocs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &mbtocs_methods);
+}
+
+static XlcConvMethodsRec cstombs_methods = {
+ close_converter,
+ cstombs,
+ NULL
+};
+
+static XlcConv
+open_cstombs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &cstombs_methods);
+}
+
+static XlcConvMethodsRec cstowcs_methods = {
+ close_converter,
+ cstowcs,
+ NULL
+};
+
+static XlcConv
+open_cstowcs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &cstowcs_methods);
+}
+
+#ifdef STDCVT
+static int
+stdc_mbstowcs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ const char *src = *((const char **) from);
+ wchar_t *dst = *((wchar_t **) to);
+ int src_left = *from_left;
+ int dst_left = *to_left;
+ int length;
+
+ while (src_left > 0 && dst_left > 0) {
+ length = mbtowc(dst, src, src_left);
+ if (length < 0)
+ break;
+
+ src += length;
+ src_left -= length;
+ if (dst)
+ dst++;
+ dst_left--;
+
+ if (length == 0) {
+ src++;
+ src_left--;
+ break;
+ }
+ }
+
+ if (*from_left == src_left)
+ return -1;
+
+ *from = (XPointer) src;
+ if (dst)
+ *to = (XPointer) dst;
+ *from_left = src_left;
+ *to_left = dst_left;
+
+ return 0;
+}
+
+static int
+stdc_wcstombs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ const wchar_t *src = *((const wchar_t **) from);
+ char *dst = *((char **) to);
+ int src_left = *from_left;
+ int dst_left = *to_left;
+ int length;
+
+ while (src_left > 0 && dst_left > 0) {
+ length = wctomb(dst, *src); /* XXX */
+ if (length < 0 || dst_left < length)
+ break;
+
+ src++;
+ src_left--;
+ dst += length;
+ dst_left -= length;
+
+ if (length == 0) {
+ dst++;
+ dst_left--;
+ break;
+ }
+ }
+
+ if (*from_left == src_left)
+ return -1;
+
+ *from = (XPointer) src;
+ *to = (XPointer) dst;
+ *from_left = src_left;
+ *to_left = dst_left;
+
+ return 0;
+}
+
+static int
+stdc_wcstocs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ const wchar_t *src = *((const wchar_t **) from);
+ wchar_t wch;
+ XlcCharSet charset = NULL;
+ XPointer tmp_args[2], tmp_from, save_from = *from;
+ char tmp[32];
+ int length, ret, src_left = *from_left;
+ int unconv_num = 0, tmp_num = 1;
+
+ tmp_args[0] = (XPointer) &charset;
+
+ while (src_left > 0 && *to_left > 0) {
+ if (wch = *src) {
+ length = wctomb(tmp, wch);
+ } else {
+ length = 1;
+ *tmp = '\0';
+ }
+
+ if (length < 0)
+ break;
+
+ tmp_from = (XPointer) tmp;
+ ret = mbtocs(conv, &tmp_from, &length, to, to_left, tmp_args, tmp_num);
+ if (ret < 0)
+ break;
+ unconv_num += ret;
+ if (tmp_num == 1 && charset) {
+ tmp_args[1] = (XPointer) charset;
+ tmp_num = 2;
+ }
+
+ src++;
+ src_left--;
+ }
+
+ if (save_from == (XPointer) src)
+ return -1;
+
+ *from = (XPointer) src;
+ *from_left = src_left;
+
+ if (num_args > 0)
+ *((XlcCharSet *) args[0]) = charset;
+
+ return unconv_num;
+}
+
+#define DefineLocalBuf char local_buf[BUFSIZ]
+#define AllocLocalBuf(length) (length > BUFSIZ ? (char*) Xmalloc(length) : local_buf)
+#define FreeLocalBuf(ptr) if (ptr != local_buf) Xfree(ptr)
+
+static int
+stdc_cstowcs(
+ XlcConv conv,
+ XPointer *from,
+ int *from_left,
+ XPointer *to,
+ int *to_left,
+ XPointer *args,
+ int num_args)
+{
+ XLCd lcd = ((State) conv->state)->lcd;
+ DefineLocalBuf;
+ XPointer buf, save_buf;
+ int length, left, ret;
+
+ left = length = *to_left * XLC_PUBLIC(lcd, mb_cur_max);
+ buf = save_buf = (XPointer) AllocLocalBuf(length);
+ if (buf == NULL)
+ return -1;
+
+ ret = cstombs(conv, from, from_left, &buf, &left, args, num_args);
+ if (ret < 0)
+ goto err;
+
+ buf = save_buf;
+ length -= left;
+ if (stdc_mbstowcs(conv, &buf, &length, to, to_left, args, num_args) < 0)
+ ret = -1;
+
+err:
+ FreeLocalBuf(save_buf);
+
+ return ret;
+}
+
+static XlcConvMethodsRec stdc_mbstowcs_methods = {
+ close_converter,
+ stdc_mbstowcs,
+ NULL
+};
+
+static XlcConv
+open_stdc_mbstowcs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_mbstowcs_methods);
+}
+
+static XlcConvMethodsRec stdc_wcstombs_methods = {
+ close_converter,
+ stdc_wcstombs,
+ NULL
+};
+
+static XlcConv
+open_stdc_wcstombs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_wcstombs_methods);
+}
+
+static XlcConvMethodsRec stdc_wcstocs_methods = {
+ close_converter,
+ stdc_wcstocs,
+ NULL
+};
+
+static XlcConv
+open_stdc_wcstocs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_wcstocs_methods);
+}
+
+static XlcConvMethodsRec stdc_cstowcs_methods = {
+ close_converter,
+ stdc_cstowcs,
+ NULL
+};
+
+static XlcConv
+open_stdc_cstowcs(
+ XLCd from_lcd,
+ const char *from_type,
+ XLCd to_lcd,
+ const char *to_type)
+{
+ return create_conv(from_lcd, &stdc_cstowcs_methods);
+}
+#endif /* STDCVT */
+
+XLCd
+_XlcJisLoader(
+ const char *name)
+{
+ XLCd lcd;
+#ifdef STDCVT
+ XLCdGenericPart *gen;
+#endif
+
+ lcd = _XlcCreateLC(name, _XlcGenericMethods);
+ if (lcd == NULL)
+ return lcd;
+
+ if (!XLC_PUBLIC_PART(lcd)->codeset ||
+ (_XlcCompareISOLatin1(XLC_PUBLIC_PART(lcd)->codeset, "JIS7"))) {
+ _XlcDestroyLC(lcd);
+ return (XLCd) NULL;
+ }
+
+ _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNChar, open_mbtocs);
+ _XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCharSet, open_mbstocs);
+ _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte, open_cstombs);
+
+#ifdef STDCVT
+ gen = XLC_GENERIC_PART(lcd);
+
+ if (gen->use_stdc_env == True) {
+ _XlcSetConverter(lcd,XlcNMultiByte,lcd,XlcNWideChar,open_stdc_mbstowcs);
+ _XlcSetConverter(lcd,XlcNWideChar,lcd,XlcNMultiByte,open_stdc_wcstombs);
+ }
+ if (gen->force_convert_to_mb == True) {
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet,open_stdc_wcstocs);
+ _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar,open_stdc_cstowcs);
+ } else {
+#endif
+ _XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet, open_wcstocs);
+ _XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar, open_cstowcs);
+#ifdef STDCVT
+ }
+#endif
+
+ _XlcAddUtf8Converters(lcd);
+
+ return lcd;
+}
+
+#else
+typedef int dummy;
+#endif /* X_LOCALE */
diff --git a/libX11/modules/om/generic/omGeneric.c b/libX11/modules/om/generic/omGeneric.c
index 330186d13..f705fbdbe 100644
--- a/libX11/modules/om/generic/omGeneric.c
+++ b/libX11/modules/om/generic/omGeneric.c
@@ -523,9 +523,7 @@ get_font_name(
if (list == NULL)
return NULL;
- name = (char *) Xmalloc(strlen(*list) + 1);
- if (name)
- strcpy(name, *list);
+ name = strdup(*list);
XFreeFontNames(list);
@@ -549,10 +547,9 @@ get_rotate_fontname(
|| len > XLFD_MAX_LEN)
return NULL;
- pattern = (char *)Xmalloc(len + 1);
+ pattern = strdup(font_name);
if(!pattern)
return NULL;
- strcpy(pattern, font_name);
memset(fields, 0, sizeof(char *) * 14);
ptr = pattern;
@@ -661,10 +658,8 @@ get_font_name_from_list(
for (i = 0; i < count; i++) {
fname = list[i];
if(is_match_charset(font_data, fname) == True) {
- name = (char *) Xmalloc(strlen(fname) + 1);
- if (name)
- strcpy(name, fname);
- break;
+ name = strdup(fname);
+ break;
}
}
@@ -685,11 +680,10 @@ parse_all_name(
if(is_match_charset(font_data, pattern) != True)
return False;
- font_data->xlfd_name = (char *)Xmalloc(strlen(pattern)+1);
+ font_data->xlfd_name = strdup(pattern);
if(font_data->xlfd_name == NULL)
return (-1);
- strcpy(font_data->xlfd_name, pattern);
return True;
#else /* OLDCODE */
Display *dpy = oc->core.om->core.display;
@@ -723,11 +717,10 @@ parse_all_name(
}
}
- font_data->xlfd_name = (char *)Xmalloc(strlen(pattern)+1);
+ font_data->xlfd_name = strdup(pattern);
if(font_data->xlfd_name == NULL)
return (-1);
- strcpy(font_data->xlfd_name, pattern);
return True;
#endif /* OLDCODE */
}
@@ -946,12 +939,9 @@ parse_fontdata(
* -- jjw/pma (HP)
*/
if (font_data_return) {
- font_data_return->xlfd_name = (char *)Xmalloc
- (strlen(font_data->xlfd_name) + 1);
+ font_data_return->xlfd_name = strdup(font_data->xlfd_name);
if (!font_data_return->xlfd_name) return -1;
- strcpy (font_data_return->xlfd_name, font_data->xlfd_name);
-
font_data_return->side = font_data->side;
}
#ifdef FONTDEBUG
@@ -996,11 +986,9 @@ parse_fontdata(
#ifdef FONTDEBUG
fprintf(stderr,"XLFD name: %s\n",font_data->xlfd_name);
#endif
- font_data_return->xlfd_name = (char *)Xmalloc
- (strlen(font_data->xlfd_name) + 1);
+ font_data_return->xlfd_name = strdup(font_data->xlfd_name);
if (!font_data_return->xlfd_name) return -1;
- strcpy (font_data_return->xlfd_name, font_data->xlfd_name);
font_data_return->side = font_data->side;
}
@@ -1192,11 +1180,10 @@ parse_fontname(
* be matched. It returns the required information in
* font_data_return.
*/
- font_set->font_name = (char *)Xmalloc
- (strlen(font_data_return.xlfd_name) + 1);
+ font_set->font_name = strdup(font_data_return.xlfd_name);
if(font_set->font_name == (char *) NULL)
goto err;
- strcpy(font_set->font_name, font_data_return.xlfd_name);
+
font_set->side = font_data_return.side;
Xfree (font_data_return.xlfd_name);
@@ -1223,11 +1210,10 @@ parse_fontname(
break;
}
}
- font_set->font_name = (char *)Xmalloc
- (strlen(font_set->substitute[i].xlfd_name) + 1);
+ font_set->font_name = strdup(font_set->substitute[i].xlfd_name);
if(font_set->font_name == (char *) NULL)
goto err;
- strcpy(font_set->font_name,font_set->substitute[i].xlfd_name);
+
font_set->side = font_set->substitute[i].side;
if(parse_vw(oc, font_set, name_list, count) == -1)
goto err;
@@ -1237,11 +1223,10 @@ parse_fontname(
}
}
- base_name = (char *) Xmalloc(strlen(oc->core.base_name_list) + 1);
+ base_name = strdup(oc->core.base_name_list);
if (base_name == NULL)
goto err;
- strcpy(base_name, oc->core.base_name_list);
oc->core.base_name_list = base_name;
XFreeStringList(name_list);
@@ -1654,10 +1639,9 @@ create_oc(
XOCMethodsList methods_list = oc_methods_list;
int count;
- oc = (XOC) Xmalloc(sizeof(XOCGenericRec));
+ oc = Xcalloc(1, sizeof(XOCGenericRec));
if (oc == NULL)
return (XOC) NULL;
- bzero((char *) oc, sizeof(XOCGenericRec));
oc->core.om = om;
@@ -1842,26 +1826,23 @@ create_om(
{
XOM om;
- om = (XOM) Xmalloc(sizeof(XOMGenericRec));
+ om = Xcalloc(1, sizeof(XOMGenericRec));
if (om == NULL)
return (XOM) NULL;
- bzero((char *) om, sizeof(XOMGenericRec));
om->methods = &methods;
om->core.lcd = lcd;
om->core.display = dpy;
om->core.rdb = rdb;
if (res_name) {
- om->core.res_name = (char *) Xmalloc(strlen(res_name) + 1);
+ om->core.res_name = strdup(res_name);
if (om->core.res_name == NULL)
goto err;
- strcpy(om->core.res_name, res_name);
}
if (res_class) {
- om->core.res_class = (char *) Xmalloc(strlen(res_class) + 1);
+ om->core.res_class = strdup(res_class);
if (om->core.res_class == NULL)
goto err;
- strcpy(om->core.res_class, res_class);
}
if (om_resources[0].xrm_name == NULLQUARK)
@@ -1913,10 +1894,9 @@ read_EncodingInfo(
FontData font_data,ret;
char *buf, *bufptr,*scp;
int len;
- font_data = (FontData) Xmalloc(sizeof(FontDataRec) * count);
+ font_data = Xcalloc(count, sizeof(FontDataRec));
if (font_data == NULL)
return NULL;
- bzero((char *) font_data, sizeof(FontDataRec) * count);
ret = font_data;
for ( ; count-- > 0; font_data++) {
@@ -2017,10 +1997,9 @@ init_om(
_XlcGetResource(lcd, "XLC_FONTSET", "object_name", &value, &count);
if (count > 0) {
- gen->object_name = (char *) Xmalloc(strlen(*value) + 1);
+ gen->object_name = strdup(*value);
if (gen->object_name == NULL)
return False;
- strcpy(gen->object_name, *value);
}
for (num = 0; ; num++) {
diff --git a/libX11/specs/libX11/CH02.xml b/libX11/specs/libX11/CH02.xml
index a00b7c283..4912f71ed 100644
--- a/libX11/specs/libX11/CH02.xml
+++ b/libX11/specs/libX11/CH02.xml
@@ -66,17 +66,12 @@ To open a connection to the X server that controls a display, use
<function>XOpenDisplay</function>.
<indexterm significance="preferred"><primary>XOpenDisplay</primary></indexterm>
</para>
-<para>
-<!-- .LP -->
-<!-- .sM -->
-</para>
-<para>
-AllPlanes()
-</para>
-<para>
-XAllPlanes
-</para>
-
+<funcsynopsis>
+<funcprototype>
+ <funcdef>Display *<function>XOpenDisplay</function></funcdef>
+ <paramdef>char *<parameter>display_name</parameter></paramdef>
+</funcprototype>
+</funcsynopsis>
<variablelist>
<varlistentry>
<term>
diff --git a/libX11/src/FSWrap.c b/libX11/src/FSWrap.c
index c9c3867c1..f1629323c 100644
--- a/libX11/src/FSWrap.c
+++ b/libX11/src/FSWrap.c
@@ -85,10 +85,9 @@ _XParseBaseFontNameList(
if (!*str)
return (char **)NULL;
- if (!(ptr = Xmalloc((unsigned)strlen(str) + 1))) {
+ if (!(ptr = strdup(str))) {
return (char **)NULL;
}
- strcpy(ptr, str);
psave = ptr;
/* somebody who specifies more than XMAXLIST basefontnames will lose */
diff --git a/libX11/src/InitExt.c b/libX11/src/InitExt.c
index cb9191de6..8eca3e989 100644
--- a/libX11/src/InitExt.c
+++ b/libX11/src/InitExt.c
@@ -1,410 +1,409 @@
-/*
-
-Copyright 1987, 1998 The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from The Open Group.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/Xlibint.h>
-#include <X11/Xos.h>
-#include <stdio.h>
-
-/*
- * This routine is used to link a extension in so it will be called
- * at appropriate times.
- */
-
-XExtCodes *XInitExtension (
- Display *dpy,
- _Xconst char *name)
-{
- XExtCodes codes; /* temp. place for extension information. */
- register _XExtension *ext;/* need a place to build it all */
- if (!XQueryExtension(dpy, name,
- &codes.major_opcode, &codes.first_event,
- &codes.first_error)) return (NULL);
-
- LockDisplay (dpy);
- if (! (ext = (_XExtension *) Xcalloc (1, sizeof (_XExtension))) ||
- ! (ext->name = Xmalloc((unsigned) strlen(name) + 1))) {
- if (ext) Xfree((char *) ext);
- UnlockDisplay(dpy);
- return (XExtCodes *) NULL;
- }
- codes.extension = dpy->ext_number++;
- ext->codes = codes;
- (void) strcpy(ext->name, name);
-
- /* chain it onto the display list */
- ext->next = dpy->ext_procs;
- dpy->ext_procs = ext;
- UnlockDisplay (dpy);
-
- return (&ext->codes); /* tell him which extension */
-}
-
-XExtCodes *XAddExtension (Display *dpy)
-{
- register _XExtension *ext;
-
- LockDisplay (dpy);
- if (! (ext = (_XExtension *) Xcalloc (1, sizeof (_XExtension)))) {
- UnlockDisplay(dpy);
- return (XExtCodes *) NULL;
- }
- ext->codes.extension = dpy->ext_number++;
-
- /* chain it onto the display list */
- ext->next = dpy->ext_procs;
- dpy->ext_procs = ext;
- UnlockDisplay (dpy);
-
- return (&ext->codes); /* tell him which extension */
-}
-
-static _XExtension *XLookupExtension (
- register Display *dpy, /* display */
- register int extension) /* extension number */
-{
- register _XExtension *ext;
- for (ext = dpy->ext_procs; ext; ext = ext->next)
- if (ext->codes.extension == extension) return (ext);
- return (NULL);
-}
-
-XExtData **XEHeadOfExtensionList(XEDataObject object)
-{
- return *(XExtData ***)&object;
-}
-
-int
-XAddToExtensionList(
- XExtData **structure,
- XExtData *ext_data)
-{
- ext_data->next = *structure;
- *structure = ext_data;
- return 1;
-}
-
-XExtData *XFindOnExtensionList(
- XExtData **structure,
- int number)
-{
- XExtData *ext;
-
- ext = *structure;
- while (ext && (ext->number != number))
- ext = ext->next;
- return ext;
-}
-
-/*
- * Routines to hang procs on the extension structure.
- */
-CreateGCType XESetCreateGC(
- Display *dpy, /* display */
- int extension, /* extension number */
- CreateGCType proc) /* routine to call when GC created */
-{
- register _XExtension *e; /* for lookup of extension */
- register CreateGCType oldproc;
- if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL);
- LockDisplay(dpy);
- oldproc = e->create_GC;
- e->create_GC = proc;
- UnlockDisplay(dpy);
- return (CreateGCType)oldproc;
-}
-
-CopyGCType XESetCopyGC(
- Display *dpy, /* display */
- int extension, /* extension number */
- CopyGCType proc) /* routine to call when GC copied */
-{
- register _XExtension *e; /* for lookup of extension */
- register CopyGCType oldproc;
- if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL);
- LockDisplay(dpy);
- oldproc = e->copy_GC;
- e->copy_GC = proc;
- UnlockDisplay(dpy);
- return (CopyGCType)oldproc;
-}
-
-FlushGCType XESetFlushGC(
- Display *dpy, /* display */
- int extension, /* extension number */
- FlushGCType proc) /* routine to call when GC copied */
-{
- register _XExtension *e; /* for lookup of extension */
- register FlushGCType oldproc;
- if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL);
- LockDisplay(dpy);
- oldproc = e->flush_GC;
- e->flush_GC = proc;
- UnlockDisplay(dpy);
- return (FlushGCType)oldproc;
-}
-
-FreeGCType XESetFreeGC(
- Display *dpy, /* display */
- int extension, /* extension number */
- FreeGCType proc) /* routine to call when GC freed */
-{
- register _XExtension *e; /* for lookup of extension */
- register FreeGCType oldproc;
- if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL);
- LockDisplay(dpy);
- oldproc = e->free_GC;
- e->free_GC = proc;
- UnlockDisplay(dpy);
- return (FreeGCType)oldproc;
-}
-
-CreateFontType XESetCreateFont(
- Display *dpy, /* display */
- int extension, /* extension number */
- CreateFontType proc) /* routine to call when font created */
-{
- register _XExtension *e; /* for lookup of extension */
- register CreateFontType oldproc;
- if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL);
- LockDisplay(dpy);
- oldproc = e->create_Font;
- e->create_Font = proc;
- UnlockDisplay(dpy);
- return (CreateFontType)oldproc;
-}
-
-FreeFontType XESetFreeFont(
- Display *dpy, /* display */
- int extension, /* extension number */
- FreeFontType proc) /* routine to call when font freed */
-{
- register _XExtension *e; /* for lookup of extension */
- register FreeFontType oldproc;
- if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL);
- LockDisplay(dpy);
- oldproc = e->free_Font;
- e->free_Font = proc;
- UnlockDisplay(dpy);
- return (FreeFontType)oldproc;
-}
-
-CloseDisplayType XESetCloseDisplay(
- Display *dpy, /* display */
- int extension, /* extension number */
- CloseDisplayType proc) /* routine to call when display closed */
-{
- register _XExtension *e; /* for lookup of extension */
- register CloseDisplayType oldproc;
- if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL);
- LockDisplay(dpy);
- oldproc = e->close_display;
- e->close_display = proc;
- UnlockDisplay(dpy);
- return (CloseDisplayType)oldproc;
-}
-
-typedef Bool (*WireToEventType) (
- Display* /* display */,
- XEvent* /* re */,
- xEvent* /* event */
-);
-
-WireToEventType XESetWireToEvent(
- Display *dpy, /* display */
- int event_number, /* event routine to replace */
- WireToEventType proc) /* routine to call when converting event */
-{
- register WireToEventType oldproc;
- if (proc == NULL) proc = (WireToEventType)_XUnknownWireEvent;
- LockDisplay (dpy);
- oldproc = dpy->event_vec[event_number];
- dpy->event_vec[event_number] = proc;
- UnlockDisplay (dpy);
- return (WireToEventType)oldproc;
-}
-
-typedef Bool (*WireToEventCookieType) (
- Display* /* display */,
- XGenericEventCookie* /* re */,
- xEvent* /* event */
-);
-
-WireToEventCookieType XESetWireToEventCookie(
- Display *dpy, /* display */
- int extension, /* extension major opcode */
- WireToEventCookieType proc /* routine to call for generic events */
- )
-{
- WireToEventCookieType oldproc;
- if (proc == NULL) proc = (WireToEventCookieType)_XUnknownWireEventCookie;
- LockDisplay (dpy);
- oldproc = dpy->generic_event_vec[extension & 0x7F];
- dpy->generic_event_vec[extension & 0x7F] = proc;
- UnlockDisplay (dpy);
- return (WireToEventCookieType)oldproc;
-}
-
-typedef Bool (*CopyEventCookieType) (
- Display* /* display */,
- XGenericEventCookie* /* in */,
- XGenericEventCookie* /* out */
-);
-
-CopyEventCookieType XESetCopyEventCookie(
- Display *dpy, /* display */
- int extension, /* extension major opcode */
- CopyEventCookieType proc /* routine to copy generic events */
- )
-{
- CopyEventCookieType oldproc;
- if (proc == NULL) proc = (CopyEventCookieType)_XUnknownCopyEventCookie;
- LockDisplay (dpy);
- oldproc = dpy->generic_event_copy_vec[extension & 0x7F];
- dpy->generic_event_copy_vec[extension & 0x7F] = proc;
- UnlockDisplay (dpy);
- return (CopyEventCookieType)oldproc;
-}
-
-
-typedef Status (*EventToWireType) (
- Display* /* display */,
- XEvent* /* re */,
- xEvent* /* event */
-);
-
-EventToWireType XESetEventToWire(
- Display *dpy, /* display */
- int event_number, /* event routine to replace */
- EventToWireType proc) /* routine to call when converting event */
-{
- register EventToWireType oldproc;
- if (proc == NULL) proc = (EventToWireType) _XUnknownNativeEvent;
- LockDisplay (dpy);
- oldproc = dpy->wire_vec[event_number];
- dpy->wire_vec[event_number] = proc;
- UnlockDisplay(dpy);
- return (EventToWireType)oldproc;
-}
-
-typedef Bool (*WireToErrorType) (
- Display* /* display */,
- XErrorEvent* /* he */,
- xError* /* we */
-);
-
-WireToErrorType XESetWireToError(
- Display *dpy, /* display */
- int error_number, /* error routine to replace */
- WireToErrorType proc) /* routine to call when converting error */
-{
- register WireToErrorType oldproc = NULL;
- if (proc == NULL) proc = (WireToErrorType)_XDefaultWireError;
- LockDisplay (dpy);
- if (!dpy->error_vec) {
- int i;
- dpy->error_vec = Xmalloc(256 * sizeof(oldproc));
- for (i = 1; i < 256; i++)
- dpy->error_vec[i] = _XDefaultWireError;
- }
- if (dpy->error_vec) {
- oldproc = dpy->error_vec[error_number];
- dpy->error_vec[error_number] = proc;
- }
- UnlockDisplay (dpy);
- return (WireToErrorType)oldproc;
-}
-
-ErrorType XESetError(
- Display *dpy, /* display */
- int extension, /* extension number */
- ErrorType proc) /* routine to call when X error happens */
-{
- register _XExtension *e; /* for lookup of extension */
- register ErrorType oldproc;
- if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL);
- LockDisplay(dpy);
- oldproc = e->error;
- e->error = proc;
- UnlockDisplay(dpy);
- return (ErrorType)oldproc;
-}
-
-ErrorStringType XESetErrorString(
- Display *dpy, /* display */
- int extension, /* extension number */
- ErrorStringType proc) /* routine to call when I/O error happens */
-{
- register _XExtension *e; /* for lookup of extension */
- register ErrorStringType oldproc;
- if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL);
- LockDisplay(dpy);
- oldproc = e->error_string;
- e->error_string = proc;
- UnlockDisplay(dpy);
- return (ErrorStringType)oldproc;
-}
-
-PrintErrorType XESetPrintErrorValues(
- Display *dpy, /* display */
- int extension, /* extension number */
- PrintErrorType proc) /* routine to call to print */
-{
- register _XExtension *e; /* for lookup of extension */
- register PrintErrorType oldproc;
- if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL);
- LockDisplay(dpy);
- oldproc = e->error_values;
- e->error_values = proc;
- UnlockDisplay(dpy);
- return (PrintErrorType)oldproc;
-}
-
-BeforeFlushType XESetBeforeFlush(
- Display *dpy, /* display */
- int extension, /* extension number */
- BeforeFlushType proc) /* routine to call on flush */
-{
- register _XExtension *e; /* for lookup of extension */
- register BeforeFlushType oldproc;
- register _XExtension *ext;
- if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL);
- LockDisplay(dpy);
- oldproc = e->before_flush;
- e->before_flush = proc;
- for (ext = dpy->flushes; ext && ext != e; ext = ext->next)
- ;
- if (!ext) {
- e->next_flush = dpy->flushes;
- dpy->flushes = e;
- }
- UnlockDisplay(dpy);
- return (BeforeFlushType)oldproc;
-}
+/*
+
+Copyright 1987, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xlibint.h>
+#include <X11/Xos.h>
+#include <stdio.h>
+
+/*
+ * This routine is used to link a extension in so it will be called
+ * at appropriate times.
+ */
+
+XExtCodes *XInitExtension (
+ Display *dpy,
+ _Xconst char *name)
+{
+ XExtCodes codes; /* temp. place for extension information. */
+ register _XExtension *ext;/* need a place to build it all */
+ if (!XQueryExtension(dpy, name,
+ &codes.major_opcode, &codes.first_event,
+ &codes.first_error)) return (NULL);
+
+ LockDisplay (dpy);
+ if (! (ext = (_XExtension *) Xcalloc (1, sizeof (_XExtension))) ||
+ ! (ext->name = strdup(name))) {
+ if (ext) Xfree((char *) ext);
+ UnlockDisplay(dpy);
+ return (XExtCodes *) NULL;
+ }
+ codes.extension = dpy->ext_number++;
+ ext->codes = codes;
+
+ /* chain it onto the display list */
+ ext->next = dpy->ext_procs;
+ dpy->ext_procs = ext;
+ UnlockDisplay (dpy);
+
+ return (&ext->codes); /* tell him which extension */
+}
+
+XExtCodes *XAddExtension (Display *dpy)
+{
+ register _XExtension *ext;
+
+ LockDisplay (dpy);
+ if (! (ext = (_XExtension *) Xcalloc (1, sizeof (_XExtension)))) {
+ UnlockDisplay(dpy);
+ return (XExtCodes *) NULL;
+ }
+ ext->codes.extension = dpy->ext_number++;
+
+ /* chain it onto the display list */
+ ext->next = dpy->ext_procs;
+ dpy->ext_procs = ext;
+ UnlockDisplay (dpy);
+
+ return (&ext->codes); /* tell him which extension */
+}
+
+static _XExtension *XLookupExtension (
+ register Display *dpy, /* display */
+ register int extension) /* extension number */
+{
+ register _XExtension *ext;
+ for (ext = dpy->ext_procs; ext; ext = ext->next)
+ if (ext->codes.extension == extension) return (ext);
+ return (NULL);
+}
+
+XExtData **XEHeadOfExtensionList(XEDataObject object)
+{
+ return *(XExtData ***)&object;
+}
+
+int
+XAddToExtensionList(
+ XExtData **structure,
+ XExtData *ext_data)
+{
+ ext_data->next = *structure;
+ *structure = ext_data;
+ return 1;
+}
+
+XExtData *XFindOnExtensionList(
+ XExtData **structure,
+ int number)
+{
+ XExtData *ext;
+
+ ext = *structure;
+ while (ext && (ext->number != number))
+ ext = ext->next;
+ return ext;
+}
+
+/*
+ * Routines to hang procs on the extension structure.
+ */
+CreateGCType XESetCreateGC(
+ Display *dpy, /* display */
+ int extension, /* extension number */
+ CreateGCType proc) /* routine to call when GC created */
+{
+ register _XExtension *e; /* for lookup of extension */
+ register CreateGCType oldproc;
+ if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL);
+ LockDisplay(dpy);
+ oldproc = e->create_GC;
+ e->create_GC = proc;
+ UnlockDisplay(dpy);
+ return (CreateGCType)oldproc;
+}
+
+CopyGCType XESetCopyGC(
+ Display *dpy, /* display */
+ int extension, /* extension number */
+ CopyGCType proc) /* routine to call when GC copied */
+{
+ register _XExtension *e; /* for lookup of extension */
+ register CopyGCType oldproc;
+ if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL);
+ LockDisplay(dpy);
+ oldproc = e->copy_GC;
+ e->copy_GC = proc;
+ UnlockDisplay(dpy);
+ return (CopyGCType)oldproc;
+}
+
+FlushGCType XESetFlushGC(
+ Display *dpy, /* display */
+ int extension, /* extension number */
+ FlushGCType proc) /* routine to call when GC copied */
+{
+ register _XExtension *e; /* for lookup of extension */
+ register FlushGCType oldproc;
+ if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL);
+ LockDisplay(dpy);
+ oldproc = e->flush_GC;
+ e->flush_GC = proc;
+ UnlockDisplay(dpy);
+ return (FlushGCType)oldproc;
+}
+
+FreeGCType XESetFreeGC(
+ Display *dpy, /* display */
+ int extension, /* extension number */
+ FreeGCType proc) /* routine to call when GC freed */
+{
+ register _XExtension *e; /* for lookup of extension */
+ register FreeGCType oldproc;
+ if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL);
+ LockDisplay(dpy);
+ oldproc = e->free_GC;
+ e->free_GC = proc;
+ UnlockDisplay(dpy);
+ return (FreeGCType)oldproc;
+}
+
+CreateFontType XESetCreateFont(
+ Display *dpy, /* display */
+ int extension, /* extension number */
+ CreateFontType proc) /* routine to call when font created */
+{
+ register _XExtension *e; /* for lookup of extension */
+ register CreateFontType oldproc;
+ if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL);
+ LockDisplay(dpy);
+ oldproc = e->create_Font;
+ e->create_Font = proc;
+ UnlockDisplay(dpy);
+ return (CreateFontType)oldproc;
+}
+
+FreeFontType XESetFreeFont(
+ Display *dpy, /* display */
+ int extension, /* extension number */
+ FreeFontType proc) /* routine to call when font freed */
+{
+ register _XExtension *e; /* for lookup of extension */
+ register FreeFontType oldproc;
+ if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL);
+ LockDisplay(dpy);
+ oldproc = e->free_Font;
+ e->free_Font = proc;
+ UnlockDisplay(dpy);
+ return (FreeFontType)oldproc;
+}
+
+CloseDisplayType XESetCloseDisplay(
+ Display *dpy, /* display */
+ int extension, /* extension number */
+ CloseDisplayType proc) /* routine to call when display closed */
+{
+ register _XExtension *e; /* for lookup of extension */
+ register CloseDisplayType oldproc;
+ if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL);
+ LockDisplay(dpy);
+ oldproc = e->close_display;
+ e->close_display = proc;
+ UnlockDisplay(dpy);
+ return (CloseDisplayType)oldproc;
+}
+
+typedef Bool (*WireToEventType) (
+ Display* /* display */,
+ XEvent* /* re */,
+ xEvent* /* event */
+);
+
+WireToEventType XESetWireToEvent(
+ Display *dpy, /* display */
+ int event_number, /* event routine to replace */
+ WireToEventType proc) /* routine to call when converting event */
+{
+ register WireToEventType oldproc;
+ if (proc == NULL) proc = (WireToEventType)_XUnknownWireEvent;
+ LockDisplay (dpy);
+ oldproc = dpy->event_vec[event_number];
+ dpy->event_vec[event_number] = proc;
+ UnlockDisplay (dpy);
+ return (WireToEventType)oldproc;
+}
+
+typedef Bool (*WireToEventCookieType) (
+ Display* /* display */,
+ XGenericEventCookie* /* re */,
+ xEvent* /* event */
+);
+
+WireToEventCookieType XESetWireToEventCookie(
+ Display *dpy, /* display */
+ int extension, /* extension major opcode */
+ WireToEventCookieType proc /* routine to call for generic events */
+ )
+{
+ WireToEventCookieType oldproc;
+ if (proc == NULL) proc = (WireToEventCookieType)_XUnknownWireEventCookie;
+ LockDisplay (dpy);
+ oldproc = dpy->generic_event_vec[extension & 0x7F];
+ dpy->generic_event_vec[extension & 0x7F] = proc;
+ UnlockDisplay (dpy);
+ return (WireToEventCookieType)oldproc;
+}
+
+typedef Bool (*CopyEventCookieType) (
+ Display* /* display */,
+ XGenericEventCookie* /* in */,
+ XGenericEventCookie* /* out */
+);
+
+CopyEventCookieType XESetCopyEventCookie(
+ Display *dpy, /* display */
+ int extension, /* extension major opcode */
+ CopyEventCookieType proc /* routine to copy generic events */
+ )
+{
+ CopyEventCookieType oldproc;
+ if (proc == NULL) proc = (CopyEventCookieType)_XUnknownCopyEventCookie;
+ LockDisplay (dpy);
+ oldproc = dpy->generic_event_copy_vec[extension & 0x7F];
+ dpy->generic_event_copy_vec[extension & 0x7F] = proc;
+ UnlockDisplay (dpy);
+ return (CopyEventCookieType)oldproc;
+}
+
+
+typedef Status (*EventToWireType) (
+ Display* /* display */,
+ XEvent* /* re */,
+ xEvent* /* event */
+);
+
+EventToWireType XESetEventToWire(
+ Display *dpy, /* display */
+ int event_number, /* event routine to replace */
+ EventToWireType proc) /* routine to call when converting event */
+{
+ register EventToWireType oldproc;
+ if (proc == NULL) proc = (EventToWireType) _XUnknownNativeEvent;
+ LockDisplay (dpy);
+ oldproc = dpy->wire_vec[event_number];
+ dpy->wire_vec[event_number] = proc;
+ UnlockDisplay(dpy);
+ return (EventToWireType)oldproc;
+}
+
+typedef Bool (*WireToErrorType) (
+ Display* /* display */,
+ XErrorEvent* /* he */,
+ xError* /* we */
+);
+
+WireToErrorType XESetWireToError(
+ Display *dpy, /* display */
+ int error_number, /* error routine to replace */
+ WireToErrorType proc) /* routine to call when converting error */
+{
+ register WireToErrorType oldproc = NULL;
+ if (proc == NULL) proc = (WireToErrorType)_XDefaultWireError;
+ LockDisplay (dpy);
+ if (!dpy->error_vec) {
+ int i;
+ dpy->error_vec = Xmalloc(256 * sizeof(oldproc));
+ for (i = 1; i < 256; i++)
+ dpy->error_vec[i] = _XDefaultWireError;
+ }
+ if (dpy->error_vec) {
+ oldproc = dpy->error_vec[error_number];
+ dpy->error_vec[error_number] = proc;
+ }
+ UnlockDisplay (dpy);
+ return (WireToErrorType)oldproc;
+}
+
+ErrorType XESetError(
+ Display *dpy, /* display */
+ int extension, /* extension number */
+ ErrorType proc) /* routine to call when X error happens */
+{
+ register _XExtension *e; /* for lookup of extension */
+ register ErrorType oldproc;
+ if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL);
+ LockDisplay(dpy);
+ oldproc = e->error;
+ e->error = proc;
+ UnlockDisplay(dpy);
+ return (ErrorType)oldproc;
+}
+
+ErrorStringType XESetErrorString(
+ Display *dpy, /* display */
+ int extension, /* extension number */
+ ErrorStringType proc) /* routine to call when I/O error happens */
+{
+ register _XExtension *e; /* for lookup of extension */
+ register ErrorStringType oldproc;
+ if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL);
+ LockDisplay(dpy);
+ oldproc = e->error_string;
+ e->error_string = proc;
+ UnlockDisplay(dpy);
+ return (ErrorStringType)oldproc;
+}
+
+PrintErrorType XESetPrintErrorValues(
+ Display *dpy, /* display */
+ int extension, /* extension number */
+ PrintErrorType proc) /* routine to call to print */
+{
+ register _XExtension *e; /* for lookup of extension */
+ register PrintErrorType oldproc;
+ if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL);
+ LockDisplay(dpy);
+ oldproc = e->error_values;
+ e->error_values = proc;
+ UnlockDisplay(dpy);
+ return (PrintErrorType)oldproc;
+}
+
+BeforeFlushType XESetBeforeFlush(
+ Display *dpy, /* display */
+ int extension, /* extension number */
+ BeforeFlushType proc) /* routine to call on flush */
+{
+ register _XExtension *e; /* for lookup of extension */
+ register BeforeFlushType oldproc;
+ register _XExtension *ext;
+ if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL);
+ LockDisplay(dpy);
+ oldproc = e->before_flush;
+ e->before_flush = proc;
+ for (ext = dpy->flushes; ext && ext != e; ext = ext->next)
+ ;
+ if (!ext) {
+ e->next_flush = dpy->flushes;
+ dpy->flushes = e;
+ }
+ UnlockDisplay(dpy);
+ return (BeforeFlushType)oldproc;
+}
diff --git a/libX11/src/Quarks.c b/libX11/src/Quarks.c
index d0eb69018..aa64392f6 100644
--- a/libX11/src/Quarks.c
+++ b/libX11/src/Quarks.c
@@ -1,414 +1,413 @@
-
-/***********************************************************
-Copyright 1987, 1988, 1990 by Digital Equipment Corporation, Maynard,
-
- All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and its
-documentation for any purpose and without fee is hereby granted,
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in
-supporting documentation, and that the name Digital not be
-used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.
-
-DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
-ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
-ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
-SOFTWARE.
-
-******************************************************************/
-/*
-
-Copyright 1987, 1988, 1990, 1998 The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from The Open Group.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include <X11/Xresource.h>
-#include "Xresinternal.h"
-
-/* Not cost effective, at least for vanilla MIT clients */
-/* #define PERMQ */
-
-#ifdef PERMQ
-typedef unsigned char Bits;
-#endif
-typedef unsigned long Entry; /* dont confuse with EntryRec from Xintatom.h */
-
-static XrmQuark nextQuark = 1; /* next available quark number */
-static unsigned long quarkMask = 0;
-static Entry zero = 0;
-static Entry *quarkTable = &zero; /* crock */
-static unsigned long quarkRehash;
-static XrmString **stringTable = NULL;
-#ifdef PERMQ
-static Bits **permTable = NULL;
-#endif
-static XrmQuark nextUniq = -1; /* next quark from XrmUniqueQuark */
-
-#define QUANTUMSHIFT 8
-#define QUANTUMMASK ((1 << QUANTUMSHIFT) - 1)
-#define CHUNKPER 8
-#define CHUNKMASK ((CHUNKPER << QUANTUMSHIFT) - 1)
-
-#define LARGEQUARK ((Entry)0x80000000L)
-#define QUARKSHIFT 18
-#define QUARKMASK ((LARGEQUARK - 1) >> QUARKSHIFT)
-#define XSIGMASK ((1L << QUARKSHIFT) - 1)
-
-#define STRQUANTSIZE (sizeof(XrmString) * (QUANTUMMASK + 1))
-#ifdef PERMQ
-#define QUANTSIZE (STRQUANTSIZE + \
- (sizeof(Bits) * ((QUANTUMMASK + 1) >> 3))
-#else
-#define QUANTSIZE STRQUANTSIZE
-#endif
-
-#define HASH(sig) ((sig) & quarkMask)
-#define REHASHVAL(sig) ((((sig) % quarkRehash) + 2) | 1)
-#define REHASH(idx,rehash) ((idx + rehash) & quarkMask)
-#define NAME(q) stringTable[(q) >> QUANTUMSHIFT][(q) & QUANTUMMASK]
-#ifdef PERMQ
-#define BYTEREF(q) permTable[(q) >> QUANTUMSHIFT][((q) & QUANTUMMASK) >> 3]
-#define ISPERM(q) (BYTEREF(q) & (1 << ((q) & 7)))
-#define SETPERM(q) BYTEREF(q) |= (1 << ((q) & 7))
-#define CLEARPERM(q) BYTEREF(q) &= ~(1 << ((q) & 7))
-#endif
-
-/* Permanent memory allocation */
-
-#define WALIGN sizeof(unsigned long)
-#define DALIGN sizeof(double)
-
-#define NEVERFREETABLESIZE ((8192-12) & ~(DALIGN-1))
-static char *neverFreeTable = NULL;
-static int neverFreeTableSize = 0;
-
-static char *permalloc(unsigned int length)
-{
- char *ret;
-
- if (neverFreeTableSize < length) {
- if (length >= NEVERFREETABLESIZE)
- return Xmalloc(length);
- if (! (ret = Xmalloc(NEVERFREETABLESIZE)))
- return (char *) NULL;
- neverFreeTableSize = NEVERFREETABLESIZE;
- neverFreeTable = ret;
- }
- ret = neverFreeTable;
- neverFreeTable += length;
- neverFreeTableSize -= length;
- return(ret);
-}
-
-#ifndef WORD64
-typedef struct {char a; double b;} TestType1;
-typedef struct {char a; unsigned long b;} TestType2;
-#endif
-
-#ifdef XTHREADS
-static char *_Xpermalloc(unsigned int length);
-
-char *Xpermalloc(unsigned int length)
-{
- char *p;
-
- _XLockMutex(_Xglobal_lock);
- p = _Xpermalloc(length);
- _XUnlockMutex(_Xglobal_lock);
- return p;
-}
-#define Xpermalloc _Xpermalloc
-
-static
-#endif /* XTHREADS */
-char *Xpermalloc(unsigned int length)
-{
- int i;
-
- if (neverFreeTableSize && length < NEVERFREETABLESIZE) {
-#ifndef WORD64
- if ((sizeof(TestType1) !=
- (sizeof(TestType2) - sizeof(unsigned long) + sizeof(double))) &&
- !(length & (DALIGN-1)) &&
- ((i = (NEVERFREETABLESIZE - neverFreeTableSize) & (DALIGN-1)))) {
- neverFreeTableSize -= DALIGN - i;
- neverFreeTable += DALIGN - i;
- } else
-#endif
- if ((i = (NEVERFREETABLESIZE - neverFreeTableSize) & (WALIGN-1))) {
- neverFreeTableSize -= WALIGN - i;
- neverFreeTable += WALIGN - i;
- }
- }
- return permalloc(length);
-}
-
-static Bool
-ExpandQuarkTable(void)
-{
- unsigned long oldmask, newmask;
- register char c, *s;
- register Entry *oldentries, *entries;
- register Entry entry;
- register int oldidx, newidx, rehash;
- Signature sig;
- XrmQuark q;
-
- oldentries = quarkTable;
- if ((oldmask = quarkMask))
- newmask = (oldmask << 1) + 1;
- else {
- if (!stringTable) {
- stringTable = (XrmString **)Xmalloc(sizeof(XrmString *) *
- CHUNKPER);
- if (!stringTable)
- return False;
- stringTable[0] = (XrmString *)NULL;
- }
-#ifdef PERMQ
- if (!permTable)
- permTable = (Bits **)Xmalloc(sizeof(Bits *) * CHUNKPER);
- if (!permTable)
- return False;
-#endif
- stringTable[0] = (XrmString *)Xpermalloc(QUANTSIZE);
- if (!stringTable[0])
- return False;
-#ifdef PERMQ
- permTable[0] = (Bits *)((char *)stringTable[0] + STRQUANTSIZE);
-#endif
- newmask = 0x1ff;
- }
- entries = (Entry *)Xmalloc(sizeof(Entry) * (newmask + 1));
- if (!entries)
- return False;
- bzero((char *)entries, sizeof(Entry) * (newmask + 1));
- quarkTable = entries;
- quarkMask = newmask;
- quarkRehash = quarkMask - 2;
- for (oldidx = 0; oldidx <= oldmask; oldidx++) {
- if ((entry = oldentries[oldidx])) {
- if (entry & LARGEQUARK)
- q = entry & (LARGEQUARK-1);
- else
- q = (entry >> QUARKSHIFT) & QUARKMASK;
- for (sig = 0, s = NAME(q); (c = *s++); )
- sig = (sig << 1) + c;
- newidx = HASH(sig);
- if (entries[newidx]) {
- rehash = REHASHVAL(sig);
- do {
- newidx = REHASH(newidx, rehash);
- } while (entries[newidx]);
- }
- entries[newidx] = entry;
- }
- }
- if (oldmask)
- Xfree((char *)oldentries);
- return True;
-}
-
-XrmQuark
-_XrmInternalStringToQuark(
- register _Xconst char *name, register int len, register Signature sig,
- Bool permstring)
-{
- register XrmQuark q;
- register Entry entry;
- register int idx, rehash;
- register int i;
- register char *s1, *s2;
- char *new;
-
- rehash = 0;
- idx = HASH(sig);
- _XLockMutex(_Xglobal_lock);
- while ((entry = quarkTable[idx])) {
- if (entry & LARGEQUARK)
- q = entry & (LARGEQUARK-1);
- else {
- if ((entry - sig) & XSIGMASK)
- goto nomatch;
- q = (entry >> QUARKSHIFT) & QUARKMASK;
- }
- for (i = len, s1 = (char *)name, s2 = NAME(q); --i >= 0; ) {
- if (*s1++ != *s2++)
- goto nomatch;
- }
- if (*s2) {
-nomatch: if (!rehash)
- rehash = REHASHVAL(sig);
- idx = REHASH(idx, rehash);
- continue;
- }
-#ifdef PERMQ
- if (permstring && !ISPERM(q)) {
- Xfree(NAME(q));
- NAME(q) = (char *)name;
- SETPERM(q);
- }
-#endif
- _XUnlockMutex(_Xglobal_lock);
- return q;
- }
- if (nextUniq == nextQuark)
- goto fail;
- if ((nextQuark + (nextQuark >> 2)) > quarkMask) {
- if (!ExpandQuarkTable())
- goto fail;
- _XUnlockMutex(_Xglobal_lock);
- return _XrmInternalStringToQuark(name, len, sig, permstring);
- }
- q = nextQuark;
- if (!(q & QUANTUMMASK)) {
- if (!(q & CHUNKMASK)) {
- if (!(new = Xrealloc((char *)stringTable,
- sizeof(XrmString *) *
- ((q >> QUANTUMSHIFT) + CHUNKPER))))
- goto fail;
- stringTable = (XrmString **)new;
-#ifdef PERMQ
- if (!(new = Xrealloc((char *)permTable,
- sizeof(Bits *) *
- ((q >> QUANTUMSHIFT) + CHUNKPER))))
- goto fail;
- permTable = (Bits **)new;
-#endif
- }
- new = Xpermalloc(QUANTSIZE);
- if (!new)
- goto fail;
- stringTable[q >> QUANTUMSHIFT] = (XrmString *)new;
-#ifdef PERMQ
- permTable[q >> QUANTUMSHIFT] = (Bits *)(new + STRQUANTSIZE);
-#endif
- }
- if (!permstring) {
- s2 = (char *)name;
-#ifdef PERMQ
- name = Xmalloc(len+1);
-#else
- name = permalloc(len+1);
-#endif
- if (!name)
- goto fail;
- for (i = len, s1 = (char *)name; --i >= 0; )
- *s1++ = *s2++;
- *s1++ = '\0';
-#ifdef PERMQ
- CLEARPERM(q);
- }
- else {
- SETPERM(q);
-#endif
- }
- NAME(q) = (char *)name;
- if (q <= QUARKMASK)
- entry = (q << QUARKSHIFT) | (sig & XSIGMASK);
- else
- entry = q | LARGEQUARK;
- quarkTable[idx] = entry;
- nextQuark++;
- _XUnlockMutex(_Xglobal_lock);
- return q;
- fail:
- _XUnlockMutex(_Xglobal_lock);
- return NULLQUARK;
-}
-
-XrmQuark
-XrmStringToQuark(
- _Xconst char *name)
-{
- register char c, *tname;
- register Signature sig = 0;
-
- if (!name)
- return (NULLQUARK);
-
- for (tname = (char *)name; (c = *tname++); )
- sig = (sig << 1) + c;
-
- return _XrmInternalStringToQuark(name, tname-(char *)name-1, sig, False);
-}
-
-XrmQuark
-XrmPermStringToQuark(
- _Xconst char *name)
-{
- register char c, *tname;
- register Signature sig = 0;
-
- if (!name)
- return (NULLQUARK);
-
- for (tname = (char *)name; (c = *tname++); )
- sig = (sig << 1) + c;
-
- return _XrmInternalStringToQuark(name, tname-(char *)name-1, sig, True);
-}
-
-XrmQuark XrmUniqueQuark(void)
-{
- XrmQuark q;
-
- _XLockMutex(_Xglobal_lock);
- if (nextUniq == nextQuark)
- q = NULLQUARK;
- else
- q = nextUniq--;
- _XUnlockMutex(_Xglobal_lock);
- return q;
-}
-
-XrmString XrmQuarkToString(register XrmQuark quark)
-{
- XrmString s;
-
- _XLockMutex(_Xglobal_lock);
- if (quark <= 0 || quark >= nextQuark)
- s = NULLSTRING;
- else {
-#ifdef PERMQ
- /* We have to mark the quark as permanent, since the caller might hold
- * onto the string pointer forver.
- */
- SETPERM(quark);
-#endif
- s = NAME(quark);
- }
- _XUnlockMutex(_Xglobal_lock);
- return s;
-}
+
+/***********************************************************
+Copyright 1987, 1988, 1990 by Digital Equipment Corporation, Maynard,
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+/*
+
+Copyright 1987, 1988, 1990, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include <X11/Xresource.h>
+#include "Xresinternal.h"
+
+/* Not cost effective, at least for vanilla MIT clients */
+/* #define PERMQ */
+
+#ifdef PERMQ
+typedef unsigned char Bits;
+#endif
+typedef unsigned long Entry; /* dont confuse with EntryRec from Xintatom.h */
+
+static XrmQuark nextQuark = 1; /* next available quark number */
+static unsigned long quarkMask = 0;
+static Entry zero = 0;
+static Entry *quarkTable = &zero; /* crock */
+static unsigned long quarkRehash;
+static XrmString **stringTable = NULL;
+#ifdef PERMQ
+static Bits **permTable = NULL;
+#endif
+static XrmQuark nextUniq = -1; /* next quark from XrmUniqueQuark */
+
+#define QUANTUMSHIFT 8
+#define QUANTUMMASK ((1 << QUANTUMSHIFT) - 1)
+#define CHUNKPER 8
+#define CHUNKMASK ((CHUNKPER << QUANTUMSHIFT) - 1)
+
+#define LARGEQUARK ((Entry)0x80000000L)
+#define QUARKSHIFT 18
+#define QUARKMASK ((LARGEQUARK - 1) >> QUARKSHIFT)
+#define XSIGMASK ((1L << QUARKSHIFT) - 1)
+
+#define STRQUANTSIZE (sizeof(XrmString) * (QUANTUMMASK + 1))
+#ifdef PERMQ
+#define QUANTSIZE (STRQUANTSIZE + \
+ (sizeof(Bits) * ((QUANTUMMASK + 1) >> 3))
+#else
+#define QUANTSIZE STRQUANTSIZE
+#endif
+
+#define HASH(sig) ((sig) & quarkMask)
+#define REHASHVAL(sig) ((((sig) % quarkRehash) + 2) | 1)
+#define REHASH(idx,rehash) ((idx + rehash) & quarkMask)
+#define NAME(q) stringTable[(q) >> QUANTUMSHIFT][(q) & QUANTUMMASK]
+#ifdef PERMQ
+#define BYTEREF(q) permTable[(q) >> QUANTUMSHIFT][((q) & QUANTUMMASK) >> 3]
+#define ISPERM(q) (BYTEREF(q) & (1 << ((q) & 7)))
+#define SETPERM(q) BYTEREF(q) |= (1 << ((q) & 7))
+#define CLEARPERM(q) BYTEREF(q) &= ~(1 << ((q) & 7))
+#endif
+
+/* Permanent memory allocation */
+
+#define WALIGN sizeof(unsigned long)
+#define DALIGN sizeof(double)
+
+#define NEVERFREETABLESIZE ((8192-12) & ~(DALIGN-1))
+static char *neverFreeTable = NULL;
+static int neverFreeTableSize = 0;
+
+static char *permalloc(unsigned int length)
+{
+ char *ret;
+
+ if (neverFreeTableSize < length) {
+ if (length >= NEVERFREETABLESIZE)
+ return Xmalloc(length);
+ if (! (ret = Xmalloc(NEVERFREETABLESIZE)))
+ return (char *) NULL;
+ neverFreeTableSize = NEVERFREETABLESIZE;
+ neverFreeTable = ret;
+ }
+ ret = neverFreeTable;
+ neverFreeTable += length;
+ neverFreeTableSize -= length;
+ return(ret);
+}
+
+#ifndef WORD64
+typedef struct {char a; double b;} TestType1;
+typedef struct {char a; unsigned long b;} TestType2;
+#endif
+
+#ifdef XTHREADS
+static char *_Xpermalloc(unsigned int length);
+
+char *Xpermalloc(unsigned int length)
+{
+ char *p;
+
+ _XLockMutex(_Xglobal_lock);
+ p = _Xpermalloc(length);
+ _XUnlockMutex(_Xglobal_lock);
+ return p;
+}
+#define Xpermalloc _Xpermalloc
+
+static
+#endif /* XTHREADS */
+char *Xpermalloc(unsigned int length)
+{
+ int i;
+
+ if (neverFreeTableSize && length < NEVERFREETABLESIZE) {
+#ifndef WORD64
+ if ((sizeof(TestType1) !=
+ (sizeof(TestType2) - sizeof(unsigned long) + sizeof(double))) &&
+ !(length & (DALIGN-1)) &&
+ ((i = (NEVERFREETABLESIZE - neverFreeTableSize) & (DALIGN-1)))) {
+ neverFreeTableSize -= DALIGN - i;
+ neverFreeTable += DALIGN - i;
+ } else
+#endif
+ if ((i = (NEVERFREETABLESIZE - neverFreeTableSize) & (WALIGN-1))) {
+ neverFreeTableSize -= WALIGN - i;
+ neverFreeTable += WALIGN - i;
+ }
+ }
+ return permalloc(length);
+}
+
+static Bool
+ExpandQuarkTable(void)
+{
+ unsigned long oldmask, newmask;
+ register char c, *s;
+ register Entry *oldentries, *entries;
+ register Entry entry;
+ register int oldidx, newidx, rehash;
+ Signature sig;
+ XrmQuark q;
+
+ oldentries = quarkTable;
+ if ((oldmask = quarkMask))
+ newmask = (oldmask << 1) + 1;
+ else {
+ if (!stringTable) {
+ stringTable = (XrmString **)Xmalloc(sizeof(XrmString *) *
+ CHUNKPER);
+ if (!stringTable)
+ return False;
+ stringTable[0] = (XrmString *)NULL;
+ }
+#ifdef PERMQ
+ if (!permTable)
+ permTable = (Bits **)Xmalloc(sizeof(Bits *) * CHUNKPER);
+ if (!permTable)
+ return False;
+#endif
+ stringTable[0] = (XrmString *)Xpermalloc(QUANTSIZE);
+ if (!stringTable[0])
+ return False;
+#ifdef PERMQ
+ permTable[0] = (Bits *)((char *)stringTable[0] + STRQUANTSIZE);
+#endif
+ newmask = 0x1ff;
+ }
+ entries = Xcalloc(newmask + 1, sizeof(Entry));
+ if (!entries)
+ return False;
+ quarkTable = entries;
+ quarkMask = newmask;
+ quarkRehash = quarkMask - 2;
+ for (oldidx = 0; oldidx <= oldmask; oldidx++) {
+ if ((entry = oldentries[oldidx])) {
+ if (entry & LARGEQUARK)
+ q = entry & (LARGEQUARK-1);
+ else
+ q = (entry >> QUARKSHIFT) & QUARKMASK;
+ for (sig = 0, s = NAME(q); (c = *s++); )
+ sig = (sig << 1) + c;
+ newidx = HASH(sig);
+ if (entries[newidx]) {
+ rehash = REHASHVAL(sig);
+ do {
+ newidx = REHASH(newidx, rehash);
+ } while (entries[newidx]);
+ }
+ entries[newidx] = entry;
+ }
+ }
+ if (oldmask)
+ Xfree((char *)oldentries);
+ return True;
+}
+
+XrmQuark
+_XrmInternalStringToQuark(
+ register _Xconst char *name, register int len, register Signature sig,
+ Bool permstring)
+{
+ register XrmQuark q;
+ register Entry entry;
+ register int idx, rehash;
+ register int i;
+ register char *s1, *s2;
+ char *new;
+
+ rehash = 0;
+ idx = HASH(sig);
+ _XLockMutex(_Xglobal_lock);
+ while ((entry = quarkTable[idx])) {
+ if (entry & LARGEQUARK)
+ q = entry & (LARGEQUARK-1);
+ else {
+ if ((entry - sig) & XSIGMASK)
+ goto nomatch;
+ q = (entry >> QUARKSHIFT) & QUARKMASK;
+ }
+ for (i = len, s1 = (char *)name, s2 = NAME(q); --i >= 0; ) {
+ if (*s1++ != *s2++)
+ goto nomatch;
+ }
+ if (*s2) {
+nomatch: if (!rehash)
+ rehash = REHASHVAL(sig);
+ idx = REHASH(idx, rehash);
+ continue;
+ }
+#ifdef PERMQ
+ if (permstring && !ISPERM(q)) {
+ Xfree(NAME(q));
+ NAME(q) = (char *)name;
+ SETPERM(q);
+ }
+#endif
+ _XUnlockMutex(_Xglobal_lock);
+ return q;
+ }
+ if (nextUniq == nextQuark)
+ goto fail;
+ if ((nextQuark + (nextQuark >> 2)) > quarkMask) {
+ if (!ExpandQuarkTable())
+ goto fail;
+ _XUnlockMutex(_Xglobal_lock);
+ return _XrmInternalStringToQuark(name, len, sig, permstring);
+ }
+ q = nextQuark;
+ if (!(q & QUANTUMMASK)) {
+ if (!(q & CHUNKMASK)) {
+ if (!(new = Xrealloc((char *)stringTable,
+ sizeof(XrmString *) *
+ ((q >> QUANTUMSHIFT) + CHUNKPER))))
+ goto fail;
+ stringTable = (XrmString **)new;
+#ifdef PERMQ
+ if (!(new = Xrealloc((char *)permTable,
+ sizeof(Bits *) *
+ ((q >> QUANTUMSHIFT) + CHUNKPER))))
+ goto fail;
+ permTable = (Bits **)new;
+#endif
+ }
+ new = Xpermalloc(QUANTSIZE);
+ if (!new)
+ goto fail;
+ stringTable[q >> QUANTUMSHIFT] = (XrmString *)new;
+#ifdef PERMQ
+ permTable[q >> QUANTUMSHIFT] = (Bits *)(new + STRQUANTSIZE);
+#endif
+ }
+ if (!permstring) {
+ s2 = (char *)name;
+#ifdef PERMQ
+ name = Xmalloc(len+1);
+#else
+ name = permalloc(len+1);
+#endif
+ if (!name)
+ goto fail;
+ for (i = len, s1 = (char *)name; --i >= 0; )
+ *s1++ = *s2++;
+ *s1++ = '\0';
+#ifdef PERMQ
+ CLEARPERM(q);
+ }
+ else {
+ SETPERM(q);
+#endif
+ }
+ NAME(q) = (char *)name;
+ if (q <= QUARKMASK)
+ entry = (q << QUARKSHIFT) | (sig & XSIGMASK);
+ else
+ entry = q | LARGEQUARK;
+ quarkTable[idx] = entry;
+ nextQuark++;
+ _XUnlockMutex(_Xglobal_lock);
+ return q;
+ fail:
+ _XUnlockMutex(_Xglobal_lock);
+ return NULLQUARK;
+}
+
+XrmQuark
+XrmStringToQuark(
+ _Xconst char *name)
+{
+ register char c, *tname;
+ register Signature sig = 0;
+
+ if (!name)
+ return (NULLQUARK);
+
+ for (tname = (char *)name; (c = *tname++); )
+ sig = (sig << 1) + c;
+
+ return _XrmInternalStringToQuark(name, tname-(char *)name-1, sig, False);
+}
+
+XrmQuark
+XrmPermStringToQuark(
+ _Xconst char *name)
+{
+ register char c, *tname;
+ register Signature sig = 0;
+
+ if (!name)
+ return (NULLQUARK);
+
+ for (tname = (char *)name; (c = *tname++); )
+ sig = (sig << 1) + c;
+
+ return _XrmInternalStringToQuark(name, tname-(char *)name-1, sig, True);
+}
+
+XrmQuark XrmUniqueQuark(void)
+{
+ XrmQuark q;
+
+ _XLockMutex(_Xglobal_lock);
+ if (nextUniq == nextQuark)
+ q = NULLQUARK;
+ else
+ q = nextUniq--;
+ _XUnlockMutex(_Xglobal_lock);
+ return q;
+}
+
+XrmString XrmQuarkToString(register XrmQuark quark)
+{
+ XrmString s;
+
+ _XLockMutex(_Xglobal_lock);
+ if (quark <= 0 || quark >= nextQuark)
+ s = NULLSTRING;
+ else {
+#ifdef PERMQ
+ /* We have to mark the quark as permanent, since the caller might hold
+ * onto the string pointer forver.
+ */
+ SETPERM(quark);
+#endif
+ s = NAME(quark);
+ }
+ _XUnlockMutex(_Xglobal_lock);
+ return s;
+}
diff --git a/libX11/src/SetLocale.c b/libX11/src/SetLocale.c
index 00c76ee45..6741f2a5d 100644
--- a/libX11/src/SetLocale.c
+++ b/libX11/src/SetLocale.c
@@ -1,254 +1,253 @@
-
-/*
- * Copyright 1990, 1991 by OMRON Corporation, NTT Software Corporation,
- * and Nippon Telegraph and Telephone Corporation
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the names of OMRON, NTT Software, and NTT
- * not be used in advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission. OMRON, NTT Software,
- * and NTT make no representations about the suitability of this
- * software for any purpose. It is provided "as is" without express or
- * implied warranty.
- *
- * OMRON, NTT SOFTWARE, AND NTT, DISCLAIM ALL WARRANTIES WITH REGARD
- * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS, IN NO EVENT SHALL OMRON, NTT SOFTWARE, OR NTT, BE
- * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * Authors: Li Yuhong OMRON Corporation
- * Tetsuya Kato NTT Software Corporation
- * Hiroshi Kuribayashi OMRON Corporation
- *
- */
-/*
-
-Copyright 1987,1998 The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from The Open Group.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include <X11/Xlocale.h>
-#include <X11/Xos.h>
-#include "XlcPubI.h"
-
-#define MAXLOCALE 64 /* buffer size of locale name */
-
-#ifdef X_LOCALE
-
-/* alternative setlocale() for when the OS does not provide one */
-
-char *
-_Xsetlocale(
- int category,
- _Xconst char *name
-)
-{
- static char *xsl_name;
- char *old_name;
- XrmMethods methods;
- XPointer state;
-
- if (category != LC_CTYPE && category != LC_ALL)
- return NULL;
- if (!name) {
- if (xsl_name)
- return xsl_name;
- return "C";
- }
- if (!*name)
- name = getenv("LC_CTYPE");
- if (!name || !*name)
- name = getenv("LANG");
- if (name && strlen(name) >= MAXLOCALE)
- name = NULL;
- if (!name || !*name || !_XOpenLC((char *) name))
- name = "C";
- old_name = xsl_name;
- xsl_name = (char *)name;
- methods = _XrmInitParseInfo(&state);
- xsl_name = old_name;
- if (!methods)
- return NULL;
- name = (*methods->lcname)(state);
- xsl_name = Xmalloc(strlen(name) + 1);
- if (!xsl_name) {
- xsl_name = old_name;
- (*methods->destroy)(state);
- return NULL;
- }
- strcpy(xsl_name, name);
- if (old_name)
- Xfree(old_name);
- (*methods->destroy)(state);
- return xsl_name;
-}
-
-#else /* X_LOCALE */
-
-#if defined(__APPLE__) || defined(__CYGWIN__)
-char *
-_Xsetlocale(
- int category,
- _Xconst char *name
-)
-{
- return setlocale(category, name);
-}
-#endif /* __APPLE__ || __CYGWIN__ */
-
-/*
- * _XlcMapOSLocaleName is an implementation dependent routine that derives
- * the LC_CTYPE locale name as used in the sample implementation from that
- * returned by setlocale.
- *
- * Should match the code in Xt ExtractLocaleName.
- *
- * This function name is a bit of a misnomer. Even the siname parameter
- * name is a misnomer. On most modern operating systems this function is
- * a no-op, simply returning the osname; but on older operating systems
- * like Ultrix, or HPUX 9.x and earlier, when you set LANG=german.88591
- * then the string returned by setlocale(LC_ALL, "") will look something
- * like: "german.88591 german.88591 ... german.88591". Then this function
- * will pick out the LC_CTYPE component and return a pointer to that.
- */
-
-char *
-_XlcMapOSLocaleName(
- char *osname,
- char *siname)
-{
-#if defined(hpux) || defined(CSRG_BASED) || defined(sun) || defined(SVR4) || defined(sgi) || defined(__osf__) || defined(AIXV3) || defined(ultrix) || defined(WIN32) || defined(__UNIXOS2__) || defined(linux)
-# ifdef hpux
-# ifndef _LastCategory
- /* HPUX 9 and earlier */
-# define SKIPCOUNT 2
-# define STARTCHAR ':'
-# define ENDCHAR ';'
-# else
- /* HPUX 10 */
-# define ENDCHAR ' '
-# endif
-# else
-# ifdef ultrix
-# define SKIPCOUNT 2
-# define STARTCHAR '\001'
-# define ENDCHAR '\001'
-# else
-# if defined(WIN32) || defined(__UNIXOS2__)
-# define SKIPCOUNT 1
-# define STARTCHAR '='
-# define ENDCHAR ';'
-# define WHITEFILL
-# else
-# if defined(__osf__) || (defined(AIXV3) && !defined(AIXV4))
-# define STARTCHAR ' '
-# define ENDCHAR ' '
-# else
-# if defined(linux)
-# define STARTSTR "LC_CTYPE="
-# define ENDCHAR ';'
-# else
-# if !defined(sun) || defined(SVR4)
-# define STARTCHAR '/'
-# define ENDCHAR '/'
-# endif
-# endif
-# endif
-# endif
-# endif
-# endif
-
- char *start;
- char *end;
- int len;
-# ifdef SKIPCOUNT
- int n;
-# endif
-
- start = osname;
-# ifdef SKIPCOUNT
- for (n = SKIPCOUNT;
- --n >= 0 && start && (start = strchr (start, STARTCHAR));
- start++)
- ;
- if (!start)
- start = osname;
-# endif
-# ifdef STARTCHAR
- if (start && (start = strchr (start, STARTCHAR)))
-# elif defined (STARTSTR)
- if (start && (start = strstr (start,STARTSTR)))
-# endif
- {
-# ifdef STARTCHAR
- start++;
-# elif defined (STARTSTR)
- start += strlen(STARTSTR);
-# endif
- if ((end = strchr (start, ENDCHAR))) {
- len = end - start;
- if (len >= MAXLOCALE)
- len = MAXLOCALE - 1;
- strncpy(siname, start, len);
- *(siname + len) = '\0';
-# ifdef WHITEFILL
- for (start = siname; start = strchr(start, ' '); )
- *start++ = '-';
-# endif
- return siname;
- } else /* if no ENDCHAR is found we are at the end of the line */
- return start;
- }
-# ifdef WHITEFILL
- if (strchr(osname, ' ')) {
- len = strlen(osname);
- if (len >= MAXLOCALE - 1)
- len = MAXLOCALE - 1;
- strncpy(siname, osname, len);
- *(siname + len) = '\0';
- for (start = siname; start = strchr(start, ' '); )
- *start++ = '-';
- return siname;
- }
-# endif
-# undef STARTCHAR
-# undef ENDCHAR
-# undef WHITEFILL
-#endif
- return osname;
-}
-
-#endif /* X_LOCALE */
+
+/*
+ * Copyright 1990, 1991 by OMRON Corporation, NTT Software Corporation,
+ * and Nippon Telegraph and Telephone Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of OMRON, NTT Software, and NTT
+ * not be used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission. OMRON, NTT Software,
+ * and NTT make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * OMRON, NTT SOFTWARE, AND NTT, DISCLAIM ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS, IN NO EVENT SHALL OMRON, NTT SOFTWARE, OR NTT, BE
+ * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Li Yuhong OMRON Corporation
+ * Tetsuya Kato NTT Software Corporation
+ * Hiroshi Kuribayashi OMRON Corporation
+ *
+ */
+/*
+
+Copyright 1987,1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include <X11/Xlocale.h>
+#include <X11/Xos.h>
+#include "XlcPubI.h"
+
+#define MAXLOCALE 64 /* buffer size of locale name */
+
+#ifdef X_LOCALE
+
+/* alternative setlocale() for when the OS does not provide one */
+
+char *
+_Xsetlocale(
+ int category,
+ _Xconst char *name
+)
+{
+ static char *xsl_name;
+ char *old_name;
+ XrmMethods methods;
+ XPointer state;
+
+ if (category != LC_CTYPE && category != LC_ALL)
+ return NULL;
+ if (!name) {
+ if (xsl_name)
+ return xsl_name;
+ return "C";
+ }
+ if (!*name)
+ name = getenv("LC_CTYPE");
+ if (!name || !*name)
+ name = getenv("LANG");
+ if (name && strlen(name) >= MAXLOCALE)
+ name = NULL;
+ if (!name || !*name || !_XOpenLC((char *) name))
+ name = "C";
+ old_name = xsl_name;
+ xsl_name = (char *)name;
+ methods = _XrmInitParseInfo(&state);
+ xsl_name = old_name;
+ if (!methods)
+ return NULL;
+ name = (*methods->lcname)(state);
+ xsl_name = strdup(name);
+ if (!xsl_name) {
+ xsl_name = old_name;
+ (*methods->destroy)(state);
+ return NULL;
+ }
+ if (old_name)
+ Xfree(old_name);
+ (*methods->destroy)(state);
+ return xsl_name;
+}
+
+#else /* X_LOCALE */
+
+#if defined(__APPLE__) || defined(__CYGWIN__)
+char *
+_Xsetlocale(
+ int category,
+ _Xconst char *name
+)
+{
+ return setlocale(category, name);
+}
+#endif /* __APPLE__ || __CYGWIN__ */
+
+/*
+ * _XlcMapOSLocaleName is an implementation dependent routine that derives
+ * the LC_CTYPE locale name as used in the sample implementation from that
+ * returned by setlocale.
+ *
+ * Should match the code in Xt ExtractLocaleName.
+ *
+ * This function name is a bit of a misnomer. Even the siname parameter
+ * name is a misnomer. On most modern operating systems this function is
+ * a no-op, simply returning the osname; but on older operating systems
+ * like Ultrix, or HPUX 9.x and earlier, when you set LANG=german.88591
+ * then the string returned by setlocale(LC_ALL, "") will look something
+ * like: "german.88591 german.88591 ... german.88591". Then this function
+ * will pick out the LC_CTYPE component and return a pointer to that.
+ */
+
+char *
+_XlcMapOSLocaleName(
+ char *osname,
+ char *siname)
+{
+#if defined(hpux) || defined(CSRG_BASED) || defined(sun) || defined(SVR4) || defined(sgi) || defined(__osf__) || defined(AIXV3) || defined(ultrix) || defined(WIN32) || defined(__UNIXOS2__) || defined(linux)
+# ifdef hpux
+# ifndef _LastCategory
+ /* HPUX 9 and earlier */
+# define SKIPCOUNT 2
+# define STARTCHAR ':'
+# define ENDCHAR ';'
+# else
+ /* HPUX 10 */
+# define ENDCHAR ' '
+# endif
+# else
+# ifdef ultrix
+# define SKIPCOUNT 2
+# define STARTCHAR '\001'
+# define ENDCHAR '\001'
+# else
+# if defined(WIN32) || defined(__UNIXOS2__)
+# define SKIPCOUNT 1
+# define STARTCHAR '='
+# define ENDCHAR ';'
+# define WHITEFILL
+# else
+# if defined(__osf__) || (defined(AIXV3) && !defined(AIXV4))
+# define STARTCHAR ' '
+# define ENDCHAR ' '
+# else
+# if defined(linux)
+# define STARTSTR "LC_CTYPE="
+# define ENDCHAR ';'
+# else
+# if !defined(sun) || defined(SVR4)
+# define STARTCHAR '/'
+# define ENDCHAR '/'
+# endif
+# endif
+# endif
+# endif
+# endif
+# endif
+
+ char *start;
+ char *end;
+ int len;
+# ifdef SKIPCOUNT
+ int n;
+# endif
+
+ start = osname;
+# ifdef SKIPCOUNT
+ for (n = SKIPCOUNT;
+ --n >= 0 && start && (start = strchr (start, STARTCHAR));
+ start++)
+ ;
+ if (!start)
+ start = osname;
+# endif
+# ifdef STARTCHAR
+ if (start && (start = strchr (start, STARTCHAR)))
+# elif defined (STARTSTR)
+ if (start && (start = strstr (start,STARTSTR)))
+# endif
+ {
+# ifdef STARTCHAR
+ start++;
+# elif defined (STARTSTR)
+ start += strlen(STARTSTR);
+# endif
+ if ((end = strchr (start, ENDCHAR))) {
+ len = end - start;
+ if (len >= MAXLOCALE)
+ len = MAXLOCALE - 1;
+ strncpy(siname, start, len);
+ *(siname + len) = '\0';
+# ifdef WHITEFILL
+ for (start = siname; start = strchr(start, ' '); )
+ *start++ = '-';
+# endif
+ return siname;
+ } else /* if no ENDCHAR is found we are at the end of the line */
+ return start;
+ }
+# ifdef WHITEFILL
+ if (strchr(osname, ' ')) {
+ len = strlen(osname);
+ if (len >= MAXLOCALE - 1)
+ len = MAXLOCALE - 1;
+ strncpy(siname, osname, len);
+ *(siname + len) = '\0';
+ for (start = siname; start = strchr(start, ' '); )
+ *start++ = '-';
+ return siname;
+ }
+# endif
+# undef STARTCHAR
+# undef ENDCHAR
+# undef WHITEFILL
+#endif
+ return osname;
+}
+
+#endif /* X_LOCALE */
diff --git a/libX11/src/Xrm.c b/libX11/src/Xrm.c
index f3816741b..7dff61e68 100644
--- a/libX11/src/Xrm.c
+++ b/libX11/src/Xrm.c
@@ -581,23 +581,21 @@ static void GrowTable(
ltable = (LTable)table;
/* cons up a copy to make MoveValues look symmetric */
otable = *ltable;
- ltable->buckets = (VEntry *)Xmalloc(i * sizeof(VEntry));
+ ltable->buckets = Xcalloc(i, sizeof(VEntry));
if (!ltable->buckets) {
ltable->buckets = otable.buckets;
return;
}
ltable->table.mask = i - 1;
- bzero((char *)ltable->buckets, i * sizeof(VEntry));
MoveValues(&otable, ltable);
} else {
register NTable ntable;
- ntable = (NTable)Xmalloc(sizeof(NTableRec) + i * sizeof(NTable));
+ ntable = Xcalloc(1, sizeof(NTableRec) + (i * sizeof(NTable)));
if (!ntable)
return;
*ntable = *table;
ntable->mask = i - 1;
- bzero((char *)NodeBuckets(ntable), i * sizeof(NTable));
*prev = ntable;
MoveTables(table, ntable);
}
diff --git a/libX11/src/xcms/PrOfId.c b/libX11/src/xcms/PrOfId.c
index 831f17ab9..1ec36d96c 100644
--- a/libX11/src/xcms/PrOfId.c
+++ b/libX11/src/xcms/PrOfId.c
@@ -1,104 +1,97 @@
-
-/*
- * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
- * All Rights Reserved
- *
- * This file is a component of an X Window System-specific implementation
- * of Xcms based on the TekColor Color Management System. Permission is
- * hereby granted to use, copy, modify, sell, and otherwise distribute this
- * software and its documentation for any purpose and without fee, provided
- * that this copyright, permission, and disclaimer notice is reproduced in
- * all copies of this software and in supporting documentation. TekColor
- * is a trademark of Tektronix, Inc.
- *
- * Tektronix makes no representation about the suitability of this software
- * for any purpose. It is provided "as is" and with all faults.
- *
- * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
- * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
- * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
- * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
- * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
- *
- *
- * NAME
- * XcmsPrOfId.c
- *
- * DESCRIPTION
- * Source for XcmsPrefixOfFormat()
- *
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include "Xcmsint.h"
-#include "Cv.h"
-
-
-/*
- * NAME
- * XcmsPrefixOfId
- *
- * SYNOPSIS
- */
-char *
-XcmsPrefixOfFormat(
- XcmsColorFormat id)
-/*
- * DESCRIPTION
- * Returns the color space prefix for the specified color
- * space ID if the color space is found in the Color
- * Conversion Context.
- *
- * RETURNS
- * Returns a color space prefix.
- *
- * CAVEATS
- * Space is allocated for the returned string, therefore,
- * the application is responsible for freeing (using XFree)
- * the space.
- *
- */
-{
- XcmsColorSpace **papColorSpaces;
- char *prefix;
-
- /*
- * First try Device-Independent color spaces
- */
- papColorSpaces = _XcmsDIColorSpaces;
- if (papColorSpaces != NULL) {
- while (*papColorSpaces != NULL) {
- if ((*papColorSpaces)->id == id) {
- prefix = (char *)Xmalloc((strlen((*papColorSpaces)->prefix) +
- 1) * sizeof(char));
- strcpy(prefix, (*papColorSpaces)->prefix);
- return(prefix);
- }
- papColorSpaces++;
- }
- }
-
- /*
- * Next try Device-Dependent color spaces
- */
- papColorSpaces = _XcmsDDColorSpaces;
- if (papColorSpaces != NULL) {
- while (*papColorSpaces != NULL) {
- if ((*papColorSpaces)->id == id) {
- prefix = (char *)Xmalloc((strlen((*papColorSpaces)->prefix) +
- 1) * sizeof(char));
- strcpy(prefix, (*papColorSpaces)->prefix);
- return(prefix);
- }
- papColorSpaces++;
- }
- }
-
- return(NULL);
-}
+
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsPrOfId.c
+ *
+ * DESCRIPTION
+ * Source for XcmsPrefixOfFormat()
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+
+/*
+ * NAME
+ * XcmsPrefixOfId
+ *
+ * SYNOPSIS
+ */
+char *
+XcmsPrefixOfFormat(
+ XcmsColorFormat id)
+/*
+ * DESCRIPTION
+ * Returns the color space prefix for the specified color
+ * space ID if the color space is found in the Color
+ * Conversion Context.
+ *
+ * RETURNS
+ * Returns a color space prefix.
+ *
+ * CAVEATS
+ * Space is allocated for the returned string, therefore,
+ * the application is responsible for freeing (using XFree)
+ * the space.
+ *
+ */
+{
+ XcmsColorSpace **papColorSpaces;
+
+ /*
+ * First try Device-Independent color spaces
+ */
+ papColorSpaces = _XcmsDIColorSpaces;
+ if (papColorSpaces != NULL) {
+ while (*papColorSpaces != NULL) {
+ if ((*papColorSpaces)->id == id) {
+ return strdup((*papColorSpaces)->prefix);
+ }
+ papColorSpaces++;
+ }
+ }
+
+ /*
+ * Next try Device-Dependent color spaces
+ */
+ papColorSpaces = _XcmsDDColorSpaces;
+ if (papColorSpaces != NULL) {
+ while (*papColorSpaces != NULL) {
+ if ((*papColorSpaces)->id == id) {
+ return strdup((*papColorSpaces)->prefix);
+ }
+ papColorSpaces++;
+ }
+ }
+
+ return(NULL);
+}
diff --git a/libX11/src/xkb/XKBGAlloc.c b/libX11/src/xkb/XKBGAlloc.c
index 832d28530..55505f4f6 100644
--- a/libX11/src/xkb/XKBGAlloc.c
+++ b/libX11/src/xkb/XKBGAlloc.c
@@ -684,9 +684,7 @@ register XkbPropertyPtr prop;
if ((prop->name)&&(strcmp(name,prop->name)==0)) {
if (prop->value)
_XkbFree(prop->value);
- prop->value= (char *)_XkbAlloc(strlen(value)+1);
- if (prop->value)
- strcpy(prop->value,value);
+ prop->value= strdup(value);
return prop;
}
}
@@ -695,17 +693,15 @@ register XkbPropertyPtr prop;
return NULL;
}
prop= &geom->properties[geom->num_properties];
- prop->name= (char *)_XkbAlloc(strlen(name)+1);
+ prop->name= strdup(name);
if (!prop->name)
return NULL;
- strcpy(prop->name,name);
- prop->value= (char *)_XkbAlloc(strlen(value)+1);
+ prop->value= strdup(value);
if (!prop->value) {
_XkbFree(prop->name);
prop->name= NULL;
return NULL;
}
- strcpy(prop->value,value);
geom->num_properties++;
return prop;
}
@@ -757,10 +753,9 @@ register XkbColorPtr color;
}
color= &geom->colors[geom->num_colors];
color->pixel= pixel;
- color->spec= (char *)_XkbAlloc(strlen(spec)+1);
+ color->spec= strdup(spec);
if (!color->spec)
return NULL;
- strcpy(color->spec,spec);
geom->num_colors++;
return color;
}
diff --git a/libX11/src/xlibi18n/XDefaultIMIF.c b/libX11/src/xlibi18n/XDefaultIMIF.c
index c7a2fe9d3..71b1af177 100644
--- a/libX11/src/xlibi18n/XDefaultIMIF.c
+++ b/libX11/src/xlibi18n/XDefaultIMIF.c
@@ -226,12 +226,10 @@ _XDefaultOpenIM(
local_impart->ctow_conv = ctow_conv;
if ((res_name != NULL) && (*res_name != '\0')){
- im->core.res_name = (char *)Xmalloc(strlen(res_name)+1);
- strcpy(im->core.res_name,res_name);
+ im->core.res_name = strdup(res_name);
}
if ((res_class != NULL) && (*res_class != '\0')){
- im->core.res_class = (char *)Xmalloc(strlen(res_class)+1);
- strcpy(im->core.res_class,res_class);
+ im->core.res_class = strdup(res_class);
}
return (XIM)im;
diff --git a/libX11/src/xlibi18n/XDefaultOMIF.c b/libX11/src/xlibi18n/XDefaultOMIF.c
index 1821e6459..73a7def4f 100644
--- a/libX11/src/xlibi18n/XDefaultOMIF.c
+++ b/libX11/src/xlibi18n/XDefaultOMIF.c
@@ -1,1277 +1,1262 @@
-/*
-Copyright 1985, 1986, 1987, 1991, 1998 The Open Group
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions: The above copyright notice and this
-permission notice shall be included in all copies or substantial
-portions of the Software.
-
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
-EVEN IF ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
-
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-
-X Window System is a trademark of The Open Group
-
-OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
-logo, LBX, X Window System, and Xinerama are trademarks of the Open
-Group. All other trademarks and registered trademarks mentioned herein
-are the property of their respective owners. No right, title or
-interest in or to any trademark, service mark, logo or trade name of
-Sun Microsystems, Inc. or its licensors is granted.
-
-*/
-/*
- * Copyright 2000 Oracle and/or its affiliates. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "XlcPublic.h"
-#include <X11/Xos.h>
-#include <X11/Xatom.h>
-#include <stdio.h>
-#include <stdint.h>
-
-#define MAXFONTS 100
-
-#define XOM_GENERIC(om) (&((XOMGeneric) om)->gen)
-#define XOC_GENERIC(font_set) (&((XOCGeneric) font_set)->gen)
-
-#define DefineLocalBuf char local_buf[BUFSIZ]
-#define AllocLocalBuf(length) (length > BUFSIZ ? (char *)Xmalloc(length) : local_buf)
-#define FreeLocalBuf(ptr) if (ptr != local_buf) Xfree(ptr)
-
-typedef struct _FontDataRec {
- char *name;
-} FontDataRec, *FontData;
-
-typedef struct _OMDataRec {
- int font_data_count;
- FontData font_data;
-} OMDataRec, *OMData;
-
-typedef struct _XOMGenericPart {
- OMData data;
-} XOMGenericPart;
-
-typedef struct _XOMGenericRec {
- XOMMethods methods;
- XOMCoreRec core;
- XOMGenericPart gen;
-} XOMGenericRec, *XOMGeneric;
-
-typedef struct _FontSetRec {
- int id;
- int font_data_count;
- FontData font_data;
- char *font_name;
- XFontStruct *info;
- XFontStruct *font;
-} FontSetRec, *FontSet;
-
-typedef struct _XOCGenericPart {
- XlcConv wcs_to_cs;
- FontSet font_set;
-} XOCGenericPart;
-
-typedef struct _XOCGenericRec {
- XOCMethods methods;
- XOCCoreRec core;
- XOCGenericPart gen;
-} XOCGenericRec, *XOCGeneric;
-
-static Bool
-init_fontset(
- XOC oc)
-{
- XOCGenericPart *gen;
- FontSet font_set;
- OMData data;
-
- data = XOM_GENERIC(oc->core.om)->data;
-
- font_set = (FontSet) Xmalloc(sizeof(FontSetRec));
- if (font_set == NULL)
- return False;
- bzero((char *) font_set, sizeof(FontSetRec));
-
- gen = XOC_GENERIC(oc);
- gen->font_set = font_set;
-
- font_set->font_data_count = data->font_data_count;
- font_set->font_data = data->font_data;
-
- return True;
-}
-
-static char *
-get_prop_name(
- Display *dpy,
- XFontStruct *fs)
-{
- unsigned long fp;
-
- if (XGetFontProperty(fs, XA_FONT, &fp))
- return XGetAtomName(dpy, fp);
-
- return (char *) NULL;
-}
-
-static FontData
-check_charset(
- FontSet font_set,
- char *font_name)
-{
- FontData font_data;
- char *last;
- int count;
- ssize_t length, name_len;
-
- name_len = strlen(font_name);
- last = font_name + name_len;
-
- count = font_set->font_data_count;
- font_data = font_set->font_data;
-
- for ( ; count-- > 0; font_data++) {
- length = strlen(font_data->name);
-
- if (length > name_len)
- return(NULL);
-
- if (_XlcCompareISOLatin1(last - length, font_data->name) == 0)
- return font_data;
- }
- return (FontData) NULL;
-}
-
-#if 0 /* Unused */
-static int
-check_fontname(
- XOC oc,
- char *name)
-{
- Display *dpy = oc->core.om->core.display;
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontData data;
- FontSet font_set;
- XFontStruct *fs_list;
- char **fn_list, *fname, *prop_fname = NULL;
- int list_num, i;
- int list2_num;
- char **fn2_list = NULL;
- int found_num = 0;
-
- fn_list = XListFonts(dpy, name, MAXFONTS, &list_num);
- if (fn_list == NULL)
- return found_num;
-
- for (i = 0; i < list_num; i++) {
- fname = fn_list[i];
-
- font_set = gen->font_set;
-
- if ((data = check_charset(font_set, fname)) == NULL) {
- if ((fn2_list = XListFontsWithInfo(dpy, name, MAXFONTS,
- &list2_num, &fs_list))
- && (prop_fname = get_prop_name(dpy, fs_list))
- && (data = check_charset(font_set, prop_fname)))
- fname = prop_fname;
- }
- if (data) {
- font_set->font_name = (char *) Xmalloc(strlen(fname) + 1);
- if (font_set->font_name) {
- strcpy(font_set->font_name, fname);
- found_num++;
- }
- }
- if (fn2_list) {
- XFreeFontInfo(fn2_list, fs_list, list2_num);
- fn2_list = NULL;
- if (prop_fname) {
- Xfree(prop_fname);
- prop_fname = NULL;
- }
- }
- if (found_num == 1)
- break;
- }
- XFreeFontNames(fn_list);
- return found_num;
-}
-#endif
-
-static Bool
-load_font(
- XOC oc)
-{
- Display *dpy = oc->core.om->core.display;
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontSet font_set = gen->font_set;
-
- if (font_set->font_name == NULL)
- return False;
-
- if (font_set->font == NULL) {
- font_set->font = XLoadQueryFont(dpy, font_set->font_name);
- if (font_set->font == NULL)
- return False;
- }
- return True;
-}
-
-#if 0
-static Bool
-load_font_info(
- XOC oc)
-{
- Display *dpy = oc->core.om->core.display;
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontSet font_set = gen->font_set;
- char **fn_list;
- int fn_num;
-
- if (font_set->font_name == NULL)
- return False;
-
- if (font_set->info == NULL) {
- fn_list = XListFontsWithInfo(dpy, font_set->font_name, 1, &fn_num,
- &font_set->info);
- if (font_set->info == NULL)
- return False;
- if (fn_num > 0)
- font_set->info->fid = XLoadFont(dpy, font_set->font_name);
-
- if (fn_list) XFreeFontNames(fn_list);
- }
- return True;
-}
-#endif
-
-static void
-set_fontset_extents(
- XOC oc)
-{
- XRectangle *ink = &oc->core.font_set_extents.max_ink_extent;
- XRectangle *logical = &oc->core.font_set_extents.max_logical_extent;
- XFontStruct **font_list, *font;
- XCharStruct overall;
- int logical_ascent, logical_descent;
-
- font_list = oc->core.font_info.font_struct_list;
- font = *font_list++;
- overall = font->max_bounds;
- overall.lbearing = font->min_bounds.lbearing;
- logical_ascent = font->ascent;
- logical_descent = font->descent;
-
- ink->x = overall.lbearing;
- ink->y = -(overall.ascent);
- ink->width = overall.rbearing - overall.lbearing;
- ink->height = overall.ascent + overall.descent;
-
- logical->x = 0;
- logical->y = -(logical_ascent);
- logical->width = overall.width;
- logical->height = logical_ascent + logical_descent;
-}
-
-static Bool
-init_core_part(
- XOC oc)
-{
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontSet font_set;
- XFontStruct **font_struct_list;
- char **font_name_list, *font_name_buf;
- int count, length;
-
- font_set = gen->font_set;
- count = length = 0;
-
- if (font_set->font_name != NULL) {
- length += strlen(font_set->font_name) + 1;
- count++;
- }
- if (count == 0)
- return False;
-
- font_struct_list = (XFontStruct **) Xmalloc(sizeof(XFontStruct *));
- if (font_struct_list == NULL)
- return False;
-
- font_name_list = (char **) Xmalloc(sizeof(char *));
- if (font_name_list == NULL)
- goto err;
-
- font_name_buf = (char *) Xmalloc(length);
- if (font_name_buf == NULL)
- goto err;
-
- oc->core.font_info.num_font = 1;
- oc->core.font_info.font_name_list = font_name_list;
- oc->core.font_info.font_struct_list = font_struct_list;
-
- font_set = gen->font_set;
-
- if (font_set->font_name != NULL) {
- font_set->id = 1;
- if (font_set->font)
- *font_struct_list++ = font_set->font;
- else
- *font_struct_list++ = font_set->info;
- strcpy(font_name_buf, font_set->font_name);
- Xfree(font_set->font_name);
- *font_name_list++ = font_set->font_name = font_name_buf;
- font_name_buf += strlen(font_name_buf) + 1;
- }
-
- set_fontset_extents(oc);
-
- return True;
-
-err:
- if (font_name_list)
- Xfree(font_name_list);
- Xfree(font_struct_list);
-
- return False;
-}
-
-static char *
-get_font_name(
- XOC oc,
- char *pattern)
-{
- char **list, *name;
- int count;
- XFontStruct *fs;
- Display *dpy = oc->core.om->core.display;
-
- list = XListFonts(dpy, pattern, 1, &count);
- if (list != NULL) {
- name = (char *) Xmalloc(strlen(*list) + 1);
- if (name)
- strcpy(name, *list);
-
- XFreeFontNames(list);
- } else {
- fs = XLoadQueryFont(dpy, pattern);
- if (fs == NULL) return NULL;
-
- name = get_prop_name(dpy, fs);
- XFreeFont(dpy, fs);
- }
- return name;
-}
-
-static int
-parse_fontname(
- XOC oc)
-{
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontSet font_set;
- FontData font_data;
- char *pattern, *last, buf[BUFSIZ];
- int font_data_count, found_num = 0;
- ssize_t length;
- int count, num_fields;
- char *base_name, *font_name, **name_list, **cur_name_list;
- char *charset_p = NULL;
- Bool append_charset;
- /*
- append_charset flag should be set to True when the XLFD fontname
- doesn't contain a chaset part.
- */
-
- name_list = _XParseBaseFontNameList(oc->core.base_name_list, &count);
- if (name_list == NULL)
- return -1;
- cur_name_list = name_list;
-
- while (count-- > 0) {
- pattern = *cur_name_list++;
- if (pattern == NULL || *pattern == '\0')
- continue;
-
- append_charset = False;
-
- if (strchr(pattern, '*') == NULL &&
- (font_name = get_font_name(oc, pattern))) {
-
- font_set = gen->font_set;
-
- font_data = check_charset(font_set, font_name);
- if (font_data == NULL) {
- Display *dpy = oc->core.om->core.display;
- char **fn_list = NULL, *prop_fname = NULL;
- int list_num;
- XFontStruct *fs_list;
- if ((fn_list = XListFontsWithInfo(dpy, font_name,
- MAXFONTS,
- &list_num, &fs_list))
- && (prop_fname = get_prop_name(dpy, fs_list))
- && (font_data = check_charset(font_set, prop_fname))) {
- if (fn_list) {
- XFreeFontInfo(fn_list, fs_list, list_num);
- fn_list = NULL;
- }
- font_name = prop_fname;
- }
- }
- if (font_data == NULL)
- continue;
-
- font_set->font_name = (char *) Xmalloc(strlen(font_name) + 1);
- if (font_set->font_name == NULL) {
- Xfree(font_name);
- goto err;
- }
- strcpy(font_set->font_name, font_name);
- Xfree(font_name);
- found_num++;
- goto found;
- }
-/*
-1266793
-Limit the length of the string copy to prevent stack corruption.
- strcpy(buf, pattern);
-*/
- strncpy(buf, pattern, BUFSIZ);
- buf[BUFSIZ-1] = '\0';
- length = strlen(buf);
- last = buf + length - 1;
-
- for (num_fields = 0, base_name = buf; *base_name != '\0'; base_name++)
- if (*base_name == '-') num_fields++;
- if (strchr(pattern, '*') == NULL) {
- if (num_fields == 12) {
- append_charset = True;
- *++last = '-';
- last++;
- } else
- continue;
- } else {
- if (num_fields == 13 || num_fields == 14) {
- /*
- * There are 14 fields in an XLFD name -- make certain the
- * charset (& encoding) is placed in the correct field.
- */
- append_charset = True;
- last = strrchr (buf, '-');
- if (num_fields == 14) {
- *last = '\0';
- last = strrchr (buf, '-');
- }
- last++;
- } else if (*last == '*') {
- append_charset = True;
- if (length > 3 && *(last-3) == '-' && *(last-2) == '*'
- && *(last-1) == '-') {
- last -= 2;
- }
- *++last = '-';
- last++;
- } else {
- last = strrchr (buf, '-');
- charset_p = last;
- charset_p = strrchr (buf, '-');
- while (*(--charset_p) != '-');
- charset_p++;
- }
- }
-
- font_set = gen->font_set;
-
- font_data = font_set->font_data;
- font_data_count = font_set->font_data_count;
- for ( ; font_data_count-- > 0; font_data++) {
- if (append_charset)
- {
-/*
-1266793
-Limit the length of the string copy to prevent stack corruption.
- strcpy(last, font_data->name);
-*/
- strncpy(last, font_data->name, BUFSIZ - length);
- buf[BUFSIZ-1] = '\0';
- }
- else {
- if (_XlcCompareISOLatin1(charset_p,
- font_data->name)) {
- continue;
- }
- }
- if ((font_set->font_name = get_font_name(oc, buf)))
- break;
- }
- if (font_set->font_name != NULL) {
- found_num++;
- goto found;
- }
- }
- found:
- base_name = (char *) Xmalloc(strlen(oc->core.base_name_list) + 1);
- if (base_name == NULL)
- goto err;
-
- strcpy(base_name, oc->core.base_name_list);
- oc->core.base_name_list = base_name;
-
- XFreeStringList(name_list);
-
- return found_num;
-err:
- XFreeStringList(name_list);
-
- return -1;
-}
-
-static Bool
-set_missing_list(
- XOC oc)
-{
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontSet font_set;
- char **charset_list, *charset_buf;
- int count, length;
-
- font_set = gen->font_set;
- count = length = 0;
-
- if (!font_set->info && !font_set->font) {
- length += strlen(font_set->font_data->name) + 1;
- count++;
- }
-
- if (count == 0)
- return True;
-
- charset_list = (char **) Xmalloc(sizeof(char *));
- if (charset_list == NULL)
- return False;
-
- charset_buf = (char *) Xmalloc(length);
- if (charset_buf == NULL) {
- Xfree(charset_list);
- return False;
- }
-
- oc->core.missing_list.charset_list = charset_list;
-
- font_set = gen->font_set;
-
- if (!font_set->info && !font_set->font) {
- strcpy(charset_buf, font_set->font_data->name);
- *charset_list++ = charset_buf;
- charset_buf += strlen(charset_buf) + 1;
- }
- return True;
-}
-
-static Bool
-create_fontset(
- XOC oc)
-{
- int found_num;
-
- if (init_fontset(oc) == False)
- return False;
-
- found_num = parse_fontname(oc);
- if (found_num <= 0) {
- if (found_num == 0)
- set_missing_list(oc);
- return False;
- }
-
- if (load_font(oc) == False)
- return False;
-
- if (init_core_part(oc) == False)
- return False;
-
- if (set_missing_list(oc) == False)
- return False;
-
- return True;
-}
-
-static void
-destroy_oc(
- XOC oc)
-{
- Display *dpy = oc->core.om->core.display;
- XOCGenericPart *gen = XOC_GENERIC(oc);
- XFontStruct **font_list, *font;
-
- if (gen->font_set)
- Xfree(gen->font_set);
-
- if (oc->core.base_name_list)
- Xfree(oc->core.base_name_list);
-
- if (oc->core.font_info.font_name_list)
- XFreeStringList(oc->core.font_info.font_name_list);
-
- if ((font_list = oc->core.font_info.font_struct_list)) {
- if ((font = *font_list)) {
- if (font->fid)
- XFreeFont(dpy, font);
- else
- XFreeFontInfo(NULL, font, 1);
- }
- Xfree(oc->core.font_info.font_struct_list);
- }
-
- if (oc->core.missing_list.charset_list)
- XFreeStringList(oc->core.missing_list.charset_list);
-
-#ifdef notdef
- if (oc->core.res_name)
- Xfree(oc->core.res_name);
- if (oc->core.res_class)
- Xfree(oc->core.res_class);
-#endif
-
- Xfree(oc);
-}
-
-static char *
-set_oc_values(
- XOC oc,
- XlcArgList args,
- int num_args)
-{
- if (oc->core.resources == NULL)
- return NULL;
-
- return _XlcSetValues((XPointer) oc, oc->core.resources,
- oc->core.num_resources, args, num_args, XlcSetMask);
-}
-
-static char *
-get_oc_values(
- XOC oc,
- XlcArgList args,
- int num_args)
-{
- if (oc->core.resources == NULL)
- return NULL;
-
- return _XlcGetValues((XPointer) oc, oc->core.resources,
- oc->core.num_resources, args, num_args, XlcGetMask);
-}
-
-static Bool
-wcs_to_mbs(
- XOC oc,
- char *to,
- _Xconst wchar_t *from,
- int length)
-{
- XlcConv conv = XOC_GENERIC(oc)->wcs_to_cs;
- XLCd lcd;
- int ret, to_left = length;
-
- if (conv == NULL) {
- lcd = oc->core.om->core.lcd;
- conv = _XlcOpenConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte);
- if (conv == NULL)
- return False;
- XOC_GENERIC(oc)->wcs_to_cs = conv;
- } else
- _XlcResetConverter(conv);
-
- ret = _XlcConvert(conv, (XPointer *) &from, &length, (XPointer *) &to,
- &to_left, NULL, 0);
- if (ret != 0 || length > 0)
- return False;
-
- return True;
-}
-
-static int
-_XmbDefaultTextEscapement(XOC oc, _Xconst char *text, int length)
-{
- return XTextWidth(*oc->core.font_info.font_struct_list, text, length);
-}
-
-static int
-_XwcDefaultTextEscapement(XOC oc, _Xconst wchar_t *text, int length)
-{
- DefineLocalBuf;
- char *buf = AllocLocalBuf(length);
- int ret = 0;
-
- if (buf == NULL)
- return 0;
-
- if (wcs_to_mbs(oc, buf, text, length) == False)
- goto err;
-
- ret = _XmbDefaultTextEscapement(oc, buf, length);
-
-err:
- FreeLocalBuf(buf);
-
- return ret;
-}
-
-static int
-_XmbDefaultTextExtents(XOC oc, _Xconst char *text, int length,
- XRectangle *overall_ink, XRectangle *overall_logical)
-{
- int direction, logical_ascent, logical_descent;
- XCharStruct overall;
-
- XTextExtents(*oc->core.font_info.font_struct_list, text, length, &direction,
- &logical_ascent, &logical_descent, &overall);
-
- if (overall_ink) {
- overall_ink->x = overall.lbearing;
- overall_ink->y = -(overall.ascent);
- overall_ink->width = overall.rbearing - overall.lbearing;
- overall_ink->height = overall.ascent + overall.descent;
- }
-
- if (overall_logical) {
- overall_logical->x = 0;
- overall_logical->y = -(logical_ascent);
- overall_logical->width = overall.width;
- overall_logical->height = logical_ascent + logical_descent;
- }
-
- return overall.width;
-}
-
-static int
-_XwcDefaultTextExtents(XOC oc, _Xconst wchar_t *text, int length,
- XRectangle *overall_ink, XRectangle *overall_logical)
-{
- DefineLocalBuf;
- char *buf = AllocLocalBuf(length);
- int ret = 0;
-
- if (buf == NULL)
- return 0;
-
- if (wcs_to_mbs(oc, buf, text, length) == False)
- goto err;
-
- ret = _XmbDefaultTextExtents(oc, buf, length, overall_ink, overall_logical);
-
-err:
- FreeLocalBuf(buf);
-
- return ret;
-}
-
-static Status
-_XmbDefaultTextPerCharExtents(XOC oc, _Xconst char *text, int length,
- XRectangle *ink_buf, XRectangle *logical_buf,
- int buf_size, int *num_chars,
- XRectangle *overall_ink,
- XRectangle *overall_logical)
-{
- XFontStruct *font = *oc->core.font_info.font_struct_list;
- XCharStruct *def, *cs, overall;
- Bool first = True;
-
- if (buf_size < length)
- return 0;
-
- bzero((char *) &overall, sizeof(XCharStruct));
- *num_chars = 0;
-
- CI_GET_DEFAULT_INFO_1D(font, def)
-
- while (length-- > 0) {
- CI_GET_CHAR_INFO_1D(font, *text, def, cs)
- text++;
- if (cs == NULL)
- continue;
-
- ink_buf->x = overall.width + cs->lbearing;
- ink_buf->y = -(cs->ascent);
- ink_buf->width = cs->rbearing - cs->lbearing;
- ink_buf->height = cs->ascent + cs->descent;
- ink_buf++;
-
- logical_buf->x = overall.width;
- logical_buf->y = -(font->ascent);
- logical_buf->width = cs->width;
- logical_buf->height = font->ascent + font->descent;
- logical_buf++;
-
- if (first) {
- overall = *cs;
- first = False;
- } else {
- overall.ascent = max(overall.ascent, cs->ascent);
- overall.descent = max(overall.descent, cs->descent);
- overall.lbearing = min(overall.lbearing, overall.width +
- cs->lbearing);
- overall.rbearing = max(overall.rbearing, overall.width +
- cs->rbearing);
- overall.width += cs->width;
- }
- (*num_chars)++;
- }
-
- if (overall_ink) {
- overall_ink->x = overall.lbearing;
- overall_ink->y = -(overall.ascent);
- overall_ink->width = overall.rbearing - overall.lbearing;
- overall_ink->height = overall.ascent + overall.descent;
- }
-
- if (overall_logical) {
- overall_logical->x = 0;
- overall_logical->y = -(font->ascent);
- overall_logical->width = overall.width;
- overall_logical->height = font->ascent + font->descent;
- }
-
- return 1;
-}
-
-static Status
-_XwcDefaultTextPerCharExtents(XOC oc, _Xconst wchar_t *text, int length,
- XRectangle *ink_buf, XRectangle *logical_buf,
- int buf_size, int *num_chars,
- XRectangle *overall_ink,
- XRectangle *overall_logical)
-{
- DefineLocalBuf;
- char *buf = AllocLocalBuf(length);
- Status ret = 0;
-
- if (buf == NULL)
- return 0;
-
- if (wcs_to_mbs(oc, buf, text, length) == False)
- goto err;
-
- ret = _XmbDefaultTextPerCharExtents(oc, buf, length, ink_buf, logical_buf,
- buf_size, num_chars, overall_ink,
- overall_logical);
-
-err:
- FreeLocalBuf(buf);
-
- return ret;
-}
-
-static int
-_XmbDefaultDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
- _Xconst char *text, int length)
-{
- XFontStruct *font = *oc->core.font_info.font_struct_list;
-
- XSetFont(dpy, gc, font->fid);
- XDrawString(dpy, d, gc, x, y, text, length);
-
- return XTextWidth(font, text, length);
-}
-
-static int
-_XwcDefaultDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
- _Xconst wchar_t *text, int length)
-{
- DefineLocalBuf;
- char *buf = AllocLocalBuf(length);
- int ret = 0;
-
- if (buf == NULL)
- return 0;
-
- if (wcs_to_mbs(oc, buf, text, length) == False)
- goto err;
-
- ret = _XmbDefaultDrawString(dpy, d, oc, gc, x, y, buf, length);
-
-err:
- FreeLocalBuf(buf);
-
- return ret;
-}
-
-static void
-_XmbDefaultDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
- int y, _Xconst char *text, int length)
-{
- XSetFont(dpy, gc, (*oc->core.font_info.font_struct_list)->fid);
- XDrawImageString(dpy, d, gc, x, y, text, length);
-}
-
-static void
-_XwcDefaultDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
- int y, _Xconst wchar_t *text, int length)
-{
- DefineLocalBuf;
- char *buf = AllocLocalBuf(length);
-
- if (buf == NULL)
- return;
-
- if (wcs_to_mbs(oc, buf, text, length) == False)
- goto err;
-
- _XmbDefaultDrawImageString(dpy, d, oc, gc, x, y, buf, length);
-
-err:
- FreeLocalBuf(buf);
-}
-
-static _Xconst XOCMethodsRec oc_default_methods = {
- destroy_oc,
- set_oc_values,
- get_oc_values,
- _XmbDefaultTextEscapement,
- _XmbDefaultTextExtents,
- _XmbDefaultTextPerCharExtents,
- _XmbDefaultDrawString,
- _XmbDefaultDrawImageString,
- _XwcDefaultTextEscapement,
- _XwcDefaultTextExtents,
- _XwcDefaultTextPerCharExtents,
- _XwcDefaultDrawString,
- _XwcDefaultDrawImageString
-};
-
-static XlcResource oc_resources[] = {
- { XNBaseFontName, NULLQUARK, sizeof(char *),
- XOffsetOf(XOCRec, core.base_name_list), XlcCreateMask | XlcGetMask },
- { XNOMAutomatic, NULLQUARK, sizeof(Bool),
- XOffsetOf(XOCRec, core.om_automatic), XlcGetMask },
- { XNMissingCharSet, NULLQUARK, sizeof(XOMCharSetList),
- XOffsetOf(XOCRec, core.missing_list), XlcGetMask },
- { XNDefaultString, NULLQUARK, sizeof(char *),
- XOffsetOf(XOCRec, core.default_string), XlcGetMask },
- { XNOrientation, NULLQUARK, sizeof(XOrientation),
- XOffsetOf(XOCRec, core.orientation), XlcSetMask | XlcGetMask },
- { XNResourceName, NULLQUARK, sizeof(char *),
- XOffsetOf(XOCRec, core.res_name), XlcSetMask | XlcGetMask },
- { XNResourceClass, NULLQUARK, sizeof(char *),
- XOffsetOf(XOCRec, core.res_class), XlcSetMask | XlcGetMask },
- { XNFontInfo, NULLQUARK, sizeof(XOMFontInfo),
- XOffsetOf(XOCRec, core.font_info), XlcGetMask }
-};
-
-static XOC
-create_oc(
- XOM om,
- XlcArgList args,
- int num_args)
-{
- XOC oc;
-
- oc = (XOC) Xmalloc(sizeof(XOCGenericRec));
- if (oc == NULL)
- return (XOC) NULL;
- bzero((char *) oc, sizeof(XOCGenericRec));
-
- oc->core.om = om;
-
- if (oc_resources[0].xrm_name == NULLQUARK)
- _XlcCompileResourceList(oc_resources, XlcNumber(oc_resources));
-
- if (_XlcSetValues((XPointer) oc, oc_resources, XlcNumber(oc_resources),
- args, num_args, XlcCreateMask | XlcDefaultMask))
- goto err;
-
- if (oc->core.base_name_list == NULL)
- goto err;
-
- oc->core.resources = oc_resources;
- oc->core.num_resources = XlcNumber(oc_resources);
-
- if (create_fontset(oc) == False)
- goto err;
-
- oc->methods = (XOCMethods)&oc_default_methods;
-
- return oc;
-
-err:
- destroy_oc(oc);
-
- return (XOC) NULL;
-}
-
-static Status
-close_om(
- XOM om)
-{
- XOMGenericPart *gen = XOM_GENERIC(om);
- OMData data;
- FontData font_data;
- int count;
-
- if ((data = gen->data)) {
- if (data->font_data) {
- for (font_data = data->font_data, count = data->font_data_count;
- count-- > 0 ; font_data++) {
- if (font_data->name)
- Xfree(font_data->name);
- }
- Xfree(data->font_data);
- }
- Xfree(gen->data);
- }
-
- if (om->core.res_name)
- Xfree(om->core.res_name);
- if (om->core.res_class)
- Xfree(om->core.res_class);
- if (om->core.required_charset.charset_list)
- XFreeStringList(om->core.required_charset.charset_list);
- else
- Xfree((char*)om->core.required_charset.charset_list);
- if (om->core.orientation_list.orientation)
- Xfree(om->core.orientation_list.orientation);
-
- Xfree(om);
-
- return 1;
-}
-
-static char *
-set_om_values(
- XOM om,
- XlcArgList args,
- int num_args)
-{
- if (om->core.resources == NULL)
- return NULL;
-
- return _XlcSetValues((XPointer) om, om->core.resources,
- om->core.num_resources, args, num_args, XlcSetMask);
-}
-
-static char *
-get_om_values(
- XOM om,
- XlcArgList args,
- int num_args)
-{
- if (om->core.resources == NULL)
- return NULL;
-
- return _XlcGetValues((XPointer) om, om->core.resources,
- om->core.num_resources, args, num_args, XlcGetMask);
-}
-
-static _Xconst XOMMethodsRec methods = {
- close_om,
- set_om_values,
- get_om_values,
- create_oc
-};
-
-static XlcResource om_resources[] = {
- { XNRequiredCharSet, NULLQUARK, sizeof(XOMCharSetList),
- XOffsetOf(XOMRec, core.required_charset), XlcGetMask },
- { XNQueryOrientation, NULLQUARK, sizeof(XOMOrientation),
- XOffsetOf(XOMRec, core.orientation_list), XlcGetMask },
- { XNDirectionalDependentDrawing, NULLQUARK, sizeof(Bool),
- XOffsetOf(XOMRec, core.directional_dependent), XlcGetMask },
- { XNContextualDrawing, NULLQUARK, sizeof(Bool),
- XOffsetOf(XOMRec, core.contextual_drawing), XlcGetMask }
-};
-
-static OMData
-add_data(
- XOM om)
-{
- XOMGenericPart *gen = XOM_GENERIC(om);
- OMData new;
-
- new = (OMData) Xmalloc(sizeof(OMDataRec));
-
- if (new == NULL)
- return NULL;
-
- gen->data = new;
-
- bzero((char *) new, sizeof(OMDataRec));
-
- return new;
-}
-
-static _Xconst char *supported_charset_list[] = {
- "ISO8859-1",
-/* fix for bug4332979 */
- "adobe-fontspecific",
-/* fix for bug4237353: "JISX0201.1976-0" entry should be removed from
- supported_charset_list because it is not a supported_charset for C locale
- "JISX0201.1976-0", */
- "SUNOLCURSOR-1",
- "SUNOLGLYPH-1"
-};
-
-static Bool
-init_om(
- XOM om)
-{
- XOMGenericPart *gen = XOM_GENERIC(om);
- OMData data;
- FontData font_data;
- char **required_list;
- XOrientation *orientation;
- char **value, buf[BUFSIZ], *bufptr;
- int count, length = 0;
-
- value = (char**)supported_charset_list;
- count = XlcNumber(supported_charset_list);
-
- data = add_data(om);
- if (data == NULL)
- return False;
-
- font_data = (FontData) Xmalloc(sizeof(FontDataRec) * count);
- if (font_data == NULL)
- return False;
- bzero((char *) font_data, sizeof(FontDataRec) * count);
- data->font_data = font_data;
- data->font_data_count = count;
-
- for ( ; count-- > 0; font_data++) {
-/*
-1266793
-This one is fine. *value points to one of the local strings in
-supported_charset_list[].
-*/
- strcpy(buf, *value++);
- font_data->name = (char *) Xmalloc(strlen(buf) + 1);
- if (font_data->name == NULL)
- return False;
- strcpy(font_data->name, buf);
- }
-
- length += strlen(data->font_data->name) + 1;
-
- /* required charset list */
- required_list = (char **) Xmalloc(sizeof(char *));
- if (required_list == NULL)
- return False;
-
- bufptr = (char *) Xmalloc(length);
- if (bufptr == NULL) {
- Xfree(required_list);
- return False;
- }
-
- om->core.required_charset.charset_list = required_list;
- om->core.required_charset.charset_count = 1; /* always 1 */
-
- data = gen->data;
-
- strcpy(bufptr, data->font_data->name);
- *required_list++ = bufptr;
- bufptr += strlen(bufptr) + 1;
-
- /* orientation list */
- orientation = (XOrientation *) Xmalloc(sizeof(XOrientation));
- if (orientation == NULL)
- return False;
-
- *orientation = XOMOrientation_LTR_TTB;
- om->core.orientation_list.orientation = orientation;
- om->core.orientation_list.num_orientation = 1;
-
- /* directional dependent drawing */
- om->core.directional_dependent = False;
-
- /* contexual drawing */
- om->core.contextual_drawing = False;
-
- /* context dependent */
- om->core.context_dependent = False;
-
- return True;
-}
-
-XOM
-_XDefaultOpenOM(XLCd lcd, Display *dpy, XrmDatabase rdb,
- _Xconst char *res_name, _Xconst char *res_class)
-{
- XOM om;
-
- om = (XOM) Xmalloc(sizeof(XOMGenericRec));
- if (om == NULL)
- return (XOM) NULL;
- bzero((char *) om, sizeof(XOMGenericRec));
-
- om->methods = (XOMMethods)&methods;
- om->core.lcd = lcd;
- om->core.display = dpy;
- om->core.rdb = rdb;
- if (res_name) {
- om->core.res_name = (char *)Xmalloc(strlen(res_name) + 1);
- if (om->core.res_name == NULL)
- goto err;
- strcpy(om->core.res_name, res_name);
- }
- if (res_class) {
- om->core.res_class = (char *)Xmalloc(strlen(res_class) + 1);
- if (om->core.res_class == NULL)
- goto err;
- strcpy(om->core.res_class, res_class);
- }
-
- if (om_resources[0].xrm_name == NULLQUARK)
- _XlcCompileResourceList(om_resources, XlcNumber(om_resources));
-
- om->core.resources = om_resources;
- om->core.num_resources = XlcNumber(om_resources);
-
- if (init_om(om) == False)
- goto err;
-
- return om;
-err:
- close_om(om);
-
- return (XOM) NULL;
-}
+/*
+Copyright 1985, 1986, 1987, 1991, 1998 The Open Group
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions: The above copyright notice and this
+permission notice shall be included in all copies or substantial
+portions of the Software.
+
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
+EVEN IF ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
+
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+
+X Window System is a trademark of The Open Group
+
+OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
+logo, LBX, X Window System, and Xinerama are trademarks of the Open
+Group. All other trademarks and registered trademarks mentioned herein
+are the property of their respective owners. No right, title or
+interest in or to any trademark, service mark, logo or trade name of
+Sun Microsystems, Inc. or its licensors is granted.
+
+*/
+/*
+ * Copyright 2000 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "XlcPublic.h"
+#include <X11/Xos.h>
+#include <X11/Xatom.h>
+#include <stdio.h>
+#include <stdint.h>
+
+#define MAXFONTS 100
+
+#define XOM_GENERIC(om) (&((XOMGeneric) om)->gen)
+#define XOC_GENERIC(font_set) (&((XOCGeneric) font_set)->gen)
+
+#define DefineLocalBuf char local_buf[BUFSIZ]
+#define AllocLocalBuf(length) (length > BUFSIZ ? (char *)Xmalloc(length) : local_buf)
+#define FreeLocalBuf(ptr) if (ptr != local_buf) Xfree(ptr)
+
+typedef struct _FontDataRec {
+ char *name;
+} FontDataRec, *FontData;
+
+typedef struct _OMDataRec {
+ int font_data_count;
+ FontData font_data;
+} OMDataRec, *OMData;
+
+typedef struct _XOMGenericPart {
+ OMData data;
+} XOMGenericPart;
+
+typedef struct _XOMGenericRec {
+ XOMMethods methods;
+ XOMCoreRec core;
+ XOMGenericPart gen;
+} XOMGenericRec, *XOMGeneric;
+
+typedef struct _FontSetRec {
+ int id;
+ int font_data_count;
+ FontData font_data;
+ char *font_name;
+ XFontStruct *info;
+ XFontStruct *font;
+} FontSetRec, *FontSet;
+
+typedef struct _XOCGenericPart {
+ XlcConv wcs_to_cs;
+ FontSet font_set;
+} XOCGenericPart;
+
+typedef struct _XOCGenericRec {
+ XOCMethods methods;
+ XOCCoreRec core;
+ XOCGenericPart gen;
+} XOCGenericRec, *XOCGeneric;
+
+static Bool
+init_fontset(
+ XOC oc)
+{
+ XOCGenericPart *gen;
+ FontSet font_set;
+ OMData data;
+
+ data = XOM_GENERIC(oc->core.om)->data;
+
+ font_set = Xcalloc(1, sizeof(FontSetRec));
+ if (font_set == NULL)
+ return False;
+
+ gen = XOC_GENERIC(oc);
+ gen->font_set = font_set;
+
+ font_set->font_data_count = data->font_data_count;
+ font_set->font_data = data->font_data;
+
+ return True;
+}
+
+static char *
+get_prop_name(
+ Display *dpy,
+ XFontStruct *fs)
+{
+ unsigned long fp;
+
+ if (XGetFontProperty(fs, XA_FONT, &fp))
+ return XGetAtomName(dpy, fp);
+
+ return (char *) NULL;
+}
+
+static FontData
+check_charset(
+ FontSet font_set,
+ char *font_name)
+{
+ FontData font_data;
+ char *last;
+ int count;
+ ssize_t length, name_len;
+
+ name_len = strlen(font_name);
+ last = font_name + name_len;
+
+ count = font_set->font_data_count;
+ font_data = font_set->font_data;
+
+ for ( ; count-- > 0; font_data++) {
+ length = strlen(font_data->name);
+
+ if (length > name_len)
+ return(NULL);
+
+ if (_XlcCompareISOLatin1(last - length, font_data->name) == 0)
+ return font_data;
+ }
+ return (FontData) NULL;
+}
+
+#if 0 /* Unused */
+static int
+check_fontname(
+ XOC oc,
+ char *name)
+{
+ Display *dpy = oc->core.om->core.display;
+ XOCGenericPart *gen = XOC_GENERIC(oc);
+ FontData data;
+ FontSet font_set;
+ XFontStruct *fs_list;
+ char **fn_list, *fname, *prop_fname = NULL;
+ int list_num, i;
+ int list2_num;
+ char **fn2_list = NULL;
+ int found_num = 0;
+
+ fn_list = XListFonts(dpy, name, MAXFONTS, &list_num);
+ if (fn_list == NULL)
+ return found_num;
+
+ for (i = 0; i < list_num; i++) {
+ fname = fn_list[i];
+
+ font_set = gen->font_set;
+
+ if ((data = check_charset(font_set, fname)) == NULL) {
+ if ((fn2_list = XListFontsWithInfo(dpy, name, MAXFONTS,
+ &list2_num, &fs_list))
+ && (prop_fname = get_prop_name(dpy, fs_list))
+ && (data = check_charset(font_set, prop_fname)))
+ fname = prop_fname;
+ }
+ if (data) {
+ font_set->font_name = strdup(fname);
+ if (font_set->font_name) {
+ found_num++;
+ }
+ }
+ if (fn2_list) {
+ XFreeFontInfo(fn2_list, fs_list, list2_num);
+ fn2_list = NULL;
+ if (prop_fname) {
+ Xfree(prop_fname);
+ prop_fname = NULL;
+ }
+ }
+ if (found_num == 1)
+ break;
+ }
+ XFreeFontNames(fn_list);
+ return found_num;
+}
+#endif
+
+static Bool
+load_font(
+ XOC oc)
+{
+ Display *dpy = oc->core.om->core.display;
+ XOCGenericPart *gen = XOC_GENERIC(oc);
+ FontSet font_set = gen->font_set;
+
+ if (font_set->font_name == NULL)
+ return False;
+
+ if (font_set->font == NULL) {
+ font_set->font = XLoadQueryFont(dpy, font_set->font_name);
+ if (font_set->font == NULL)
+ return False;
+ }
+ return True;
+}
+
+#if 0
+static Bool
+load_font_info(
+ XOC oc)
+{
+ Display *dpy = oc->core.om->core.display;
+ XOCGenericPart *gen = XOC_GENERIC(oc);
+ FontSet font_set = gen->font_set;
+ char **fn_list;
+ int fn_num;
+
+ if (font_set->font_name == NULL)
+ return False;
+
+ if (font_set->info == NULL) {
+ fn_list = XListFontsWithInfo(dpy, font_set->font_name, 1, &fn_num,
+ &font_set->info);
+ if (font_set->info == NULL)
+ return False;
+ if (fn_num > 0)
+ font_set->info->fid = XLoadFont(dpy, font_set->font_name);
+
+ if (fn_list) XFreeFontNames(fn_list);
+ }
+ return True;
+}
+#endif
+
+static void
+set_fontset_extents(
+ XOC oc)
+{
+ XRectangle *ink = &oc->core.font_set_extents.max_ink_extent;
+ XRectangle *logical = &oc->core.font_set_extents.max_logical_extent;
+ XFontStruct **font_list, *font;
+ XCharStruct overall;
+ int logical_ascent, logical_descent;
+
+ font_list = oc->core.font_info.font_struct_list;
+ font = *font_list++;
+ overall = font->max_bounds;
+ overall.lbearing = font->min_bounds.lbearing;
+ logical_ascent = font->ascent;
+ logical_descent = font->descent;
+
+ ink->x = overall.lbearing;
+ ink->y = -(overall.ascent);
+ ink->width = overall.rbearing - overall.lbearing;
+ ink->height = overall.ascent + overall.descent;
+
+ logical->x = 0;
+ logical->y = -(logical_ascent);
+ logical->width = overall.width;
+ logical->height = logical_ascent + logical_descent;
+}
+
+static Bool
+init_core_part(
+ XOC oc)
+{
+ XOCGenericPart *gen = XOC_GENERIC(oc);
+ FontSet font_set;
+ XFontStruct **font_struct_list;
+ char **font_name_list, *font_name_buf;
+ int count, length;
+
+ font_set = gen->font_set;
+ count = length = 0;
+
+ if (font_set->font_name != NULL) {
+ length += strlen(font_set->font_name) + 1;
+ count++;
+ }
+ if (count == 0)
+ return False;
+
+ font_struct_list = (XFontStruct **) Xmalloc(sizeof(XFontStruct *));
+ if (font_struct_list == NULL)
+ return False;
+
+ font_name_list = (char **) Xmalloc(sizeof(char *));
+ if (font_name_list == NULL)
+ goto err;
+
+ font_name_buf = (char *) Xmalloc(length);
+ if (font_name_buf == NULL)
+ goto err;
+
+ oc->core.font_info.num_font = 1;
+ oc->core.font_info.font_name_list = font_name_list;
+ oc->core.font_info.font_struct_list = font_struct_list;
+
+ font_set = gen->font_set;
+
+ if (font_set->font_name != NULL) {
+ font_set->id = 1;
+ if (font_set->font)
+ *font_struct_list++ = font_set->font;
+ else
+ *font_struct_list++ = font_set->info;
+ strcpy(font_name_buf, font_set->font_name);
+ Xfree(font_set->font_name);
+ *font_name_list++ = font_set->font_name = font_name_buf;
+ font_name_buf += strlen(font_name_buf) + 1;
+ }
+
+ set_fontset_extents(oc);
+
+ return True;
+
+err:
+ if (font_name_list)
+ Xfree(font_name_list);
+ Xfree(font_struct_list);
+
+ return False;
+}
+
+static char *
+get_font_name(
+ XOC oc,
+ char *pattern)
+{
+ char **list, *name;
+ int count;
+ XFontStruct *fs;
+ Display *dpy = oc->core.om->core.display;
+
+ list = XListFonts(dpy, pattern, 1, &count);
+ if (list != NULL) {
+ name = strdup(*list);
+
+ XFreeFontNames(list);
+ } else {
+ fs = XLoadQueryFont(dpy, pattern);
+ if (fs == NULL) return NULL;
+
+ name = get_prop_name(dpy, fs);
+ XFreeFont(dpy, fs);
+ }
+ return name;
+}
+
+static int
+parse_fontname(
+ XOC oc)
+{
+ XOCGenericPart *gen = XOC_GENERIC(oc);
+ FontSet font_set;
+ FontData font_data;
+ char *pattern, *last, buf[BUFSIZ];
+ int font_data_count, found_num = 0;
+ ssize_t length;
+ int count, num_fields;
+ char *base_name, *font_name, **name_list, **cur_name_list;
+ char *charset_p = NULL;
+ Bool append_charset;
+ /*
+ append_charset flag should be set to True when the XLFD fontname
+ doesn't contain a chaset part.
+ */
+
+ name_list = _XParseBaseFontNameList(oc->core.base_name_list, &count);
+ if (name_list == NULL)
+ return -1;
+ cur_name_list = name_list;
+
+ while (count-- > 0) {
+ pattern = *cur_name_list++;
+ if (pattern == NULL || *pattern == '\0')
+ continue;
+
+ append_charset = False;
+
+ if (strchr(pattern, '*') == NULL &&
+ (font_name = get_font_name(oc, pattern))) {
+
+ font_set = gen->font_set;
+
+ font_data = check_charset(font_set, font_name);
+ if (font_data == NULL) {
+ Display *dpy = oc->core.om->core.display;
+ char **fn_list = NULL, *prop_fname = NULL;
+ int list_num;
+ XFontStruct *fs_list;
+ if ((fn_list = XListFontsWithInfo(dpy, font_name,
+ MAXFONTS,
+ &list_num, &fs_list))
+ && (prop_fname = get_prop_name(dpy, fs_list))
+ && (font_data = check_charset(font_set, prop_fname))) {
+ if (fn_list) {
+ XFreeFontInfo(fn_list, fs_list, list_num);
+ fn_list = NULL;
+ }
+ font_name = prop_fname;
+ }
+ }
+ if (font_data == NULL)
+ continue;
+
+ font_set->font_name = strdup(font_name);
+ Xfree(font_name);
+ if (font_set->font_name == NULL) {
+ goto err;
+ }
+ found_num++;
+ goto found;
+ }
+/*
+1266793
+Limit the length of the string copy to prevent stack corruption.
+ strcpy(buf, pattern);
+*/
+ strncpy(buf, pattern, BUFSIZ);
+ buf[BUFSIZ-1] = '\0';
+ length = strlen(buf);
+ last = buf + length - 1;
+
+ for (num_fields = 0, base_name = buf; *base_name != '\0'; base_name++)
+ if (*base_name == '-') num_fields++;
+ if (strchr(pattern, '*') == NULL) {
+ if (num_fields == 12) {
+ append_charset = True;
+ *++last = '-';
+ last++;
+ } else
+ continue;
+ } else {
+ if (num_fields == 13 || num_fields == 14) {
+ /*
+ * There are 14 fields in an XLFD name -- make certain the
+ * charset (& encoding) is placed in the correct field.
+ */
+ append_charset = True;
+ last = strrchr (buf, '-');
+ if (num_fields == 14) {
+ *last = '\0';
+ last = strrchr (buf, '-');
+ }
+ last++;
+ } else if (*last == '*') {
+ append_charset = True;
+ if (length > 3 && *(last-3) == '-' && *(last-2) == '*'
+ && *(last-1) == '-') {
+ last -= 2;
+ }
+ *++last = '-';
+ last++;
+ } else {
+ last = strrchr (buf, '-');
+ charset_p = last;
+ charset_p = strrchr (buf, '-');
+ while (*(--charset_p) != '-');
+ charset_p++;
+ }
+ }
+
+ font_set = gen->font_set;
+
+ font_data = font_set->font_data;
+ font_data_count = font_set->font_data_count;
+ for ( ; font_data_count-- > 0; font_data++) {
+ if (append_charset)
+ {
+/*
+1266793
+Limit the length of the string copy to prevent stack corruption.
+ strcpy(last, font_data->name);
+*/
+ strncpy(last, font_data->name, BUFSIZ - length);
+ buf[BUFSIZ-1] = '\0';
+ }
+ else {
+ if (_XlcCompareISOLatin1(charset_p,
+ font_data->name)) {
+ continue;
+ }
+ }
+ if ((font_set->font_name = get_font_name(oc, buf)))
+ break;
+ }
+ if (font_set->font_name != NULL) {
+ found_num++;
+ goto found;
+ }
+ }
+ found:
+ base_name = strdup(oc->core.base_name_list);
+ if (base_name == NULL)
+ goto err;
+
+ oc->core.base_name_list = base_name;
+
+ XFreeStringList(name_list);
+
+ return found_num;
+err:
+ XFreeStringList(name_list);
+
+ return -1;
+}
+
+static Bool
+set_missing_list(
+ XOC oc)
+{
+ XOCGenericPart *gen = XOC_GENERIC(oc);
+ FontSet font_set;
+ char **charset_list, *charset_buf;
+ int count, length;
+
+ font_set = gen->font_set;
+ count = length = 0;
+
+ if (!font_set->info && !font_set->font) {
+ length += strlen(font_set->font_data->name) + 1;
+ count++;
+ }
+
+ if (count == 0)
+ return True;
+
+ charset_list = (char **) Xmalloc(sizeof(char *));
+ if (charset_list == NULL)
+ return False;
+
+ charset_buf = (char *) Xmalloc(length);
+ if (charset_buf == NULL) {
+ Xfree(charset_list);
+ return False;
+ }
+
+ oc->core.missing_list.charset_list = charset_list;
+
+ font_set = gen->font_set;
+
+ if (!font_set->info && !font_set->font) {
+ strcpy(charset_buf, font_set->font_data->name);
+ *charset_list++ = charset_buf;
+ charset_buf += strlen(charset_buf) + 1;
+ }
+ return True;
+}
+
+static Bool
+create_fontset(
+ XOC oc)
+{
+ int found_num;
+
+ if (init_fontset(oc) == False)
+ return False;
+
+ found_num = parse_fontname(oc);
+ if (found_num <= 0) {
+ if (found_num == 0)
+ set_missing_list(oc);
+ return False;
+ }
+
+ if (load_font(oc) == False)
+ return False;
+
+ if (init_core_part(oc) == False)
+ return False;
+
+ if (set_missing_list(oc) == False)
+ return False;
+
+ return True;
+}
+
+static void
+destroy_oc(
+ XOC oc)
+{
+ Display *dpy = oc->core.om->core.display;
+ XOCGenericPart *gen = XOC_GENERIC(oc);
+ XFontStruct **font_list, *font;
+
+ if (gen->font_set)
+ Xfree(gen->font_set);
+
+ if (oc->core.base_name_list)
+ Xfree(oc->core.base_name_list);
+
+ if (oc->core.font_info.font_name_list)
+ XFreeStringList(oc->core.font_info.font_name_list);
+
+ if ((font_list = oc->core.font_info.font_struct_list)) {
+ if ((font = *font_list)) {
+ if (font->fid)
+ XFreeFont(dpy, font);
+ else
+ XFreeFontInfo(NULL, font, 1);
+ }
+ Xfree(oc->core.font_info.font_struct_list);
+ }
+
+ if (oc->core.missing_list.charset_list)
+ XFreeStringList(oc->core.missing_list.charset_list);
+
+#ifdef notdef
+ if (oc->core.res_name)
+ Xfree(oc->core.res_name);
+ if (oc->core.res_class)
+ Xfree(oc->core.res_class);
+#endif
+
+ Xfree(oc);
+}
+
+static char *
+set_oc_values(
+ XOC oc,
+ XlcArgList args,
+ int num_args)
+{
+ if (oc->core.resources == NULL)
+ return NULL;
+
+ return _XlcSetValues((XPointer) oc, oc->core.resources,
+ oc->core.num_resources, args, num_args, XlcSetMask);
+}
+
+static char *
+get_oc_values(
+ XOC oc,
+ XlcArgList args,
+ int num_args)
+{
+ if (oc->core.resources == NULL)
+ return NULL;
+
+ return _XlcGetValues((XPointer) oc, oc->core.resources,
+ oc->core.num_resources, args, num_args, XlcGetMask);
+}
+
+static Bool
+wcs_to_mbs(
+ XOC oc,
+ char *to,
+ _Xconst wchar_t *from,
+ int length)
+{
+ XlcConv conv = XOC_GENERIC(oc)->wcs_to_cs;
+ XLCd lcd;
+ int ret, to_left = length;
+
+ if (conv == NULL) {
+ lcd = oc->core.om->core.lcd;
+ conv = _XlcOpenConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte);
+ if (conv == NULL)
+ return False;
+ XOC_GENERIC(oc)->wcs_to_cs = conv;
+ } else
+ _XlcResetConverter(conv);
+
+ ret = _XlcConvert(conv, (XPointer *) &from, &length, (XPointer *) &to,
+ &to_left, NULL, 0);
+ if (ret != 0 || length > 0)
+ return False;
+
+ return True;
+}
+
+static int
+_XmbDefaultTextEscapement(XOC oc, _Xconst char *text, int length)
+{
+ return XTextWidth(*oc->core.font_info.font_struct_list, text, length);
+}
+
+static int
+_XwcDefaultTextEscapement(XOC oc, _Xconst wchar_t *text, int length)
+{
+ DefineLocalBuf;
+ char *buf = AllocLocalBuf(length);
+ int ret = 0;
+
+ if (buf == NULL)
+ return 0;
+
+ if (wcs_to_mbs(oc, buf, text, length) == False)
+ goto err;
+
+ ret = _XmbDefaultTextEscapement(oc, buf, length);
+
+err:
+ FreeLocalBuf(buf);
+
+ return ret;
+}
+
+static int
+_XmbDefaultTextExtents(XOC oc, _Xconst char *text, int length,
+ XRectangle *overall_ink, XRectangle *overall_logical)
+{
+ int direction, logical_ascent, logical_descent;
+ XCharStruct overall;
+
+ XTextExtents(*oc->core.font_info.font_struct_list, text, length, &direction,
+ &logical_ascent, &logical_descent, &overall);
+
+ if (overall_ink) {
+ overall_ink->x = overall.lbearing;
+ overall_ink->y = -(overall.ascent);
+ overall_ink->width = overall.rbearing - overall.lbearing;
+ overall_ink->height = overall.ascent + overall.descent;
+ }
+
+ if (overall_logical) {
+ overall_logical->x = 0;
+ overall_logical->y = -(logical_ascent);
+ overall_logical->width = overall.width;
+ overall_logical->height = logical_ascent + logical_descent;
+ }
+
+ return overall.width;
+}
+
+static int
+_XwcDefaultTextExtents(XOC oc, _Xconst wchar_t *text, int length,
+ XRectangle *overall_ink, XRectangle *overall_logical)
+{
+ DefineLocalBuf;
+ char *buf = AllocLocalBuf(length);
+ int ret = 0;
+
+ if (buf == NULL)
+ return 0;
+
+ if (wcs_to_mbs(oc, buf, text, length) == False)
+ goto err;
+
+ ret = _XmbDefaultTextExtents(oc, buf, length, overall_ink, overall_logical);
+
+err:
+ FreeLocalBuf(buf);
+
+ return ret;
+}
+
+static Status
+_XmbDefaultTextPerCharExtents(XOC oc, _Xconst char *text, int length,
+ XRectangle *ink_buf, XRectangle *logical_buf,
+ int buf_size, int *num_chars,
+ XRectangle *overall_ink,
+ XRectangle *overall_logical)
+{
+ XFontStruct *font = *oc->core.font_info.font_struct_list;
+ XCharStruct *def, *cs, overall;
+ Bool first = True;
+
+ if (buf_size < length)
+ return 0;
+
+ bzero((char *) &overall, sizeof(XCharStruct));
+ *num_chars = 0;
+
+ CI_GET_DEFAULT_INFO_1D(font, def)
+
+ while (length-- > 0) {
+ CI_GET_CHAR_INFO_1D(font, *text, def, cs)
+ text++;
+ if (cs == NULL)
+ continue;
+
+ ink_buf->x = overall.width + cs->lbearing;
+ ink_buf->y = -(cs->ascent);
+ ink_buf->width = cs->rbearing - cs->lbearing;
+ ink_buf->height = cs->ascent + cs->descent;
+ ink_buf++;
+
+ logical_buf->x = overall.width;
+ logical_buf->y = -(font->ascent);
+ logical_buf->width = cs->width;
+ logical_buf->height = font->ascent + font->descent;
+ logical_buf++;
+
+ if (first) {
+ overall = *cs;
+ first = False;
+ } else {
+ overall.ascent = max(overall.ascent, cs->ascent);
+ overall.descent = max(overall.descent, cs->descent);
+ overall.lbearing = min(overall.lbearing, overall.width +
+ cs->lbearing);
+ overall.rbearing = max(overall.rbearing, overall.width +
+ cs->rbearing);
+ overall.width += cs->width;
+ }
+ (*num_chars)++;
+ }
+
+ if (overall_ink) {
+ overall_ink->x = overall.lbearing;
+ overall_ink->y = -(overall.ascent);
+ overall_ink->width = overall.rbearing - overall.lbearing;
+ overall_ink->height = overall.ascent + overall.descent;
+ }
+
+ if (overall_logical) {
+ overall_logical->x = 0;
+ overall_logical->y = -(font->ascent);
+ overall_logical->width = overall.width;
+ overall_logical->height = font->ascent + font->descent;
+ }
+
+ return 1;
+}
+
+static Status
+_XwcDefaultTextPerCharExtents(XOC oc, _Xconst wchar_t *text, int length,
+ XRectangle *ink_buf, XRectangle *logical_buf,
+ int buf_size, int *num_chars,
+ XRectangle *overall_ink,
+ XRectangle *overall_logical)
+{
+ DefineLocalBuf;
+ char *buf = AllocLocalBuf(length);
+ Status ret = 0;
+
+ if (buf == NULL)
+ return 0;
+
+ if (wcs_to_mbs(oc, buf, text, length) == False)
+ goto err;
+
+ ret = _XmbDefaultTextPerCharExtents(oc, buf, length, ink_buf, logical_buf,
+ buf_size, num_chars, overall_ink,
+ overall_logical);
+
+err:
+ FreeLocalBuf(buf);
+
+ return ret;
+}
+
+static int
+_XmbDefaultDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
+ _Xconst char *text, int length)
+{
+ XFontStruct *font = *oc->core.font_info.font_struct_list;
+
+ XSetFont(dpy, gc, font->fid);
+ XDrawString(dpy, d, gc, x, y, text, length);
+
+ return XTextWidth(font, text, length);
+}
+
+static int
+_XwcDefaultDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
+ _Xconst wchar_t *text, int length)
+{
+ DefineLocalBuf;
+ char *buf = AllocLocalBuf(length);
+ int ret = 0;
+
+ if (buf == NULL)
+ return 0;
+
+ if (wcs_to_mbs(oc, buf, text, length) == False)
+ goto err;
+
+ ret = _XmbDefaultDrawString(dpy, d, oc, gc, x, y, buf, length);
+
+err:
+ FreeLocalBuf(buf);
+
+ return ret;
+}
+
+static void
+_XmbDefaultDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
+ int y, _Xconst char *text, int length)
+{
+ XSetFont(dpy, gc, (*oc->core.font_info.font_struct_list)->fid);
+ XDrawImageString(dpy, d, gc, x, y, text, length);
+}
+
+static void
+_XwcDefaultDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
+ int y, _Xconst wchar_t *text, int length)
+{
+ DefineLocalBuf;
+ char *buf = AllocLocalBuf(length);
+
+ if (buf == NULL)
+ return;
+
+ if (wcs_to_mbs(oc, buf, text, length) == False)
+ goto err;
+
+ _XmbDefaultDrawImageString(dpy, d, oc, gc, x, y, buf, length);
+
+err:
+ FreeLocalBuf(buf);
+}
+
+static _Xconst XOCMethodsRec oc_default_methods = {
+ destroy_oc,
+ set_oc_values,
+ get_oc_values,
+ _XmbDefaultTextEscapement,
+ _XmbDefaultTextExtents,
+ _XmbDefaultTextPerCharExtents,
+ _XmbDefaultDrawString,
+ _XmbDefaultDrawImageString,
+ _XwcDefaultTextEscapement,
+ _XwcDefaultTextExtents,
+ _XwcDefaultTextPerCharExtents,
+ _XwcDefaultDrawString,
+ _XwcDefaultDrawImageString
+};
+
+static XlcResource oc_resources[] = {
+ { XNBaseFontName, NULLQUARK, sizeof(char *),
+ XOffsetOf(XOCRec, core.base_name_list), XlcCreateMask | XlcGetMask },
+ { XNOMAutomatic, NULLQUARK, sizeof(Bool),
+ XOffsetOf(XOCRec, core.om_automatic), XlcGetMask },
+ { XNMissingCharSet, NULLQUARK, sizeof(XOMCharSetList),
+ XOffsetOf(XOCRec, core.missing_list), XlcGetMask },
+ { XNDefaultString, NULLQUARK, sizeof(char *),
+ XOffsetOf(XOCRec, core.default_string), XlcGetMask },
+ { XNOrientation, NULLQUARK, sizeof(XOrientation),
+ XOffsetOf(XOCRec, core.orientation), XlcSetMask | XlcGetMask },
+ { XNResourceName, NULLQUARK, sizeof(char *),
+ XOffsetOf(XOCRec, core.res_name), XlcSetMask | XlcGetMask },
+ { XNResourceClass, NULLQUARK, sizeof(char *),
+ XOffsetOf(XOCRec, core.res_class), XlcSetMask | XlcGetMask },
+ { XNFontInfo, NULLQUARK, sizeof(XOMFontInfo),
+ XOffsetOf(XOCRec, core.font_info), XlcGetMask }
+};
+
+static XOC
+create_oc(
+ XOM om,
+ XlcArgList args,
+ int num_args)
+{
+ XOC oc;
+
+ oc = Xcalloc(1, sizeof(XOCGenericRec));
+ if (oc == NULL)
+ return (XOC) NULL;
+
+ oc->core.om = om;
+
+ if (oc_resources[0].xrm_name == NULLQUARK)
+ _XlcCompileResourceList(oc_resources, XlcNumber(oc_resources));
+
+ if (_XlcSetValues((XPointer) oc, oc_resources, XlcNumber(oc_resources),
+ args, num_args, XlcCreateMask | XlcDefaultMask))
+ goto err;
+
+ if (oc->core.base_name_list == NULL)
+ goto err;
+
+ oc->core.resources = oc_resources;
+ oc->core.num_resources = XlcNumber(oc_resources);
+
+ if (create_fontset(oc) == False)
+ goto err;
+
+ oc->methods = (XOCMethods)&oc_default_methods;
+
+ return oc;
+
+err:
+ destroy_oc(oc);
+
+ return (XOC) NULL;
+}
+
+static Status
+close_om(
+ XOM om)
+{
+ XOMGenericPart *gen = XOM_GENERIC(om);
+ OMData data;
+ FontData font_data;
+ int count;
+
+ if ((data = gen->data)) {
+ if (data->font_data) {
+ for (font_data = data->font_data, count = data->font_data_count;
+ count-- > 0 ; font_data++) {
+ if (font_data->name)
+ Xfree(font_data->name);
+ }
+ Xfree(data->font_data);
+ }
+ Xfree(gen->data);
+ }
+
+ if (om->core.res_name)
+ Xfree(om->core.res_name);
+ if (om->core.res_class)
+ Xfree(om->core.res_class);
+ if (om->core.required_charset.charset_list)
+ XFreeStringList(om->core.required_charset.charset_list);
+ else
+ Xfree((char*)om->core.required_charset.charset_list);
+ if (om->core.orientation_list.orientation)
+ Xfree(om->core.orientation_list.orientation);
+
+ Xfree(om);
+
+ return 1;
+}
+
+static char *
+set_om_values(
+ XOM om,
+ XlcArgList args,
+ int num_args)
+{
+ if (om->core.resources == NULL)
+ return NULL;
+
+ return _XlcSetValues((XPointer) om, om->core.resources,
+ om->core.num_resources, args, num_args, XlcSetMask);
+}
+
+static char *
+get_om_values(
+ XOM om,
+ XlcArgList args,
+ int num_args)
+{
+ if (om->core.resources == NULL)
+ return NULL;
+
+ return _XlcGetValues((XPointer) om, om->core.resources,
+ om->core.num_resources, args, num_args, XlcGetMask);
+}
+
+static _Xconst XOMMethodsRec methods = {
+ close_om,
+ set_om_values,
+ get_om_values,
+ create_oc
+};
+
+static XlcResource om_resources[] = {
+ { XNRequiredCharSet, NULLQUARK, sizeof(XOMCharSetList),
+ XOffsetOf(XOMRec, core.required_charset), XlcGetMask },
+ { XNQueryOrientation, NULLQUARK, sizeof(XOMOrientation),
+ XOffsetOf(XOMRec, core.orientation_list), XlcGetMask },
+ { XNDirectionalDependentDrawing, NULLQUARK, sizeof(Bool),
+ XOffsetOf(XOMRec, core.directional_dependent), XlcGetMask },
+ { XNContextualDrawing, NULLQUARK, sizeof(Bool),
+ XOffsetOf(XOMRec, core.contextual_drawing), XlcGetMask }
+};
+
+static OMData
+add_data(
+ XOM om)
+{
+ XOMGenericPart *gen = XOM_GENERIC(om);
+ OMData new;
+
+ new = Xcalloc(1, sizeof(OMDataRec));
+
+ if (new == NULL)
+ return NULL;
+
+ gen->data = new;
+
+ return new;
+}
+
+static _Xconst char *supported_charset_list[] = {
+ "ISO8859-1",
+/* fix for bug4332979 */
+ "adobe-fontspecific",
+/* fix for bug4237353: "JISX0201.1976-0" entry should be removed from
+ supported_charset_list because it is not a supported_charset for C locale
+ "JISX0201.1976-0", */
+ "SUNOLCURSOR-1",
+ "SUNOLGLYPH-1"
+};
+
+static Bool
+init_om(
+ XOM om)
+{
+ XOMGenericPart *gen = XOM_GENERIC(om);
+ OMData data;
+ FontData font_data;
+ char **required_list;
+ XOrientation *orientation;
+ char **value, buf[BUFSIZ], *bufptr;
+ int count, length = 0;
+
+ value = (char**)supported_charset_list;
+ count = XlcNumber(supported_charset_list);
+
+ data = add_data(om);
+ if (data == NULL)
+ return False;
+
+ font_data = Xcalloc(count, sizeof(FontDataRec));
+ if (font_data == NULL)
+ return False;
+ data->font_data = font_data;
+ data->font_data_count = count;
+
+ for ( ; count-- > 0; font_data++) {
+/*
+1266793
+This one is fine. *value points to one of the local strings in
+supported_charset_list[].
+*/
+ strcpy(buf, *value++);
+ font_data->name = strdup(buf);
+ if (font_data->name == NULL)
+ return False;
+ }
+
+ length += strlen(data->font_data->name) + 1;
+
+ /* required charset list */
+ required_list = (char **) Xmalloc(sizeof(char *));
+ if (required_list == NULL)
+ return False;
+
+ bufptr = (char *) Xmalloc(length);
+ if (bufptr == NULL) {
+ Xfree(required_list);
+ return False;
+ }
+
+ om->core.required_charset.charset_list = required_list;
+ om->core.required_charset.charset_count = 1; /* always 1 */
+
+ data = gen->data;
+
+ strcpy(bufptr, data->font_data->name);
+ *required_list++ = bufptr;
+ bufptr += strlen(bufptr) + 1;
+
+ /* orientation list */
+ orientation = (XOrientation *) Xmalloc(sizeof(XOrientation));
+ if (orientation == NULL)
+ return False;
+
+ *orientation = XOMOrientation_LTR_TTB;
+ om->core.orientation_list.orientation = orientation;
+ om->core.orientation_list.num_orientation = 1;
+
+ /* directional dependent drawing */
+ om->core.directional_dependent = False;
+
+ /* contexual drawing */
+ om->core.contextual_drawing = False;
+
+ /* context dependent */
+ om->core.context_dependent = False;
+
+ return True;
+}
+
+XOM
+_XDefaultOpenOM(XLCd lcd, Display *dpy, XrmDatabase rdb,
+ _Xconst char *res_name, _Xconst char *res_class)
+{
+ XOM om;
+
+ om = Xcalloc(1, sizeof(XOMGenericRec));
+ if (om == NULL)
+ return (XOM) NULL;
+
+ om->methods = (XOMMethods)&methods;
+ om->core.lcd = lcd;
+ om->core.display = dpy;
+ om->core.rdb = rdb;
+ if (res_name) {
+ om->core.res_name = strdup(res_name);
+ if (om->core.res_name == NULL)
+ goto err;
+ }
+ if (res_class) {
+ om->core.res_class = strdup(res_class);
+ if (om->core.res_class == NULL)
+ goto err;
+ }
+
+ if (om_resources[0].xrm_name == NULLQUARK)
+ _XlcCompileResourceList(om_resources, XlcNumber(om_resources));
+
+ om->core.resources = om_resources;
+ om->core.num_resources = XlcNumber(om_resources);
+
+ if (init_om(om) == False)
+ goto err;
+
+ return om;
+err:
+ close_om(om);
+
+ return (XOM) NULL;
+}
diff --git a/libX11/src/xlibi18n/XlcDL.c b/libX11/src/xlibi18n/XlcDL.c
index 58e9ade87..4a05c40e4 100644
--- a/libX11/src/xlibi18n/XlcDL.c
+++ b/libX11/src/xlibi18n/XlcDL.c
@@ -86,16 +86,6 @@ Sun Microsystems, Inc. or its licensors is granted.
#include "XlcPublic.h"
#include "XlcPubI.h"
-#if defined(_LP64) && defined(__sparcv9)
-# define _MACH64_NAME "sparcv9"
-#else
-# undef _MACH64_NAME
-#endif /* defined(_LP64) && defined(__sparcv9) */
-
-#ifdef _MACH64_NAME
-# define _MACH64_NAME_LEN (sizeof (_MACH64_NAME) - 1)
-#endif
-
#define XI18N_DLREL 2
#define iscomment(ch) ((ch) == '\0' || (ch) == '#')
@@ -269,35 +259,6 @@ __lc_path(const char *dl_name, const char *lc_dir)
if (strstr (dl_name, "../"))
return NULL;
-#if defined (_LP64) && defined (_MACH64_NAME)
- len = (lc_dir ? strlen(lc_dir) : 0 ) +
- (dl_name ? strlen(dl_name) : 0) + _MACH64_NAME_LEN + 10;
- path = Xmalloc(len + 1);
-
- if (strchr(dl_name, '/') != NULL) {
- char *tmp = strdup(dl_name);
- char *dl_dir, *dl_file;
- char *slash_p;
- slash_p = strchr(tmp, '/');
- *slash_p = '\0';
- dl_dir = tmp;
- dl_file = ++slash_p;
-
- slash_p = strrchr(lc_dir, '/');
- *slash_p = '\0';
- strcpy(path, lc_dir); strcat(path, "/");
- strcat(path, dl_dir); strcat(path, "/");
- strcat(path, _MACH64_NAME); strcat(path, "/");
- strcat(path, dl_file); strcat(path, ".so.2");
-
- *slash_p = '/';
- Xfree(tmp);
- } else {
- strcpy(path, lc_dir); strcat(path, "/");
- strcat(path, _MACH64_NAME); strcat(path, "/");
- strcat(path, dl_name); strcat(path, ".so.2");
- }
-#else
len = (lc_dir ? strlen(lc_dir) : 0 ) +
(dl_name ? strlen(dl_name) : 0) + 10;
#if defined POSTLOCALELIBDIR
@@ -322,7 +283,6 @@ __lc_path(const char *dl_name, const char *lc_dir)
#endif
strcat(path, dl_name); strcat(path, ".so.2");
}
-#endif
return path;
}
diff --git a/libX11/src/xlibi18n/lcCharSet.c b/libX11/src/xlibi18n/lcCharSet.c
index 0fa39d869..6be5f5d16 100644
--- a/libX11/src/xlibi18n/lcCharSet.c
+++ b/libX11/src/xlibi18n/lcCharSet.c
@@ -1,226 +1,225 @@
-/*
- * Copyright 1992, 1993 by TOSHIBA Corp.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of TOSHIBA not be used in advertising
- * or publicity pertaining to distribution of the software without specific,
- * written prior permission. TOSHIBA make no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
- * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- *
- * Author: Katsuhisa Yano TOSHIBA Corp.
- * mopi@osa.ilab.toshiba.co.jp
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include "Xlibint.h"
-#include "XlcPublic.h"
-#include "XlcPubI.h"
-
-/* The list of all known XlcCharSets. They are identified by their name. */
-
-typedef struct _XlcCharSetListRec {
- XlcCharSet charset;
- struct _XlcCharSetListRec *next;
-} XlcCharSetListRec, *XlcCharSetList;
-
-static XlcCharSetList charset_list = NULL;
-
-/* Returns the charset with the given name (including side suffix).
- Returns NULL if not found. */
-XlcCharSet
-_XlcGetCharSet(
- const char *name)
-{
- XlcCharSetList list;
- XrmQuark xrm_name;
-
- xrm_name = XrmStringToQuark(name);
-
- for (list = charset_list; list; list = list->next) {
- if (xrm_name == list->charset->xrm_name)
- return (XlcCharSet) list->charset;
- }
-
- return (XlcCharSet) NULL;
-}
-
-/* Returns the charset with the given encoding (no side suffix) and
- responsible for at least the given side (XlcGL or XlcGR).
- Returns NULL if not found. */
-XlcCharSet
-_XlcGetCharSetWithSide(
- const char *encoding_name,
- XlcSide side)
-{
- XlcCharSetList list;
- XrmQuark xrm_encoding_name;
-
- xrm_encoding_name = XrmStringToQuark(encoding_name);
-
- for (list = charset_list; list; list = list->next) {
- if (list->charset->xrm_encoding_name == xrm_encoding_name
- && (list->charset->side == XlcGLGR || list->charset->side == side))
- return (XlcCharSet) list->charset;
- }
-
- return (XlcCharSet) NULL;
-}
-
-/* Registers an XlcCharSet in the list of character sets.
- Returns True if successful. */
-Bool
-_XlcAddCharSet(
- XlcCharSet charset)
-{
- XlcCharSetList list;
-
- if (_XlcGetCharSet(charset->name))
- return False;
-
- list = (XlcCharSetList) Xmalloc(sizeof(XlcCharSetListRec));
- if (list == NULL)
- return False;
-
- list->charset = charset;
- list->next = charset_list;
- charset_list = list;
-
- return True;
-}
-
-/* List of resources for XlcCharSet. */
-static XlcResource resources[] = {
- { XlcNName, NULLQUARK, sizeof(char *),
- XOffsetOf(XlcCharSetRec, name), XlcGetMask },
- { XlcNEncodingName, NULLQUARK, sizeof(char *),
- XOffsetOf(XlcCharSetRec, encoding_name), XlcGetMask },
- { XlcNSide, NULLQUARK, sizeof(XlcSide),
- XOffsetOf(XlcCharSetRec, side), XlcGetMask },
- { XlcNCharSize, NULLQUARK, sizeof(int),
- XOffsetOf(XlcCharSetRec, char_size), XlcGetMask },
- { XlcNSetSize, NULLQUARK, sizeof(int),
- XOffsetOf(XlcCharSetRec, set_size), XlcGetMask },
- { XlcNControlSequence, NULLQUARK, sizeof(char *),
- XOffsetOf(XlcCharSetRec, ct_sequence), XlcGetMask }
-};
-
-/* Retrieves a number of attributes of an XlcCharSet.
- Return NULL if successful, otherwise the name of the first argument
- specifiying a nonexistent attribute. */
-static char *
-get_values(
- XlcCharSet charset,
- XlcArgList args,
- int num_args)
-{
- if (resources[0].xrm_name == NULLQUARK)
- _XlcCompileResourceList(resources, XlcNumber(resources));
-
- return _XlcGetValues((XPointer) charset, resources, XlcNumber(resources),
- args, num_args, XlcGetMask);
-}
-
-/* Retrieves a number of attributes of an XlcCharSet.
- Return NULL if successful, otherwise the name of the first argument
- specifiying a nonexistent attribute. */
-char *
-_XlcGetCSValues(XlcCharSet charset, ...)
-{
- va_list var;
- XlcArgList args;
- char *ret;
- int num_args;
-
- va_start(var, charset);
- _XlcCountVaList(var, &num_args);
- va_end(var);
-
- va_start(var, charset);
- _XlcVaToArgList(var, num_args, &args);
- va_end(var);
-
- if (args == (XlcArgList) NULL)
- return (char *) NULL;
-
- ret = get_values(charset, args, num_args);
-
- Xfree(args);
-
- return ret;
-}
-
-/* Creates a new XlcCharSet, given its name (including side suffix) and
- Compound Text ESC sequence (normally at most 4 bytes). */
-XlcCharSet
-_XlcCreateDefaultCharSet(
- const char *name,
- const char *ct_sequence)
-{
- XlcCharSet charset;
- int name_len, ct_sequence_len;
- const char *colon;
- char *tmp;
-
- charset = (XlcCharSet) Xmalloc(sizeof(XlcCharSetRec));
- if (charset == NULL)
- return (XlcCharSet) NULL;
- bzero((char *) charset, sizeof(XlcCharSetRec));
-
- name_len = strlen(name);
- ct_sequence_len = strlen(ct_sequence);
-
- /* Fill in name and xrm_name. */
- tmp = (char *) Xmalloc(name_len + 1 + ct_sequence_len + 1);
- if (tmp == NULL) {
- Xfree((char *) charset);
- return (XlcCharSet) NULL;
- }
- memcpy(tmp, name, name_len+1);
- charset->name = tmp;
- charset->xrm_name = XrmStringToQuark(charset->name);
-
- /* Fill in encoding_name and xrm_encoding_name. */
- if ((colon = strchr(charset->name, ':')) != NULL) {
- unsigned int length = colon - charset->name;
- char *encoding_tmp = (char *) Xmalloc(length + 1);
- if (encoding_tmp == NULL) {
- Xfree((char *) charset->name);
- Xfree((char *) charset);
- return (XlcCharSet) NULL;
- }
- memcpy(encoding_tmp, charset->name, length);
- encoding_tmp[length] = '\0';
- charset->encoding_name = encoding_tmp;
- charset->xrm_encoding_name = XrmStringToQuark(charset->encoding_name);
- } else {
- charset->encoding_name = charset->name;
- charset->xrm_encoding_name = charset->xrm_name;
- }
-
- /* Fill in ct_sequence. */
- tmp += name_len + 1;
- memcpy(tmp, ct_sequence, ct_sequence_len+1);
- charset->ct_sequence = tmp;
-
- /* Fill in side, char_size, set_size. */
- if (!_XlcParseCharSet(charset))
- /* If ct_sequence is not usable in Compound Text, remove it. */
- charset->ct_sequence = "";
-
- return (XlcCharSet) charset;
-}
+/*
+ * Copyright 1992, 1993 by TOSHIBA Corp.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of TOSHIBA not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission. TOSHIBA make no representations about the
+ * suitability of this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+ * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Author: Katsuhisa Yano TOSHIBA Corp.
+ * mopi@osa.ilab.toshiba.co.jp
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include "Xlibint.h"
+#include "XlcPublic.h"
+#include "XlcPubI.h"
+
+/* The list of all known XlcCharSets. They are identified by their name. */
+
+typedef struct _XlcCharSetListRec {
+ XlcCharSet charset;
+ struct _XlcCharSetListRec *next;
+} XlcCharSetListRec, *XlcCharSetList;
+
+static XlcCharSetList charset_list = NULL;
+
+/* Returns the charset with the given name (including side suffix).
+ Returns NULL if not found. */
+XlcCharSet
+_XlcGetCharSet(
+ const char *name)
+{
+ XlcCharSetList list;
+ XrmQuark xrm_name;
+
+ xrm_name = XrmStringToQuark(name);
+
+ for (list = charset_list; list; list = list->next) {
+ if (xrm_name == list->charset->xrm_name)
+ return (XlcCharSet) list->charset;
+ }
+
+ return (XlcCharSet) NULL;
+}
+
+/* Returns the charset with the given encoding (no side suffix) and
+ responsible for at least the given side (XlcGL or XlcGR).
+ Returns NULL if not found. */
+XlcCharSet
+_XlcGetCharSetWithSide(
+ const char *encoding_name,
+ XlcSide side)
+{
+ XlcCharSetList list;
+ XrmQuark xrm_encoding_name;
+
+ xrm_encoding_name = XrmStringToQuark(encoding_name);
+
+ for (list = charset_list; list; list = list->next) {
+ if (list->charset->xrm_encoding_name == xrm_encoding_name
+ && (list->charset->side == XlcGLGR || list->charset->side == side))
+ return (XlcCharSet) list->charset;
+ }
+
+ return (XlcCharSet) NULL;
+}
+
+/* Registers an XlcCharSet in the list of character sets.
+ Returns True if successful. */
+Bool
+_XlcAddCharSet(
+ XlcCharSet charset)
+{
+ XlcCharSetList list;
+
+ if (_XlcGetCharSet(charset->name))
+ return False;
+
+ list = (XlcCharSetList) Xmalloc(sizeof(XlcCharSetListRec));
+ if (list == NULL)
+ return False;
+
+ list->charset = charset;
+ list->next = charset_list;
+ charset_list = list;
+
+ return True;
+}
+
+/* List of resources for XlcCharSet. */
+static XlcResource resources[] = {
+ { XlcNName, NULLQUARK, sizeof(char *),
+ XOffsetOf(XlcCharSetRec, name), XlcGetMask },
+ { XlcNEncodingName, NULLQUARK, sizeof(char *),
+ XOffsetOf(XlcCharSetRec, encoding_name), XlcGetMask },
+ { XlcNSide, NULLQUARK, sizeof(XlcSide),
+ XOffsetOf(XlcCharSetRec, side), XlcGetMask },
+ { XlcNCharSize, NULLQUARK, sizeof(int),
+ XOffsetOf(XlcCharSetRec, char_size), XlcGetMask },
+ { XlcNSetSize, NULLQUARK, sizeof(int),
+ XOffsetOf(XlcCharSetRec, set_size), XlcGetMask },
+ { XlcNControlSequence, NULLQUARK, sizeof(char *),
+ XOffsetOf(XlcCharSetRec, ct_sequence), XlcGetMask }
+};
+
+/* Retrieves a number of attributes of an XlcCharSet.
+ Return NULL if successful, otherwise the name of the first argument
+ specifiying a nonexistent attribute. */
+static char *
+get_values(
+ XlcCharSet charset,
+ XlcArgList args,
+ int num_args)
+{
+ if (resources[0].xrm_name == NULLQUARK)
+ _XlcCompileResourceList(resources, XlcNumber(resources));
+
+ return _XlcGetValues((XPointer) charset, resources, XlcNumber(resources),
+ args, num_args, XlcGetMask);
+}
+
+/* Retrieves a number of attributes of an XlcCharSet.
+ Return NULL if successful, otherwise the name of the first argument
+ specifiying a nonexistent attribute. */
+char *
+_XlcGetCSValues(XlcCharSet charset, ...)
+{
+ va_list var;
+ XlcArgList args;
+ char *ret;
+ int num_args;
+
+ va_start(var, charset);
+ _XlcCountVaList(var, &num_args);
+ va_end(var);
+
+ va_start(var, charset);
+ _XlcVaToArgList(var, num_args, &args);
+ va_end(var);
+
+ if (args == (XlcArgList) NULL)
+ return (char *) NULL;
+
+ ret = get_values(charset, args, num_args);
+
+ Xfree(args);
+
+ return ret;
+}
+
+/* Creates a new XlcCharSet, given its name (including side suffix) and
+ Compound Text ESC sequence (normally at most 4 bytes). */
+XlcCharSet
+_XlcCreateDefaultCharSet(
+ const char *name,
+ const char *ct_sequence)
+{
+ XlcCharSet charset;
+ int name_len, ct_sequence_len;
+ const char *colon;
+ char *tmp;
+
+ charset = Xcalloc(1, sizeof(XlcCharSetRec));
+ if (charset == NULL)
+ return (XlcCharSet) NULL;
+
+ name_len = strlen(name);
+ ct_sequence_len = strlen(ct_sequence);
+
+ /* Fill in name and xrm_name. */
+ tmp = (char *) Xmalloc(name_len + 1 + ct_sequence_len + 1);
+ if (tmp == NULL) {
+ Xfree((char *) charset);
+ return (XlcCharSet) NULL;
+ }
+ memcpy(tmp, name, name_len+1);
+ charset->name = tmp;
+ charset->xrm_name = XrmStringToQuark(charset->name);
+
+ /* Fill in encoding_name and xrm_encoding_name. */
+ if ((colon = strchr(charset->name, ':')) != NULL) {
+ unsigned int length = colon - charset->name;
+ char *encoding_tmp = (char *) Xmalloc(length + 1);
+ if (encoding_tmp == NULL) {
+ Xfree((char *) charset->name);
+ Xfree((char *) charset);
+ return (XlcCharSet) NULL;
+ }
+ memcpy(encoding_tmp, charset->name, length);
+ encoding_tmp[length] = '\0';
+ charset->encoding_name = encoding_tmp;
+ charset->xrm_encoding_name = XrmStringToQuark(charset->encoding_name);
+ } else {
+ charset->encoding_name = charset->name;
+ charset->xrm_encoding_name = charset->xrm_name;
+ }
+
+ /* Fill in ct_sequence. */
+ tmp += name_len + 1;
+ memcpy(tmp, ct_sequence, ct_sequence_len+1);
+ charset->ct_sequence = tmp;
+
+ /* Fill in side, char_size, set_size. */
+ if (!_XlcParseCharSet(charset))
+ /* If ct_sequence is not usable in Compound Text, remove it. */
+ charset->ct_sequence = "";
+
+ return (XlcCharSet) charset;
+}
diff --git a/libX11/src/xlibi18n/lcDB.c b/libX11/src/xlibi18n/lcDB.c
index 4a25ae69d..79df2450c 100644
--- a/libX11/src/xlibi18n/lcDB.c
+++ b/libX11/src/xlibi18n/lcDB.c
@@ -1,1347 +1,1341 @@
-/*
- *
- * Copyright IBM Corporation 1993
- *
- * All Rights Reserved
- *
- * License to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appear in all copies and that
- * both that copyright notice and this permission notice appear in
- * supporting documentation, and that the name of IBM not be
- * used in advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- *
- * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- * ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS, AND
- * NONINFRINGEMENT OF THIRD PARTY RIGHTS, IN NO EVENT SHALL
- * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- *
-*/
-/*
- * (c) Copyright 1995 FUJITSU LIMITED
- * This is source code modified by FUJITSU LIMITED under the Joint
- * Development Agreement for the CDE/Motif PST.
- */
-
-
-
-#ifndef NOT_X_ENV
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/Xlib.h>
-#include <X11/Xresource.h>
-#include "Xlibint.h"
-#include "XlcPubI.h"
-
-#else /* NOT_X_ENV */
-
-#define Xmalloc malloc
-#define Xrealloc realloc
-#define Xfree free
-
-#endif /* NOT_X_ENV */
-
-#include <stdint.h>
-
-/* specifying NOT_X_ENV allows users to just use
- the database parsing routine. */
-/* For UDC/VW */
-#ifndef BUFSIZE
-#define BUFSIZE 2048
-#endif
-
-#ifdef COMMENT
-#ifdef BUFSIZE
-#undef BUFSIZE
-#endif
-#define BUFSIZE 6144 /* 2048*3 */
-#endif
-
-#include <stdio.h>
-
-typedef struct _DatabaseRec {
- char *category;
- char *name;
- char **value;
- int value_num;
- struct _DatabaseRec *next;
-} DatabaseRec, *Database;
-
-typedef enum {
- S_NULL, /* outside category */
- S_CATEGORY, /* inside category */
- S_NAME, /* has name, expecting values */
- S_VALUE
-} ParseState;
-
-typedef enum {
- T_NEWLINE,
- T_COMMENT,
- T_SEMICOLON,
- T_DOUBLE_QUOTE,
- T_LEFT_BRACE,
- T_RIGHT_BRACE,
- T_SPACE,
- T_TAB,
- T_BACKSLASH,
- T_NUMERIC_HEX,
- T_NUMERIC_DEC,
- T_NUMERIC_OCT,
- T_DEFAULT
-} Token;
-
-typedef struct {
- Token token; /* token id */
- int len; /* length of token sequence */
-} TokenTable;
-
-static int f_newline (const char *str, Token token, Database *db);
-static int f_comment (const char *str, Token token, Database *db);
-static int f_semicolon (const char *str, Token token, Database *db);
-static int f_double_quote (const char *str, Token token, Database *db);
-static int f_left_brace (const char *str, Token token, Database *db);
-static int f_right_brace (const char *str, Token token, Database *db);
-static int f_white (const char *str, Token token, Database *db);
-static int f_backslash (const char *str, Token token, Database *db);
-static int f_numeric (const char *str, Token token, Database *db);
-static int f_default (const char *str, Token token, Database *db);
-
-static const TokenTable token_tbl[] = {
- { T_NEWLINE, 1 },
- { T_COMMENT, 1 },
- { T_SEMICOLON, 1 },
- { T_DOUBLE_QUOTE, 1 },
- { T_LEFT_BRACE, 1 },
- { T_RIGHT_BRACE, 1 },
- { T_SPACE, 1 },
- { T_TAB, 1 },
- { T_BACKSLASH, 1 },
- { T_NUMERIC_HEX, 2 },
- { T_NUMERIC_DEC, 2 },
- { T_NUMERIC_OCT, 2 },
- { T_DEFAULT, 1 } /* any character */
-};
-
-#define SYM_CR '\r'
-#define SYM_NEWLINE '\n'
-#define SYM_COMMENT '#'
-#define SYM_SEMICOLON ';'
-#define SYM_DOUBLE_QUOTE '"'
-#define SYM_LEFT_BRACE '{'
-#define SYM_RIGHT_BRACE '}'
-#define SYM_SPACE ' '
-#define SYM_TAB '\t'
-#define SYM_BACKSLASH '\\'
-
-/************************************************************************/
-
-#define MAX_NAME_NEST 64
-
-typedef struct {
- ParseState pre_state;
- char *category;
- char *name[MAX_NAME_NEST];
- int nest_depth;
- char **value;
- int value_len;
- int value_num;
- int bufsize; /* bufMaxSize >= bufsize >= 0 */
- int bufMaxSize; /* default : BUFSIZE */
- char *buf;
-} DBParseInfo;
-
-static DBParseInfo parse_info;
-
-static void
-init_parse_info (void)
-{
- static int allocated /* = 0 */;
- char *ptr;
- int size;
- if (!allocated) {
- bzero(&parse_info, sizeof(DBParseInfo));
- parse_info.buf = (char *)Xmalloc(BUFSIZE);
- parse_info.bufMaxSize = BUFSIZE;
- allocated = 1;
- return;
- }
- ptr = parse_info.buf;
- size = parse_info.bufMaxSize;
- bzero(&parse_info, sizeof(DBParseInfo));
- parse_info.buf = ptr;
- parse_info.bufMaxSize = size;
-}
-
-static void
-clear_parse_info (void)
-{
- int i;
- char *ptr;
- int size;
- parse_info.pre_state = S_NULL;
- if (parse_info.category != NULL) {
- Xfree(parse_info.category);
- }
- for (i = 0; i <= parse_info.nest_depth; ++i) {
- if (parse_info.name[i]) {
- Xfree(parse_info.name[i]);
- }
- }
- if (parse_info.value) {
- if (*parse_info.value) {
- Xfree(*parse_info.value);
- }
- Xfree((char *)parse_info.value);
- }
- ptr = parse_info.buf;
- size = parse_info.bufMaxSize;
- bzero(&parse_info, sizeof(DBParseInfo));
- parse_info.buf = ptr;
- parse_info.bufMaxSize = size;
-}
-
-static Bool
-realloc_parse_info(
- int len)
-{
- char *p;
-
- parse_info.bufMaxSize = BUFSIZE * ((parse_info.bufsize + len)/BUFSIZE + 1);
- p = (char *)Xrealloc(parse_info.buf, parse_info.bufMaxSize);
- if (p == NULL)
- return False;
- parse_info.buf = p;
-
- return True;
-}
-
-/************************************************************************/
-
-typedef struct _Line {
- char *str;
- int cursize;
- int maxsize;
- int seq;
-} Line;
-
-static void
-free_line(
- Line *line)
-{
- if (line->str != NULL) {
- Xfree(line->str);
- }
- bzero(line, sizeof(Line));
-}
-
-static int
-realloc_line(
- Line *line,
- int size)
-{
- char *str = line->str;
-
- if (str != NULL) {
- str = (char *)Xrealloc(str, size);
- } else {
- str = (char *)Xmalloc(size);
- }
- if (str == NULL) {
- /* malloc error */
- if (line->str != NULL) {
- Xfree(line->str);
- }
- bzero(line, sizeof(Line));
- return 0;
- }
- line->str = str;
- line->maxsize = size;
- return 1;
-}
-
-#define iswhite(ch) ((ch) == SYM_SPACE || (ch) == SYM_TAB)
-
-static void
-zap_comment(
- char *str,
- int *quoted)
-{
- char *p = str;
-#ifdef never
- *quoted = 0;
- if (*p == SYM_COMMENT) {
- int len = strlen(str);
- if (p[len - 1] == SYM_NEWLINE || p[len - 1] == SYM_CR) {
- *p++ = SYM_NEWLINE;
- }
- *p = '\0';
- }
-#else
- while (*p) {
- if (*p == SYM_DOUBLE_QUOTE) {
- if (p == str || p[-1] != SYM_BACKSLASH) {
- /* unescaped double quote changes quoted state. */
- *quoted = *quoted ? 0 : 1;
- }
- }
- if (*p == SYM_COMMENT && !*quoted) {
- int pos = p - str;
- if (pos == 0 ||
- (iswhite(p[-1]) && (pos == 1 || p[-2] != SYM_BACKSLASH))) {
- int len = strlen(p);
- if (len > 0 && (p[len - 1] == SYM_NEWLINE || p[len-1] == SYM_CR)) {
- /* newline is the identifier for finding end of value.
- therefore, it should not be removed. */
- *p++ = SYM_NEWLINE;
- }
- *p = '\0';
- break;
- }
- }
- ++p;
- }
-#endif
-}
-
-static int
-read_line(
- FILE *fd,
- Line *line)
-{
- char buf[BUFSIZE], *p;
- int len;
- int quoted = 0; /* quoted by double quote? */
- char *str;
- int cur;
-
- str = line->str;
- cur = line->cursize = 0;
-
- while ((p = fgets(buf, BUFSIZE, fd)) != NULL) {
- ++line->seq;
- zap_comment(p, &quoted); /* remove comment line */
- len = strlen(p);
- if (len == 0) {
- if (cur > 0) {
- break;
- }
- continue;
- }
- if (cur + len + 1 > line->maxsize) {
- /* need to reallocate buffer. */
- if (! realloc_line(line, line->maxsize + BUFSIZE)) {
- return -1; /* realloc error. */
- }
- str = line->str;
- }
- strncpy(str + cur, p, len);
-
- cur += len;
- str[cur] = '\0';
-#ifdef __UNIXOS2__ /* Take out carriage returns under OS/2 */
- if (cur>1) {
- if (str[cur-2] == '\r' && str[cur-1] == '\n') {
- str[cur-2] = '\n';
- str[cur-1] = '\0';
- cur--;
- }
- }
-#endif
- if (!quoted && cur > 1 && str[cur - 2] == SYM_BACKSLASH &&
- (str[cur - 1] == SYM_NEWLINE || str[cur-1] == SYM_CR)) {
- /* the line is ended backslash followed by newline.
- need to concatinate the next line. */
- cur -= 2;
- str[cur] = '\0';
- } else if (len < BUFSIZE - 1 || buf[len - 1] == SYM_NEWLINE ||
- buf[len - 1] == SYM_CR) {
- /* the line is shorter than BUFSIZE. */
- break;
- }
- }
- if (quoted) {
- /* error. still in quoted state. */
- return -1;
- }
- return line->cursize = cur;
-}
-
-/************************************************************************/
-
-static Token
-get_token(
- const char *str)
-{
- switch (*str) {
- case SYM_NEWLINE:
- case SYM_CR: return T_NEWLINE;
- case SYM_COMMENT: return T_COMMENT;
- case SYM_SEMICOLON: return T_SEMICOLON;
- case SYM_DOUBLE_QUOTE: return T_DOUBLE_QUOTE;
- case SYM_LEFT_BRACE: return T_LEFT_BRACE;
- case SYM_RIGHT_BRACE: return T_RIGHT_BRACE;
- case SYM_SPACE: return T_SPACE;
- case SYM_TAB: return T_TAB;
- case SYM_BACKSLASH:
- switch (str[1]) {
- case 'x': return T_NUMERIC_HEX;
- case 'd': return T_NUMERIC_DEC;
- case 'o': return T_NUMERIC_OCT;
- }
- return T_BACKSLASH;
- default:
- return T_DEFAULT;
- }
-}
-
-static int
-get_word(
- const char *str,
- char *word)
-{
- const char *p = str;
- char *w = word;
- Token token;
- int token_len;
-
- while (*p != '\0') {
- token = get_token(p);
- token_len = token_tbl[token].len;
- if (token == T_BACKSLASH) {
- p += token_len;
- if (*p == '\0')
- break;
- token = get_token(p);
- token_len = token_tbl[token].len;
- } else if (token != T_COMMENT && token != T_DEFAULT) {
- break;
- }
- strncpy(w, p, token_len);
- p += token_len; w += token_len;
- }
- *w = '\0';
- return p - str; /* return number of scanned chars */
-}
-
-static int
-get_quoted_word(
- const char *str,
- char *word)
-{
- const char *p = str;
- char *w = word;
- Token token;
- int token_len;
-
- if (*p == SYM_DOUBLE_QUOTE) {
- ++p;
- }
- while (*p != '\0') {
- token = get_token(p);
- token_len = token_tbl[token].len;
- if (token == T_DOUBLE_QUOTE) {
- p += token_len;
- goto found;
- }
- if (token == T_BACKSLASH) {
- p += token_len;
- if (*p == '\0') {
- break;
- }
- token = get_token(p);
- token_len = token_tbl[token].len;
- }
- strncpy(w, p, token_len);
- p += token_len; w += token_len;
- }
- /* error. cannot detect next double quote */
- return 0;
-
- found:;
- *w = '\0';
- return p - str;
-}
-
-/************************************************************************/
-
-static int
-append_value_list (void)
-{
- char **value_list = parse_info.value;
- char *value;
- int value_num = parse_info.value_num;
- int value_len = parse_info.value_len;
- char *str = parse_info.buf;
- int len = parse_info.bufsize;
- char *p;
-
- if (len < 1) {
- return 1; /* return with no error */
- }
-
- if (value_list == (char **)NULL) {
- value_list = (char **)Xmalloc(sizeof(char *) * 2);
- *value_list = NULL;
- } else {
- char **prev_list = value_list;
-
- value_list = (char **)
- Xrealloc(value_list, sizeof(char *) * (value_num + 2));
- if (value_list == NULL) {
- Xfree(prev_list);
- }
- }
- if (value_list == (char **)NULL)
- goto err2;
-
- value = *value_list;
- if (value == NULL) {
- value = (char *)Xmalloc(value_len + len + 1);
- } else {
- char *prev_value = value;
-
- value = (char *)Xrealloc(value, value_len + len + 1);
- if (value == NULL) {
- Xfree(prev_value);
- }
- }
- if (value == NULL) {
- goto err1;
- }
- if (value != *value_list) {
- int i;
- ssize_t delta;
- delta = value - *value_list;
- *value_list = value;
- for (i = 1; i < value_num; ++i) {
- value_list[i] += delta;
- }
- }
-
- value_list[value_num] = p = &value[value_len];
- value_list[value_num + 1] = NULL;
- strncpy(p, str, len);
- p[len] = 0;
-
- parse_info.value = value_list;
- parse_info.value_num = value_num + 1;
- parse_info.value_len = value_len + len + 1;
- parse_info.bufsize = 0;
- return 1;
-
- err1:
- if (value_list) {
- Xfree((char **)value_list);
- }
- if (value) {
- Xfree(value);
- }
- err2:
- parse_info.value = (char **)NULL;
- parse_info.value_num = 0;
- parse_info.value_len = 0;
- parse_info.bufsize = 0;
- return 0;
-}
-
-static int
-construct_name(
- char *name,
- int size)
-{
- int i;
- int len = 0;
- char *p = name;
-
- for (i = 0; i <= parse_info.nest_depth; ++i) {
- len += strlen(parse_info.name[i]) + 1;
- }
- if (len >= size)
- return 0;
-
- strcpy(p, parse_info.name[0]);
- p += strlen(parse_info.name[0]);
- for (i = 1; i <= parse_info.nest_depth; ++i) {
- *p++ = '.';
- strcpy(p, parse_info.name[i]);
- p += strlen(parse_info.name[i]);
- }
- return *name != '\0';
-}
-
-static int
-store_to_database(
- Database *db)
-{
- Database new = (Database)NULL;
- char name[BUFSIZE];
-
- if (parse_info.pre_state == S_VALUE) {
- if (! append_value_list()) {
- goto err;
- }
- }
-
- if (parse_info.name[parse_info.nest_depth] == NULL) {
- goto err;
- }
-
- new = (Database)Xmalloc(sizeof(DatabaseRec));
- if (new == (Database)NULL) {
- goto err;
- }
- bzero(new, sizeof(DatabaseRec));
-
- new->category = (char *)Xmalloc(strlen(parse_info.category) + 1);
- if (new->category == NULL) {
- goto err;
- }
- strcpy(new->category, parse_info.category);
-
- if (! construct_name(name, sizeof(name))) {
- goto err;
- }
- new->name = (char *)Xmalloc(strlen(name) + 1);
- if (new->name == NULL) {
- goto err;
- }
- strcpy(new->name, name);
- new->next = *db;
- new->value = parse_info.value;
- new->value_num = parse_info.value_num;
- *db = new;
-
- Xfree(parse_info.name[parse_info.nest_depth]);
- parse_info.name[parse_info.nest_depth] = NULL;
-
- parse_info.value = (char **)NULL;
- parse_info.value_num = 0;
- parse_info.value_len = 0;
-
- return 1;
-
- err:
- if (new) {
- if (new->category) {
- Xfree(new->category);
- }
- if (new->name) {
- Xfree(new->name);
- }
- Xfree(new);
- }
- if (parse_info.value) {
- if (*parse_info.value) {
- Xfree(*parse_info.value);
- }
- Xfree((char **)parse_info.value);
- parse_info.value = (char **)NULL;
- parse_info.value_num = 0;
- parse_info.value_len = 0;
- }
- return 0;
-}
-
-#define END_MARK "END"
-#define END_MARK_LEN 3 /*strlen(END_MARK)*/
-
-static int
-check_category_end(
- const char *str)
-{
- const char *p;
- int len;
-
- p = str;
- if (strncmp(p, END_MARK, END_MARK_LEN)) {
- return 0;
- }
- p += END_MARK_LEN;
-
- while (iswhite(*p)) {
- ++p;
- }
- len = strlen(parse_info.category);
- if (strncmp(p, parse_info.category, len)) {
- return 0;
- }
- p += len;
- return p - str;
-}
-
-/************************************************************************/
-
-static int
-f_newline(
- const char *str,
- Token token,
- Database *db)
-{
- switch (parse_info.pre_state) {
- case S_NULL:
- case S_CATEGORY:
- break;
- case S_NAME:
- return 0; /* no value */
- case S_VALUE:
- if (!store_to_database(db))
- return 0;
- parse_info.pre_state = S_CATEGORY;
- break;
- default:
- return 0;
- }
- return token_tbl[token].len;
-}
-
-static int
-f_comment(
- const char *str,
- Token token,
- Database *db)
-{
- /* NOTE: comment is already handled in read_line(),
- so this function is not necessary. */
-
- const char *p = str;
-
- while (*p != SYM_NEWLINE && *p != SYM_CR && *p != '\0') {
- ++p; /* zap to the end of line */
- }
- return p - str;
-}
-
-static int
-f_white(
- const char *str,
- Token token,
- Database *db)
-{
- const char *p = str;
-
- while (iswhite(*p)) {
- ++p;
- }
- return p - str;
-}
-
-static int
-f_semicolon(
- const char *str,
- Token token,
- Database *db)
-{
- switch (parse_info.pre_state) {
- case S_NULL:
- case S_CATEGORY:
- case S_NAME:
- return 0;
- case S_VALUE:
- if (! append_value_list())
- return 0;
- parse_info.pre_state = S_VALUE;
- break;
- default:
- return 0;
- }
- return token_tbl[token].len;
-}
-
-static int
-f_left_brace(
- const char *str,
- Token token,
- Database *db)
-{
- switch (parse_info.pre_state) {
- case S_NULL:
- case S_CATEGORY:
- case S_VALUE:
- return 0;
- case S_NAME:
- if (parse_info.name[parse_info.nest_depth] == NULL
- || parse_info.nest_depth + 1 > MAX_NAME_NEST)
- return 0;
- ++parse_info.nest_depth;
- parse_info.pre_state = S_CATEGORY;
- break;
- default:
- return 0;
- }
- return token_tbl[token].len;
-}
-
-static int
-f_right_brace(
- const char *str,
- Token token,
- Database *db)
-{
- if (parse_info.nest_depth < 1)
- return 0;
-
- switch (parse_info.pre_state) {
- case S_NULL:
- case S_NAME:
- return 0;
- case S_VALUE:
- if (! store_to_database(db))
- return 0;
- /* fall into next case */
- case S_CATEGORY:
- if (parse_info.name[parse_info.nest_depth] != NULL) {
- Xfree(parse_info.name[parse_info.nest_depth]);
- parse_info.name[parse_info.nest_depth] = NULL;
- }
- --parse_info.nest_depth;
- parse_info.pre_state = S_CATEGORY;
- break;
- default:
- return 0;
- }
- return token_tbl[token].len;
-}
-
-static int
-f_double_quote(
- const char *str,
- Token token,
- Database *db)
-{
- char word[BUFSIZE];
- char* wordp;
- int len;
-
- if ((len = strlen (str)) < sizeof word)
- wordp = word;
- else
- wordp = Xmalloc (len + 1);
- if (wordp == NULL)
- return 0;
-
- len = 0;
- switch (parse_info.pre_state) {
- case S_NULL:
- case S_CATEGORY:
- goto err;
- case S_NAME:
- case S_VALUE:
- len = get_quoted_word(str, wordp);
- if (len < 1)
- goto err;
- if ((parse_info.bufsize + (int)strlen(wordp) + 1)
- >= parse_info.bufMaxSize) {
- if (realloc_parse_info(strlen(wordp)+1) == False) {
- goto err;
- }
- }
- strcpy(&parse_info.buf[parse_info.bufsize], wordp);
- parse_info.bufsize += strlen(wordp);
- parse_info.pre_state = S_VALUE;
- break;
- default:
- goto err;
- }
- if (wordp != word)
- Xfree (wordp);
- return len; /* including length of token */
-
-err:
- if (wordp != word)
- Xfree (wordp);
- return 0;
-}
-
-static int
-f_backslash(
- const char *str,
- Token token,
- Database *db)
-{
- return f_default(str, token, db);
-}
-
-static int
-f_numeric(
- const char *str,
- Token token,
- Database *db)
-{
- char word[BUFSIZE];
- const char *p;
- char* wordp;
- int len;
- int token_len;
-
- if ((len = strlen (str)) < sizeof word)
- wordp = word;
- else
- wordp = Xmalloc (len + 1);
- if (wordp == NULL)
- return 0;
-
- switch (parse_info.pre_state) {
- case S_NULL:
- case S_CATEGORY:
- goto err;
- case S_NAME:
- case S_VALUE:
- token_len = token_tbl[token].len;
- p = str + token_len;
- len = get_word(p, wordp);
- if (len < 1)
- goto err;
- if ((parse_info.bufsize + token_len + (int)strlen(wordp) + 1)
- >= parse_info.bufMaxSize) {
- if (realloc_parse_info(token_len + strlen(wordp) + 1) == False)
- goto err;
- }
- strncpy(&parse_info.buf[parse_info.bufsize], str, token_len);
- strcpy(&parse_info.buf[parse_info.bufsize + token_len], wordp);
- parse_info.bufsize += token_len + strlen(wordp);
- parse_info.pre_state = S_VALUE;
- break;
- default:
- goto err;
- }
- if (wordp != word)
- Xfree (wordp);
- return len + token_len;
-
-err:
- if (wordp != word)
- Xfree (wordp);
- return 0;
-}
-
-static int
-f_default(
- const char *str,
- Token token,
- Database *db)
-{
- char word[BUFSIZE], *p;
- char* wordp;
- int len;
-
- if ((len = strlen (str)) < sizeof word)
- wordp = word;
- else
- wordp = Xmalloc (len + 1);
- if (wordp == NULL)
- return 0;
-
- len = get_word(str, wordp);
- if (len < 1)
- goto err;
-
- switch (parse_info.pre_state) {
- case S_NULL:
- if (parse_info.category != NULL)
- goto err;
- p = (char *)Xmalloc(strlen(wordp) + 1);
- if (p == NULL)
- goto err;
- strcpy(p, wordp);
- parse_info.category = p;
- parse_info.pre_state = S_CATEGORY;
- break;
- case S_CATEGORY:
- if (parse_info.nest_depth == 0) {
- if (check_category_end(str)) {
- /* end of category is detected.
- clear context and zap to end of this line */
- clear_parse_info();
- len = strlen(str);
- break;
- }
- }
- p = (char *)Xmalloc(strlen(wordp) + 1);
- if (p == NULL)
- goto err;
- strcpy(p, wordp);
- if (parse_info.name[parse_info.nest_depth] != NULL) {
- Xfree(parse_info.name[parse_info.nest_depth]);
- }
- parse_info.name[parse_info.nest_depth] = p;
- parse_info.pre_state = S_NAME;
- break;
- case S_NAME:
- case S_VALUE:
- if ((parse_info.bufsize + (int)strlen(wordp) + 1)
- >= parse_info.bufMaxSize) {
- if (realloc_parse_info(strlen(wordp) + 1) == False)
- goto err;
- }
- strcpy(&parse_info.buf[parse_info.bufsize], wordp);
- parse_info.bufsize += strlen(wordp);
- parse_info.pre_state = S_VALUE;
- break;
- default:
- goto err;
- }
- if (wordp != word)
- Xfree (wordp);
- return len;
-
-err:
- if (wordp != word)
- Xfree (wordp);
- return 0;
-}
-
-/************************************************************************/
-
-#ifdef DEBUG
-static void
-PrintDatabase(
- Database db)
-{
- Database p = db;
- int i = 0, j;
-
- printf("***\n*** BEGIN Database\n***\n");
- while (p) {
- printf("%3d: ", i++);
- printf("%s, %s, ", p->category, p->name);
- printf("\t[%d: ", p->value_num);
- for (j = 0; j < p->value_num; ++j) {
- printf("%s, ", p->value[j]);
- }
- printf("]\n");
- p = p->next;
- }
- printf("***\n*** END Database\n***\n");
-}
-#endif
-
-static void
-DestroyDatabase(
- Database db)
-{
- Database p = db;
-
- while (p) {
- if (p->category != NULL) {
- Xfree(p->category);
- }
- if (p->name != NULL) {
- Xfree(p->name);
- }
- if (p->value != (char **)NULL) {
- if (*p->value != NULL) {
- Xfree(*p->value);
- }
- Xfree((char *)p->value);
- }
- db = p->next;
- Xfree((char *)p);
- p = db;
- }
-}
-
-static int
-CountDatabase(
- Database db)
-{
- Database p = db;
- int cnt = 0;
-
- while (p) {
- ++cnt;
- p = p->next;
- }
- return cnt;
-}
-
-static Database
-CreateDatabase(
- char *dbfile)
-{
- Database db = (Database)NULL;
- FILE *fd;
- Line line;
- char *p;
- Token token;
- int len;
- int error = 0;
-
- fd = _XFopenFile(dbfile, "r");
- if (fd == (FILE *)NULL)
- return NULL;
-
- bzero(&line, sizeof(Line));
- init_parse_info();
-
- do {
- int rc = read_line(fd, &line);
- if (rc < 0) {
- error = 1;
- break;
- } else if (rc == 0) {
- break;
- }
- p = line.str;
- while (*p) {
- int (*parse_proc)(const char *str, Token token, Database *db) = NULL;
-
- token = get_token(p);
-
- switch (token_tbl[token].token) {
- case T_NEWLINE:
- parse_proc = f_newline;
- break;
- case T_COMMENT:
- parse_proc = f_comment;
- break;
- case T_SEMICOLON:
- parse_proc = f_semicolon;
- break;
- case T_DOUBLE_QUOTE:
- parse_proc = f_double_quote;
- break;
- case T_LEFT_BRACE:
- parse_proc = f_left_brace;
- break;
- case T_RIGHT_BRACE:
- parse_proc = f_right_brace;
- break;
- case T_SPACE:
- case T_TAB:
- parse_proc = f_white;
- break;
- case T_BACKSLASH:
- parse_proc = f_backslash;
- break;
- case T_NUMERIC_HEX:
- case T_NUMERIC_DEC:
- case T_NUMERIC_OCT:
- parse_proc = f_numeric;
- break;
- case T_DEFAULT:
- parse_proc = f_default;
- break;
- }
-
- len = parse_proc(p, token, &db);
-
- if (len < 1) {
- error = 1;
- break;
- }
- p += len;
- }
- } while (!error);
-
- if (parse_info.pre_state != S_NULL) {
- clear_parse_info();
- error = 1;
- }
- if (error) {
-#ifdef DEBUG
- fprintf(stderr, "database format error at line %d.\n", line.seq);
-#endif
- DestroyDatabase(db);
- db = (Database)NULL;
- }
-
- fclose(fd);
- free_line(&line);
-
-#ifdef DEBUG
- PrintDatabase(db);
-#endif
-
- return db;
-}
-
-/************************************************************************/
-
-#ifndef NOT_X_ENV
-
-/* locale framework functions */
-
-typedef struct _XlcDatabaseRec {
- XrmQuark category_q;
- XrmQuark name_q;
- Database db;
- struct _XlcDatabaseRec *next;
-} XlcDatabaseRec, *XlcDatabase;
-
-typedef struct _XlcDatabaseListRec {
- XrmQuark name_q;
- XlcDatabase lc_db;
- Database database;
- int ref_count;
- struct _XlcDatabaseListRec *next;
-} XlcDatabaseListRec, *XlcDatabaseList;
-
-/* database cache list (per file) */
-static XlcDatabaseList _db_list = (XlcDatabaseList)NULL;
-
-/************************************************************************/
-/* _XlcGetResource(lcd, category, class, value, count) */
-/*----------------------------------------------------------------------*/
-/* This function retrieves XLocale database information. */
-/************************************************************************/
-void
-_XlcGetResource(
- XLCd lcd,
- const char *category,
- const char *class,
- char ***value,
- int *count)
-{
- XLCdPublicMethodsPart *methods = XLC_PUBLIC_METHODS(lcd);
-
- (*methods->get_resource)(lcd, category, class, value, count);
- return;
-}
-
-/************************************************************************/
-/* _XlcGetLocaleDataBase(lcd, category, class, value, count) */
-/*----------------------------------------------------------------------*/
-/* This function retrieves XLocale database information. */
-/************************************************************************/
-void
-_XlcGetLocaleDataBase(
- XLCd lcd,
- const char *category,
- const char *name,
- char ***value,
- int *count)
-{
- XlcDatabase lc_db = (XlcDatabase)XLC_PUBLIC(lcd, xlocale_db);
- XrmQuark category_q, name_q;
-
- category_q = XrmStringToQuark(category);
- name_q = XrmStringToQuark(name);
- for (; lc_db->db; ++lc_db) {
- if (category_q == lc_db->category_q && name_q == lc_db->name_q) {
- *value = lc_db->db->value;
- *count = lc_db->db->value_num;
- return;
- }
- }
- *value = (char **)NULL;
- *count = 0;
-}
-
-/************************************************************************/
-/* _XlcDestroyLocaleDataBase(lcd) */
-/*----------------------------------------------------------------------*/
-/* This function destroy the XLocale Database that bound to the */
-/* specified lcd. If the XLocale Database is refered from some */
-/* other lcd, this function just decreases reference count of */
-/* the database. If no locale refers the database, this function */
-/* remove it from the cache list and free work area. */
-/************************************************************************/
-void
-_XlcDestroyLocaleDataBase(
- XLCd lcd)
-{
- XlcDatabase lc_db = (XlcDatabase)XLC_PUBLIC(lcd, xlocale_db);
- XlcDatabaseList p, prev;
-
- for (p = _db_list, prev = (XlcDatabaseList)NULL; p;
- prev = p, p = p->next) {
- if (p->lc_db == lc_db) {
- if ((-- p->ref_count) < 1) {
- if (p->lc_db != (XlcDatabase)NULL) {
- Xfree((char *)p->lc_db);
- }
- DestroyDatabase(p->database);
- if (prev == (XlcDatabaseList)NULL) {
- _db_list = p->next;
- } else {
- prev->next = p->next;
- }
- Xfree((char*)p);
- }
- break;
- }
- }
- XLC_PUBLIC(lcd, xlocale_db) = (XPointer)NULL;
-}
-
-/************************************************************************/
-/* _XlcCreateLocaleDataBase(lcd) */
-/*----------------------------------------------------------------------*/
-/* This function create an XLocale database which correspond to */
-/* the specified XLCd. */
-/************************************************************************/
-XPointer
-_XlcCreateLocaleDataBase(
- XLCd lcd)
-{
- XlcDatabaseList list, new;
- Database p, database = (Database)NULL;
- XlcDatabase lc_db = (XlcDatabase)NULL;
- XrmQuark name_q;
- char *name;
- int i, n;
-
- name = _XlcFileName(lcd, "locale");
- if (name == NULL)
- return (XPointer)NULL;
-
-#ifndef __UNIXOS2__
- name_q = XrmStringToQuark(name);
-#else
- name_q = XrmStringToQuark((char*)__XOS2RedirRoot(name));
-#endif
- for (list = _db_list; list; list = list->next) {
- if (name_q == list->name_q) {
- list->ref_count++;
- Xfree (name);
- return XLC_PUBLIC(lcd, xlocale_db) = (XPointer)list->lc_db;
- }
- }
-
- database = CreateDatabase(name);
- if (database == (Database)NULL) {
- Xfree (name);
- return (XPointer)NULL;
- }
- n = CountDatabase(database);
- lc_db = (XlcDatabase)Xmalloc(sizeof(XlcDatabaseRec) * (n + 1));
- if (lc_db == (XlcDatabase)NULL)
- goto err;
- bzero(lc_db, sizeof(XlcDatabaseRec) * (n + 1));
- for (p = database, i = 0; p && i < n; p = p->next, ++i) {
- lc_db[i].category_q = XrmStringToQuark(p->category);
- lc_db[i].name_q = XrmStringToQuark(p->name);
- lc_db[i].db = p;
- }
-
- new = (XlcDatabaseList)Xmalloc(sizeof(XlcDatabaseListRec));
- if (new == (XlcDatabaseList)NULL) {
- goto err;
- }
- new->name_q = name_q;
- new->lc_db = lc_db;
- new->database = database;
- new->ref_count = 1;
- new->next = _db_list;
- _db_list = new;
-
- Xfree (name);
- return XLC_PUBLIC(lcd, xlocale_db) = (XPointer)lc_db;
-
- err:
- DestroyDatabase(database);
- if (lc_db != (XlcDatabase)NULL) {
- Xfree((char *)lc_db);
- }
- Xfree (name);
- return (XPointer)NULL;
-}
-
-#endif /* NOT_X_ENV */
+/*
+ *
+ * Copyright IBM Corporation 1993
+ *
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of IBM not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ *
+ * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ * ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS, AND
+ * NONINFRINGEMENT OF THIRD PARTY RIGHTS, IN NO EVENT SHALL
+ * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+*/
+/*
+ * (c) Copyright 1995 FUJITSU LIMITED
+ * This is source code modified by FUJITSU LIMITED under the Joint
+ * Development Agreement for the CDE/Motif PST.
+ */
+
+
+
+#ifndef NOT_X_ENV
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xlib.h>
+#include <X11/Xresource.h>
+#include "Xlibint.h"
+#include "XlcPubI.h"
+
+#else /* NOT_X_ENV */
+
+#define Xmalloc malloc
+#define Xrealloc realloc
+#define Xfree free
+
+#endif /* NOT_X_ENV */
+
+#include <stdint.h>
+
+/* specifying NOT_X_ENV allows users to just use
+ the database parsing routine. */
+/* For UDC/VW */
+#ifndef BUFSIZE
+#define BUFSIZE 2048
+#endif
+
+#ifdef COMMENT
+#ifdef BUFSIZE
+#undef BUFSIZE
+#endif
+#define BUFSIZE 6144 /* 2048*3 */
+#endif
+
+#include <stdio.h>
+
+typedef struct _DatabaseRec {
+ char *category;
+ char *name;
+ char **value;
+ int value_num;
+ struct _DatabaseRec *next;
+} DatabaseRec, *Database;
+
+typedef enum {
+ S_NULL, /* outside category */
+ S_CATEGORY, /* inside category */
+ S_NAME, /* has name, expecting values */
+ S_VALUE
+} ParseState;
+
+typedef enum {
+ T_NEWLINE,
+ T_COMMENT,
+ T_SEMICOLON,
+ T_DOUBLE_QUOTE,
+ T_LEFT_BRACE,
+ T_RIGHT_BRACE,
+ T_SPACE,
+ T_TAB,
+ T_BACKSLASH,
+ T_NUMERIC_HEX,
+ T_NUMERIC_DEC,
+ T_NUMERIC_OCT,
+ T_DEFAULT
+} Token;
+
+typedef struct {
+ Token token; /* token id */
+ int len; /* length of token sequence */
+} TokenTable;
+
+static int f_newline (const char *str, Token token, Database *db);
+static int f_comment (const char *str, Token token, Database *db);
+static int f_semicolon (const char *str, Token token, Database *db);
+static int f_double_quote (const char *str, Token token, Database *db);
+static int f_left_brace (const char *str, Token token, Database *db);
+static int f_right_brace (const char *str, Token token, Database *db);
+static int f_white (const char *str, Token token, Database *db);
+static int f_backslash (const char *str, Token token, Database *db);
+static int f_numeric (const char *str, Token token, Database *db);
+static int f_default (const char *str, Token token, Database *db);
+
+static const TokenTable token_tbl[] = {
+ { T_NEWLINE, 1 },
+ { T_COMMENT, 1 },
+ { T_SEMICOLON, 1 },
+ { T_DOUBLE_QUOTE, 1 },
+ { T_LEFT_BRACE, 1 },
+ { T_RIGHT_BRACE, 1 },
+ { T_SPACE, 1 },
+ { T_TAB, 1 },
+ { T_BACKSLASH, 1 },
+ { T_NUMERIC_HEX, 2 },
+ { T_NUMERIC_DEC, 2 },
+ { T_NUMERIC_OCT, 2 },
+ { T_DEFAULT, 1 } /* any character */
+};
+
+#define SYM_CR '\r'
+#define SYM_NEWLINE '\n'
+#define SYM_COMMENT '#'
+#define SYM_SEMICOLON ';'
+#define SYM_DOUBLE_QUOTE '"'
+#define SYM_LEFT_BRACE '{'
+#define SYM_RIGHT_BRACE '}'
+#define SYM_SPACE ' '
+#define SYM_TAB '\t'
+#define SYM_BACKSLASH '\\'
+
+/************************************************************************/
+
+#define MAX_NAME_NEST 64
+
+typedef struct {
+ ParseState pre_state;
+ char *category;
+ char *name[MAX_NAME_NEST];
+ int nest_depth;
+ char **value;
+ int value_len;
+ int value_num;
+ int bufsize; /* bufMaxSize >= bufsize >= 0 */
+ int bufMaxSize; /* default : BUFSIZE */
+ char *buf;
+} DBParseInfo;
+
+static DBParseInfo parse_info;
+
+static void
+init_parse_info (void)
+{
+ static int allocated /* = 0 */;
+ char *ptr;
+ int size;
+ if (!allocated) {
+ bzero(&parse_info, sizeof(DBParseInfo));
+ parse_info.buf = (char *)Xmalloc(BUFSIZE);
+ parse_info.bufMaxSize = BUFSIZE;
+ allocated = 1;
+ return;
+ }
+ ptr = parse_info.buf;
+ size = parse_info.bufMaxSize;
+ bzero(&parse_info, sizeof(DBParseInfo));
+ parse_info.buf = ptr;
+ parse_info.bufMaxSize = size;
+}
+
+static void
+clear_parse_info (void)
+{
+ int i;
+ char *ptr;
+ int size;
+ parse_info.pre_state = S_NULL;
+ if (parse_info.category != NULL) {
+ Xfree(parse_info.category);
+ }
+ for (i = 0; i <= parse_info.nest_depth; ++i) {
+ if (parse_info.name[i]) {
+ Xfree(parse_info.name[i]);
+ }
+ }
+ if (parse_info.value) {
+ if (*parse_info.value) {
+ Xfree(*parse_info.value);
+ }
+ Xfree((char *)parse_info.value);
+ }
+ ptr = parse_info.buf;
+ size = parse_info.bufMaxSize;
+ bzero(&parse_info, sizeof(DBParseInfo));
+ parse_info.buf = ptr;
+ parse_info.bufMaxSize = size;
+}
+
+static Bool
+realloc_parse_info(
+ int len)
+{
+ char *p;
+
+ parse_info.bufMaxSize = BUFSIZE * ((parse_info.bufsize + len)/BUFSIZE + 1);
+ p = (char *)Xrealloc(parse_info.buf, parse_info.bufMaxSize);
+ if (p == NULL)
+ return False;
+ parse_info.buf = p;
+
+ return True;
+}
+
+/************************************************************************/
+
+typedef struct _Line {
+ char *str;
+ int cursize;
+ int maxsize;
+ int seq;
+} Line;
+
+static void
+free_line(
+ Line *line)
+{
+ if (line->str != NULL) {
+ Xfree(line->str);
+ }
+ bzero(line, sizeof(Line));
+}
+
+static int
+realloc_line(
+ Line *line,
+ int size)
+{
+ char *str = line->str;
+
+ if (str != NULL) {
+ str = (char *)Xrealloc(str, size);
+ } else {
+ str = (char *)Xmalloc(size);
+ }
+ if (str == NULL) {
+ /* malloc error */
+ if (line->str != NULL) {
+ Xfree(line->str);
+ }
+ bzero(line, sizeof(Line));
+ return 0;
+ }
+ line->str = str;
+ line->maxsize = size;
+ return 1;
+}
+
+#define iswhite(ch) ((ch) == SYM_SPACE || (ch) == SYM_TAB)
+
+static void
+zap_comment(
+ char *str,
+ int *quoted)
+{
+ char *p = str;
+#ifdef never
+ *quoted = 0;
+ if (*p == SYM_COMMENT) {
+ int len = strlen(str);
+ if (p[len - 1] == SYM_NEWLINE || p[len - 1] == SYM_CR) {
+ *p++ = SYM_NEWLINE;
+ }
+ *p = '\0';
+ }
+#else
+ while (*p) {
+ if (*p == SYM_DOUBLE_QUOTE) {
+ if (p == str || p[-1] != SYM_BACKSLASH) {
+ /* unescaped double quote changes quoted state. */
+ *quoted = *quoted ? 0 : 1;
+ }
+ }
+ if (*p == SYM_COMMENT && !*quoted) {
+ int pos = p - str;
+ if (pos == 0 ||
+ (iswhite(p[-1]) && (pos == 1 || p[-2] != SYM_BACKSLASH))) {
+ int len = strlen(p);
+ if (len > 0 && (p[len - 1] == SYM_NEWLINE || p[len-1] == SYM_CR)) {
+ /* newline is the identifier for finding end of value.
+ therefore, it should not be removed. */
+ *p++ = SYM_NEWLINE;
+ }
+ *p = '\0';
+ break;
+ }
+ }
+ ++p;
+ }
+#endif
+}
+
+static int
+read_line(
+ FILE *fd,
+ Line *line)
+{
+ char buf[BUFSIZE], *p;
+ int len;
+ int quoted = 0; /* quoted by double quote? */
+ char *str;
+ int cur;
+
+ str = line->str;
+ cur = line->cursize = 0;
+
+ while ((p = fgets(buf, BUFSIZE, fd)) != NULL) {
+ ++line->seq;
+ zap_comment(p, &quoted); /* remove comment line */
+ len = strlen(p);
+ if (len == 0) {
+ if (cur > 0) {
+ break;
+ }
+ continue;
+ }
+ if (cur + len + 1 > line->maxsize) {
+ /* need to reallocate buffer. */
+ if (! realloc_line(line, line->maxsize + BUFSIZE)) {
+ return -1; /* realloc error. */
+ }
+ str = line->str;
+ }
+ strncpy(str + cur, p, len);
+
+ cur += len;
+ str[cur] = '\0';
+#ifdef __UNIXOS2__ /* Take out carriage returns under OS/2 */
+ if (cur>1) {
+ if (str[cur-2] == '\r' && str[cur-1] == '\n') {
+ str[cur-2] = '\n';
+ str[cur-1] = '\0';
+ cur--;
+ }
+ }
+#endif
+ if (!quoted && cur > 1 && str[cur - 2] == SYM_BACKSLASH &&
+ (str[cur - 1] == SYM_NEWLINE || str[cur-1] == SYM_CR)) {
+ /* the line is ended backslash followed by newline.
+ need to concatinate the next line. */
+ cur -= 2;
+ str[cur] = '\0';
+ } else if (len < BUFSIZE - 1 || buf[len - 1] == SYM_NEWLINE ||
+ buf[len - 1] == SYM_CR) {
+ /* the line is shorter than BUFSIZE. */
+ break;
+ }
+ }
+ if (quoted) {
+ /* error. still in quoted state. */
+ return -1;
+ }
+ return line->cursize = cur;
+}
+
+/************************************************************************/
+
+static Token
+get_token(
+ const char *str)
+{
+ switch (*str) {
+ case SYM_NEWLINE:
+ case SYM_CR: return T_NEWLINE;
+ case SYM_COMMENT: return T_COMMENT;
+ case SYM_SEMICOLON: return T_SEMICOLON;
+ case SYM_DOUBLE_QUOTE: return T_DOUBLE_QUOTE;
+ case SYM_LEFT_BRACE: return T_LEFT_BRACE;
+ case SYM_RIGHT_BRACE: return T_RIGHT_BRACE;
+ case SYM_SPACE: return T_SPACE;
+ case SYM_TAB: return T_TAB;
+ case SYM_BACKSLASH:
+ switch (str[1]) {
+ case 'x': return T_NUMERIC_HEX;
+ case 'd': return T_NUMERIC_DEC;
+ case 'o': return T_NUMERIC_OCT;
+ }
+ return T_BACKSLASH;
+ default:
+ return T_DEFAULT;
+ }
+}
+
+static int
+get_word(
+ const char *str,
+ char *word)
+{
+ const char *p = str;
+ char *w = word;
+ Token token;
+ int token_len;
+
+ while (*p != '\0') {
+ token = get_token(p);
+ token_len = token_tbl[token].len;
+ if (token == T_BACKSLASH) {
+ p += token_len;
+ if (*p == '\0')
+ break;
+ token = get_token(p);
+ token_len = token_tbl[token].len;
+ } else if (token != T_COMMENT && token != T_DEFAULT) {
+ break;
+ }
+ strncpy(w, p, token_len);
+ p += token_len; w += token_len;
+ }
+ *w = '\0';
+ return p - str; /* return number of scanned chars */
+}
+
+static int
+get_quoted_word(
+ const char *str,
+ char *word)
+{
+ const char *p = str;
+ char *w = word;
+ Token token;
+ int token_len;
+
+ if (*p == SYM_DOUBLE_QUOTE) {
+ ++p;
+ }
+ while (*p != '\0') {
+ token = get_token(p);
+ token_len = token_tbl[token].len;
+ if (token == T_DOUBLE_QUOTE) {
+ p += token_len;
+ goto found;
+ }
+ if (token == T_BACKSLASH) {
+ p += token_len;
+ if (*p == '\0') {
+ break;
+ }
+ token = get_token(p);
+ token_len = token_tbl[token].len;
+ }
+ strncpy(w, p, token_len);
+ p += token_len; w += token_len;
+ }
+ /* error. cannot detect next double quote */
+ return 0;
+
+ found:;
+ *w = '\0';
+ return p - str;
+}
+
+/************************************************************************/
+
+static int
+append_value_list (void)
+{
+ char **value_list = parse_info.value;
+ char *value;
+ int value_num = parse_info.value_num;
+ int value_len = parse_info.value_len;
+ char *str = parse_info.buf;
+ int len = parse_info.bufsize;
+ char *p;
+
+ if (len < 1) {
+ return 1; /* return with no error */
+ }
+
+ if (value_list == (char **)NULL) {
+ value_list = (char **)Xmalloc(sizeof(char *) * 2);
+ *value_list = NULL;
+ } else {
+ char **prev_list = value_list;
+
+ value_list = (char **)
+ Xrealloc(value_list, sizeof(char *) * (value_num + 2));
+ if (value_list == NULL) {
+ Xfree(prev_list);
+ }
+ }
+ if (value_list == (char **)NULL)
+ goto err2;
+
+ value = *value_list;
+ if (value == NULL) {
+ value = (char *)Xmalloc(value_len + len + 1);
+ } else {
+ char *prev_value = value;
+
+ value = (char *)Xrealloc(value, value_len + len + 1);
+ if (value == NULL) {
+ Xfree(prev_value);
+ }
+ }
+ if (value == NULL) {
+ goto err1;
+ }
+ if (value != *value_list) {
+ int i;
+ ssize_t delta;
+ delta = value - *value_list;
+ *value_list = value;
+ for (i = 1; i < value_num; ++i) {
+ value_list[i] += delta;
+ }
+ }
+
+ value_list[value_num] = p = &value[value_len];
+ value_list[value_num + 1] = NULL;
+ strncpy(p, str, len);
+ p[len] = 0;
+
+ parse_info.value = value_list;
+ parse_info.value_num = value_num + 1;
+ parse_info.value_len = value_len + len + 1;
+ parse_info.bufsize = 0;
+ return 1;
+
+ err1:
+ if (value_list) {
+ Xfree((char **)value_list);
+ }
+ if (value) {
+ Xfree(value);
+ }
+ err2:
+ parse_info.value = (char **)NULL;
+ parse_info.value_num = 0;
+ parse_info.value_len = 0;
+ parse_info.bufsize = 0;
+ return 0;
+}
+
+static int
+construct_name(
+ char *name,
+ int size)
+{
+ int i;
+ int len = 0;
+ char *p = name;
+
+ for (i = 0; i <= parse_info.nest_depth; ++i) {
+ len += strlen(parse_info.name[i]) + 1;
+ }
+ if (len >= size)
+ return 0;
+
+ strcpy(p, parse_info.name[0]);
+ p += strlen(parse_info.name[0]);
+ for (i = 1; i <= parse_info.nest_depth; ++i) {
+ *p++ = '.';
+ strcpy(p, parse_info.name[i]);
+ p += strlen(parse_info.name[i]);
+ }
+ return *name != '\0';
+}
+
+static int
+store_to_database(
+ Database *db)
+{
+ Database new = (Database)NULL;
+ char name[BUFSIZE];
+
+ if (parse_info.pre_state == S_VALUE) {
+ if (! append_value_list()) {
+ goto err;
+ }
+ }
+
+ if (parse_info.name[parse_info.nest_depth] == NULL) {
+ goto err;
+ }
+
+ new = Xcalloc(1, sizeof(DatabaseRec));
+ if (new == (Database)NULL) {
+ goto err;
+ }
+
+ new->category = strdup(parse_info.category);
+ if (new->category == NULL) {
+ goto err;
+ }
+
+ if (! construct_name(name, sizeof(name))) {
+ goto err;
+ }
+ new->name = strdup(name);
+ if (new->name == NULL) {
+ goto err;
+ }
+ new->next = *db;
+ new->value = parse_info.value;
+ new->value_num = parse_info.value_num;
+ *db = new;
+
+ Xfree(parse_info.name[parse_info.nest_depth]);
+ parse_info.name[parse_info.nest_depth] = NULL;
+
+ parse_info.value = (char **)NULL;
+ parse_info.value_num = 0;
+ parse_info.value_len = 0;
+
+ return 1;
+
+ err:
+ if (new) {
+ if (new->category) {
+ Xfree(new->category);
+ }
+ if (new->name) {
+ Xfree(new->name);
+ }
+ Xfree(new);
+ }
+ if (parse_info.value) {
+ if (*parse_info.value) {
+ Xfree(*parse_info.value);
+ }
+ Xfree((char **)parse_info.value);
+ parse_info.value = (char **)NULL;
+ parse_info.value_num = 0;
+ parse_info.value_len = 0;
+ }
+ return 0;
+}
+
+#define END_MARK "END"
+#define END_MARK_LEN 3 /*strlen(END_MARK)*/
+
+static int
+check_category_end(
+ const char *str)
+{
+ const char *p;
+ int len;
+
+ p = str;
+ if (strncmp(p, END_MARK, END_MARK_LEN)) {
+ return 0;
+ }
+ p += END_MARK_LEN;
+
+ while (iswhite(*p)) {
+ ++p;
+ }
+ len = strlen(parse_info.category);
+ if (strncmp(p, parse_info.category, len)) {
+ return 0;
+ }
+ p += len;
+ return p - str;
+}
+
+/************************************************************************/
+
+static int
+f_newline(
+ const char *str,
+ Token token,
+ Database *db)
+{
+ switch (parse_info.pre_state) {
+ case S_NULL:
+ case S_CATEGORY:
+ break;
+ case S_NAME:
+ return 0; /* no value */
+ case S_VALUE:
+ if (!store_to_database(db))
+ return 0;
+ parse_info.pre_state = S_CATEGORY;
+ break;
+ default:
+ return 0;
+ }
+ return token_tbl[token].len;
+}
+
+static int
+f_comment(
+ const char *str,
+ Token token,
+ Database *db)
+{
+ /* NOTE: comment is already handled in read_line(),
+ so this function is not necessary. */
+
+ const char *p = str;
+
+ while (*p != SYM_NEWLINE && *p != SYM_CR && *p != '\0') {
+ ++p; /* zap to the end of line */
+ }
+ return p - str;
+}
+
+static int
+f_white(
+ const char *str,
+ Token token,
+ Database *db)
+{
+ const char *p = str;
+
+ while (iswhite(*p)) {
+ ++p;
+ }
+ return p - str;
+}
+
+static int
+f_semicolon(
+ const char *str,
+ Token token,
+ Database *db)
+{
+ switch (parse_info.pre_state) {
+ case S_NULL:
+ case S_CATEGORY:
+ case S_NAME:
+ return 0;
+ case S_VALUE:
+ if (! append_value_list())
+ return 0;
+ parse_info.pre_state = S_VALUE;
+ break;
+ default:
+ return 0;
+ }
+ return token_tbl[token].len;
+}
+
+static int
+f_left_brace(
+ const char *str,
+ Token token,
+ Database *db)
+{
+ switch (parse_info.pre_state) {
+ case S_NULL:
+ case S_CATEGORY:
+ case S_VALUE:
+ return 0;
+ case S_NAME:
+ if (parse_info.name[parse_info.nest_depth] == NULL
+ || parse_info.nest_depth + 1 > MAX_NAME_NEST)
+ return 0;
+ ++parse_info.nest_depth;
+ parse_info.pre_state = S_CATEGORY;
+ break;
+ default:
+ return 0;
+ }
+ return token_tbl[token].len;
+}
+
+static int
+f_right_brace(
+ const char *str,
+ Token token,
+ Database *db)
+{
+ if (parse_info.nest_depth < 1)
+ return 0;
+
+ switch (parse_info.pre_state) {
+ case S_NULL:
+ case S_NAME:
+ return 0;
+ case S_VALUE:
+ if (! store_to_database(db))
+ return 0;
+ /* fall into next case */
+ case S_CATEGORY:
+ if (parse_info.name[parse_info.nest_depth] != NULL) {
+ Xfree(parse_info.name[parse_info.nest_depth]);
+ parse_info.name[parse_info.nest_depth] = NULL;
+ }
+ --parse_info.nest_depth;
+ parse_info.pre_state = S_CATEGORY;
+ break;
+ default:
+ return 0;
+ }
+ return token_tbl[token].len;
+}
+
+static int
+f_double_quote(
+ const char *str,
+ Token token,
+ Database *db)
+{
+ char word[BUFSIZE];
+ char* wordp;
+ int len;
+
+ if ((len = strlen (str)) < sizeof word)
+ wordp = word;
+ else
+ wordp = Xmalloc (len + 1);
+ if (wordp == NULL)
+ return 0;
+
+ len = 0;
+ switch (parse_info.pre_state) {
+ case S_NULL:
+ case S_CATEGORY:
+ goto err;
+ case S_NAME:
+ case S_VALUE:
+ len = get_quoted_word(str, wordp);
+ if (len < 1)
+ goto err;
+ if ((parse_info.bufsize + (int)strlen(wordp) + 1)
+ >= parse_info.bufMaxSize) {
+ if (realloc_parse_info(strlen(wordp)+1) == False) {
+ goto err;
+ }
+ }
+ strcpy(&parse_info.buf[parse_info.bufsize], wordp);
+ parse_info.bufsize += strlen(wordp);
+ parse_info.pre_state = S_VALUE;
+ break;
+ default:
+ goto err;
+ }
+ if (wordp != word)
+ Xfree (wordp);
+ return len; /* including length of token */
+
+err:
+ if (wordp != word)
+ Xfree (wordp);
+ return 0;
+}
+
+static int
+f_backslash(
+ const char *str,
+ Token token,
+ Database *db)
+{
+ return f_default(str, token, db);
+}
+
+static int
+f_numeric(
+ const char *str,
+ Token token,
+ Database *db)
+{
+ char word[BUFSIZE];
+ const char *p;
+ char* wordp;
+ int len;
+ int token_len;
+
+ if ((len = strlen (str)) < sizeof word)
+ wordp = word;
+ else
+ wordp = Xmalloc (len + 1);
+ if (wordp == NULL)
+ return 0;
+
+ switch (parse_info.pre_state) {
+ case S_NULL:
+ case S_CATEGORY:
+ goto err;
+ case S_NAME:
+ case S_VALUE:
+ token_len = token_tbl[token].len;
+ p = str + token_len;
+ len = get_word(p, wordp);
+ if (len < 1)
+ goto err;
+ if ((parse_info.bufsize + token_len + (int)strlen(wordp) + 1)
+ >= parse_info.bufMaxSize) {
+ if (realloc_parse_info(token_len + strlen(wordp) + 1) == False)
+ goto err;
+ }
+ strncpy(&parse_info.buf[parse_info.bufsize], str, token_len);
+ strcpy(&parse_info.buf[parse_info.bufsize + token_len], wordp);
+ parse_info.bufsize += token_len + strlen(wordp);
+ parse_info.pre_state = S_VALUE;
+ break;
+ default:
+ goto err;
+ }
+ if (wordp != word)
+ Xfree (wordp);
+ return len + token_len;
+
+err:
+ if (wordp != word)
+ Xfree (wordp);
+ return 0;
+}
+
+static int
+f_default(
+ const char *str,
+ Token token,
+ Database *db)
+{
+ char word[BUFSIZE], *p;
+ char* wordp;
+ int len;
+
+ if ((len = strlen (str)) < sizeof word)
+ wordp = word;
+ else
+ wordp = Xmalloc (len + 1);
+ if (wordp == NULL)
+ return 0;
+
+ len = get_word(str, wordp);
+ if (len < 1)
+ goto err;
+
+ switch (parse_info.pre_state) {
+ case S_NULL:
+ if (parse_info.category != NULL)
+ goto err;
+ p = strdup(wordp);
+ if (p == NULL)
+ goto err;
+ parse_info.category = p;
+ parse_info.pre_state = S_CATEGORY;
+ break;
+ case S_CATEGORY:
+ if (parse_info.nest_depth == 0) {
+ if (check_category_end(str)) {
+ /* end of category is detected.
+ clear context and zap to end of this line */
+ clear_parse_info();
+ len = strlen(str);
+ break;
+ }
+ }
+ p = strdup(wordp);
+ if (p == NULL)
+ goto err;
+ if (parse_info.name[parse_info.nest_depth] != NULL) {
+ Xfree(parse_info.name[parse_info.nest_depth]);
+ }
+ parse_info.name[parse_info.nest_depth] = p;
+ parse_info.pre_state = S_NAME;
+ break;
+ case S_NAME:
+ case S_VALUE:
+ if ((parse_info.bufsize + (int)strlen(wordp) + 1)
+ >= parse_info.bufMaxSize) {
+ if (realloc_parse_info(strlen(wordp) + 1) == False)
+ goto err;
+ }
+ strcpy(&parse_info.buf[parse_info.bufsize], wordp);
+ parse_info.bufsize += strlen(wordp);
+ parse_info.pre_state = S_VALUE;
+ break;
+ default:
+ goto err;
+ }
+ if (wordp != word)
+ Xfree (wordp);
+ return len;
+
+err:
+ if (wordp != word)
+ Xfree (wordp);
+ return 0;
+}
+
+/************************************************************************/
+
+#ifdef DEBUG
+static void
+PrintDatabase(
+ Database db)
+{
+ Database p = db;
+ int i = 0, j;
+
+ printf("***\n*** BEGIN Database\n***\n");
+ while (p) {
+ printf("%3d: ", i++);
+ printf("%s, %s, ", p->category, p->name);
+ printf("\t[%d: ", p->value_num);
+ for (j = 0; j < p->value_num; ++j) {
+ printf("%s, ", p->value[j]);
+ }
+ printf("]\n");
+ p = p->next;
+ }
+ printf("***\n*** END Database\n***\n");
+}
+#endif
+
+static void
+DestroyDatabase(
+ Database db)
+{
+ Database p = db;
+
+ while (p) {
+ if (p->category != NULL) {
+ Xfree(p->category);
+ }
+ if (p->name != NULL) {
+ Xfree(p->name);
+ }
+ if (p->value != (char **)NULL) {
+ if (*p->value != NULL) {
+ Xfree(*p->value);
+ }
+ Xfree((char *)p->value);
+ }
+ db = p->next;
+ Xfree((char *)p);
+ p = db;
+ }
+}
+
+static int
+CountDatabase(
+ Database db)
+{
+ Database p = db;
+ int cnt = 0;
+
+ while (p) {
+ ++cnt;
+ p = p->next;
+ }
+ return cnt;
+}
+
+static Database
+CreateDatabase(
+ char *dbfile)
+{
+ Database db = (Database)NULL;
+ FILE *fd;
+ Line line;
+ char *p;
+ Token token;
+ int len;
+ int error = 0;
+
+ fd = _XFopenFile(dbfile, "r");
+ if (fd == (FILE *)NULL)
+ return NULL;
+
+ bzero(&line, sizeof(Line));
+ init_parse_info();
+
+ do {
+ int rc = read_line(fd, &line);
+ if (rc < 0) {
+ error = 1;
+ break;
+ } else if (rc == 0) {
+ break;
+ }
+ p = line.str;
+ while (*p) {
+ int (*parse_proc)(const char *str, Token token, Database *db) = NULL;
+
+ token = get_token(p);
+
+ switch (token_tbl[token].token) {
+ case T_NEWLINE:
+ parse_proc = f_newline;
+ break;
+ case T_COMMENT:
+ parse_proc = f_comment;
+ break;
+ case T_SEMICOLON:
+ parse_proc = f_semicolon;
+ break;
+ case T_DOUBLE_QUOTE:
+ parse_proc = f_double_quote;
+ break;
+ case T_LEFT_BRACE:
+ parse_proc = f_left_brace;
+ break;
+ case T_RIGHT_BRACE:
+ parse_proc = f_right_brace;
+ break;
+ case T_SPACE:
+ case T_TAB:
+ parse_proc = f_white;
+ break;
+ case T_BACKSLASH:
+ parse_proc = f_backslash;
+ break;
+ case T_NUMERIC_HEX:
+ case T_NUMERIC_DEC:
+ case T_NUMERIC_OCT:
+ parse_proc = f_numeric;
+ break;
+ case T_DEFAULT:
+ parse_proc = f_default;
+ break;
+ }
+
+ len = parse_proc(p, token, &db);
+
+ if (len < 1) {
+ error = 1;
+ break;
+ }
+ p += len;
+ }
+ } while (!error);
+
+ if (parse_info.pre_state != S_NULL) {
+ clear_parse_info();
+ error = 1;
+ }
+ if (error) {
+#ifdef DEBUG
+ fprintf(stderr, "database format error at line %d.\n", line.seq);
+#endif
+ DestroyDatabase(db);
+ db = (Database)NULL;
+ }
+
+ fclose(fd);
+ free_line(&line);
+
+#ifdef DEBUG
+ PrintDatabase(db);
+#endif
+
+ return db;
+}
+
+/************************************************************************/
+
+#ifndef NOT_X_ENV
+
+/* locale framework functions */
+
+typedef struct _XlcDatabaseRec {
+ XrmQuark category_q;
+ XrmQuark name_q;
+ Database db;
+ struct _XlcDatabaseRec *next;
+} XlcDatabaseRec, *XlcDatabase;
+
+typedef struct _XlcDatabaseListRec {
+ XrmQuark name_q;
+ XlcDatabase lc_db;
+ Database database;
+ int ref_count;
+ struct _XlcDatabaseListRec *next;
+} XlcDatabaseListRec, *XlcDatabaseList;
+
+/* database cache list (per file) */
+static XlcDatabaseList _db_list = (XlcDatabaseList)NULL;
+
+/************************************************************************/
+/* _XlcGetResource(lcd, category, class, value, count) */
+/*----------------------------------------------------------------------*/
+/* This function retrieves XLocale database information. */
+/************************************************************************/
+void
+_XlcGetResource(
+ XLCd lcd,
+ const char *category,
+ const char *class,
+ char ***value,
+ int *count)
+{
+ XLCdPublicMethodsPart *methods = XLC_PUBLIC_METHODS(lcd);
+
+ (*methods->get_resource)(lcd, category, class, value, count);
+ return;
+}
+
+/************************************************************************/
+/* _XlcGetLocaleDataBase(lcd, category, class, value, count) */
+/*----------------------------------------------------------------------*/
+/* This function retrieves XLocale database information. */
+/************************************************************************/
+void
+_XlcGetLocaleDataBase(
+ XLCd lcd,
+ const char *category,
+ const char *name,
+ char ***value,
+ int *count)
+{
+ XlcDatabase lc_db = (XlcDatabase)XLC_PUBLIC(lcd, xlocale_db);
+ XrmQuark category_q, name_q;
+
+ category_q = XrmStringToQuark(category);
+ name_q = XrmStringToQuark(name);
+ for (; lc_db->db; ++lc_db) {
+ if (category_q == lc_db->category_q && name_q == lc_db->name_q) {
+ *value = lc_db->db->value;
+ *count = lc_db->db->value_num;
+ return;
+ }
+ }
+ *value = (char **)NULL;
+ *count = 0;
+}
+
+/************************************************************************/
+/* _XlcDestroyLocaleDataBase(lcd) */
+/*----------------------------------------------------------------------*/
+/* This function destroy the XLocale Database that bound to the */
+/* specified lcd. If the XLocale Database is refered from some */
+/* other lcd, this function just decreases reference count of */
+/* the database. If no locale refers the database, this function */
+/* remove it from the cache list and free work area. */
+/************************************************************************/
+void
+_XlcDestroyLocaleDataBase(
+ XLCd lcd)
+{
+ XlcDatabase lc_db = (XlcDatabase)XLC_PUBLIC(lcd, xlocale_db);
+ XlcDatabaseList p, prev;
+
+ for (p = _db_list, prev = (XlcDatabaseList)NULL; p;
+ prev = p, p = p->next) {
+ if (p->lc_db == lc_db) {
+ if ((-- p->ref_count) < 1) {
+ if (p->lc_db != (XlcDatabase)NULL) {
+ Xfree((char *)p->lc_db);
+ }
+ DestroyDatabase(p->database);
+ if (prev == (XlcDatabaseList)NULL) {
+ _db_list = p->next;
+ } else {
+ prev->next = p->next;
+ }
+ Xfree((char*)p);
+ }
+ break;
+ }
+ }
+ XLC_PUBLIC(lcd, xlocale_db) = (XPointer)NULL;
+}
+
+/************************************************************************/
+/* _XlcCreateLocaleDataBase(lcd) */
+/*----------------------------------------------------------------------*/
+/* This function create an XLocale database which correspond to */
+/* the specified XLCd. */
+/************************************************************************/
+XPointer
+_XlcCreateLocaleDataBase(
+ XLCd lcd)
+{
+ XlcDatabaseList list, new;
+ Database p, database = (Database)NULL;
+ XlcDatabase lc_db = (XlcDatabase)NULL;
+ XrmQuark name_q;
+ char *name;
+ int i, n;
+
+ name = _XlcFileName(lcd, "locale");
+ if (name == NULL)
+ return (XPointer)NULL;
+
+#ifndef __UNIXOS2__
+ name_q = XrmStringToQuark(name);
+#else
+ name_q = XrmStringToQuark((char*)__XOS2RedirRoot(name));
+#endif
+ for (list = _db_list; list; list = list->next) {
+ if (name_q == list->name_q) {
+ list->ref_count++;
+ Xfree (name);
+ return XLC_PUBLIC(lcd, xlocale_db) = (XPointer)list->lc_db;
+ }
+ }
+
+ database = CreateDatabase(name);
+ if (database == (Database)NULL) {
+ Xfree (name);
+ return (XPointer)NULL;
+ }
+ n = CountDatabase(database);
+ lc_db = Xcalloc(n + 1, sizeof(XlcDatabaseRec));
+ if (lc_db == (XlcDatabase)NULL)
+ goto err;
+ for (p = database, i = 0; p && i < n; p = p->next, ++i) {
+ lc_db[i].category_q = XrmStringToQuark(p->category);
+ lc_db[i].name_q = XrmStringToQuark(p->name);
+ lc_db[i].db = p;
+ }
+
+ new = (XlcDatabaseList)Xmalloc(sizeof(XlcDatabaseListRec));
+ if (new == (XlcDatabaseList)NULL) {
+ goto err;
+ }
+ new->name_q = name_q;
+ new->lc_db = lc_db;
+ new->database = database;
+ new->ref_count = 1;
+ new->next = _db_list;
+ _db_list = new;
+
+ Xfree (name);
+ return XLC_PUBLIC(lcd, xlocale_db) = (XPointer)lc_db;
+
+ err:
+ DestroyDatabase(database);
+ if (lc_db != (XlcDatabase)NULL) {
+ Xfree((char *)lc_db);
+ }
+ Xfree (name);
+ return (XPointer)NULL;
+}
+
+#endif /* NOT_X_ENV */
diff --git a/libX11/src/xlibi18n/lcFile.c b/libX11/src/xlibi18n/lcFile.c
index 167943d3c..5a9b0f4ab 100644
--- a/libX11/src/xlibi18n/lcFile.c
+++ b/libX11/src/xlibi18n/lcFile.c
@@ -1,835 +1,829 @@
-/*
- *
- * Copyright IBM Corporation 1993
- *
- * All Rights Reserved
- *
- * License to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appear in all copies and that
- * both that copyright notice and this permission notice appear in
- * supporting documentation, and that the name of IBM not be
- * used in advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- *
- * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- * ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS, AND
- * NONINFRINGEMENT OF THIRD PARTY RIGHTS, IN NO EVENT SHALL
- * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- *
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdlib.h>
-#include <stdio.h>
-#include <ctype.h>
-#include "Xlibint.h"
-#include "XlcPubI.h"
-#include <X11/Xos.h>
-#include <unistd.h>
-
-/************************************************************************/
-
-#ifdef __UNIXOS2__
-# define seteuid setuid
-#endif
-#define iscomment(ch) ((ch) == '#' || (ch) == '\0')
-#if defined(WIN32)
-#define isreadable(f) (_XAccessFile(f))
-#else
-#define isreadable(f) ((access((f), R_OK) != -1) ? 1 : 0)
-#endif
-
-#ifndef __UNIXOS2__
-#define LC_PATHDELIM ':'
-#else
-#define LC_PATHDELIM ';'
-#endif
-
-#define XLC_BUFSIZE 256
-
-#ifndef X_NOT_POSIX
-#ifdef _POSIX_SOURCE
-#include <limits.h>
-#else
-#define _POSIX_SOURCE
-#include <limits.h>
-#undef _POSIX_SOURCE
-#endif
-#endif
-#ifndef PATH_MAX
-#ifdef WIN32
-#define PATH_MAX 512
-#else
-#include <sys/param.h>
-#endif
-#ifndef PATH_MAX
-#ifdef MAXPATHLEN
-#define PATH_MAX MAXPATHLEN
-#else
-#define PATH_MAX 1024
-#endif
-#endif
-#endif
-
-#define NUM_LOCALEDIR 64
-
-/* Splits a NUL terminated line into constituents, at colons and newline
- characters. Leading whitespace is removed from constituents. The
- constituents are stored at argv[0..argsize-1]. The number of stored
- constituents (<= argsize) is returned. The line is destructively
- modified. */
-static int
-parse_line(
- char *line,
- char **argv,
- int argsize)
-{
- int argc = 0;
- char *p = line;
-
- while (argc < argsize) {
- while (isspace(*p)) {
- ++p;
- }
- if (*p == '\0') {
- break;
- }
- argv[argc++] = p;
- while (*p != ':' && *p != '\n' && *p != '\0') {
- ++p;
- }
- if (*p == '\0') {
- break;
- }
- *p++ = '\0';
- }
-
- return argc;
-}
-
-#ifdef __UNIXOS2__
-
-/* fg021216: entries in locale files are separated by colons while under
- OS/2, path entries are separated by semicolon, so we need two functions */
-
-static int
-parse_line1(
- char *line,
- char **argv,
- int argsize)
-{
- int argc = 0;
- char *p = line;
-
- while (argc < argsize) {
- while (isspace(*p)) {
- ++p;
- }
- if (*p == '\0') {
- break;
- }
- argv[argc++] = p;
- while (*p != ';' && *p != '\n' && *p != '\0') {
- ++p;
- }
- if (*p == '\0') {
- break;
- }
- *p++ = '\0';
- }
-
- return argc;
-}
-#elif defined(WIN32)
-
-/* this is parse_line but skips drive letters at the beginning of the entry */
-static int
-parse_line1(
- char *line,
- char **argv,
- int argsize)
-{
- int argc = 0;
- char *p = line;
-
- while (argc < argsize) {
- while (isspace(*p)) {
- ++p;
- }
- if (*p == '\0') {
- break;
- }
- argv[argc++] = p;
- if (isalpha(*p) && p[1] == ':') {
- p+= 2; /* skip drive letters */
- }
- while (*p != ':' && *p != '\n' && *p != '\0') {
- ++p;
- }
- if (*p == '\0') {
- break;
- }
- *p++ = '\0';
- }
-
- return argc;
-}
-
-#endif /* __UNIXOS2__ */
-
-/* Splits a colon separated list of directories, and returns the constituent
- paths (without trailing slash). At most argsize constituents are stored
- at argv[0..argsize-1]. The number of stored constituents is returned. */
-static int
-_XlcParsePath(
- char *path,
- char **argv,
- int argsize)
-{
- char *p = path;
- int n, i;
-
-#if !defined(__UNIXOS2__) && !defined(WIN32)
- n = parse_line(path, argv, argsize);
-#else
- n = parse_line1(path, argv, argsize);
-#endif
- for (i = 0; i < n; ++i) {
- int len;
- p = argv[i];
- len = strlen(p);
- if (len > 0 && p[len - 1] == '/') {
- /* eliminate trailing slash */
- p[len - 1] = '\0';
- }
- }
- return n;
-}
-
-#ifndef XLOCALEDIR
-#define XLOCALEDIR "locale"
-#endif
-
-void
-xlocaledir(
- char *buf,
- int buf_len)
-{
- char *p = buf;
- int len = 0;
-
-#ifndef NO_XLOCALEDIR
- char *dir;
- int priv = 1;
-
- dir = getenv("XLOCALEDIR");
-
- if (dir) {
-#ifndef WIN32
- /*
- * Only use the user-supplied path if the process isn't priviledged.
- */
- if (getuid() == geteuid() && getgid() == getegid()) {
-#if defined(HASSETUGID)
- priv = issetugid();
-#elif defined(HASGETRESUID)
- {
- uid_t ruid, euid, suid;
- gid_t rgid, egid, sgid;
- if ((getresuid(&ruid, &euid, &suid) == 0) &&
- (getresgid(&rgid, &egid, &sgid) == 0))
- priv = (euid != suid) || (egid != sgid);
- }
-#else
- /*
- * If there are saved ID's the process might still be priviledged
- * even though the above test succeeded. If issetugid() and
- * getresgid() aren't available, test this by trying to set
- * euid to 0.
- *
- * Note: this only protects setuid-root clients. It doesn't
- * protect other setuid or any setgid clients. If this tradeoff
- * isn't acceptable, set DisableXLocaleDirEnv to YES in host.def.
- */
- unsigned int oldeuid;
- oldeuid = geteuid();
- if (seteuid(0) != 0) {
- priv = 0;
- } else {
- if (seteuid(oldeuid) == -1) {
- /* XXX ouch, coudn't get back to original uid
- what can we do ??? */
- _exit(127);
- }
- priv = 1;
- }
-#endif
- }
-#else
- priv = 0;
-#endif
- if (!priv) {
- len = strlen(dir);
- strncpy(p, dir, buf_len);
- if (len < buf_len) {
- p[len++] = LC_PATHDELIM;
- p += len;
- }
- }
- }
-#endif /* NO_XLOCALEDIR */
-
- if (len < buf_len)
-#ifndef __UNIXOS2__
- strncpy(p, XLOCALEDIR, buf_len - len);
-#else
- strncpy(p,__XOS2RedirRoot(XLOCALEDIR), buf_len - len);
-#endif
- buf[buf_len-1] = '\0';
-}
-
-static void
-xlocalelibdir(
- char *buf,
- int buf_len)
-{
- char *p = buf;
- int len = 0;
-
-#ifndef NO_XLOCALEDIR
- char *dir;
- int priv = 1;
-
- dir = getenv("XLOCALELIBDIR");
-
- if (dir) {
-#ifndef WIN32
- /*
- * Only use the user-supplied path if the process isn't priviledged.
- */
- if (getuid() == geteuid() && getgid() == getegid()) {
-#if defined(HASSETUGID)
- priv = issetugid();
-#elif defined(HASGETRESUID)
- {
- uid_t ruid, euid, suid;
- gid_t rgid, egid, sgid;
- if ((getresuid(&ruid, &euid, &suid) == 0) &&
- (getresgid(&rgid, &egid, &sgid) == 0))
- priv = (euid != suid) || (egid != sgid);
- }
-#else
- /*
- * If there are saved ID's the process might still be priviledged
- * even though the above test succeeded. If issetugid() and
- * getresgid() aren't available, test this by trying to set
- * euid to 0.
- *
- * Note: this only protects setuid-root clients. It doesn't
- * protect other setuid or any setgid clients. If this tradeoff
- * isn't acceptable, set DisableXLocaleDirEnv to YES in host.def.
- */
- unsigned int oldeuid;
- oldeuid = geteuid();
- if (seteuid(0) != 0) {
- priv = 0;
- } else {
- if (seteuid(oldeuid) == -1) {
- /* XXX ouch, coudn't get back to original uid
- what can we do ??? */
- _exit(127);
- }
- priv = 1;
- }
-#endif
- }
-#else
- priv = 0;
-#endif
- if (!priv) {
- len = strlen(dir);
- strncpy(p, dir, buf_len);
- if (len < buf_len) {
- p[len++] = LC_PATHDELIM;
- p += len;
- }
- }
- }
-#endif /* NO_XLOCALEDIR */
-
- if (len < buf_len)
-#ifndef __UNIXOS2__
- strncpy(p, XLOCALELIBDIR, buf_len - len);
-#else
- strncpy(p,__XOS2RedirRoot(XLOCALELIBDIR), buf_len - len);
-#endif
- buf[buf_len-1] = '\0';
-}
-
-/* Mapping direction */
-typedef enum {
- LtoR, /* Map first field to second field */
- RtoL /* Map second field to first field */
-} MapDirection;
-
-static char *
-resolve_name(
- const char *lc_name,
- char *file_name,
- MapDirection direction)
-{
- FILE *fp;
- char buf[XLC_BUFSIZE], *name = NULL;
-
- fp = _XFopenFile (file_name, "r");
- if (fp == NULL)
- return NULL;
-
- while (fgets(buf, XLC_BUFSIZE, fp) != NULL) {
- char *p = buf;
- int n;
- char *args[2], *from, *to;
-#ifdef __UNIXOS2__ /* Take out CR under OS/2 */
- int len;
-
- len = strlen(p);
- if (len > 1) {
- if (*(p+len-2) == '\r' && *(p+len-1) == '\n') {
- *(p+len-2) = '\n';
- *(p+len-1) = '\0';
- }
- }
-#endif
- while (isspace(*p)) {
- ++p;
- }
- if (iscomment(*p)) {
- continue;
- }
- n = parse_line(p, args, 2); /* get first 2 fields */
- if (n != 2) {
- continue;
- }
- if (direction == LtoR) {
- from = args[0], to = args[1]; /* left to right */
- } else {
- from = args[1], to = args[0]; /* right to left */
- }
- if (! strcmp(from, lc_name)) {
- name = Xmalloc(strlen(to) + 1);
- if (name != NULL) {
- strcpy(name, to);
- }
- break;
- }
- }
- fclose(fp);
- return name;
-}
-
-#define c_tolower(ch) ((ch) >= 'A' && (ch) <= 'Z' ? (ch) - 'A' + 'a' : (ch))
-
-static char *
-lowercase(
- char *dst,
- const char *src)
-{
- const char *s;
- char *t;
-
- for (s = src, t = dst; *s; ++s, ++t)
- *t = c_tolower(*s);
- *t = '\0';
- return dst;
-}
-
-/*
- * normalize_lcname(): remove any '_' and '-' and convert any character
- * to lower case after the <language>_<territory> part. If result is identical
- * to argument, free result and
- * return NULL.
- */
-static char *
-normalize_lcname (const char *name)
-{
- char *p, *ret;
- const char *tmp = name;
-
- p = ret = Xmalloc(strlen(name) + 1);
- if (!p)
- return NULL;
-
- if (tmp) {
- while (*tmp && *tmp != '.' && *tmp != '@')
- *p++ = *tmp++;
- while (*tmp) {
- if (*tmp != '-')
- *p++ = c_tolower(*tmp);
- tmp++;
- }
- }
- *p = '\0';
-
- if (strcmp(ret, name) == 0) {
- Xfree(ret);
- return NULL;
- }
-
- return ret;
-}
-
-/************************************************************************/
-char *
-_XlcFileName(
- XLCd lcd,
- const char *category)
-{
- char *siname;
- char cat[XLC_BUFSIZE], dir[XLC_BUFSIZE];
- int i, n;
- char *args[NUM_LOCALEDIR];
- char *file_name = NULL;
-
- if (lcd == (XLCd)NULL)
- return NULL;
-
- siname = XLC_PUBLIC(lcd, siname);
-
- if (category)
- lowercase(cat, category);
- else
- cat[0] = '\0';
- xlocaledir(dir,XLC_BUFSIZE);
- n = _XlcParsePath(dir, args, NUM_LOCALEDIR);
- for (i = 0; i < n; ++i) {
- char buf[PATH_MAX], *name;
-
- name = NULL;
- if ((5 + (args[i] ? strlen (args[i]) : 0) + strlen(cat)) < PATH_MAX) {
- sprintf(buf, "%s/%s.dir", args[i], cat);
- name = resolve_name(siname, buf, RtoL);
- }
- if (name == NULL) {
- continue;
- }
- if (*name == '/') {
- /* supposed to be absolute path name */
- file_name = name;
- } else {
- file_name = Xmalloc(2 + (args[i] ? strlen (args[i]) : 0) +
- (name ? strlen (name) : 0));
- if (file_name != NULL)
- sprintf(file_name, "%s/%s", args[i], name);
- Xfree(name);
- }
- if (isreadable(file_name)) {
- break;
- }
- Xfree(file_name);
- file_name = NULL;
- /* Then, try with next dir */
- }
- return file_name;
-}
-
-/************************************************************************/
-#ifndef LOCALE_ALIAS
-#define LOCALE_ALIAS "locale.alias"
-#endif
-
-int
-_XlcResolveLocaleName(
- const char* lc_name,
- XLCdPublicPart* pub)
-{
- char dir[PATH_MAX], buf[PATH_MAX], *name = NULL;
- char *dst;
- int i, n, sinamelen;
- char *args[NUM_LOCALEDIR];
- static const char locale_alias[] = LOCALE_ALIAS;
- char *tmp_siname;
- char *nlc_name = NULL;
-
- xlocaledir (dir, PATH_MAX);
- n = _XlcParsePath(dir, args, NUM_LOCALEDIR);
- for (i = 0; i < n; ++i) {
- if ((2 + (args[i] ? strlen (args[i]) : 0) +
- strlen (locale_alias)) < PATH_MAX) {
- sprintf (buf, "%s/%s", args[i], locale_alias);
- name = resolve_name (lc_name, buf, LtoR);
- if (!name) {
- if (!nlc_name)
- nlc_name = normalize_lcname(lc_name);
- if (nlc_name)
- name = resolve_name (nlc_name, buf, LtoR);
- }
- }
- if (name != NULL) {
- break;
- }
- }
- if (nlc_name) Xfree(nlc_name);
-
- if (name == NULL) {
- /* vendor locale name == Xlocale name, no expansion of alias */
- pub->siname = Xmalloc (strlen (lc_name) + 1);
- strcpy (pub->siname, lc_name);
- } else {
- pub->siname = name;
- }
-
- sinamelen = strlen (pub->siname);
- if (sinamelen == 1 && pub->siname[0] == 'C') {
- pub->language = pub->siname;
- pub->territory = pub->codeset = NULL;
- return 1;
- }
-
- /*
- * pub->siname is in the format <lang>_<terr>.<codeset>, typical would
- * be "en_US.ISO8859-1", "en_US.utf8", "ru_RU.KOI-8", or ja_JP.SJIS,
- * although it could be ja.SJIS too.
- */
- tmp_siname = Xrealloc (pub->siname, 2 * (sinamelen + 1));
- if (tmp_siname == NULL) {
- return 0;
- }
- pub->siname = tmp_siname;
-
- /* language */
- dst = &pub->siname[sinamelen + 1];
- strcpy (dst, pub->siname);
- pub->language = dst;
-
- /* territory */
- dst = strchr (dst, '_');
- if (dst) {
- *dst = '\0';
- pub->territory = ++dst;
- } else
- dst = &pub->siname[sinamelen + 1];
-
- /* codeset */
- dst = strchr (dst, '.');
- if (dst) {
- *dst = '\0';
- pub->codeset = ++dst;
- }
-
- return (pub->siname[0] != '\0') ? 1 : 0;
-}
-
-/************************************************************************/
-int
-_XlcResolveI18NPath(char *buf, int buf_len)
-{
- if (buf != NULL) {
- xlocaledir(buf, buf_len);
- }
- return 1;
-}
-
-char *
-_XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name)
-{
- char dir[PATH_MAX], buf[PATH_MAX], *name = NULL;
- int i, n;
- char *args[NUM_LOCALEDIR];
- static char locale_alias[] = LOCALE_ALIAS;
- char *target_name = (char*)0;
- char *target_dir = (char*)0;
- char *nlc_name = NULL;
- static char* last_dir_name = 0;
- static size_t last_dir_len = 0;
- static char* last_lc_name = 0;
-
- if (last_lc_name != 0 && strcmp (last_lc_name, lc_name) == 0
- && dir_len >= last_dir_len) {
- strcpy (dir_name, last_dir_name);
- return dir_name;
- }
-
- xlocaledir (dir, PATH_MAX);
- n = _XlcParsePath(dir, args, 256);
- for (i = 0; i < n; ++i) {
-
- if ((2 + (args[i] ? strlen(args[i]) : 0) +
- strlen(locale_alias)) < PATH_MAX) {
- sprintf (buf, "%s/%s", args[i], locale_alias);
- name = resolve_name(lc_name, buf, LtoR);
- if (!name) {
- if (!nlc_name)
- nlc_name = normalize_lcname(lc_name);
- if (nlc_name)
- name = resolve_name (nlc_name, buf, LtoR);
- }
- }
-
- /* If name is not an alias, use lc_name for locale.dir search */
- if (name == NULL)
- name = lc_name;
-
- /* look at locale.dir */
-
- target_dir = args[i];
- if (!target_dir) {
- /* something wrong */
- if (name != lc_name)
- Xfree(name);
- continue;
- }
- if ((1 + strlen (target_dir) + strlen("locale.dir")) < PATH_MAX) {
- sprintf(buf, "%s/locale.dir", target_dir);
- target_name = resolve_name(name, buf, RtoL);
- }
- if (name != lc_name)
- Xfree(name);
- if (target_name != NULL) {
- char *p = 0;
- if ((p = strstr(target_name, "/XLC_LOCALE"))) {
- *p = '\0';
- break;
- }
- Xfree(target_name);
- target_name = NULL;
- }
- name = NULL;
- }
- if (nlc_name) Xfree(nlc_name);
-
- if (target_name == NULL) {
- /* vendor locale name == Xlocale name, no expansion of alias */
- target_dir = args[0];
- target_name = lc_name;
- }
- /* snprintf(dir_name, dir_len, "%s/%", target_dir, target_name); */
- strncpy(dir_name, target_dir, dir_len - 1);
- if (strlen(target_dir) >= dir_len - 1) {
- dir_name[dir_len - 1] = '\0';
- } else {
- strcat(dir_name, "/");
- strncat(dir_name, target_name, dir_len - strlen(dir_name) - 1);
- if (strlen(target_name) >= dir_len - strlen(dir_name) - 1)
- dir_name[dir_len - 1] = '\0';
- }
- if (target_name != lc_name)
- Xfree(target_name);
-
- if (last_dir_name != 0)
- Xfree (last_dir_name);
- if (last_lc_name != 0)
- Xfree (last_lc_name);
- last_dir_len = strlen (dir_name) + 1;
- last_dir_name = Xmalloc (last_dir_len);
- strcpy (last_dir_name, dir_name);
- last_lc_name = Xmalloc (strlen (lc_name) + 1);
- strcpy (last_lc_name, lc_name);
-
- return dir_name;
-}
-
-char *
-_XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name)
-{
- char dir[PATH_MAX], buf[PATH_MAX], *name = NULL;
- int i, n;
- char *args[NUM_LOCALEDIR];
- static char locale_alias[] = LOCALE_ALIAS;
- char *target_name = (char*)0;
- char *target_dir = (char*)0;
- char *nlc_name = NULL;
- static char* last_dir_name = 0;
- static size_t last_dir_len = 0;
- static char* last_lc_name = 0;
-
- if (last_lc_name != 0 && strcmp (last_lc_name, lc_name) == 0
- && dir_len >= last_dir_len) {
- strcpy (dir_name, last_dir_name);
- return dir_name;
- }
-
- xlocalelibdir (dir, PATH_MAX);
- n = _XlcParsePath(dir, args, 256);
- for (i = 0; i < n; ++i) {
-
- if ((2 + (args[i] ? strlen(args[i]) : 0) +
- strlen(locale_alias)) < PATH_MAX) {
- sprintf (buf, "%s/%s", args[i], locale_alias);
- name = resolve_name(lc_name, buf, LtoR);
- if (!name) {
- if (!nlc_name)
- nlc_name = normalize_lcname(lc_name);
- if (nlc_name)
- name = resolve_name (nlc_name, buf, LtoR);
- }
- }
-
- /* If name is not an alias, use lc_name for locale.dir search */
- if (name == NULL)
- name = lc_name;
-
- /* look at locale.dir */
-
- target_dir = args[i];
- if (!target_dir) {
- /* something wrong */
- if (name != lc_name)
- Xfree(name);
- continue;
- }
- if ((1 + strlen (target_dir) + strlen("locale.dir")) < PATH_MAX) {
- sprintf(buf, "%s/locale.dir", target_dir);
- target_name = resolve_name(name, buf, RtoL);
- }
- if (name != lc_name)
- Xfree(name);
- if (target_name != NULL) {
- char *p = 0;
- if ((p = strstr(target_name, "/XLC_LOCALE"))) {
- *p = '\0';
- break;
- }
- Xfree(target_name);
- target_name = NULL;
- }
- name = NULL;
- }
- if (nlc_name) Xfree(nlc_name);
-
- if (target_name == NULL) {
- /* vendor locale name == Xlocale name, no expansion of alias */
- target_dir = args[0];
- target_name = lc_name;
- }
- /* snprintf(dir_name, dir_len, "%s/%", target_dir, target_name); */
- strncpy(dir_name, target_dir, dir_len - 1);
- if (strlen(target_dir) >= dir_len - 1) {
- dir_name[dir_len - 1] = '\0';
- } else {
- strcat(dir_name, "/");
- strncat(dir_name, target_name, dir_len - strlen(dir_name) - 1);
- if (strlen(target_name) >= dir_len - strlen(dir_name) - 1)
- dir_name[dir_len - 1] = '\0';
- }
- if (target_name != lc_name)
- Xfree(target_name);
-
- if (last_dir_name != 0)
- Xfree (last_dir_name);
- if (last_lc_name != 0)
- Xfree (last_lc_name);
- last_dir_len = strlen (dir_name) + 1;
- last_dir_name = Xmalloc (last_dir_len);
- strcpy (last_dir_name, dir_name);
- last_lc_name = Xmalloc (strlen (lc_name) + 1);
- strcpy (last_lc_name, lc_name);
-
- return dir_name;
-}
+/*
+ *
+ * Copyright IBM Corporation 1993
+ *
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of IBM not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ *
+ * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ * ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS, AND
+ * NONINFRINGEMENT OF THIRD PARTY RIGHTS, IN NO EVENT SHALL
+ * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>
+#include "Xlibint.h"
+#include "XlcPubI.h"
+#include <X11/Xos.h>
+#include <unistd.h>
+
+/************************************************************************/
+
+#ifdef __UNIXOS2__
+# define seteuid setuid
+#endif
+#define iscomment(ch) ((ch) == '#' || (ch) == '\0')
+#if defined(WIN32)
+#define isreadable(f) (_XAccessFile(f))
+#else
+#define isreadable(f) ((access((f), R_OK) != -1) ? 1 : 0)
+#endif
+
+#ifndef __UNIXOS2__
+#define LC_PATHDELIM ':'
+#else
+#define LC_PATHDELIM ';'
+#endif
+
+#define XLC_BUFSIZE 256
+
+#ifndef X_NOT_POSIX
+#ifdef _POSIX_SOURCE
+#include <limits.h>
+#else
+#define _POSIX_SOURCE
+#include <limits.h>
+#undef _POSIX_SOURCE
+#endif
+#endif
+#ifndef PATH_MAX
+#ifdef WIN32
+#define PATH_MAX 512
+#else
+#include <sys/param.h>
+#endif
+#ifndef PATH_MAX
+#ifdef MAXPATHLEN
+#define PATH_MAX MAXPATHLEN
+#else
+#define PATH_MAX 1024
+#endif
+#endif
+#endif
+
+#define NUM_LOCALEDIR 64
+
+/* Splits a NUL terminated line into constituents, at colons and newline
+ characters. Leading whitespace is removed from constituents. The
+ constituents are stored at argv[0..argsize-1]. The number of stored
+ constituents (<= argsize) is returned. The line is destructively
+ modified. */
+static int
+parse_line(
+ char *line,
+ char **argv,
+ int argsize)
+{
+ int argc = 0;
+ char *p = line;
+
+ while (argc < argsize) {
+ while (isspace(*p)) {
+ ++p;
+ }
+ if (*p == '\0') {
+ break;
+ }
+ argv[argc++] = p;
+ while (*p != ':' && *p != '\n' && *p != '\0') {
+ ++p;
+ }
+ if (*p == '\0') {
+ break;
+ }
+ *p++ = '\0';
+ }
+
+ return argc;
+}
+
+#ifdef __UNIXOS2__
+
+/* fg021216: entries in locale files are separated by colons while under
+ OS/2, path entries are separated by semicolon, so we need two functions */
+
+static int
+parse_line1(
+ char *line,
+ char **argv,
+ int argsize)
+{
+ int argc = 0;
+ char *p = line;
+
+ while (argc < argsize) {
+ while (isspace(*p)) {
+ ++p;
+ }
+ if (*p == '\0') {
+ break;
+ }
+ argv[argc++] = p;
+ while (*p != ';' && *p != '\n' && *p != '\0') {
+ ++p;
+ }
+ if (*p == '\0') {
+ break;
+ }
+ *p++ = '\0';
+ }
+
+ return argc;
+}
+#elif defined(WIN32)
+
+/* this is parse_line but skips drive letters at the beginning of the entry */
+static int
+parse_line1(
+ char *line,
+ char **argv,
+ int argsize)
+{
+ int argc = 0;
+ char *p = line;
+
+ while (argc < argsize) {
+ while (isspace(*p)) {
+ ++p;
+ }
+ if (*p == '\0') {
+ break;
+ }
+ argv[argc++] = p;
+ if (isalpha(*p) && p[1] == ':') {
+ p+= 2; /* skip drive letters */
+ }
+ while (*p != ':' && *p != '\n' && *p != '\0') {
+ ++p;
+ }
+ if (*p == '\0') {
+ break;
+ }
+ *p++ = '\0';
+ }
+
+ return argc;
+}
+
+#endif /* __UNIXOS2__ */
+
+/* Splits a colon separated list of directories, and returns the constituent
+ paths (without trailing slash). At most argsize constituents are stored
+ at argv[0..argsize-1]. The number of stored constituents is returned. */
+static int
+_XlcParsePath(
+ char *path,
+ char **argv,
+ int argsize)
+{
+ char *p = path;
+ int n, i;
+
+#if !defined(__UNIXOS2__) && !defined(WIN32)
+ n = parse_line(path, argv, argsize);
+#else
+ n = parse_line1(path, argv, argsize);
+#endif
+ for (i = 0; i < n; ++i) {
+ int len;
+ p = argv[i];
+ len = strlen(p);
+ if (len > 0 && p[len - 1] == '/') {
+ /* eliminate trailing slash */
+ p[len - 1] = '\0';
+ }
+ }
+ return n;
+}
+
+#ifndef XLOCALEDIR
+#define XLOCALEDIR "locale"
+#endif
+
+void
+xlocaledir(
+ char *buf,
+ int buf_len)
+{
+ char *p = buf;
+ int len = 0;
+
+#ifndef NO_XLOCALEDIR
+ char *dir;
+ int priv = 1;
+
+ dir = getenv("XLOCALEDIR");
+
+ if (dir) {
+#ifndef WIN32
+ /*
+ * Only use the user-supplied path if the process isn't priviledged.
+ */
+ if (getuid() == geteuid() && getgid() == getegid()) {
+#if defined(HASSETUGID)
+ priv = issetugid();
+#elif defined(HASGETRESUID)
+ {
+ uid_t ruid, euid, suid;
+ gid_t rgid, egid, sgid;
+ if ((getresuid(&ruid, &euid, &suid) == 0) &&
+ (getresgid(&rgid, &egid, &sgid) == 0))
+ priv = (euid != suid) || (egid != sgid);
+ }
+#else
+ /*
+ * If there are saved ID's the process might still be priviledged
+ * even though the above test succeeded. If issetugid() and
+ * getresgid() aren't available, test this by trying to set
+ * euid to 0.
+ *
+ * Note: this only protects setuid-root clients. It doesn't
+ * protect other setuid or any setgid clients. If this tradeoff
+ * isn't acceptable, set DisableXLocaleDirEnv to YES in host.def.
+ */
+ unsigned int oldeuid;
+ oldeuid = geteuid();
+ if (seteuid(0) != 0) {
+ priv = 0;
+ } else {
+ if (seteuid(oldeuid) == -1) {
+ /* XXX ouch, coudn't get back to original uid
+ what can we do ??? */
+ _exit(127);
+ }
+ priv = 1;
+ }
+#endif
+ }
+#else
+ priv = 0;
+#endif
+ if (!priv) {
+ len = strlen(dir);
+ strncpy(p, dir, buf_len);
+ if (len < buf_len) {
+ p[len++] = LC_PATHDELIM;
+ p += len;
+ }
+ }
+ }
+#endif /* NO_XLOCALEDIR */
+
+ if (len < buf_len)
+#ifndef __UNIXOS2__
+ strncpy(p, XLOCALEDIR, buf_len - len);
+#else
+ strncpy(p,__XOS2RedirRoot(XLOCALEDIR), buf_len - len);
+#endif
+ buf[buf_len-1] = '\0';
+}
+
+static void
+xlocalelibdir(
+ char *buf,
+ int buf_len)
+{
+ char *p = buf;
+ int len = 0;
+
+#ifndef NO_XLOCALEDIR
+ char *dir;
+ int priv = 1;
+
+ dir = getenv("XLOCALELIBDIR");
+
+ if (dir) {
+#ifndef WIN32
+ /*
+ * Only use the user-supplied path if the process isn't priviledged.
+ */
+ if (getuid() == geteuid() && getgid() == getegid()) {
+#if defined(HASSETUGID)
+ priv = issetugid();
+#elif defined(HASGETRESUID)
+ {
+ uid_t ruid, euid, suid;
+ gid_t rgid, egid, sgid;
+ if ((getresuid(&ruid, &euid, &suid) == 0) &&
+ (getresgid(&rgid, &egid, &sgid) == 0))
+ priv = (euid != suid) || (egid != sgid);
+ }
+#else
+ /*
+ * If there are saved ID's the process might still be priviledged
+ * even though the above test succeeded. If issetugid() and
+ * getresgid() aren't available, test this by trying to set
+ * euid to 0.
+ *
+ * Note: this only protects setuid-root clients. It doesn't
+ * protect other setuid or any setgid clients. If this tradeoff
+ * isn't acceptable, set DisableXLocaleDirEnv to YES in host.def.
+ */
+ unsigned int oldeuid;
+ oldeuid = geteuid();
+ if (seteuid(0) != 0) {
+ priv = 0;
+ } else {
+ if (seteuid(oldeuid) == -1) {
+ /* XXX ouch, coudn't get back to original uid
+ what can we do ??? */
+ _exit(127);
+ }
+ priv = 1;
+ }
+#endif
+ }
+#else
+ priv = 0;
+#endif
+ if (!priv) {
+ len = strlen(dir);
+ strncpy(p, dir, buf_len);
+ if (len < buf_len) {
+ p[len++] = LC_PATHDELIM;
+ p += len;
+ }
+ }
+ }
+#endif /* NO_XLOCALEDIR */
+
+ if (len < buf_len)
+#ifndef __UNIXOS2__
+ strncpy(p, XLOCALELIBDIR, buf_len - len);
+#else
+ strncpy(p,__XOS2RedirRoot(XLOCALELIBDIR), buf_len - len);
+#endif
+ buf[buf_len-1] = '\0';
+}
+
+/* Mapping direction */
+typedef enum {
+ LtoR, /* Map first field to second field */
+ RtoL /* Map second field to first field */
+} MapDirection;
+
+static char *
+resolve_name(
+ const char *lc_name,
+ char *file_name,
+ MapDirection direction)
+{
+ FILE *fp;
+ char buf[XLC_BUFSIZE], *name = NULL;
+
+ fp = _XFopenFile (file_name, "r");
+ if (fp == NULL)
+ return NULL;
+
+ while (fgets(buf, XLC_BUFSIZE, fp) != NULL) {
+ char *p = buf;
+ int n;
+ char *args[2], *from, *to;
+#ifdef __UNIXOS2__ /* Take out CR under OS/2 */
+ int len;
+
+ len = strlen(p);
+ if (len > 1) {
+ if (*(p+len-2) == '\r' && *(p+len-1) == '\n') {
+ *(p+len-2) = '\n';
+ *(p+len-1) = '\0';
+ }
+ }
+#endif
+ while (isspace(*p)) {
+ ++p;
+ }
+ if (iscomment(*p)) {
+ continue;
+ }
+ n = parse_line(p, args, 2); /* get first 2 fields */
+ if (n != 2) {
+ continue;
+ }
+ if (direction == LtoR) {
+ from = args[0], to = args[1]; /* left to right */
+ } else {
+ from = args[1], to = args[0]; /* right to left */
+ }
+ if (! strcmp(from, lc_name)) {
+ name = strdup(to);
+ break;
+ }
+ }
+ fclose(fp);
+ return name;
+}
+
+#define c_tolower(ch) ((ch) >= 'A' && (ch) <= 'Z' ? (ch) - 'A' + 'a' : (ch))
+
+static char *
+lowercase(
+ char *dst,
+ const char *src)
+{
+ const char *s;
+ char *t;
+
+ for (s = src, t = dst; *s; ++s, ++t)
+ *t = c_tolower(*s);
+ *t = '\0';
+ return dst;
+}
+
+/*
+ * normalize_lcname(): remove any '_' and '-' and convert any character
+ * to lower case after the <language>_<territory> part. If result is identical
+ * to argument, free result and
+ * return NULL.
+ */
+static char *
+normalize_lcname (const char *name)
+{
+ char *p, *ret;
+ const char *tmp = name;
+
+ p = ret = Xmalloc(strlen(name) + 1);
+ if (!p)
+ return NULL;
+
+ if (tmp) {
+ while (*tmp && *tmp != '.' && *tmp != '@')
+ *p++ = *tmp++;
+ while (*tmp) {
+ if (*tmp != '-')
+ *p++ = c_tolower(*tmp);
+ tmp++;
+ }
+ }
+ *p = '\0';
+
+ if (strcmp(ret, name) == 0) {
+ Xfree(ret);
+ return NULL;
+ }
+
+ return ret;
+}
+
+/************************************************************************/
+char *
+_XlcFileName(
+ XLCd lcd,
+ const char *category)
+{
+ char *siname;
+ char cat[XLC_BUFSIZE], dir[XLC_BUFSIZE];
+ int i, n;
+ char *args[NUM_LOCALEDIR];
+ char *file_name = NULL;
+
+ if (lcd == (XLCd)NULL)
+ return NULL;
+
+ siname = XLC_PUBLIC(lcd, siname);
+
+ if (category)
+ lowercase(cat, category);
+ else
+ cat[0] = '\0';
+ xlocaledir(dir,XLC_BUFSIZE);
+ n = _XlcParsePath(dir, args, NUM_LOCALEDIR);
+ for (i = 0; i < n; ++i) {
+ char buf[PATH_MAX], *name;
+
+ name = NULL;
+ if ((5 + (args[i] ? strlen (args[i]) : 0) + strlen(cat)) < PATH_MAX) {
+ sprintf(buf, "%s/%s.dir", args[i], cat);
+ name = resolve_name(siname, buf, RtoL);
+ }
+ if (name == NULL) {
+ continue;
+ }
+ if (*name == '/') {
+ /* supposed to be absolute path name */
+ file_name = name;
+ } else {
+ file_name = Xmalloc(2 + (args[i] ? strlen (args[i]) : 0) +
+ (name ? strlen (name) : 0));
+ if (file_name != NULL)
+ sprintf(file_name, "%s/%s", args[i], name);
+ Xfree(name);
+ }
+ if (isreadable(file_name)) {
+ break;
+ }
+ Xfree(file_name);
+ file_name = NULL;
+ /* Then, try with next dir */
+ }
+ return file_name;
+}
+
+/************************************************************************/
+#ifndef LOCALE_ALIAS
+#define LOCALE_ALIAS "locale.alias"
+#endif
+
+int
+_XlcResolveLocaleName(
+ const char* lc_name,
+ XLCdPublicPart* pub)
+{
+ char dir[PATH_MAX], buf[PATH_MAX], *name = NULL;
+ char *dst;
+ int i, n, sinamelen;
+ char *args[NUM_LOCALEDIR];
+ static const char locale_alias[] = LOCALE_ALIAS;
+ char *tmp_siname;
+ char *nlc_name = NULL;
+
+ xlocaledir (dir, PATH_MAX);
+ n = _XlcParsePath(dir, args, NUM_LOCALEDIR);
+ for (i = 0; i < n; ++i) {
+ if ((2 + (args[i] ? strlen (args[i]) : 0) +
+ strlen (locale_alias)) < PATH_MAX) {
+ sprintf (buf, "%s/%s", args[i], locale_alias);
+ name = resolve_name (lc_name, buf, LtoR);
+ if (!name) {
+ if (!nlc_name)
+ nlc_name = normalize_lcname(lc_name);
+ if (nlc_name)
+ name = resolve_name (nlc_name, buf, LtoR);
+ }
+ }
+ if (name != NULL) {
+ break;
+ }
+ }
+ if (nlc_name) Xfree(nlc_name);
+
+ if (name == NULL) {
+ /* vendor locale name == Xlocale name, no expansion of alias */
+ pub->siname = strdup (lc_name);
+ } else {
+ pub->siname = name;
+ }
+
+ sinamelen = strlen (pub->siname);
+ if (sinamelen == 1 && pub->siname[0] == 'C') {
+ pub->language = pub->siname;
+ pub->territory = pub->codeset = NULL;
+ return 1;
+ }
+
+ /*
+ * pub->siname is in the format <lang>_<terr>.<codeset>, typical would
+ * be "en_US.ISO8859-1", "en_US.utf8", "ru_RU.KOI-8", or ja_JP.SJIS,
+ * although it could be ja.SJIS too.
+ */
+ tmp_siname = Xrealloc (pub->siname, 2 * (sinamelen + 1));
+ if (tmp_siname == NULL) {
+ return 0;
+ }
+ pub->siname = tmp_siname;
+
+ /* language */
+ dst = &pub->siname[sinamelen + 1];
+ strcpy (dst, pub->siname);
+ pub->language = dst;
+
+ /* territory */
+ dst = strchr (dst, '_');
+ if (dst) {
+ *dst = '\0';
+ pub->territory = ++dst;
+ } else
+ dst = &pub->siname[sinamelen + 1];
+
+ /* codeset */
+ dst = strchr (dst, '.');
+ if (dst) {
+ *dst = '\0';
+ pub->codeset = ++dst;
+ }
+
+ return (pub->siname[0] != '\0') ? 1 : 0;
+}
+
+/************************************************************************/
+int
+_XlcResolveI18NPath(char *buf, int buf_len)
+{
+ if (buf != NULL) {
+ xlocaledir(buf, buf_len);
+ }
+ return 1;
+}
+
+char *
+_XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name)
+{
+ char dir[PATH_MAX], buf[PATH_MAX], *name = NULL;
+ int i, n;
+ char *args[NUM_LOCALEDIR];
+ static char locale_alias[] = LOCALE_ALIAS;
+ char *target_name = (char*)0;
+ char *target_dir = (char*)0;
+ char *nlc_name = NULL;
+ static char* last_dir_name = 0;
+ static size_t last_dir_len = 0;
+ static char* last_lc_name = 0;
+
+ if (last_lc_name != 0 && strcmp (last_lc_name, lc_name) == 0
+ && dir_len >= last_dir_len) {
+ strcpy (dir_name, last_dir_name);
+ return dir_name;
+ }
+
+ xlocaledir (dir, PATH_MAX);
+ n = _XlcParsePath(dir, args, 256);
+ for (i = 0; i < n; ++i) {
+
+ if ((2 + (args[i] ? strlen(args[i]) : 0) +
+ strlen(locale_alias)) < PATH_MAX) {
+ sprintf (buf, "%s/%s", args[i], locale_alias);
+ name = resolve_name(lc_name, buf, LtoR);
+ if (!name) {
+ if (!nlc_name)
+ nlc_name = normalize_lcname(lc_name);
+ if (nlc_name)
+ name = resolve_name (nlc_name, buf, LtoR);
+ }
+ }
+
+ /* If name is not an alias, use lc_name for locale.dir search */
+ if (name == NULL)
+ name = lc_name;
+
+ /* look at locale.dir */
+
+ target_dir = args[i];
+ if (!target_dir) {
+ /* something wrong */
+ if (name != lc_name)
+ Xfree(name);
+ continue;
+ }
+ if ((1 + strlen (target_dir) + strlen("locale.dir")) < PATH_MAX) {
+ sprintf(buf, "%s/locale.dir", target_dir);
+ target_name = resolve_name(name, buf, RtoL);
+ }
+ if (name != lc_name)
+ Xfree(name);
+ if (target_name != NULL) {
+ char *p = 0;
+ if ((p = strstr(target_name, "/XLC_LOCALE"))) {
+ *p = '\0';
+ break;
+ }
+ Xfree(target_name);
+ target_name = NULL;
+ }
+ name = NULL;
+ }
+ if (nlc_name) Xfree(nlc_name);
+
+ if (target_name == NULL) {
+ /* vendor locale name == Xlocale name, no expansion of alias */
+ target_dir = args[0];
+ target_name = lc_name;
+ }
+ /* snprintf(dir_name, dir_len, "%s/%", target_dir, target_name); */
+ strncpy(dir_name, target_dir, dir_len - 1);
+ if (strlen(target_dir) >= dir_len - 1) {
+ dir_name[dir_len - 1] = '\0';
+ } else {
+ strcat(dir_name, "/");
+ strncat(dir_name, target_name, dir_len - strlen(dir_name) - 1);
+ if (strlen(target_name) >= dir_len - strlen(dir_name) - 1)
+ dir_name[dir_len - 1] = '\0';
+ }
+ if (target_name != lc_name)
+ Xfree(target_name);
+
+ if (last_dir_name != 0)
+ Xfree (last_dir_name);
+ if (last_lc_name != 0)
+ Xfree (last_lc_name);
+ last_dir_len = strlen (dir_name) + 1;
+ last_dir_name = Xmalloc (last_dir_len);
+ strcpy (last_dir_name, dir_name);
+ last_lc_name = strdup (lc_name);
+
+ return dir_name;
+}
+
+char *
+_XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name)
+{
+ char dir[PATH_MAX], buf[PATH_MAX], *name = NULL;
+ int i, n;
+ char *args[NUM_LOCALEDIR];
+ static char locale_alias[] = LOCALE_ALIAS;
+ char *target_name = (char*)0;
+ char *target_dir = (char*)0;
+ char *nlc_name = NULL;
+ static char* last_dir_name = 0;
+ static size_t last_dir_len = 0;
+ static char* last_lc_name = 0;
+
+ if (last_lc_name != 0 && strcmp (last_lc_name, lc_name) == 0
+ && dir_len >= last_dir_len) {
+ strcpy (dir_name, last_dir_name);
+ return dir_name;
+ }
+
+ xlocalelibdir (dir, PATH_MAX);
+ n = _XlcParsePath(dir, args, 256);
+ for (i = 0; i < n; ++i) {
+
+ if ((2 + (args[i] ? strlen(args[i]) : 0) +
+ strlen(locale_alias)) < PATH_MAX) {
+ sprintf (buf, "%s/%s", args[i], locale_alias);
+ name = resolve_name(lc_name, buf, LtoR);
+ if (!name) {
+ if (!nlc_name)
+ nlc_name = normalize_lcname(lc_name);
+ if (nlc_name)
+ name = resolve_name (nlc_name, buf, LtoR);
+ }
+ }
+
+ /* If name is not an alias, use lc_name for locale.dir search */
+ if (name == NULL)
+ name = lc_name;
+
+ /* look at locale.dir */
+
+ target_dir = args[i];
+ if (!target_dir) {
+ /* something wrong */
+ if (name != lc_name)
+ Xfree(name);
+ continue;
+ }
+ if ((1 + strlen (target_dir) + strlen("locale.dir")) < PATH_MAX) {
+ sprintf(buf, "%s/locale.dir", target_dir);
+ target_name = resolve_name(name, buf, RtoL);
+ }
+ if (name != lc_name)
+ Xfree(name);
+ if (target_name != NULL) {
+ char *p = 0;
+ if ((p = strstr(target_name, "/XLC_LOCALE"))) {
+ *p = '\0';
+ break;
+ }
+ Xfree(target_name);
+ target_name = NULL;
+ }
+ name = NULL;
+ }
+ if (nlc_name) Xfree(nlc_name);
+
+ if (target_name == NULL) {
+ /* vendor locale name == Xlocale name, no expansion of alias */
+ target_dir = args[0];
+ target_name = lc_name;
+ }
+ /* snprintf(dir_name, dir_len, "%s/%", target_dir, target_name); */
+ strncpy(dir_name, target_dir, dir_len - 1);
+ if (strlen(target_dir) >= dir_len - 1) {
+ dir_name[dir_len - 1] = '\0';
+ } else {
+ strcat(dir_name, "/");
+ strncat(dir_name, target_name, dir_len - strlen(dir_name) - 1);
+ if (strlen(target_name) >= dir_len - strlen(dir_name) - 1)
+ dir_name[dir_len - 1] = '\0';
+ }
+ if (target_name != lc_name)
+ Xfree(target_name);
+
+ if (last_dir_name != 0)
+ Xfree (last_dir_name);
+ if (last_lc_name != 0)
+ Xfree (last_lc_name);
+ last_dir_len = strlen (dir_name) + 1;
+ last_dir_name = Xmalloc (last_dir_len);
+ strcpy (last_dir_name, dir_name);
+ last_lc_name = strdup (lc_name);
+
+ return dir_name;
+}
diff --git a/libX11/src/xlibi18n/lcGeneric.c b/libX11/src/xlibi18n/lcGeneric.c
index 688a4cfc4..ec31cb581 100644
--- a/libX11/src/xlibi18n/lcGeneric.c
+++ b/libX11/src/xlibi18n/lcGeneric.c
@@ -1,1191 +1,1180 @@
-/*
- * Copyright 1992, 1993 by TOSHIBA Corp.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of TOSHIBA not be used in advertising
- * or publicity pertaining to distribution of the software without specific,
- * written prior permission. TOSHIBA make no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
- * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- *
- * Author: Katsuhisa Yano TOSHIBA Corp.
- * mopi@osa.ilab.toshiba.co.jp
- */
-/*
- * (c) Copyright 1995 FUJITSU LIMITED
- * This is source code modified by FUJITSU LIMITED under the Joint
- * Development Agreement for the CDE/Motif PST.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include "Xlibint.h"
-#include "XlcGeneric.h"
-
-static XLCd create (const char *name, XLCdMethods methods);
-static Bool initialize (XLCd lcd);
-static void destroy (XLCd lcd);
-
-static XLCdPublicMethodsRec genericMethods = {
- { NULL }, /* use default methods */
- {
- NULL,
- create,
- initialize,
- destroy,
- NULL
- }
-};
-
-XLCdMethods _XlcGenericMethods = (XLCdMethods) &genericMethods;
-
-static XLCd
-create(
- const char *name,
- XLCdMethods methods)
-{
- XLCd lcd;
- XLCdPublicMethods new;
-
- lcd = (XLCd) Xmalloc(sizeof(XLCdRec));
- if (lcd == NULL)
- return (XLCd) NULL;
- bzero((char *) lcd, sizeof(XLCdRec));
-
- lcd->core = (XLCdCore) Xmalloc(sizeof(XLCdGenericRec));
- if (lcd->core == NULL)
- goto err;
- bzero((char *) lcd->core, sizeof(XLCdGenericRec));
-
- new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec));
- if (new == NULL)
- goto err;
- memcpy(new,methods,sizeof(XLCdPublicMethodsRec));
- lcd->methods = (XLCdMethods) new;
-
- return lcd;
-
-err:
- Xfree(lcd);
- return (XLCd) NULL;
-}
-
-static Bool
-string_to_encoding(
- const char *str,
- char *encoding)
-{
- char *next;
- long value;
- int base;
-
- while (*str) {
- if (*str == '\\') {
- switch (*(str + 1)) {
- case 'x':
- case 'X':
- base = 16;
- break;
- default:
- base = 8;
- break;
- }
- value = strtol(str + 2, &next, base);
- if (str + 2 != next) {
- *((unsigned char *) encoding++) = (unsigned char) value;
- str = next;
- continue;
- }
- }
- *encoding++ = *str++;
- }
-
- *encoding = '\0';
-
- return True;
-}
-
-static Bool
-string_to_ulong(
- const char *str,
- unsigned long *value)
-{
- const char *tmp1 = str;
- int base;
-
- if (*tmp1++ != '\\') {
- tmp1--;
- base = 10;
- } else {
- switch (*tmp1++) {
- case 'x':
- base = 16;
- break;
- case 'o':
- base = 8;
- break;
- case 'd':
- base = 10;
- break;
- default:
- return(False);
- }
- }
- *value = (unsigned long) strtol(tmp1, NULL, base);
- return(True);
-}
-
-
-static Bool
-add_charset(
- CodeSet codeset,
- XlcCharSet charset)
-{
- XlcCharSet *new_list;
- int num;
-
- if ((num = codeset->num_charsets))
- new_list = (XlcCharSet *) Xrealloc(codeset->charset_list,
- (num + 1) * sizeof(XlcCharSet));
- else
- new_list = (XlcCharSet *) Xmalloc(sizeof(XlcCharSet));
-
- if (new_list == NULL)
- return False;
-
- new_list[num] = charset;
- codeset->charset_list = new_list;
- codeset->num_charsets = num + 1;
-
- return True;
-}
-
-static CodeSet
-add_codeset(
- XLCdGenericPart *gen)
-{
- CodeSet new, *new_list;
- int num;
-
- new = (CodeSet) Xmalloc(sizeof(CodeSetRec));
- if (new == NULL)
- return NULL;
- bzero((char *) new, sizeof(CodeSetRec));
-
- if ((num = gen->codeset_num))
- new_list = (CodeSet *) Xrealloc(gen->codeset_list,
- (num + 1) * sizeof(CodeSet));
- else
- new_list = (CodeSet *) Xmalloc(sizeof(CodeSet));
-
- if (new_list == NULL)
- goto err;
-
- new_list[num] = new;
- gen->codeset_list = new_list;
- gen->codeset_num = num + 1;
-
- return new;
-
-err:
- Xfree(new);
-
- return NULL;
-}
-
-static Bool
-add_parse_list(
- XLCdGenericPart *gen,
- EncodingType type,
- const char *encoding,
- CodeSet codeset)
-{
- ParseInfo new, *new_list;
- char *str;
- unsigned char ch;
- int num;
-
- str = (char *) Xmalloc(strlen(encoding) + 1);
- if (str == NULL)
- return False;
- strcpy(str, encoding);
-
- new = (ParseInfo) Xmalloc(sizeof(ParseInfoRec));
- if (new == NULL)
- goto err;
- bzero((char *) new, sizeof(ParseInfoRec));
-
- if (gen->mb_parse_table == NULL) {
- gen->mb_parse_table = (unsigned char *) Xmalloc(256); /* 2^8 */
- if (gen->mb_parse_table == NULL)
- goto err;
- bzero((char *) gen->mb_parse_table, 256);
- }
-
- if ((num = gen->mb_parse_list_num))
- new_list = (ParseInfo *) Xrealloc(gen->mb_parse_list,
- (num + 2) * sizeof(ParseInfo));
- else {
- new_list = (ParseInfo *) Xmalloc(2 * sizeof(ParseInfo));
- }
-
- if (new_list == NULL)
- goto err;
-
- new_list[num] = new;
- new_list[num + 1] = NULL;
- gen->mb_parse_list = new_list;
- gen->mb_parse_list_num = num + 1;
-
- ch = (unsigned char) *str;
- if (gen->mb_parse_table[ch] == 0)
- gen->mb_parse_table[ch] = num + 1;
-
- new->type = type;
- new->encoding = str;
- new->codeset = codeset;
-
- if (codeset->parse_info == NULL)
- codeset->parse_info = new;
-
- return True;
-
-err:
- Xfree(str);
- if (new)
- Xfree(new);
-
- return False;
-}
-
-static void
-free_charset(
- XLCd lcd)
-{
- XLCdGenericPart *gen = XLC_GENERIC_PART(lcd);
- ParseInfo *parse_info;
- int num;
-
- if (gen->mb_parse_table)
- Xfree(gen->mb_parse_table);
- if ((num = gen->mb_parse_list_num) > 0) {
- for (parse_info = gen->mb_parse_list; num-- > 0; parse_info++) {
- if ((*parse_info)->encoding)
- Xfree((*parse_info)->encoding);
- Xfree(*parse_info);
- }
- Xfree(gen->mb_parse_list);
- }
-
- if ((num = gen->codeset_num) > 0)
- Xfree(gen->codeset_list);
-}
-
-/* For VW/UDC */
-
-#define FORWARD (unsigned long)'+'
-#define BACKWARD (unsigned long)'-'
-
-static const char *
-getscope(
- const char *str,
- FontScope scp)
-{
- unsigned long start = 0;
- unsigned long end = 0;
- unsigned long dest = 0;
- unsigned long shift = 0;
- unsigned long direction = 0;
- sscanf(str,"[\\x%lx,\\x%lx]->\\x%lx", &start, &end, &dest);
- if (dest) {
- if (dest >= start) {
- shift = dest - start;
- direction = FORWARD ;
- } else {
- shift = start - dest;
- direction = BACKWARD;
- }
- }
- scp->start = start ;
- scp->end = end ;
- scp->shift = shift ;
- scp->shift_direction
- = direction ;
- /* .......... */
- while (*str) {
- if (*str == ',' && *(str+1) == '[')
- break;
- str++;
- }
- return str+1;
-}
-
-static int
-count_scopemap(
- const char *str)
-{
- const char *ptr;
- int num=0;
- for (ptr=str; *ptr; ptr++) {
- if (*ptr == ']') {
- num++;
- }
- }
- return num;
-}
-
-FontScope
-_XlcParse_scopemaps(
- const char *str,
- int *size)
-{
- int num=0,i;
- FontScope scope,sc_ptr;
- const char *str_sc;
-
- num = count_scopemap(str);
- scope = (FontScope) Xmalloc(num * sizeof(FontScopeRec));
- if (scope == NULL)
- return NULL;
-
- for (i=0, str_sc=str, sc_ptr=scope; i < num; i++, sc_ptr++) {
- str_sc = getscope(str_sc, sc_ptr);
- }
- *size = num;
- return scope;
-}
-
-void
-_XlcDbg_printValue(
- const char *str,
- char **value,
- int num)
-{
-/*
- int i;
- for (i = 0; i < num; i++)
- fprintf(stderr, "%s value[%d] = %s\n", str, i, value[i]);
-*/
-}
-
-static void
-dmpscope(
- const char* name,
- FontScope sc,
- int num)
-{
-/*
- int i;
- fprintf(stderr, "dmpscope %s\n", name);
- for (i=0; i<num; i++)
- fprintf(stderr,"%x %x %x %x \n",
- sc[i].start,
- sc[i].end,
- sc[i].shift,
- sc[i].shift_direction);
- fprintf(stderr, "dmpscope end\n");
-*/
-}
-
-static XlcCharSet
-srch_charset_define(
- const char *name,
- int *new)
-{
- XlcCharSet charset;
-
- *new = 0;
- charset = _XlcGetCharSet(name);
- if (charset == NULL &&
- (charset = _XlcCreateDefaultCharSet(name, ""))) {
- _XlcAddCharSet(charset);
- *new = 1;
- charset->source = CSsrcXLC;
- }
- return charset;
-}
-
-static void
-read_charset_define(
- XLCd lcd,
- XLCdGenericPart *gen)
-{
- int i;
- char csd[16], cset_name[256];
- char name[BUFSIZ];
- XlcCharSet charsetd;
- char **value;
- int num, new = 0;
- XlcSide side = XlcUnknown;
- char *tmp;
-
- for (i=0; ; i++) { /* loop start */
- charsetd = 0;
- sprintf(csd, "csd%d", i);
-
- /* charset_name */
- sprintf(name, "%s.%s", csd, "charset_name");
- _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
- _XlcDbg_printValue(name,value,num);
- if (num > 0) {
- /* hackers will get truncated -- C'est la vie */
- strncpy(cset_name,value[0], sizeof cset_name - 1);
- cset_name[(sizeof cset_name) - 1] = '\0';
- sprintf(name, "%s.%s", csd , "side");
- _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
- if (!_XlcNCompareISOLatin1(value[0], "none", 4)) {
- side = XlcGLGR;
- } else if (!_XlcNCompareISOLatin1(value[0], "GL", 2)) {
- side = XlcGL;
- strcat(cset_name,":GL");
- } else {
- side = XlcGR;
- strcat(cset_name,":GR");
- }
- if (charsetd == NULL &&
- (charsetd = srch_charset_define(cset_name,&new)) == NULL)
- return;
- }
- } else {
- if (i == 0)
- continue;
- else
- break;
- }
- if (new) {
- tmp = (char *)Xmalloc(strlen(cset_name)+1);
- if (tmp == NULL)
- return;
- strcpy(tmp,cset_name);
- charsetd->name = tmp;
- }
- /* side */
- charsetd->side = side ;
- /* length */
- sprintf(name, "%s.%s", csd, "length");
- _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
- charsetd->char_size = atoi(value[0]);
- }
- /* gc_number */
- sprintf(name, "%s.%s", csd, "gc_number");
- _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
- charsetd->set_size = atoi(value[0]);
- }
- /* string_encoding */
- sprintf(name, "%s.%s", csd, "string_encoding");
- _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
- if (!strcmp("False",value[0])) {
- charsetd->string_encoding = False;
- } else {
- charsetd->string_encoding = True;
- }
- }
- /* sequence */
- sprintf(name, "%s.%s", csd, "sequence");
- _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
-/*
- if (charsetd->ct_sequence) {
- Xfree(charsetd->ct_sequence);
- }
-*/
- tmp = (char *)Xmalloc(strlen(value[0])+1);
- if (tmp == NULL)
- return;
- charsetd->ct_sequence = tmp;
- string_to_encoding(value[0],tmp);
- }
- /* encoding_name */
- sprintf(name, "%s.%s", csd, "encoding_name");
- _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
-/*
- if (charsetd->encoding_name) {
- Xfree(charsetd->encoding_name);
- }
-*/
- tmp = (char *)Xmalloc(strlen(value[0])+1);
- strcpy(tmp,value[0]);
- charsetd->encoding_name = tmp;
- charsetd->xrm_encoding_name = XrmStringToQuark(tmp);
- }
- _XlcAddCT(charsetd->name, charsetd->ct_sequence);
- }
-}
-
-static SegConv
-add_conversion(
- XLCdGenericPart *gen)
-{
- SegConv new_list;
- int num;
-
- if ((num = gen->segment_conv_num) > 0) {
- new_list = (SegConv) Xrealloc(gen->segment_conv,
- (num + 1) * sizeof(SegConvRec));
- } else {
- new_list = (SegConv) Xmalloc(sizeof(SegConvRec));
- }
-
- if (new_list == NULL)
- return NULL;
-
- gen->segment_conv = new_list;
- gen->segment_conv_num = num + 1;
-
- return &new_list[num];
-
-}
-
-static void
-read_segmentconversion(
- XLCd lcd,
- XLCdGenericPart *gen)
-{
- int i;
- char conv[16];
- char name[BUFSIZ];
- char **value;
- int num,new;
- SegConv conversion;
- for (i=0 ; ; i++) { /* loop start */
- conversion = 0;
- sprintf(conv, "conv%d", i);
-
- /* length */
- sprintf(name, "%s.%s", conv, "length");
- _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
- if (num > 0) {
- if (conversion == NULL &&
- (conversion = add_conversion(gen)) == NULL) {
- return;
- }
- _XlcDbg_printValue(name,value,num);
- } else {
- if (i == 0)
- continue;
- else
- break;
- }
- conversion->length = atoi(value[0]);
-
- /* source_encoding */
- sprintf(name, "%s.%s", conv, "source_encoding");
- _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
- if (num > 0) {
- char *tmp;
- _XlcDbg_printValue(name,value,num);
- tmp = (char *)Xmalloc(strlen(value[0])+1);
- if (tmp == NULL)
- return;
- strcpy(tmp,value[0]);
- conversion->source_encoding = tmp;
- conversion->source = srch_charset_define(tmp,&new);
- }
- /* destination_encoding */
- sprintf(name, "%s.%s", conv, "destination_encoding");
- _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
- if (num > 0) {
- char *tmp;
- _XlcDbg_printValue(name,value,num);
- tmp = (char *)Xmalloc(strlen(value[0])+1);
- if (tmp == NULL)
- return;
- strcpy(tmp,value[0]);
- conversion->destination_encoding = tmp;
- conversion->dest = srch_charset_define(tmp,&new);
- }
- /* range */
- sprintf(name, "%s.%s", conv, "range");
- _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
- sscanf(value[0],"\\x%lx,\\x%lx",
- &(conversion->range.start), &(conversion->range.end));
- }
- /* conversion */
- sprintf(name, "%s.%s", conv, "conversion");
- _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
- conversion->conv =
- _XlcParse_scopemaps(value[0],&conversion->conv_num);
- }
- } /* loop end */
-}
-
-static ExtdSegment
-create_ctextseg(
- char **value,
- int num)
-{
- ExtdSegment ret;
- char* ptr;
- char* cset_name = NULL;
- int i,new;
- FontScope scope;
- ret = (ExtdSegment)Xmalloc(sizeof(ExtdSegmentRec));
- if (ret == NULL)
- return NULL;
- ret->name = (char *)Xmalloc(strlen(value[0]) + 1);
- if (ret->name == NULL) {
- Xfree (ret);
- return NULL;
- }
- strcpy(ret->name,value[0]);
- cset_name = (char*) Xmalloc (strlen(ret->name) + 1);
- if (cset_name == NULL) {
- Xfree (ret->name);
- Xfree (ret);
- return NULL;
- }
- if (strchr(value[0],':')) {
- ptr = strchr(ret->name,':');
- *ptr = '\0';
- ptr++;
- if (!_XlcNCompareISOLatin1(ptr, "GL", 2)) {
- ret->side = XlcGL;
- sprintf(cset_name,"%s:%s",ret->name,"GL");
- } else {
- ret->side = XlcGR;
- sprintf(cset_name,"%s:%s",ret->name,"GR");
- }
- } else {
- ret->side = XlcGLGR;
- strcpy(cset_name,ret->name);
- }
- ret->area = (FontScope)Xmalloc((num - 1)*sizeof(FontScopeRec));
- if (ret->area == NULL) {
- Xfree (cset_name);
- Xfree (ret->name);
- Xfree (ret);
- return NULL;
- }
- ret->area_num = num - 1;
- scope = ret->area ;
- for (i = 1; i < num; i++) {
- sscanf(value[i],"\\x%lx,\\x%lx",
- &scope[i-1].start, &scope[i-1].end);
- }
- ret->charset = srch_charset_define(cset_name,&new);
- Xfree (cset_name);
-
- return ret;
-}
-/* For VW/UDC end */
-
-static Bool
-load_generic(
- XLCd lcd)
-{
- XLCdGenericPart *gen = XLC_GENERIC_PART(lcd);
- char **value;
- int num;
- unsigned long l;
- int i;
- int M,ii;
- XlcCharSet charset;
-
- gen->codeset_num = 0;
-
- /***** wc_encoding_mask *****/
- _XlcGetResource(lcd, "XLC_XLOCALE", "wc_encoding_mask", &value, &num);
- if (num > 0) {
- if (string_to_ulong(value[0], &l) == False)
- goto err;
- gen->wc_encode_mask = l;
- }
- /***** wc_shift_bits *****/
- _XlcGetResource(lcd, "XLC_XLOCALE", "wc_shift_bits", &value, &num);
- if (num > 0)
- gen->wc_shift_bits = atoi(value[0]);
- if (gen->wc_shift_bits < 1)
- gen->wc_shift_bits = 8;
- /***** use_stdc_env *****/
- _XlcGetResource(lcd, "XLC_XLOCALE", "use_stdc_env", &value, &num);
- if (num > 0 && !_XlcCompareISOLatin1(value[0], "True"))
- gen->use_stdc_env = True;
- else
- gen->use_stdc_env = False;
- /***** force_convert_to_mb *****/
- _XlcGetResource(lcd, "XLC_XLOCALE", "force_convert_to_mb", &value, &num);
- if (num > 0 && !_XlcCompareISOLatin1(value[0], "True"))
- gen->force_convert_to_mb = True;
- else
- gen->force_convert_to_mb = False;
-
- for (i = 0; ; i++) {
- CodeSetRec *codeset = NULL;
- char cs[16];
- char name[BUFSIZ];
-
- sprintf(cs, "cs%d", i);
-
- /***** codeset.side *****/
- sprintf(name, "%s.%s", cs , "side");
- _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
- if (num > 0) {
- char *tmp;
-
- if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
- goto err;
-
- /* 3.4.1 side */
- if (!_XlcNCompareISOLatin1(value[0], "none", 4)) {
- codeset->side = XlcNONE;
- } else if (!_XlcNCompareISOLatin1(value[0], "GL", 2)) {
- codeset->side = XlcGL;
- } else {
- codeset->side = XlcGR;
- }
-
- tmp = strrchr(value[0], ':');
- if (tmp != NULL && !_XlcCompareISOLatin1(tmp + 1, "Default")) {
- if (codeset->side == XlcGR)
- gen->initial_state_GR = codeset;
- else
- gen->initial_state_GL = codeset;
- }
- }
-
- /***** codeset.length *****/
- sprintf(name, "%s.%s", cs , "length");
- _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
- if (num > 0) {
- if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
- goto err;
- codeset->length = atoi(value[0]);
- if (codeset->length < 1)
- codeset->length = 1;
- }
-
- /***** codeset.mb_encoding *****/
- sprintf(name, "%s.%s", cs, "mb_encoding");
- _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
- if (num > 0) {
- static struct {
- const char *str;
- EncodingType type;
- } shifts[] = {
- {"<SS>", E_SS},
- {"<LSL>", E_LSL},
- {"<LSR>", E_LSR},
- {0}
- };
- int j;
-
- if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
- goto err;
- for ( ; num-- > 0; value++) {
- char encoding[256];
- char *tmp = *value;
- EncodingType type = E_SS; /* for BC */
- for (j = 0; shifts[j].str; j++) {
- if (!_XlcNCompareISOLatin1(tmp, shifts[j].str,
- strlen(shifts[j].str))) {
- type = shifts[j].type;
- tmp += strlen(shifts[j].str);
- break;
- }
- }
- if (strlen (tmp) > sizeof encoding ||
- string_to_encoding(tmp, encoding) == False)
- goto err;
- add_parse_list(gen, type, encoding, codeset);
- }
- }
-
- /***** codeset.wc_encoding *****/
- sprintf(name, "%s.%s", cs, "wc_encoding");
- _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
- if (num > 0) {
- if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
- goto err;
- if (string_to_ulong(value[0], &l) == False)
- goto err;
- codeset->wc_encoding = l;
- }
-
- /***** codeset.ct_encoding *****/
- sprintf(name, "%s.%s", cs, "ct_encoding");
- _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
- if (num > 0) {
- char *encoding;
-
- if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
- goto err;
- for ( ; num-- > 0; value++) {
- if (strlen (*value) > sizeof name)
- goto err;
- string_to_encoding(*value, name);
- charset = NULL;
- if ((encoding = strchr(name, ':')) &&
- (encoding = strchr(encoding + 1, ':'))) {
- *encoding++ = '\0';
- charset = _XlcAddCT(name, encoding);
- }
- if (charset == NULL) {
- charset = _XlcGetCharSet(name);
- if (charset == NULL &&
- (charset = _XlcCreateDefaultCharSet(name, ""))) {
- charset->side = codeset->side;
- charset->char_size = codeset->length;
- _XlcAddCharSet(charset);
- }
- }
- if (charset) {
- if (add_charset(codeset, charset) == False)
- goto err;
- }
- }
- }
-
- if (codeset == NULL)
- break;
- codeset->cs_num = i;
- /* For VW/UDC */
- /***** 3.4.2 byteM (1 <= M <= length)*****/
- for (M=1; M-1 < codeset->length; M++) {
- unsigned long start,end;
- ByteInfo tmpb;
-
- sprintf(name,"%s.%s%d",cs,"byte",M);
- _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
-
- if (M == 1) {
- if (num < 1) {
- codeset->byteM = NULL;
- break ;
- }
- codeset->byteM =
- (ByteInfoListRec *)Xmalloc(
- (codeset->length)*sizeof(ByteInfoListRec));
- if (codeset->byteM == NULL) {
- goto err;
- }
- }
-
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
- (codeset->byteM)[M-1].M = M;
- (codeset->byteM)[M-1].byteinfo_num = num;
- (codeset->byteM)[M-1].byteinfo =
- (ByteInfo)Xmalloc( num * sizeof(ByteInfoRec));
- for (ii = 0 ; ii < num ; ii++) {
- tmpb = (codeset->byteM)[M-1].byteinfo ;
- /* default 0x00 - 0xff */
- sscanf(value[ii],"\\x%lx,\\x%lx",&start,&end);
- tmpb[ii].start = (unsigned char)start;
- tmpb[ii].end = (unsigned char)end;
- }
- }
- /* .... */
- }
-
-
- /***** codeset.mb_conversion *****/
- sprintf(name, "%s.%s", cs, "mb_conversion");
- _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
- codeset->mbconv = Xmalloc(sizeof(ConversionRec));
- codeset->mbconv->convlist =
- _XlcParse_scopemaps(value[0],&(codeset->mbconv->conv_num));
- dmpscope("mb_conv",codeset->mbconv->convlist,
- codeset->mbconv->conv_num);
- /* [\x%x,\x%x]->\x%x,... */
- }
- /***** codeset.ct_conversion *****/
- sprintf(name, "%s.%s", cs, "ct_conversion");
- _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
- codeset->ctconv = Xmalloc(sizeof(ConversionRec));
- codeset->ctconv->convlist =
- _XlcParse_scopemaps(value[0],&(codeset->ctconv->conv_num));
- dmpscope("ctconv",codeset->ctconv->convlist,
- codeset->ctconv->conv_num);
- /* [\x%x,\x%x]->\x%x,... */
- }
- /***** codeset.ct_conversion_file *****/
- sprintf(name, "%s.%s", cs, "ct_conversion_file");
- _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
- /* [\x%x,\x%x]->\x%x,... */
- }
- /***** codeset.ct_extended_segment *****/
- sprintf(name, "%s.%s", cs, "ct_extended_segment");
- _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
- codeset->ctextseg = create_ctextseg(value,num);
- /* [\x%x,\x%x]->\x%x,... */
- }
- /* For VW/UDC end */
-
- }
-
- read_charset_define(lcd,gen); /* For VW/UDC */
- read_segmentconversion(lcd,gen); /* For VW/UDC */
-
- if (gen->initial_state_GL == NULL) {
- CodeSetRec *codeset;
- for (i = 0; i < gen->codeset_num; i++) {
- codeset = gen->codeset_list[i];
- if (codeset->side == XlcGL)
- gen->initial_state_GL = codeset;
- }
- }
-
- if (gen->initial_state_GR == NULL) {
- CodeSetRec *codeset;
- for (i = 0; i < gen->codeset_num; i++) {
- codeset = gen->codeset_list[i];
- if (codeset->side == XlcGR)
- gen->initial_state_GR = codeset;
- }
- }
-
- for (i = 0; i < gen->codeset_num; i++) {
- CodeSetRec *codeset = gen->codeset_list[i];
- for (ii = 0; ii < codeset->num_charsets; ii++) {
- charset = codeset->charset_list[ii];
- if (! strcmp(charset->encoding_name, "ISO8859-1"))
- charset->string_encoding = True;
- if ( charset->string_encoding )
- codeset->string_encoding = True;
- }
- }
- return True;
-
-err:
- free_charset(lcd);
-
- return False;
-}
-
-#ifdef USE_DYNAMIC_LC
-/* override the open_om and open_im methods which were set by
- super_class's initialize method() */
-
-static Bool
-initialize_core(
- XLCd lcd)
-{
- _XInitDynamicOM(lcd);
-
- _XInitDynamicIM(lcd);
-
- return True;
-}
-#endif
-
-static Bool
-initialize(XLCd lcd)
-{
- XLCdPublicMethods superclass = (XLCdPublicMethods) _XlcPublicMethods;
-
- XLC_PUBLIC_METHODS(lcd)->superclass = superclass;
-
- if (superclass->pub.initialize) {
- if ((*superclass->pub.initialize)(lcd) == False)
- return False;
- }
-
-#ifdef USE_DYNAMIC_LC
- if (initialize_core(lcd) == False)
- return False;
-#endif
-
- if (load_generic(lcd) == False)
- return False;
-
- return True;
-}
-
-/* VW/UDC start 95.01.08 */
-static void
-freeByteM(
- CodeSet codeset)
-{
- int i;
- ByteInfoList blst;
- if (codeset->byteM == NULL) {
- return ;
- }
- blst = codeset->byteM;
- for (i = 0; i < codeset->length; i++) {
- if (blst[i].byteinfo) {
- Xfree(blst[i].byteinfo);
- blst[i].byteinfo = NULL;
- }
- }
- Xfree(codeset->byteM);
- codeset->byteM = NULL;
-}
-
-static void
-freeConversion(
- CodeSet codeset)
-{
- Conversion mbconv,ctconv;
- if (codeset->mbconv) {
- mbconv = codeset->mbconv;
- /* ... */
- if (mbconv->convlist) {
- Xfree(mbconv->convlist);
- mbconv->convlist = NULL;
- }
- Xfree(mbconv);
- codeset->mbconv = NULL;
- }
- if (codeset->ctconv) {
- ctconv = codeset->ctconv;
- /* ... */
- if (ctconv->convlist) {
- Xfree(ctconv->convlist);
- ctconv->convlist = NULL;
- }
- Xfree(ctconv);
- codeset->ctconv = NULL;
- }
-}
-
-static void
-freeExtdSegment(
- CodeSet codeset)
-{
- ExtdSegment ctextseg;
- if (codeset->ctextseg == NULL) {
- return;
- }
- ctextseg = codeset->ctextseg;
- if (ctextseg->name) {
- Xfree(ctextseg->name);
- ctextseg->name = NULL;
- }
- if (ctextseg->area) {
- Xfree(ctextseg->area);
- ctextseg->area = NULL;
- }
- Xfree(codeset->ctextseg);
- codeset->ctextseg = NULL;
-}
-
-static void
-freeParseInfo(
- CodeSet codeset)
-{
- ParseInfo parse_info;
- if (codeset->parse_info == NULL) {
- return;
- }
- parse_info = codeset->parse_info;
- if (parse_info->encoding) {
- Xfree(parse_info->encoding);
- parse_info->encoding = NULL;
- }
- Xfree(codeset->parse_info);
- codeset->parse_info = NULL;
-}
-
-static void
-destroy_CodeSetList(
- XLCdGenericPart *gen)
-{
- CodeSet *codeset = gen->codeset_list;
- int i;
- if (gen->codeset_num == 0) {
- return;
- }
- for (i=0;i<gen->codeset_num;i++) {
- freeByteM(codeset[i]);
- freeConversion(codeset[i]);
- freeExtdSegment(codeset[i]);
- freeParseInfo(codeset[i]);
- if (codeset[i]->charset_list) {
- Xfree(codeset[i]->charset_list);
- codeset[i]->charset_list = NULL;
- }
- Xfree(codeset[i]); codeset[i]=NULL;
- }
- Xfree(codeset); gen->codeset_list = NULL;
-}
-
-static void
-destroy_SegConv(
- XLCdGenericPart *gen)
-{
- SegConv seg = gen->segment_conv;
- int i;
- if (gen->segment_conv_num == 0) {
- return;
- }
- for (i=0;i<gen->segment_conv_num;i++) {
- if (seg[i].source_encoding) {
- Xfree(seg[i].source_encoding);
- seg[i].source_encoding = NULL;
- }
- if (seg[i].destination_encoding) {
- Xfree(seg[i].destination_encoding);
- seg[i].destination_encoding = NULL;
- }
- if (seg[i].conv) {
- Xfree(seg[i].conv); seg[i].conv = NULL;
- }
- }
- Xfree(seg); gen->segment_conv = NULL;
-}
-
-static void
-destroy_gen(
- XLCd lcd)
-{
- XLCdGenericPart *gen = XLC_GENERIC_PART(lcd);
- destroy_SegConv(gen);
- destroy_CodeSetList(gen);
- if (gen->mb_parse_table) {
- Xfree(gen->mb_parse_table);
- gen->mb_parse_table = NULL;
- }
- if (gen->mb_parse_list) {
- Xfree(gen->mb_parse_list);
- gen->mb_parse_list = NULL;
- }
-}
-/* VW/UDC end 95.01.08 */
-
-static void
-destroy(
- XLCd lcd)
-{
- XLCdPublicMethods superclass = XLC_PUBLIC_METHODS(lcd)->superclass;
-
- destroy_gen(lcd); /* ADD 1996.01.08 */
- if (superclass && superclass->pub.destroy)
- (*superclass->pub.destroy)(lcd);
-}
+/*
+ * Copyright 1992, 1993 by TOSHIBA Corp.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of TOSHIBA not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission. TOSHIBA make no representations about the
+ * suitability of this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+ * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Author: Katsuhisa Yano TOSHIBA Corp.
+ * mopi@osa.ilab.toshiba.co.jp
+ */
+/*
+ * (c) Copyright 1995 FUJITSU LIMITED
+ * This is source code modified by FUJITSU LIMITED under the Joint
+ * Development Agreement for the CDE/Motif PST.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include "Xlibint.h"
+#include "XlcGeneric.h"
+
+static XLCd create (const char *name, XLCdMethods methods);
+static Bool initialize (XLCd lcd);
+static void destroy (XLCd lcd);
+
+static XLCdPublicMethodsRec genericMethods = {
+ { NULL }, /* use default methods */
+ {
+ NULL,
+ create,
+ initialize,
+ destroy,
+ NULL
+ }
+};
+
+XLCdMethods _XlcGenericMethods = (XLCdMethods) &genericMethods;
+
+static XLCd
+create(
+ const char *name,
+ XLCdMethods methods)
+{
+ XLCd lcd;
+ XLCdPublicMethods new;
+
+ lcd = Xcalloc(1, sizeof(XLCdRec));
+ if (lcd == NULL)
+ return (XLCd) NULL;
+
+ lcd->core = Xcalloc(1, sizeof(XLCdGenericRec));
+ if (lcd->core == NULL)
+ goto err;
+
+ new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec));
+ if (new == NULL)
+ goto err;
+ memcpy(new,methods,sizeof(XLCdPublicMethodsRec));
+ lcd->methods = (XLCdMethods) new;
+
+ return lcd;
+
+err:
+ Xfree(lcd);
+ return (XLCd) NULL;
+}
+
+static Bool
+string_to_encoding(
+ const char *str,
+ char *encoding)
+{
+ char *next;
+ long value;
+ int base;
+
+ while (*str) {
+ if (*str == '\\') {
+ switch (*(str + 1)) {
+ case 'x':
+ case 'X':
+ base = 16;
+ break;
+ default:
+ base = 8;
+ break;
+ }
+ value = strtol(str + 2, &next, base);
+ if (str + 2 != next) {
+ *((unsigned char *) encoding++) = (unsigned char) value;
+ str = next;
+ continue;
+ }
+ }
+ *encoding++ = *str++;
+ }
+
+ *encoding = '\0';
+
+ return True;
+}
+
+static Bool
+string_to_ulong(
+ const char *str,
+ unsigned long *value)
+{
+ const char *tmp1 = str;
+ int base;
+
+ if (*tmp1++ != '\\') {
+ tmp1--;
+ base = 10;
+ } else {
+ switch (*tmp1++) {
+ case 'x':
+ base = 16;
+ break;
+ case 'o':
+ base = 8;
+ break;
+ case 'd':
+ base = 10;
+ break;
+ default:
+ return(False);
+ }
+ }
+ *value = (unsigned long) strtol(tmp1, NULL, base);
+ return(True);
+}
+
+
+static Bool
+add_charset(
+ CodeSet codeset,
+ XlcCharSet charset)
+{
+ XlcCharSet *new_list;
+ int num;
+
+ if ((num = codeset->num_charsets))
+ new_list = (XlcCharSet *) Xrealloc(codeset->charset_list,
+ (num + 1) * sizeof(XlcCharSet));
+ else
+ new_list = (XlcCharSet *) Xmalloc(sizeof(XlcCharSet));
+
+ if (new_list == NULL)
+ return False;
+
+ new_list[num] = charset;
+ codeset->charset_list = new_list;
+ codeset->num_charsets = num + 1;
+
+ return True;
+}
+
+static CodeSet
+add_codeset(
+ XLCdGenericPart *gen)
+{
+ CodeSet new, *new_list;
+ int num;
+
+ new = Xcalloc(1, sizeof(CodeSetRec));
+ if (new == NULL)
+ return NULL;
+
+ if ((num = gen->codeset_num))
+ new_list = (CodeSet *) Xrealloc(gen->codeset_list,
+ (num + 1) * sizeof(CodeSet));
+ else
+ new_list = (CodeSet *) Xmalloc(sizeof(CodeSet));
+
+ if (new_list == NULL)
+ goto err;
+
+ new_list[num] = new;
+ gen->codeset_list = new_list;
+ gen->codeset_num = num + 1;
+
+ return new;
+
+err:
+ Xfree(new);
+
+ return NULL;
+}
+
+static Bool
+add_parse_list(
+ XLCdGenericPart *gen,
+ EncodingType type,
+ const char *encoding,
+ CodeSet codeset)
+{
+ ParseInfo new, *new_list;
+ char *str;
+ unsigned char ch;
+ int num;
+
+ str = strdup(encoding);
+ if (str == NULL)
+ return False;
+
+ new = Xcalloc(1, sizeof(ParseInfoRec));
+ if (new == NULL)
+ goto err;
+
+ if (gen->mb_parse_table == NULL) {
+ gen->mb_parse_table = Xcalloc(1, 256); /* 2^8 */
+ if (gen->mb_parse_table == NULL)
+ goto err;
+ }
+
+ if ((num = gen->mb_parse_list_num))
+ new_list = (ParseInfo *) Xrealloc(gen->mb_parse_list,
+ (num + 2) * sizeof(ParseInfo));
+ else {
+ new_list = (ParseInfo *) Xmalloc(2 * sizeof(ParseInfo));
+ }
+
+ if (new_list == NULL)
+ goto err;
+
+ new_list[num] = new;
+ new_list[num + 1] = NULL;
+ gen->mb_parse_list = new_list;
+ gen->mb_parse_list_num = num + 1;
+
+ ch = (unsigned char) *str;
+ if (gen->mb_parse_table[ch] == 0)
+ gen->mb_parse_table[ch] = num + 1;
+
+ new->type = type;
+ new->encoding = str;
+ new->codeset = codeset;
+
+ if (codeset->parse_info == NULL)
+ codeset->parse_info = new;
+
+ return True;
+
+err:
+ Xfree(str);
+ if (new)
+ Xfree(new);
+
+ return False;
+}
+
+static void
+free_charset(
+ XLCd lcd)
+{
+ XLCdGenericPart *gen = XLC_GENERIC_PART(lcd);
+ ParseInfo *parse_info;
+ int num;
+
+ if (gen->mb_parse_table)
+ Xfree(gen->mb_parse_table);
+ if ((num = gen->mb_parse_list_num) > 0) {
+ for (parse_info = gen->mb_parse_list; num-- > 0; parse_info++) {
+ if ((*parse_info)->encoding)
+ Xfree((*parse_info)->encoding);
+ Xfree(*parse_info);
+ }
+ Xfree(gen->mb_parse_list);
+ }
+
+ if ((num = gen->codeset_num) > 0)
+ Xfree(gen->codeset_list);
+}
+
+/* For VW/UDC */
+
+#define FORWARD (unsigned long)'+'
+#define BACKWARD (unsigned long)'-'
+
+static const char *
+getscope(
+ const char *str,
+ FontScope scp)
+{
+ unsigned long start = 0;
+ unsigned long end = 0;
+ unsigned long dest = 0;
+ unsigned long shift = 0;
+ unsigned long direction = 0;
+ sscanf(str,"[\\x%lx,\\x%lx]->\\x%lx", &start, &end, &dest);
+ if (dest) {
+ if (dest >= start) {
+ shift = dest - start;
+ direction = FORWARD ;
+ } else {
+ shift = start - dest;
+ direction = BACKWARD;
+ }
+ }
+ scp->start = start ;
+ scp->end = end ;
+ scp->shift = shift ;
+ scp->shift_direction
+ = direction ;
+ /* .......... */
+ while (*str) {
+ if (*str == ',' && *(str+1) == '[')
+ break;
+ str++;
+ }
+ return str+1;
+}
+
+static int
+count_scopemap(
+ const char *str)
+{
+ const char *ptr;
+ int num=0;
+ for (ptr=str; *ptr; ptr++) {
+ if (*ptr == ']') {
+ num++;
+ }
+ }
+ return num;
+}
+
+FontScope
+_XlcParse_scopemaps(
+ const char *str,
+ int *size)
+{
+ int num=0,i;
+ FontScope scope,sc_ptr;
+ const char *str_sc;
+
+ num = count_scopemap(str);
+ scope = (FontScope) Xmalloc(num * sizeof(FontScopeRec));
+ if (scope == NULL)
+ return NULL;
+
+ for (i=0, str_sc=str, sc_ptr=scope; i < num; i++, sc_ptr++) {
+ str_sc = getscope(str_sc, sc_ptr);
+ }
+ *size = num;
+ return scope;
+}
+
+void
+_XlcDbg_printValue(
+ const char *str,
+ char **value,
+ int num)
+{
+/*
+ int i;
+ for (i = 0; i < num; i++)
+ fprintf(stderr, "%s value[%d] = %s\n", str, i, value[i]);
+*/
+}
+
+static void
+dmpscope(
+ const char* name,
+ FontScope sc,
+ int num)
+{
+/*
+ int i;
+ fprintf(stderr, "dmpscope %s\n", name);
+ for (i=0; i<num; i++)
+ fprintf(stderr,"%x %x %x %x \n",
+ sc[i].start,
+ sc[i].end,
+ sc[i].shift,
+ sc[i].shift_direction);
+ fprintf(stderr, "dmpscope end\n");
+*/
+}
+
+static XlcCharSet
+srch_charset_define(
+ const char *name,
+ int *new)
+{
+ XlcCharSet charset;
+
+ *new = 0;
+ charset = _XlcGetCharSet(name);
+ if (charset == NULL &&
+ (charset = _XlcCreateDefaultCharSet(name, ""))) {
+ _XlcAddCharSet(charset);
+ *new = 1;
+ charset->source = CSsrcXLC;
+ }
+ return charset;
+}
+
+static void
+read_charset_define(
+ XLCd lcd,
+ XLCdGenericPart *gen)
+{
+ int i;
+ char csd[16], cset_name[256];
+ char name[BUFSIZ];
+ XlcCharSet charsetd;
+ char **value;
+ int num, new = 0;
+ XlcSide side = XlcUnknown;
+ char *tmp;
+
+ for (i=0; ; i++) { /* loop start */
+ charsetd = 0;
+ sprintf(csd, "csd%d", i);
+
+ /* charset_name */
+ sprintf(name, "%s.%s", csd, "charset_name");
+ _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
+ _XlcDbg_printValue(name,value,num);
+ if (num > 0) {
+ /* hackers will get truncated -- C'est la vie */
+ strncpy(cset_name,value[0], sizeof cset_name - 1);
+ cset_name[(sizeof cset_name) - 1] = '\0';
+ sprintf(name, "%s.%s", csd , "side");
+ _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+ if (!_XlcNCompareISOLatin1(value[0], "none", 4)) {
+ side = XlcGLGR;
+ } else if (!_XlcNCompareISOLatin1(value[0], "GL", 2)) {
+ side = XlcGL;
+ strcat(cset_name,":GL");
+ } else {
+ side = XlcGR;
+ strcat(cset_name,":GR");
+ }
+ if (charsetd == NULL &&
+ (charsetd = srch_charset_define(cset_name,&new)) == NULL)
+ return;
+ }
+ } else {
+ if (i == 0)
+ continue;
+ else
+ break;
+ }
+ if (new) {
+ tmp = strdup(cset_name);
+ if (tmp == NULL)
+ return;
+ charsetd->name = tmp;
+ }
+ /* side */
+ charsetd->side = side ;
+ /* length */
+ sprintf(name, "%s.%s", csd, "length");
+ _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+ charsetd->char_size = atoi(value[0]);
+ }
+ /* gc_number */
+ sprintf(name, "%s.%s", csd, "gc_number");
+ _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+ charsetd->set_size = atoi(value[0]);
+ }
+ /* string_encoding */
+ sprintf(name, "%s.%s", csd, "string_encoding");
+ _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+ if (!strcmp("False",value[0])) {
+ charsetd->string_encoding = False;
+ } else {
+ charsetd->string_encoding = True;
+ }
+ }
+ /* sequence */
+ sprintf(name, "%s.%s", csd, "sequence");
+ _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+/*
+ if (charsetd->ct_sequence) {
+ Xfree(charsetd->ct_sequence);
+ }
+*/
+ tmp = (char *)Xmalloc(strlen(value[0])+1);
+ if (tmp == NULL)
+ return;
+ charsetd->ct_sequence = tmp;
+ string_to_encoding(value[0],tmp);
+ }
+ /* encoding_name */
+ sprintf(name, "%s.%s", csd, "encoding_name");
+ _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+/*
+ if (charsetd->encoding_name) {
+ Xfree(charsetd->encoding_name);
+ }
+*/
+ tmp = strdup(value[0]);
+ charsetd->encoding_name = tmp;
+ charsetd->xrm_encoding_name = XrmStringToQuark(tmp);
+ }
+ _XlcAddCT(charsetd->name, charsetd->ct_sequence);
+ }
+}
+
+static SegConv
+add_conversion(
+ XLCdGenericPart *gen)
+{
+ SegConv new_list;
+ int num;
+
+ if ((num = gen->segment_conv_num) > 0) {
+ new_list = (SegConv) Xrealloc(gen->segment_conv,
+ (num + 1) * sizeof(SegConvRec));
+ } else {
+ new_list = (SegConv) Xmalloc(sizeof(SegConvRec));
+ }
+
+ if (new_list == NULL)
+ return NULL;
+
+ gen->segment_conv = new_list;
+ gen->segment_conv_num = num + 1;
+
+ return &new_list[num];
+
+}
+
+static void
+read_segmentconversion(
+ XLCd lcd,
+ XLCdGenericPart *gen)
+{
+ int i;
+ char conv[16];
+ char name[BUFSIZ];
+ char **value;
+ int num,new;
+ SegConv conversion;
+ for (i=0 ; ; i++) { /* loop start */
+ conversion = 0;
+ sprintf(conv, "conv%d", i);
+
+ /* length */
+ sprintf(name, "%s.%s", conv, "length");
+ _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
+ if (num > 0) {
+ if (conversion == NULL &&
+ (conversion = add_conversion(gen)) == NULL) {
+ return;
+ }
+ _XlcDbg_printValue(name,value,num);
+ } else {
+ if (i == 0)
+ continue;
+ else
+ break;
+ }
+ conversion->length = atoi(value[0]);
+
+ /* source_encoding */
+ sprintf(name, "%s.%s", conv, "source_encoding");
+ _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
+ if (num > 0) {
+ char *tmp;
+ _XlcDbg_printValue(name,value,num);
+ tmp = strdup(value[0]);
+ if (tmp == NULL)
+ return;
+ conversion->source_encoding = tmp;
+ conversion->source = srch_charset_define(tmp,&new);
+ }
+ /* destination_encoding */
+ sprintf(name, "%s.%s", conv, "destination_encoding");
+ _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
+ if (num > 0) {
+ char *tmp;
+ _XlcDbg_printValue(name,value,num);
+ tmp = strdup(value[0]);
+ if (tmp == NULL)
+ return;
+ conversion->destination_encoding = tmp;
+ conversion->dest = srch_charset_define(tmp,&new);
+ }
+ /* range */
+ sprintf(name, "%s.%s", conv, "range");
+ _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+ sscanf(value[0],"\\x%lx,\\x%lx",
+ &(conversion->range.start), &(conversion->range.end));
+ }
+ /* conversion */
+ sprintf(name, "%s.%s", conv, "conversion");
+ _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+ conversion->conv =
+ _XlcParse_scopemaps(value[0],&conversion->conv_num);
+ }
+ } /* loop end */
+}
+
+static ExtdSegment
+create_ctextseg(
+ char **value,
+ int num)
+{
+ ExtdSegment ret;
+ char* ptr;
+ char* cset_name = NULL;
+ int i,new;
+ FontScope scope;
+ ret = (ExtdSegment)Xmalloc(sizeof(ExtdSegmentRec));
+ if (ret == NULL)
+ return NULL;
+ ret->name = strdup(value[0]);
+ if (ret->name == NULL) {
+ Xfree (ret);
+ return NULL;
+ }
+ cset_name = (char*) Xmalloc (strlen(ret->name) + 1);
+ if (cset_name == NULL) {
+ Xfree (ret->name);
+ Xfree (ret);
+ return NULL;
+ }
+ if (strchr(value[0],':')) {
+ ptr = strchr(ret->name,':');
+ *ptr = '\0';
+ ptr++;
+ if (!_XlcNCompareISOLatin1(ptr, "GL", 2)) {
+ ret->side = XlcGL;
+ sprintf(cset_name,"%s:%s",ret->name,"GL");
+ } else {
+ ret->side = XlcGR;
+ sprintf(cset_name,"%s:%s",ret->name,"GR");
+ }
+ } else {
+ ret->side = XlcGLGR;
+ strcpy(cset_name,ret->name);
+ }
+ ret->area = (FontScope)Xmalloc((num - 1)*sizeof(FontScopeRec));
+ if (ret->area == NULL) {
+ Xfree (cset_name);
+ Xfree (ret->name);
+ Xfree (ret);
+ return NULL;
+ }
+ ret->area_num = num - 1;
+ scope = ret->area ;
+ for (i = 1; i < num; i++) {
+ sscanf(value[i],"\\x%lx,\\x%lx",
+ &scope[i-1].start, &scope[i-1].end);
+ }
+ ret->charset = srch_charset_define(cset_name,&new);
+ Xfree (cset_name);
+
+ return ret;
+}
+/* For VW/UDC end */
+
+static Bool
+load_generic(
+ XLCd lcd)
+{
+ XLCdGenericPart *gen = XLC_GENERIC_PART(lcd);
+ char **value;
+ int num;
+ unsigned long l;
+ int i;
+ int M,ii;
+ XlcCharSet charset;
+
+ gen->codeset_num = 0;
+
+ /***** wc_encoding_mask *****/
+ _XlcGetResource(lcd, "XLC_XLOCALE", "wc_encoding_mask", &value, &num);
+ if (num > 0) {
+ if (string_to_ulong(value[0], &l) == False)
+ goto err;
+ gen->wc_encode_mask = l;
+ }
+ /***** wc_shift_bits *****/
+ _XlcGetResource(lcd, "XLC_XLOCALE", "wc_shift_bits", &value, &num);
+ if (num > 0)
+ gen->wc_shift_bits = atoi(value[0]);
+ if (gen->wc_shift_bits < 1)
+ gen->wc_shift_bits = 8;
+ /***** use_stdc_env *****/
+ _XlcGetResource(lcd, "XLC_XLOCALE", "use_stdc_env", &value, &num);
+ if (num > 0 && !_XlcCompareISOLatin1(value[0], "True"))
+ gen->use_stdc_env = True;
+ else
+ gen->use_stdc_env = False;
+ /***** force_convert_to_mb *****/
+ _XlcGetResource(lcd, "XLC_XLOCALE", "force_convert_to_mb", &value, &num);
+ if (num > 0 && !_XlcCompareISOLatin1(value[0], "True"))
+ gen->force_convert_to_mb = True;
+ else
+ gen->force_convert_to_mb = False;
+
+ for (i = 0; ; i++) {
+ CodeSetRec *codeset = NULL;
+ char cs[16];
+ char name[BUFSIZ];
+
+ sprintf(cs, "cs%d", i);
+
+ /***** codeset.side *****/
+ sprintf(name, "%s.%s", cs , "side");
+ _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
+ if (num > 0) {
+ char *tmp;
+
+ if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
+ goto err;
+
+ /* 3.4.1 side */
+ if (!_XlcNCompareISOLatin1(value[0], "none", 4)) {
+ codeset->side = XlcNONE;
+ } else if (!_XlcNCompareISOLatin1(value[0], "GL", 2)) {
+ codeset->side = XlcGL;
+ } else {
+ codeset->side = XlcGR;
+ }
+
+ tmp = strrchr(value[0], ':');
+ if (tmp != NULL && !_XlcCompareISOLatin1(tmp + 1, "Default")) {
+ if (codeset->side == XlcGR)
+ gen->initial_state_GR = codeset;
+ else
+ gen->initial_state_GL = codeset;
+ }
+ }
+
+ /***** codeset.length *****/
+ sprintf(name, "%s.%s", cs , "length");
+ _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
+ if (num > 0) {
+ if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
+ goto err;
+ codeset->length = atoi(value[0]);
+ if (codeset->length < 1)
+ codeset->length = 1;
+ }
+
+ /***** codeset.mb_encoding *****/
+ sprintf(name, "%s.%s", cs, "mb_encoding");
+ _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
+ if (num > 0) {
+ static struct {
+ const char *str;
+ EncodingType type;
+ } shifts[] = {
+ {"<SS>", E_SS},
+ {"<LSL>", E_LSL},
+ {"<LSR>", E_LSR},
+ {0}
+ };
+ int j;
+
+ if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
+ goto err;
+ for ( ; num-- > 0; value++) {
+ char encoding[256];
+ char *tmp = *value;
+ EncodingType type = E_SS; /* for BC */
+ for (j = 0; shifts[j].str; j++) {
+ if (!_XlcNCompareISOLatin1(tmp, shifts[j].str,
+ strlen(shifts[j].str))) {
+ type = shifts[j].type;
+ tmp += strlen(shifts[j].str);
+ break;
+ }
+ }
+ if (strlen (tmp) > sizeof encoding ||
+ string_to_encoding(tmp, encoding) == False)
+ goto err;
+ add_parse_list(gen, type, encoding, codeset);
+ }
+ }
+
+ /***** codeset.wc_encoding *****/
+ sprintf(name, "%s.%s", cs, "wc_encoding");
+ _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
+ if (num > 0) {
+ if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
+ goto err;
+ if (string_to_ulong(value[0], &l) == False)
+ goto err;
+ codeset->wc_encoding = l;
+ }
+
+ /***** codeset.ct_encoding *****/
+ sprintf(name, "%s.%s", cs, "ct_encoding");
+ _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
+ if (num > 0) {
+ char *encoding;
+
+ if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
+ goto err;
+ for ( ; num-- > 0; value++) {
+ if (strlen (*value) > sizeof name)
+ goto err;
+ string_to_encoding(*value, name);
+ charset = NULL;
+ if ((encoding = strchr(name, ':')) &&
+ (encoding = strchr(encoding + 1, ':'))) {
+ *encoding++ = '\0';
+ charset = _XlcAddCT(name, encoding);
+ }
+ if (charset == NULL) {
+ charset = _XlcGetCharSet(name);
+ if (charset == NULL &&
+ (charset = _XlcCreateDefaultCharSet(name, ""))) {
+ charset->side = codeset->side;
+ charset->char_size = codeset->length;
+ _XlcAddCharSet(charset);
+ }
+ }
+ if (charset) {
+ if (add_charset(codeset, charset) == False)
+ goto err;
+ }
+ }
+ }
+
+ if (codeset == NULL)
+ break;
+ codeset->cs_num = i;
+ /* For VW/UDC */
+ /***** 3.4.2 byteM (1 <= M <= length)*****/
+ for (M=1; M-1 < codeset->length; M++) {
+ unsigned long start,end;
+ ByteInfo tmpb;
+
+ sprintf(name,"%s.%s%d",cs,"byte",M);
+ _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
+
+ if (M == 1) {
+ if (num < 1) {
+ codeset->byteM = NULL;
+ break ;
+ }
+ codeset->byteM =
+ (ByteInfoListRec *)Xmalloc(
+ (codeset->length)*sizeof(ByteInfoListRec));
+ if (codeset->byteM == NULL) {
+ goto err;
+ }
+ }
+
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+ (codeset->byteM)[M-1].M = M;
+ (codeset->byteM)[M-1].byteinfo_num = num;
+ (codeset->byteM)[M-1].byteinfo =
+ (ByteInfo)Xmalloc( num * sizeof(ByteInfoRec));
+ for (ii = 0 ; ii < num ; ii++) {
+ tmpb = (codeset->byteM)[M-1].byteinfo ;
+ /* default 0x00 - 0xff */
+ sscanf(value[ii],"\\x%lx,\\x%lx",&start,&end);
+ tmpb[ii].start = (unsigned char)start;
+ tmpb[ii].end = (unsigned char)end;
+ }
+ }
+ /* .... */
+ }
+
+
+ /***** codeset.mb_conversion *****/
+ sprintf(name, "%s.%s", cs, "mb_conversion");
+ _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+ codeset->mbconv = Xmalloc(sizeof(ConversionRec));
+ codeset->mbconv->convlist =
+ _XlcParse_scopemaps(value[0],&(codeset->mbconv->conv_num));
+ dmpscope("mb_conv",codeset->mbconv->convlist,
+ codeset->mbconv->conv_num);
+ /* [\x%x,\x%x]->\x%x,... */
+ }
+ /***** codeset.ct_conversion *****/
+ sprintf(name, "%s.%s", cs, "ct_conversion");
+ _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+ codeset->ctconv = Xmalloc(sizeof(ConversionRec));
+ codeset->ctconv->convlist =
+ _XlcParse_scopemaps(value[0],&(codeset->ctconv->conv_num));
+ dmpscope("ctconv",codeset->ctconv->convlist,
+ codeset->ctconv->conv_num);
+ /* [\x%x,\x%x]->\x%x,... */
+ }
+ /***** codeset.ct_conversion_file *****/
+ sprintf(name, "%s.%s", cs, "ct_conversion_file");
+ _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+ /* [\x%x,\x%x]->\x%x,... */
+ }
+ /***** codeset.ct_extended_segment *****/
+ sprintf(name, "%s.%s", cs, "ct_extended_segment");
+ _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+ codeset->ctextseg = create_ctextseg(value,num);
+ /* [\x%x,\x%x]->\x%x,... */
+ }
+ /* For VW/UDC end */
+
+ }
+
+ read_charset_define(lcd,gen); /* For VW/UDC */
+ read_segmentconversion(lcd,gen); /* For VW/UDC */
+
+ if (gen->initial_state_GL == NULL) {
+ CodeSetRec *codeset;
+ for (i = 0; i < gen->codeset_num; i++) {
+ codeset = gen->codeset_list[i];
+ if (codeset->side == XlcGL)
+ gen->initial_state_GL = codeset;
+ }
+ }
+
+ if (gen->initial_state_GR == NULL) {
+ CodeSetRec *codeset;
+ for (i = 0; i < gen->codeset_num; i++) {
+ codeset = gen->codeset_list[i];
+ if (codeset->side == XlcGR)
+ gen->initial_state_GR = codeset;
+ }
+ }
+
+ for (i = 0; i < gen->codeset_num; i++) {
+ CodeSetRec *codeset = gen->codeset_list[i];
+ for (ii = 0; ii < codeset->num_charsets; ii++) {
+ charset = codeset->charset_list[ii];
+ if (! strcmp(charset->encoding_name, "ISO8859-1"))
+ charset->string_encoding = True;
+ if ( charset->string_encoding )
+ codeset->string_encoding = True;
+ }
+ }
+ return True;
+
+err:
+ free_charset(lcd);
+
+ return False;
+}
+
+#ifdef USE_DYNAMIC_LC
+/* override the open_om and open_im methods which were set by
+ super_class's initialize method() */
+
+static Bool
+initialize_core(
+ XLCd lcd)
+{
+ _XInitDynamicOM(lcd);
+
+ _XInitDynamicIM(lcd);
+
+ return True;
+}
+#endif
+
+static Bool
+initialize(XLCd lcd)
+{
+ XLCdPublicMethods superclass = (XLCdPublicMethods) _XlcPublicMethods;
+
+ XLC_PUBLIC_METHODS(lcd)->superclass = superclass;
+
+ if (superclass->pub.initialize) {
+ if ((*superclass->pub.initialize)(lcd) == False)
+ return False;
+ }
+
+#ifdef USE_DYNAMIC_LC
+ if (initialize_core(lcd) == False)
+ return False;
+#endif
+
+ if (load_generic(lcd) == False)
+ return False;
+
+ return True;
+}
+
+/* VW/UDC start 95.01.08 */
+static void
+freeByteM(
+ CodeSet codeset)
+{
+ int i;
+ ByteInfoList blst;
+ if (codeset->byteM == NULL) {
+ return ;
+ }
+ blst = codeset->byteM;
+ for (i = 0; i < codeset->length; i++) {
+ if (blst[i].byteinfo) {
+ Xfree(blst[i].byteinfo);
+ blst[i].byteinfo = NULL;
+ }
+ }
+ Xfree(codeset->byteM);
+ codeset->byteM = NULL;
+}
+
+static void
+freeConversion(
+ CodeSet codeset)
+{
+ Conversion mbconv,ctconv;
+ if (codeset->mbconv) {
+ mbconv = codeset->mbconv;
+ /* ... */
+ if (mbconv->convlist) {
+ Xfree(mbconv->convlist);
+ mbconv->convlist = NULL;
+ }
+ Xfree(mbconv);
+ codeset->mbconv = NULL;
+ }
+ if (codeset->ctconv) {
+ ctconv = codeset->ctconv;
+ /* ... */
+ if (ctconv->convlist) {
+ Xfree(ctconv->convlist);
+ ctconv->convlist = NULL;
+ }
+ Xfree(ctconv);
+ codeset->ctconv = NULL;
+ }
+}
+
+static void
+freeExtdSegment(
+ CodeSet codeset)
+{
+ ExtdSegment ctextseg;
+ if (codeset->ctextseg == NULL) {
+ return;
+ }
+ ctextseg = codeset->ctextseg;
+ if (ctextseg->name) {
+ Xfree(ctextseg->name);
+ ctextseg->name = NULL;
+ }
+ if (ctextseg->area) {
+ Xfree(ctextseg->area);
+ ctextseg->area = NULL;
+ }
+ Xfree(codeset->ctextseg);
+ codeset->ctextseg = NULL;
+}
+
+static void
+freeParseInfo(
+ CodeSet codeset)
+{
+ ParseInfo parse_info;
+ if (codeset->parse_info == NULL) {
+ return;
+ }
+ parse_info = codeset->parse_info;
+ if (parse_info->encoding) {
+ Xfree(parse_info->encoding);
+ parse_info->encoding = NULL;
+ }
+ Xfree(codeset->parse_info);
+ codeset->parse_info = NULL;
+}
+
+static void
+destroy_CodeSetList(
+ XLCdGenericPart *gen)
+{
+ CodeSet *codeset = gen->codeset_list;
+ int i;
+ if (gen->codeset_num == 0) {
+ return;
+ }
+ for (i=0;i<gen->codeset_num;i++) {
+ freeByteM(codeset[i]);
+ freeConversion(codeset[i]);
+ freeExtdSegment(codeset[i]);
+ freeParseInfo(codeset[i]);
+ if (codeset[i]->charset_list) {
+ Xfree(codeset[i]->charset_list);
+ codeset[i]->charset_list = NULL;
+ }
+ Xfree(codeset[i]); codeset[i]=NULL;
+ }
+ Xfree(codeset); gen->codeset_list = NULL;
+}
+
+static void
+destroy_SegConv(
+ XLCdGenericPart *gen)
+{
+ SegConv seg = gen->segment_conv;
+ int i;
+ if (gen->segment_conv_num == 0) {
+ return;
+ }
+ for (i=0;i<gen->segment_conv_num;i++) {
+ if (seg[i].source_encoding) {
+ Xfree(seg[i].source_encoding);
+ seg[i].source_encoding = NULL;
+ }
+ if (seg[i].destination_encoding) {
+ Xfree(seg[i].destination_encoding);
+ seg[i].destination_encoding = NULL;
+ }
+ if (seg[i].conv) {
+ Xfree(seg[i].conv); seg[i].conv = NULL;
+ }
+ }
+ Xfree(seg); gen->segment_conv = NULL;
+}
+
+static void
+destroy_gen(
+ XLCd lcd)
+{
+ XLCdGenericPart *gen = XLC_GENERIC_PART(lcd);
+ destroy_SegConv(gen);
+ destroy_CodeSetList(gen);
+ if (gen->mb_parse_table) {
+ Xfree(gen->mb_parse_table);
+ gen->mb_parse_table = NULL;
+ }
+ if (gen->mb_parse_list) {
+ Xfree(gen->mb_parse_list);
+ gen->mb_parse_list = NULL;
+ }
+}
+/* VW/UDC end 95.01.08 */
+
+static void
+destroy(
+ XLCd lcd)
+{
+ XLCdPublicMethods superclass = XLC_PUBLIC_METHODS(lcd)->superclass;
+
+ destroy_gen(lcd); /* ADD 1996.01.08 */
+ if (superclass && superclass->pub.destroy)
+ (*superclass->pub.destroy)(lcd);
+}
diff --git a/libX11/src/xlibi18n/lcPublic.c b/libX11/src/xlibi18n/lcPublic.c
index 2c02f5fba..d0db410fc 100644
--- a/libX11/src/xlibi18n/lcPublic.c
+++ b/libX11/src/xlibi18n/lcPublic.c
@@ -1,317 +1,314 @@
-/*
- * Copyright 1992, 1993 by TOSHIBA Corp.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of TOSHIBA not be used in advertising
- * or publicity pertaining to distribution of the software without specific,
- * written prior permission. TOSHIBA make no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
- * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- *
- * Author: Katsuhisa Yano TOSHIBA Corp.
- * mopi@osa.ilab.toshiba.co.jp
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include "Xlibint.h"
-#include "XlcPubI.h"
-
-static const char *
-default_string(
- XLCd lcd)
-{
- return XLC_PUBLIC(lcd, default_string);
-}
-
-static XLCd create (const char *name, XLCdMethods methods);
-static Bool initialize (XLCd lcd);
-static void destroy (XLCd lcd);
-static char *get_values (XLCd lcd, XlcArgList args, int num_args);
-
-static XLCdPublicMethodsRec publicMethods = {
- {
- destroy,
- _XlcDefaultMapModifiers,
- NULL,
- NULL,
- _XrmDefaultInitParseInfo,
- _XmbTextPropertyToTextList,
- _XwcTextPropertyToTextList,
- _Xutf8TextPropertyToTextList,
- _XmbTextListToTextProperty,
- _XwcTextListToTextProperty,
- _Xutf8TextListToTextProperty,
- _XwcFreeStringList,
- default_string,
- NULL,
- NULL
- },
- {
- NULL,
- create,
- initialize,
- destroy,
- get_values,
- _XlcGetLocaleDataBase
- }
-};
-
-XLCdMethods _XlcPublicMethods = (XLCdMethods) &publicMethods;
-
-static XLCd
-create(
- const char *name,
- XLCdMethods methods)
-{
- XLCd lcd;
- XLCdPublicMethods new;
-
- lcd = (XLCd) Xmalloc(sizeof(XLCdRec));
- if (lcd == NULL)
- return (XLCd) NULL;
- bzero((char *) lcd, sizeof(XLCdRec));
-
- lcd->core = (XLCdCore) Xmalloc(sizeof(XLCdPublicRec));
- if (lcd->core == NULL)
- goto err;
- bzero((char *) lcd->core, sizeof(XLCdPublicRec));
-
- new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec));
- if (new == NULL)
- goto err;
- memcpy(new,methods,sizeof(XLCdPublicMethodsRec));
- lcd->methods = (XLCdMethods) new;
-
- return lcd;
-
-err:
- Xfree(lcd);
- return (XLCd) NULL;
-}
-
-static Bool
-load_public(
- XLCd lcd)
-{
- XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd);
- char **values, *str;
- int num;
-
- if(_XlcCreateLocaleDataBase(lcd) == NULL)
- return False;
-
- _XlcGetResource(lcd, "XLC_XLOCALE", "mb_cur_max", &values, &num);
- if (num > 0) {
- pub->mb_cur_max = atoi(values[0]);
- if (pub->mb_cur_max < 1)
- pub->mb_cur_max = 1;
- } else
- pub->mb_cur_max = 1;
-
- _XlcGetResource(lcd, "XLC_XLOCALE", "state_depend_encoding", &values, &num);
- if (num > 0 && !_XlcCompareISOLatin1(values[0], "True"))
- pub->is_state_depend = True;
- else
- pub->is_state_depend = False;
-
- _XlcGetResource(lcd, "XLC_XLOCALE", "encoding_name", &values, &num);
- str = (num > 0) ? values[0] : "STRING";
- pub->encoding_name = (char*) Xmalloc(strlen(str) + 1);
- if (pub->encoding_name == NULL)
- return False;
- strcpy(pub->encoding_name, str);
-
- return True;
-}
-
-static Bool
-initialize_core(
- XLCd lcd)
-{
- XLCdMethods methods = lcd->methods;
- XLCdMethods core = &publicMethods.core;
-
- if (methods->close == NULL)
- methods->close = core->close;
-
- if (methods->map_modifiers == NULL)
- methods->map_modifiers = core->map_modifiers;
-
- if (methods->open_om == NULL)
-#ifdef USE_DYNAMIC_LC
- _XInitDefaultOM(lcd);
-#else
- _XInitOM(lcd);
-#endif
-
- if (methods->open_im == NULL)
-#ifdef USE_DYNAMIC_LC
- _XInitDefaultIM(lcd);
-#else
- _XInitIM(lcd);
-#endif
-
- if (methods->init_parse_info == NULL)
- methods->init_parse_info = core->init_parse_info;
-
- if (methods->mb_text_prop_to_list == NULL)
- methods->mb_text_prop_to_list = core->mb_text_prop_to_list;
-
- if (methods->wc_text_prop_to_list == NULL)
- methods->wc_text_prop_to_list = core->wc_text_prop_to_list;
-
- if (methods->utf8_text_prop_to_list == NULL)
- methods->utf8_text_prop_to_list = core->utf8_text_prop_to_list;
-
- if (methods->mb_text_list_to_prop == NULL)
- methods->mb_text_list_to_prop = core->mb_text_list_to_prop;
-
- if (methods->wc_text_list_to_prop == NULL)
- methods->wc_text_list_to_prop = core->wc_text_list_to_prop;
-
- if (methods->utf8_text_list_to_prop == NULL)
- methods->utf8_text_list_to_prop = core->utf8_text_list_to_prop;
-
- if (methods->wc_free_string_list == NULL)
- methods->wc_free_string_list = core->wc_free_string_list;
-
- if (methods->default_string == NULL)
- methods->default_string = core->default_string;
-
- return True;
-}
-
-static Bool
-initialize(
- XLCd lcd)
-{
- XLCdPublicMethodsPart *methods = XLC_PUBLIC_METHODS(lcd);
- XLCdPublicMethodsPart *pub_methods = &publicMethods.pub;
- XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd);
- char *name;
-#if !defined(X_LOCALE)
- int len;
- char sinamebuf[256];
- char* siname;
-#endif
-
- _XlcInitCTInfo();
-
- if (initialize_core(lcd) == False)
- return False;
-
- name = lcd->core->name;
-#if !defined(X_LOCALE)
- /*
- * _XlMapOSLocaleName will return the same string or a substring
- * of name, so strlen(name) is okay
- */
- if ((len = strlen(name)) < sizeof sinamebuf)
- siname = sinamebuf;
- else
- siname = Xmalloc (len + 1);
- if (siname == NULL)
- return False;
- name = _XlcMapOSLocaleName(name, siname);
-#endif
- /* _XlcResolveLocaleName will lookup the SI's name for the locale */
- if (_XlcResolveLocaleName(name, pub) == 0) {
-#if !defined(X_LOCALE)
- if (siname != sinamebuf) Xfree (siname);
-#endif
- return False;
- }
-#if !defined(X_LOCALE)
- if (siname != sinamebuf)
- Xfree (siname);
-#endif
-
- if (pub->default_string == NULL)
- pub->default_string = "";
-
- if (methods->get_values == NULL)
- methods->get_values = pub_methods->get_values;
-
- if (methods->get_resource == NULL)
- methods->get_resource = pub_methods->get_resource;
-
- return load_public(lcd);
-}
-
-static void
-destroy_core(
- XLCd lcd)
-{
- if (lcd->core) {
- if (lcd->core->name)
- Xfree(lcd->core->name);
- Xfree(lcd->core);
- }
-
- if (lcd->methods)
- Xfree(lcd->methods);
-
- Xfree(lcd);
-}
-
-static void
-destroy(
- XLCd lcd)
-{
- XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd);
-
- _XlcDestroyLocaleDataBase(lcd);
-
- if (pub->siname)
- Xfree(pub->siname);
- if (pub->encoding_name)
- Xfree(pub->encoding_name);
-
- destroy_core(lcd);
-}
-
-static XlcResource resources[] = {
- { XlcNCodeset, NULLQUARK, sizeof(char *),
- XOffsetOf(XLCdPublicRec, pub.codeset), XlcGetMask },
- { XlcNDefaultString, NULLQUARK, sizeof(char *),
- XOffsetOf(XLCdPublicRec, pub.default_string), XlcGetMask },
- { XlcNEncodingName, NULLQUARK, sizeof(char *),
- XOffsetOf(XLCdPublicRec, pub.encoding_name), XlcGetMask },
- { XlcNLanguage, NULLQUARK, sizeof(char *),
- XOffsetOf(XLCdPublicRec, pub.language), XlcGetMask },
- { XlcNMbCurMax, NULLQUARK, sizeof(int),
- XOffsetOf(XLCdPublicRec, pub.mb_cur_max), XlcGetMask },
- { XlcNStateDependentEncoding, NULLQUARK, sizeof(Bool),
- XOffsetOf(XLCdPublicRec, pub.is_state_depend), XlcGetMask },
- { XlcNTerritory, NULLQUARK, sizeof(char *),
- XOffsetOf(XLCdPublicRec, pub.territory), XlcGetMask }
-};
-
-static char *
-get_values(
- XLCd lcd,
- XlcArgList args,
- int num_args)
-{
- XLCdPublic pub = (XLCdPublic) lcd->core;
-
- if (resources[0].xrm_name == NULLQUARK)
- _XlcCompileResourceList(resources, XlcNumber(resources));
-
- return _XlcGetValues((XPointer) pub, resources, XlcNumber(resources), args,
- num_args, XlcGetMask);
-}
+/*
+ * Copyright 1992, 1993 by TOSHIBA Corp.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of TOSHIBA not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission. TOSHIBA make no representations about the
+ * suitability of this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+ * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Author: Katsuhisa Yano TOSHIBA Corp.
+ * mopi@osa.ilab.toshiba.co.jp
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include "Xlibint.h"
+#include "XlcPubI.h"
+
+static const char *
+default_string(
+ XLCd lcd)
+{
+ return XLC_PUBLIC(lcd, default_string);
+}
+
+static XLCd create (const char *name, XLCdMethods methods);
+static Bool initialize (XLCd lcd);
+static void destroy (XLCd lcd);
+static char *get_values (XLCd lcd, XlcArgList args, int num_args);
+
+static XLCdPublicMethodsRec publicMethods = {
+ {
+ destroy,
+ _XlcDefaultMapModifiers,
+ NULL,
+ NULL,
+ _XrmDefaultInitParseInfo,
+ _XmbTextPropertyToTextList,
+ _XwcTextPropertyToTextList,
+ _Xutf8TextPropertyToTextList,
+ _XmbTextListToTextProperty,
+ _XwcTextListToTextProperty,
+ _Xutf8TextListToTextProperty,
+ _XwcFreeStringList,
+ default_string,
+ NULL,
+ NULL
+ },
+ {
+ NULL,
+ create,
+ initialize,
+ destroy,
+ get_values,
+ _XlcGetLocaleDataBase
+ }
+};
+
+XLCdMethods _XlcPublicMethods = (XLCdMethods) &publicMethods;
+
+static XLCd
+create(
+ const char *name,
+ XLCdMethods methods)
+{
+ XLCd lcd;
+ XLCdPublicMethods new;
+
+ lcd = Xcalloc(1, sizeof(XLCdRec));
+ if (lcd == NULL)
+ return (XLCd) NULL;
+
+ lcd->core = Xcalloc(1, sizeof(XLCdPublicRec));
+ if (lcd->core == NULL)
+ goto err;
+
+ new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec));
+ if (new == NULL)
+ goto err;
+ memcpy(new,methods,sizeof(XLCdPublicMethodsRec));
+ lcd->methods = (XLCdMethods) new;
+
+ return lcd;
+
+err:
+ Xfree(lcd);
+ return (XLCd) NULL;
+}
+
+static Bool
+load_public(
+ XLCd lcd)
+{
+ XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd);
+ char **values, *str;
+ int num;
+
+ if(_XlcCreateLocaleDataBase(lcd) == NULL)
+ return False;
+
+ _XlcGetResource(lcd, "XLC_XLOCALE", "mb_cur_max", &values, &num);
+ if (num > 0) {
+ pub->mb_cur_max = atoi(values[0]);
+ if (pub->mb_cur_max < 1)
+ pub->mb_cur_max = 1;
+ } else
+ pub->mb_cur_max = 1;
+
+ _XlcGetResource(lcd, "XLC_XLOCALE", "state_depend_encoding", &values, &num);
+ if (num > 0 && !_XlcCompareISOLatin1(values[0], "True"))
+ pub->is_state_depend = True;
+ else
+ pub->is_state_depend = False;
+
+ _XlcGetResource(lcd, "XLC_XLOCALE", "encoding_name", &values, &num);
+ str = (num > 0) ? values[0] : "STRING";
+ pub->encoding_name = strdup(str);
+ if (pub->encoding_name == NULL)
+ return False;
+
+ return True;
+}
+
+static Bool
+initialize_core(
+ XLCd lcd)
+{
+ XLCdMethods methods = lcd->methods;
+ XLCdMethods core = &publicMethods.core;
+
+ if (methods->close == NULL)
+ methods->close = core->close;
+
+ if (methods->map_modifiers == NULL)
+ methods->map_modifiers = core->map_modifiers;
+
+ if (methods->open_om == NULL)
+#ifdef USE_DYNAMIC_LC
+ _XInitDefaultOM(lcd);
+#else
+ _XInitOM(lcd);
+#endif
+
+ if (methods->open_im == NULL)
+#ifdef USE_DYNAMIC_LC
+ _XInitDefaultIM(lcd);
+#else
+ _XInitIM(lcd);
+#endif
+
+ if (methods->init_parse_info == NULL)
+ methods->init_parse_info = core->init_parse_info;
+
+ if (methods->mb_text_prop_to_list == NULL)
+ methods->mb_text_prop_to_list = core->mb_text_prop_to_list;
+
+ if (methods->wc_text_prop_to_list == NULL)
+ methods->wc_text_prop_to_list = core->wc_text_prop_to_list;
+
+ if (methods->utf8_text_prop_to_list == NULL)
+ methods->utf8_text_prop_to_list = core->utf8_text_prop_to_list;
+
+ if (methods->mb_text_list_to_prop == NULL)
+ methods->mb_text_list_to_prop = core->mb_text_list_to_prop;
+
+ if (methods->wc_text_list_to_prop == NULL)
+ methods->wc_text_list_to_prop = core->wc_text_list_to_prop;
+
+ if (methods->utf8_text_list_to_prop == NULL)
+ methods->utf8_text_list_to_prop = core->utf8_text_list_to_prop;
+
+ if (methods->wc_free_string_list == NULL)
+ methods->wc_free_string_list = core->wc_free_string_list;
+
+ if (methods->default_string == NULL)
+ methods->default_string = core->default_string;
+
+ return True;
+}
+
+static Bool
+initialize(
+ XLCd lcd)
+{
+ XLCdPublicMethodsPart *methods = XLC_PUBLIC_METHODS(lcd);
+ XLCdPublicMethodsPart *pub_methods = &publicMethods.pub;
+ XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd);
+ char *name;
+#if !defined(X_LOCALE)
+ int len;
+ char sinamebuf[256];
+ char* siname;
+#endif
+
+ _XlcInitCTInfo();
+
+ if (initialize_core(lcd) == False)
+ return False;
+
+ name = lcd->core->name;
+#if !defined(X_LOCALE)
+ /*
+ * _XlMapOSLocaleName will return the same string or a substring
+ * of name, so strlen(name) is okay
+ */
+ if ((len = strlen(name)) < sizeof sinamebuf)
+ siname = sinamebuf;
+ else
+ siname = Xmalloc (len + 1);
+ if (siname == NULL)
+ return False;
+ name = _XlcMapOSLocaleName(name, siname);
+#endif
+ /* _XlcResolveLocaleName will lookup the SI's name for the locale */
+ if (_XlcResolveLocaleName(name, pub) == 0) {
+#if !defined(X_LOCALE)
+ if (siname != sinamebuf) Xfree (siname);
+#endif
+ return False;
+ }
+#if !defined(X_LOCALE)
+ if (siname != sinamebuf)
+ Xfree (siname);
+#endif
+
+ if (pub->default_string == NULL)
+ pub->default_string = "";
+
+ if (methods->get_values == NULL)
+ methods->get_values = pub_methods->get_values;
+
+ if (methods->get_resource == NULL)
+ methods->get_resource = pub_methods->get_resource;
+
+ return load_public(lcd);
+}
+
+static void
+destroy_core(
+ XLCd lcd)
+{
+ if (lcd->core) {
+ if (lcd->core->name)
+ Xfree(lcd->core->name);
+ Xfree(lcd->core);
+ }
+
+ if (lcd->methods)
+ Xfree(lcd->methods);
+
+ Xfree(lcd);
+}
+
+static void
+destroy(
+ XLCd lcd)
+{
+ XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd);
+
+ _XlcDestroyLocaleDataBase(lcd);
+
+ if (pub->siname)
+ Xfree(pub->siname);
+ if (pub->encoding_name)
+ Xfree(pub->encoding_name);
+
+ destroy_core(lcd);
+}
+
+static XlcResource resources[] = {
+ { XlcNCodeset, NULLQUARK, sizeof(char *),
+ XOffsetOf(XLCdPublicRec, pub.codeset), XlcGetMask },
+ { XlcNDefaultString, NULLQUARK, sizeof(char *),
+ XOffsetOf(XLCdPublicRec, pub.default_string), XlcGetMask },
+ { XlcNEncodingName, NULLQUARK, sizeof(char *),
+ XOffsetOf(XLCdPublicRec, pub.encoding_name), XlcGetMask },
+ { XlcNLanguage, NULLQUARK, sizeof(char *),
+ XOffsetOf(XLCdPublicRec, pub.language), XlcGetMask },
+ { XlcNMbCurMax, NULLQUARK, sizeof(int),
+ XOffsetOf(XLCdPublicRec, pub.mb_cur_max), XlcGetMask },
+ { XlcNStateDependentEncoding, NULLQUARK, sizeof(Bool),
+ XOffsetOf(XLCdPublicRec, pub.is_state_depend), XlcGetMask },
+ { XlcNTerritory, NULLQUARK, sizeof(char *),
+ XOffsetOf(XLCdPublicRec, pub.territory), XlcGetMask }
+};
+
+static char *
+get_values(
+ XLCd lcd,
+ XlcArgList args,
+ int num_args)
+{
+ XLCdPublic pub = (XLCdPublic) lcd->core;
+
+ if (resources[0].xrm_name == NULLQUARK)
+ _XlcCompileResourceList(resources, XlcNumber(resources));
+
+ return _XlcGetValues((XPointer) pub, resources, XlcNumber(resources), args,
+ num_args, XlcGetMask);
+}