diff options
Diffstat (limited to 'libX11/src/xlibi18n')
-rw-r--r-- | libX11/src/xlibi18n/XDefaultIMIF.c | 938 | ||||
-rw-r--r-- | libX11/src/xlibi18n/XDefaultOMIF.c | 2523 | ||||
-rw-r--r-- | libX11/src/xlibi18n/XimProto.h | 7 | ||||
-rw-r--r-- | libX11/src/xlibi18n/XlcDL.c | 1224 | ||||
-rw-r--r-- | libX11/src/xlibi18n/lcCharSet.c | 450 | ||||
-rw-r--r-- | libX11/src/xlibi18n/lcDB.c | 2680 | ||||
-rw-r--r-- | libX11/src/xlibi18n/lcDynamic.c | 2 | ||||
-rw-r--r-- | libX11/src/xlibi18n/lcFile.c | 1658 | ||||
-rw-r--r-- | libX11/src/xlibi18n/lcGeneric.c | 2360 | ||||
-rw-r--r-- | libX11/src/xlibi18n/lcPublic.c | 628 | ||||
-rw-r--r-- | libX11/src/xlibi18n/makefile | 80 |
11 files changed, 6320 insertions, 6230 deletions
diff --git a/libX11/src/xlibi18n/XDefaultIMIF.c b/libX11/src/xlibi18n/XDefaultIMIF.c index e97d2f444..71b1af177 100644 --- a/libX11/src/xlibi18n/XDefaultIMIF.c +++ b/libX11/src/xlibi18n/XDefaultIMIF.c @@ -1,469 +1,469 @@ -/* -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 <stdio.h> -#include "Xlibint.h" -#include "Xlcint.h" -#include "XlcGeneric.h" - -#ifndef MAXINT -#define MAXINT (~((unsigned int)1 << (8 * sizeof(int)) - 1)) -#endif /* !MAXINT */ - -typedef struct _StaticXIM *StaticXIM; - -typedef struct _XIMStaticXIMRec { - /* for CT => MB,WC converter */ - XlcConv ctom_conv; - XlcConv ctow_conv; -} XIMStaticXIMRec; - -typedef enum { - CREATE_IC = 1, - SET_ICVAL = 2, - GET_ICVAL = 3 -} XICOp_t; - -typedef struct _StaticXIM { - XIMMethods methods; - XIMCoreRec core; - XIMStaticXIMRec *private; -} StaticXIMRec; - -static Status _CloseIM( - XIM -); - -static char *_SetIMValues( - XIM, XIMArg * -); - -static char *_GetIMValues( - XIM, XIMArg* -); - -static XIC _CreateIC( - XIM, XIMArg* -); - -static _Xconst XIMMethodsRec local_im_methods = { - _CloseIM, /* close */ - _SetIMValues, /* set_values */ - _GetIMValues, /* get_values */ - _CreateIC, /* create_ic */ - NULL, /* ctstombs */ - NULL /* ctstowcs */ -}; - -static void _DestroyIC( - XIC -); -static void _SetFocus( - XIC -); -static void _UnsetFocus( - XIC -); -static char* _SetICValues( - XIC, XIMArg * -); -static char* _GetICValues( - XIC, XIMArg * -); -static char *_MbReset( - XIC -); -static wchar_t *_WcReset( - XIC -); -static int _MbLookupString( - XIC, XKeyEvent *, char *, int, KeySym *, Status * -); -static int _WcLookupString( - XIC, XKeyEvent *, wchar_t *, int, KeySym *, Status * -); - -static _Xconst XICMethodsRec local_ic_methods = { - _DestroyIC, /* destroy */ - _SetFocus, /* set_focus */ - _UnsetFocus, /* unset_focus */ - _SetICValues, /* set_values */ - _GetICValues, /* get_values */ - _MbReset, /* mb_reset */ - _WcReset, /* wc_reset */ - NULL, /* utf8_reset */ /* ??? */ - _MbLookupString, /* mb_lookup_string */ - _WcLookupString, /* wc_lookup_string */ - NULL /* utf8_lookup_string */ /* ??? */ -}; - -XIM -_XDefaultOpenIM( - XLCd lcd, - Display *dpy, - XrmDatabase rdb, - char *res_name, - char *res_class) -{ - StaticXIM im; - XIMStaticXIMRec *local_impart; - XlcConv ctom_conv, ctow_conv; - int i; - char *mod; - char buf[BUFSIZ]; - - if (!(ctom_conv = _XlcOpenConverter(lcd, - XlcNCompoundText, lcd, XlcNMultiByte))) { - return((XIM)NULL); - } - - if (!(ctow_conv = _XlcOpenConverter(lcd, - XlcNCompoundText, lcd, XlcNWideChar))) { - return((XIM)NULL); - } - - if ((im = (StaticXIM)Xmalloc(sizeof(StaticXIMRec))) == (StaticXIM)NULL) { - return((XIM)NULL); - } - if ((local_impart = (XIMStaticXIMRec*)Xmalloc(sizeof(XIMStaticXIMRec))) - == (XIMStaticXIMRec *)NULL) { - Xfree(im); - return((XIM)NULL); - } - memset(im, 0, sizeof(StaticXIMRec)); - memset(local_impart, 0, sizeof(XIMStaticXIMRec)); - - buf[0] = '\0'; - i = 0; - if ((lcd->core->modifiers) && (*lcd->core->modifiers)) { -#define MODIFIER "@im=" - mod = strstr(lcd->core->modifiers, MODIFIER); - if (mod) { - mod += strlen(MODIFIER); - while (*mod && *mod != '@' && i < BUFSIZ - 1) { - buf[i++] = *mod++; - } - buf[i] = '\0'; - } - } -#undef MODIFIER - if ((im->core.im_name = Xmalloc(i+1)) == NULL) - goto Error2; - strcpy(im->core.im_name, buf); - - im->private = local_impart; - im->methods = (XIMMethods)&local_im_methods; - 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; - - local_impart->ctom_conv = ctom_conv; - local_impart->ctow_conv = ctow_conv; - - if ((res_name != NULL) && (*res_name != '\0')){ - im->core.res_name = strdup(res_name); - } - if ((res_class != NULL) && (*res_class != '\0')){ - im->core.res_class = strdup(res_class); - } - - return (XIM)im; -Error2 : - Xfree(im->private); - Xfree(im->core.im_name); - Xfree(im); - _XlcCloseConverter(ctom_conv); - _XlcCloseConverter(ctow_conv); - return(NULL); -} - -static Status -_CloseIM(XIM xim) -{ - StaticXIM im = (StaticXIM)xim; - _XlcCloseConverter(im->private->ctom_conv); - _XlcCloseConverter(im->private->ctow_conv); - XFree(im->private); - XFree(im->core.im_name); - if (im->core.res_name) XFree(im->core.res_name); - if (im->core.res_class) XFree(im->core.res_class); - return 1; /*bugID 4163122*/ -} - -static char * -_SetIMValues( - XIM xim, - XIMArg *arg) -{ - return(arg->name); /* evil */ -} - -static char * -_GetIMValues( - XIM xim, - XIMArg *values) -{ - XIMArg *p; - XIMStyles *styles; - - for (p = values; p->name != NULL; p++) { - if (strcmp(p->name, XNQueryInputStyle) == 0) { - styles = (XIMStyles *)Xmalloc(sizeof(XIMStyles)); - *(XIMStyles **)p->value = styles; - styles->count_styles = 1; - styles->supported_styles = - (XIMStyle*)Xmalloc(styles->count_styles * sizeof(XIMStyle)); - styles->supported_styles[0] = (XIMPreeditNone | XIMStatusNone); - } else { - break; - } - } - return (p->name); -} - -static char* -_SetICValueData(XIC ic, XIMArg *values, XICOp_t mode) -{ - XIMArg *p; - char *return_name = NULL; - - for (p = values; p != NULL && p->name != NULL; p++) { - if(strcmp(p->name, XNInputStyle) == 0) { - if (mode == CREATE_IC) - ic->core.input_style = (XIMStyle)p->value; - } else if (strcmp(p->name, XNClientWindow) == 0) { - ic->core.client_window = (Window)p->value ; - } else if (strcmp(p->name, XNFocusWindow) == 0) { - ic->core.focus_window = (Window)p->value ; - } else if (strcmp(p->name, XNPreeditAttributes) == 0 - || strcmp(p->name, XNStatusAttributes) == 0) { - return_name = _SetICValueData(ic, (XIMArg*)p->value, mode); - if (return_name) break; - } else { - return_name = p->name; - break; - } - } - return(return_name); -} - -static char* -_GetICValueData(XIC ic, XIMArg *values, XICOp_t mode) -{ - XIMArg *p; - char *return_name = NULL; - - for (p = values; p->name != NULL; p++) { - if(strcmp(p->name, XNInputStyle) == 0) { - *((XIMStyle *)(p->value)) = ic->core.input_style; - } else if (strcmp(p->name, XNClientWindow) == 0) { - *((Window *)(p->value)) = ic->core.client_window; - } else if (strcmp(p->name, XNFocusWindow) == 0) { - *((Window *)(p->value)) = ic->core.focus_window; - } else if (strcmp(p->name, XNFilterEvents) == 0) { - *((unsigned long *)(p->value))= ic->core.filter_events; - } else if (strcmp(p->name, XNPreeditAttributes) == 0 - || strcmp(p->name, XNStatusAttributes) == 0) { - return_name = _GetICValueData(ic, (XIMArg*)p->value, mode); - if (return_name) break; - } else { - return_name = p->name; - break; - } - } - return(return_name); -} - -static XIC -_CreateIC(XIM im, XIMArg *arg) -{ - XIC ic; - - if ((ic = (XIC)Xmalloc(sizeof(XICRec))) == (XIC)NULL) { - return ((XIC)NULL); - } - memset(ic, 0, sizeof(XICRec)); - - ic->methods = (XICMethods)&local_ic_methods; - ic->core.im = im; - ic->core.filter_events = KeyPressMask; - - if (_SetICValueData(ic, arg, CREATE_IC) != NULL) - goto err_return; - if (!(ic->core.input_style)) - goto err_return; - - return (XIC)ic; -err_return: - XFree(ic); - return ((XIC)NULL); -} - -static void -_DestroyIC(XIC ic) -{ -/*BugId4255571. This Xfree() should be removed because XDestroyIC() still need ic after invoking _DestroyIC() and there is a XFree(ic) at the end of XDestroyIC() already. - if(ic) - XFree(ic); */ -} - -static void -_SetFocus(XIC ic) -{ -} - -static void -_UnsetFocus(XIC ic) -{ -} - -static char* -_SetICValues(XIC ic, XIMArg *args) -{ - char *ret = NULL; - if (!ic) { - return (args->name); - } - ret = _SetICValueData(ic, args, SET_ICVAL); - return(ret); -} - -static char* -_GetICValues(XIC ic, XIMArg *args) -{ - char *ret = NULL; - if (!ic) { - return (args->name); - } - ret = _GetICValueData(ic, args, GET_ICVAL); - return(ret); -} - -static char * -_MbReset(XIC xic) -{ - return(NULL); -} - -static wchar_t * -_WcReset(XIC xic) -{ - return(NULL); -} - -static int -_MbLookupString( - XIC xic, - XKeyEvent *ev, - char * buffer, - int bytes, - KeySym *keysym, - Status *status) -{ - XComposeStatus NotSupportedYet ; - int length; - - length = XLookupString(ev, buffer, bytes, keysym, &NotSupportedYet); - - if (keysym && *keysym == NoSymbol){ - *status = XLookupNone; - } else if (length > 0) { - *status = XLookupBoth; - } else { - *status = XLookupKeySym; - } - return(length); -} - -static int -_WcLookupString( - XIC xic, - XKeyEvent *ev, - wchar_t * buffer, - int wlen, - KeySym *keysym, - Status *status) -{ - XComposeStatus NotSupportedYet ; - int length; - /* In single-byte, mb_len = wc_len */ - char *mb_buf = (char *)Xmalloc(wlen); - - length = XLookupString(ev, mb_buf, wlen, keysym, &NotSupportedYet); - - if (keysym && *keysym == NoSymbol){ - *status = XLookupNone; - } else if (length > 0) { - *status = XLookupBoth; - } else { - *status = XLookupKeySym; - } - mbstowcs(buffer, mb_buf, length); - XFree(mb_buf); - return(length); -} +/*
+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 <stdio.h>
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "XlcGeneric.h"
+
+#ifndef MAXINT
+#define MAXINT (~((unsigned int)1 << (8 * sizeof(int)) - 1))
+#endif /* !MAXINT */
+
+typedef struct _StaticXIM *StaticXIM;
+
+typedef struct _XIMStaticXIMRec {
+ /* for CT => MB,WC converter */
+ XlcConv ctom_conv;
+ XlcConv ctow_conv;
+} XIMStaticXIMRec;
+
+typedef enum {
+ CREATE_IC = 1,
+ SET_ICVAL = 2,
+ GET_ICVAL = 3
+} XICOp_t;
+
+typedef struct _StaticXIM {
+ XIMMethods methods;
+ XIMCoreRec core;
+ XIMStaticXIMRec *private;
+} StaticXIMRec;
+
+static Status _CloseIM(
+ XIM
+);
+
+static char *_SetIMValues(
+ XIM, XIMArg *
+);
+
+static char *_GetIMValues(
+ XIM, XIMArg*
+);
+
+static XIC _CreateIC(
+ XIM, XIMArg*
+);
+
+static _Xconst XIMMethodsRec local_im_methods = {
+ _CloseIM, /* close */
+ _SetIMValues, /* set_values */
+ _GetIMValues, /* get_values */
+ _CreateIC, /* create_ic */
+ NULL, /* ctstombs */
+ NULL /* ctstowcs */
+};
+
+static void _DestroyIC(
+ XIC
+);
+static void _SetFocus(
+ XIC
+);
+static void _UnsetFocus(
+ XIC
+);
+static char* _SetICValues(
+ XIC, XIMArg *
+);
+static char* _GetICValues(
+ XIC, XIMArg *
+);
+static char *_MbReset(
+ XIC
+);
+static wchar_t *_WcReset(
+ XIC
+);
+static int _MbLookupString(
+ XIC, XKeyEvent *, char *, int, KeySym *, Status *
+);
+static int _WcLookupString(
+ XIC, XKeyEvent *, wchar_t *, int, KeySym *, Status *
+);
+
+static _Xconst XICMethodsRec local_ic_methods = {
+ _DestroyIC, /* destroy */
+ _SetFocus, /* set_focus */
+ _UnsetFocus, /* unset_focus */
+ _SetICValues, /* set_values */
+ _GetICValues, /* get_values */
+ _MbReset, /* mb_reset */
+ _WcReset, /* wc_reset */
+ NULL, /* utf8_reset */ /* ??? */
+ _MbLookupString, /* mb_lookup_string */
+ _WcLookupString, /* wc_lookup_string */
+ NULL /* utf8_lookup_string */ /* ??? */
+};
+
+XIM
+_XDefaultOpenIM(
+ XLCd lcd,
+ Display *dpy,
+ XrmDatabase rdb,
+ char *res_name,
+ char *res_class)
+{
+ StaticXIM im;
+ XIMStaticXIMRec *local_impart;
+ XlcConv ctom_conv, ctow_conv;
+ int i;
+ char *mod;
+ char buf[BUFSIZ];
+
+ if (!(ctom_conv = _XlcOpenConverter(lcd,
+ XlcNCompoundText, lcd, XlcNMultiByte))) {
+ return((XIM)NULL);
+ }
+
+ if (!(ctow_conv = _XlcOpenConverter(lcd,
+ XlcNCompoundText, lcd, XlcNWideChar))) {
+ return((XIM)NULL);
+ }
+
+ if ((im = (StaticXIM)Xmalloc(sizeof(StaticXIMRec))) == (StaticXIM)NULL) {
+ return((XIM)NULL);
+ }
+ if ((local_impart = (XIMStaticXIMRec*)Xmalloc(sizeof(XIMStaticXIMRec)))
+ == (XIMStaticXIMRec *)NULL) {
+ Xfree(im);
+ return((XIM)NULL);
+ }
+ memset(im, 0, sizeof(StaticXIMRec));
+ memset(local_impart, 0, sizeof(XIMStaticXIMRec));
+
+ buf[0] = '\0';
+ i = 0;
+ if ((lcd->core->modifiers) && (*lcd->core->modifiers)) {
+#define MODIFIER "@im="
+ mod = strstr(lcd->core->modifiers, MODIFIER);
+ if (mod) {
+ mod += strlen(MODIFIER);
+ while (*mod && *mod != '@' && i < BUFSIZ - 1) {
+ buf[i++] = *mod++;
+ }
+ buf[i] = '\0';
+ }
+ }
+#undef MODIFIER
+ if ((im->core.im_name = Xmalloc(i+1)) == NULL)
+ goto Error2;
+ strcpy(im->core.im_name, buf);
+
+ im->private = local_impart;
+ im->methods = (XIMMethods)&local_im_methods;
+ 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;
+
+ local_impart->ctom_conv = ctom_conv;
+ local_impart->ctow_conv = ctow_conv;
+
+ if ((res_name != NULL) && (*res_name != '\0')){
+ im->core.res_name = strdup(res_name);
+ }
+ if ((res_class != NULL) && (*res_class != '\0')){
+ im->core.res_class = strdup(res_class);
+ }
+
+ return (XIM)im;
+Error2 :
+ Xfree(im->private);
+ Xfree(im->core.im_name);
+ Xfree(im);
+ _XlcCloseConverter(ctom_conv);
+ _XlcCloseConverter(ctow_conv);
+ return(NULL);
+}
+
+static Status
+_CloseIM(XIM xim)
+{
+ StaticXIM im = (StaticXIM)xim;
+ _XlcCloseConverter(im->private->ctom_conv);
+ _XlcCloseConverter(im->private->ctow_conv);
+ XFree(im->private);
+ XFree(im->core.im_name);
+ if (im->core.res_name) XFree(im->core.res_name);
+ if (im->core.res_class) XFree(im->core.res_class);
+ return 1; /*bugID 4163122*/
+}
+
+static char *
+_SetIMValues(
+ XIM xim,
+ XIMArg *arg)
+{
+ return(arg->name); /* evil */
+}
+
+static char *
+_GetIMValues(
+ XIM xim,
+ XIMArg *values)
+{
+ XIMArg *p;
+ XIMStyles *styles;
+
+ for (p = values; p->name != NULL; p++) {
+ if (strcmp(p->name, XNQueryInputStyle) == 0) {
+ styles = (XIMStyles *)Xmalloc(sizeof(XIMStyles));
+ *(XIMStyles **)p->value = styles;
+ styles->count_styles = 1;
+ styles->supported_styles =
+ (XIMStyle*)Xmalloc(styles->count_styles * sizeof(XIMStyle));
+ styles->supported_styles[0] = (XIMPreeditNone | XIMStatusNone);
+ } else {
+ break;
+ }
+ }
+ return (p->name);
+}
+
+static char*
+_SetICValueData(XIC ic, XIMArg *values, XICOp_t mode)
+{
+ XIMArg *p;
+ char *return_name = NULL;
+
+ for (p = values; p != NULL && p->name != NULL; p++) {
+ if(strcmp(p->name, XNInputStyle) == 0) {
+ if (mode == CREATE_IC)
+ ic->core.input_style = (XIMStyle)p->value;
+ } else if (strcmp(p->name, XNClientWindow) == 0) {
+ ic->core.client_window = (Window)p->value ;
+ } else if (strcmp(p->name, XNFocusWindow) == 0) {
+ ic->core.focus_window = (Window)p->value ;
+ } else if (strcmp(p->name, XNPreeditAttributes) == 0
+ || strcmp(p->name, XNStatusAttributes) == 0) {
+ return_name = _SetICValueData(ic, (XIMArg*)p->value, mode);
+ if (return_name) break;
+ } else {
+ return_name = p->name;
+ break;
+ }
+ }
+ return(return_name);
+}
+
+static char*
+_GetICValueData(XIC ic, XIMArg *values, XICOp_t mode)
+{
+ XIMArg *p;
+ char *return_name = NULL;
+
+ for (p = values; p->name != NULL; p++) {
+ if(strcmp(p->name, XNInputStyle) == 0) {
+ *((XIMStyle *)(p->value)) = ic->core.input_style;
+ } else if (strcmp(p->name, XNClientWindow) == 0) {
+ *((Window *)(p->value)) = ic->core.client_window;
+ } else if (strcmp(p->name, XNFocusWindow) == 0) {
+ *((Window *)(p->value)) = ic->core.focus_window;
+ } else if (strcmp(p->name, XNFilterEvents) == 0) {
+ *((unsigned long *)(p->value))= ic->core.filter_events;
+ } else if (strcmp(p->name, XNPreeditAttributes) == 0
+ || strcmp(p->name, XNStatusAttributes) == 0) {
+ return_name = _GetICValueData(ic, (XIMArg*)p->value, mode);
+ if (return_name) break;
+ } else {
+ return_name = p->name;
+ break;
+ }
+ }
+ return(return_name);
+}
+
+static XIC
+_CreateIC(XIM im, XIMArg *arg)
+{
+ XIC ic;
+
+ if ((ic = (XIC)Xmalloc(sizeof(XICRec))) == (XIC)NULL) {
+ return ((XIC)NULL);
+ }
+ memset(ic, 0, sizeof(XICRec));
+
+ ic->methods = (XICMethods)&local_ic_methods;
+ ic->core.im = im;
+ ic->core.filter_events = KeyPressMask;
+
+ if (_SetICValueData(ic, arg, CREATE_IC) != NULL)
+ goto err_return;
+ if (!(ic->core.input_style))
+ goto err_return;
+
+ return (XIC)ic;
+err_return:
+ XFree(ic);
+ return ((XIC)NULL);
+}
+
+static void
+_DestroyIC(XIC ic)
+{
+/*BugId4255571. This Xfree() should be removed because XDestroyIC() still need ic after invoking _DestroyIC() and there is a XFree(ic) at the end of XDestroyIC() already.
+ if(ic)
+ XFree(ic); */
+}
+
+static void
+_SetFocus(XIC ic)
+{
+}
+
+static void
+_UnsetFocus(XIC ic)
+{
+}
+
+static char*
+_SetICValues(XIC ic, XIMArg *args)
+{
+ char *ret = NULL;
+ if (!ic) {
+ return (args->name);
+ }
+ ret = _SetICValueData(ic, args, SET_ICVAL);
+ return(ret);
+}
+
+static char*
+_GetICValues(XIC ic, XIMArg *args)
+{
+ char *ret = NULL;
+ if (!ic) {
+ return (args->name);
+ }
+ ret = _GetICValueData(ic, args, GET_ICVAL);
+ return(ret);
+}
+
+static char *
+_MbReset(XIC xic)
+{
+ return(NULL);
+}
+
+static wchar_t *
+_WcReset(XIC xic)
+{
+ return(NULL);
+}
+
+static int
+_MbLookupString(
+ XIC xic,
+ XKeyEvent *ev,
+ char * buffer,
+ int bytes,
+ KeySym *keysym,
+ Status *status)
+{
+ XComposeStatus NotSupportedYet ;
+ int length;
+
+ length = XLookupString(ev, buffer, bytes, keysym, &NotSupportedYet);
+
+ if (keysym && *keysym == NoSymbol){
+ *status = XLookupNone;
+ } else if (length > 0) {
+ *status = XLookupBoth;
+ } else {
+ *status = XLookupKeySym;
+ }
+ return(length);
+}
+
+static int
+_WcLookupString(
+ XIC xic,
+ XKeyEvent *ev,
+ wchar_t * buffer,
+ int wlen,
+ KeySym *keysym,
+ Status *status)
+{
+ XComposeStatus NotSupportedYet ;
+ int length;
+ /* In single-byte, mb_len = wc_len */
+ char *mb_buf = (char *)Xmalloc(wlen);
+
+ length = XLookupString(ev, mb_buf, wlen, keysym, &NotSupportedYet);
+
+ if (keysym && *keysym == NoSymbol){
+ *status = XLookupNone;
+ } else if (length > 0) {
+ *status = XLookupBoth;
+ } else {
+ *status = XLookupKeySym;
+ }
+ mbstowcs(buffer, mb_buf, length);
+ XFree(mb_buf);
+ return(length);
+}
diff --git a/libX11/src/xlibi18n/XDefaultOMIF.c b/libX11/src/xlibi18n/XDefaultOMIF.c index b1dc66df6..73a7def4f 100644 --- a/libX11/src/xlibi18n/XDefaultOMIF.c +++ b/libX11/src/xlibi18n/XDefaultOMIF.c @@ -1,1261 +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> - -#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; -} +/*
+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/XimProto.h b/libX11/src/xlibi18n/XimProto.h index 6b0096dd6..9551301a2 100644 --- a/libX11/src/xlibi18n/XimProto.h +++ b/libX11/src/xlibi18n/XimProto.h @@ -143,6 +143,13 @@ PERFORMANCE OF THIS SOFTWARE. /* * byte order */ +#ifdef BIGENDIAN +#undef BIGENDIAN +#endif +#ifdef LITTLEENDIAN +#undef LITTLEENDIAN +#endif + #define BIGENDIAN (CARD8)0x42 /* MSB first */ #define LITTLEENDIAN (CARD8)0x6c /* LSB first */ diff --git a/libX11/src/xlibi18n/XlcDL.c b/libX11/src/xlibi18n/XlcDL.c index 75e193c05..4a05c40e4 100644 --- a/libX11/src/xlibi18n/XlcDL.c +++ b/libX11/src/xlibi18n/XlcDL.c @@ -1,612 +1,612 @@ -/* -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> -#else -# if defined(hpux) -# define HAVE_DL_H -# else -# define HAVE_DLFCN_H -# endif -#endif - -#include <stdio.h> - -#ifdef HAVE_DL_H -#include <dl.h> -#endif - -#ifdef HAVE_DLFCN_H -#include <dlfcn.h> -#endif - -#include <ctype.h> - -#include "Xlibint.h" -#include "XlcPublic.h" -#include "XlcPubI.h" - -#define XI18N_DLREL 2 - -#define iscomment(ch) ((ch) == '\0' || (ch) == '#') - -typedef enum { - XLC_OBJECT, - XIM_OBJECT, - XOM_OBJECT -} XI18NDLType; - -typedef struct { - XI18NDLType type; - int locale_name_len; - char *locale_name; - char *dl_name; - char *open; - char *im_register; - char *im_unregister; - int dl_release; - unsigned int refcount; -#if defined(hpux) - shl_t dl_module; -#else - void *dl_module; -#endif -} XI18NObjectsListRec, *XI18NObjectsList; - -#define OBJECT_INIT_LEN 8 -#define OBJECT_INC_LEN 4 -static int lc_len = 0; -static XI18NObjectsListRec *xi18n_objects_list = NULL; -static int lc_count = 0; - -static int -parse_line(char *line, char **argv, int argsize) -{ - int argc = 0; - char *p = line; - - while (argc < argsize) { - while (isspace(*p)) { - ++p; - } - if (iscomment(*p)){ - break; - } - argv[argc++] = p; - while (!isspace(*p)) { - ++p; - } - if (iscomment(*p)) { - break; - } - *p++ = '\0'; - } - return argc; -} - -static char * -strdup_with_underscore(const char *symbol) -{ - char *result; - - if ((result = malloc(strlen(symbol) + 2)) == NULL) - return NULL; - result[0] = '_'; - strcpy(result + 1, symbol); - return result; -} - -#ifndef hpux -static void * -try_both_dlsym (void *handle, char *name) -{ - void *ret; - - ret = dlsym (handle, name); - if (!ret) - { - name = strdup_with_underscore (name); - if (name) - { - ret = dlsym (handle, name); - free (name); - } - } - return ret; -} -#endif - -static void -resolve_object(char *path, const char *lc_name) -{ - char filename[BUFSIZ]; - FILE *fp; - char buf[BUFSIZ]; - - if (lc_len == 0) { /* True only for the 1st time */ - lc_len = OBJECT_INIT_LEN; - xi18n_objects_list = (XI18NObjectsList) - Xmalloc(sizeof(XI18NObjectsListRec) * lc_len); - if (!xi18n_objects_list) return; - } -/* -1266793 -Limit the length of path to prevent stack buffer corruption. - sprintf(filename, "%s/%s", path, "XI18N_OBJS"); -*/ - sprintf(filename, "%.*s/%s", BUFSIZ - 12, path, "XI18N_OBJS"); - fp = fopen(filename, "r"); - if (fp == (FILE *)NULL){ - return; - } - - while (fgets(buf, BUFSIZ, fp) != NULL){ - char *p = buf; - int n; - char *args[6]; - while (isspace(*p)){ - ++p; - } - if (iscomment(*p)){ - continue; - } - - if (lc_count == lc_len) { - lc_len += OBJECT_INC_LEN; - xi18n_objects_list = (XI18NObjectsList) - Xrealloc(xi18n_objects_list, - sizeof(XI18NObjectsListRec) * lc_len); - if (!xi18n_objects_list) return; - } - n = parse_line(p, args, 6); - - if (n == 3 || n == 5) { - if (!strcmp(args[0], "XLC")){ - xi18n_objects_list[lc_count].type = XLC_OBJECT; - } else if (!strcmp(args[0], "XOM")){ - xi18n_objects_list[lc_count].type = XOM_OBJECT; - } else if (!strcmp(args[0], "XIM")){ - xi18n_objects_list[lc_count].type = XIM_OBJECT; - } - xi18n_objects_list[lc_count].dl_name = strdup(args[1]); - xi18n_objects_list[lc_count].open = strdup(args[2]); - xi18n_objects_list[lc_count].dl_release = XI18N_DLREL; - xi18n_objects_list[lc_count].locale_name = strdup(lc_name); - xi18n_objects_list[lc_count].refcount = 0; - xi18n_objects_list[lc_count].dl_module = (void*)NULL; - if (n == 5) { - xi18n_objects_list[lc_count].im_register = strdup(args[3]); - xi18n_objects_list[lc_count].im_unregister = strdup(args[4]); - } else { - xi18n_objects_list[lc_count].im_register = NULL; - xi18n_objects_list[lc_count].im_unregister = NULL; - } - lc_count++; - } - } - fclose(fp); -} - -static char* -__lc_path(const char *dl_name, const char *lc_dir) -{ - char *path; - size_t len; - - /* - * reject this for possible security issue - */ - if (strstr (dl_name, "../")) - return NULL; - - len = (lc_dir ? strlen(lc_dir) : 0 ) + - (dl_name ? strlen(dl_name) : 0) + 10; -#if defined POSTLOCALELIBDIR - len += (strlen(POSTLOCALELIBDIR) + 1); -#endif - path = Xmalloc(len + 1); - - if (strchr(dl_name, '/') != NULL) { - char *slash_p; - slash_p = strrchr(lc_dir, '/'); - *slash_p = '\0'; - strcpy(path, lc_dir); strcat(path, "/"); -#if defined POSTLOCALELIBDIR - strcat(path, POSTLOCALELIBDIR); strcat(path, "/"); -#endif - strcat(path, dl_name); strcat(path, ".so.2"); - *slash_p = '/'; - } else { - strcpy(path, lc_dir); strcat(path, "/"); -#if defined POSTLOCALELIBDIR - strcat(path, POSTLOCALELIBDIR); strcat(path, "/"); -#endif - strcat(path, dl_name); strcat(path, ".so.2"); - } - return path; -} - -/* We reference count dlopen() and dlclose() of modules; unfortunately, - * since XCloseIM, XCloseOM, XlcClose aren't wrapped, but directly - * call the close method of the object, we leak a reference count every - * time we open then close a module. Fixing this would require - * either creating proxy objects or hooks for close_im/close_om - * in XLCd - */ -static Bool -open_object( - XI18NObjectsList object, - char *lc_dir) -{ - char *path; - - if (object->refcount == 0) { - path = __lc_path(object->dl_name, lc_dir); - if (!path) - return False; -#if defined(hpux) - object->dl_module = shl_load(path, BIND_DEFERRED, 0L); -#else - object->dl_module = dlopen(path, RTLD_LAZY); -#endif - Xfree(path); - - if (!object->dl_module) - return False; - } - - object->refcount++; - return True; -} - -static void * -fetch_symbol( - XI18NObjectsList object, - char *symbol) -{ - void *result = NULL; -#if defined(hpux) - int getsyms_cnt, i; - struct shl_symbol *symbols; -#endif - - if (symbol == NULL) - return NULL; - -#if defined(hpux) - getsyms_cnt = shl_getsymbols(object->dl_module, TYPE_PROCEDURE, - EXPORT_SYMBOLS, malloc, &symbols); - - for(i=0; i<getsyms_cnt; i++) { - if(!strcmp(symbols[i].name, symbol)) { - result = symbols[i].value; - break; - } - } - - if(getsyms_cnt > 0) { - free(symbols); - } -#else - result = try_both_dlsym(object->dl_module, symbol); -#endif - - return result; -} - -static void -close_object(XI18NObjectsList object) -{ - object->refcount--; - if (object->refcount == 0) - { -#if defined(hpux) - shl_unload(object->dl_module); -#else - dlclose(object->dl_module); -#endif - object->dl_module = NULL; - } -} - - -typedef XLCd (*dynamicLoadProc)(const char *); - -XLCd -_XlcDynamicLoad(const char *lc_name) -{ - XLCd lcd = (XLCd)NULL; - dynamicLoadProc lc_loader = (dynamicLoadProc)NULL; - int count; - XI18NObjectsList objects_list; - char lc_dir[BUFSIZE], lc_lib_dir[BUFSIZE]; - - if (lc_name == NULL) return (XLCd)NULL; - - if (_XlcLocaleDirName(lc_dir, BUFSIZE, (char *)lc_name) == (char *)NULL) - return (XLCd)NULL; - if (_XlcLocaleLibDirName(lc_lib_dir, BUFSIZE, (char *)lc_name) == (char*)NULL) - return (XLCd)NULL; - - resolve_object(lc_dir, lc_name); - resolve_object(lc_lib_dir, lc_name); - - objects_list = xi18n_objects_list; - count = lc_count; - for (; count-- > 0; objects_list++) { - if (objects_list->type != XLC_OBJECT || - strcmp(objects_list->locale_name, lc_name)) continue; - if (!open_object (objects_list, lc_dir) && \ - !open_object (objects_list, lc_lib_dir)) - continue; - - lc_loader = (dynamicLoadProc)fetch_symbol (objects_list, objects_list->open); - if (!lc_loader) continue; - lcd = (*lc_loader)(lc_name); - if (lcd != (XLCd)NULL) { - break; - } - - close_object (objects_list); - } - return (XLCd)lcd; -} - - -typedef XIM (*dynamicOpenProcp)(XLCd, Display *, XrmDatabase, char *, char *); - -static XIM -_XDynamicOpenIM(XLCd lcd, Display *display, XrmDatabase rdb, - char *res_name, char *res_class) -{ - XIM im = (XIM)NULL; - char lc_dir[BUFSIZE]; - char *lc_name; - dynamicOpenProcp im_openIM = (dynamicOpenProcp)NULL; - int count; - XI18NObjectsList objects_list = xi18n_objects_list; - - lc_name = lcd->core->name; - - if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return (XIM)0; - - count = lc_count; - for (; count-- > 0; objects_list++) { - if (objects_list->type != XIM_OBJECT || - strcmp(objects_list->locale_name, lc_name)) continue; - - if (!open_object (objects_list, lc_dir)) - continue; - - im_openIM = (dynamicOpenProcp)fetch_symbol(objects_list, objects_list->open); - if (!im_openIM) continue; - im = (*im_openIM)(lcd, display, rdb, res_name, res_class); - if (im != (XIM)NULL) { - break; - } - - close_object (objects_list); - } - return (XIM)im; -} - -typedef Bool (*dynamicRegisterCBProcp)( - XLCd, Display *, XrmDatabase, char *, char *, XIDProc, XPointer); - -static Bool -_XDynamicRegisterIMInstantiateCallback( - XLCd lcd, - Display *display, - XrmDatabase rdb, - char *res_name, - char *res_class, - XIDProc callback, - XPointer client_data) -{ - char lc_dir[BUFSIZE]; - char *lc_name; - dynamicRegisterCBProcp im_registerIM = (dynamicRegisterCBProcp)NULL; - Bool ret_flag = False; - int count; - XI18NObjectsList objects_list = xi18n_objects_list; -#if defined(hpux) - int getsyms_cnt, i; - struct shl_symbol *symbols; -#endif - - lc_name = lcd->core->name; - - if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return False; - - count = lc_count; - for (; count-- > 0; objects_list++) { - if (objects_list->type != XIM_OBJECT || - strcmp(objects_list->locale_name, lc_name)) continue; - - if (!open_object (objects_list, lc_dir)) - continue; - im_registerIM = (dynamicRegisterCBProcp)fetch_symbol(objects_list, - objects_list->im_register); - if (!im_registerIM) continue; - ret_flag = (*im_registerIM)(lcd, display, rdb, - res_name, res_class, - callback, client_data); - if (ret_flag) break; - - close_object (objects_list); - } - return (Bool)ret_flag; -} - -typedef Bool (*dynamicUnregisterProcp)( - XLCd, Display *, XrmDatabase, char *, char *, XIDProc, XPointer); - -static Bool -_XDynamicUnRegisterIMInstantiateCallback( - XLCd lcd, - Display *display, - XrmDatabase rdb, - char *res_name, - char *res_class, - XIDProc callback, - XPointer client_data) -{ - char lc_dir[BUFSIZE]; - char *lc_name; - dynamicUnregisterProcp im_unregisterIM = (dynamicUnregisterProcp)NULL; - Bool ret_flag = False; - int count; - XI18NObjectsList objects_list = xi18n_objects_list; -#if defined(hpux) - int getsyms_cnt, i; - struct shl_symbol *symbols; -#endif - - lc_name = lcd->core->name; - if (_XlcLocaleDirName(lc_dir, BUFSIZE, lc_name) == NULL) return False; - - count = lc_count; - for (; count-- > 0; objects_list++) { - if (objects_list->type != XIM_OBJECT || - strcmp(objects_list->locale_name, lc_name)) continue; - - if (!objects_list->refcount) /* Must already be opened */ - continue; - - im_unregisterIM = (dynamicUnregisterProcp)fetch_symbol(objects_list, - objects_list->im_unregister); - - if (!im_unregisterIM) continue; - ret_flag = (*im_unregisterIM)(lcd, display, rdb, - res_name, res_class, - callback, client_data); - if (ret_flag) { - close_object (objects_list); /* opened in RegisterIMInstantiateCallback */ - break; - } - } - return (Bool)ret_flag; -} - -Bool -_XInitDynamicIM(XLCd lcd) -{ - if(lcd == (XLCd)NULL) - return False; - lcd->methods->open_im = _XDynamicOpenIM; - lcd->methods->register_callback = _XDynamicRegisterIMInstantiateCallback; - lcd->methods->unregister_callback = _XDynamicUnRegisterIMInstantiateCallback; - return True; -} - - -typedef XOM (*dynamicIOpenProcp)( - XLCd, Display *, XrmDatabase, _Xconst char *, _Xconst char *); - -static XOM -_XDynamicOpenOM(XLCd lcd, Display *display, XrmDatabase rdb, - _Xconst char *res_name, _Xconst char *res_class) -{ - XOM om = (XOM)NULL; - int count; - char lc_dir[BUFSIZE]; - char *lc_name; - dynamicIOpenProcp om_openOM = (dynamicIOpenProcp)NULL; - XI18NObjectsList objects_list = xi18n_objects_list; -#if defined(hpux) - int getsyms_cnt, i; - struct shl_symbol *symbols; -#endif - - lc_name = lcd->core->name; - - if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return (XOM)0; - - count = lc_count; - for (; count-- > 0; objects_list++) { - if (objects_list->type != XOM_OBJECT || - strcmp(objects_list->locale_name, lc_name)) continue; - if (!open_object (objects_list, lc_dir)) - continue; - - om_openOM = (dynamicIOpenProcp)fetch_symbol(objects_list, objects_list->open); - if (!om_openOM) continue; - om = (*om_openOM)(lcd, display, rdb, res_name, res_class); - if (om != (XOM)NULL) { - break; - } - close_object(objects_list); - } - return (XOM)om; -} - -Bool -_XInitDynamicOM(XLCd lcd) -{ - if(lcd == (XLCd)NULL) - return False; - - lcd->methods->open_om = _XDynamicOpenOM; - - return True; -} +/*
+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>
+#else
+# if defined(hpux)
+# define HAVE_DL_H
+# else
+# define HAVE_DLFCN_H
+# endif
+#endif
+
+#include <stdio.h>
+
+#ifdef HAVE_DL_H
+#include <dl.h>
+#endif
+
+#ifdef HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+#include <ctype.h>
+
+#include "Xlibint.h"
+#include "XlcPublic.h"
+#include "XlcPubI.h"
+
+#define XI18N_DLREL 2
+
+#define iscomment(ch) ((ch) == '\0' || (ch) == '#')
+
+typedef enum {
+ XLC_OBJECT,
+ XIM_OBJECT,
+ XOM_OBJECT
+} XI18NDLType;
+
+typedef struct {
+ XI18NDLType type;
+ int locale_name_len;
+ char *locale_name;
+ char *dl_name;
+ char *open;
+ char *im_register;
+ char *im_unregister;
+ int dl_release;
+ unsigned int refcount;
+#if defined(hpux)
+ shl_t dl_module;
+#else
+ void *dl_module;
+#endif
+} XI18NObjectsListRec, *XI18NObjectsList;
+
+#define OBJECT_INIT_LEN 8
+#define OBJECT_INC_LEN 4
+static int lc_len = 0;
+static XI18NObjectsListRec *xi18n_objects_list = NULL;
+static int lc_count = 0;
+
+static int
+parse_line(char *line, char **argv, int argsize)
+{
+ int argc = 0;
+ char *p = line;
+
+ while (argc < argsize) {
+ while (isspace(*p)) {
+ ++p;
+ }
+ if (iscomment(*p)){
+ break;
+ }
+ argv[argc++] = p;
+ while (!isspace(*p)) {
+ ++p;
+ }
+ if (iscomment(*p)) {
+ break;
+ }
+ *p++ = '\0';
+ }
+ return argc;
+}
+
+static char *
+strdup_with_underscore(const char *symbol)
+{
+ char *result;
+
+ if ((result = malloc(strlen(symbol) + 2)) == NULL)
+ return NULL;
+ result[0] = '_';
+ strcpy(result + 1, symbol);
+ return result;
+}
+
+#ifndef hpux
+static void *
+try_both_dlsym (void *handle, char *name)
+{
+ void *ret;
+
+ ret = dlsym (handle, name);
+ if (!ret)
+ {
+ name = strdup_with_underscore (name);
+ if (name)
+ {
+ ret = dlsym (handle, name);
+ free (name);
+ }
+ }
+ return ret;
+}
+#endif
+
+static void
+resolve_object(char *path, const char *lc_name)
+{
+ char filename[BUFSIZ];
+ FILE *fp;
+ char buf[BUFSIZ];
+
+ if (lc_len == 0) { /* True only for the 1st time */
+ lc_len = OBJECT_INIT_LEN;
+ xi18n_objects_list = (XI18NObjectsList)
+ Xmalloc(sizeof(XI18NObjectsListRec) * lc_len);
+ if (!xi18n_objects_list) return;
+ }
+/*
+1266793
+Limit the length of path to prevent stack buffer corruption.
+ sprintf(filename, "%s/%s", path, "XI18N_OBJS");
+*/
+ sprintf(filename, "%.*s/%s", BUFSIZ - 12, path, "XI18N_OBJS");
+ fp = fopen(filename, "r");
+ if (fp == (FILE *)NULL){
+ return;
+ }
+
+ while (fgets(buf, BUFSIZ, fp) != NULL){
+ char *p = buf;
+ int n;
+ char *args[6];
+ while (isspace(*p)){
+ ++p;
+ }
+ if (iscomment(*p)){
+ continue;
+ }
+
+ if (lc_count == lc_len) {
+ lc_len += OBJECT_INC_LEN;
+ xi18n_objects_list = (XI18NObjectsList)
+ Xrealloc(xi18n_objects_list,
+ sizeof(XI18NObjectsListRec) * lc_len);
+ if (!xi18n_objects_list) return;
+ }
+ n = parse_line(p, args, 6);
+
+ if (n == 3 || n == 5) {
+ if (!strcmp(args[0], "XLC")){
+ xi18n_objects_list[lc_count].type = XLC_OBJECT;
+ } else if (!strcmp(args[0], "XOM")){
+ xi18n_objects_list[lc_count].type = XOM_OBJECT;
+ } else if (!strcmp(args[0], "XIM")){
+ xi18n_objects_list[lc_count].type = XIM_OBJECT;
+ }
+ xi18n_objects_list[lc_count].dl_name = strdup(args[1]);
+ xi18n_objects_list[lc_count].open = strdup(args[2]);
+ xi18n_objects_list[lc_count].dl_release = XI18N_DLREL;
+ xi18n_objects_list[lc_count].locale_name = strdup(lc_name);
+ xi18n_objects_list[lc_count].refcount = 0;
+ xi18n_objects_list[lc_count].dl_module = (void*)NULL;
+ if (n == 5) {
+ xi18n_objects_list[lc_count].im_register = strdup(args[3]);
+ xi18n_objects_list[lc_count].im_unregister = strdup(args[4]);
+ } else {
+ xi18n_objects_list[lc_count].im_register = NULL;
+ xi18n_objects_list[lc_count].im_unregister = NULL;
+ }
+ lc_count++;
+ }
+ }
+ fclose(fp);
+}
+
+static char*
+__lc_path(const char *dl_name, const char *lc_dir)
+{
+ char *path;
+ size_t len;
+
+ /*
+ * reject this for possible security issue
+ */
+ if (strstr (dl_name, "../"))
+ return NULL;
+
+ len = (lc_dir ? strlen(lc_dir) : 0 ) +
+ (dl_name ? strlen(dl_name) : 0) + 10;
+#if defined POSTLOCALELIBDIR
+ len += (strlen(POSTLOCALELIBDIR) + 1);
+#endif
+ path = Xmalloc(len + 1);
+
+ if (strchr(dl_name, '/') != NULL) {
+ char *slash_p;
+ slash_p = strrchr(lc_dir, '/');
+ *slash_p = '\0';
+ strcpy(path, lc_dir); strcat(path, "/");
+#if defined POSTLOCALELIBDIR
+ strcat(path, POSTLOCALELIBDIR); strcat(path, "/");
+#endif
+ strcat(path, dl_name); strcat(path, ".so.2");
+ *slash_p = '/';
+ } else {
+ strcpy(path, lc_dir); strcat(path, "/");
+#if defined POSTLOCALELIBDIR
+ strcat(path, POSTLOCALELIBDIR); strcat(path, "/");
+#endif
+ strcat(path, dl_name); strcat(path, ".so.2");
+ }
+ return path;
+}
+
+/* We reference count dlopen() and dlclose() of modules; unfortunately,
+ * since XCloseIM, XCloseOM, XlcClose aren't wrapped, but directly
+ * call the close method of the object, we leak a reference count every
+ * time we open then close a module. Fixing this would require
+ * either creating proxy objects or hooks for close_im/close_om
+ * in XLCd
+ */
+static Bool
+open_object(
+ XI18NObjectsList object,
+ char *lc_dir)
+{
+ char *path;
+
+ if (object->refcount == 0) {
+ path = __lc_path(object->dl_name, lc_dir);
+ if (!path)
+ return False;
+#if defined(hpux)
+ object->dl_module = shl_load(path, BIND_DEFERRED, 0L);
+#else
+ object->dl_module = dlopen(path, RTLD_LAZY);
+#endif
+ Xfree(path);
+
+ if (!object->dl_module)
+ return False;
+ }
+
+ object->refcount++;
+ return True;
+}
+
+static void *
+fetch_symbol(
+ XI18NObjectsList object,
+ char *symbol)
+{
+ void *result = NULL;
+#if defined(hpux)
+ int getsyms_cnt, i;
+ struct shl_symbol *symbols;
+#endif
+
+ if (symbol == NULL)
+ return NULL;
+
+#if defined(hpux)
+ getsyms_cnt = shl_getsymbols(object->dl_module, TYPE_PROCEDURE,
+ EXPORT_SYMBOLS, malloc, &symbols);
+
+ for(i=0; i<getsyms_cnt; i++) {
+ if(!strcmp(symbols[i].name, symbol)) {
+ result = symbols[i].value;
+ break;
+ }
+ }
+
+ if(getsyms_cnt > 0) {
+ free(symbols);
+ }
+#else
+ result = try_both_dlsym(object->dl_module, symbol);
+#endif
+
+ return result;
+}
+
+static void
+close_object(XI18NObjectsList object)
+{
+ object->refcount--;
+ if (object->refcount == 0)
+ {
+#if defined(hpux)
+ shl_unload(object->dl_module);
+#else
+ dlclose(object->dl_module);
+#endif
+ object->dl_module = NULL;
+ }
+}
+
+
+typedef XLCd (*dynamicLoadProc)(const char *);
+
+XLCd
+_XlcDynamicLoad(const char *lc_name)
+{
+ XLCd lcd = (XLCd)NULL;
+ dynamicLoadProc lc_loader = (dynamicLoadProc)NULL;
+ int count;
+ XI18NObjectsList objects_list;
+ char lc_dir[BUFSIZE], lc_lib_dir[BUFSIZE];
+
+ if (lc_name == NULL) return (XLCd)NULL;
+
+ if (_XlcLocaleDirName(lc_dir, BUFSIZE, (char *)lc_name) == (char *)NULL)
+ return (XLCd)NULL;
+ if (_XlcLocaleLibDirName(lc_lib_dir, BUFSIZE, (char *)lc_name) == (char*)NULL)
+ return (XLCd)NULL;
+
+ resolve_object(lc_dir, lc_name);
+ resolve_object(lc_lib_dir, lc_name);
+
+ objects_list = xi18n_objects_list;
+ count = lc_count;
+ for (; count-- > 0; objects_list++) {
+ if (objects_list->type != XLC_OBJECT ||
+ strcmp(objects_list->locale_name, lc_name)) continue;
+ if (!open_object (objects_list, lc_dir) && \
+ !open_object (objects_list, lc_lib_dir))
+ continue;
+
+ lc_loader = (dynamicLoadProc)fetch_symbol (objects_list, objects_list->open);
+ if (!lc_loader) continue;
+ lcd = (*lc_loader)(lc_name);
+ if (lcd != (XLCd)NULL) {
+ break;
+ }
+
+ close_object (objects_list);
+ }
+ return (XLCd)lcd;
+}
+
+
+typedef XIM (*dynamicOpenProcp)(XLCd, Display *, XrmDatabase, char *, char *);
+
+static XIM
+_XDynamicOpenIM(XLCd lcd, Display *display, XrmDatabase rdb,
+ char *res_name, char *res_class)
+{
+ XIM im = (XIM)NULL;
+ char lc_dir[BUFSIZE];
+ char *lc_name;
+ dynamicOpenProcp im_openIM = (dynamicOpenProcp)NULL;
+ int count;
+ XI18NObjectsList objects_list = xi18n_objects_list;
+
+ lc_name = lcd->core->name;
+
+ if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return (XIM)0;
+
+ count = lc_count;
+ for (; count-- > 0; objects_list++) {
+ if (objects_list->type != XIM_OBJECT ||
+ strcmp(objects_list->locale_name, lc_name)) continue;
+
+ if (!open_object (objects_list, lc_dir))
+ continue;
+
+ im_openIM = (dynamicOpenProcp)fetch_symbol(objects_list, objects_list->open);
+ if (!im_openIM) continue;
+ im = (*im_openIM)(lcd, display, rdb, res_name, res_class);
+ if (im != (XIM)NULL) {
+ break;
+ }
+
+ close_object (objects_list);
+ }
+ return (XIM)im;
+}
+
+typedef Bool (*dynamicRegisterCBProcp)(
+ XLCd, Display *, XrmDatabase, char *, char *, XIDProc, XPointer);
+
+static Bool
+_XDynamicRegisterIMInstantiateCallback(
+ XLCd lcd,
+ Display *display,
+ XrmDatabase rdb,
+ char *res_name,
+ char *res_class,
+ XIDProc callback,
+ XPointer client_data)
+{
+ char lc_dir[BUFSIZE];
+ char *lc_name;
+ dynamicRegisterCBProcp im_registerIM = (dynamicRegisterCBProcp)NULL;
+ Bool ret_flag = False;
+ int count;
+ XI18NObjectsList objects_list = xi18n_objects_list;
+#if defined(hpux)
+ int getsyms_cnt, i;
+ struct shl_symbol *symbols;
+#endif
+
+ lc_name = lcd->core->name;
+
+ if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return False;
+
+ count = lc_count;
+ for (; count-- > 0; objects_list++) {
+ if (objects_list->type != XIM_OBJECT ||
+ strcmp(objects_list->locale_name, lc_name)) continue;
+
+ if (!open_object (objects_list, lc_dir))
+ continue;
+ im_registerIM = (dynamicRegisterCBProcp)fetch_symbol(objects_list,
+ objects_list->im_register);
+ if (!im_registerIM) continue;
+ ret_flag = (*im_registerIM)(lcd, display, rdb,
+ res_name, res_class,
+ callback, client_data);
+ if (ret_flag) break;
+
+ close_object (objects_list);
+ }
+ return (Bool)ret_flag;
+}
+
+typedef Bool (*dynamicUnregisterProcp)(
+ XLCd, Display *, XrmDatabase, char *, char *, XIDProc, XPointer);
+
+static Bool
+_XDynamicUnRegisterIMInstantiateCallback(
+ XLCd lcd,
+ Display *display,
+ XrmDatabase rdb,
+ char *res_name,
+ char *res_class,
+ XIDProc callback,
+ XPointer client_data)
+{
+ char lc_dir[BUFSIZE];
+ char *lc_name;
+ dynamicUnregisterProcp im_unregisterIM = (dynamicUnregisterProcp)NULL;
+ Bool ret_flag = False;
+ int count;
+ XI18NObjectsList objects_list = xi18n_objects_list;
+#if defined(hpux)
+ int getsyms_cnt, i;
+ struct shl_symbol *symbols;
+#endif
+
+ lc_name = lcd->core->name;
+ if (_XlcLocaleDirName(lc_dir, BUFSIZE, lc_name) == NULL) return False;
+
+ count = lc_count;
+ for (; count-- > 0; objects_list++) {
+ if (objects_list->type != XIM_OBJECT ||
+ strcmp(objects_list->locale_name, lc_name)) continue;
+
+ if (!objects_list->refcount) /* Must already be opened */
+ continue;
+
+ im_unregisterIM = (dynamicUnregisterProcp)fetch_symbol(objects_list,
+ objects_list->im_unregister);
+
+ if (!im_unregisterIM) continue;
+ ret_flag = (*im_unregisterIM)(lcd, display, rdb,
+ res_name, res_class,
+ callback, client_data);
+ if (ret_flag) {
+ close_object (objects_list); /* opened in RegisterIMInstantiateCallback */
+ break;
+ }
+ }
+ return (Bool)ret_flag;
+}
+
+Bool
+_XInitDynamicIM(XLCd lcd)
+{
+ if(lcd == (XLCd)NULL)
+ return False;
+ lcd->methods->open_im = _XDynamicOpenIM;
+ lcd->methods->register_callback = _XDynamicRegisterIMInstantiateCallback;
+ lcd->methods->unregister_callback = _XDynamicUnRegisterIMInstantiateCallback;
+ return True;
+}
+
+
+typedef XOM (*dynamicIOpenProcp)(
+ XLCd, Display *, XrmDatabase, _Xconst char *, _Xconst char *);
+
+static XOM
+_XDynamicOpenOM(XLCd lcd, Display *display, XrmDatabase rdb,
+ _Xconst char *res_name, _Xconst char *res_class)
+{
+ XOM om = (XOM)NULL;
+ int count;
+ char lc_dir[BUFSIZE];
+ char *lc_name;
+ dynamicIOpenProcp om_openOM = (dynamicIOpenProcp)NULL;
+ XI18NObjectsList objects_list = xi18n_objects_list;
+#if defined(hpux)
+ int getsyms_cnt, i;
+ struct shl_symbol *symbols;
+#endif
+
+ lc_name = lcd->core->name;
+
+ if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return (XOM)0;
+
+ count = lc_count;
+ for (; count-- > 0; objects_list++) {
+ if (objects_list->type != XOM_OBJECT ||
+ strcmp(objects_list->locale_name, lc_name)) continue;
+ if (!open_object (objects_list, lc_dir))
+ continue;
+
+ om_openOM = (dynamicIOpenProcp)fetch_symbol(objects_list, objects_list->open);
+ if (!om_openOM) continue;
+ om = (*om_openOM)(lcd, display, rdb, res_name, res_class);
+ if (om != (XOM)NULL) {
+ break;
+ }
+ close_object(objects_list);
+ }
+ return (XOM)om;
+}
+
+Bool
+_XInitDynamicOM(XLCd lcd)
+{
+ if(lcd == (XLCd)NULL)
+ return False;
+
+ lcd->methods->open_om = _XDynamicOpenOM;
+
+ return True;
+}
diff --git a/libX11/src/xlibi18n/lcCharSet.c b/libX11/src/xlibi18n/lcCharSet.c index 5d287811c..6be5f5d16 100644 --- a/libX11/src/xlibi18n/lcCharSet.c +++ b/libX11/src/xlibi18n/lcCharSet.c @@ -1,225 +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 = 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; -} +/*
+ * 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 97b22ac44..79df2450c 100644 --- a/libX11/src/xlibi18n/lcDB.c +++ b/libX11/src/xlibi18n/lcDB.c @@ -1,1339 +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 */ - -/* 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, "ed); /* 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 */ +/*
+ *
+ * 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, "ed); /* 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/lcDynamic.c b/libX11/src/xlibi18n/lcDynamic.c index f6df94cbb..8d022d885 100644 --- a/libX11/src/xlibi18n/lcDynamic.c +++ b/libX11/src/xlibi18n/lcDynamic.c @@ -51,7 +51,7 @@ from The Open Group. #include "Xlcint.h" #ifndef XLOCALEDIR -#define XLOCALEDIR "/usr/lib/X11/locale" +#define XLOCALEDIR "locale" #endif #define LCLIBNAME "xi18n.so" diff --git a/libX11/src/xlibi18n/lcFile.c b/libX11/src/xlibi18n/lcFile.c index 4e4439773..5a9b0f4ab 100644 --- a/libX11/src/xlibi18n/lcFile.c +++ b/libX11/src/xlibi18n/lcFile.c @@ -1,829 +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 "/usr/lib/X11/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; -} +/*
+ *
+ * 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 619cb47f9..ec31cb581 100644 --- a/libX11/src/xlibi18n/lcGeneric.c +++ b/libX11/src/xlibi18n/lcGeneric.c @@ -1,1180 +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 = 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); -} +/*
+ * 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 1b1fb548a..d0db410fc 100644 --- a/libX11/src/xlibi18n/lcPublic.c +++ b/libX11/src/xlibi18n/lcPublic.c @@ -1,314 +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 = 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); -} +/*
+ * 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);
+}
diff --git a/libX11/src/xlibi18n/makefile b/libX11/src/xlibi18n/makefile new file mode 100644 index 000000000..5be81d350 --- /dev/null +++ b/libX11/src/xlibi18n/makefile @@ -0,0 +1,80 @@ +#AM_CFLAGS= \ +# -I$(top_srcdir)/include \ +# -I$(top_srcdir)/include/X11 \ +# -I$(top_builddir)/include \ +# -I$(top_builddir)/include/X11 \ +# -I$(top_srcdir)/src/xcms \ +# -I$(top_srcdir)/src/xkb \ +# -I$(top_srcdir)/src/xlibi18n \ +# -I$(top_srcdir)/src \ +# $(X11_CFLAGS) \ +# $(BIGFONT_CFLAGS) \ +# $(XDMCP_CFLAGS) \ +# -D_BSD_SOURCE \ +# $(XMALLOC_ZERO_CFLAGS) + +LIBRARY = libi18n + + +# +# Dynamic loading code for i18n modules +# +#if XLIB_LOADABLE_I18N +#XI18N_DL_SOURCES = \ +# XlcDL.c \ +# XlcSL.c +#else +# +# Static interfaces to input/output methods +# +#IM_LIBS = \ +# ${top_builddir}/modules/im/ximcp/libximcp.la + +#LC_LIBS = \ +# ${top_builddir}/modules/lc/def/libxlcDef.la \ +# ${top_builddir}/modules/lc/gen/libxlibi18n.la \ +# ${top_builddir}/modules/lc/Utf8/libxlcUTF8Load.la \ +# ${top_builddir}/modules/lc/xlocale/libxlocale.la + +#OM_LIBS = \ +# ${top_builddir}/modules/om/generic/libxomGeneric.la +#endif + +#libi18n_la_LIBADD = \ +# $(IM_LIBS) $(LC_LIBS) $(OM_LIBS) + +INCLUDES += ..\..\include\X11 +DEFINES += XLOCALELIBDIR="\".\"" + +CSRCS = \ + $(XI18N_DL_SOURCES) \ + XDefaultIMIF.c \ + XDefaultOMIF.c \ + xim_trans.c\ + ICWrap.c\ + IMWrap.c\ + imKStoUCS.c\ + lcCT.c\ + lcCharSet.c\ + lcConv.c\ + lcDB.c\ + lcDynamic.c\ + lcFile.c\ + lcGeneric.c\ + lcInit.c\ + lcPrTxt.c\ + lcPubWrap.c\ + lcPublic.c\ + lcRM.c\ + lcStd.c\ + lcTxtPr.c\ + lcUTF8.c\ + lcUtil.c\ + lcWrap.c\ + mbWMProps.c\ + mbWrap.c\ + utf8WMProps.c\ + utf8Wrap.c\ + wcWrap.c + + |