aboutsummaryrefslogtreecommitdiff
path: root/libX11/src/xlibi18n
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-04-27 15:56:59 +0000
committermarha <marha@users.sourceforge.net>2011-04-27 15:56:59 +0000
commit100633b3e7619842f345cb7603b0db6b5761dd11 (patch)
tree3c3af754c7e801c07263269837d6a05072ff834c /libX11/src/xlibi18n
parent205a4bdae76f287126db9f45a4f0ba631e3efca1 (diff)
parent96d6df5da9cddedf4931bf8e17f96e242467c661 (diff)
downloadvcxsrv-100633b3e7619842f345cb7603b0db6b5761dd11.tar.gz
vcxsrv-100633b3e7619842f345cb7603b0db6b5761dd11.tar.bz2
vcxsrv-100633b3e7619842f345cb7603b0db6b5761dd11.zip
svn merge ^/branches/released .
Diffstat (limited to 'libX11/src/xlibi18n')
-rw-r--r--libX11/src/xlibi18n/XDefaultIMIF.c6
-rw-r--r--libX11/src/xlibi18n/XDefaultOMIF.c2539
-rw-r--r--libX11/src/xlibi18n/XlcDL.c40
-rw-r--r--libX11/src/xlibi18n/lcCharSet.c451
-rw-r--r--libX11/src/xlibi18n/lcDB.c2688
-rw-r--r--libX11/src/xlibi18n/lcFile.c1664
-rw-r--r--libX11/src/xlibi18n/lcGeneric.c2371
-rw-r--r--libX11/src/xlibi18n/lcPublic.c631
8 files changed, 5153 insertions, 5237 deletions
diff --git a/libX11/src/xlibi18n/XDefaultIMIF.c b/libX11/src/xlibi18n/XDefaultIMIF.c
index c7a2fe9d3..71b1af177 100644
--- a/libX11/src/xlibi18n/XDefaultIMIF.c
+++ b/libX11/src/xlibi18n/XDefaultIMIF.c
@@ -226,12 +226,10 @@ _XDefaultOpenIM(
local_impart->ctow_conv = ctow_conv;
if ((res_name != NULL) && (*res_name != '\0')){
- im->core.res_name = (char *)Xmalloc(strlen(res_name)+1);
- strcpy(im->core.res_name,res_name);
+ im->core.res_name = strdup(res_name);
}
if ((res_class != NULL) && (*res_class != '\0')){
- im->core.res_class = (char *)Xmalloc(strlen(res_class)+1);
- strcpy(im->core.res_class,res_class);
+ im->core.res_class = strdup(res_class);
}
return (XIM)im;
diff --git a/libX11/src/xlibi18n/XDefaultOMIF.c b/libX11/src/xlibi18n/XDefaultOMIF.c
index 1821e6459..73a7def4f 100644
--- a/libX11/src/xlibi18n/XDefaultOMIF.c
+++ b/libX11/src/xlibi18n/XDefaultOMIF.c
@@ -1,1277 +1,1262 @@
-/*
-Copyright 1985, 1986, 1987, 1991, 1998 The Open Group
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions: The above copyright notice and this
-permission notice shall be included in all copies or substantial
-portions of the Software.
-
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
-EVEN IF ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
-
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-
-X Window System is a trademark of The Open Group
-
-OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
-logo, LBX, X Window System, and Xinerama are trademarks of the Open
-Group. All other trademarks and registered trademarks mentioned herein
-are the property of their respective owners. No right, title or
-interest in or to any trademark, service mark, logo or trade name of
-Sun Microsystems, Inc. or its licensors is granted.
-
-*/
-/*
- * Copyright 2000 Oracle and/or its affiliates. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include "Xlibint.h"
-#include "Xlcint.h"
-#include "XlcPublic.h"
-#include <X11/Xos.h>
-#include <X11/Xatom.h>
-#include <stdio.h>
-#include <stdint.h>
-
-#define MAXFONTS 100
-
-#define XOM_GENERIC(om) (&((XOMGeneric) om)->gen)
-#define XOC_GENERIC(font_set) (&((XOCGeneric) font_set)->gen)
-
-#define DefineLocalBuf char local_buf[BUFSIZ]
-#define AllocLocalBuf(length) (length > BUFSIZ ? (char *)Xmalloc(length) : local_buf)
-#define FreeLocalBuf(ptr) if (ptr != local_buf) Xfree(ptr)
-
-typedef struct _FontDataRec {
- char *name;
-} FontDataRec, *FontData;
-
-typedef struct _OMDataRec {
- int font_data_count;
- FontData font_data;
-} OMDataRec, *OMData;
-
-typedef struct _XOMGenericPart {
- OMData data;
-} XOMGenericPart;
-
-typedef struct _XOMGenericRec {
- XOMMethods methods;
- XOMCoreRec core;
- XOMGenericPart gen;
-} XOMGenericRec, *XOMGeneric;
-
-typedef struct _FontSetRec {
- int id;
- int font_data_count;
- FontData font_data;
- char *font_name;
- XFontStruct *info;
- XFontStruct *font;
-} FontSetRec, *FontSet;
-
-typedef struct _XOCGenericPart {
- XlcConv wcs_to_cs;
- FontSet font_set;
-} XOCGenericPart;
-
-typedef struct _XOCGenericRec {
- XOCMethods methods;
- XOCCoreRec core;
- XOCGenericPart gen;
-} XOCGenericRec, *XOCGeneric;
-
-static Bool
-init_fontset(
- XOC oc)
-{
- XOCGenericPart *gen;
- FontSet font_set;
- OMData data;
-
- data = XOM_GENERIC(oc->core.om)->data;
-
- font_set = (FontSet) Xmalloc(sizeof(FontSetRec));
- if (font_set == NULL)
- return False;
- bzero((char *) font_set, sizeof(FontSetRec));
-
- gen = XOC_GENERIC(oc);
- gen->font_set = font_set;
-
- font_set->font_data_count = data->font_data_count;
- font_set->font_data = data->font_data;
-
- return True;
-}
-
-static char *
-get_prop_name(
- Display *dpy,
- XFontStruct *fs)
-{
- unsigned long fp;
-
- if (XGetFontProperty(fs, XA_FONT, &fp))
- return XGetAtomName(dpy, fp);
-
- return (char *) NULL;
-}
-
-static FontData
-check_charset(
- FontSet font_set,
- char *font_name)
-{
- FontData font_data;
- char *last;
- int count;
- ssize_t length, name_len;
-
- name_len = strlen(font_name);
- last = font_name + name_len;
-
- count = font_set->font_data_count;
- font_data = font_set->font_data;
-
- for ( ; count-- > 0; font_data++) {
- length = strlen(font_data->name);
-
- if (length > name_len)
- return(NULL);
-
- if (_XlcCompareISOLatin1(last - length, font_data->name) == 0)
- return font_data;
- }
- return (FontData) NULL;
-}
-
-#if 0 /* Unused */
-static int
-check_fontname(
- XOC oc,
- char *name)
-{
- Display *dpy = oc->core.om->core.display;
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontData data;
- FontSet font_set;
- XFontStruct *fs_list;
- char **fn_list, *fname, *prop_fname = NULL;
- int list_num, i;
- int list2_num;
- char **fn2_list = NULL;
- int found_num = 0;
-
- fn_list = XListFonts(dpy, name, MAXFONTS, &list_num);
- if (fn_list == NULL)
- return found_num;
-
- for (i = 0; i < list_num; i++) {
- fname = fn_list[i];
-
- font_set = gen->font_set;
-
- if ((data = check_charset(font_set, fname)) == NULL) {
- if ((fn2_list = XListFontsWithInfo(dpy, name, MAXFONTS,
- &list2_num, &fs_list))
- && (prop_fname = get_prop_name(dpy, fs_list))
- && (data = check_charset(font_set, prop_fname)))
- fname = prop_fname;
- }
- if (data) {
- font_set->font_name = (char *) Xmalloc(strlen(fname) + 1);
- if (font_set->font_name) {
- strcpy(font_set->font_name, fname);
- found_num++;
- }
- }
- if (fn2_list) {
- XFreeFontInfo(fn2_list, fs_list, list2_num);
- fn2_list = NULL;
- if (prop_fname) {
- Xfree(prop_fname);
- prop_fname = NULL;
- }
- }
- if (found_num == 1)
- break;
- }
- XFreeFontNames(fn_list);
- return found_num;
-}
-#endif
-
-static Bool
-load_font(
- XOC oc)
-{
- Display *dpy = oc->core.om->core.display;
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontSet font_set = gen->font_set;
-
- if (font_set->font_name == NULL)
- return False;
-
- if (font_set->font == NULL) {
- font_set->font = XLoadQueryFont(dpy, font_set->font_name);
- if (font_set->font == NULL)
- return False;
- }
- return True;
-}
-
-#if 0
-static Bool
-load_font_info(
- XOC oc)
-{
- Display *dpy = oc->core.om->core.display;
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontSet font_set = gen->font_set;
- char **fn_list;
- int fn_num;
-
- if (font_set->font_name == NULL)
- return False;
-
- if (font_set->info == NULL) {
- fn_list = XListFontsWithInfo(dpy, font_set->font_name, 1, &fn_num,
- &font_set->info);
- if (font_set->info == NULL)
- return False;
- if (fn_num > 0)
- font_set->info->fid = XLoadFont(dpy, font_set->font_name);
-
- if (fn_list) XFreeFontNames(fn_list);
- }
- return True;
-}
-#endif
-
-static void
-set_fontset_extents(
- XOC oc)
-{
- XRectangle *ink = &oc->core.font_set_extents.max_ink_extent;
- XRectangle *logical = &oc->core.font_set_extents.max_logical_extent;
- XFontStruct **font_list, *font;
- XCharStruct overall;
- int logical_ascent, logical_descent;
-
- font_list = oc->core.font_info.font_struct_list;
- font = *font_list++;
- overall = font->max_bounds;
- overall.lbearing = font->min_bounds.lbearing;
- logical_ascent = font->ascent;
- logical_descent = font->descent;
-
- ink->x = overall.lbearing;
- ink->y = -(overall.ascent);
- ink->width = overall.rbearing - overall.lbearing;
- ink->height = overall.ascent + overall.descent;
-
- logical->x = 0;
- logical->y = -(logical_ascent);
- logical->width = overall.width;
- logical->height = logical_ascent + logical_descent;
-}
-
-static Bool
-init_core_part(
- XOC oc)
-{
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontSet font_set;
- XFontStruct **font_struct_list;
- char **font_name_list, *font_name_buf;
- int count, length;
-
- font_set = gen->font_set;
- count = length = 0;
-
- if (font_set->font_name != NULL) {
- length += strlen(font_set->font_name) + 1;
- count++;
- }
- if (count == 0)
- return False;
-
- font_struct_list = (XFontStruct **) Xmalloc(sizeof(XFontStruct *));
- if (font_struct_list == NULL)
- return False;
-
- font_name_list = (char **) Xmalloc(sizeof(char *));
- if (font_name_list == NULL)
- goto err;
-
- font_name_buf = (char *) Xmalloc(length);
- if (font_name_buf == NULL)
- goto err;
-
- oc->core.font_info.num_font = 1;
- oc->core.font_info.font_name_list = font_name_list;
- oc->core.font_info.font_struct_list = font_struct_list;
-
- font_set = gen->font_set;
-
- if (font_set->font_name != NULL) {
- font_set->id = 1;
- if (font_set->font)
- *font_struct_list++ = font_set->font;
- else
- *font_struct_list++ = font_set->info;
- strcpy(font_name_buf, font_set->font_name);
- Xfree(font_set->font_name);
- *font_name_list++ = font_set->font_name = font_name_buf;
- font_name_buf += strlen(font_name_buf) + 1;
- }
-
- set_fontset_extents(oc);
-
- return True;
-
-err:
- if (font_name_list)
- Xfree(font_name_list);
- Xfree(font_struct_list);
-
- return False;
-}
-
-static char *
-get_font_name(
- XOC oc,
- char *pattern)
-{
- char **list, *name;
- int count;
- XFontStruct *fs;
- Display *dpy = oc->core.om->core.display;
-
- list = XListFonts(dpy, pattern, 1, &count);
- if (list != NULL) {
- name = (char *) Xmalloc(strlen(*list) + 1);
- if (name)
- strcpy(name, *list);
-
- XFreeFontNames(list);
- } else {
- fs = XLoadQueryFont(dpy, pattern);
- if (fs == NULL) return NULL;
-
- name = get_prop_name(dpy, fs);
- XFreeFont(dpy, fs);
- }
- return name;
-}
-
-static int
-parse_fontname(
- XOC oc)
-{
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontSet font_set;
- FontData font_data;
- char *pattern, *last, buf[BUFSIZ];
- int font_data_count, found_num = 0;
- ssize_t length;
- int count, num_fields;
- char *base_name, *font_name, **name_list, **cur_name_list;
- char *charset_p = NULL;
- Bool append_charset;
- /*
- append_charset flag should be set to True when the XLFD fontname
- doesn't contain a chaset part.
- */
-
- name_list = _XParseBaseFontNameList(oc->core.base_name_list, &count);
- if (name_list == NULL)
- return -1;
- cur_name_list = name_list;
-
- while (count-- > 0) {
- pattern = *cur_name_list++;
- if (pattern == NULL || *pattern == '\0')
- continue;
-
- append_charset = False;
-
- if (strchr(pattern, '*') == NULL &&
- (font_name = get_font_name(oc, pattern))) {
-
- font_set = gen->font_set;
-
- font_data = check_charset(font_set, font_name);
- if (font_data == NULL) {
- Display *dpy = oc->core.om->core.display;
- char **fn_list = NULL, *prop_fname = NULL;
- int list_num;
- XFontStruct *fs_list;
- if ((fn_list = XListFontsWithInfo(dpy, font_name,
- MAXFONTS,
- &list_num, &fs_list))
- && (prop_fname = get_prop_name(dpy, fs_list))
- && (font_data = check_charset(font_set, prop_fname))) {
- if (fn_list) {
- XFreeFontInfo(fn_list, fs_list, list_num);
- fn_list = NULL;
- }
- font_name = prop_fname;
- }
- }
- if (font_data == NULL)
- continue;
-
- font_set->font_name = (char *) Xmalloc(strlen(font_name) + 1);
- if (font_set->font_name == NULL) {
- Xfree(font_name);
- goto err;
- }
- strcpy(font_set->font_name, font_name);
- Xfree(font_name);
- found_num++;
- goto found;
- }
-/*
-1266793
-Limit the length of the string copy to prevent stack corruption.
- strcpy(buf, pattern);
-*/
- strncpy(buf, pattern, BUFSIZ);
- buf[BUFSIZ-1] = '\0';
- length = strlen(buf);
- last = buf + length - 1;
-
- for (num_fields = 0, base_name = buf; *base_name != '\0'; base_name++)
- if (*base_name == '-') num_fields++;
- if (strchr(pattern, '*') == NULL) {
- if (num_fields == 12) {
- append_charset = True;
- *++last = '-';
- last++;
- } else
- continue;
- } else {
- if (num_fields == 13 || num_fields == 14) {
- /*
- * There are 14 fields in an XLFD name -- make certain the
- * charset (& encoding) is placed in the correct field.
- */
- append_charset = True;
- last = strrchr (buf, '-');
- if (num_fields == 14) {
- *last = '\0';
- last = strrchr (buf, '-');
- }
- last++;
- } else if (*last == '*') {
- append_charset = True;
- if (length > 3 && *(last-3) == '-' && *(last-2) == '*'
- && *(last-1) == '-') {
- last -= 2;
- }
- *++last = '-';
- last++;
- } else {
- last = strrchr (buf, '-');
- charset_p = last;
- charset_p = strrchr (buf, '-');
- while (*(--charset_p) != '-');
- charset_p++;
- }
- }
-
- font_set = gen->font_set;
-
- font_data = font_set->font_data;
- font_data_count = font_set->font_data_count;
- for ( ; font_data_count-- > 0; font_data++) {
- if (append_charset)
- {
-/*
-1266793
-Limit the length of the string copy to prevent stack corruption.
- strcpy(last, font_data->name);
-*/
- strncpy(last, font_data->name, BUFSIZ - length);
- buf[BUFSIZ-1] = '\0';
- }
- else {
- if (_XlcCompareISOLatin1(charset_p,
- font_data->name)) {
- continue;
- }
- }
- if ((font_set->font_name = get_font_name(oc, buf)))
- break;
- }
- if (font_set->font_name != NULL) {
- found_num++;
- goto found;
- }
- }
- found:
- base_name = (char *) Xmalloc(strlen(oc->core.base_name_list) + 1);
- if (base_name == NULL)
- goto err;
-
- strcpy(base_name, oc->core.base_name_list);
- oc->core.base_name_list = base_name;
-
- XFreeStringList(name_list);
-
- return found_num;
-err:
- XFreeStringList(name_list);
-
- return -1;
-}
-
-static Bool
-set_missing_list(
- XOC oc)
-{
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontSet font_set;
- char **charset_list, *charset_buf;
- int count, length;
-
- font_set = gen->font_set;
- count = length = 0;
-
- if (!font_set->info && !font_set->font) {
- length += strlen(font_set->font_data->name) + 1;
- count++;
- }
-
- if (count == 0)
- return True;
-
- charset_list = (char **) Xmalloc(sizeof(char *));
- if (charset_list == NULL)
- return False;
-
- charset_buf = (char *) Xmalloc(length);
- if (charset_buf == NULL) {
- Xfree(charset_list);
- return False;
- }
-
- oc->core.missing_list.charset_list = charset_list;
-
- font_set = gen->font_set;
-
- if (!font_set->info && !font_set->font) {
- strcpy(charset_buf, font_set->font_data->name);
- *charset_list++ = charset_buf;
- charset_buf += strlen(charset_buf) + 1;
- }
- return True;
-}
-
-static Bool
-create_fontset(
- XOC oc)
-{
- int found_num;
-
- if (init_fontset(oc) == False)
- return False;
-
- found_num = parse_fontname(oc);
- if (found_num <= 0) {
- if (found_num == 0)
- set_missing_list(oc);
- return False;
- }
-
- if (load_font(oc) == False)
- return False;
-
- if (init_core_part(oc) == False)
- return False;
-
- if (set_missing_list(oc) == False)
- return False;
-
- return True;
-}
-
-static void
-destroy_oc(
- XOC oc)
-{
- Display *dpy = oc->core.om->core.display;
- XOCGenericPart *gen = XOC_GENERIC(oc);
- XFontStruct **font_list, *font;
-
- if (gen->font_set)
- Xfree(gen->font_set);
-
- if (oc->core.base_name_list)
- Xfree(oc->core.base_name_list);
-
- if (oc->core.font_info.font_name_list)
- XFreeStringList(oc->core.font_info.font_name_list);
-
- if ((font_list = oc->core.font_info.font_struct_list)) {
- if ((font = *font_list)) {
- if (font->fid)
- XFreeFont(dpy, font);
- else
- XFreeFontInfo(NULL, font, 1);
- }
- Xfree(oc->core.font_info.font_struct_list);
- }
-
- if (oc->core.missing_list.charset_list)
- XFreeStringList(oc->core.missing_list.charset_list);
-
-#ifdef notdef
- if (oc->core.res_name)
- Xfree(oc->core.res_name);
- if (oc->core.res_class)
- Xfree(oc->core.res_class);
-#endif
-
- Xfree(oc);
-}
-
-static char *
-set_oc_values(
- XOC oc,
- XlcArgList args,
- int num_args)
-{
- if (oc->core.resources == NULL)
- return NULL;
-
- return _XlcSetValues((XPointer) oc, oc->core.resources,
- oc->core.num_resources, args, num_args, XlcSetMask);
-}
-
-static char *
-get_oc_values(
- XOC oc,
- XlcArgList args,
- int num_args)
-{
- if (oc->core.resources == NULL)
- return NULL;
-
- return _XlcGetValues((XPointer) oc, oc->core.resources,
- oc->core.num_resources, args, num_args, XlcGetMask);
-}
-
-static Bool
-wcs_to_mbs(
- XOC oc,
- char *to,
- _Xconst wchar_t *from,
- int length)
-{
- XlcConv conv = XOC_GENERIC(oc)->wcs_to_cs;
- XLCd lcd;
- int ret, to_left = length;
-
- if (conv == NULL) {
- lcd = oc->core.om->core.lcd;
- conv = _XlcOpenConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte);
- if (conv == NULL)
- return False;
- XOC_GENERIC(oc)->wcs_to_cs = conv;
- } else
- _XlcResetConverter(conv);
-
- ret = _XlcConvert(conv, (XPointer *) &from, &length, (XPointer *) &to,
- &to_left, NULL, 0);
- if (ret != 0 || length > 0)
- return False;
-
- return True;
-}
-
-static int
-_XmbDefaultTextEscapement(XOC oc, _Xconst char *text, int length)
-{
- return XTextWidth(*oc->core.font_info.font_struct_list, text, length);
-}
-
-static int
-_XwcDefaultTextEscapement(XOC oc, _Xconst wchar_t *text, int length)
-{
- DefineLocalBuf;
- char *buf = AllocLocalBuf(length);
- int ret = 0;
-
- if (buf == NULL)
- return 0;
-
- if (wcs_to_mbs(oc, buf, text, length) == False)
- goto err;
-
- ret = _XmbDefaultTextEscapement(oc, buf, length);
-
-err:
- FreeLocalBuf(buf);
-
- return ret;
-}
-
-static int
-_XmbDefaultTextExtents(XOC oc, _Xconst char *text, int length,
- XRectangle *overall_ink, XRectangle *overall_logical)
-{
- int direction, logical_ascent, logical_descent;
- XCharStruct overall;
-
- XTextExtents(*oc->core.font_info.font_struct_list, text, length, &direction,
- &logical_ascent, &logical_descent, &overall);
-
- if (overall_ink) {
- overall_ink->x = overall.lbearing;
- overall_ink->y = -(overall.ascent);
- overall_ink->width = overall.rbearing - overall.lbearing;
- overall_ink->height = overall.ascent + overall.descent;
- }
-
- if (overall_logical) {
- overall_logical->x = 0;
- overall_logical->y = -(logical_ascent);
- overall_logical->width = overall.width;
- overall_logical->height = logical_ascent + logical_descent;
- }
-
- return overall.width;
-}
-
-static int
-_XwcDefaultTextExtents(XOC oc, _Xconst wchar_t *text, int length,
- XRectangle *overall_ink, XRectangle *overall_logical)
-{
- DefineLocalBuf;
- char *buf = AllocLocalBuf(length);
- int ret = 0;
-
- if (buf == NULL)
- return 0;
-
- if (wcs_to_mbs(oc, buf, text, length) == False)
- goto err;
-
- ret = _XmbDefaultTextExtents(oc, buf, length, overall_ink, overall_logical);
-
-err:
- FreeLocalBuf(buf);
-
- return ret;
-}
-
-static Status
-_XmbDefaultTextPerCharExtents(XOC oc, _Xconst char *text, int length,
- XRectangle *ink_buf, XRectangle *logical_buf,
- int buf_size, int *num_chars,
- XRectangle *overall_ink,
- XRectangle *overall_logical)
-{
- XFontStruct *font = *oc->core.font_info.font_struct_list;
- XCharStruct *def, *cs, overall;
- Bool first = True;
-
- if (buf_size < length)
- return 0;
-
- bzero((char *) &overall, sizeof(XCharStruct));
- *num_chars = 0;
-
- CI_GET_DEFAULT_INFO_1D(font, def)
-
- while (length-- > 0) {
- CI_GET_CHAR_INFO_1D(font, *text, def, cs)
- text++;
- if (cs == NULL)
- continue;
-
- ink_buf->x = overall.width + cs->lbearing;
- ink_buf->y = -(cs->ascent);
- ink_buf->width = cs->rbearing - cs->lbearing;
- ink_buf->height = cs->ascent + cs->descent;
- ink_buf++;
-
- logical_buf->x = overall.width;
- logical_buf->y = -(font->ascent);
- logical_buf->width = cs->width;
- logical_buf->height = font->ascent + font->descent;
- logical_buf++;
-
- if (first) {
- overall = *cs;
- first = False;
- } else {
- overall.ascent = max(overall.ascent, cs->ascent);
- overall.descent = max(overall.descent, cs->descent);
- overall.lbearing = min(overall.lbearing, overall.width +
- cs->lbearing);
- overall.rbearing = max(overall.rbearing, overall.width +
- cs->rbearing);
- overall.width += cs->width;
- }
- (*num_chars)++;
- }
-
- if (overall_ink) {
- overall_ink->x = overall.lbearing;
- overall_ink->y = -(overall.ascent);
- overall_ink->width = overall.rbearing - overall.lbearing;
- overall_ink->height = overall.ascent + overall.descent;
- }
-
- if (overall_logical) {
- overall_logical->x = 0;
- overall_logical->y = -(font->ascent);
- overall_logical->width = overall.width;
- overall_logical->height = font->ascent + font->descent;
- }
-
- return 1;
-}
-
-static Status
-_XwcDefaultTextPerCharExtents(XOC oc, _Xconst wchar_t *text, int length,
- XRectangle *ink_buf, XRectangle *logical_buf,
- int buf_size, int *num_chars,
- XRectangle *overall_ink,
- XRectangle *overall_logical)
-{
- DefineLocalBuf;
- char *buf = AllocLocalBuf(length);
- Status ret = 0;
-
- if (buf == NULL)
- return 0;
-
- if (wcs_to_mbs(oc, buf, text, length) == False)
- goto err;
-
- ret = _XmbDefaultTextPerCharExtents(oc, buf, length, ink_buf, logical_buf,
- buf_size, num_chars, overall_ink,
- overall_logical);
-
-err:
- FreeLocalBuf(buf);
-
- return ret;
-}
-
-static int
-_XmbDefaultDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
- _Xconst char *text, int length)
-{
- XFontStruct *font = *oc->core.font_info.font_struct_list;
-
- XSetFont(dpy, gc, font->fid);
- XDrawString(dpy, d, gc, x, y, text, length);
-
- return XTextWidth(font, text, length);
-}
-
-static int
-_XwcDefaultDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
- _Xconst wchar_t *text, int length)
-{
- DefineLocalBuf;
- char *buf = AllocLocalBuf(length);
- int ret = 0;
-
- if (buf == NULL)
- return 0;
-
- if (wcs_to_mbs(oc, buf, text, length) == False)
- goto err;
-
- ret = _XmbDefaultDrawString(dpy, d, oc, gc, x, y, buf, length);
-
-err:
- FreeLocalBuf(buf);
-
- return ret;
-}
-
-static void
-_XmbDefaultDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
- int y, _Xconst char *text, int length)
-{
- XSetFont(dpy, gc, (*oc->core.font_info.font_struct_list)->fid);
- XDrawImageString(dpy, d, gc, x, y, text, length);
-}
-
-static void
-_XwcDefaultDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
- int y, _Xconst wchar_t *text, int length)
-{
- DefineLocalBuf;
- char *buf = AllocLocalBuf(length);
-
- if (buf == NULL)
- return;
-
- if (wcs_to_mbs(oc, buf, text, length) == False)
- goto err;
-
- _XmbDefaultDrawImageString(dpy, d, oc, gc, x, y, buf, length);
-
-err:
- FreeLocalBuf(buf);
-}
-
-static _Xconst XOCMethodsRec oc_default_methods = {
- destroy_oc,
- set_oc_values,
- get_oc_values,
- _XmbDefaultTextEscapement,
- _XmbDefaultTextExtents,
- _XmbDefaultTextPerCharExtents,
- _XmbDefaultDrawString,
- _XmbDefaultDrawImageString,
- _XwcDefaultTextEscapement,
- _XwcDefaultTextExtents,
- _XwcDefaultTextPerCharExtents,
- _XwcDefaultDrawString,
- _XwcDefaultDrawImageString
-};
-
-static XlcResource oc_resources[] = {
- { XNBaseFontName, NULLQUARK, sizeof(char *),
- XOffsetOf(XOCRec, core.base_name_list), XlcCreateMask | XlcGetMask },
- { XNOMAutomatic, NULLQUARK, sizeof(Bool),
- XOffsetOf(XOCRec, core.om_automatic), XlcGetMask },
- { XNMissingCharSet, NULLQUARK, sizeof(XOMCharSetList),
- XOffsetOf(XOCRec, core.missing_list), XlcGetMask },
- { XNDefaultString, NULLQUARK, sizeof(char *),
- XOffsetOf(XOCRec, core.default_string), XlcGetMask },
- { XNOrientation, NULLQUARK, sizeof(XOrientation),
- XOffsetOf(XOCRec, core.orientation), XlcSetMask | XlcGetMask },
- { XNResourceName, NULLQUARK, sizeof(char *),
- XOffsetOf(XOCRec, core.res_name), XlcSetMask | XlcGetMask },
- { XNResourceClass, NULLQUARK, sizeof(char *),
- XOffsetOf(XOCRec, core.res_class), XlcSetMask | XlcGetMask },
- { XNFontInfo, NULLQUARK, sizeof(XOMFontInfo),
- XOffsetOf(XOCRec, core.font_info), XlcGetMask }
-};
-
-static XOC
-create_oc(
- XOM om,
- XlcArgList args,
- int num_args)
-{
- XOC oc;
-
- oc = (XOC) Xmalloc(sizeof(XOCGenericRec));
- if (oc == NULL)
- return (XOC) NULL;
- bzero((char *) oc, sizeof(XOCGenericRec));
-
- oc->core.om = om;
-
- if (oc_resources[0].xrm_name == NULLQUARK)
- _XlcCompileResourceList(oc_resources, XlcNumber(oc_resources));
-
- if (_XlcSetValues((XPointer) oc, oc_resources, XlcNumber(oc_resources),
- args, num_args, XlcCreateMask | XlcDefaultMask))
- goto err;
-
- if (oc->core.base_name_list == NULL)
- goto err;
-
- oc->core.resources = oc_resources;
- oc->core.num_resources = XlcNumber(oc_resources);
-
- if (create_fontset(oc) == False)
- goto err;
-
- oc->methods = (XOCMethods)&oc_default_methods;
-
- return oc;
-
-err:
- destroy_oc(oc);
-
- return (XOC) NULL;
-}
-
-static Status
-close_om(
- XOM om)
-{
- XOMGenericPart *gen = XOM_GENERIC(om);
- OMData data;
- FontData font_data;
- int count;
-
- if ((data = gen->data)) {
- if (data->font_data) {
- for (font_data = data->font_data, count = data->font_data_count;
- count-- > 0 ; font_data++) {
- if (font_data->name)
- Xfree(font_data->name);
- }
- Xfree(data->font_data);
- }
- Xfree(gen->data);
- }
-
- if (om->core.res_name)
- Xfree(om->core.res_name);
- if (om->core.res_class)
- Xfree(om->core.res_class);
- if (om->core.required_charset.charset_list)
- XFreeStringList(om->core.required_charset.charset_list);
- else
- Xfree((char*)om->core.required_charset.charset_list);
- if (om->core.orientation_list.orientation)
- Xfree(om->core.orientation_list.orientation);
-
- Xfree(om);
-
- return 1;
-}
-
-static char *
-set_om_values(
- XOM om,
- XlcArgList args,
- int num_args)
-{
- if (om->core.resources == NULL)
- return NULL;
-
- return _XlcSetValues((XPointer) om, om->core.resources,
- om->core.num_resources, args, num_args, XlcSetMask);
-}
-
-static char *
-get_om_values(
- XOM om,
- XlcArgList args,
- int num_args)
-{
- if (om->core.resources == NULL)
- return NULL;
-
- return _XlcGetValues((XPointer) om, om->core.resources,
- om->core.num_resources, args, num_args, XlcGetMask);
-}
-
-static _Xconst XOMMethodsRec methods = {
- close_om,
- set_om_values,
- get_om_values,
- create_oc
-};
-
-static XlcResource om_resources[] = {
- { XNRequiredCharSet, NULLQUARK, sizeof(XOMCharSetList),
- XOffsetOf(XOMRec, core.required_charset), XlcGetMask },
- { XNQueryOrientation, NULLQUARK, sizeof(XOMOrientation),
- XOffsetOf(XOMRec, core.orientation_list), XlcGetMask },
- { XNDirectionalDependentDrawing, NULLQUARK, sizeof(Bool),
- XOffsetOf(XOMRec, core.directional_dependent), XlcGetMask },
- { XNContextualDrawing, NULLQUARK, sizeof(Bool),
- XOffsetOf(XOMRec, core.contextual_drawing), XlcGetMask }
-};
-
-static OMData
-add_data(
- XOM om)
-{
- XOMGenericPart *gen = XOM_GENERIC(om);
- OMData new;
-
- new = (OMData) Xmalloc(sizeof(OMDataRec));
-
- if (new == NULL)
- return NULL;
-
- gen->data = new;
-
- bzero((char *) new, sizeof(OMDataRec));
-
- return new;
-}
-
-static _Xconst char *supported_charset_list[] = {
- "ISO8859-1",
-/* fix for bug4332979 */
- "adobe-fontspecific",
-/* fix for bug4237353: "JISX0201.1976-0" entry should be removed from
- supported_charset_list because it is not a supported_charset for C locale
- "JISX0201.1976-0", */
- "SUNOLCURSOR-1",
- "SUNOLGLYPH-1"
-};
-
-static Bool
-init_om(
- XOM om)
-{
- XOMGenericPart *gen = XOM_GENERIC(om);
- OMData data;
- FontData font_data;
- char **required_list;
- XOrientation *orientation;
- char **value, buf[BUFSIZ], *bufptr;
- int count, length = 0;
-
- value = (char**)supported_charset_list;
- count = XlcNumber(supported_charset_list);
-
- data = add_data(om);
- if (data == NULL)
- return False;
-
- font_data = (FontData) Xmalloc(sizeof(FontDataRec) * count);
- if (font_data == NULL)
- return False;
- bzero((char *) font_data, sizeof(FontDataRec) * count);
- data->font_data = font_data;
- data->font_data_count = count;
-
- for ( ; count-- > 0; font_data++) {
-/*
-1266793
-This one is fine. *value points to one of the local strings in
-supported_charset_list[].
-*/
- strcpy(buf, *value++);
- font_data->name = (char *) Xmalloc(strlen(buf) + 1);
- if (font_data->name == NULL)
- return False;
- strcpy(font_data->name, buf);
- }
-
- length += strlen(data->font_data->name) + 1;
-
- /* required charset list */
- required_list = (char **) Xmalloc(sizeof(char *));
- if (required_list == NULL)
- return False;
-
- bufptr = (char *) Xmalloc(length);
- if (bufptr == NULL) {
- Xfree(required_list);
- return False;
- }
-
- om->core.required_charset.charset_list = required_list;
- om->core.required_charset.charset_count = 1; /* always 1 */
-
- data = gen->data;
-
- strcpy(bufptr, data->font_data->name);
- *required_list++ = bufptr;
- bufptr += strlen(bufptr) + 1;
-
- /* orientation list */
- orientation = (XOrientation *) Xmalloc(sizeof(XOrientation));
- if (orientation == NULL)
- return False;
-
- *orientation = XOMOrientation_LTR_TTB;
- om->core.orientation_list.orientation = orientation;
- om->core.orientation_list.num_orientation = 1;
-
- /* directional dependent drawing */
- om->core.directional_dependent = False;
-
- /* contexual drawing */
- om->core.contextual_drawing = False;
-
- /* context dependent */
- om->core.context_dependent = False;
-
- return True;
-}
-
-XOM
-_XDefaultOpenOM(XLCd lcd, Display *dpy, XrmDatabase rdb,
- _Xconst char *res_name, _Xconst char *res_class)
-{
- XOM om;
-
- om = (XOM) Xmalloc(sizeof(XOMGenericRec));
- if (om == NULL)
- return (XOM) NULL;
- bzero((char *) om, sizeof(XOMGenericRec));
-
- om->methods = (XOMMethods)&methods;
- om->core.lcd = lcd;
- om->core.display = dpy;
- om->core.rdb = rdb;
- if (res_name) {
- om->core.res_name = (char *)Xmalloc(strlen(res_name) + 1);
- if (om->core.res_name == NULL)
- goto err;
- strcpy(om->core.res_name, res_name);
- }
- if (res_class) {
- om->core.res_class = (char *)Xmalloc(strlen(res_class) + 1);
- if (om->core.res_class == NULL)
- goto err;
- strcpy(om->core.res_class, res_class);
- }
-
- if (om_resources[0].xrm_name == NULLQUARK)
- _XlcCompileResourceList(om_resources, XlcNumber(om_resources));
-
- om->core.resources = om_resources;
- om->core.num_resources = XlcNumber(om_resources);
-
- if (init_om(om) == False)
- goto err;
-
- return om;
-err:
- close_om(om);
-
- return (XOM) NULL;
-}
+/*
+Copyright 1985, 1986, 1987, 1991, 1998 The Open Group
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions: The above copyright notice and this
+permission notice shall be included in all copies or substantial
+portions of the Software.
+
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
+EVEN IF ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
+
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+
+X Window System is a trademark of The Open Group
+
+OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
+logo, LBX, X Window System, and Xinerama are trademarks of the Open
+Group. All other trademarks and registered trademarks mentioned herein
+are the property of their respective owners. No right, title or
+interest in or to any trademark, service mark, logo or trade name of
+Sun Microsystems, Inc. or its licensors is granted.
+
+*/
+/*
+ * Copyright 2000 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xlcint.h"
+#include "XlcPublic.h"
+#include <X11/Xos.h>
+#include <X11/Xatom.h>
+#include <stdio.h>
+#include <stdint.h>
+
+#define MAXFONTS 100
+
+#define XOM_GENERIC(om) (&((XOMGeneric) om)->gen)
+#define XOC_GENERIC(font_set) (&((XOCGeneric) font_set)->gen)
+
+#define DefineLocalBuf char local_buf[BUFSIZ]
+#define AllocLocalBuf(length) (length > BUFSIZ ? (char *)Xmalloc(length) : local_buf)
+#define FreeLocalBuf(ptr) if (ptr != local_buf) Xfree(ptr)
+
+typedef struct _FontDataRec {
+ char *name;
+} FontDataRec, *FontData;
+
+typedef struct _OMDataRec {
+ int font_data_count;
+ FontData font_data;
+} OMDataRec, *OMData;
+
+typedef struct _XOMGenericPart {
+ OMData data;
+} XOMGenericPart;
+
+typedef struct _XOMGenericRec {
+ XOMMethods methods;
+ XOMCoreRec core;
+ XOMGenericPart gen;
+} XOMGenericRec, *XOMGeneric;
+
+typedef struct _FontSetRec {
+ int id;
+ int font_data_count;
+ FontData font_data;
+ char *font_name;
+ XFontStruct *info;
+ XFontStruct *font;
+} FontSetRec, *FontSet;
+
+typedef struct _XOCGenericPart {
+ XlcConv wcs_to_cs;
+ FontSet font_set;
+} XOCGenericPart;
+
+typedef struct _XOCGenericRec {
+ XOCMethods methods;
+ XOCCoreRec core;
+ XOCGenericPart gen;
+} XOCGenericRec, *XOCGeneric;
+
+static Bool
+init_fontset(
+ XOC oc)
+{
+ XOCGenericPart *gen;
+ FontSet font_set;
+ OMData data;
+
+ data = XOM_GENERIC(oc->core.om)->data;
+
+ font_set = Xcalloc(1, sizeof(FontSetRec));
+ if (font_set == NULL)
+ return False;
+
+ gen = XOC_GENERIC(oc);
+ gen->font_set = font_set;
+
+ font_set->font_data_count = data->font_data_count;
+ font_set->font_data = data->font_data;
+
+ return True;
+}
+
+static char *
+get_prop_name(
+ Display *dpy,
+ XFontStruct *fs)
+{
+ unsigned long fp;
+
+ if (XGetFontProperty(fs, XA_FONT, &fp))
+ return XGetAtomName(dpy, fp);
+
+ return (char *) NULL;
+}
+
+static FontData
+check_charset(
+ FontSet font_set,
+ char *font_name)
+{
+ FontData font_data;
+ char *last;
+ int count;
+ ssize_t length, name_len;
+
+ name_len = strlen(font_name);
+ last = font_name + name_len;
+
+ count = font_set->font_data_count;
+ font_data = font_set->font_data;
+
+ for ( ; count-- > 0; font_data++) {
+ length = strlen(font_data->name);
+
+ if (length > name_len)
+ return(NULL);
+
+ if (_XlcCompareISOLatin1(last - length, font_data->name) == 0)
+ return font_data;
+ }
+ return (FontData) NULL;
+}
+
+#if 0 /* Unused */
+static int
+check_fontname(
+ XOC oc,
+ char *name)
+{
+ Display *dpy = oc->core.om->core.display;
+ XOCGenericPart *gen = XOC_GENERIC(oc);
+ FontData data;
+ FontSet font_set;
+ XFontStruct *fs_list;
+ char **fn_list, *fname, *prop_fname = NULL;
+ int list_num, i;
+ int list2_num;
+ char **fn2_list = NULL;
+ int found_num = 0;
+
+ fn_list = XListFonts(dpy, name, MAXFONTS, &list_num);
+ if (fn_list == NULL)
+ return found_num;
+
+ for (i = 0; i < list_num; i++) {
+ fname = fn_list[i];
+
+ font_set = gen->font_set;
+
+ if ((data = check_charset(font_set, fname)) == NULL) {
+ if ((fn2_list = XListFontsWithInfo(dpy, name, MAXFONTS,
+ &list2_num, &fs_list))
+ && (prop_fname = get_prop_name(dpy, fs_list))
+ && (data = check_charset(font_set, prop_fname)))
+ fname = prop_fname;
+ }
+ if (data) {
+ font_set->font_name = strdup(fname);
+ if (font_set->font_name) {
+ found_num++;
+ }
+ }
+ if (fn2_list) {
+ XFreeFontInfo(fn2_list, fs_list, list2_num);
+ fn2_list = NULL;
+ if (prop_fname) {
+ Xfree(prop_fname);
+ prop_fname = NULL;
+ }
+ }
+ if (found_num == 1)
+ break;
+ }
+ XFreeFontNames(fn_list);
+ return found_num;
+}
+#endif
+
+static Bool
+load_font(
+ XOC oc)
+{
+ Display *dpy = oc->core.om->core.display;
+ XOCGenericPart *gen = XOC_GENERIC(oc);
+ FontSet font_set = gen->font_set;
+
+ if (font_set->font_name == NULL)
+ return False;
+
+ if (font_set->font == NULL) {
+ font_set->font = XLoadQueryFont(dpy, font_set->font_name);
+ if (font_set->font == NULL)
+ return False;
+ }
+ return True;
+}
+
+#if 0
+static Bool
+load_font_info(
+ XOC oc)
+{
+ Display *dpy = oc->core.om->core.display;
+ XOCGenericPart *gen = XOC_GENERIC(oc);
+ FontSet font_set = gen->font_set;
+ char **fn_list;
+ int fn_num;
+
+ if (font_set->font_name == NULL)
+ return False;
+
+ if (font_set->info == NULL) {
+ fn_list = XListFontsWithInfo(dpy, font_set->font_name, 1, &fn_num,
+ &font_set->info);
+ if (font_set->info == NULL)
+ return False;
+ if (fn_num > 0)
+ font_set->info->fid = XLoadFont(dpy, font_set->font_name);
+
+ if (fn_list) XFreeFontNames(fn_list);
+ }
+ return True;
+}
+#endif
+
+static void
+set_fontset_extents(
+ XOC oc)
+{
+ XRectangle *ink = &oc->core.font_set_extents.max_ink_extent;
+ XRectangle *logical = &oc->core.font_set_extents.max_logical_extent;
+ XFontStruct **font_list, *font;
+ XCharStruct overall;
+ int logical_ascent, logical_descent;
+
+ font_list = oc->core.font_info.font_struct_list;
+ font = *font_list++;
+ overall = font->max_bounds;
+ overall.lbearing = font->min_bounds.lbearing;
+ logical_ascent = font->ascent;
+ logical_descent = font->descent;
+
+ ink->x = overall.lbearing;
+ ink->y = -(overall.ascent);
+ ink->width = overall.rbearing - overall.lbearing;
+ ink->height = overall.ascent + overall.descent;
+
+ logical->x = 0;
+ logical->y = -(logical_ascent);
+ logical->width = overall.width;
+ logical->height = logical_ascent + logical_descent;
+}
+
+static Bool
+init_core_part(
+ XOC oc)
+{
+ XOCGenericPart *gen = XOC_GENERIC(oc);
+ FontSet font_set;
+ XFontStruct **font_struct_list;
+ char **font_name_list, *font_name_buf;
+ int count, length;
+
+ font_set = gen->font_set;
+ count = length = 0;
+
+ if (font_set->font_name != NULL) {
+ length += strlen(font_set->font_name) + 1;
+ count++;
+ }
+ if (count == 0)
+ return False;
+
+ font_struct_list = (XFontStruct **) Xmalloc(sizeof(XFontStruct *));
+ if (font_struct_list == NULL)
+ return False;
+
+ font_name_list = (char **) Xmalloc(sizeof(char *));
+ if (font_name_list == NULL)
+ goto err;
+
+ font_name_buf = (char *) Xmalloc(length);
+ if (font_name_buf == NULL)
+ goto err;
+
+ oc->core.font_info.num_font = 1;
+ oc->core.font_info.font_name_list = font_name_list;
+ oc->core.font_info.font_struct_list = font_struct_list;
+
+ font_set = gen->font_set;
+
+ if (font_set->font_name != NULL) {
+ font_set->id = 1;
+ if (font_set->font)
+ *font_struct_list++ = font_set->font;
+ else
+ *font_struct_list++ = font_set->info;
+ strcpy(font_name_buf, font_set->font_name);
+ Xfree(font_set->font_name);
+ *font_name_list++ = font_set->font_name = font_name_buf;
+ font_name_buf += strlen(font_name_buf) + 1;
+ }
+
+ set_fontset_extents(oc);
+
+ return True;
+
+err:
+ if (font_name_list)
+ Xfree(font_name_list);
+ Xfree(font_struct_list);
+
+ return False;
+}
+
+static char *
+get_font_name(
+ XOC oc,
+ char *pattern)
+{
+ char **list, *name;
+ int count;
+ XFontStruct *fs;
+ Display *dpy = oc->core.om->core.display;
+
+ list = XListFonts(dpy, pattern, 1, &count);
+ if (list != NULL) {
+ name = strdup(*list);
+
+ XFreeFontNames(list);
+ } else {
+ fs = XLoadQueryFont(dpy, pattern);
+ if (fs == NULL) return NULL;
+
+ name = get_prop_name(dpy, fs);
+ XFreeFont(dpy, fs);
+ }
+ return name;
+}
+
+static int
+parse_fontname(
+ XOC oc)
+{
+ XOCGenericPart *gen = XOC_GENERIC(oc);
+ FontSet font_set;
+ FontData font_data;
+ char *pattern, *last, buf[BUFSIZ];
+ int font_data_count, found_num = 0;
+ ssize_t length;
+ int count, num_fields;
+ char *base_name, *font_name, **name_list, **cur_name_list;
+ char *charset_p = NULL;
+ Bool append_charset;
+ /*
+ append_charset flag should be set to True when the XLFD fontname
+ doesn't contain a chaset part.
+ */
+
+ name_list = _XParseBaseFontNameList(oc->core.base_name_list, &count);
+ if (name_list == NULL)
+ return -1;
+ cur_name_list = name_list;
+
+ while (count-- > 0) {
+ pattern = *cur_name_list++;
+ if (pattern == NULL || *pattern == '\0')
+ continue;
+
+ append_charset = False;
+
+ if (strchr(pattern, '*') == NULL &&
+ (font_name = get_font_name(oc, pattern))) {
+
+ font_set = gen->font_set;
+
+ font_data = check_charset(font_set, font_name);
+ if (font_data == NULL) {
+ Display *dpy = oc->core.om->core.display;
+ char **fn_list = NULL, *prop_fname = NULL;
+ int list_num;
+ XFontStruct *fs_list;
+ if ((fn_list = XListFontsWithInfo(dpy, font_name,
+ MAXFONTS,
+ &list_num, &fs_list))
+ && (prop_fname = get_prop_name(dpy, fs_list))
+ && (font_data = check_charset(font_set, prop_fname))) {
+ if (fn_list) {
+ XFreeFontInfo(fn_list, fs_list, list_num);
+ fn_list = NULL;
+ }
+ font_name = prop_fname;
+ }
+ }
+ if (font_data == NULL)
+ continue;
+
+ font_set->font_name = strdup(font_name);
+ Xfree(font_name);
+ if (font_set->font_name == NULL) {
+ goto err;
+ }
+ found_num++;
+ goto found;
+ }
+/*
+1266793
+Limit the length of the string copy to prevent stack corruption.
+ strcpy(buf, pattern);
+*/
+ strncpy(buf, pattern, BUFSIZ);
+ buf[BUFSIZ-1] = '\0';
+ length = strlen(buf);
+ last = buf + length - 1;
+
+ for (num_fields = 0, base_name = buf; *base_name != '\0'; base_name++)
+ if (*base_name == '-') num_fields++;
+ if (strchr(pattern, '*') == NULL) {
+ if (num_fields == 12) {
+ append_charset = True;
+ *++last = '-';
+ last++;
+ } else
+ continue;
+ } else {
+ if (num_fields == 13 || num_fields == 14) {
+ /*
+ * There are 14 fields in an XLFD name -- make certain the
+ * charset (& encoding) is placed in the correct field.
+ */
+ append_charset = True;
+ last = strrchr (buf, '-');
+ if (num_fields == 14) {
+ *last = '\0';
+ last = strrchr (buf, '-');
+ }
+ last++;
+ } else if (*last == '*') {
+ append_charset = True;
+ if (length > 3 && *(last-3) == '-' && *(last-2) == '*'
+ && *(last-1) == '-') {
+ last -= 2;
+ }
+ *++last = '-';
+ last++;
+ } else {
+ last = strrchr (buf, '-');
+ charset_p = last;
+ charset_p = strrchr (buf, '-');
+ while (*(--charset_p) != '-');
+ charset_p++;
+ }
+ }
+
+ font_set = gen->font_set;
+
+ font_data = font_set->font_data;
+ font_data_count = font_set->font_data_count;
+ for ( ; font_data_count-- > 0; font_data++) {
+ if (append_charset)
+ {
+/*
+1266793
+Limit the length of the string copy to prevent stack corruption.
+ strcpy(last, font_data->name);
+*/
+ strncpy(last, font_data->name, BUFSIZ - length);
+ buf[BUFSIZ-1] = '\0';
+ }
+ else {
+ if (_XlcCompareISOLatin1(charset_p,
+ font_data->name)) {
+ continue;
+ }
+ }
+ if ((font_set->font_name = get_font_name(oc, buf)))
+ break;
+ }
+ if (font_set->font_name != NULL) {
+ found_num++;
+ goto found;
+ }
+ }
+ found:
+ base_name = strdup(oc->core.base_name_list);
+ if (base_name == NULL)
+ goto err;
+
+ oc->core.base_name_list = base_name;
+
+ XFreeStringList(name_list);
+
+ return found_num;
+err:
+ XFreeStringList(name_list);
+
+ return -1;
+}
+
+static Bool
+set_missing_list(
+ XOC oc)
+{
+ XOCGenericPart *gen = XOC_GENERIC(oc);
+ FontSet font_set;
+ char **charset_list, *charset_buf;
+ int count, length;
+
+ font_set = gen->font_set;
+ count = length = 0;
+
+ if (!font_set->info && !font_set->font) {
+ length += strlen(font_set->font_data->name) + 1;
+ count++;
+ }
+
+ if (count == 0)
+ return True;
+
+ charset_list = (char **) Xmalloc(sizeof(char *));
+ if (charset_list == NULL)
+ return False;
+
+ charset_buf = (char *) Xmalloc(length);
+ if (charset_buf == NULL) {
+ Xfree(charset_list);
+ return False;
+ }
+
+ oc->core.missing_list.charset_list = charset_list;
+
+ font_set = gen->font_set;
+
+ if (!font_set->info && !font_set->font) {
+ strcpy(charset_buf, font_set->font_data->name);
+ *charset_list++ = charset_buf;
+ charset_buf += strlen(charset_buf) + 1;
+ }
+ return True;
+}
+
+static Bool
+create_fontset(
+ XOC oc)
+{
+ int found_num;
+
+ if (init_fontset(oc) == False)
+ return False;
+
+ found_num = parse_fontname(oc);
+ if (found_num <= 0) {
+ if (found_num == 0)
+ set_missing_list(oc);
+ return False;
+ }
+
+ if (load_font(oc) == False)
+ return False;
+
+ if (init_core_part(oc) == False)
+ return False;
+
+ if (set_missing_list(oc) == False)
+ return False;
+
+ return True;
+}
+
+static void
+destroy_oc(
+ XOC oc)
+{
+ Display *dpy = oc->core.om->core.display;
+ XOCGenericPart *gen = XOC_GENERIC(oc);
+ XFontStruct **font_list, *font;
+
+ if (gen->font_set)
+ Xfree(gen->font_set);
+
+ if (oc->core.base_name_list)
+ Xfree(oc->core.base_name_list);
+
+ if (oc->core.font_info.font_name_list)
+ XFreeStringList(oc->core.font_info.font_name_list);
+
+ if ((font_list = oc->core.font_info.font_struct_list)) {
+ if ((font = *font_list)) {
+ if (font->fid)
+ XFreeFont(dpy, font);
+ else
+ XFreeFontInfo(NULL, font, 1);
+ }
+ Xfree(oc->core.font_info.font_struct_list);
+ }
+
+ if (oc->core.missing_list.charset_list)
+ XFreeStringList(oc->core.missing_list.charset_list);
+
+#ifdef notdef
+ if (oc->core.res_name)
+ Xfree(oc->core.res_name);
+ if (oc->core.res_class)
+ Xfree(oc->core.res_class);
+#endif
+
+ Xfree(oc);
+}
+
+static char *
+set_oc_values(
+ XOC oc,
+ XlcArgList args,
+ int num_args)
+{
+ if (oc->core.resources == NULL)
+ return NULL;
+
+ return _XlcSetValues((XPointer) oc, oc->core.resources,
+ oc->core.num_resources, args, num_args, XlcSetMask);
+}
+
+static char *
+get_oc_values(
+ XOC oc,
+ XlcArgList args,
+ int num_args)
+{
+ if (oc->core.resources == NULL)
+ return NULL;
+
+ return _XlcGetValues((XPointer) oc, oc->core.resources,
+ oc->core.num_resources, args, num_args, XlcGetMask);
+}
+
+static Bool
+wcs_to_mbs(
+ XOC oc,
+ char *to,
+ _Xconst wchar_t *from,
+ int length)
+{
+ XlcConv conv = XOC_GENERIC(oc)->wcs_to_cs;
+ XLCd lcd;
+ int ret, to_left = length;
+
+ if (conv == NULL) {
+ lcd = oc->core.om->core.lcd;
+ conv = _XlcOpenConverter(lcd, XlcNWideChar, lcd, XlcNMultiByte);
+ if (conv == NULL)
+ return False;
+ XOC_GENERIC(oc)->wcs_to_cs = conv;
+ } else
+ _XlcResetConverter(conv);
+
+ ret = _XlcConvert(conv, (XPointer *) &from, &length, (XPointer *) &to,
+ &to_left, NULL, 0);
+ if (ret != 0 || length > 0)
+ return False;
+
+ return True;
+}
+
+static int
+_XmbDefaultTextEscapement(XOC oc, _Xconst char *text, int length)
+{
+ return XTextWidth(*oc->core.font_info.font_struct_list, text, length);
+}
+
+static int
+_XwcDefaultTextEscapement(XOC oc, _Xconst wchar_t *text, int length)
+{
+ DefineLocalBuf;
+ char *buf = AllocLocalBuf(length);
+ int ret = 0;
+
+ if (buf == NULL)
+ return 0;
+
+ if (wcs_to_mbs(oc, buf, text, length) == False)
+ goto err;
+
+ ret = _XmbDefaultTextEscapement(oc, buf, length);
+
+err:
+ FreeLocalBuf(buf);
+
+ return ret;
+}
+
+static int
+_XmbDefaultTextExtents(XOC oc, _Xconst char *text, int length,
+ XRectangle *overall_ink, XRectangle *overall_logical)
+{
+ int direction, logical_ascent, logical_descent;
+ XCharStruct overall;
+
+ XTextExtents(*oc->core.font_info.font_struct_list, text, length, &direction,
+ &logical_ascent, &logical_descent, &overall);
+
+ if (overall_ink) {
+ overall_ink->x = overall.lbearing;
+ overall_ink->y = -(overall.ascent);
+ overall_ink->width = overall.rbearing - overall.lbearing;
+ overall_ink->height = overall.ascent + overall.descent;
+ }
+
+ if (overall_logical) {
+ overall_logical->x = 0;
+ overall_logical->y = -(logical_ascent);
+ overall_logical->width = overall.width;
+ overall_logical->height = logical_ascent + logical_descent;
+ }
+
+ return overall.width;
+}
+
+static int
+_XwcDefaultTextExtents(XOC oc, _Xconst wchar_t *text, int length,
+ XRectangle *overall_ink, XRectangle *overall_logical)
+{
+ DefineLocalBuf;
+ char *buf = AllocLocalBuf(length);
+ int ret = 0;
+
+ if (buf == NULL)
+ return 0;
+
+ if (wcs_to_mbs(oc, buf, text, length) == False)
+ goto err;
+
+ ret = _XmbDefaultTextExtents(oc, buf, length, overall_ink, overall_logical);
+
+err:
+ FreeLocalBuf(buf);
+
+ return ret;
+}
+
+static Status
+_XmbDefaultTextPerCharExtents(XOC oc, _Xconst char *text, int length,
+ XRectangle *ink_buf, XRectangle *logical_buf,
+ int buf_size, int *num_chars,
+ XRectangle *overall_ink,
+ XRectangle *overall_logical)
+{
+ XFontStruct *font = *oc->core.font_info.font_struct_list;
+ XCharStruct *def, *cs, overall;
+ Bool first = True;
+
+ if (buf_size < length)
+ return 0;
+
+ bzero((char *) &overall, sizeof(XCharStruct));
+ *num_chars = 0;
+
+ CI_GET_DEFAULT_INFO_1D(font, def)
+
+ while (length-- > 0) {
+ CI_GET_CHAR_INFO_1D(font, *text, def, cs)
+ text++;
+ if (cs == NULL)
+ continue;
+
+ ink_buf->x = overall.width + cs->lbearing;
+ ink_buf->y = -(cs->ascent);
+ ink_buf->width = cs->rbearing - cs->lbearing;
+ ink_buf->height = cs->ascent + cs->descent;
+ ink_buf++;
+
+ logical_buf->x = overall.width;
+ logical_buf->y = -(font->ascent);
+ logical_buf->width = cs->width;
+ logical_buf->height = font->ascent + font->descent;
+ logical_buf++;
+
+ if (first) {
+ overall = *cs;
+ first = False;
+ } else {
+ overall.ascent = max(overall.ascent, cs->ascent);
+ overall.descent = max(overall.descent, cs->descent);
+ overall.lbearing = min(overall.lbearing, overall.width +
+ cs->lbearing);
+ overall.rbearing = max(overall.rbearing, overall.width +
+ cs->rbearing);
+ overall.width += cs->width;
+ }
+ (*num_chars)++;
+ }
+
+ if (overall_ink) {
+ overall_ink->x = overall.lbearing;
+ overall_ink->y = -(overall.ascent);
+ overall_ink->width = overall.rbearing - overall.lbearing;
+ overall_ink->height = overall.ascent + overall.descent;
+ }
+
+ if (overall_logical) {
+ overall_logical->x = 0;
+ overall_logical->y = -(font->ascent);
+ overall_logical->width = overall.width;
+ overall_logical->height = font->ascent + font->descent;
+ }
+
+ return 1;
+}
+
+static Status
+_XwcDefaultTextPerCharExtents(XOC oc, _Xconst wchar_t *text, int length,
+ XRectangle *ink_buf, XRectangle *logical_buf,
+ int buf_size, int *num_chars,
+ XRectangle *overall_ink,
+ XRectangle *overall_logical)
+{
+ DefineLocalBuf;
+ char *buf = AllocLocalBuf(length);
+ Status ret = 0;
+
+ if (buf == NULL)
+ return 0;
+
+ if (wcs_to_mbs(oc, buf, text, length) == False)
+ goto err;
+
+ ret = _XmbDefaultTextPerCharExtents(oc, buf, length, ink_buf, logical_buf,
+ buf_size, num_chars, overall_ink,
+ overall_logical);
+
+err:
+ FreeLocalBuf(buf);
+
+ return ret;
+}
+
+static int
+_XmbDefaultDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
+ _Xconst char *text, int length)
+{
+ XFontStruct *font = *oc->core.font_info.font_struct_list;
+
+ XSetFont(dpy, gc, font->fid);
+ XDrawString(dpy, d, gc, x, y, text, length);
+
+ return XTextWidth(font, text, length);
+}
+
+static int
+_XwcDefaultDrawString(Display *dpy, Drawable d, XOC oc, GC gc, int x, int y,
+ _Xconst wchar_t *text, int length)
+{
+ DefineLocalBuf;
+ char *buf = AllocLocalBuf(length);
+ int ret = 0;
+
+ if (buf == NULL)
+ return 0;
+
+ if (wcs_to_mbs(oc, buf, text, length) == False)
+ goto err;
+
+ ret = _XmbDefaultDrawString(dpy, d, oc, gc, x, y, buf, length);
+
+err:
+ FreeLocalBuf(buf);
+
+ return ret;
+}
+
+static void
+_XmbDefaultDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
+ int y, _Xconst char *text, int length)
+{
+ XSetFont(dpy, gc, (*oc->core.font_info.font_struct_list)->fid);
+ XDrawImageString(dpy, d, gc, x, y, text, length);
+}
+
+static void
+_XwcDefaultDrawImageString(Display *dpy, Drawable d, XOC oc, GC gc, int x,
+ int y, _Xconst wchar_t *text, int length)
+{
+ DefineLocalBuf;
+ char *buf = AllocLocalBuf(length);
+
+ if (buf == NULL)
+ return;
+
+ if (wcs_to_mbs(oc, buf, text, length) == False)
+ goto err;
+
+ _XmbDefaultDrawImageString(dpy, d, oc, gc, x, y, buf, length);
+
+err:
+ FreeLocalBuf(buf);
+}
+
+static _Xconst XOCMethodsRec oc_default_methods = {
+ destroy_oc,
+ set_oc_values,
+ get_oc_values,
+ _XmbDefaultTextEscapement,
+ _XmbDefaultTextExtents,
+ _XmbDefaultTextPerCharExtents,
+ _XmbDefaultDrawString,
+ _XmbDefaultDrawImageString,
+ _XwcDefaultTextEscapement,
+ _XwcDefaultTextExtents,
+ _XwcDefaultTextPerCharExtents,
+ _XwcDefaultDrawString,
+ _XwcDefaultDrawImageString
+};
+
+static XlcResource oc_resources[] = {
+ { XNBaseFontName, NULLQUARK, sizeof(char *),
+ XOffsetOf(XOCRec, core.base_name_list), XlcCreateMask | XlcGetMask },
+ { XNOMAutomatic, NULLQUARK, sizeof(Bool),
+ XOffsetOf(XOCRec, core.om_automatic), XlcGetMask },
+ { XNMissingCharSet, NULLQUARK, sizeof(XOMCharSetList),
+ XOffsetOf(XOCRec, core.missing_list), XlcGetMask },
+ { XNDefaultString, NULLQUARK, sizeof(char *),
+ XOffsetOf(XOCRec, core.default_string), XlcGetMask },
+ { XNOrientation, NULLQUARK, sizeof(XOrientation),
+ XOffsetOf(XOCRec, core.orientation), XlcSetMask | XlcGetMask },
+ { XNResourceName, NULLQUARK, sizeof(char *),
+ XOffsetOf(XOCRec, core.res_name), XlcSetMask | XlcGetMask },
+ { XNResourceClass, NULLQUARK, sizeof(char *),
+ XOffsetOf(XOCRec, core.res_class), XlcSetMask | XlcGetMask },
+ { XNFontInfo, NULLQUARK, sizeof(XOMFontInfo),
+ XOffsetOf(XOCRec, core.font_info), XlcGetMask }
+};
+
+static XOC
+create_oc(
+ XOM om,
+ XlcArgList args,
+ int num_args)
+{
+ XOC oc;
+
+ oc = Xcalloc(1, sizeof(XOCGenericRec));
+ if (oc == NULL)
+ return (XOC) NULL;
+
+ oc->core.om = om;
+
+ if (oc_resources[0].xrm_name == NULLQUARK)
+ _XlcCompileResourceList(oc_resources, XlcNumber(oc_resources));
+
+ if (_XlcSetValues((XPointer) oc, oc_resources, XlcNumber(oc_resources),
+ args, num_args, XlcCreateMask | XlcDefaultMask))
+ goto err;
+
+ if (oc->core.base_name_list == NULL)
+ goto err;
+
+ oc->core.resources = oc_resources;
+ oc->core.num_resources = XlcNumber(oc_resources);
+
+ if (create_fontset(oc) == False)
+ goto err;
+
+ oc->methods = (XOCMethods)&oc_default_methods;
+
+ return oc;
+
+err:
+ destroy_oc(oc);
+
+ return (XOC) NULL;
+}
+
+static Status
+close_om(
+ XOM om)
+{
+ XOMGenericPart *gen = XOM_GENERIC(om);
+ OMData data;
+ FontData font_data;
+ int count;
+
+ if ((data = gen->data)) {
+ if (data->font_data) {
+ for (font_data = data->font_data, count = data->font_data_count;
+ count-- > 0 ; font_data++) {
+ if (font_data->name)
+ Xfree(font_data->name);
+ }
+ Xfree(data->font_data);
+ }
+ Xfree(gen->data);
+ }
+
+ if (om->core.res_name)
+ Xfree(om->core.res_name);
+ if (om->core.res_class)
+ Xfree(om->core.res_class);
+ if (om->core.required_charset.charset_list)
+ XFreeStringList(om->core.required_charset.charset_list);
+ else
+ Xfree((char*)om->core.required_charset.charset_list);
+ if (om->core.orientation_list.orientation)
+ Xfree(om->core.orientation_list.orientation);
+
+ Xfree(om);
+
+ return 1;
+}
+
+static char *
+set_om_values(
+ XOM om,
+ XlcArgList args,
+ int num_args)
+{
+ if (om->core.resources == NULL)
+ return NULL;
+
+ return _XlcSetValues((XPointer) om, om->core.resources,
+ om->core.num_resources, args, num_args, XlcSetMask);
+}
+
+static char *
+get_om_values(
+ XOM om,
+ XlcArgList args,
+ int num_args)
+{
+ if (om->core.resources == NULL)
+ return NULL;
+
+ return _XlcGetValues((XPointer) om, om->core.resources,
+ om->core.num_resources, args, num_args, XlcGetMask);
+}
+
+static _Xconst XOMMethodsRec methods = {
+ close_om,
+ set_om_values,
+ get_om_values,
+ create_oc
+};
+
+static XlcResource om_resources[] = {
+ { XNRequiredCharSet, NULLQUARK, sizeof(XOMCharSetList),
+ XOffsetOf(XOMRec, core.required_charset), XlcGetMask },
+ { XNQueryOrientation, NULLQUARK, sizeof(XOMOrientation),
+ XOffsetOf(XOMRec, core.orientation_list), XlcGetMask },
+ { XNDirectionalDependentDrawing, NULLQUARK, sizeof(Bool),
+ XOffsetOf(XOMRec, core.directional_dependent), XlcGetMask },
+ { XNContextualDrawing, NULLQUARK, sizeof(Bool),
+ XOffsetOf(XOMRec, core.contextual_drawing), XlcGetMask }
+};
+
+static OMData
+add_data(
+ XOM om)
+{
+ XOMGenericPart *gen = XOM_GENERIC(om);
+ OMData new;
+
+ new = Xcalloc(1, sizeof(OMDataRec));
+
+ if (new == NULL)
+ return NULL;
+
+ gen->data = new;
+
+ return new;
+}
+
+static _Xconst char *supported_charset_list[] = {
+ "ISO8859-1",
+/* fix for bug4332979 */
+ "adobe-fontspecific",
+/* fix for bug4237353: "JISX0201.1976-0" entry should be removed from
+ supported_charset_list because it is not a supported_charset for C locale
+ "JISX0201.1976-0", */
+ "SUNOLCURSOR-1",
+ "SUNOLGLYPH-1"
+};
+
+static Bool
+init_om(
+ XOM om)
+{
+ XOMGenericPart *gen = XOM_GENERIC(om);
+ OMData data;
+ FontData font_data;
+ char **required_list;
+ XOrientation *orientation;
+ char **value, buf[BUFSIZ], *bufptr;
+ int count, length = 0;
+
+ value = (char**)supported_charset_list;
+ count = XlcNumber(supported_charset_list);
+
+ data = add_data(om);
+ if (data == NULL)
+ return False;
+
+ font_data = Xcalloc(count, sizeof(FontDataRec));
+ if (font_data == NULL)
+ return False;
+ data->font_data = font_data;
+ data->font_data_count = count;
+
+ for ( ; count-- > 0; font_data++) {
+/*
+1266793
+This one is fine. *value points to one of the local strings in
+supported_charset_list[].
+*/
+ strcpy(buf, *value++);
+ font_data->name = strdup(buf);
+ if (font_data->name == NULL)
+ return False;
+ }
+
+ length += strlen(data->font_data->name) + 1;
+
+ /* required charset list */
+ required_list = (char **) Xmalloc(sizeof(char *));
+ if (required_list == NULL)
+ return False;
+
+ bufptr = (char *) Xmalloc(length);
+ if (bufptr == NULL) {
+ Xfree(required_list);
+ return False;
+ }
+
+ om->core.required_charset.charset_list = required_list;
+ om->core.required_charset.charset_count = 1; /* always 1 */
+
+ data = gen->data;
+
+ strcpy(bufptr, data->font_data->name);
+ *required_list++ = bufptr;
+ bufptr += strlen(bufptr) + 1;
+
+ /* orientation list */
+ orientation = (XOrientation *) Xmalloc(sizeof(XOrientation));
+ if (orientation == NULL)
+ return False;
+
+ *orientation = XOMOrientation_LTR_TTB;
+ om->core.orientation_list.orientation = orientation;
+ om->core.orientation_list.num_orientation = 1;
+
+ /* directional dependent drawing */
+ om->core.directional_dependent = False;
+
+ /* contexual drawing */
+ om->core.contextual_drawing = False;
+
+ /* context dependent */
+ om->core.context_dependent = False;
+
+ return True;
+}
+
+XOM
+_XDefaultOpenOM(XLCd lcd, Display *dpy, XrmDatabase rdb,
+ _Xconst char *res_name, _Xconst char *res_class)
+{
+ XOM om;
+
+ om = Xcalloc(1, sizeof(XOMGenericRec));
+ if (om == NULL)
+ return (XOM) NULL;
+
+ om->methods = (XOMMethods)&methods;
+ om->core.lcd = lcd;
+ om->core.display = dpy;
+ om->core.rdb = rdb;
+ if (res_name) {
+ om->core.res_name = strdup(res_name);
+ if (om->core.res_name == NULL)
+ goto err;
+ }
+ if (res_class) {
+ om->core.res_class = strdup(res_class);
+ if (om->core.res_class == NULL)
+ goto err;
+ }
+
+ if (om_resources[0].xrm_name == NULLQUARK)
+ _XlcCompileResourceList(om_resources, XlcNumber(om_resources));
+
+ om->core.resources = om_resources;
+ om->core.num_resources = XlcNumber(om_resources);
+
+ if (init_om(om) == False)
+ goto err;
+
+ return om;
+err:
+ close_om(om);
+
+ return (XOM) NULL;
+}
diff --git a/libX11/src/xlibi18n/XlcDL.c b/libX11/src/xlibi18n/XlcDL.c
index 58e9ade87..4a05c40e4 100644
--- a/libX11/src/xlibi18n/XlcDL.c
+++ b/libX11/src/xlibi18n/XlcDL.c
@@ -86,16 +86,6 @@ Sun Microsystems, Inc. or its licensors is granted.
#include "XlcPublic.h"
#include "XlcPubI.h"
-#if defined(_LP64) && defined(__sparcv9)
-# define _MACH64_NAME "sparcv9"
-#else
-# undef _MACH64_NAME
-#endif /* defined(_LP64) && defined(__sparcv9) */
-
-#ifdef _MACH64_NAME
-# define _MACH64_NAME_LEN (sizeof (_MACH64_NAME) - 1)
-#endif
-
#define XI18N_DLREL 2
#define iscomment(ch) ((ch) == '\0' || (ch) == '#')
@@ -269,35 +259,6 @@ __lc_path(const char *dl_name, const char *lc_dir)
if (strstr (dl_name, "../"))
return NULL;
-#if defined (_LP64) && defined (_MACH64_NAME)
- len = (lc_dir ? strlen(lc_dir) : 0 ) +
- (dl_name ? strlen(dl_name) : 0) + _MACH64_NAME_LEN + 10;
- path = Xmalloc(len + 1);
-
- if (strchr(dl_name, '/') != NULL) {
- char *tmp = strdup(dl_name);
- char *dl_dir, *dl_file;
- char *slash_p;
- slash_p = strchr(tmp, '/');
- *slash_p = '\0';
- dl_dir = tmp;
- dl_file = ++slash_p;
-
- slash_p = strrchr(lc_dir, '/');
- *slash_p = '\0';
- strcpy(path, lc_dir); strcat(path, "/");
- strcat(path, dl_dir); strcat(path, "/");
- strcat(path, _MACH64_NAME); strcat(path, "/");
- strcat(path, dl_file); strcat(path, ".so.2");
-
- *slash_p = '/';
- Xfree(tmp);
- } else {
- strcpy(path, lc_dir); strcat(path, "/");
- strcat(path, _MACH64_NAME); strcat(path, "/");
- strcat(path, dl_name); strcat(path, ".so.2");
- }
-#else
len = (lc_dir ? strlen(lc_dir) : 0 ) +
(dl_name ? strlen(dl_name) : 0) + 10;
#if defined POSTLOCALELIBDIR
@@ -322,7 +283,6 @@ __lc_path(const char *dl_name, const char *lc_dir)
#endif
strcat(path, dl_name); strcat(path, ".so.2");
}
-#endif
return path;
}
diff --git a/libX11/src/xlibi18n/lcCharSet.c b/libX11/src/xlibi18n/lcCharSet.c
index 0fa39d869..6be5f5d16 100644
--- a/libX11/src/xlibi18n/lcCharSet.c
+++ b/libX11/src/xlibi18n/lcCharSet.c
@@ -1,226 +1,225 @@
-/*
- * Copyright 1992, 1993 by TOSHIBA Corp.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of TOSHIBA not be used in advertising
- * or publicity pertaining to distribution of the software without specific,
- * written prior permission. TOSHIBA make no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
- * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- *
- * Author: Katsuhisa Yano TOSHIBA Corp.
- * mopi@osa.ilab.toshiba.co.jp
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include "Xlibint.h"
-#include "XlcPublic.h"
-#include "XlcPubI.h"
-
-/* The list of all known XlcCharSets. They are identified by their name. */
-
-typedef struct _XlcCharSetListRec {
- XlcCharSet charset;
- struct _XlcCharSetListRec *next;
-} XlcCharSetListRec, *XlcCharSetList;
-
-static XlcCharSetList charset_list = NULL;
-
-/* Returns the charset with the given name (including side suffix).
- Returns NULL if not found. */
-XlcCharSet
-_XlcGetCharSet(
- const char *name)
-{
- XlcCharSetList list;
- XrmQuark xrm_name;
-
- xrm_name = XrmStringToQuark(name);
-
- for (list = charset_list; list; list = list->next) {
- if (xrm_name == list->charset->xrm_name)
- return (XlcCharSet) list->charset;
- }
-
- return (XlcCharSet) NULL;
-}
-
-/* Returns the charset with the given encoding (no side suffix) and
- responsible for at least the given side (XlcGL or XlcGR).
- Returns NULL if not found. */
-XlcCharSet
-_XlcGetCharSetWithSide(
- const char *encoding_name,
- XlcSide side)
-{
- XlcCharSetList list;
- XrmQuark xrm_encoding_name;
-
- xrm_encoding_name = XrmStringToQuark(encoding_name);
-
- for (list = charset_list; list; list = list->next) {
- if (list->charset->xrm_encoding_name == xrm_encoding_name
- && (list->charset->side == XlcGLGR || list->charset->side == side))
- return (XlcCharSet) list->charset;
- }
-
- return (XlcCharSet) NULL;
-}
-
-/* Registers an XlcCharSet in the list of character sets.
- Returns True if successful. */
-Bool
-_XlcAddCharSet(
- XlcCharSet charset)
-{
- XlcCharSetList list;
-
- if (_XlcGetCharSet(charset->name))
- return False;
-
- list = (XlcCharSetList) Xmalloc(sizeof(XlcCharSetListRec));
- if (list == NULL)
- return False;
-
- list->charset = charset;
- list->next = charset_list;
- charset_list = list;
-
- return True;
-}
-
-/* List of resources for XlcCharSet. */
-static XlcResource resources[] = {
- { XlcNName, NULLQUARK, sizeof(char *),
- XOffsetOf(XlcCharSetRec, name), XlcGetMask },
- { XlcNEncodingName, NULLQUARK, sizeof(char *),
- XOffsetOf(XlcCharSetRec, encoding_name), XlcGetMask },
- { XlcNSide, NULLQUARK, sizeof(XlcSide),
- XOffsetOf(XlcCharSetRec, side), XlcGetMask },
- { XlcNCharSize, NULLQUARK, sizeof(int),
- XOffsetOf(XlcCharSetRec, char_size), XlcGetMask },
- { XlcNSetSize, NULLQUARK, sizeof(int),
- XOffsetOf(XlcCharSetRec, set_size), XlcGetMask },
- { XlcNControlSequence, NULLQUARK, sizeof(char *),
- XOffsetOf(XlcCharSetRec, ct_sequence), XlcGetMask }
-};
-
-/* Retrieves a number of attributes of an XlcCharSet.
- Return NULL if successful, otherwise the name of the first argument
- specifiying a nonexistent attribute. */
-static char *
-get_values(
- XlcCharSet charset,
- XlcArgList args,
- int num_args)
-{
- if (resources[0].xrm_name == NULLQUARK)
- _XlcCompileResourceList(resources, XlcNumber(resources));
-
- return _XlcGetValues((XPointer) charset, resources, XlcNumber(resources),
- args, num_args, XlcGetMask);
-}
-
-/* Retrieves a number of attributes of an XlcCharSet.
- Return NULL if successful, otherwise the name of the first argument
- specifiying a nonexistent attribute. */
-char *
-_XlcGetCSValues(XlcCharSet charset, ...)
-{
- va_list var;
- XlcArgList args;
- char *ret;
- int num_args;
-
- va_start(var, charset);
- _XlcCountVaList(var, &num_args);
- va_end(var);
-
- va_start(var, charset);
- _XlcVaToArgList(var, num_args, &args);
- va_end(var);
-
- if (args == (XlcArgList) NULL)
- return (char *) NULL;
-
- ret = get_values(charset, args, num_args);
-
- Xfree(args);
-
- return ret;
-}
-
-/* Creates a new XlcCharSet, given its name (including side suffix) and
- Compound Text ESC sequence (normally at most 4 bytes). */
-XlcCharSet
-_XlcCreateDefaultCharSet(
- const char *name,
- const char *ct_sequence)
-{
- XlcCharSet charset;
- int name_len, ct_sequence_len;
- const char *colon;
- char *tmp;
-
- charset = (XlcCharSet) Xmalloc(sizeof(XlcCharSetRec));
- if (charset == NULL)
- return (XlcCharSet) NULL;
- bzero((char *) charset, sizeof(XlcCharSetRec));
-
- name_len = strlen(name);
- ct_sequence_len = strlen(ct_sequence);
-
- /* Fill in name and xrm_name. */
- tmp = (char *) Xmalloc(name_len + 1 + ct_sequence_len + 1);
- if (tmp == NULL) {
- Xfree((char *) charset);
- return (XlcCharSet) NULL;
- }
- memcpy(tmp, name, name_len+1);
- charset->name = tmp;
- charset->xrm_name = XrmStringToQuark(charset->name);
-
- /* Fill in encoding_name and xrm_encoding_name. */
- if ((colon = strchr(charset->name, ':')) != NULL) {
- unsigned int length = colon - charset->name;
- char *encoding_tmp = (char *) Xmalloc(length + 1);
- if (encoding_tmp == NULL) {
- Xfree((char *) charset->name);
- Xfree((char *) charset);
- return (XlcCharSet) NULL;
- }
- memcpy(encoding_tmp, charset->name, length);
- encoding_tmp[length] = '\0';
- charset->encoding_name = encoding_tmp;
- charset->xrm_encoding_name = XrmStringToQuark(charset->encoding_name);
- } else {
- charset->encoding_name = charset->name;
- charset->xrm_encoding_name = charset->xrm_name;
- }
-
- /* Fill in ct_sequence. */
- tmp += name_len + 1;
- memcpy(tmp, ct_sequence, ct_sequence_len+1);
- charset->ct_sequence = tmp;
-
- /* Fill in side, char_size, set_size. */
- if (!_XlcParseCharSet(charset))
- /* If ct_sequence is not usable in Compound Text, remove it. */
- charset->ct_sequence = "";
-
- return (XlcCharSet) charset;
-}
+/*
+ * Copyright 1992, 1993 by TOSHIBA Corp.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of TOSHIBA not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission. TOSHIBA make no representations about the
+ * suitability of this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+ * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Author: Katsuhisa Yano TOSHIBA Corp.
+ * mopi@osa.ilab.toshiba.co.jp
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include "Xlibint.h"
+#include "XlcPublic.h"
+#include "XlcPubI.h"
+
+/* The list of all known XlcCharSets. They are identified by their name. */
+
+typedef struct _XlcCharSetListRec {
+ XlcCharSet charset;
+ struct _XlcCharSetListRec *next;
+} XlcCharSetListRec, *XlcCharSetList;
+
+static XlcCharSetList charset_list = NULL;
+
+/* Returns the charset with the given name (including side suffix).
+ Returns NULL if not found. */
+XlcCharSet
+_XlcGetCharSet(
+ const char *name)
+{
+ XlcCharSetList list;
+ XrmQuark xrm_name;
+
+ xrm_name = XrmStringToQuark(name);
+
+ for (list = charset_list; list; list = list->next) {
+ if (xrm_name == list->charset->xrm_name)
+ return (XlcCharSet) list->charset;
+ }
+
+ return (XlcCharSet) NULL;
+}
+
+/* Returns the charset with the given encoding (no side suffix) and
+ responsible for at least the given side (XlcGL or XlcGR).
+ Returns NULL if not found. */
+XlcCharSet
+_XlcGetCharSetWithSide(
+ const char *encoding_name,
+ XlcSide side)
+{
+ XlcCharSetList list;
+ XrmQuark xrm_encoding_name;
+
+ xrm_encoding_name = XrmStringToQuark(encoding_name);
+
+ for (list = charset_list; list; list = list->next) {
+ if (list->charset->xrm_encoding_name == xrm_encoding_name
+ && (list->charset->side == XlcGLGR || list->charset->side == side))
+ return (XlcCharSet) list->charset;
+ }
+
+ return (XlcCharSet) NULL;
+}
+
+/* Registers an XlcCharSet in the list of character sets.
+ Returns True if successful. */
+Bool
+_XlcAddCharSet(
+ XlcCharSet charset)
+{
+ XlcCharSetList list;
+
+ if (_XlcGetCharSet(charset->name))
+ return False;
+
+ list = (XlcCharSetList) Xmalloc(sizeof(XlcCharSetListRec));
+ if (list == NULL)
+ return False;
+
+ list->charset = charset;
+ list->next = charset_list;
+ charset_list = list;
+
+ return True;
+}
+
+/* List of resources for XlcCharSet. */
+static XlcResource resources[] = {
+ { XlcNName, NULLQUARK, sizeof(char *),
+ XOffsetOf(XlcCharSetRec, name), XlcGetMask },
+ { XlcNEncodingName, NULLQUARK, sizeof(char *),
+ XOffsetOf(XlcCharSetRec, encoding_name), XlcGetMask },
+ { XlcNSide, NULLQUARK, sizeof(XlcSide),
+ XOffsetOf(XlcCharSetRec, side), XlcGetMask },
+ { XlcNCharSize, NULLQUARK, sizeof(int),
+ XOffsetOf(XlcCharSetRec, char_size), XlcGetMask },
+ { XlcNSetSize, NULLQUARK, sizeof(int),
+ XOffsetOf(XlcCharSetRec, set_size), XlcGetMask },
+ { XlcNControlSequence, NULLQUARK, sizeof(char *),
+ XOffsetOf(XlcCharSetRec, ct_sequence), XlcGetMask }
+};
+
+/* Retrieves a number of attributes of an XlcCharSet.
+ Return NULL if successful, otherwise the name of the first argument
+ specifiying a nonexistent attribute. */
+static char *
+get_values(
+ XlcCharSet charset,
+ XlcArgList args,
+ int num_args)
+{
+ if (resources[0].xrm_name == NULLQUARK)
+ _XlcCompileResourceList(resources, XlcNumber(resources));
+
+ return _XlcGetValues((XPointer) charset, resources, XlcNumber(resources),
+ args, num_args, XlcGetMask);
+}
+
+/* Retrieves a number of attributes of an XlcCharSet.
+ Return NULL if successful, otherwise the name of the first argument
+ specifiying a nonexistent attribute. */
+char *
+_XlcGetCSValues(XlcCharSet charset, ...)
+{
+ va_list var;
+ XlcArgList args;
+ char *ret;
+ int num_args;
+
+ va_start(var, charset);
+ _XlcCountVaList(var, &num_args);
+ va_end(var);
+
+ va_start(var, charset);
+ _XlcVaToArgList(var, num_args, &args);
+ va_end(var);
+
+ if (args == (XlcArgList) NULL)
+ return (char *) NULL;
+
+ ret = get_values(charset, args, num_args);
+
+ Xfree(args);
+
+ return ret;
+}
+
+/* Creates a new XlcCharSet, given its name (including side suffix) and
+ Compound Text ESC sequence (normally at most 4 bytes). */
+XlcCharSet
+_XlcCreateDefaultCharSet(
+ const char *name,
+ const char *ct_sequence)
+{
+ XlcCharSet charset;
+ int name_len, ct_sequence_len;
+ const char *colon;
+ char *tmp;
+
+ charset = Xcalloc(1, sizeof(XlcCharSetRec));
+ if (charset == NULL)
+ return (XlcCharSet) NULL;
+
+ name_len = strlen(name);
+ ct_sequence_len = strlen(ct_sequence);
+
+ /* Fill in name and xrm_name. */
+ tmp = (char *) Xmalloc(name_len + 1 + ct_sequence_len + 1);
+ if (tmp == NULL) {
+ Xfree((char *) charset);
+ return (XlcCharSet) NULL;
+ }
+ memcpy(tmp, name, name_len+1);
+ charset->name = tmp;
+ charset->xrm_name = XrmStringToQuark(charset->name);
+
+ /* Fill in encoding_name and xrm_encoding_name. */
+ if ((colon = strchr(charset->name, ':')) != NULL) {
+ unsigned int length = colon - charset->name;
+ char *encoding_tmp = (char *) Xmalloc(length + 1);
+ if (encoding_tmp == NULL) {
+ Xfree((char *) charset->name);
+ Xfree((char *) charset);
+ return (XlcCharSet) NULL;
+ }
+ memcpy(encoding_tmp, charset->name, length);
+ encoding_tmp[length] = '\0';
+ charset->encoding_name = encoding_tmp;
+ charset->xrm_encoding_name = XrmStringToQuark(charset->encoding_name);
+ } else {
+ charset->encoding_name = charset->name;
+ charset->xrm_encoding_name = charset->xrm_name;
+ }
+
+ /* Fill in ct_sequence. */
+ tmp += name_len + 1;
+ memcpy(tmp, ct_sequence, ct_sequence_len+1);
+ charset->ct_sequence = tmp;
+
+ /* Fill in side, char_size, set_size. */
+ if (!_XlcParseCharSet(charset))
+ /* If ct_sequence is not usable in Compound Text, remove it. */
+ charset->ct_sequence = "";
+
+ return (XlcCharSet) charset;
+}
diff --git a/libX11/src/xlibi18n/lcDB.c b/libX11/src/xlibi18n/lcDB.c
index 4a25ae69d..79df2450c 100644
--- a/libX11/src/xlibi18n/lcDB.c
+++ b/libX11/src/xlibi18n/lcDB.c
@@ -1,1347 +1,1341 @@
-/*
- *
- * Copyright IBM Corporation 1993
- *
- * All Rights Reserved
- *
- * License to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appear in all copies and that
- * both that copyright notice and this permission notice appear in
- * supporting documentation, and that the name of IBM not be
- * used in advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- *
- * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- * ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS, AND
- * NONINFRINGEMENT OF THIRD PARTY RIGHTS, IN NO EVENT SHALL
- * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- *
-*/
-/*
- * (c) Copyright 1995 FUJITSU LIMITED
- * This is source code modified by FUJITSU LIMITED under the Joint
- * Development Agreement for the CDE/Motif PST.
- */
-
-
-
-#ifndef NOT_X_ENV
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/Xlib.h>
-#include <X11/Xresource.h>
-#include "Xlibint.h"
-#include "XlcPubI.h"
-
-#else /* NOT_X_ENV */
-
-#define Xmalloc malloc
-#define Xrealloc realloc
-#define Xfree free
-
-#endif /* NOT_X_ENV */
-
-#include <stdint.h>
-
-/* specifying NOT_X_ENV allows users to just use
- the database parsing routine. */
-/* For UDC/VW */
-#ifndef BUFSIZE
-#define BUFSIZE 2048
-#endif
-
-#ifdef COMMENT
-#ifdef BUFSIZE
-#undef BUFSIZE
-#endif
-#define BUFSIZE 6144 /* 2048*3 */
-#endif
-
-#include <stdio.h>
-
-typedef struct _DatabaseRec {
- char *category;
- char *name;
- char **value;
- int value_num;
- struct _DatabaseRec *next;
-} DatabaseRec, *Database;
-
-typedef enum {
- S_NULL, /* outside category */
- S_CATEGORY, /* inside category */
- S_NAME, /* has name, expecting values */
- S_VALUE
-} ParseState;
-
-typedef enum {
- T_NEWLINE,
- T_COMMENT,
- T_SEMICOLON,
- T_DOUBLE_QUOTE,
- T_LEFT_BRACE,
- T_RIGHT_BRACE,
- T_SPACE,
- T_TAB,
- T_BACKSLASH,
- T_NUMERIC_HEX,
- T_NUMERIC_DEC,
- T_NUMERIC_OCT,
- T_DEFAULT
-} Token;
-
-typedef struct {
- Token token; /* token id */
- int len; /* length of token sequence */
-} TokenTable;
-
-static int f_newline (const char *str, Token token, Database *db);
-static int f_comment (const char *str, Token token, Database *db);
-static int f_semicolon (const char *str, Token token, Database *db);
-static int f_double_quote (const char *str, Token token, Database *db);
-static int f_left_brace (const char *str, Token token, Database *db);
-static int f_right_brace (const char *str, Token token, Database *db);
-static int f_white (const char *str, Token token, Database *db);
-static int f_backslash (const char *str, Token token, Database *db);
-static int f_numeric (const char *str, Token token, Database *db);
-static int f_default (const char *str, Token token, Database *db);
-
-static const TokenTable token_tbl[] = {
- { T_NEWLINE, 1 },
- { T_COMMENT, 1 },
- { T_SEMICOLON, 1 },
- { T_DOUBLE_QUOTE, 1 },
- { T_LEFT_BRACE, 1 },
- { T_RIGHT_BRACE, 1 },
- { T_SPACE, 1 },
- { T_TAB, 1 },
- { T_BACKSLASH, 1 },
- { T_NUMERIC_HEX, 2 },
- { T_NUMERIC_DEC, 2 },
- { T_NUMERIC_OCT, 2 },
- { T_DEFAULT, 1 } /* any character */
-};
-
-#define SYM_CR '\r'
-#define SYM_NEWLINE '\n'
-#define SYM_COMMENT '#'
-#define SYM_SEMICOLON ';'
-#define SYM_DOUBLE_QUOTE '"'
-#define SYM_LEFT_BRACE '{'
-#define SYM_RIGHT_BRACE '}'
-#define SYM_SPACE ' '
-#define SYM_TAB '\t'
-#define SYM_BACKSLASH '\\'
-
-/************************************************************************/
-
-#define MAX_NAME_NEST 64
-
-typedef struct {
- ParseState pre_state;
- char *category;
- char *name[MAX_NAME_NEST];
- int nest_depth;
- char **value;
- int value_len;
- int value_num;
- int bufsize; /* bufMaxSize >= bufsize >= 0 */
- int bufMaxSize; /* default : BUFSIZE */
- char *buf;
-} DBParseInfo;
-
-static DBParseInfo parse_info;
-
-static void
-init_parse_info (void)
-{
- static int allocated /* = 0 */;
- char *ptr;
- int size;
- if (!allocated) {
- bzero(&parse_info, sizeof(DBParseInfo));
- parse_info.buf = (char *)Xmalloc(BUFSIZE);
- parse_info.bufMaxSize = BUFSIZE;
- allocated = 1;
- return;
- }
- ptr = parse_info.buf;
- size = parse_info.bufMaxSize;
- bzero(&parse_info, sizeof(DBParseInfo));
- parse_info.buf = ptr;
- parse_info.bufMaxSize = size;
-}
-
-static void
-clear_parse_info (void)
-{
- int i;
- char *ptr;
- int size;
- parse_info.pre_state = S_NULL;
- if (parse_info.category != NULL) {
- Xfree(parse_info.category);
- }
- for (i = 0; i <= parse_info.nest_depth; ++i) {
- if (parse_info.name[i]) {
- Xfree(parse_info.name[i]);
- }
- }
- if (parse_info.value) {
- if (*parse_info.value) {
- Xfree(*parse_info.value);
- }
- Xfree((char *)parse_info.value);
- }
- ptr = parse_info.buf;
- size = parse_info.bufMaxSize;
- bzero(&parse_info, sizeof(DBParseInfo));
- parse_info.buf = ptr;
- parse_info.bufMaxSize = size;
-}
-
-static Bool
-realloc_parse_info(
- int len)
-{
- char *p;
-
- parse_info.bufMaxSize = BUFSIZE * ((parse_info.bufsize + len)/BUFSIZE + 1);
- p = (char *)Xrealloc(parse_info.buf, parse_info.bufMaxSize);
- if (p == NULL)
- return False;
- parse_info.buf = p;
-
- return True;
-}
-
-/************************************************************************/
-
-typedef struct _Line {
- char *str;
- int cursize;
- int maxsize;
- int seq;
-} Line;
-
-static void
-free_line(
- Line *line)
-{
- if (line->str != NULL) {
- Xfree(line->str);
- }
- bzero(line, sizeof(Line));
-}
-
-static int
-realloc_line(
- Line *line,
- int size)
-{
- char *str = line->str;
-
- if (str != NULL) {
- str = (char *)Xrealloc(str, size);
- } else {
- str = (char *)Xmalloc(size);
- }
- if (str == NULL) {
- /* malloc error */
- if (line->str != NULL) {
- Xfree(line->str);
- }
- bzero(line, sizeof(Line));
- return 0;
- }
- line->str = str;
- line->maxsize = size;
- return 1;
-}
-
-#define iswhite(ch) ((ch) == SYM_SPACE || (ch) == SYM_TAB)
-
-static void
-zap_comment(
- char *str,
- int *quoted)
-{
- char *p = str;
-#ifdef never
- *quoted = 0;
- if (*p == SYM_COMMENT) {
- int len = strlen(str);
- if (p[len - 1] == SYM_NEWLINE || p[len - 1] == SYM_CR) {
- *p++ = SYM_NEWLINE;
- }
- *p = '\0';
- }
-#else
- while (*p) {
- if (*p == SYM_DOUBLE_QUOTE) {
- if (p == str || p[-1] != SYM_BACKSLASH) {
- /* unescaped double quote changes quoted state. */
- *quoted = *quoted ? 0 : 1;
- }
- }
- if (*p == SYM_COMMENT && !*quoted) {
- int pos = p - str;
- if (pos == 0 ||
- (iswhite(p[-1]) && (pos == 1 || p[-2] != SYM_BACKSLASH))) {
- int len = strlen(p);
- if (len > 0 && (p[len - 1] == SYM_NEWLINE || p[len-1] == SYM_CR)) {
- /* newline is the identifier for finding end of value.
- therefore, it should not be removed. */
- *p++ = SYM_NEWLINE;
- }
- *p = '\0';
- break;
- }
- }
- ++p;
- }
-#endif
-}
-
-static int
-read_line(
- FILE *fd,
- Line *line)
-{
- char buf[BUFSIZE], *p;
- int len;
- int quoted = 0; /* quoted by double quote? */
- char *str;
- int cur;
-
- str = line->str;
- cur = line->cursize = 0;
-
- while ((p = fgets(buf, BUFSIZE, fd)) != NULL) {
- ++line->seq;
- zap_comment(p, &quoted); /* remove comment line */
- len = strlen(p);
- if (len == 0) {
- if (cur > 0) {
- break;
- }
- continue;
- }
- if (cur + len + 1 > line->maxsize) {
- /* need to reallocate buffer. */
- if (! realloc_line(line, line->maxsize + BUFSIZE)) {
- return -1; /* realloc error. */
- }
- str = line->str;
- }
- strncpy(str + cur, p, len);
-
- cur += len;
- str[cur] = '\0';
-#ifdef __UNIXOS2__ /* Take out carriage returns under OS/2 */
- if (cur>1) {
- if (str[cur-2] == '\r' && str[cur-1] == '\n') {
- str[cur-2] = '\n';
- str[cur-1] = '\0';
- cur--;
- }
- }
-#endif
- if (!quoted && cur > 1 && str[cur - 2] == SYM_BACKSLASH &&
- (str[cur - 1] == SYM_NEWLINE || str[cur-1] == SYM_CR)) {
- /* the line is ended backslash followed by newline.
- need to concatinate the next line. */
- cur -= 2;
- str[cur] = '\0';
- } else if (len < BUFSIZE - 1 || buf[len - 1] == SYM_NEWLINE ||
- buf[len - 1] == SYM_CR) {
- /* the line is shorter than BUFSIZE. */
- break;
- }
- }
- if (quoted) {
- /* error. still in quoted state. */
- return -1;
- }
- return line->cursize = cur;
-}
-
-/************************************************************************/
-
-static Token
-get_token(
- const char *str)
-{
- switch (*str) {
- case SYM_NEWLINE:
- case SYM_CR: return T_NEWLINE;
- case SYM_COMMENT: return T_COMMENT;
- case SYM_SEMICOLON: return T_SEMICOLON;
- case SYM_DOUBLE_QUOTE: return T_DOUBLE_QUOTE;
- case SYM_LEFT_BRACE: return T_LEFT_BRACE;
- case SYM_RIGHT_BRACE: return T_RIGHT_BRACE;
- case SYM_SPACE: return T_SPACE;
- case SYM_TAB: return T_TAB;
- case SYM_BACKSLASH:
- switch (str[1]) {
- case 'x': return T_NUMERIC_HEX;
- case 'd': return T_NUMERIC_DEC;
- case 'o': return T_NUMERIC_OCT;
- }
- return T_BACKSLASH;
- default:
- return T_DEFAULT;
- }
-}
-
-static int
-get_word(
- const char *str,
- char *word)
-{
- const char *p = str;
- char *w = word;
- Token token;
- int token_len;
-
- while (*p != '\0') {
- token = get_token(p);
- token_len = token_tbl[token].len;
- if (token == T_BACKSLASH) {
- p += token_len;
- if (*p == '\0')
- break;
- token = get_token(p);
- token_len = token_tbl[token].len;
- } else if (token != T_COMMENT && token != T_DEFAULT) {
- break;
- }
- strncpy(w, p, token_len);
- p += token_len; w += token_len;
- }
- *w = '\0';
- return p - str; /* return number of scanned chars */
-}
-
-static int
-get_quoted_word(
- const char *str,
- char *word)
-{
- const char *p = str;
- char *w = word;
- Token token;
- int token_len;
-
- if (*p == SYM_DOUBLE_QUOTE) {
- ++p;
- }
- while (*p != '\0') {
- token = get_token(p);
- token_len = token_tbl[token].len;
- if (token == T_DOUBLE_QUOTE) {
- p += token_len;
- goto found;
- }
- if (token == T_BACKSLASH) {
- p += token_len;
- if (*p == '\0') {
- break;
- }
- token = get_token(p);
- token_len = token_tbl[token].len;
- }
- strncpy(w, p, token_len);
- p += token_len; w += token_len;
- }
- /* error. cannot detect next double quote */
- return 0;
-
- found:;
- *w = '\0';
- return p - str;
-}
-
-/************************************************************************/
-
-static int
-append_value_list (void)
-{
- char **value_list = parse_info.value;
- char *value;
- int value_num = parse_info.value_num;
- int value_len = parse_info.value_len;
- char *str = parse_info.buf;
- int len = parse_info.bufsize;
- char *p;
-
- if (len < 1) {
- return 1; /* return with no error */
- }
-
- if (value_list == (char **)NULL) {
- value_list = (char **)Xmalloc(sizeof(char *) * 2);
- *value_list = NULL;
- } else {
- char **prev_list = value_list;
-
- value_list = (char **)
- Xrealloc(value_list, sizeof(char *) * (value_num + 2));
- if (value_list == NULL) {
- Xfree(prev_list);
- }
- }
- if (value_list == (char **)NULL)
- goto err2;
-
- value = *value_list;
- if (value == NULL) {
- value = (char *)Xmalloc(value_len + len + 1);
- } else {
- char *prev_value = value;
-
- value = (char *)Xrealloc(value, value_len + len + 1);
- if (value == NULL) {
- Xfree(prev_value);
- }
- }
- if (value == NULL) {
- goto err1;
- }
- if (value != *value_list) {
- int i;
- ssize_t delta;
- delta = value - *value_list;
- *value_list = value;
- for (i = 1; i < value_num; ++i) {
- value_list[i] += delta;
- }
- }
-
- value_list[value_num] = p = &value[value_len];
- value_list[value_num + 1] = NULL;
- strncpy(p, str, len);
- p[len] = 0;
-
- parse_info.value = value_list;
- parse_info.value_num = value_num + 1;
- parse_info.value_len = value_len + len + 1;
- parse_info.bufsize = 0;
- return 1;
-
- err1:
- if (value_list) {
- Xfree((char **)value_list);
- }
- if (value) {
- Xfree(value);
- }
- err2:
- parse_info.value = (char **)NULL;
- parse_info.value_num = 0;
- parse_info.value_len = 0;
- parse_info.bufsize = 0;
- return 0;
-}
-
-static int
-construct_name(
- char *name,
- int size)
-{
- int i;
- int len = 0;
- char *p = name;
-
- for (i = 0; i <= parse_info.nest_depth; ++i) {
- len += strlen(parse_info.name[i]) + 1;
- }
- if (len >= size)
- return 0;
-
- strcpy(p, parse_info.name[0]);
- p += strlen(parse_info.name[0]);
- for (i = 1; i <= parse_info.nest_depth; ++i) {
- *p++ = '.';
- strcpy(p, parse_info.name[i]);
- p += strlen(parse_info.name[i]);
- }
- return *name != '\0';
-}
-
-static int
-store_to_database(
- Database *db)
-{
- Database new = (Database)NULL;
- char name[BUFSIZE];
-
- if (parse_info.pre_state == S_VALUE) {
- if (! append_value_list()) {
- goto err;
- }
- }
-
- if (parse_info.name[parse_info.nest_depth] == NULL) {
- goto err;
- }
-
- new = (Database)Xmalloc(sizeof(DatabaseRec));
- if (new == (Database)NULL) {
- goto err;
- }
- bzero(new, sizeof(DatabaseRec));
-
- new->category = (char *)Xmalloc(strlen(parse_info.category) + 1);
- if (new->category == NULL) {
- goto err;
- }
- strcpy(new->category, parse_info.category);
-
- if (! construct_name(name, sizeof(name))) {
- goto err;
- }
- new->name = (char *)Xmalloc(strlen(name) + 1);
- if (new->name == NULL) {
- goto err;
- }
- strcpy(new->name, name);
- new->next = *db;
- new->value = parse_info.value;
- new->value_num = parse_info.value_num;
- *db = new;
-
- Xfree(parse_info.name[parse_info.nest_depth]);
- parse_info.name[parse_info.nest_depth] = NULL;
-
- parse_info.value = (char **)NULL;
- parse_info.value_num = 0;
- parse_info.value_len = 0;
-
- return 1;
-
- err:
- if (new) {
- if (new->category) {
- Xfree(new->category);
- }
- if (new->name) {
- Xfree(new->name);
- }
- Xfree(new);
- }
- if (parse_info.value) {
- if (*parse_info.value) {
- Xfree(*parse_info.value);
- }
- Xfree((char **)parse_info.value);
- parse_info.value = (char **)NULL;
- parse_info.value_num = 0;
- parse_info.value_len = 0;
- }
- return 0;
-}
-
-#define END_MARK "END"
-#define END_MARK_LEN 3 /*strlen(END_MARK)*/
-
-static int
-check_category_end(
- const char *str)
-{
- const char *p;
- int len;
-
- p = str;
- if (strncmp(p, END_MARK, END_MARK_LEN)) {
- return 0;
- }
- p += END_MARK_LEN;
-
- while (iswhite(*p)) {
- ++p;
- }
- len = strlen(parse_info.category);
- if (strncmp(p, parse_info.category, len)) {
- return 0;
- }
- p += len;
- return p - str;
-}
-
-/************************************************************************/
-
-static int
-f_newline(
- const char *str,
- Token token,
- Database *db)
-{
- switch (parse_info.pre_state) {
- case S_NULL:
- case S_CATEGORY:
- break;
- case S_NAME:
- return 0; /* no value */
- case S_VALUE:
- if (!store_to_database(db))
- return 0;
- parse_info.pre_state = S_CATEGORY;
- break;
- default:
- return 0;
- }
- return token_tbl[token].len;
-}
-
-static int
-f_comment(
- const char *str,
- Token token,
- Database *db)
-{
- /* NOTE: comment is already handled in read_line(),
- so this function is not necessary. */
-
- const char *p = str;
-
- while (*p != SYM_NEWLINE && *p != SYM_CR && *p != '\0') {
- ++p; /* zap to the end of line */
- }
- return p - str;
-}
-
-static int
-f_white(
- const char *str,
- Token token,
- Database *db)
-{
- const char *p = str;
-
- while (iswhite(*p)) {
- ++p;
- }
- return p - str;
-}
-
-static int
-f_semicolon(
- const char *str,
- Token token,
- Database *db)
-{
- switch (parse_info.pre_state) {
- case S_NULL:
- case S_CATEGORY:
- case S_NAME:
- return 0;
- case S_VALUE:
- if (! append_value_list())
- return 0;
- parse_info.pre_state = S_VALUE;
- break;
- default:
- return 0;
- }
- return token_tbl[token].len;
-}
-
-static int
-f_left_brace(
- const char *str,
- Token token,
- Database *db)
-{
- switch (parse_info.pre_state) {
- case S_NULL:
- case S_CATEGORY:
- case S_VALUE:
- return 0;
- case S_NAME:
- if (parse_info.name[parse_info.nest_depth] == NULL
- || parse_info.nest_depth + 1 > MAX_NAME_NEST)
- return 0;
- ++parse_info.nest_depth;
- parse_info.pre_state = S_CATEGORY;
- break;
- default:
- return 0;
- }
- return token_tbl[token].len;
-}
-
-static int
-f_right_brace(
- const char *str,
- Token token,
- Database *db)
-{
- if (parse_info.nest_depth < 1)
- return 0;
-
- switch (parse_info.pre_state) {
- case S_NULL:
- case S_NAME:
- return 0;
- case S_VALUE:
- if (! store_to_database(db))
- return 0;
- /* fall into next case */
- case S_CATEGORY:
- if (parse_info.name[parse_info.nest_depth] != NULL) {
- Xfree(parse_info.name[parse_info.nest_depth]);
- parse_info.name[parse_info.nest_depth] = NULL;
- }
- --parse_info.nest_depth;
- parse_info.pre_state = S_CATEGORY;
- break;
- default:
- return 0;
- }
- return token_tbl[token].len;
-}
-
-static int
-f_double_quote(
- const char *str,
- Token token,
- Database *db)
-{
- char word[BUFSIZE];
- char* wordp;
- int len;
-
- if ((len = strlen (str)) < sizeof word)
- wordp = word;
- else
- wordp = Xmalloc (len + 1);
- if (wordp == NULL)
- return 0;
-
- len = 0;
- switch (parse_info.pre_state) {
- case S_NULL:
- case S_CATEGORY:
- goto err;
- case S_NAME:
- case S_VALUE:
- len = get_quoted_word(str, wordp);
- if (len < 1)
- goto err;
- if ((parse_info.bufsize + (int)strlen(wordp) + 1)
- >= parse_info.bufMaxSize) {
- if (realloc_parse_info(strlen(wordp)+1) == False) {
- goto err;
- }
- }
- strcpy(&parse_info.buf[parse_info.bufsize], wordp);
- parse_info.bufsize += strlen(wordp);
- parse_info.pre_state = S_VALUE;
- break;
- default:
- goto err;
- }
- if (wordp != word)
- Xfree (wordp);
- return len; /* including length of token */
-
-err:
- if (wordp != word)
- Xfree (wordp);
- return 0;
-}
-
-static int
-f_backslash(
- const char *str,
- Token token,
- Database *db)
-{
- return f_default(str, token, db);
-}
-
-static int
-f_numeric(
- const char *str,
- Token token,
- Database *db)
-{
- char word[BUFSIZE];
- const char *p;
- char* wordp;
- int len;
- int token_len;
-
- if ((len = strlen (str)) < sizeof word)
- wordp = word;
- else
- wordp = Xmalloc (len + 1);
- if (wordp == NULL)
- return 0;
-
- switch (parse_info.pre_state) {
- case S_NULL:
- case S_CATEGORY:
- goto err;
- case S_NAME:
- case S_VALUE:
- token_len = token_tbl[token].len;
- p = str + token_len;
- len = get_word(p, wordp);
- if (len < 1)
- goto err;
- if ((parse_info.bufsize + token_len + (int)strlen(wordp) + 1)
- >= parse_info.bufMaxSize) {
- if (realloc_parse_info(token_len + strlen(wordp) + 1) == False)
- goto err;
- }
- strncpy(&parse_info.buf[parse_info.bufsize], str, token_len);
- strcpy(&parse_info.buf[parse_info.bufsize + token_len], wordp);
- parse_info.bufsize += token_len + strlen(wordp);
- parse_info.pre_state = S_VALUE;
- break;
- default:
- goto err;
- }
- if (wordp != word)
- Xfree (wordp);
- return len + token_len;
-
-err:
- if (wordp != word)
- Xfree (wordp);
- return 0;
-}
-
-static int
-f_default(
- const char *str,
- Token token,
- Database *db)
-{
- char word[BUFSIZE], *p;
- char* wordp;
- int len;
-
- if ((len = strlen (str)) < sizeof word)
- wordp = word;
- else
- wordp = Xmalloc (len + 1);
- if (wordp == NULL)
- return 0;
-
- len = get_word(str, wordp);
- if (len < 1)
- goto err;
-
- switch (parse_info.pre_state) {
- case S_NULL:
- if (parse_info.category != NULL)
- goto err;
- p = (char *)Xmalloc(strlen(wordp) + 1);
- if (p == NULL)
- goto err;
- strcpy(p, wordp);
- parse_info.category = p;
- parse_info.pre_state = S_CATEGORY;
- break;
- case S_CATEGORY:
- if (parse_info.nest_depth == 0) {
- if (check_category_end(str)) {
- /* end of category is detected.
- clear context and zap to end of this line */
- clear_parse_info();
- len = strlen(str);
- break;
- }
- }
- p = (char *)Xmalloc(strlen(wordp) + 1);
- if (p == NULL)
- goto err;
- strcpy(p, wordp);
- if (parse_info.name[parse_info.nest_depth] != NULL) {
- Xfree(parse_info.name[parse_info.nest_depth]);
- }
- parse_info.name[parse_info.nest_depth] = p;
- parse_info.pre_state = S_NAME;
- break;
- case S_NAME:
- case S_VALUE:
- if ((parse_info.bufsize + (int)strlen(wordp) + 1)
- >= parse_info.bufMaxSize) {
- if (realloc_parse_info(strlen(wordp) + 1) == False)
- goto err;
- }
- strcpy(&parse_info.buf[parse_info.bufsize], wordp);
- parse_info.bufsize += strlen(wordp);
- parse_info.pre_state = S_VALUE;
- break;
- default:
- goto err;
- }
- if (wordp != word)
- Xfree (wordp);
- return len;
-
-err:
- if (wordp != word)
- Xfree (wordp);
- return 0;
-}
-
-/************************************************************************/
-
-#ifdef DEBUG
-static void
-PrintDatabase(
- Database db)
-{
- Database p = db;
- int i = 0, j;
-
- printf("***\n*** BEGIN Database\n***\n");
- while (p) {
- printf("%3d: ", i++);
- printf("%s, %s, ", p->category, p->name);
- printf("\t[%d: ", p->value_num);
- for (j = 0; j < p->value_num; ++j) {
- printf("%s, ", p->value[j]);
- }
- printf("]\n");
- p = p->next;
- }
- printf("***\n*** END Database\n***\n");
-}
-#endif
-
-static void
-DestroyDatabase(
- Database db)
-{
- Database p = db;
-
- while (p) {
- if (p->category != NULL) {
- Xfree(p->category);
- }
- if (p->name != NULL) {
- Xfree(p->name);
- }
- if (p->value != (char **)NULL) {
- if (*p->value != NULL) {
- Xfree(*p->value);
- }
- Xfree((char *)p->value);
- }
- db = p->next;
- Xfree((char *)p);
- p = db;
- }
-}
-
-static int
-CountDatabase(
- Database db)
-{
- Database p = db;
- int cnt = 0;
-
- while (p) {
- ++cnt;
- p = p->next;
- }
- return cnt;
-}
-
-static Database
-CreateDatabase(
- char *dbfile)
-{
- Database db = (Database)NULL;
- FILE *fd;
- Line line;
- char *p;
- Token token;
- int len;
- int error = 0;
-
- fd = _XFopenFile(dbfile, "r");
- if (fd == (FILE *)NULL)
- return NULL;
-
- bzero(&line, sizeof(Line));
- init_parse_info();
-
- do {
- int rc = read_line(fd, &line);
- if (rc < 0) {
- error = 1;
- break;
- } else if (rc == 0) {
- break;
- }
- p = line.str;
- while (*p) {
- int (*parse_proc)(const char *str, Token token, Database *db) = NULL;
-
- token = get_token(p);
-
- switch (token_tbl[token].token) {
- case T_NEWLINE:
- parse_proc = f_newline;
- break;
- case T_COMMENT:
- parse_proc = f_comment;
- break;
- case T_SEMICOLON:
- parse_proc = f_semicolon;
- break;
- case T_DOUBLE_QUOTE:
- parse_proc = f_double_quote;
- break;
- case T_LEFT_BRACE:
- parse_proc = f_left_brace;
- break;
- case T_RIGHT_BRACE:
- parse_proc = f_right_brace;
- break;
- case T_SPACE:
- case T_TAB:
- parse_proc = f_white;
- break;
- case T_BACKSLASH:
- parse_proc = f_backslash;
- break;
- case T_NUMERIC_HEX:
- case T_NUMERIC_DEC:
- case T_NUMERIC_OCT:
- parse_proc = f_numeric;
- break;
- case T_DEFAULT:
- parse_proc = f_default;
- break;
- }
-
- len = parse_proc(p, token, &db);
-
- if (len < 1) {
- error = 1;
- break;
- }
- p += len;
- }
- } while (!error);
-
- if (parse_info.pre_state != S_NULL) {
- clear_parse_info();
- error = 1;
- }
- if (error) {
-#ifdef DEBUG
- fprintf(stderr, "database format error at line %d.\n", line.seq);
-#endif
- DestroyDatabase(db);
- db = (Database)NULL;
- }
-
- fclose(fd);
- free_line(&line);
-
-#ifdef DEBUG
- PrintDatabase(db);
-#endif
-
- return db;
-}
-
-/************************************************************************/
-
-#ifndef NOT_X_ENV
-
-/* locale framework functions */
-
-typedef struct _XlcDatabaseRec {
- XrmQuark category_q;
- XrmQuark name_q;
- Database db;
- struct _XlcDatabaseRec *next;
-} XlcDatabaseRec, *XlcDatabase;
-
-typedef struct _XlcDatabaseListRec {
- XrmQuark name_q;
- XlcDatabase lc_db;
- Database database;
- int ref_count;
- struct _XlcDatabaseListRec *next;
-} XlcDatabaseListRec, *XlcDatabaseList;
-
-/* database cache list (per file) */
-static XlcDatabaseList _db_list = (XlcDatabaseList)NULL;
-
-/************************************************************************/
-/* _XlcGetResource(lcd, category, class, value, count) */
-/*----------------------------------------------------------------------*/
-/* This function retrieves XLocale database information. */
-/************************************************************************/
-void
-_XlcGetResource(
- XLCd lcd,
- const char *category,
- const char *class,
- char ***value,
- int *count)
-{
- XLCdPublicMethodsPart *methods = XLC_PUBLIC_METHODS(lcd);
-
- (*methods->get_resource)(lcd, category, class, value, count);
- return;
-}
-
-/************************************************************************/
-/* _XlcGetLocaleDataBase(lcd, category, class, value, count) */
-/*----------------------------------------------------------------------*/
-/* This function retrieves XLocale database information. */
-/************************************************************************/
-void
-_XlcGetLocaleDataBase(
- XLCd lcd,
- const char *category,
- const char *name,
- char ***value,
- int *count)
-{
- XlcDatabase lc_db = (XlcDatabase)XLC_PUBLIC(lcd, xlocale_db);
- XrmQuark category_q, name_q;
-
- category_q = XrmStringToQuark(category);
- name_q = XrmStringToQuark(name);
- for (; lc_db->db; ++lc_db) {
- if (category_q == lc_db->category_q && name_q == lc_db->name_q) {
- *value = lc_db->db->value;
- *count = lc_db->db->value_num;
- return;
- }
- }
- *value = (char **)NULL;
- *count = 0;
-}
-
-/************************************************************************/
-/* _XlcDestroyLocaleDataBase(lcd) */
-/*----------------------------------------------------------------------*/
-/* This function destroy the XLocale Database that bound to the */
-/* specified lcd. If the XLocale Database is refered from some */
-/* other lcd, this function just decreases reference count of */
-/* the database. If no locale refers the database, this function */
-/* remove it from the cache list and free work area. */
-/************************************************************************/
-void
-_XlcDestroyLocaleDataBase(
- XLCd lcd)
-{
- XlcDatabase lc_db = (XlcDatabase)XLC_PUBLIC(lcd, xlocale_db);
- XlcDatabaseList p, prev;
-
- for (p = _db_list, prev = (XlcDatabaseList)NULL; p;
- prev = p, p = p->next) {
- if (p->lc_db == lc_db) {
- if ((-- p->ref_count) < 1) {
- if (p->lc_db != (XlcDatabase)NULL) {
- Xfree((char *)p->lc_db);
- }
- DestroyDatabase(p->database);
- if (prev == (XlcDatabaseList)NULL) {
- _db_list = p->next;
- } else {
- prev->next = p->next;
- }
- Xfree((char*)p);
- }
- break;
- }
- }
- XLC_PUBLIC(lcd, xlocale_db) = (XPointer)NULL;
-}
-
-/************************************************************************/
-/* _XlcCreateLocaleDataBase(lcd) */
-/*----------------------------------------------------------------------*/
-/* This function create an XLocale database which correspond to */
-/* the specified XLCd. */
-/************************************************************************/
-XPointer
-_XlcCreateLocaleDataBase(
- XLCd lcd)
-{
- XlcDatabaseList list, new;
- Database p, database = (Database)NULL;
- XlcDatabase lc_db = (XlcDatabase)NULL;
- XrmQuark name_q;
- char *name;
- int i, n;
-
- name = _XlcFileName(lcd, "locale");
- if (name == NULL)
- return (XPointer)NULL;
-
-#ifndef __UNIXOS2__
- name_q = XrmStringToQuark(name);
-#else
- name_q = XrmStringToQuark((char*)__XOS2RedirRoot(name));
-#endif
- for (list = _db_list; list; list = list->next) {
- if (name_q == list->name_q) {
- list->ref_count++;
- Xfree (name);
- return XLC_PUBLIC(lcd, xlocale_db) = (XPointer)list->lc_db;
- }
- }
-
- database = CreateDatabase(name);
- if (database == (Database)NULL) {
- Xfree (name);
- return (XPointer)NULL;
- }
- n = CountDatabase(database);
- lc_db = (XlcDatabase)Xmalloc(sizeof(XlcDatabaseRec) * (n + 1));
- if (lc_db == (XlcDatabase)NULL)
- goto err;
- bzero(lc_db, sizeof(XlcDatabaseRec) * (n + 1));
- for (p = database, i = 0; p && i < n; p = p->next, ++i) {
- lc_db[i].category_q = XrmStringToQuark(p->category);
- lc_db[i].name_q = XrmStringToQuark(p->name);
- lc_db[i].db = p;
- }
-
- new = (XlcDatabaseList)Xmalloc(sizeof(XlcDatabaseListRec));
- if (new == (XlcDatabaseList)NULL) {
- goto err;
- }
- new->name_q = name_q;
- new->lc_db = lc_db;
- new->database = database;
- new->ref_count = 1;
- new->next = _db_list;
- _db_list = new;
-
- Xfree (name);
- return XLC_PUBLIC(lcd, xlocale_db) = (XPointer)lc_db;
-
- err:
- DestroyDatabase(database);
- if (lc_db != (XlcDatabase)NULL) {
- Xfree((char *)lc_db);
- }
- Xfree (name);
- return (XPointer)NULL;
-}
-
-#endif /* NOT_X_ENV */
+/*
+ *
+ * Copyright IBM Corporation 1993
+ *
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of IBM not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ *
+ * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ * ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS, AND
+ * NONINFRINGEMENT OF THIRD PARTY RIGHTS, IN NO EVENT SHALL
+ * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+*/
+/*
+ * (c) Copyright 1995 FUJITSU LIMITED
+ * This is source code modified by FUJITSU LIMITED under the Joint
+ * Development Agreement for the CDE/Motif PST.
+ */
+
+
+
+#ifndef NOT_X_ENV
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xlib.h>
+#include <X11/Xresource.h>
+#include "Xlibint.h"
+#include "XlcPubI.h"
+
+#else /* NOT_X_ENV */
+
+#define Xmalloc malloc
+#define Xrealloc realloc
+#define Xfree free
+
+#endif /* NOT_X_ENV */
+
+#include <stdint.h>
+
+/* specifying NOT_X_ENV allows users to just use
+ the database parsing routine. */
+/* For UDC/VW */
+#ifndef BUFSIZE
+#define BUFSIZE 2048
+#endif
+
+#ifdef COMMENT
+#ifdef BUFSIZE
+#undef BUFSIZE
+#endif
+#define BUFSIZE 6144 /* 2048*3 */
+#endif
+
+#include <stdio.h>
+
+typedef struct _DatabaseRec {
+ char *category;
+ char *name;
+ char **value;
+ int value_num;
+ struct _DatabaseRec *next;
+} DatabaseRec, *Database;
+
+typedef enum {
+ S_NULL, /* outside category */
+ S_CATEGORY, /* inside category */
+ S_NAME, /* has name, expecting values */
+ S_VALUE
+} ParseState;
+
+typedef enum {
+ T_NEWLINE,
+ T_COMMENT,
+ T_SEMICOLON,
+ T_DOUBLE_QUOTE,
+ T_LEFT_BRACE,
+ T_RIGHT_BRACE,
+ T_SPACE,
+ T_TAB,
+ T_BACKSLASH,
+ T_NUMERIC_HEX,
+ T_NUMERIC_DEC,
+ T_NUMERIC_OCT,
+ T_DEFAULT
+} Token;
+
+typedef struct {
+ Token token; /* token id */
+ int len; /* length of token sequence */
+} TokenTable;
+
+static int f_newline (const char *str, Token token, Database *db);
+static int f_comment (const char *str, Token token, Database *db);
+static int f_semicolon (const char *str, Token token, Database *db);
+static int f_double_quote (const char *str, Token token, Database *db);
+static int f_left_brace (const char *str, Token token, Database *db);
+static int f_right_brace (const char *str, Token token, Database *db);
+static int f_white (const char *str, Token token, Database *db);
+static int f_backslash (const char *str, Token token, Database *db);
+static int f_numeric (const char *str, Token token, Database *db);
+static int f_default (const char *str, Token token, Database *db);
+
+static const TokenTable token_tbl[] = {
+ { T_NEWLINE, 1 },
+ { T_COMMENT, 1 },
+ { T_SEMICOLON, 1 },
+ { T_DOUBLE_QUOTE, 1 },
+ { T_LEFT_BRACE, 1 },
+ { T_RIGHT_BRACE, 1 },
+ { T_SPACE, 1 },
+ { T_TAB, 1 },
+ { T_BACKSLASH, 1 },
+ { T_NUMERIC_HEX, 2 },
+ { T_NUMERIC_DEC, 2 },
+ { T_NUMERIC_OCT, 2 },
+ { T_DEFAULT, 1 } /* any character */
+};
+
+#define SYM_CR '\r'
+#define SYM_NEWLINE '\n'
+#define SYM_COMMENT '#'
+#define SYM_SEMICOLON ';'
+#define SYM_DOUBLE_QUOTE '"'
+#define SYM_LEFT_BRACE '{'
+#define SYM_RIGHT_BRACE '}'
+#define SYM_SPACE ' '
+#define SYM_TAB '\t'
+#define SYM_BACKSLASH '\\'
+
+/************************************************************************/
+
+#define MAX_NAME_NEST 64
+
+typedef struct {
+ ParseState pre_state;
+ char *category;
+ char *name[MAX_NAME_NEST];
+ int nest_depth;
+ char **value;
+ int value_len;
+ int value_num;
+ int bufsize; /* bufMaxSize >= bufsize >= 0 */
+ int bufMaxSize; /* default : BUFSIZE */
+ char *buf;
+} DBParseInfo;
+
+static DBParseInfo parse_info;
+
+static void
+init_parse_info (void)
+{
+ static int allocated /* = 0 */;
+ char *ptr;
+ int size;
+ if (!allocated) {
+ bzero(&parse_info, sizeof(DBParseInfo));
+ parse_info.buf = (char *)Xmalloc(BUFSIZE);
+ parse_info.bufMaxSize = BUFSIZE;
+ allocated = 1;
+ return;
+ }
+ ptr = parse_info.buf;
+ size = parse_info.bufMaxSize;
+ bzero(&parse_info, sizeof(DBParseInfo));
+ parse_info.buf = ptr;
+ parse_info.bufMaxSize = size;
+}
+
+static void
+clear_parse_info (void)
+{
+ int i;
+ char *ptr;
+ int size;
+ parse_info.pre_state = S_NULL;
+ if (parse_info.category != NULL) {
+ Xfree(parse_info.category);
+ }
+ for (i = 0; i <= parse_info.nest_depth; ++i) {
+ if (parse_info.name[i]) {
+ Xfree(parse_info.name[i]);
+ }
+ }
+ if (parse_info.value) {
+ if (*parse_info.value) {
+ Xfree(*parse_info.value);
+ }
+ Xfree((char *)parse_info.value);
+ }
+ ptr = parse_info.buf;
+ size = parse_info.bufMaxSize;
+ bzero(&parse_info, sizeof(DBParseInfo));
+ parse_info.buf = ptr;
+ parse_info.bufMaxSize = size;
+}
+
+static Bool
+realloc_parse_info(
+ int len)
+{
+ char *p;
+
+ parse_info.bufMaxSize = BUFSIZE * ((parse_info.bufsize + len)/BUFSIZE + 1);
+ p = (char *)Xrealloc(parse_info.buf, parse_info.bufMaxSize);
+ if (p == NULL)
+ return False;
+ parse_info.buf = p;
+
+ return True;
+}
+
+/************************************************************************/
+
+typedef struct _Line {
+ char *str;
+ int cursize;
+ int maxsize;
+ int seq;
+} Line;
+
+static void
+free_line(
+ Line *line)
+{
+ if (line->str != NULL) {
+ Xfree(line->str);
+ }
+ bzero(line, sizeof(Line));
+}
+
+static int
+realloc_line(
+ Line *line,
+ int size)
+{
+ char *str = line->str;
+
+ if (str != NULL) {
+ str = (char *)Xrealloc(str, size);
+ } else {
+ str = (char *)Xmalloc(size);
+ }
+ if (str == NULL) {
+ /* malloc error */
+ if (line->str != NULL) {
+ Xfree(line->str);
+ }
+ bzero(line, sizeof(Line));
+ return 0;
+ }
+ line->str = str;
+ line->maxsize = size;
+ return 1;
+}
+
+#define iswhite(ch) ((ch) == SYM_SPACE || (ch) == SYM_TAB)
+
+static void
+zap_comment(
+ char *str,
+ int *quoted)
+{
+ char *p = str;
+#ifdef never
+ *quoted = 0;
+ if (*p == SYM_COMMENT) {
+ int len = strlen(str);
+ if (p[len - 1] == SYM_NEWLINE || p[len - 1] == SYM_CR) {
+ *p++ = SYM_NEWLINE;
+ }
+ *p = '\0';
+ }
+#else
+ while (*p) {
+ if (*p == SYM_DOUBLE_QUOTE) {
+ if (p == str || p[-1] != SYM_BACKSLASH) {
+ /* unescaped double quote changes quoted state. */
+ *quoted = *quoted ? 0 : 1;
+ }
+ }
+ if (*p == SYM_COMMENT && !*quoted) {
+ int pos = p - str;
+ if (pos == 0 ||
+ (iswhite(p[-1]) && (pos == 1 || p[-2] != SYM_BACKSLASH))) {
+ int len = strlen(p);
+ if (len > 0 && (p[len - 1] == SYM_NEWLINE || p[len-1] == SYM_CR)) {
+ /* newline is the identifier for finding end of value.
+ therefore, it should not be removed. */
+ *p++ = SYM_NEWLINE;
+ }
+ *p = '\0';
+ break;
+ }
+ }
+ ++p;
+ }
+#endif
+}
+
+static int
+read_line(
+ FILE *fd,
+ Line *line)
+{
+ char buf[BUFSIZE], *p;
+ int len;
+ int quoted = 0; /* quoted by double quote? */
+ char *str;
+ int cur;
+
+ str = line->str;
+ cur = line->cursize = 0;
+
+ while ((p = fgets(buf, BUFSIZE, fd)) != NULL) {
+ ++line->seq;
+ zap_comment(p, &quoted); /* remove comment line */
+ len = strlen(p);
+ if (len == 0) {
+ if (cur > 0) {
+ break;
+ }
+ continue;
+ }
+ if (cur + len + 1 > line->maxsize) {
+ /* need to reallocate buffer. */
+ if (! realloc_line(line, line->maxsize + BUFSIZE)) {
+ return -1; /* realloc error. */
+ }
+ str = line->str;
+ }
+ strncpy(str + cur, p, len);
+
+ cur += len;
+ str[cur] = '\0';
+#ifdef __UNIXOS2__ /* Take out carriage returns under OS/2 */
+ if (cur>1) {
+ if (str[cur-2] == '\r' && str[cur-1] == '\n') {
+ str[cur-2] = '\n';
+ str[cur-1] = '\0';
+ cur--;
+ }
+ }
+#endif
+ if (!quoted && cur > 1 && str[cur - 2] == SYM_BACKSLASH &&
+ (str[cur - 1] == SYM_NEWLINE || str[cur-1] == SYM_CR)) {
+ /* the line is ended backslash followed by newline.
+ need to concatinate the next line. */
+ cur -= 2;
+ str[cur] = '\0';
+ } else if (len < BUFSIZE - 1 || buf[len - 1] == SYM_NEWLINE ||
+ buf[len - 1] == SYM_CR) {
+ /* the line is shorter than BUFSIZE. */
+ break;
+ }
+ }
+ if (quoted) {
+ /* error. still in quoted state. */
+ return -1;
+ }
+ return line->cursize = cur;
+}
+
+/************************************************************************/
+
+static Token
+get_token(
+ const char *str)
+{
+ switch (*str) {
+ case SYM_NEWLINE:
+ case SYM_CR: return T_NEWLINE;
+ case SYM_COMMENT: return T_COMMENT;
+ case SYM_SEMICOLON: return T_SEMICOLON;
+ case SYM_DOUBLE_QUOTE: return T_DOUBLE_QUOTE;
+ case SYM_LEFT_BRACE: return T_LEFT_BRACE;
+ case SYM_RIGHT_BRACE: return T_RIGHT_BRACE;
+ case SYM_SPACE: return T_SPACE;
+ case SYM_TAB: return T_TAB;
+ case SYM_BACKSLASH:
+ switch (str[1]) {
+ case 'x': return T_NUMERIC_HEX;
+ case 'd': return T_NUMERIC_DEC;
+ case 'o': return T_NUMERIC_OCT;
+ }
+ return T_BACKSLASH;
+ default:
+ return T_DEFAULT;
+ }
+}
+
+static int
+get_word(
+ const char *str,
+ char *word)
+{
+ const char *p = str;
+ char *w = word;
+ Token token;
+ int token_len;
+
+ while (*p != '\0') {
+ token = get_token(p);
+ token_len = token_tbl[token].len;
+ if (token == T_BACKSLASH) {
+ p += token_len;
+ if (*p == '\0')
+ break;
+ token = get_token(p);
+ token_len = token_tbl[token].len;
+ } else if (token != T_COMMENT && token != T_DEFAULT) {
+ break;
+ }
+ strncpy(w, p, token_len);
+ p += token_len; w += token_len;
+ }
+ *w = '\0';
+ return p - str; /* return number of scanned chars */
+}
+
+static int
+get_quoted_word(
+ const char *str,
+ char *word)
+{
+ const char *p = str;
+ char *w = word;
+ Token token;
+ int token_len;
+
+ if (*p == SYM_DOUBLE_QUOTE) {
+ ++p;
+ }
+ while (*p != '\0') {
+ token = get_token(p);
+ token_len = token_tbl[token].len;
+ if (token == T_DOUBLE_QUOTE) {
+ p += token_len;
+ goto found;
+ }
+ if (token == T_BACKSLASH) {
+ p += token_len;
+ if (*p == '\0') {
+ break;
+ }
+ token = get_token(p);
+ token_len = token_tbl[token].len;
+ }
+ strncpy(w, p, token_len);
+ p += token_len; w += token_len;
+ }
+ /* error. cannot detect next double quote */
+ return 0;
+
+ found:;
+ *w = '\0';
+ return p - str;
+}
+
+/************************************************************************/
+
+static int
+append_value_list (void)
+{
+ char **value_list = parse_info.value;
+ char *value;
+ int value_num = parse_info.value_num;
+ int value_len = parse_info.value_len;
+ char *str = parse_info.buf;
+ int len = parse_info.bufsize;
+ char *p;
+
+ if (len < 1) {
+ return 1; /* return with no error */
+ }
+
+ if (value_list == (char **)NULL) {
+ value_list = (char **)Xmalloc(sizeof(char *) * 2);
+ *value_list = NULL;
+ } else {
+ char **prev_list = value_list;
+
+ value_list = (char **)
+ Xrealloc(value_list, sizeof(char *) * (value_num + 2));
+ if (value_list == NULL) {
+ Xfree(prev_list);
+ }
+ }
+ if (value_list == (char **)NULL)
+ goto err2;
+
+ value = *value_list;
+ if (value == NULL) {
+ value = (char *)Xmalloc(value_len + len + 1);
+ } else {
+ char *prev_value = value;
+
+ value = (char *)Xrealloc(value, value_len + len + 1);
+ if (value == NULL) {
+ Xfree(prev_value);
+ }
+ }
+ if (value == NULL) {
+ goto err1;
+ }
+ if (value != *value_list) {
+ int i;
+ ssize_t delta;
+ delta = value - *value_list;
+ *value_list = value;
+ for (i = 1; i < value_num; ++i) {
+ value_list[i] += delta;
+ }
+ }
+
+ value_list[value_num] = p = &value[value_len];
+ value_list[value_num + 1] = NULL;
+ strncpy(p, str, len);
+ p[len] = 0;
+
+ parse_info.value = value_list;
+ parse_info.value_num = value_num + 1;
+ parse_info.value_len = value_len + len + 1;
+ parse_info.bufsize = 0;
+ return 1;
+
+ err1:
+ if (value_list) {
+ Xfree((char **)value_list);
+ }
+ if (value) {
+ Xfree(value);
+ }
+ err2:
+ parse_info.value = (char **)NULL;
+ parse_info.value_num = 0;
+ parse_info.value_len = 0;
+ parse_info.bufsize = 0;
+ return 0;
+}
+
+static int
+construct_name(
+ char *name,
+ int size)
+{
+ int i;
+ int len = 0;
+ char *p = name;
+
+ for (i = 0; i <= parse_info.nest_depth; ++i) {
+ len += strlen(parse_info.name[i]) + 1;
+ }
+ if (len >= size)
+ return 0;
+
+ strcpy(p, parse_info.name[0]);
+ p += strlen(parse_info.name[0]);
+ for (i = 1; i <= parse_info.nest_depth; ++i) {
+ *p++ = '.';
+ strcpy(p, parse_info.name[i]);
+ p += strlen(parse_info.name[i]);
+ }
+ return *name != '\0';
+}
+
+static int
+store_to_database(
+ Database *db)
+{
+ Database new = (Database)NULL;
+ char name[BUFSIZE];
+
+ if (parse_info.pre_state == S_VALUE) {
+ if (! append_value_list()) {
+ goto err;
+ }
+ }
+
+ if (parse_info.name[parse_info.nest_depth] == NULL) {
+ goto err;
+ }
+
+ new = Xcalloc(1, sizeof(DatabaseRec));
+ if (new == (Database)NULL) {
+ goto err;
+ }
+
+ new->category = strdup(parse_info.category);
+ if (new->category == NULL) {
+ goto err;
+ }
+
+ if (! construct_name(name, sizeof(name))) {
+ goto err;
+ }
+ new->name = strdup(name);
+ if (new->name == NULL) {
+ goto err;
+ }
+ new->next = *db;
+ new->value = parse_info.value;
+ new->value_num = parse_info.value_num;
+ *db = new;
+
+ Xfree(parse_info.name[parse_info.nest_depth]);
+ parse_info.name[parse_info.nest_depth] = NULL;
+
+ parse_info.value = (char **)NULL;
+ parse_info.value_num = 0;
+ parse_info.value_len = 0;
+
+ return 1;
+
+ err:
+ if (new) {
+ if (new->category) {
+ Xfree(new->category);
+ }
+ if (new->name) {
+ Xfree(new->name);
+ }
+ Xfree(new);
+ }
+ if (parse_info.value) {
+ if (*parse_info.value) {
+ Xfree(*parse_info.value);
+ }
+ Xfree((char **)parse_info.value);
+ parse_info.value = (char **)NULL;
+ parse_info.value_num = 0;
+ parse_info.value_len = 0;
+ }
+ return 0;
+}
+
+#define END_MARK "END"
+#define END_MARK_LEN 3 /*strlen(END_MARK)*/
+
+static int
+check_category_end(
+ const char *str)
+{
+ const char *p;
+ int len;
+
+ p = str;
+ if (strncmp(p, END_MARK, END_MARK_LEN)) {
+ return 0;
+ }
+ p += END_MARK_LEN;
+
+ while (iswhite(*p)) {
+ ++p;
+ }
+ len = strlen(parse_info.category);
+ if (strncmp(p, parse_info.category, len)) {
+ return 0;
+ }
+ p += len;
+ return p - str;
+}
+
+/************************************************************************/
+
+static int
+f_newline(
+ const char *str,
+ Token token,
+ Database *db)
+{
+ switch (parse_info.pre_state) {
+ case S_NULL:
+ case S_CATEGORY:
+ break;
+ case S_NAME:
+ return 0; /* no value */
+ case S_VALUE:
+ if (!store_to_database(db))
+ return 0;
+ parse_info.pre_state = S_CATEGORY;
+ break;
+ default:
+ return 0;
+ }
+ return token_tbl[token].len;
+}
+
+static int
+f_comment(
+ const char *str,
+ Token token,
+ Database *db)
+{
+ /* NOTE: comment is already handled in read_line(),
+ so this function is not necessary. */
+
+ const char *p = str;
+
+ while (*p != SYM_NEWLINE && *p != SYM_CR && *p != '\0') {
+ ++p; /* zap to the end of line */
+ }
+ return p - str;
+}
+
+static int
+f_white(
+ const char *str,
+ Token token,
+ Database *db)
+{
+ const char *p = str;
+
+ while (iswhite(*p)) {
+ ++p;
+ }
+ return p - str;
+}
+
+static int
+f_semicolon(
+ const char *str,
+ Token token,
+ Database *db)
+{
+ switch (parse_info.pre_state) {
+ case S_NULL:
+ case S_CATEGORY:
+ case S_NAME:
+ return 0;
+ case S_VALUE:
+ if (! append_value_list())
+ return 0;
+ parse_info.pre_state = S_VALUE;
+ break;
+ default:
+ return 0;
+ }
+ return token_tbl[token].len;
+}
+
+static int
+f_left_brace(
+ const char *str,
+ Token token,
+ Database *db)
+{
+ switch (parse_info.pre_state) {
+ case S_NULL:
+ case S_CATEGORY:
+ case S_VALUE:
+ return 0;
+ case S_NAME:
+ if (parse_info.name[parse_info.nest_depth] == NULL
+ || parse_info.nest_depth + 1 > MAX_NAME_NEST)
+ return 0;
+ ++parse_info.nest_depth;
+ parse_info.pre_state = S_CATEGORY;
+ break;
+ default:
+ return 0;
+ }
+ return token_tbl[token].len;
+}
+
+static int
+f_right_brace(
+ const char *str,
+ Token token,
+ Database *db)
+{
+ if (parse_info.nest_depth < 1)
+ return 0;
+
+ switch (parse_info.pre_state) {
+ case S_NULL:
+ case S_NAME:
+ return 0;
+ case S_VALUE:
+ if (! store_to_database(db))
+ return 0;
+ /* fall into next case */
+ case S_CATEGORY:
+ if (parse_info.name[parse_info.nest_depth] != NULL) {
+ Xfree(parse_info.name[parse_info.nest_depth]);
+ parse_info.name[parse_info.nest_depth] = NULL;
+ }
+ --parse_info.nest_depth;
+ parse_info.pre_state = S_CATEGORY;
+ break;
+ default:
+ return 0;
+ }
+ return token_tbl[token].len;
+}
+
+static int
+f_double_quote(
+ const char *str,
+ Token token,
+ Database *db)
+{
+ char word[BUFSIZE];
+ char* wordp;
+ int len;
+
+ if ((len = strlen (str)) < sizeof word)
+ wordp = word;
+ else
+ wordp = Xmalloc (len + 1);
+ if (wordp == NULL)
+ return 0;
+
+ len = 0;
+ switch (parse_info.pre_state) {
+ case S_NULL:
+ case S_CATEGORY:
+ goto err;
+ case S_NAME:
+ case S_VALUE:
+ len = get_quoted_word(str, wordp);
+ if (len < 1)
+ goto err;
+ if ((parse_info.bufsize + (int)strlen(wordp) + 1)
+ >= parse_info.bufMaxSize) {
+ if (realloc_parse_info(strlen(wordp)+1) == False) {
+ goto err;
+ }
+ }
+ strcpy(&parse_info.buf[parse_info.bufsize], wordp);
+ parse_info.bufsize += strlen(wordp);
+ parse_info.pre_state = S_VALUE;
+ break;
+ default:
+ goto err;
+ }
+ if (wordp != word)
+ Xfree (wordp);
+ return len; /* including length of token */
+
+err:
+ if (wordp != word)
+ Xfree (wordp);
+ return 0;
+}
+
+static int
+f_backslash(
+ const char *str,
+ Token token,
+ Database *db)
+{
+ return f_default(str, token, db);
+}
+
+static int
+f_numeric(
+ const char *str,
+ Token token,
+ Database *db)
+{
+ char word[BUFSIZE];
+ const char *p;
+ char* wordp;
+ int len;
+ int token_len;
+
+ if ((len = strlen (str)) < sizeof word)
+ wordp = word;
+ else
+ wordp = Xmalloc (len + 1);
+ if (wordp == NULL)
+ return 0;
+
+ switch (parse_info.pre_state) {
+ case S_NULL:
+ case S_CATEGORY:
+ goto err;
+ case S_NAME:
+ case S_VALUE:
+ token_len = token_tbl[token].len;
+ p = str + token_len;
+ len = get_word(p, wordp);
+ if (len < 1)
+ goto err;
+ if ((parse_info.bufsize + token_len + (int)strlen(wordp) + 1)
+ >= parse_info.bufMaxSize) {
+ if (realloc_parse_info(token_len + strlen(wordp) + 1) == False)
+ goto err;
+ }
+ strncpy(&parse_info.buf[parse_info.bufsize], str, token_len);
+ strcpy(&parse_info.buf[parse_info.bufsize + token_len], wordp);
+ parse_info.bufsize += token_len + strlen(wordp);
+ parse_info.pre_state = S_VALUE;
+ break;
+ default:
+ goto err;
+ }
+ if (wordp != word)
+ Xfree (wordp);
+ return len + token_len;
+
+err:
+ if (wordp != word)
+ Xfree (wordp);
+ return 0;
+}
+
+static int
+f_default(
+ const char *str,
+ Token token,
+ Database *db)
+{
+ char word[BUFSIZE], *p;
+ char* wordp;
+ int len;
+
+ if ((len = strlen (str)) < sizeof word)
+ wordp = word;
+ else
+ wordp = Xmalloc (len + 1);
+ if (wordp == NULL)
+ return 0;
+
+ len = get_word(str, wordp);
+ if (len < 1)
+ goto err;
+
+ switch (parse_info.pre_state) {
+ case S_NULL:
+ if (parse_info.category != NULL)
+ goto err;
+ p = strdup(wordp);
+ if (p == NULL)
+ goto err;
+ parse_info.category = p;
+ parse_info.pre_state = S_CATEGORY;
+ break;
+ case S_CATEGORY:
+ if (parse_info.nest_depth == 0) {
+ if (check_category_end(str)) {
+ /* end of category is detected.
+ clear context and zap to end of this line */
+ clear_parse_info();
+ len = strlen(str);
+ break;
+ }
+ }
+ p = strdup(wordp);
+ if (p == NULL)
+ goto err;
+ if (parse_info.name[parse_info.nest_depth] != NULL) {
+ Xfree(parse_info.name[parse_info.nest_depth]);
+ }
+ parse_info.name[parse_info.nest_depth] = p;
+ parse_info.pre_state = S_NAME;
+ break;
+ case S_NAME:
+ case S_VALUE:
+ if ((parse_info.bufsize + (int)strlen(wordp) + 1)
+ >= parse_info.bufMaxSize) {
+ if (realloc_parse_info(strlen(wordp) + 1) == False)
+ goto err;
+ }
+ strcpy(&parse_info.buf[parse_info.bufsize], wordp);
+ parse_info.bufsize += strlen(wordp);
+ parse_info.pre_state = S_VALUE;
+ break;
+ default:
+ goto err;
+ }
+ if (wordp != word)
+ Xfree (wordp);
+ return len;
+
+err:
+ if (wordp != word)
+ Xfree (wordp);
+ return 0;
+}
+
+/************************************************************************/
+
+#ifdef DEBUG
+static void
+PrintDatabase(
+ Database db)
+{
+ Database p = db;
+ int i = 0, j;
+
+ printf("***\n*** BEGIN Database\n***\n");
+ while (p) {
+ printf("%3d: ", i++);
+ printf("%s, %s, ", p->category, p->name);
+ printf("\t[%d: ", p->value_num);
+ for (j = 0; j < p->value_num; ++j) {
+ printf("%s, ", p->value[j]);
+ }
+ printf("]\n");
+ p = p->next;
+ }
+ printf("***\n*** END Database\n***\n");
+}
+#endif
+
+static void
+DestroyDatabase(
+ Database db)
+{
+ Database p = db;
+
+ while (p) {
+ if (p->category != NULL) {
+ Xfree(p->category);
+ }
+ if (p->name != NULL) {
+ Xfree(p->name);
+ }
+ if (p->value != (char **)NULL) {
+ if (*p->value != NULL) {
+ Xfree(*p->value);
+ }
+ Xfree((char *)p->value);
+ }
+ db = p->next;
+ Xfree((char *)p);
+ p = db;
+ }
+}
+
+static int
+CountDatabase(
+ Database db)
+{
+ Database p = db;
+ int cnt = 0;
+
+ while (p) {
+ ++cnt;
+ p = p->next;
+ }
+ return cnt;
+}
+
+static Database
+CreateDatabase(
+ char *dbfile)
+{
+ Database db = (Database)NULL;
+ FILE *fd;
+ Line line;
+ char *p;
+ Token token;
+ int len;
+ int error = 0;
+
+ fd = _XFopenFile(dbfile, "r");
+ if (fd == (FILE *)NULL)
+ return NULL;
+
+ bzero(&line, sizeof(Line));
+ init_parse_info();
+
+ do {
+ int rc = read_line(fd, &line);
+ if (rc < 0) {
+ error = 1;
+ break;
+ } else if (rc == 0) {
+ break;
+ }
+ p = line.str;
+ while (*p) {
+ int (*parse_proc)(const char *str, Token token, Database *db) = NULL;
+
+ token = get_token(p);
+
+ switch (token_tbl[token].token) {
+ case T_NEWLINE:
+ parse_proc = f_newline;
+ break;
+ case T_COMMENT:
+ parse_proc = f_comment;
+ break;
+ case T_SEMICOLON:
+ parse_proc = f_semicolon;
+ break;
+ case T_DOUBLE_QUOTE:
+ parse_proc = f_double_quote;
+ break;
+ case T_LEFT_BRACE:
+ parse_proc = f_left_brace;
+ break;
+ case T_RIGHT_BRACE:
+ parse_proc = f_right_brace;
+ break;
+ case T_SPACE:
+ case T_TAB:
+ parse_proc = f_white;
+ break;
+ case T_BACKSLASH:
+ parse_proc = f_backslash;
+ break;
+ case T_NUMERIC_HEX:
+ case T_NUMERIC_DEC:
+ case T_NUMERIC_OCT:
+ parse_proc = f_numeric;
+ break;
+ case T_DEFAULT:
+ parse_proc = f_default;
+ break;
+ }
+
+ len = parse_proc(p, token, &db);
+
+ if (len < 1) {
+ error = 1;
+ break;
+ }
+ p += len;
+ }
+ } while (!error);
+
+ if (parse_info.pre_state != S_NULL) {
+ clear_parse_info();
+ error = 1;
+ }
+ if (error) {
+#ifdef DEBUG
+ fprintf(stderr, "database format error at line %d.\n", line.seq);
+#endif
+ DestroyDatabase(db);
+ db = (Database)NULL;
+ }
+
+ fclose(fd);
+ free_line(&line);
+
+#ifdef DEBUG
+ PrintDatabase(db);
+#endif
+
+ return db;
+}
+
+/************************************************************************/
+
+#ifndef NOT_X_ENV
+
+/* locale framework functions */
+
+typedef struct _XlcDatabaseRec {
+ XrmQuark category_q;
+ XrmQuark name_q;
+ Database db;
+ struct _XlcDatabaseRec *next;
+} XlcDatabaseRec, *XlcDatabase;
+
+typedef struct _XlcDatabaseListRec {
+ XrmQuark name_q;
+ XlcDatabase lc_db;
+ Database database;
+ int ref_count;
+ struct _XlcDatabaseListRec *next;
+} XlcDatabaseListRec, *XlcDatabaseList;
+
+/* database cache list (per file) */
+static XlcDatabaseList _db_list = (XlcDatabaseList)NULL;
+
+/************************************************************************/
+/* _XlcGetResource(lcd, category, class, value, count) */
+/*----------------------------------------------------------------------*/
+/* This function retrieves XLocale database information. */
+/************************************************************************/
+void
+_XlcGetResource(
+ XLCd lcd,
+ const char *category,
+ const char *class,
+ char ***value,
+ int *count)
+{
+ XLCdPublicMethodsPart *methods = XLC_PUBLIC_METHODS(lcd);
+
+ (*methods->get_resource)(lcd, category, class, value, count);
+ return;
+}
+
+/************************************************************************/
+/* _XlcGetLocaleDataBase(lcd, category, class, value, count) */
+/*----------------------------------------------------------------------*/
+/* This function retrieves XLocale database information. */
+/************************************************************************/
+void
+_XlcGetLocaleDataBase(
+ XLCd lcd,
+ const char *category,
+ const char *name,
+ char ***value,
+ int *count)
+{
+ XlcDatabase lc_db = (XlcDatabase)XLC_PUBLIC(lcd, xlocale_db);
+ XrmQuark category_q, name_q;
+
+ category_q = XrmStringToQuark(category);
+ name_q = XrmStringToQuark(name);
+ for (; lc_db->db; ++lc_db) {
+ if (category_q == lc_db->category_q && name_q == lc_db->name_q) {
+ *value = lc_db->db->value;
+ *count = lc_db->db->value_num;
+ return;
+ }
+ }
+ *value = (char **)NULL;
+ *count = 0;
+}
+
+/************************************************************************/
+/* _XlcDestroyLocaleDataBase(lcd) */
+/*----------------------------------------------------------------------*/
+/* This function destroy the XLocale Database that bound to the */
+/* specified lcd. If the XLocale Database is refered from some */
+/* other lcd, this function just decreases reference count of */
+/* the database. If no locale refers the database, this function */
+/* remove it from the cache list and free work area. */
+/************************************************************************/
+void
+_XlcDestroyLocaleDataBase(
+ XLCd lcd)
+{
+ XlcDatabase lc_db = (XlcDatabase)XLC_PUBLIC(lcd, xlocale_db);
+ XlcDatabaseList p, prev;
+
+ for (p = _db_list, prev = (XlcDatabaseList)NULL; p;
+ prev = p, p = p->next) {
+ if (p->lc_db == lc_db) {
+ if ((-- p->ref_count) < 1) {
+ if (p->lc_db != (XlcDatabase)NULL) {
+ Xfree((char *)p->lc_db);
+ }
+ DestroyDatabase(p->database);
+ if (prev == (XlcDatabaseList)NULL) {
+ _db_list = p->next;
+ } else {
+ prev->next = p->next;
+ }
+ Xfree((char*)p);
+ }
+ break;
+ }
+ }
+ XLC_PUBLIC(lcd, xlocale_db) = (XPointer)NULL;
+}
+
+/************************************************************************/
+/* _XlcCreateLocaleDataBase(lcd) */
+/*----------------------------------------------------------------------*/
+/* This function create an XLocale database which correspond to */
+/* the specified XLCd. */
+/************************************************************************/
+XPointer
+_XlcCreateLocaleDataBase(
+ XLCd lcd)
+{
+ XlcDatabaseList list, new;
+ Database p, database = (Database)NULL;
+ XlcDatabase lc_db = (XlcDatabase)NULL;
+ XrmQuark name_q;
+ char *name;
+ int i, n;
+
+ name = _XlcFileName(lcd, "locale");
+ if (name == NULL)
+ return (XPointer)NULL;
+
+#ifndef __UNIXOS2__
+ name_q = XrmStringToQuark(name);
+#else
+ name_q = XrmStringToQuark((char*)__XOS2RedirRoot(name));
+#endif
+ for (list = _db_list; list; list = list->next) {
+ if (name_q == list->name_q) {
+ list->ref_count++;
+ Xfree (name);
+ return XLC_PUBLIC(lcd, xlocale_db) = (XPointer)list->lc_db;
+ }
+ }
+
+ database = CreateDatabase(name);
+ if (database == (Database)NULL) {
+ Xfree (name);
+ return (XPointer)NULL;
+ }
+ n = CountDatabase(database);
+ lc_db = Xcalloc(n + 1, sizeof(XlcDatabaseRec));
+ if (lc_db == (XlcDatabase)NULL)
+ goto err;
+ for (p = database, i = 0; p && i < n; p = p->next, ++i) {
+ lc_db[i].category_q = XrmStringToQuark(p->category);
+ lc_db[i].name_q = XrmStringToQuark(p->name);
+ lc_db[i].db = p;
+ }
+
+ new = (XlcDatabaseList)Xmalloc(sizeof(XlcDatabaseListRec));
+ if (new == (XlcDatabaseList)NULL) {
+ goto err;
+ }
+ new->name_q = name_q;
+ new->lc_db = lc_db;
+ new->database = database;
+ new->ref_count = 1;
+ new->next = _db_list;
+ _db_list = new;
+
+ Xfree (name);
+ return XLC_PUBLIC(lcd, xlocale_db) = (XPointer)lc_db;
+
+ err:
+ DestroyDatabase(database);
+ if (lc_db != (XlcDatabase)NULL) {
+ Xfree((char *)lc_db);
+ }
+ Xfree (name);
+ return (XPointer)NULL;
+}
+
+#endif /* NOT_X_ENV */
diff --git a/libX11/src/xlibi18n/lcFile.c b/libX11/src/xlibi18n/lcFile.c
index 167943d3c..5a9b0f4ab 100644
--- a/libX11/src/xlibi18n/lcFile.c
+++ b/libX11/src/xlibi18n/lcFile.c
@@ -1,835 +1,829 @@
-/*
- *
- * Copyright IBM Corporation 1993
- *
- * All Rights Reserved
- *
- * License to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted,
- * provided that the above copyright notice appear in all copies and that
- * both that copyright notice and this permission notice appear in
- * supporting documentation, and that the name of IBM not be
- * used in advertising or publicity pertaining to distribution of the
- * software without specific, written prior permission.
- *
- * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- * ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS, AND
- * NONINFRINGEMENT OF THIRD PARTY RIGHTS, IN NO EVENT SHALL
- * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- *
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdlib.h>
-#include <stdio.h>
-#include <ctype.h>
-#include "Xlibint.h"
-#include "XlcPubI.h"
-#include <X11/Xos.h>
-#include <unistd.h>
-
-/************************************************************************/
-
-#ifdef __UNIXOS2__
-# define seteuid setuid
-#endif
-#define iscomment(ch) ((ch) == '#' || (ch) == '\0')
-#if defined(WIN32)
-#define isreadable(f) (_XAccessFile(f))
-#else
-#define isreadable(f) ((access((f), R_OK) != -1) ? 1 : 0)
-#endif
-
-#ifndef __UNIXOS2__
-#define LC_PATHDELIM ':'
-#else
-#define LC_PATHDELIM ';'
-#endif
-
-#define XLC_BUFSIZE 256
-
-#ifndef X_NOT_POSIX
-#ifdef _POSIX_SOURCE
-#include <limits.h>
-#else
-#define _POSIX_SOURCE
-#include <limits.h>
-#undef _POSIX_SOURCE
-#endif
-#endif
-#ifndef PATH_MAX
-#ifdef WIN32
-#define PATH_MAX 512
-#else
-#include <sys/param.h>
-#endif
-#ifndef PATH_MAX
-#ifdef MAXPATHLEN
-#define PATH_MAX MAXPATHLEN
-#else
-#define PATH_MAX 1024
-#endif
-#endif
-#endif
-
-#define NUM_LOCALEDIR 64
-
-/* Splits a NUL terminated line into constituents, at colons and newline
- characters. Leading whitespace is removed from constituents. The
- constituents are stored at argv[0..argsize-1]. The number of stored
- constituents (<= argsize) is returned. The line is destructively
- modified. */
-static int
-parse_line(
- char *line,
- char **argv,
- int argsize)
-{
- int argc = 0;
- char *p = line;
-
- while (argc < argsize) {
- while (isspace(*p)) {
- ++p;
- }
- if (*p == '\0') {
- break;
- }
- argv[argc++] = p;
- while (*p != ':' && *p != '\n' && *p != '\0') {
- ++p;
- }
- if (*p == '\0') {
- break;
- }
- *p++ = '\0';
- }
-
- return argc;
-}
-
-#ifdef __UNIXOS2__
-
-/* fg021216: entries in locale files are separated by colons while under
- OS/2, path entries are separated by semicolon, so we need two functions */
-
-static int
-parse_line1(
- char *line,
- char **argv,
- int argsize)
-{
- int argc = 0;
- char *p = line;
-
- while (argc < argsize) {
- while (isspace(*p)) {
- ++p;
- }
- if (*p == '\0') {
- break;
- }
- argv[argc++] = p;
- while (*p != ';' && *p != '\n' && *p != '\0') {
- ++p;
- }
- if (*p == '\0') {
- break;
- }
- *p++ = '\0';
- }
-
- return argc;
-}
-#elif defined(WIN32)
-
-/* this is parse_line but skips drive letters at the beginning of the entry */
-static int
-parse_line1(
- char *line,
- char **argv,
- int argsize)
-{
- int argc = 0;
- char *p = line;
-
- while (argc < argsize) {
- while (isspace(*p)) {
- ++p;
- }
- if (*p == '\0') {
- break;
- }
- argv[argc++] = p;
- if (isalpha(*p) && p[1] == ':') {
- p+= 2; /* skip drive letters */
- }
- while (*p != ':' && *p != '\n' && *p != '\0') {
- ++p;
- }
- if (*p == '\0') {
- break;
- }
- *p++ = '\0';
- }
-
- return argc;
-}
-
-#endif /* __UNIXOS2__ */
-
-/* Splits a colon separated list of directories, and returns the constituent
- paths (without trailing slash). At most argsize constituents are stored
- at argv[0..argsize-1]. The number of stored constituents is returned. */
-static int
-_XlcParsePath(
- char *path,
- char **argv,
- int argsize)
-{
- char *p = path;
- int n, i;
-
-#if !defined(__UNIXOS2__) && !defined(WIN32)
- n = parse_line(path, argv, argsize);
-#else
- n = parse_line1(path, argv, argsize);
-#endif
- for (i = 0; i < n; ++i) {
- int len;
- p = argv[i];
- len = strlen(p);
- if (len > 0 && p[len - 1] == '/') {
- /* eliminate trailing slash */
- p[len - 1] = '\0';
- }
- }
- return n;
-}
-
-#ifndef XLOCALEDIR
-#define XLOCALEDIR "locale"
-#endif
-
-void
-xlocaledir(
- char *buf,
- int buf_len)
-{
- char *p = buf;
- int len = 0;
-
-#ifndef NO_XLOCALEDIR
- char *dir;
- int priv = 1;
-
- dir = getenv("XLOCALEDIR");
-
- if (dir) {
-#ifndef WIN32
- /*
- * Only use the user-supplied path if the process isn't priviledged.
- */
- if (getuid() == geteuid() && getgid() == getegid()) {
-#if defined(HASSETUGID)
- priv = issetugid();
-#elif defined(HASGETRESUID)
- {
- uid_t ruid, euid, suid;
- gid_t rgid, egid, sgid;
- if ((getresuid(&ruid, &euid, &suid) == 0) &&
- (getresgid(&rgid, &egid, &sgid) == 0))
- priv = (euid != suid) || (egid != sgid);
- }
-#else
- /*
- * If there are saved ID's the process might still be priviledged
- * even though the above test succeeded. If issetugid() and
- * getresgid() aren't available, test this by trying to set
- * euid to 0.
- *
- * Note: this only protects setuid-root clients. It doesn't
- * protect other setuid or any setgid clients. If this tradeoff
- * isn't acceptable, set DisableXLocaleDirEnv to YES in host.def.
- */
- unsigned int oldeuid;
- oldeuid = geteuid();
- if (seteuid(0) != 0) {
- priv = 0;
- } else {
- if (seteuid(oldeuid) == -1) {
- /* XXX ouch, coudn't get back to original uid
- what can we do ??? */
- _exit(127);
- }
- priv = 1;
- }
-#endif
- }
-#else
- priv = 0;
-#endif
- if (!priv) {
- len = strlen(dir);
- strncpy(p, dir, buf_len);
- if (len < buf_len) {
- p[len++] = LC_PATHDELIM;
- p += len;
- }
- }
- }
-#endif /* NO_XLOCALEDIR */
-
- if (len < buf_len)
-#ifndef __UNIXOS2__
- strncpy(p, XLOCALEDIR, buf_len - len);
-#else
- strncpy(p,__XOS2RedirRoot(XLOCALEDIR), buf_len - len);
-#endif
- buf[buf_len-1] = '\0';
-}
-
-static void
-xlocalelibdir(
- char *buf,
- int buf_len)
-{
- char *p = buf;
- int len = 0;
-
-#ifndef NO_XLOCALEDIR
- char *dir;
- int priv = 1;
-
- dir = getenv("XLOCALELIBDIR");
-
- if (dir) {
-#ifndef WIN32
- /*
- * Only use the user-supplied path if the process isn't priviledged.
- */
- if (getuid() == geteuid() && getgid() == getegid()) {
-#if defined(HASSETUGID)
- priv = issetugid();
-#elif defined(HASGETRESUID)
- {
- uid_t ruid, euid, suid;
- gid_t rgid, egid, sgid;
- if ((getresuid(&ruid, &euid, &suid) == 0) &&
- (getresgid(&rgid, &egid, &sgid) == 0))
- priv = (euid != suid) || (egid != sgid);
- }
-#else
- /*
- * If there are saved ID's the process might still be priviledged
- * even though the above test succeeded. If issetugid() and
- * getresgid() aren't available, test this by trying to set
- * euid to 0.
- *
- * Note: this only protects setuid-root clients. It doesn't
- * protect other setuid or any setgid clients. If this tradeoff
- * isn't acceptable, set DisableXLocaleDirEnv to YES in host.def.
- */
- unsigned int oldeuid;
- oldeuid = geteuid();
- if (seteuid(0) != 0) {
- priv = 0;
- } else {
- if (seteuid(oldeuid) == -1) {
- /* XXX ouch, coudn't get back to original uid
- what can we do ??? */
- _exit(127);
- }
- priv = 1;
- }
-#endif
- }
-#else
- priv = 0;
-#endif
- if (!priv) {
- len = strlen(dir);
- strncpy(p, dir, buf_len);
- if (len < buf_len) {
- p[len++] = LC_PATHDELIM;
- p += len;
- }
- }
- }
-#endif /* NO_XLOCALEDIR */
-
- if (len < buf_len)
-#ifndef __UNIXOS2__
- strncpy(p, XLOCALELIBDIR, buf_len - len);
-#else
- strncpy(p,__XOS2RedirRoot(XLOCALELIBDIR), buf_len - len);
-#endif
- buf[buf_len-1] = '\0';
-}
-
-/* Mapping direction */
-typedef enum {
- LtoR, /* Map first field to second field */
- RtoL /* Map second field to first field */
-} MapDirection;
-
-static char *
-resolve_name(
- const char *lc_name,
- char *file_name,
- MapDirection direction)
-{
- FILE *fp;
- char buf[XLC_BUFSIZE], *name = NULL;
-
- fp = _XFopenFile (file_name, "r");
- if (fp == NULL)
- return NULL;
-
- while (fgets(buf, XLC_BUFSIZE, fp) != NULL) {
- char *p = buf;
- int n;
- char *args[2], *from, *to;
-#ifdef __UNIXOS2__ /* Take out CR under OS/2 */
- int len;
-
- len = strlen(p);
- if (len > 1) {
- if (*(p+len-2) == '\r' && *(p+len-1) == '\n') {
- *(p+len-2) = '\n';
- *(p+len-1) = '\0';
- }
- }
-#endif
- while (isspace(*p)) {
- ++p;
- }
- if (iscomment(*p)) {
- continue;
- }
- n = parse_line(p, args, 2); /* get first 2 fields */
- if (n != 2) {
- continue;
- }
- if (direction == LtoR) {
- from = args[0], to = args[1]; /* left to right */
- } else {
- from = args[1], to = args[0]; /* right to left */
- }
- if (! strcmp(from, lc_name)) {
- name = Xmalloc(strlen(to) + 1);
- if (name != NULL) {
- strcpy(name, to);
- }
- break;
- }
- }
- fclose(fp);
- return name;
-}
-
-#define c_tolower(ch) ((ch) >= 'A' && (ch) <= 'Z' ? (ch) - 'A' + 'a' : (ch))
-
-static char *
-lowercase(
- char *dst,
- const char *src)
-{
- const char *s;
- char *t;
-
- for (s = src, t = dst; *s; ++s, ++t)
- *t = c_tolower(*s);
- *t = '\0';
- return dst;
-}
-
-/*
- * normalize_lcname(): remove any '_' and '-' and convert any character
- * to lower case after the <language>_<territory> part. If result is identical
- * to argument, free result and
- * return NULL.
- */
-static char *
-normalize_lcname (const char *name)
-{
- char *p, *ret;
- const char *tmp = name;
-
- p = ret = Xmalloc(strlen(name) + 1);
- if (!p)
- return NULL;
-
- if (tmp) {
- while (*tmp && *tmp != '.' && *tmp != '@')
- *p++ = *tmp++;
- while (*tmp) {
- if (*tmp != '-')
- *p++ = c_tolower(*tmp);
- tmp++;
- }
- }
- *p = '\0';
-
- if (strcmp(ret, name) == 0) {
- Xfree(ret);
- return NULL;
- }
-
- return ret;
-}
-
-/************************************************************************/
-char *
-_XlcFileName(
- XLCd lcd,
- const char *category)
-{
- char *siname;
- char cat[XLC_BUFSIZE], dir[XLC_BUFSIZE];
- int i, n;
- char *args[NUM_LOCALEDIR];
- char *file_name = NULL;
-
- if (lcd == (XLCd)NULL)
- return NULL;
-
- siname = XLC_PUBLIC(lcd, siname);
-
- if (category)
- lowercase(cat, category);
- else
- cat[0] = '\0';
- xlocaledir(dir,XLC_BUFSIZE);
- n = _XlcParsePath(dir, args, NUM_LOCALEDIR);
- for (i = 0; i < n; ++i) {
- char buf[PATH_MAX], *name;
-
- name = NULL;
- if ((5 + (args[i] ? strlen (args[i]) : 0) + strlen(cat)) < PATH_MAX) {
- sprintf(buf, "%s/%s.dir", args[i], cat);
- name = resolve_name(siname, buf, RtoL);
- }
- if (name == NULL) {
- continue;
- }
- if (*name == '/') {
- /* supposed to be absolute path name */
- file_name = name;
- } else {
- file_name = Xmalloc(2 + (args[i] ? strlen (args[i]) : 0) +
- (name ? strlen (name) : 0));
- if (file_name != NULL)
- sprintf(file_name, "%s/%s", args[i], name);
- Xfree(name);
- }
- if (isreadable(file_name)) {
- break;
- }
- Xfree(file_name);
- file_name = NULL;
- /* Then, try with next dir */
- }
- return file_name;
-}
-
-/************************************************************************/
-#ifndef LOCALE_ALIAS
-#define LOCALE_ALIAS "locale.alias"
-#endif
-
-int
-_XlcResolveLocaleName(
- const char* lc_name,
- XLCdPublicPart* pub)
-{
- char dir[PATH_MAX], buf[PATH_MAX], *name = NULL;
- char *dst;
- int i, n, sinamelen;
- char *args[NUM_LOCALEDIR];
- static const char locale_alias[] = LOCALE_ALIAS;
- char *tmp_siname;
- char *nlc_name = NULL;
-
- xlocaledir (dir, PATH_MAX);
- n = _XlcParsePath(dir, args, NUM_LOCALEDIR);
- for (i = 0; i < n; ++i) {
- if ((2 + (args[i] ? strlen (args[i]) : 0) +
- strlen (locale_alias)) < PATH_MAX) {
- sprintf (buf, "%s/%s", args[i], locale_alias);
- name = resolve_name (lc_name, buf, LtoR);
- if (!name) {
- if (!nlc_name)
- nlc_name = normalize_lcname(lc_name);
- if (nlc_name)
- name = resolve_name (nlc_name, buf, LtoR);
- }
- }
- if (name != NULL) {
- break;
- }
- }
- if (nlc_name) Xfree(nlc_name);
-
- if (name == NULL) {
- /* vendor locale name == Xlocale name, no expansion of alias */
- pub->siname = Xmalloc (strlen (lc_name) + 1);
- strcpy (pub->siname, lc_name);
- } else {
- pub->siname = name;
- }
-
- sinamelen = strlen (pub->siname);
- if (sinamelen == 1 && pub->siname[0] == 'C') {
- pub->language = pub->siname;
- pub->territory = pub->codeset = NULL;
- return 1;
- }
-
- /*
- * pub->siname is in the format <lang>_<terr>.<codeset>, typical would
- * be "en_US.ISO8859-1", "en_US.utf8", "ru_RU.KOI-8", or ja_JP.SJIS,
- * although it could be ja.SJIS too.
- */
- tmp_siname = Xrealloc (pub->siname, 2 * (sinamelen + 1));
- if (tmp_siname == NULL) {
- return 0;
- }
- pub->siname = tmp_siname;
-
- /* language */
- dst = &pub->siname[sinamelen + 1];
- strcpy (dst, pub->siname);
- pub->language = dst;
-
- /* territory */
- dst = strchr (dst, '_');
- if (dst) {
- *dst = '\0';
- pub->territory = ++dst;
- } else
- dst = &pub->siname[sinamelen + 1];
-
- /* codeset */
- dst = strchr (dst, '.');
- if (dst) {
- *dst = '\0';
- pub->codeset = ++dst;
- }
-
- return (pub->siname[0] != '\0') ? 1 : 0;
-}
-
-/************************************************************************/
-int
-_XlcResolveI18NPath(char *buf, int buf_len)
-{
- if (buf != NULL) {
- xlocaledir(buf, buf_len);
- }
- return 1;
-}
-
-char *
-_XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name)
-{
- char dir[PATH_MAX], buf[PATH_MAX], *name = NULL;
- int i, n;
- char *args[NUM_LOCALEDIR];
- static char locale_alias[] = LOCALE_ALIAS;
- char *target_name = (char*)0;
- char *target_dir = (char*)0;
- char *nlc_name = NULL;
- static char* last_dir_name = 0;
- static size_t last_dir_len = 0;
- static char* last_lc_name = 0;
-
- if (last_lc_name != 0 && strcmp (last_lc_name, lc_name) == 0
- && dir_len >= last_dir_len) {
- strcpy (dir_name, last_dir_name);
- return dir_name;
- }
-
- xlocaledir (dir, PATH_MAX);
- n = _XlcParsePath(dir, args, 256);
- for (i = 0; i < n; ++i) {
-
- if ((2 + (args[i] ? strlen(args[i]) : 0) +
- strlen(locale_alias)) < PATH_MAX) {
- sprintf (buf, "%s/%s", args[i], locale_alias);
- name = resolve_name(lc_name, buf, LtoR);
- if (!name) {
- if (!nlc_name)
- nlc_name = normalize_lcname(lc_name);
- if (nlc_name)
- name = resolve_name (nlc_name, buf, LtoR);
- }
- }
-
- /* If name is not an alias, use lc_name for locale.dir search */
- if (name == NULL)
- name = lc_name;
-
- /* look at locale.dir */
-
- target_dir = args[i];
- if (!target_dir) {
- /* something wrong */
- if (name != lc_name)
- Xfree(name);
- continue;
- }
- if ((1 + strlen (target_dir) + strlen("locale.dir")) < PATH_MAX) {
- sprintf(buf, "%s/locale.dir", target_dir);
- target_name = resolve_name(name, buf, RtoL);
- }
- if (name != lc_name)
- Xfree(name);
- if (target_name != NULL) {
- char *p = 0;
- if ((p = strstr(target_name, "/XLC_LOCALE"))) {
- *p = '\0';
- break;
- }
- Xfree(target_name);
- target_name = NULL;
- }
- name = NULL;
- }
- if (nlc_name) Xfree(nlc_name);
-
- if (target_name == NULL) {
- /* vendor locale name == Xlocale name, no expansion of alias */
- target_dir = args[0];
- target_name = lc_name;
- }
- /* snprintf(dir_name, dir_len, "%s/%", target_dir, target_name); */
- strncpy(dir_name, target_dir, dir_len - 1);
- if (strlen(target_dir) >= dir_len - 1) {
- dir_name[dir_len - 1] = '\0';
- } else {
- strcat(dir_name, "/");
- strncat(dir_name, target_name, dir_len - strlen(dir_name) - 1);
- if (strlen(target_name) >= dir_len - strlen(dir_name) - 1)
- dir_name[dir_len - 1] = '\0';
- }
- if (target_name != lc_name)
- Xfree(target_name);
-
- if (last_dir_name != 0)
- Xfree (last_dir_name);
- if (last_lc_name != 0)
- Xfree (last_lc_name);
- last_dir_len = strlen (dir_name) + 1;
- last_dir_name = Xmalloc (last_dir_len);
- strcpy (last_dir_name, dir_name);
- last_lc_name = Xmalloc (strlen (lc_name) + 1);
- strcpy (last_lc_name, lc_name);
-
- return dir_name;
-}
-
-char *
-_XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name)
-{
- char dir[PATH_MAX], buf[PATH_MAX], *name = NULL;
- int i, n;
- char *args[NUM_LOCALEDIR];
- static char locale_alias[] = LOCALE_ALIAS;
- char *target_name = (char*)0;
- char *target_dir = (char*)0;
- char *nlc_name = NULL;
- static char* last_dir_name = 0;
- static size_t last_dir_len = 0;
- static char* last_lc_name = 0;
-
- if (last_lc_name != 0 && strcmp (last_lc_name, lc_name) == 0
- && dir_len >= last_dir_len) {
- strcpy (dir_name, last_dir_name);
- return dir_name;
- }
-
- xlocalelibdir (dir, PATH_MAX);
- n = _XlcParsePath(dir, args, 256);
- for (i = 0; i < n; ++i) {
-
- if ((2 + (args[i] ? strlen(args[i]) : 0) +
- strlen(locale_alias)) < PATH_MAX) {
- sprintf (buf, "%s/%s", args[i], locale_alias);
- name = resolve_name(lc_name, buf, LtoR);
- if (!name) {
- if (!nlc_name)
- nlc_name = normalize_lcname(lc_name);
- if (nlc_name)
- name = resolve_name (nlc_name, buf, LtoR);
- }
- }
-
- /* If name is not an alias, use lc_name for locale.dir search */
- if (name == NULL)
- name = lc_name;
-
- /* look at locale.dir */
-
- target_dir = args[i];
- if (!target_dir) {
- /* something wrong */
- if (name != lc_name)
- Xfree(name);
- continue;
- }
- if ((1 + strlen (target_dir) + strlen("locale.dir")) < PATH_MAX) {
- sprintf(buf, "%s/locale.dir", target_dir);
- target_name = resolve_name(name, buf, RtoL);
- }
- if (name != lc_name)
- Xfree(name);
- if (target_name != NULL) {
- char *p = 0;
- if ((p = strstr(target_name, "/XLC_LOCALE"))) {
- *p = '\0';
- break;
- }
- Xfree(target_name);
- target_name = NULL;
- }
- name = NULL;
- }
- if (nlc_name) Xfree(nlc_name);
-
- if (target_name == NULL) {
- /* vendor locale name == Xlocale name, no expansion of alias */
- target_dir = args[0];
- target_name = lc_name;
- }
- /* snprintf(dir_name, dir_len, "%s/%", target_dir, target_name); */
- strncpy(dir_name, target_dir, dir_len - 1);
- if (strlen(target_dir) >= dir_len - 1) {
- dir_name[dir_len - 1] = '\0';
- } else {
- strcat(dir_name, "/");
- strncat(dir_name, target_name, dir_len - strlen(dir_name) - 1);
- if (strlen(target_name) >= dir_len - strlen(dir_name) - 1)
- dir_name[dir_len - 1] = '\0';
- }
- if (target_name != lc_name)
- Xfree(target_name);
-
- if (last_dir_name != 0)
- Xfree (last_dir_name);
- if (last_lc_name != 0)
- Xfree (last_lc_name);
- last_dir_len = strlen (dir_name) + 1;
- last_dir_name = Xmalloc (last_dir_len);
- strcpy (last_dir_name, dir_name);
- last_lc_name = Xmalloc (strlen (lc_name) + 1);
- strcpy (last_lc_name, lc_name);
-
- return dir_name;
-}
+/*
+ *
+ * Copyright IBM Corporation 1993
+ *
+ * All Rights Reserved
+ *
+ * License to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of IBM not be
+ * used in advertising or publicity pertaining to distribution of the
+ * software without specific, written prior permission.
+ *
+ * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ * ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS, AND
+ * NONINFRINGEMENT OF THIRD PARTY RIGHTS, IN NO EVENT SHALL
+ * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>
+#include "Xlibint.h"
+#include "XlcPubI.h"
+#include <X11/Xos.h>
+#include <unistd.h>
+
+/************************************************************************/
+
+#ifdef __UNIXOS2__
+# define seteuid setuid
+#endif
+#define iscomment(ch) ((ch) == '#' || (ch) == '\0')
+#if defined(WIN32)
+#define isreadable(f) (_XAccessFile(f))
+#else
+#define isreadable(f) ((access((f), R_OK) != -1) ? 1 : 0)
+#endif
+
+#ifndef __UNIXOS2__
+#define LC_PATHDELIM ':'
+#else
+#define LC_PATHDELIM ';'
+#endif
+
+#define XLC_BUFSIZE 256
+
+#ifndef X_NOT_POSIX
+#ifdef _POSIX_SOURCE
+#include <limits.h>
+#else
+#define _POSIX_SOURCE
+#include <limits.h>
+#undef _POSIX_SOURCE
+#endif
+#endif
+#ifndef PATH_MAX
+#ifdef WIN32
+#define PATH_MAX 512
+#else
+#include <sys/param.h>
+#endif
+#ifndef PATH_MAX
+#ifdef MAXPATHLEN
+#define PATH_MAX MAXPATHLEN
+#else
+#define PATH_MAX 1024
+#endif
+#endif
+#endif
+
+#define NUM_LOCALEDIR 64
+
+/* Splits a NUL terminated line into constituents, at colons and newline
+ characters. Leading whitespace is removed from constituents. The
+ constituents are stored at argv[0..argsize-1]. The number of stored
+ constituents (<= argsize) is returned. The line is destructively
+ modified. */
+static int
+parse_line(
+ char *line,
+ char **argv,
+ int argsize)
+{
+ int argc = 0;
+ char *p = line;
+
+ while (argc < argsize) {
+ while (isspace(*p)) {
+ ++p;
+ }
+ if (*p == '\0') {
+ break;
+ }
+ argv[argc++] = p;
+ while (*p != ':' && *p != '\n' && *p != '\0') {
+ ++p;
+ }
+ if (*p == '\0') {
+ break;
+ }
+ *p++ = '\0';
+ }
+
+ return argc;
+}
+
+#ifdef __UNIXOS2__
+
+/* fg021216: entries in locale files are separated by colons while under
+ OS/2, path entries are separated by semicolon, so we need two functions */
+
+static int
+parse_line1(
+ char *line,
+ char **argv,
+ int argsize)
+{
+ int argc = 0;
+ char *p = line;
+
+ while (argc < argsize) {
+ while (isspace(*p)) {
+ ++p;
+ }
+ if (*p == '\0') {
+ break;
+ }
+ argv[argc++] = p;
+ while (*p != ';' && *p != '\n' && *p != '\0') {
+ ++p;
+ }
+ if (*p == '\0') {
+ break;
+ }
+ *p++ = '\0';
+ }
+
+ return argc;
+}
+#elif defined(WIN32)
+
+/* this is parse_line but skips drive letters at the beginning of the entry */
+static int
+parse_line1(
+ char *line,
+ char **argv,
+ int argsize)
+{
+ int argc = 0;
+ char *p = line;
+
+ while (argc < argsize) {
+ while (isspace(*p)) {
+ ++p;
+ }
+ if (*p == '\0') {
+ break;
+ }
+ argv[argc++] = p;
+ if (isalpha(*p) && p[1] == ':') {
+ p+= 2; /* skip drive letters */
+ }
+ while (*p != ':' && *p != '\n' && *p != '\0') {
+ ++p;
+ }
+ if (*p == '\0') {
+ break;
+ }
+ *p++ = '\0';
+ }
+
+ return argc;
+}
+
+#endif /* __UNIXOS2__ */
+
+/* Splits a colon separated list of directories, and returns the constituent
+ paths (without trailing slash). At most argsize constituents are stored
+ at argv[0..argsize-1]. The number of stored constituents is returned. */
+static int
+_XlcParsePath(
+ char *path,
+ char **argv,
+ int argsize)
+{
+ char *p = path;
+ int n, i;
+
+#if !defined(__UNIXOS2__) && !defined(WIN32)
+ n = parse_line(path, argv, argsize);
+#else
+ n = parse_line1(path, argv, argsize);
+#endif
+ for (i = 0; i < n; ++i) {
+ int len;
+ p = argv[i];
+ len = strlen(p);
+ if (len > 0 && p[len - 1] == '/') {
+ /* eliminate trailing slash */
+ p[len - 1] = '\0';
+ }
+ }
+ return n;
+}
+
+#ifndef XLOCALEDIR
+#define XLOCALEDIR "locale"
+#endif
+
+void
+xlocaledir(
+ char *buf,
+ int buf_len)
+{
+ char *p = buf;
+ int len = 0;
+
+#ifndef NO_XLOCALEDIR
+ char *dir;
+ int priv = 1;
+
+ dir = getenv("XLOCALEDIR");
+
+ if (dir) {
+#ifndef WIN32
+ /*
+ * Only use the user-supplied path if the process isn't priviledged.
+ */
+ if (getuid() == geteuid() && getgid() == getegid()) {
+#if defined(HASSETUGID)
+ priv = issetugid();
+#elif defined(HASGETRESUID)
+ {
+ uid_t ruid, euid, suid;
+ gid_t rgid, egid, sgid;
+ if ((getresuid(&ruid, &euid, &suid) == 0) &&
+ (getresgid(&rgid, &egid, &sgid) == 0))
+ priv = (euid != suid) || (egid != sgid);
+ }
+#else
+ /*
+ * If there are saved ID's the process might still be priviledged
+ * even though the above test succeeded. If issetugid() and
+ * getresgid() aren't available, test this by trying to set
+ * euid to 0.
+ *
+ * Note: this only protects setuid-root clients. It doesn't
+ * protect other setuid or any setgid clients. If this tradeoff
+ * isn't acceptable, set DisableXLocaleDirEnv to YES in host.def.
+ */
+ unsigned int oldeuid;
+ oldeuid = geteuid();
+ if (seteuid(0) != 0) {
+ priv = 0;
+ } else {
+ if (seteuid(oldeuid) == -1) {
+ /* XXX ouch, coudn't get back to original uid
+ what can we do ??? */
+ _exit(127);
+ }
+ priv = 1;
+ }
+#endif
+ }
+#else
+ priv = 0;
+#endif
+ if (!priv) {
+ len = strlen(dir);
+ strncpy(p, dir, buf_len);
+ if (len < buf_len) {
+ p[len++] = LC_PATHDELIM;
+ p += len;
+ }
+ }
+ }
+#endif /* NO_XLOCALEDIR */
+
+ if (len < buf_len)
+#ifndef __UNIXOS2__
+ strncpy(p, XLOCALEDIR, buf_len - len);
+#else
+ strncpy(p,__XOS2RedirRoot(XLOCALEDIR), buf_len - len);
+#endif
+ buf[buf_len-1] = '\0';
+}
+
+static void
+xlocalelibdir(
+ char *buf,
+ int buf_len)
+{
+ char *p = buf;
+ int len = 0;
+
+#ifndef NO_XLOCALEDIR
+ char *dir;
+ int priv = 1;
+
+ dir = getenv("XLOCALELIBDIR");
+
+ if (dir) {
+#ifndef WIN32
+ /*
+ * Only use the user-supplied path if the process isn't priviledged.
+ */
+ if (getuid() == geteuid() && getgid() == getegid()) {
+#if defined(HASSETUGID)
+ priv = issetugid();
+#elif defined(HASGETRESUID)
+ {
+ uid_t ruid, euid, suid;
+ gid_t rgid, egid, sgid;
+ if ((getresuid(&ruid, &euid, &suid) == 0) &&
+ (getresgid(&rgid, &egid, &sgid) == 0))
+ priv = (euid != suid) || (egid != sgid);
+ }
+#else
+ /*
+ * If there are saved ID's the process might still be priviledged
+ * even though the above test succeeded. If issetugid() and
+ * getresgid() aren't available, test this by trying to set
+ * euid to 0.
+ *
+ * Note: this only protects setuid-root clients. It doesn't
+ * protect other setuid or any setgid clients. If this tradeoff
+ * isn't acceptable, set DisableXLocaleDirEnv to YES in host.def.
+ */
+ unsigned int oldeuid;
+ oldeuid = geteuid();
+ if (seteuid(0) != 0) {
+ priv = 0;
+ } else {
+ if (seteuid(oldeuid) == -1) {
+ /* XXX ouch, coudn't get back to original uid
+ what can we do ??? */
+ _exit(127);
+ }
+ priv = 1;
+ }
+#endif
+ }
+#else
+ priv = 0;
+#endif
+ if (!priv) {
+ len = strlen(dir);
+ strncpy(p, dir, buf_len);
+ if (len < buf_len) {
+ p[len++] = LC_PATHDELIM;
+ p += len;
+ }
+ }
+ }
+#endif /* NO_XLOCALEDIR */
+
+ if (len < buf_len)
+#ifndef __UNIXOS2__
+ strncpy(p, XLOCALELIBDIR, buf_len - len);
+#else
+ strncpy(p,__XOS2RedirRoot(XLOCALELIBDIR), buf_len - len);
+#endif
+ buf[buf_len-1] = '\0';
+}
+
+/* Mapping direction */
+typedef enum {
+ LtoR, /* Map first field to second field */
+ RtoL /* Map second field to first field */
+} MapDirection;
+
+static char *
+resolve_name(
+ const char *lc_name,
+ char *file_name,
+ MapDirection direction)
+{
+ FILE *fp;
+ char buf[XLC_BUFSIZE], *name = NULL;
+
+ fp = _XFopenFile (file_name, "r");
+ if (fp == NULL)
+ return NULL;
+
+ while (fgets(buf, XLC_BUFSIZE, fp) != NULL) {
+ char *p = buf;
+ int n;
+ char *args[2], *from, *to;
+#ifdef __UNIXOS2__ /* Take out CR under OS/2 */
+ int len;
+
+ len = strlen(p);
+ if (len > 1) {
+ if (*(p+len-2) == '\r' && *(p+len-1) == '\n') {
+ *(p+len-2) = '\n';
+ *(p+len-1) = '\0';
+ }
+ }
+#endif
+ while (isspace(*p)) {
+ ++p;
+ }
+ if (iscomment(*p)) {
+ continue;
+ }
+ n = parse_line(p, args, 2); /* get first 2 fields */
+ if (n != 2) {
+ continue;
+ }
+ if (direction == LtoR) {
+ from = args[0], to = args[1]; /* left to right */
+ } else {
+ from = args[1], to = args[0]; /* right to left */
+ }
+ if (! strcmp(from, lc_name)) {
+ name = strdup(to);
+ break;
+ }
+ }
+ fclose(fp);
+ return name;
+}
+
+#define c_tolower(ch) ((ch) >= 'A' && (ch) <= 'Z' ? (ch) - 'A' + 'a' : (ch))
+
+static char *
+lowercase(
+ char *dst,
+ const char *src)
+{
+ const char *s;
+ char *t;
+
+ for (s = src, t = dst; *s; ++s, ++t)
+ *t = c_tolower(*s);
+ *t = '\0';
+ return dst;
+}
+
+/*
+ * normalize_lcname(): remove any '_' and '-' and convert any character
+ * to lower case after the <language>_<territory> part. If result is identical
+ * to argument, free result and
+ * return NULL.
+ */
+static char *
+normalize_lcname (const char *name)
+{
+ char *p, *ret;
+ const char *tmp = name;
+
+ p = ret = Xmalloc(strlen(name) + 1);
+ if (!p)
+ return NULL;
+
+ if (tmp) {
+ while (*tmp && *tmp != '.' && *tmp != '@')
+ *p++ = *tmp++;
+ while (*tmp) {
+ if (*tmp != '-')
+ *p++ = c_tolower(*tmp);
+ tmp++;
+ }
+ }
+ *p = '\0';
+
+ if (strcmp(ret, name) == 0) {
+ Xfree(ret);
+ return NULL;
+ }
+
+ return ret;
+}
+
+/************************************************************************/
+char *
+_XlcFileName(
+ XLCd lcd,
+ const char *category)
+{
+ char *siname;
+ char cat[XLC_BUFSIZE], dir[XLC_BUFSIZE];
+ int i, n;
+ char *args[NUM_LOCALEDIR];
+ char *file_name = NULL;
+
+ if (lcd == (XLCd)NULL)
+ return NULL;
+
+ siname = XLC_PUBLIC(lcd, siname);
+
+ if (category)
+ lowercase(cat, category);
+ else
+ cat[0] = '\0';
+ xlocaledir(dir,XLC_BUFSIZE);
+ n = _XlcParsePath(dir, args, NUM_LOCALEDIR);
+ for (i = 0; i < n; ++i) {
+ char buf[PATH_MAX], *name;
+
+ name = NULL;
+ if ((5 + (args[i] ? strlen (args[i]) : 0) + strlen(cat)) < PATH_MAX) {
+ sprintf(buf, "%s/%s.dir", args[i], cat);
+ name = resolve_name(siname, buf, RtoL);
+ }
+ if (name == NULL) {
+ continue;
+ }
+ if (*name == '/') {
+ /* supposed to be absolute path name */
+ file_name = name;
+ } else {
+ file_name = Xmalloc(2 + (args[i] ? strlen (args[i]) : 0) +
+ (name ? strlen (name) : 0));
+ if (file_name != NULL)
+ sprintf(file_name, "%s/%s", args[i], name);
+ Xfree(name);
+ }
+ if (isreadable(file_name)) {
+ break;
+ }
+ Xfree(file_name);
+ file_name = NULL;
+ /* Then, try with next dir */
+ }
+ return file_name;
+}
+
+/************************************************************************/
+#ifndef LOCALE_ALIAS
+#define LOCALE_ALIAS "locale.alias"
+#endif
+
+int
+_XlcResolveLocaleName(
+ const char* lc_name,
+ XLCdPublicPart* pub)
+{
+ char dir[PATH_MAX], buf[PATH_MAX], *name = NULL;
+ char *dst;
+ int i, n, sinamelen;
+ char *args[NUM_LOCALEDIR];
+ static const char locale_alias[] = LOCALE_ALIAS;
+ char *tmp_siname;
+ char *nlc_name = NULL;
+
+ xlocaledir (dir, PATH_MAX);
+ n = _XlcParsePath(dir, args, NUM_LOCALEDIR);
+ for (i = 0; i < n; ++i) {
+ if ((2 + (args[i] ? strlen (args[i]) : 0) +
+ strlen (locale_alias)) < PATH_MAX) {
+ sprintf (buf, "%s/%s", args[i], locale_alias);
+ name = resolve_name (lc_name, buf, LtoR);
+ if (!name) {
+ if (!nlc_name)
+ nlc_name = normalize_lcname(lc_name);
+ if (nlc_name)
+ name = resolve_name (nlc_name, buf, LtoR);
+ }
+ }
+ if (name != NULL) {
+ break;
+ }
+ }
+ if (nlc_name) Xfree(nlc_name);
+
+ if (name == NULL) {
+ /* vendor locale name == Xlocale name, no expansion of alias */
+ pub->siname = strdup (lc_name);
+ } else {
+ pub->siname = name;
+ }
+
+ sinamelen = strlen (pub->siname);
+ if (sinamelen == 1 && pub->siname[0] == 'C') {
+ pub->language = pub->siname;
+ pub->territory = pub->codeset = NULL;
+ return 1;
+ }
+
+ /*
+ * pub->siname is in the format <lang>_<terr>.<codeset>, typical would
+ * be "en_US.ISO8859-1", "en_US.utf8", "ru_RU.KOI-8", or ja_JP.SJIS,
+ * although it could be ja.SJIS too.
+ */
+ tmp_siname = Xrealloc (pub->siname, 2 * (sinamelen + 1));
+ if (tmp_siname == NULL) {
+ return 0;
+ }
+ pub->siname = tmp_siname;
+
+ /* language */
+ dst = &pub->siname[sinamelen + 1];
+ strcpy (dst, pub->siname);
+ pub->language = dst;
+
+ /* territory */
+ dst = strchr (dst, '_');
+ if (dst) {
+ *dst = '\0';
+ pub->territory = ++dst;
+ } else
+ dst = &pub->siname[sinamelen + 1];
+
+ /* codeset */
+ dst = strchr (dst, '.');
+ if (dst) {
+ *dst = '\0';
+ pub->codeset = ++dst;
+ }
+
+ return (pub->siname[0] != '\0') ? 1 : 0;
+}
+
+/************************************************************************/
+int
+_XlcResolveI18NPath(char *buf, int buf_len)
+{
+ if (buf != NULL) {
+ xlocaledir(buf, buf_len);
+ }
+ return 1;
+}
+
+char *
+_XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name)
+{
+ char dir[PATH_MAX], buf[PATH_MAX], *name = NULL;
+ int i, n;
+ char *args[NUM_LOCALEDIR];
+ static char locale_alias[] = LOCALE_ALIAS;
+ char *target_name = (char*)0;
+ char *target_dir = (char*)0;
+ char *nlc_name = NULL;
+ static char* last_dir_name = 0;
+ static size_t last_dir_len = 0;
+ static char* last_lc_name = 0;
+
+ if (last_lc_name != 0 && strcmp (last_lc_name, lc_name) == 0
+ && dir_len >= last_dir_len) {
+ strcpy (dir_name, last_dir_name);
+ return dir_name;
+ }
+
+ xlocaledir (dir, PATH_MAX);
+ n = _XlcParsePath(dir, args, 256);
+ for (i = 0; i < n; ++i) {
+
+ if ((2 + (args[i] ? strlen(args[i]) : 0) +
+ strlen(locale_alias)) < PATH_MAX) {
+ sprintf (buf, "%s/%s", args[i], locale_alias);
+ name = resolve_name(lc_name, buf, LtoR);
+ if (!name) {
+ if (!nlc_name)
+ nlc_name = normalize_lcname(lc_name);
+ if (nlc_name)
+ name = resolve_name (nlc_name, buf, LtoR);
+ }
+ }
+
+ /* If name is not an alias, use lc_name for locale.dir search */
+ if (name == NULL)
+ name = lc_name;
+
+ /* look at locale.dir */
+
+ target_dir = args[i];
+ if (!target_dir) {
+ /* something wrong */
+ if (name != lc_name)
+ Xfree(name);
+ continue;
+ }
+ if ((1 + strlen (target_dir) + strlen("locale.dir")) < PATH_MAX) {
+ sprintf(buf, "%s/locale.dir", target_dir);
+ target_name = resolve_name(name, buf, RtoL);
+ }
+ if (name != lc_name)
+ Xfree(name);
+ if (target_name != NULL) {
+ char *p = 0;
+ if ((p = strstr(target_name, "/XLC_LOCALE"))) {
+ *p = '\0';
+ break;
+ }
+ Xfree(target_name);
+ target_name = NULL;
+ }
+ name = NULL;
+ }
+ if (nlc_name) Xfree(nlc_name);
+
+ if (target_name == NULL) {
+ /* vendor locale name == Xlocale name, no expansion of alias */
+ target_dir = args[0];
+ target_name = lc_name;
+ }
+ /* snprintf(dir_name, dir_len, "%s/%", target_dir, target_name); */
+ strncpy(dir_name, target_dir, dir_len - 1);
+ if (strlen(target_dir) >= dir_len - 1) {
+ dir_name[dir_len - 1] = '\0';
+ } else {
+ strcat(dir_name, "/");
+ strncat(dir_name, target_name, dir_len - strlen(dir_name) - 1);
+ if (strlen(target_name) >= dir_len - strlen(dir_name) - 1)
+ dir_name[dir_len - 1] = '\0';
+ }
+ if (target_name != lc_name)
+ Xfree(target_name);
+
+ if (last_dir_name != 0)
+ Xfree (last_dir_name);
+ if (last_lc_name != 0)
+ Xfree (last_lc_name);
+ last_dir_len = strlen (dir_name) + 1;
+ last_dir_name = Xmalloc (last_dir_len);
+ strcpy (last_dir_name, dir_name);
+ last_lc_name = strdup (lc_name);
+
+ return dir_name;
+}
+
+char *
+_XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name)
+{
+ char dir[PATH_MAX], buf[PATH_MAX], *name = NULL;
+ int i, n;
+ char *args[NUM_LOCALEDIR];
+ static char locale_alias[] = LOCALE_ALIAS;
+ char *target_name = (char*)0;
+ char *target_dir = (char*)0;
+ char *nlc_name = NULL;
+ static char* last_dir_name = 0;
+ static size_t last_dir_len = 0;
+ static char* last_lc_name = 0;
+
+ if (last_lc_name != 0 && strcmp (last_lc_name, lc_name) == 0
+ && dir_len >= last_dir_len) {
+ strcpy (dir_name, last_dir_name);
+ return dir_name;
+ }
+
+ xlocalelibdir (dir, PATH_MAX);
+ n = _XlcParsePath(dir, args, 256);
+ for (i = 0; i < n; ++i) {
+
+ if ((2 + (args[i] ? strlen(args[i]) : 0) +
+ strlen(locale_alias)) < PATH_MAX) {
+ sprintf (buf, "%s/%s", args[i], locale_alias);
+ name = resolve_name(lc_name, buf, LtoR);
+ if (!name) {
+ if (!nlc_name)
+ nlc_name = normalize_lcname(lc_name);
+ if (nlc_name)
+ name = resolve_name (nlc_name, buf, LtoR);
+ }
+ }
+
+ /* If name is not an alias, use lc_name for locale.dir search */
+ if (name == NULL)
+ name = lc_name;
+
+ /* look at locale.dir */
+
+ target_dir = args[i];
+ if (!target_dir) {
+ /* something wrong */
+ if (name != lc_name)
+ Xfree(name);
+ continue;
+ }
+ if ((1 + strlen (target_dir) + strlen("locale.dir")) < PATH_MAX) {
+ sprintf(buf, "%s/locale.dir", target_dir);
+ target_name = resolve_name(name, buf, RtoL);
+ }
+ if (name != lc_name)
+ Xfree(name);
+ if (target_name != NULL) {
+ char *p = 0;
+ if ((p = strstr(target_name, "/XLC_LOCALE"))) {
+ *p = '\0';
+ break;
+ }
+ Xfree(target_name);
+ target_name = NULL;
+ }
+ name = NULL;
+ }
+ if (nlc_name) Xfree(nlc_name);
+
+ if (target_name == NULL) {
+ /* vendor locale name == Xlocale name, no expansion of alias */
+ target_dir = args[0];
+ target_name = lc_name;
+ }
+ /* snprintf(dir_name, dir_len, "%s/%", target_dir, target_name); */
+ strncpy(dir_name, target_dir, dir_len - 1);
+ if (strlen(target_dir) >= dir_len - 1) {
+ dir_name[dir_len - 1] = '\0';
+ } else {
+ strcat(dir_name, "/");
+ strncat(dir_name, target_name, dir_len - strlen(dir_name) - 1);
+ if (strlen(target_name) >= dir_len - strlen(dir_name) - 1)
+ dir_name[dir_len - 1] = '\0';
+ }
+ if (target_name != lc_name)
+ Xfree(target_name);
+
+ if (last_dir_name != 0)
+ Xfree (last_dir_name);
+ if (last_lc_name != 0)
+ Xfree (last_lc_name);
+ last_dir_len = strlen (dir_name) + 1;
+ last_dir_name = Xmalloc (last_dir_len);
+ strcpy (last_dir_name, dir_name);
+ last_lc_name = strdup (lc_name);
+
+ return dir_name;
+}
diff --git a/libX11/src/xlibi18n/lcGeneric.c b/libX11/src/xlibi18n/lcGeneric.c
index 688a4cfc4..ec31cb581 100644
--- a/libX11/src/xlibi18n/lcGeneric.c
+++ b/libX11/src/xlibi18n/lcGeneric.c
@@ -1,1191 +1,1180 @@
-/*
- * Copyright 1992, 1993 by TOSHIBA Corp.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of TOSHIBA not be used in advertising
- * or publicity pertaining to distribution of the software without specific,
- * written prior permission. TOSHIBA make no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
- * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- *
- * Author: Katsuhisa Yano TOSHIBA Corp.
- * mopi@osa.ilab.toshiba.co.jp
- */
-/*
- * (c) Copyright 1995 FUJITSU LIMITED
- * This is source code modified by FUJITSU LIMITED under the Joint
- * Development Agreement for the CDE/Motif PST.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include "Xlibint.h"
-#include "XlcGeneric.h"
-
-static XLCd create (const char *name, XLCdMethods methods);
-static Bool initialize (XLCd lcd);
-static void destroy (XLCd lcd);
-
-static XLCdPublicMethodsRec genericMethods = {
- { NULL }, /* use default methods */
- {
- NULL,
- create,
- initialize,
- destroy,
- NULL
- }
-};
-
-XLCdMethods _XlcGenericMethods = (XLCdMethods) &genericMethods;
-
-static XLCd
-create(
- const char *name,
- XLCdMethods methods)
-{
- XLCd lcd;
- XLCdPublicMethods new;
-
- lcd = (XLCd) Xmalloc(sizeof(XLCdRec));
- if (lcd == NULL)
- return (XLCd) NULL;
- bzero((char *) lcd, sizeof(XLCdRec));
-
- lcd->core = (XLCdCore) Xmalloc(sizeof(XLCdGenericRec));
- if (lcd->core == NULL)
- goto err;
- bzero((char *) lcd->core, sizeof(XLCdGenericRec));
-
- new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec));
- if (new == NULL)
- goto err;
- memcpy(new,methods,sizeof(XLCdPublicMethodsRec));
- lcd->methods = (XLCdMethods) new;
-
- return lcd;
-
-err:
- Xfree(lcd);
- return (XLCd) NULL;
-}
-
-static Bool
-string_to_encoding(
- const char *str,
- char *encoding)
-{
- char *next;
- long value;
- int base;
-
- while (*str) {
- if (*str == '\\') {
- switch (*(str + 1)) {
- case 'x':
- case 'X':
- base = 16;
- break;
- default:
- base = 8;
- break;
- }
- value = strtol(str + 2, &next, base);
- if (str + 2 != next) {
- *((unsigned char *) encoding++) = (unsigned char) value;
- str = next;
- continue;
- }
- }
- *encoding++ = *str++;
- }
-
- *encoding = '\0';
-
- return True;
-}
-
-static Bool
-string_to_ulong(
- const char *str,
- unsigned long *value)
-{
- const char *tmp1 = str;
- int base;
-
- if (*tmp1++ != '\\') {
- tmp1--;
- base = 10;
- } else {
- switch (*tmp1++) {
- case 'x':
- base = 16;
- break;
- case 'o':
- base = 8;
- break;
- case 'd':
- base = 10;
- break;
- default:
- return(False);
- }
- }
- *value = (unsigned long) strtol(tmp1, NULL, base);
- return(True);
-}
-
-
-static Bool
-add_charset(
- CodeSet codeset,
- XlcCharSet charset)
-{
- XlcCharSet *new_list;
- int num;
-
- if ((num = codeset->num_charsets))
- new_list = (XlcCharSet *) Xrealloc(codeset->charset_list,
- (num + 1) * sizeof(XlcCharSet));
- else
- new_list = (XlcCharSet *) Xmalloc(sizeof(XlcCharSet));
-
- if (new_list == NULL)
- return False;
-
- new_list[num] = charset;
- codeset->charset_list = new_list;
- codeset->num_charsets = num + 1;
-
- return True;
-}
-
-static CodeSet
-add_codeset(
- XLCdGenericPart *gen)
-{
- CodeSet new, *new_list;
- int num;
-
- new = (CodeSet) Xmalloc(sizeof(CodeSetRec));
- if (new == NULL)
- return NULL;
- bzero((char *) new, sizeof(CodeSetRec));
-
- if ((num = gen->codeset_num))
- new_list = (CodeSet *) Xrealloc(gen->codeset_list,
- (num + 1) * sizeof(CodeSet));
- else
- new_list = (CodeSet *) Xmalloc(sizeof(CodeSet));
-
- if (new_list == NULL)
- goto err;
-
- new_list[num] = new;
- gen->codeset_list = new_list;
- gen->codeset_num = num + 1;
-
- return new;
-
-err:
- Xfree(new);
-
- return NULL;
-}
-
-static Bool
-add_parse_list(
- XLCdGenericPart *gen,
- EncodingType type,
- const char *encoding,
- CodeSet codeset)
-{
- ParseInfo new, *new_list;
- char *str;
- unsigned char ch;
- int num;
-
- str = (char *) Xmalloc(strlen(encoding) + 1);
- if (str == NULL)
- return False;
- strcpy(str, encoding);
-
- new = (ParseInfo) Xmalloc(sizeof(ParseInfoRec));
- if (new == NULL)
- goto err;
- bzero((char *) new, sizeof(ParseInfoRec));
-
- if (gen->mb_parse_table == NULL) {
- gen->mb_parse_table = (unsigned char *) Xmalloc(256); /* 2^8 */
- if (gen->mb_parse_table == NULL)
- goto err;
- bzero((char *) gen->mb_parse_table, 256);
- }
-
- if ((num = gen->mb_parse_list_num))
- new_list = (ParseInfo *) Xrealloc(gen->mb_parse_list,
- (num + 2) * sizeof(ParseInfo));
- else {
- new_list = (ParseInfo *) Xmalloc(2 * sizeof(ParseInfo));
- }
-
- if (new_list == NULL)
- goto err;
-
- new_list[num] = new;
- new_list[num + 1] = NULL;
- gen->mb_parse_list = new_list;
- gen->mb_parse_list_num = num + 1;
-
- ch = (unsigned char) *str;
- if (gen->mb_parse_table[ch] == 0)
- gen->mb_parse_table[ch] = num + 1;
-
- new->type = type;
- new->encoding = str;
- new->codeset = codeset;
-
- if (codeset->parse_info == NULL)
- codeset->parse_info = new;
-
- return True;
-
-err:
- Xfree(str);
- if (new)
- Xfree(new);
-
- return False;
-}
-
-static void
-free_charset(
- XLCd lcd)
-{
- XLCdGenericPart *gen = XLC_GENERIC_PART(lcd);
- ParseInfo *parse_info;
- int num;
-
- if (gen->mb_parse_table)
- Xfree(gen->mb_parse_table);
- if ((num = gen->mb_parse_list_num) > 0) {
- for (parse_info = gen->mb_parse_list; num-- > 0; parse_info++) {
- if ((*parse_info)->encoding)
- Xfree((*parse_info)->encoding);
- Xfree(*parse_info);
- }
- Xfree(gen->mb_parse_list);
- }
-
- if ((num = gen->codeset_num) > 0)
- Xfree(gen->codeset_list);
-}
-
-/* For VW/UDC */
-
-#define FORWARD (unsigned long)'+'
-#define BACKWARD (unsigned long)'-'
-
-static const char *
-getscope(
- const char *str,
- FontScope scp)
-{
- unsigned long start = 0;
- unsigned long end = 0;
- unsigned long dest = 0;
- unsigned long shift = 0;
- unsigned long direction = 0;
- sscanf(str,"[\\x%lx,\\x%lx]->\\x%lx", &start, &end, &dest);
- if (dest) {
- if (dest >= start) {
- shift = dest - start;
- direction = FORWARD ;
- } else {
- shift = start - dest;
- direction = BACKWARD;
- }
- }
- scp->start = start ;
- scp->end = end ;
- scp->shift = shift ;
- scp->shift_direction
- = direction ;
- /* .......... */
- while (*str) {
- if (*str == ',' && *(str+1) == '[')
- break;
- str++;
- }
- return str+1;
-}
-
-static int
-count_scopemap(
- const char *str)
-{
- const char *ptr;
- int num=0;
- for (ptr=str; *ptr; ptr++) {
- if (*ptr == ']') {
- num++;
- }
- }
- return num;
-}
-
-FontScope
-_XlcParse_scopemaps(
- const char *str,
- int *size)
-{
- int num=0,i;
- FontScope scope,sc_ptr;
- const char *str_sc;
-
- num = count_scopemap(str);
- scope = (FontScope) Xmalloc(num * sizeof(FontScopeRec));
- if (scope == NULL)
- return NULL;
-
- for (i=0, str_sc=str, sc_ptr=scope; i < num; i++, sc_ptr++) {
- str_sc = getscope(str_sc, sc_ptr);
- }
- *size = num;
- return scope;
-}
-
-void
-_XlcDbg_printValue(
- const char *str,
- char **value,
- int num)
-{
-/*
- int i;
- for (i = 0; i < num; i++)
- fprintf(stderr, "%s value[%d] = %s\n", str, i, value[i]);
-*/
-}
-
-static void
-dmpscope(
- const char* name,
- FontScope sc,
- int num)
-{
-/*
- int i;
- fprintf(stderr, "dmpscope %s\n", name);
- for (i=0; i<num; i++)
- fprintf(stderr,"%x %x %x %x \n",
- sc[i].start,
- sc[i].end,
- sc[i].shift,
- sc[i].shift_direction);
- fprintf(stderr, "dmpscope end\n");
-*/
-}
-
-static XlcCharSet
-srch_charset_define(
- const char *name,
- int *new)
-{
- XlcCharSet charset;
-
- *new = 0;
- charset = _XlcGetCharSet(name);
- if (charset == NULL &&
- (charset = _XlcCreateDefaultCharSet(name, ""))) {
- _XlcAddCharSet(charset);
- *new = 1;
- charset->source = CSsrcXLC;
- }
- return charset;
-}
-
-static void
-read_charset_define(
- XLCd lcd,
- XLCdGenericPart *gen)
-{
- int i;
- char csd[16], cset_name[256];
- char name[BUFSIZ];
- XlcCharSet charsetd;
- char **value;
- int num, new = 0;
- XlcSide side = XlcUnknown;
- char *tmp;
-
- for (i=0; ; i++) { /* loop start */
- charsetd = 0;
- sprintf(csd, "csd%d", i);
-
- /* charset_name */
- sprintf(name, "%s.%s", csd, "charset_name");
- _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
- _XlcDbg_printValue(name,value,num);
- if (num > 0) {
- /* hackers will get truncated -- C'est la vie */
- strncpy(cset_name,value[0], sizeof cset_name - 1);
- cset_name[(sizeof cset_name) - 1] = '\0';
- sprintf(name, "%s.%s", csd , "side");
- _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
- if (!_XlcNCompareISOLatin1(value[0], "none", 4)) {
- side = XlcGLGR;
- } else if (!_XlcNCompareISOLatin1(value[0], "GL", 2)) {
- side = XlcGL;
- strcat(cset_name,":GL");
- } else {
- side = XlcGR;
- strcat(cset_name,":GR");
- }
- if (charsetd == NULL &&
- (charsetd = srch_charset_define(cset_name,&new)) == NULL)
- return;
- }
- } else {
- if (i == 0)
- continue;
- else
- break;
- }
- if (new) {
- tmp = (char *)Xmalloc(strlen(cset_name)+1);
- if (tmp == NULL)
- return;
- strcpy(tmp,cset_name);
- charsetd->name = tmp;
- }
- /* side */
- charsetd->side = side ;
- /* length */
- sprintf(name, "%s.%s", csd, "length");
- _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
- charsetd->char_size = atoi(value[0]);
- }
- /* gc_number */
- sprintf(name, "%s.%s", csd, "gc_number");
- _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
- charsetd->set_size = atoi(value[0]);
- }
- /* string_encoding */
- sprintf(name, "%s.%s", csd, "string_encoding");
- _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
- if (!strcmp("False",value[0])) {
- charsetd->string_encoding = False;
- } else {
- charsetd->string_encoding = True;
- }
- }
- /* sequence */
- sprintf(name, "%s.%s", csd, "sequence");
- _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
-/*
- if (charsetd->ct_sequence) {
- Xfree(charsetd->ct_sequence);
- }
-*/
- tmp = (char *)Xmalloc(strlen(value[0])+1);
- if (tmp == NULL)
- return;
- charsetd->ct_sequence = tmp;
- string_to_encoding(value[0],tmp);
- }
- /* encoding_name */
- sprintf(name, "%s.%s", csd, "encoding_name");
- _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
-/*
- if (charsetd->encoding_name) {
- Xfree(charsetd->encoding_name);
- }
-*/
- tmp = (char *)Xmalloc(strlen(value[0])+1);
- strcpy(tmp,value[0]);
- charsetd->encoding_name = tmp;
- charsetd->xrm_encoding_name = XrmStringToQuark(tmp);
- }
- _XlcAddCT(charsetd->name, charsetd->ct_sequence);
- }
-}
-
-static SegConv
-add_conversion(
- XLCdGenericPart *gen)
-{
- SegConv new_list;
- int num;
-
- if ((num = gen->segment_conv_num) > 0) {
- new_list = (SegConv) Xrealloc(gen->segment_conv,
- (num + 1) * sizeof(SegConvRec));
- } else {
- new_list = (SegConv) Xmalloc(sizeof(SegConvRec));
- }
-
- if (new_list == NULL)
- return NULL;
-
- gen->segment_conv = new_list;
- gen->segment_conv_num = num + 1;
-
- return &new_list[num];
-
-}
-
-static void
-read_segmentconversion(
- XLCd lcd,
- XLCdGenericPart *gen)
-{
- int i;
- char conv[16];
- char name[BUFSIZ];
- char **value;
- int num,new;
- SegConv conversion;
- for (i=0 ; ; i++) { /* loop start */
- conversion = 0;
- sprintf(conv, "conv%d", i);
-
- /* length */
- sprintf(name, "%s.%s", conv, "length");
- _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
- if (num > 0) {
- if (conversion == NULL &&
- (conversion = add_conversion(gen)) == NULL) {
- return;
- }
- _XlcDbg_printValue(name,value,num);
- } else {
- if (i == 0)
- continue;
- else
- break;
- }
- conversion->length = atoi(value[0]);
-
- /* source_encoding */
- sprintf(name, "%s.%s", conv, "source_encoding");
- _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
- if (num > 0) {
- char *tmp;
- _XlcDbg_printValue(name,value,num);
- tmp = (char *)Xmalloc(strlen(value[0])+1);
- if (tmp == NULL)
- return;
- strcpy(tmp,value[0]);
- conversion->source_encoding = tmp;
- conversion->source = srch_charset_define(tmp,&new);
- }
- /* destination_encoding */
- sprintf(name, "%s.%s", conv, "destination_encoding");
- _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
- if (num > 0) {
- char *tmp;
- _XlcDbg_printValue(name,value,num);
- tmp = (char *)Xmalloc(strlen(value[0])+1);
- if (tmp == NULL)
- return;
- strcpy(tmp,value[0]);
- conversion->destination_encoding = tmp;
- conversion->dest = srch_charset_define(tmp,&new);
- }
- /* range */
- sprintf(name, "%s.%s", conv, "range");
- _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
- sscanf(value[0],"\\x%lx,\\x%lx",
- &(conversion->range.start), &(conversion->range.end));
- }
- /* conversion */
- sprintf(name, "%s.%s", conv, "conversion");
- _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
- conversion->conv =
- _XlcParse_scopemaps(value[0],&conversion->conv_num);
- }
- } /* loop end */
-}
-
-static ExtdSegment
-create_ctextseg(
- char **value,
- int num)
-{
- ExtdSegment ret;
- char* ptr;
- char* cset_name = NULL;
- int i,new;
- FontScope scope;
- ret = (ExtdSegment)Xmalloc(sizeof(ExtdSegmentRec));
- if (ret == NULL)
- return NULL;
- ret->name = (char *)Xmalloc(strlen(value[0]) + 1);
- if (ret->name == NULL) {
- Xfree (ret);
- return NULL;
- }
- strcpy(ret->name,value[0]);
- cset_name = (char*) Xmalloc (strlen(ret->name) + 1);
- if (cset_name == NULL) {
- Xfree (ret->name);
- Xfree (ret);
- return NULL;
- }
- if (strchr(value[0],':')) {
- ptr = strchr(ret->name,':');
- *ptr = '\0';
- ptr++;
- if (!_XlcNCompareISOLatin1(ptr, "GL", 2)) {
- ret->side = XlcGL;
- sprintf(cset_name,"%s:%s",ret->name,"GL");
- } else {
- ret->side = XlcGR;
- sprintf(cset_name,"%s:%s",ret->name,"GR");
- }
- } else {
- ret->side = XlcGLGR;
- strcpy(cset_name,ret->name);
- }
- ret->area = (FontScope)Xmalloc((num - 1)*sizeof(FontScopeRec));
- if (ret->area == NULL) {
- Xfree (cset_name);
- Xfree (ret->name);
- Xfree (ret);
- return NULL;
- }
- ret->area_num = num - 1;
- scope = ret->area ;
- for (i = 1; i < num; i++) {
- sscanf(value[i],"\\x%lx,\\x%lx",
- &scope[i-1].start, &scope[i-1].end);
- }
- ret->charset = srch_charset_define(cset_name,&new);
- Xfree (cset_name);
-
- return ret;
-}
-/* For VW/UDC end */
-
-static Bool
-load_generic(
- XLCd lcd)
-{
- XLCdGenericPart *gen = XLC_GENERIC_PART(lcd);
- char **value;
- int num;
- unsigned long l;
- int i;
- int M,ii;
- XlcCharSet charset;
-
- gen->codeset_num = 0;
-
- /***** wc_encoding_mask *****/
- _XlcGetResource(lcd, "XLC_XLOCALE", "wc_encoding_mask", &value, &num);
- if (num > 0) {
- if (string_to_ulong(value[0], &l) == False)
- goto err;
- gen->wc_encode_mask = l;
- }
- /***** wc_shift_bits *****/
- _XlcGetResource(lcd, "XLC_XLOCALE", "wc_shift_bits", &value, &num);
- if (num > 0)
- gen->wc_shift_bits = atoi(value[0]);
- if (gen->wc_shift_bits < 1)
- gen->wc_shift_bits = 8;
- /***** use_stdc_env *****/
- _XlcGetResource(lcd, "XLC_XLOCALE", "use_stdc_env", &value, &num);
- if (num > 0 && !_XlcCompareISOLatin1(value[0], "True"))
- gen->use_stdc_env = True;
- else
- gen->use_stdc_env = False;
- /***** force_convert_to_mb *****/
- _XlcGetResource(lcd, "XLC_XLOCALE", "force_convert_to_mb", &value, &num);
- if (num > 0 && !_XlcCompareISOLatin1(value[0], "True"))
- gen->force_convert_to_mb = True;
- else
- gen->force_convert_to_mb = False;
-
- for (i = 0; ; i++) {
- CodeSetRec *codeset = NULL;
- char cs[16];
- char name[BUFSIZ];
-
- sprintf(cs, "cs%d", i);
-
- /***** codeset.side *****/
- sprintf(name, "%s.%s", cs , "side");
- _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
- if (num > 0) {
- char *tmp;
-
- if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
- goto err;
-
- /* 3.4.1 side */
- if (!_XlcNCompareISOLatin1(value[0], "none", 4)) {
- codeset->side = XlcNONE;
- } else if (!_XlcNCompareISOLatin1(value[0], "GL", 2)) {
- codeset->side = XlcGL;
- } else {
- codeset->side = XlcGR;
- }
-
- tmp = strrchr(value[0], ':');
- if (tmp != NULL && !_XlcCompareISOLatin1(tmp + 1, "Default")) {
- if (codeset->side == XlcGR)
- gen->initial_state_GR = codeset;
- else
- gen->initial_state_GL = codeset;
- }
- }
-
- /***** codeset.length *****/
- sprintf(name, "%s.%s", cs , "length");
- _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
- if (num > 0) {
- if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
- goto err;
- codeset->length = atoi(value[0]);
- if (codeset->length < 1)
- codeset->length = 1;
- }
-
- /***** codeset.mb_encoding *****/
- sprintf(name, "%s.%s", cs, "mb_encoding");
- _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
- if (num > 0) {
- static struct {
- const char *str;
- EncodingType type;
- } shifts[] = {
- {"<SS>", E_SS},
- {"<LSL>", E_LSL},
- {"<LSR>", E_LSR},
- {0}
- };
- int j;
-
- if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
- goto err;
- for ( ; num-- > 0; value++) {
- char encoding[256];
- char *tmp = *value;
- EncodingType type = E_SS; /* for BC */
- for (j = 0; shifts[j].str; j++) {
- if (!_XlcNCompareISOLatin1(tmp, shifts[j].str,
- strlen(shifts[j].str))) {
- type = shifts[j].type;
- tmp += strlen(shifts[j].str);
- break;
- }
- }
- if (strlen (tmp) > sizeof encoding ||
- string_to_encoding(tmp, encoding) == False)
- goto err;
- add_parse_list(gen, type, encoding, codeset);
- }
- }
-
- /***** codeset.wc_encoding *****/
- sprintf(name, "%s.%s", cs, "wc_encoding");
- _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
- if (num > 0) {
- if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
- goto err;
- if (string_to_ulong(value[0], &l) == False)
- goto err;
- codeset->wc_encoding = l;
- }
-
- /***** codeset.ct_encoding *****/
- sprintf(name, "%s.%s", cs, "ct_encoding");
- _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
- if (num > 0) {
- char *encoding;
-
- if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
- goto err;
- for ( ; num-- > 0; value++) {
- if (strlen (*value) > sizeof name)
- goto err;
- string_to_encoding(*value, name);
- charset = NULL;
- if ((encoding = strchr(name, ':')) &&
- (encoding = strchr(encoding + 1, ':'))) {
- *encoding++ = '\0';
- charset = _XlcAddCT(name, encoding);
- }
- if (charset == NULL) {
- charset = _XlcGetCharSet(name);
- if (charset == NULL &&
- (charset = _XlcCreateDefaultCharSet(name, ""))) {
- charset->side = codeset->side;
- charset->char_size = codeset->length;
- _XlcAddCharSet(charset);
- }
- }
- if (charset) {
- if (add_charset(codeset, charset) == False)
- goto err;
- }
- }
- }
-
- if (codeset == NULL)
- break;
- codeset->cs_num = i;
- /* For VW/UDC */
- /***** 3.4.2 byteM (1 <= M <= length)*****/
- for (M=1; M-1 < codeset->length; M++) {
- unsigned long start,end;
- ByteInfo tmpb;
-
- sprintf(name,"%s.%s%d",cs,"byte",M);
- _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
-
- if (M == 1) {
- if (num < 1) {
- codeset->byteM = NULL;
- break ;
- }
- codeset->byteM =
- (ByteInfoListRec *)Xmalloc(
- (codeset->length)*sizeof(ByteInfoListRec));
- if (codeset->byteM == NULL) {
- goto err;
- }
- }
-
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
- (codeset->byteM)[M-1].M = M;
- (codeset->byteM)[M-1].byteinfo_num = num;
- (codeset->byteM)[M-1].byteinfo =
- (ByteInfo)Xmalloc( num * sizeof(ByteInfoRec));
- for (ii = 0 ; ii < num ; ii++) {
- tmpb = (codeset->byteM)[M-1].byteinfo ;
- /* default 0x00 - 0xff */
- sscanf(value[ii],"\\x%lx,\\x%lx",&start,&end);
- tmpb[ii].start = (unsigned char)start;
- tmpb[ii].end = (unsigned char)end;
- }
- }
- /* .... */
- }
-
-
- /***** codeset.mb_conversion *****/
- sprintf(name, "%s.%s", cs, "mb_conversion");
- _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
- codeset->mbconv = Xmalloc(sizeof(ConversionRec));
- codeset->mbconv->convlist =
- _XlcParse_scopemaps(value[0],&(codeset->mbconv->conv_num));
- dmpscope("mb_conv",codeset->mbconv->convlist,
- codeset->mbconv->conv_num);
- /* [\x%x,\x%x]->\x%x,... */
- }
- /***** codeset.ct_conversion *****/
- sprintf(name, "%s.%s", cs, "ct_conversion");
- _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
- codeset->ctconv = Xmalloc(sizeof(ConversionRec));
- codeset->ctconv->convlist =
- _XlcParse_scopemaps(value[0],&(codeset->ctconv->conv_num));
- dmpscope("ctconv",codeset->ctconv->convlist,
- codeset->ctconv->conv_num);
- /* [\x%x,\x%x]->\x%x,... */
- }
- /***** codeset.ct_conversion_file *****/
- sprintf(name, "%s.%s", cs, "ct_conversion_file");
- _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
- /* [\x%x,\x%x]->\x%x,... */
- }
- /***** codeset.ct_extended_segment *****/
- sprintf(name, "%s.%s", cs, "ct_extended_segment");
- _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
- if (num > 0) {
- _XlcDbg_printValue(name,value,num);
- codeset->ctextseg = create_ctextseg(value,num);
- /* [\x%x,\x%x]->\x%x,... */
- }
- /* For VW/UDC end */
-
- }
-
- read_charset_define(lcd,gen); /* For VW/UDC */
- read_segmentconversion(lcd,gen); /* For VW/UDC */
-
- if (gen->initial_state_GL == NULL) {
- CodeSetRec *codeset;
- for (i = 0; i < gen->codeset_num; i++) {
- codeset = gen->codeset_list[i];
- if (codeset->side == XlcGL)
- gen->initial_state_GL = codeset;
- }
- }
-
- if (gen->initial_state_GR == NULL) {
- CodeSetRec *codeset;
- for (i = 0; i < gen->codeset_num; i++) {
- codeset = gen->codeset_list[i];
- if (codeset->side == XlcGR)
- gen->initial_state_GR = codeset;
- }
- }
-
- for (i = 0; i < gen->codeset_num; i++) {
- CodeSetRec *codeset = gen->codeset_list[i];
- for (ii = 0; ii < codeset->num_charsets; ii++) {
- charset = codeset->charset_list[ii];
- if (! strcmp(charset->encoding_name, "ISO8859-1"))
- charset->string_encoding = True;
- if ( charset->string_encoding )
- codeset->string_encoding = True;
- }
- }
- return True;
-
-err:
- free_charset(lcd);
-
- return False;
-}
-
-#ifdef USE_DYNAMIC_LC
-/* override the open_om and open_im methods which were set by
- super_class's initialize method() */
-
-static Bool
-initialize_core(
- XLCd lcd)
-{
- _XInitDynamicOM(lcd);
-
- _XInitDynamicIM(lcd);
-
- return True;
-}
-#endif
-
-static Bool
-initialize(XLCd lcd)
-{
- XLCdPublicMethods superclass = (XLCdPublicMethods) _XlcPublicMethods;
-
- XLC_PUBLIC_METHODS(lcd)->superclass = superclass;
-
- if (superclass->pub.initialize) {
- if ((*superclass->pub.initialize)(lcd) == False)
- return False;
- }
-
-#ifdef USE_DYNAMIC_LC
- if (initialize_core(lcd) == False)
- return False;
-#endif
-
- if (load_generic(lcd) == False)
- return False;
-
- return True;
-}
-
-/* VW/UDC start 95.01.08 */
-static void
-freeByteM(
- CodeSet codeset)
-{
- int i;
- ByteInfoList blst;
- if (codeset->byteM == NULL) {
- return ;
- }
- blst = codeset->byteM;
- for (i = 0; i < codeset->length; i++) {
- if (blst[i].byteinfo) {
- Xfree(blst[i].byteinfo);
- blst[i].byteinfo = NULL;
- }
- }
- Xfree(codeset->byteM);
- codeset->byteM = NULL;
-}
-
-static void
-freeConversion(
- CodeSet codeset)
-{
- Conversion mbconv,ctconv;
- if (codeset->mbconv) {
- mbconv = codeset->mbconv;
- /* ... */
- if (mbconv->convlist) {
- Xfree(mbconv->convlist);
- mbconv->convlist = NULL;
- }
- Xfree(mbconv);
- codeset->mbconv = NULL;
- }
- if (codeset->ctconv) {
- ctconv = codeset->ctconv;
- /* ... */
- if (ctconv->convlist) {
- Xfree(ctconv->convlist);
- ctconv->convlist = NULL;
- }
- Xfree(ctconv);
- codeset->ctconv = NULL;
- }
-}
-
-static void
-freeExtdSegment(
- CodeSet codeset)
-{
- ExtdSegment ctextseg;
- if (codeset->ctextseg == NULL) {
- return;
- }
- ctextseg = codeset->ctextseg;
- if (ctextseg->name) {
- Xfree(ctextseg->name);
- ctextseg->name = NULL;
- }
- if (ctextseg->area) {
- Xfree(ctextseg->area);
- ctextseg->area = NULL;
- }
- Xfree(codeset->ctextseg);
- codeset->ctextseg = NULL;
-}
-
-static void
-freeParseInfo(
- CodeSet codeset)
-{
- ParseInfo parse_info;
- if (codeset->parse_info == NULL) {
- return;
- }
- parse_info = codeset->parse_info;
- if (parse_info->encoding) {
- Xfree(parse_info->encoding);
- parse_info->encoding = NULL;
- }
- Xfree(codeset->parse_info);
- codeset->parse_info = NULL;
-}
-
-static void
-destroy_CodeSetList(
- XLCdGenericPart *gen)
-{
- CodeSet *codeset = gen->codeset_list;
- int i;
- if (gen->codeset_num == 0) {
- return;
- }
- for (i=0;i<gen->codeset_num;i++) {
- freeByteM(codeset[i]);
- freeConversion(codeset[i]);
- freeExtdSegment(codeset[i]);
- freeParseInfo(codeset[i]);
- if (codeset[i]->charset_list) {
- Xfree(codeset[i]->charset_list);
- codeset[i]->charset_list = NULL;
- }
- Xfree(codeset[i]); codeset[i]=NULL;
- }
- Xfree(codeset); gen->codeset_list = NULL;
-}
-
-static void
-destroy_SegConv(
- XLCdGenericPart *gen)
-{
- SegConv seg = gen->segment_conv;
- int i;
- if (gen->segment_conv_num == 0) {
- return;
- }
- for (i=0;i<gen->segment_conv_num;i++) {
- if (seg[i].source_encoding) {
- Xfree(seg[i].source_encoding);
- seg[i].source_encoding = NULL;
- }
- if (seg[i].destination_encoding) {
- Xfree(seg[i].destination_encoding);
- seg[i].destination_encoding = NULL;
- }
- if (seg[i].conv) {
- Xfree(seg[i].conv); seg[i].conv = NULL;
- }
- }
- Xfree(seg); gen->segment_conv = NULL;
-}
-
-static void
-destroy_gen(
- XLCd lcd)
-{
- XLCdGenericPart *gen = XLC_GENERIC_PART(lcd);
- destroy_SegConv(gen);
- destroy_CodeSetList(gen);
- if (gen->mb_parse_table) {
- Xfree(gen->mb_parse_table);
- gen->mb_parse_table = NULL;
- }
- if (gen->mb_parse_list) {
- Xfree(gen->mb_parse_list);
- gen->mb_parse_list = NULL;
- }
-}
-/* VW/UDC end 95.01.08 */
-
-static void
-destroy(
- XLCd lcd)
-{
- XLCdPublicMethods superclass = XLC_PUBLIC_METHODS(lcd)->superclass;
-
- destroy_gen(lcd); /* ADD 1996.01.08 */
- if (superclass && superclass->pub.destroy)
- (*superclass->pub.destroy)(lcd);
-}
+/*
+ * Copyright 1992, 1993 by TOSHIBA Corp.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of TOSHIBA not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission. TOSHIBA make no representations about the
+ * suitability of this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+ * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Author: Katsuhisa Yano TOSHIBA Corp.
+ * mopi@osa.ilab.toshiba.co.jp
+ */
+/*
+ * (c) Copyright 1995 FUJITSU LIMITED
+ * This is source code modified by FUJITSU LIMITED under the Joint
+ * Development Agreement for the CDE/Motif PST.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include "Xlibint.h"
+#include "XlcGeneric.h"
+
+static XLCd create (const char *name, XLCdMethods methods);
+static Bool initialize (XLCd lcd);
+static void destroy (XLCd lcd);
+
+static XLCdPublicMethodsRec genericMethods = {
+ { NULL }, /* use default methods */
+ {
+ NULL,
+ create,
+ initialize,
+ destroy,
+ NULL
+ }
+};
+
+XLCdMethods _XlcGenericMethods = (XLCdMethods) &genericMethods;
+
+static XLCd
+create(
+ const char *name,
+ XLCdMethods methods)
+{
+ XLCd lcd;
+ XLCdPublicMethods new;
+
+ lcd = Xcalloc(1, sizeof(XLCdRec));
+ if (lcd == NULL)
+ return (XLCd) NULL;
+
+ lcd->core = Xcalloc(1, sizeof(XLCdGenericRec));
+ if (lcd->core == NULL)
+ goto err;
+
+ new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec));
+ if (new == NULL)
+ goto err;
+ memcpy(new,methods,sizeof(XLCdPublicMethodsRec));
+ lcd->methods = (XLCdMethods) new;
+
+ return lcd;
+
+err:
+ Xfree(lcd);
+ return (XLCd) NULL;
+}
+
+static Bool
+string_to_encoding(
+ const char *str,
+ char *encoding)
+{
+ char *next;
+ long value;
+ int base;
+
+ while (*str) {
+ if (*str == '\\') {
+ switch (*(str + 1)) {
+ case 'x':
+ case 'X':
+ base = 16;
+ break;
+ default:
+ base = 8;
+ break;
+ }
+ value = strtol(str + 2, &next, base);
+ if (str + 2 != next) {
+ *((unsigned char *) encoding++) = (unsigned char) value;
+ str = next;
+ continue;
+ }
+ }
+ *encoding++ = *str++;
+ }
+
+ *encoding = '\0';
+
+ return True;
+}
+
+static Bool
+string_to_ulong(
+ const char *str,
+ unsigned long *value)
+{
+ const char *tmp1 = str;
+ int base;
+
+ if (*tmp1++ != '\\') {
+ tmp1--;
+ base = 10;
+ } else {
+ switch (*tmp1++) {
+ case 'x':
+ base = 16;
+ break;
+ case 'o':
+ base = 8;
+ break;
+ case 'd':
+ base = 10;
+ break;
+ default:
+ return(False);
+ }
+ }
+ *value = (unsigned long) strtol(tmp1, NULL, base);
+ return(True);
+}
+
+
+static Bool
+add_charset(
+ CodeSet codeset,
+ XlcCharSet charset)
+{
+ XlcCharSet *new_list;
+ int num;
+
+ if ((num = codeset->num_charsets))
+ new_list = (XlcCharSet *) Xrealloc(codeset->charset_list,
+ (num + 1) * sizeof(XlcCharSet));
+ else
+ new_list = (XlcCharSet *) Xmalloc(sizeof(XlcCharSet));
+
+ if (new_list == NULL)
+ return False;
+
+ new_list[num] = charset;
+ codeset->charset_list = new_list;
+ codeset->num_charsets = num + 1;
+
+ return True;
+}
+
+static CodeSet
+add_codeset(
+ XLCdGenericPart *gen)
+{
+ CodeSet new, *new_list;
+ int num;
+
+ new = Xcalloc(1, sizeof(CodeSetRec));
+ if (new == NULL)
+ return NULL;
+
+ if ((num = gen->codeset_num))
+ new_list = (CodeSet *) Xrealloc(gen->codeset_list,
+ (num + 1) * sizeof(CodeSet));
+ else
+ new_list = (CodeSet *) Xmalloc(sizeof(CodeSet));
+
+ if (new_list == NULL)
+ goto err;
+
+ new_list[num] = new;
+ gen->codeset_list = new_list;
+ gen->codeset_num = num + 1;
+
+ return new;
+
+err:
+ Xfree(new);
+
+ return NULL;
+}
+
+static Bool
+add_parse_list(
+ XLCdGenericPart *gen,
+ EncodingType type,
+ const char *encoding,
+ CodeSet codeset)
+{
+ ParseInfo new, *new_list;
+ char *str;
+ unsigned char ch;
+ int num;
+
+ str = strdup(encoding);
+ if (str == NULL)
+ return False;
+
+ new = Xcalloc(1, sizeof(ParseInfoRec));
+ if (new == NULL)
+ goto err;
+
+ if (gen->mb_parse_table == NULL) {
+ gen->mb_parse_table = Xcalloc(1, 256); /* 2^8 */
+ if (gen->mb_parse_table == NULL)
+ goto err;
+ }
+
+ if ((num = gen->mb_parse_list_num))
+ new_list = (ParseInfo *) Xrealloc(gen->mb_parse_list,
+ (num + 2) * sizeof(ParseInfo));
+ else {
+ new_list = (ParseInfo *) Xmalloc(2 * sizeof(ParseInfo));
+ }
+
+ if (new_list == NULL)
+ goto err;
+
+ new_list[num] = new;
+ new_list[num + 1] = NULL;
+ gen->mb_parse_list = new_list;
+ gen->mb_parse_list_num = num + 1;
+
+ ch = (unsigned char) *str;
+ if (gen->mb_parse_table[ch] == 0)
+ gen->mb_parse_table[ch] = num + 1;
+
+ new->type = type;
+ new->encoding = str;
+ new->codeset = codeset;
+
+ if (codeset->parse_info == NULL)
+ codeset->parse_info = new;
+
+ return True;
+
+err:
+ Xfree(str);
+ if (new)
+ Xfree(new);
+
+ return False;
+}
+
+static void
+free_charset(
+ XLCd lcd)
+{
+ XLCdGenericPart *gen = XLC_GENERIC_PART(lcd);
+ ParseInfo *parse_info;
+ int num;
+
+ if (gen->mb_parse_table)
+ Xfree(gen->mb_parse_table);
+ if ((num = gen->mb_parse_list_num) > 0) {
+ for (parse_info = gen->mb_parse_list; num-- > 0; parse_info++) {
+ if ((*parse_info)->encoding)
+ Xfree((*parse_info)->encoding);
+ Xfree(*parse_info);
+ }
+ Xfree(gen->mb_parse_list);
+ }
+
+ if ((num = gen->codeset_num) > 0)
+ Xfree(gen->codeset_list);
+}
+
+/* For VW/UDC */
+
+#define FORWARD (unsigned long)'+'
+#define BACKWARD (unsigned long)'-'
+
+static const char *
+getscope(
+ const char *str,
+ FontScope scp)
+{
+ unsigned long start = 0;
+ unsigned long end = 0;
+ unsigned long dest = 0;
+ unsigned long shift = 0;
+ unsigned long direction = 0;
+ sscanf(str,"[\\x%lx,\\x%lx]->\\x%lx", &start, &end, &dest);
+ if (dest) {
+ if (dest >= start) {
+ shift = dest - start;
+ direction = FORWARD ;
+ } else {
+ shift = start - dest;
+ direction = BACKWARD;
+ }
+ }
+ scp->start = start ;
+ scp->end = end ;
+ scp->shift = shift ;
+ scp->shift_direction
+ = direction ;
+ /* .......... */
+ while (*str) {
+ if (*str == ',' && *(str+1) == '[')
+ break;
+ str++;
+ }
+ return str+1;
+}
+
+static int
+count_scopemap(
+ const char *str)
+{
+ const char *ptr;
+ int num=0;
+ for (ptr=str; *ptr; ptr++) {
+ if (*ptr == ']') {
+ num++;
+ }
+ }
+ return num;
+}
+
+FontScope
+_XlcParse_scopemaps(
+ const char *str,
+ int *size)
+{
+ int num=0,i;
+ FontScope scope,sc_ptr;
+ const char *str_sc;
+
+ num = count_scopemap(str);
+ scope = (FontScope) Xmalloc(num * sizeof(FontScopeRec));
+ if (scope == NULL)
+ return NULL;
+
+ for (i=0, str_sc=str, sc_ptr=scope; i < num; i++, sc_ptr++) {
+ str_sc = getscope(str_sc, sc_ptr);
+ }
+ *size = num;
+ return scope;
+}
+
+void
+_XlcDbg_printValue(
+ const char *str,
+ char **value,
+ int num)
+{
+/*
+ int i;
+ for (i = 0; i < num; i++)
+ fprintf(stderr, "%s value[%d] = %s\n", str, i, value[i]);
+*/
+}
+
+static void
+dmpscope(
+ const char* name,
+ FontScope sc,
+ int num)
+{
+/*
+ int i;
+ fprintf(stderr, "dmpscope %s\n", name);
+ for (i=0; i<num; i++)
+ fprintf(stderr,"%x %x %x %x \n",
+ sc[i].start,
+ sc[i].end,
+ sc[i].shift,
+ sc[i].shift_direction);
+ fprintf(stderr, "dmpscope end\n");
+*/
+}
+
+static XlcCharSet
+srch_charset_define(
+ const char *name,
+ int *new)
+{
+ XlcCharSet charset;
+
+ *new = 0;
+ charset = _XlcGetCharSet(name);
+ if (charset == NULL &&
+ (charset = _XlcCreateDefaultCharSet(name, ""))) {
+ _XlcAddCharSet(charset);
+ *new = 1;
+ charset->source = CSsrcXLC;
+ }
+ return charset;
+}
+
+static void
+read_charset_define(
+ XLCd lcd,
+ XLCdGenericPart *gen)
+{
+ int i;
+ char csd[16], cset_name[256];
+ char name[BUFSIZ];
+ XlcCharSet charsetd;
+ char **value;
+ int num, new = 0;
+ XlcSide side = XlcUnknown;
+ char *tmp;
+
+ for (i=0; ; i++) { /* loop start */
+ charsetd = 0;
+ sprintf(csd, "csd%d", i);
+
+ /* charset_name */
+ sprintf(name, "%s.%s", csd, "charset_name");
+ _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
+ _XlcDbg_printValue(name,value,num);
+ if (num > 0) {
+ /* hackers will get truncated -- C'est la vie */
+ strncpy(cset_name,value[0], sizeof cset_name - 1);
+ cset_name[(sizeof cset_name) - 1] = '\0';
+ sprintf(name, "%s.%s", csd , "side");
+ _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+ if (!_XlcNCompareISOLatin1(value[0], "none", 4)) {
+ side = XlcGLGR;
+ } else if (!_XlcNCompareISOLatin1(value[0], "GL", 2)) {
+ side = XlcGL;
+ strcat(cset_name,":GL");
+ } else {
+ side = XlcGR;
+ strcat(cset_name,":GR");
+ }
+ if (charsetd == NULL &&
+ (charsetd = srch_charset_define(cset_name,&new)) == NULL)
+ return;
+ }
+ } else {
+ if (i == 0)
+ continue;
+ else
+ break;
+ }
+ if (new) {
+ tmp = strdup(cset_name);
+ if (tmp == NULL)
+ return;
+ charsetd->name = tmp;
+ }
+ /* side */
+ charsetd->side = side ;
+ /* length */
+ sprintf(name, "%s.%s", csd, "length");
+ _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+ charsetd->char_size = atoi(value[0]);
+ }
+ /* gc_number */
+ sprintf(name, "%s.%s", csd, "gc_number");
+ _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+ charsetd->set_size = atoi(value[0]);
+ }
+ /* string_encoding */
+ sprintf(name, "%s.%s", csd, "string_encoding");
+ _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+ if (!strcmp("False",value[0])) {
+ charsetd->string_encoding = False;
+ } else {
+ charsetd->string_encoding = True;
+ }
+ }
+ /* sequence */
+ sprintf(name, "%s.%s", csd, "sequence");
+ _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+/*
+ if (charsetd->ct_sequence) {
+ Xfree(charsetd->ct_sequence);
+ }
+*/
+ tmp = (char *)Xmalloc(strlen(value[0])+1);
+ if (tmp == NULL)
+ return;
+ charsetd->ct_sequence = tmp;
+ string_to_encoding(value[0],tmp);
+ }
+ /* encoding_name */
+ sprintf(name, "%s.%s", csd, "encoding_name");
+ _XlcGetResource(lcd, "XLC_CHARSET_DEFINE", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+/*
+ if (charsetd->encoding_name) {
+ Xfree(charsetd->encoding_name);
+ }
+*/
+ tmp = strdup(value[0]);
+ charsetd->encoding_name = tmp;
+ charsetd->xrm_encoding_name = XrmStringToQuark(tmp);
+ }
+ _XlcAddCT(charsetd->name, charsetd->ct_sequence);
+ }
+}
+
+static SegConv
+add_conversion(
+ XLCdGenericPart *gen)
+{
+ SegConv new_list;
+ int num;
+
+ if ((num = gen->segment_conv_num) > 0) {
+ new_list = (SegConv) Xrealloc(gen->segment_conv,
+ (num + 1) * sizeof(SegConvRec));
+ } else {
+ new_list = (SegConv) Xmalloc(sizeof(SegConvRec));
+ }
+
+ if (new_list == NULL)
+ return NULL;
+
+ gen->segment_conv = new_list;
+ gen->segment_conv_num = num + 1;
+
+ return &new_list[num];
+
+}
+
+static void
+read_segmentconversion(
+ XLCd lcd,
+ XLCdGenericPart *gen)
+{
+ int i;
+ char conv[16];
+ char name[BUFSIZ];
+ char **value;
+ int num,new;
+ SegConv conversion;
+ for (i=0 ; ; i++) { /* loop start */
+ conversion = 0;
+ sprintf(conv, "conv%d", i);
+
+ /* length */
+ sprintf(name, "%s.%s", conv, "length");
+ _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
+ if (num > 0) {
+ if (conversion == NULL &&
+ (conversion = add_conversion(gen)) == NULL) {
+ return;
+ }
+ _XlcDbg_printValue(name,value,num);
+ } else {
+ if (i == 0)
+ continue;
+ else
+ break;
+ }
+ conversion->length = atoi(value[0]);
+
+ /* source_encoding */
+ sprintf(name, "%s.%s", conv, "source_encoding");
+ _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
+ if (num > 0) {
+ char *tmp;
+ _XlcDbg_printValue(name,value,num);
+ tmp = strdup(value[0]);
+ if (tmp == NULL)
+ return;
+ conversion->source_encoding = tmp;
+ conversion->source = srch_charset_define(tmp,&new);
+ }
+ /* destination_encoding */
+ sprintf(name, "%s.%s", conv, "destination_encoding");
+ _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
+ if (num > 0) {
+ char *tmp;
+ _XlcDbg_printValue(name,value,num);
+ tmp = strdup(value[0]);
+ if (tmp == NULL)
+ return;
+ conversion->destination_encoding = tmp;
+ conversion->dest = srch_charset_define(tmp,&new);
+ }
+ /* range */
+ sprintf(name, "%s.%s", conv, "range");
+ _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+ sscanf(value[0],"\\x%lx,\\x%lx",
+ &(conversion->range.start), &(conversion->range.end));
+ }
+ /* conversion */
+ sprintf(name, "%s.%s", conv, "conversion");
+ _XlcGetResource(lcd, "XLC_SEGMENTCONVERSION", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+ conversion->conv =
+ _XlcParse_scopemaps(value[0],&conversion->conv_num);
+ }
+ } /* loop end */
+}
+
+static ExtdSegment
+create_ctextseg(
+ char **value,
+ int num)
+{
+ ExtdSegment ret;
+ char* ptr;
+ char* cset_name = NULL;
+ int i,new;
+ FontScope scope;
+ ret = (ExtdSegment)Xmalloc(sizeof(ExtdSegmentRec));
+ if (ret == NULL)
+ return NULL;
+ ret->name = strdup(value[0]);
+ if (ret->name == NULL) {
+ Xfree (ret);
+ return NULL;
+ }
+ cset_name = (char*) Xmalloc (strlen(ret->name) + 1);
+ if (cset_name == NULL) {
+ Xfree (ret->name);
+ Xfree (ret);
+ return NULL;
+ }
+ if (strchr(value[0],':')) {
+ ptr = strchr(ret->name,':');
+ *ptr = '\0';
+ ptr++;
+ if (!_XlcNCompareISOLatin1(ptr, "GL", 2)) {
+ ret->side = XlcGL;
+ sprintf(cset_name,"%s:%s",ret->name,"GL");
+ } else {
+ ret->side = XlcGR;
+ sprintf(cset_name,"%s:%s",ret->name,"GR");
+ }
+ } else {
+ ret->side = XlcGLGR;
+ strcpy(cset_name,ret->name);
+ }
+ ret->area = (FontScope)Xmalloc((num - 1)*sizeof(FontScopeRec));
+ if (ret->area == NULL) {
+ Xfree (cset_name);
+ Xfree (ret->name);
+ Xfree (ret);
+ return NULL;
+ }
+ ret->area_num = num - 1;
+ scope = ret->area ;
+ for (i = 1; i < num; i++) {
+ sscanf(value[i],"\\x%lx,\\x%lx",
+ &scope[i-1].start, &scope[i-1].end);
+ }
+ ret->charset = srch_charset_define(cset_name,&new);
+ Xfree (cset_name);
+
+ return ret;
+}
+/* For VW/UDC end */
+
+static Bool
+load_generic(
+ XLCd lcd)
+{
+ XLCdGenericPart *gen = XLC_GENERIC_PART(lcd);
+ char **value;
+ int num;
+ unsigned long l;
+ int i;
+ int M,ii;
+ XlcCharSet charset;
+
+ gen->codeset_num = 0;
+
+ /***** wc_encoding_mask *****/
+ _XlcGetResource(lcd, "XLC_XLOCALE", "wc_encoding_mask", &value, &num);
+ if (num > 0) {
+ if (string_to_ulong(value[0], &l) == False)
+ goto err;
+ gen->wc_encode_mask = l;
+ }
+ /***** wc_shift_bits *****/
+ _XlcGetResource(lcd, "XLC_XLOCALE", "wc_shift_bits", &value, &num);
+ if (num > 0)
+ gen->wc_shift_bits = atoi(value[0]);
+ if (gen->wc_shift_bits < 1)
+ gen->wc_shift_bits = 8;
+ /***** use_stdc_env *****/
+ _XlcGetResource(lcd, "XLC_XLOCALE", "use_stdc_env", &value, &num);
+ if (num > 0 && !_XlcCompareISOLatin1(value[0], "True"))
+ gen->use_stdc_env = True;
+ else
+ gen->use_stdc_env = False;
+ /***** force_convert_to_mb *****/
+ _XlcGetResource(lcd, "XLC_XLOCALE", "force_convert_to_mb", &value, &num);
+ if (num > 0 && !_XlcCompareISOLatin1(value[0], "True"))
+ gen->force_convert_to_mb = True;
+ else
+ gen->force_convert_to_mb = False;
+
+ for (i = 0; ; i++) {
+ CodeSetRec *codeset = NULL;
+ char cs[16];
+ char name[BUFSIZ];
+
+ sprintf(cs, "cs%d", i);
+
+ /***** codeset.side *****/
+ sprintf(name, "%s.%s", cs , "side");
+ _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
+ if (num > 0) {
+ char *tmp;
+
+ if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
+ goto err;
+
+ /* 3.4.1 side */
+ if (!_XlcNCompareISOLatin1(value[0], "none", 4)) {
+ codeset->side = XlcNONE;
+ } else if (!_XlcNCompareISOLatin1(value[0], "GL", 2)) {
+ codeset->side = XlcGL;
+ } else {
+ codeset->side = XlcGR;
+ }
+
+ tmp = strrchr(value[0], ':');
+ if (tmp != NULL && !_XlcCompareISOLatin1(tmp + 1, "Default")) {
+ if (codeset->side == XlcGR)
+ gen->initial_state_GR = codeset;
+ else
+ gen->initial_state_GL = codeset;
+ }
+ }
+
+ /***** codeset.length *****/
+ sprintf(name, "%s.%s", cs , "length");
+ _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
+ if (num > 0) {
+ if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
+ goto err;
+ codeset->length = atoi(value[0]);
+ if (codeset->length < 1)
+ codeset->length = 1;
+ }
+
+ /***** codeset.mb_encoding *****/
+ sprintf(name, "%s.%s", cs, "mb_encoding");
+ _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
+ if (num > 0) {
+ static struct {
+ const char *str;
+ EncodingType type;
+ } shifts[] = {
+ {"<SS>", E_SS},
+ {"<LSL>", E_LSL},
+ {"<LSR>", E_LSR},
+ {0}
+ };
+ int j;
+
+ if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
+ goto err;
+ for ( ; num-- > 0; value++) {
+ char encoding[256];
+ char *tmp = *value;
+ EncodingType type = E_SS; /* for BC */
+ for (j = 0; shifts[j].str; j++) {
+ if (!_XlcNCompareISOLatin1(tmp, shifts[j].str,
+ strlen(shifts[j].str))) {
+ type = shifts[j].type;
+ tmp += strlen(shifts[j].str);
+ break;
+ }
+ }
+ if (strlen (tmp) > sizeof encoding ||
+ string_to_encoding(tmp, encoding) == False)
+ goto err;
+ add_parse_list(gen, type, encoding, codeset);
+ }
+ }
+
+ /***** codeset.wc_encoding *****/
+ sprintf(name, "%s.%s", cs, "wc_encoding");
+ _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
+ if (num > 0) {
+ if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
+ goto err;
+ if (string_to_ulong(value[0], &l) == False)
+ goto err;
+ codeset->wc_encoding = l;
+ }
+
+ /***** codeset.ct_encoding *****/
+ sprintf(name, "%s.%s", cs, "ct_encoding");
+ _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
+ if (num > 0) {
+ char *encoding;
+
+ if (codeset == NULL && (codeset = add_codeset(gen)) == NULL)
+ goto err;
+ for ( ; num-- > 0; value++) {
+ if (strlen (*value) > sizeof name)
+ goto err;
+ string_to_encoding(*value, name);
+ charset = NULL;
+ if ((encoding = strchr(name, ':')) &&
+ (encoding = strchr(encoding + 1, ':'))) {
+ *encoding++ = '\0';
+ charset = _XlcAddCT(name, encoding);
+ }
+ if (charset == NULL) {
+ charset = _XlcGetCharSet(name);
+ if (charset == NULL &&
+ (charset = _XlcCreateDefaultCharSet(name, ""))) {
+ charset->side = codeset->side;
+ charset->char_size = codeset->length;
+ _XlcAddCharSet(charset);
+ }
+ }
+ if (charset) {
+ if (add_charset(codeset, charset) == False)
+ goto err;
+ }
+ }
+ }
+
+ if (codeset == NULL)
+ break;
+ codeset->cs_num = i;
+ /* For VW/UDC */
+ /***** 3.4.2 byteM (1 <= M <= length)*****/
+ for (M=1; M-1 < codeset->length; M++) {
+ unsigned long start,end;
+ ByteInfo tmpb;
+
+ sprintf(name,"%s.%s%d",cs,"byte",M);
+ _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
+
+ if (M == 1) {
+ if (num < 1) {
+ codeset->byteM = NULL;
+ break ;
+ }
+ codeset->byteM =
+ (ByteInfoListRec *)Xmalloc(
+ (codeset->length)*sizeof(ByteInfoListRec));
+ if (codeset->byteM == NULL) {
+ goto err;
+ }
+ }
+
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+ (codeset->byteM)[M-1].M = M;
+ (codeset->byteM)[M-1].byteinfo_num = num;
+ (codeset->byteM)[M-1].byteinfo =
+ (ByteInfo)Xmalloc( num * sizeof(ByteInfoRec));
+ for (ii = 0 ; ii < num ; ii++) {
+ tmpb = (codeset->byteM)[M-1].byteinfo ;
+ /* default 0x00 - 0xff */
+ sscanf(value[ii],"\\x%lx,\\x%lx",&start,&end);
+ tmpb[ii].start = (unsigned char)start;
+ tmpb[ii].end = (unsigned char)end;
+ }
+ }
+ /* .... */
+ }
+
+
+ /***** codeset.mb_conversion *****/
+ sprintf(name, "%s.%s", cs, "mb_conversion");
+ _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+ codeset->mbconv = Xmalloc(sizeof(ConversionRec));
+ codeset->mbconv->convlist =
+ _XlcParse_scopemaps(value[0],&(codeset->mbconv->conv_num));
+ dmpscope("mb_conv",codeset->mbconv->convlist,
+ codeset->mbconv->conv_num);
+ /* [\x%x,\x%x]->\x%x,... */
+ }
+ /***** codeset.ct_conversion *****/
+ sprintf(name, "%s.%s", cs, "ct_conversion");
+ _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+ codeset->ctconv = Xmalloc(sizeof(ConversionRec));
+ codeset->ctconv->convlist =
+ _XlcParse_scopemaps(value[0],&(codeset->ctconv->conv_num));
+ dmpscope("ctconv",codeset->ctconv->convlist,
+ codeset->ctconv->conv_num);
+ /* [\x%x,\x%x]->\x%x,... */
+ }
+ /***** codeset.ct_conversion_file *****/
+ sprintf(name, "%s.%s", cs, "ct_conversion_file");
+ _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+ /* [\x%x,\x%x]->\x%x,... */
+ }
+ /***** codeset.ct_extended_segment *****/
+ sprintf(name, "%s.%s", cs, "ct_extended_segment");
+ _XlcGetResource(lcd, "XLC_XLOCALE", name, &value, &num);
+ if (num > 0) {
+ _XlcDbg_printValue(name,value,num);
+ codeset->ctextseg = create_ctextseg(value,num);
+ /* [\x%x,\x%x]->\x%x,... */
+ }
+ /* For VW/UDC end */
+
+ }
+
+ read_charset_define(lcd,gen); /* For VW/UDC */
+ read_segmentconversion(lcd,gen); /* For VW/UDC */
+
+ if (gen->initial_state_GL == NULL) {
+ CodeSetRec *codeset;
+ for (i = 0; i < gen->codeset_num; i++) {
+ codeset = gen->codeset_list[i];
+ if (codeset->side == XlcGL)
+ gen->initial_state_GL = codeset;
+ }
+ }
+
+ if (gen->initial_state_GR == NULL) {
+ CodeSetRec *codeset;
+ for (i = 0; i < gen->codeset_num; i++) {
+ codeset = gen->codeset_list[i];
+ if (codeset->side == XlcGR)
+ gen->initial_state_GR = codeset;
+ }
+ }
+
+ for (i = 0; i < gen->codeset_num; i++) {
+ CodeSetRec *codeset = gen->codeset_list[i];
+ for (ii = 0; ii < codeset->num_charsets; ii++) {
+ charset = codeset->charset_list[ii];
+ if (! strcmp(charset->encoding_name, "ISO8859-1"))
+ charset->string_encoding = True;
+ if ( charset->string_encoding )
+ codeset->string_encoding = True;
+ }
+ }
+ return True;
+
+err:
+ free_charset(lcd);
+
+ return False;
+}
+
+#ifdef USE_DYNAMIC_LC
+/* override the open_om and open_im methods which were set by
+ super_class's initialize method() */
+
+static Bool
+initialize_core(
+ XLCd lcd)
+{
+ _XInitDynamicOM(lcd);
+
+ _XInitDynamicIM(lcd);
+
+ return True;
+}
+#endif
+
+static Bool
+initialize(XLCd lcd)
+{
+ XLCdPublicMethods superclass = (XLCdPublicMethods) _XlcPublicMethods;
+
+ XLC_PUBLIC_METHODS(lcd)->superclass = superclass;
+
+ if (superclass->pub.initialize) {
+ if ((*superclass->pub.initialize)(lcd) == False)
+ return False;
+ }
+
+#ifdef USE_DYNAMIC_LC
+ if (initialize_core(lcd) == False)
+ return False;
+#endif
+
+ if (load_generic(lcd) == False)
+ return False;
+
+ return True;
+}
+
+/* VW/UDC start 95.01.08 */
+static void
+freeByteM(
+ CodeSet codeset)
+{
+ int i;
+ ByteInfoList blst;
+ if (codeset->byteM == NULL) {
+ return ;
+ }
+ blst = codeset->byteM;
+ for (i = 0; i < codeset->length; i++) {
+ if (blst[i].byteinfo) {
+ Xfree(blst[i].byteinfo);
+ blst[i].byteinfo = NULL;
+ }
+ }
+ Xfree(codeset->byteM);
+ codeset->byteM = NULL;
+}
+
+static void
+freeConversion(
+ CodeSet codeset)
+{
+ Conversion mbconv,ctconv;
+ if (codeset->mbconv) {
+ mbconv = codeset->mbconv;
+ /* ... */
+ if (mbconv->convlist) {
+ Xfree(mbconv->convlist);
+ mbconv->convlist = NULL;
+ }
+ Xfree(mbconv);
+ codeset->mbconv = NULL;
+ }
+ if (codeset->ctconv) {
+ ctconv = codeset->ctconv;
+ /* ... */
+ if (ctconv->convlist) {
+ Xfree(ctconv->convlist);
+ ctconv->convlist = NULL;
+ }
+ Xfree(ctconv);
+ codeset->ctconv = NULL;
+ }
+}
+
+static void
+freeExtdSegment(
+ CodeSet codeset)
+{
+ ExtdSegment ctextseg;
+ if (codeset->ctextseg == NULL) {
+ return;
+ }
+ ctextseg = codeset->ctextseg;
+ if (ctextseg->name) {
+ Xfree(ctextseg->name);
+ ctextseg->name = NULL;
+ }
+ if (ctextseg->area) {
+ Xfree(ctextseg->area);
+ ctextseg->area = NULL;
+ }
+ Xfree(codeset->ctextseg);
+ codeset->ctextseg = NULL;
+}
+
+static void
+freeParseInfo(
+ CodeSet codeset)
+{
+ ParseInfo parse_info;
+ if (codeset->parse_info == NULL) {
+ return;
+ }
+ parse_info = codeset->parse_info;
+ if (parse_info->encoding) {
+ Xfree(parse_info->encoding);
+ parse_info->encoding = NULL;
+ }
+ Xfree(codeset->parse_info);
+ codeset->parse_info = NULL;
+}
+
+static void
+destroy_CodeSetList(
+ XLCdGenericPart *gen)
+{
+ CodeSet *codeset = gen->codeset_list;
+ int i;
+ if (gen->codeset_num == 0) {
+ return;
+ }
+ for (i=0;i<gen->codeset_num;i++) {
+ freeByteM(codeset[i]);
+ freeConversion(codeset[i]);
+ freeExtdSegment(codeset[i]);
+ freeParseInfo(codeset[i]);
+ if (codeset[i]->charset_list) {
+ Xfree(codeset[i]->charset_list);
+ codeset[i]->charset_list = NULL;
+ }
+ Xfree(codeset[i]); codeset[i]=NULL;
+ }
+ Xfree(codeset); gen->codeset_list = NULL;
+}
+
+static void
+destroy_SegConv(
+ XLCdGenericPart *gen)
+{
+ SegConv seg = gen->segment_conv;
+ int i;
+ if (gen->segment_conv_num == 0) {
+ return;
+ }
+ for (i=0;i<gen->segment_conv_num;i++) {
+ if (seg[i].source_encoding) {
+ Xfree(seg[i].source_encoding);
+ seg[i].source_encoding = NULL;
+ }
+ if (seg[i].destination_encoding) {
+ Xfree(seg[i].destination_encoding);
+ seg[i].destination_encoding = NULL;
+ }
+ if (seg[i].conv) {
+ Xfree(seg[i].conv); seg[i].conv = NULL;
+ }
+ }
+ Xfree(seg); gen->segment_conv = NULL;
+}
+
+static void
+destroy_gen(
+ XLCd lcd)
+{
+ XLCdGenericPart *gen = XLC_GENERIC_PART(lcd);
+ destroy_SegConv(gen);
+ destroy_CodeSetList(gen);
+ if (gen->mb_parse_table) {
+ Xfree(gen->mb_parse_table);
+ gen->mb_parse_table = NULL;
+ }
+ if (gen->mb_parse_list) {
+ Xfree(gen->mb_parse_list);
+ gen->mb_parse_list = NULL;
+ }
+}
+/* VW/UDC end 95.01.08 */
+
+static void
+destroy(
+ XLCd lcd)
+{
+ XLCdPublicMethods superclass = XLC_PUBLIC_METHODS(lcd)->superclass;
+
+ destroy_gen(lcd); /* ADD 1996.01.08 */
+ if (superclass && superclass->pub.destroy)
+ (*superclass->pub.destroy)(lcd);
+}
diff --git a/libX11/src/xlibi18n/lcPublic.c b/libX11/src/xlibi18n/lcPublic.c
index 2c02f5fba..d0db410fc 100644
--- a/libX11/src/xlibi18n/lcPublic.c
+++ b/libX11/src/xlibi18n/lcPublic.c
@@ -1,317 +1,314 @@
-/*
- * Copyright 1992, 1993 by TOSHIBA Corp.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of TOSHIBA not be used in advertising
- * or publicity pertaining to distribution of the software without specific,
- * written prior permission. TOSHIBA make no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
- * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- *
- * Author: Katsuhisa Yano TOSHIBA Corp.
- * mopi@osa.ilab.toshiba.co.jp
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include "Xlibint.h"
-#include "XlcPubI.h"
-
-static const char *
-default_string(
- XLCd lcd)
-{
- return XLC_PUBLIC(lcd, default_string);
-}
-
-static XLCd create (const char *name, XLCdMethods methods);
-static Bool initialize (XLCd lcd);
-static void destroy (XLCd lcd);
-static char *get_values (XLCd lcd, XlcArgList args, int num_args);
-
-static XLCdPublicMethodsRec publicMethods = {
- {
- destroy,
- _XlcDefaultMapModifiers,
- NULL,
- NULL,
- _XrmDefaultInitParseInfo,
- _XmbTextPropertyToTextList,
- _XwcTextPropertyToTextList,
- _Xutf8TextPropertyToTextList,
- _XmbTextListToTextProperty,
- _XwcTextListToTextProperty,
- _Xutf8TextListToTextProperty,
- _XwcFreeStringList,
- default_string,
- NULL,
- NULL
- },
- {
- NULL,
- create,
- initialize,
- destroy,
- get_values,
- _XlcGetLocaleDataBase
- }
-};
-
-XLCdMethods _XlcPublicMethods = (XLCdMethods) &publicMethods;
-
-static XLCd
-create(
- const char *name,
- XLCdMethods methods)
-{
- XLCd lcd;
- XLCdPublicMethods new;
-
- lcd = (XLCd) Xmalloc(sizeof(XLCdRec));
- if (lcd == NULL)
- return (XLCd) NULL;
- bzero((char *) lcd, sizeof(XLCdRec));
-
- lcd->core = (XLCdCore) Xmalloc(sizeof(XLCdPublicRec));
- if (lcd->core == NULL)
- goto err;
- bzero((char *) lcd->core, sizeof(XLCdPublicRec));
-
- new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec));
- if (new == NULL)
- goto err;
- memcpy(new,methods,sizeof(XLCdPublicMethodsRec));
- lcd->methods = (XLCdMethods) new;
-
- return lcd;
-
-err:
- Xfree(lcd);
- return (XLCd) NULL;
-}
-
-static Bool
-load_public(
- XLCd lcd)
-{
- XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd);
- char **values, *str;
- int num;
-
- if(_XlcCreateLocaleDataBase(lcd) == NULL)
- return False;
-
- _XlcGetResource(lcd, "XLC_XLOCALE", "mb_cur_max", &values, &num);
- if (num > 0) {
- pub->mb_cur_max = atoi(values[0]);
- if (pub->mb_cur_max < 1)
- pub->mb_cur_max = 1;
- } else
- pub->mb_cur_max = 1;
-
- _XlcGetResource(lcd, "XLC_XLOCALE", "state_depend_encoding", &values, &num);
- if (num > 0 && !_XlcCompareISOLatin1(values[0], "True"))
- pub->is_state_depend = True;
- else
- pub->is_state_depend = False;
-
- _XlcGetResource(lcd, "XLC_XLOCALE", "encoding_name", &values, &num);
- str = (num > 0) ? values[0] : "STRING";
- pub->encoding_name = (char*) Xmalloc(strlen(str) + 1);
- if (pub->encoding_name == NULL)
- return False;
- strcpy(pub->encoding_name, str);
-
- return True;
-}
-
-static Bool
-initialize_core(
- XLCd lcd)
-{
- XLCdMethods methods = lcd->methods;
- XLCdMethods core = &publicMethods.core;
-
- if (methods->close == NULL)
- methods->close = core->close;
-
- if (methods->map_modifiers == NULL)
- methods->map_modifiers = core->map_modifiers;
-
- if (methods->open_om == NULL)
-#ifdef USE_DYNAMIC_LC
- _XInitDefaultOM(lcd);
-#else
- _XInitOM(lcd);
-#endif
-
- if (methods->open_im == NULL)
-#ifdef USE_DYNAMIC_LC
- _XInitDefaultIM(lcd);
-#else
- _XInitIM(lcd);
-#endif
-
- if (methods->init_parse_info == NULL)
- methods->init_parse_info = core->init_parse_info;
-
- if (methods->mb_text_prop_to_list == NULL)
- methods->mb_text_prop_to_list = core->mb_text_prop_to_list;
-
- if (methods->wc_text_prop_to_list == NULL)
- methods->wc_text_prop_to_list = core->wc_text_prop_to_list;
-
- if (methods->utf8_text_prop_to_list == NULL)
- methods->utf8_text_prop_to_list = core->utf8_text_prop_to_list;
-
- if (methods->mb_text_list_to_prop == NULL)
- methods->mb_text_list_to_prop = core->mb_text_list_to_prop;
-
- if (methods->wc_text_list_to_prop == NULL)
- methods->wc_text_list_to_prop = core->wc_text_list_to_prop;
-
- if (methods->utf8_text_list_to_prop == NULL)
- methods->utf8_text_list_to_prop = core->utf8_text_list_to_prop;
-
- if (methods->wc_free_string_list == NULL)
- methods->wc_free_string_list = core->wc_free_string_list;
-
- if (methods->default_string == NULL)
- methods->default_string = core->default_string;
-
- return True;
-}
-
-static Bool
-initialize(
- XLCd lcd)
-{
- XLCdPublicMethodsPart *methods = XLC_PUBLIC_METHODS(lcd);
- XLCdPublicMethodsPart *pub_methods = &publicMethods.pub;
- XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd);
- char *name;
-#if !defined(X_LOCALE)
- int len;
- char sinamebuf[256];
- char* siname;
-#endif
-
- _XlcInitCTInfo();
-
- if (initialize_core(lcd) == False)
- return False;
-
- name = lcd->core->name;
-#if !defined(X_LOCALE)
- /*
- * _XlMapOSLocaleName will return the same string or a substring
- * of name, so strlen(name) is okay
- */
- if ((len = strlen(name)) < sizeof sinamebuf)
- siname = sinamebuf;
- else
- siname = Xmalloc (len + 1);
- if (siname == NULL)
- return False;
- name = _XlcMapOSLocaleName(name, siname);
-#endif
- /* _XlcResolveLocaleName will lookup the SI's name for the locale */
- if (_XlcResolveLocaleName(name, pub) == 0) {
-#if !defined(X_LOCALE)
- if (siname != sinamebuf) Xfree (siname);
-#endif
- return False;
- }
-#if !defined(X_LOCALE)
- if (siname != sinamebuf)
- Xfree (siname);
-#endif
-
- if (pub->default_string == NULL)
- pub->default_string = "";
-
- if (methods->get_values == NULL)
- methods->get_values = pub_methods->get_values;
-
- if (methods->get_resource == NULL)
- methods->get_resource = pub_methods->get_resource;
-
- return load_public(lcd);
-}
-
-static void
-destroy_core(
- XLCd lcd)
-{
- if (lcd->core) {
- if (lcd->core->name)
- Xfree(lcd->core->name);
- Xfree(lcd->core);
- }
-
- if (lcd->methods)
- Xfree(lcd->methods);
-
- Xfree(lcd);
-}
-
-static void
-destroy(
- XLCd lcd)
-{
- XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd);
-
- _XlcDestroyLocaleDataBase(lcd);
-
- if (pub->siname)
- Xfree(pub->siname);
- if (pub->encoding_name)
- Xfree(pub->encoding_name);
-
- destroy_core(lcd);
-}
-
-static XlcResource resources[] = {
- { XlcNCodeset, NULLQUARK, sizeof(char *),
- XOffsetOf(XLCdPublicRec, pub.codeset), XlcGetMask },
- { XlcNDefaultString, NULLQUARK, sizeof(char *),
- XOffsetOf(XLCdPublicRec, pub.default_string), XlcGetMask },
- { XlcNEncodingName, NULLQUARK, sizeof(char *),
- XOffsetOf(XLCdPublicRec, pub.encoding_name), XlcGetMask },
- { XlcNLanguage, NULLQUARK, sizeof(char *),
- XOffsetOf(XLCdPublicRec, pub.language), XlcGetMask },
- { XlcNMbCurMax, NULLQUARK, sizeof(int),
- XOffsetOf(XLCdPublicRec, pub.mb_cur_max), XlcGetMask },
- { XlcNStateDependentEncoding, NULLQUARK, sizeof(Bool),
- XOffsetOf(XLCdPublicRec, pub.is_state_depend), XlcGetMask },
- { XlcNTerritory, NULLQUARK, sizeof(char *),
- XOffsetOf(XLCdPublicRec, pub.territory), XlcGetMask }
-};
-
-static char *
-get_values(
- XLCd lcd,
- XlcArgList args,
- int num_args)
-{
- XLCdPublic pub = (XLCdPublic) lcd->core;
-
- if (resources[0].xrm_name == NULLQUARK)
- _XlcCompileResourceList(resources, XlcNumber(resources));
-
- return _XlcGetValues((XPointer) pub, resources, XlcNumber(resources), args,
- num_args, XlcGetMask);
-}
+/*
+ * Copyright 1992, 1993 by TOSHIBA Corp.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of TOSHIBA not be used in advertising
+ * or publicity pertaining to distribution of the software without specific,
+ * written prior permission. TOSHIBA make no representations about the
+ * suitability of this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+ * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ *
+ * Author: Katsuhisa Yano TOSHIBA Corp.
+ * mopi@osa.ilab.toshiba.co.jp
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include "Xlibint.h"
+#include "XlcPubI.h"
+
+static const char *
+default_string(
+ XLCd lcd)
+{
+ return XLC_PUBLIC(lcd, default_string);
+}
+
+static XLCd create (const char *name, XLCdMethods methods);
+static Bool initialize (XLCd lcd);
+static void destroy (XLCd lcd);
+static char *get_values (XLCd lcd, XlcArgList args, int num_args);
+
+static XLCdPublicMethodsRec publicMethods = {
+ {
+ destroy,
+ _XlcDefaultMapModifiers,
+ NULL,
+ NULL,
+ _XrmDefaultInitParseInfo,
+ _XmbTextPropertyToTextList,
+ _XwcTextPropertyToTextList,
+ _Xutf8TextPropertyToTextList,
+ _XmbTextListToTextProperty,
+ _XwcTextListToTextProperty,
+ _Xutf8TextListToTextProperty,
+ _XwcFreeStringList,
+ default_string,
+ NULL,
+ NULL
+ },
+ {
+ NULL,
+ create,
+ initialize,
+ destroy,
+ get_values,
+ _XlcGetLocaleDataBase
+ }
+};
+
+XLCdMethods _XlcPublicMethods = (XLCdMethods) &publicMethods;
+
+static XLCd
+create(
+ const char *name,
+ XLCdMethods methods)
+{
+ XLCd lcd;
+ XLCdPublicMethods new;
+
+ lcd = Xcalloc(1, sizeof(XLCdRec));
+ if (lcd == NULL)
+ return (XLCd) NULL;
+
+ lcd->core = Xcalloc(1, sizeof(XLCdPublicRec));
+ if (lcd->core == NULL)
+ goto err;
+
+ new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec));
+ if (new == NULL)
+ goto err;
+ memcpy(new,methods,sizeof(XLCdPublicMethodsRec));
+ lcd->methods = (XLCdMethods) new;
+
+ return lcd;
+
+err:
+ Xfree(lcd);
+ return (XLCd) NULL;
+}
+
+static Bool
+load_public(
+ XLCd lcd)
+{
+ XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd);
+ char **values, *str;
+ int num;
+
+ if(_XlcCreateLocaleDataBase(lcd) == NULL)
+ return False;
+
+ _XlcGetResource(lcd, "XLC_XLOCALE", "mb_cur_max", &values, &num);
+ if (num > 0) {
+ pub->mb_cur_max = atoi(values[0]);
+ if (pub->mb_cur_max < 1)
+ pub->mb_cur_max = 1;
+ } else
+ pub->mb_cur_max = 1;
+
+ _XlcGetResource(lcd, "XLC_XLOCALE", "state_depend_encoding", &values, &num);
+ if (num > 0 && !_XlcCompareISOLatin1(values[0], "True"))
+ pub->is_state_depend = True;
+ else
+ pub->is_state_depend = False;
+
+ _XlcGetResource(lcd, "XLC_XLOCALE", "encoding_name", &values, &num);
+ str = (num > 0) ? values[0] : "STRING";
+ pub->encoding_name = strdup(str);
+ if (pub->encoding_name == NULL)
+ return False;
+
+ return True;
+}
+
+static Bool
+initialize_core(
+ XLCd lcd)
+{
+ XLCdMethods methods = lcd->methods;
+ XLCdMethods core = &publicMethods.core;
+
+ if (methods->close == NULL)
+ methods->close = core->close;
+
+ if (methods->map_modifiers == NULL)
+ methods->map_modifiers = core->map_modifiers;
+
+ if (methods->open_om == NULL)
+#ifdef USE_DYNAMIC_LC
+ _XInitDefaultOM(lcd);
+#else
+ _XInitOM(lcd);
+#endif
+
+ if (methods->open_im == NULL)
+#ifdef USE_DYNAMIC_LC
+ _XInitDefaultIM(lcd);
+#else
+ _XInitIM(lcd);
+#endif
+
+ if (methods->init_parse_info == NULL)
+ methods->init_parse_info = core->init_parse_info;
+
+ if (methods->mb_text_prop_to_list == NULL)
+ methods->mb_text_prop_to_list = core->mb_text_prop_to_list;
+
+ if (methods->wc_text_prop_to_list == NULL)
+ methods->wc_text_prop_to_list = core->wc_text_prop_to_list;
+
+ if (methods->utf8_text_prop_to_list == NULL)
+ methods->utf8_text_prop_to_list = core->utf8_text_prop_to_list;
+
+ if (methods->mb_text_list_to_prop == NULL)
+ methods->mb_text_list_to_prop = core->mb_text_list_to_prop;
+
+ if (methods->wc_text_list_to_prop == NULL)
+ methods->wc_text_list_to_prop = core->wc_text_list_to_prop;
+
+ if (methods->utf8_text_list_to_prop == NULL)
+ methods->utf8_text_list_to_prop = core->utf8_text_list_to_prop;
+
+ if (methods->wc_free_string_list == NULL)
+ methods->wc_free_string_list = core->wc_free_string_list;
+
+ if (methods->default_string == NULL)
+ methods->default_string = core->default_string;
+
+ return True;
+}
+
+static Bool
+initialize(
+ XLCd lcd)
+{
+ XLCdPublicMethodsPart *methods = XLC_PUBLIC_METHODS(lcd);
+ XLCdPublicMethodsPart *pub_methods = &publicMethods.pub;
+ XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd);
+ char *name;
+#if !defined(X_LOCALE)
+ int len;
+ char sinamebuf[256];
+ char* siname;
+#endif
+
+ _XlcInitCTInfo();
+
+ if (initialize_core(lcd) == False)
+ return False;
+
+ name = lcd->core->name;
+#if !defined(X_LOCALE)
+ /*
+ * _XlMapOSLocaleName will return the same string or a substring
+ * of name, so strlen(name) is okay
+ */
+ if ((len = strlen(name)) < sizeof sinamebuf)
+ siname = sinamebuf;
+ else
+ siname = Xmalloc (len + 1);
+ if (siname == NULL)
+ return False;
+ name = _XlcMapOSLocaleName(name, siname);
+#endif
+ /* _XlcResolveLocaleName will lookup the SI's name for the locale */
+ if (_XlcResolveLocaleName(name, pub) == 0) {
+#if !defined(X_LOCALE)
+ if (siname != sinamebuf) Xfree (siname);
+#endif
+ return False;
+ }
+#if !defined(X_LOCALE)
+ if (siname != sinamebuf)
+ Xfree (siname);
+#endif
+
+ if (pub->default_string == NULL)
+ pub->default_string = "";
+
+ if (methods->get_values == NULL)
+ methods->get_values = pub_methods->get_values;
+
+ if (methods->get_resource == NULL)
+ methods->get_resource = pub_methods->get_resource;
+
+ return load_public(lcd);
+}
+
+static void
+destroy_core(
+ XLCd lcd)
+{
+ if (lcd->core) {
+ if (lcd->core->name)
+ Xfree(lcd->core->name);
+ Xfree(lcd->core);
+ }
+
+ if (lcd->methods)
+ Xfree(lcd->methods);
+
+ Xfree(lcd);
+}
+
+static void
+destroy(
+ XLCd lcd)
+{
+ XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd);
+
+ _XlcDestroyLocaleDataBase(lcd);
+
+ if (pub->siname)
+ Xfree(pub->siname);
+ if (pub->encoding_name)
+ Xfree(pub->encoding_name);
+
+ destroy_core(lcd);
+}
+
+static XlcResource resources[] = {
+ { XlcNCodeset, NULLQUARK, sizeof(char *),
+ XOffsetOf(XLCdPublicRec, pub.codeset), XlcGetMask },
+ { XlcNDefaultString, NULLQUARK, sizeof(char *),
+ XOffsetOf(XLCdPublicRec, pub.default_string), XlcGetMask },
+ { XlcNEncodingName, NULLQUARK, sizeof(char *),
+ XOffsetOf(XLCdPublicRec, pub.encoding_name), XlcGetMask },
+ { XlcNLanguage, NULLQUARK, sizeof(char *),
+ XOffsetOf(XLCdPublicRec, pub.language), XlcGetMask },
+ { XlcNMbCurMax, NULLQUARK, sizeof(int),
+ XOffsetOf(XLCdPublicRec, pub.mb_cur_max), XlcGetMask },
+ { XlcNStateDependentEncoding, NULLQUARK, sizeof(Bool),
+ XOffsetOf(XLCdPublicRec, pub.is_state_depend), XlcGetMask },
+ { XlcNTerritory, NULLQUARK, sizeof(char *),
+ XOffsetOf(XLCdPublicRec, pub.territory), XlcGetMask }
+};
+
+static char *
+get_values(
+ XLCd lcd,
+ XlcArgList args,
+ int num_args)
+{
+ XLCdPublic pub = (XLCdPublic) lcd->core;
+
+ if (resources[0].xrm_name == NULLQUARK)
+ _XlcCompileResourceList(resources, XlcNumber(resources));
+
+ return _XlcGetValues((XPointer) pub, resources, XlcNumber(resources), args,
+ num_args, XlcGetMask);
+}