11ab64890Smrg/* 21ab64890SmrgCopyright 1985, 1986, 1987, 1991, 1998 The Open Group 31ab64890Smrg 41ab64890SmrgPermission is hereby granted, free of charge, to any person obtaining a 51ab64890Smrgcopy of this software and associated documentation files (the 61ab64890Smrg"Software"), to deal in the Software without restriction, including 71ab64890Smrgwithout limitation the rights to use, copy, modify, merge, publish, 81ab64890Smrgdistribute, sublicense, and/or sell copies of the Software, and to 91ab64890Smrgpermit persons to whom the Software is furnished to do so, subject to 101ab64890Smrgthe following conditions: The above copyright notice and this 111ab64890Smrgpermission notice shall be included in all copies or substantial 121ab64890Smrgportions of the Software. 131ab64890Smrg 141ab64890Smrg 155a473929SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 165a473929SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 175a473929SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 185a473929SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 195a473929SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 205a473929SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE 215a473929SmrgEVEN IF ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES. 221ab64890Smrg 231ab64890Smrg 245a473929SmrgExcept as contained in this notice, the name of The Open Group shall not be 255a473929Smrgused in advertising or otherwise to promote the sale, use or other dealings 265a473929Smrgin this Software without prior written authorization from The Open Group. 271ab64890Smrg 281ab64890Smrg 291ab64890SmrgX Window System is a trademark of The Open Group 301ab64890Smrg 311ab64890SmrgOSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF 321ab64890Smrglogo, LBX, X Window System, and Xinerama are trademarks of the Open 331ab64890SmrgGroup. All other trademarks and registered trademarks mentioned herein 341ab64890Smrgare the property of their respective owners. No right, title or 351ab64890Smrginterest in or to any trademark, service mark, logo or trade name of 361ab64890SmrgSun Microsystems, Inc. or its licensors is granted. 371ab64890Smrg 381ab64890Smrg*/ 395a473929Smrg/* 40ff3f3c6fSmrg * Copyright (c) 2000, Oracle and/or its affiliates. 415a473929Smrg * 425a473929Smrg * Permission is hereby granted, free of charge, to any person obtaining a 435a473929Smrg * copy of this software and associated documentation files (the "Software"), 445a473929Smrg * to deal in the Software without restriction, including without limitation 455a473929Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 465a473929Smrg * and/or sell copies of the Software, and to permit persons to whom the 475a473929Smrg * Software is furnished to do so, subject to the following conditions: 485a473929Smrg * 495a473929Smrg * The above copyright notice and this permission notice (including the next 505a473929Smrg * paragraph) shall be included in all copies or substantial portions of the 515a473929Smrg * Software. 525a473929Smrg * 535a473929Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 545a473929Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 555a473929Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 565a473929Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 575a473929Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 585a473929Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 595a473929Smrg * DEALINGS IN THE SOFTWARE. 605a473929Smrg */ 615a473929Smrg 621ab64890Smrg 631ab64890Smrg#ifdef HAVE_CONFIG_H 641ab64890Smrg# include <config.h> 651ab64890Smrg#else 66c6e579a2Smrg# define HAVE_DLFCN_H 671ab64890Smrg#endif 681ab64890Smrg 691ab64890Smrg#include <stdio.h> 701ab64890Smrg 711ab64890Smrg#ifdef HAVE_DLFCN_H 721ab64890Smrg#include <dlfcn.h> 731ab64890Smrg#endif 741ab64890Smrg 751ab64890Smrg#include <ctype.h> 761ab64890Smrg 771ab64890Smrg#include "Xlibint.h" 781ab64890Smrg#include "XlcPublic.h" 791ab64890Smrg#include "XlcPubI.h" 80f2d49d05Smrg#include "reallocarray.h" 811ab64890Smrg 821ab64890Smrg#define XI18N_DLREL 2 831ab64890Smrg 841ab64890Smrg#define iscomment(ch) ((ch) == '\0' || (ch) == '#') 851ab64890Smrg 861ab64890Smrgtypedef enum { 871ab64890Smrg XLC_OBJECT, 881ab64890Smrg XIM_OBJECT, 891ab64890Smrg XOM_OBJECT 901ab64890Smrg} XI18NDLType; 911ab64890Smrg 921ab64890Smrgtypedef struct { 931ab64890Smrg XI18NDLType type; 941ab64890Smrg int locale_name_len; 951ab64890Smrg char *locale_name; 961ab64890Smrg char *dl_name; 971ab64890Smrg char *open; 981ab64890Smrg char *im_register; 991ab64890Smrg char *im_unregister; 1001ab64890Smrg int dl_release; 1011ab64890Smrg unsigned int refcount; 1021ab64890Smrg void *dl_module; 1031ab64890Smrg} XI18NObjectsListRec, *XI18NObjectsList; 1041ab64890Smrg 1051ab64890Smrg#define OBJECT_INIT_LEN 8 1061ab64890Smrg#define OBJECT_INC_LEN 4 1071ab64890Smrgstatic int lc_len = 0; 1081ab64890Smrgstatic XI18NObjectsListRec *xi18n_objects_list = NULL; 1091ab64890Smrgstatic int lc_count = 0; 1101ab64890Smrg 1111ab64890Smrgstatic int 1121ab64890Smrgparse_line(char *line, char **argv, int argsize) 1131ab64890Smrg{ 1141ab64890Smrg int argc = 0; 1151ab64890Smrg char *p = line; 1161ab64890Smrg 1171ab64890Smrg while (argc < argsize) { 1181ab64890Smrg while (isspace(*p)) { 1191ab64890Smrg ++p; 1201ab64890Smrg } 1211ab64890Smrg if (iscomment(*p)){ 1221ab64890Smrg break; 1231ab64890Smrg } 1241ab64890Smrg argv[argc++] = p; 1251ab64890Smrg while (!isspace(*p)) { 1261ab64890Smrg ++p; 1271ab64890Smrg } 1281ab64890Smrg if (iscomment(*p)) { 1291ab64890Smrg break; 1301ab64890Smrg } 1311ab64890Smrg *p++ = '\0'; 1321ab64890Smrg } 1331ab64890Smrg return argc; 1341ab64890Smrg} 1351ab64890Smrg 1361ab64890Smrgstatic char * 1371ab64890Smrgstrdup_with_underscore(const char *symbol) 1381ab64890Smrg{ 1391ab64890Smrg char *result; 1401ab64890Smrg 1412f44462dSmrg if ((result = malloc(strlen(symbol) + 2)) == NULL) 1421ab64890Smrg return NULL; 1431ab64890Smrg result[0] = '_'; 1441ab64890Smrg strcpy(result + 1, symbol); 1451ab64890Smrg return result; 1461ab64890Smrg} 1471ab64890Smrg 1481ab64890Smrgstatic void * 1491ab64890Smrgtry_both_dlsym (void *handle, char *name) 1501ab64890Smrg{ 1511ab64890Smrg void *ret; 1521ab64890Smrg 1531ab64890Smrg ret = dlsym (handle, name); 1541ab64890Smrg if (!ret) 1551ab64890Smrg { 1561ab64890Smrg name = strdup_with_underscore (name); 1571ab64890Smrg if (name) 1581ab64890Smrg { 1591ab64890Smrg ret = dlsym (handle, name); 1601ab64890Smrg free (name); 1611ab64890Smrg } 1621ab64890Smrg } 1631ab64890Smrg return ret; 1641ab64890Smrg} 1651ab64890Smrg 1661ab64890Smrgstatic void 1671ab64890Smrgresolve_object(char *path, const char *lc_name) 1681ab64890Smrg{ 1691ab64890Smrg char filename[BUFSIZ]; 1701ab64890Smrg FILE *fp; 1711ab64890Smrg char buf[BUFSIZ]; 1721ab64890Smrg 1731ab64890Smrg if (lc_len == 0) { /* True only for the 1st time */ 1741ab64890Smrg lc_len = OBJECT_INIT_LEN; 175f2d49d05Smrg xi18n_objects_list = Xmallocarray(lc_len, sizeof(XI18NObjectsListRec)); 1761ab64890Smrg if (!xi18n_objects_list) return; 1771ab64890Smrg } 178c555af55Smrg snprintf(filename, sizeof(filename), "%s/%s", path, "XI18N_OBJS"); 1791ab64890Smrg fp = fopen(filename, "r"); 1801ab64890Smrg if (fp == (FILE *)NULL){ 1811ab64890Smrg return; 1821ab64890Smrg } 1831ab64890Smrg 1841ab64890Smrg while (fgets(buf, BUFSIZ, fp) != NULL){ 1851ab64890Smrg char *p = buf; 1861ab64890Smrg int n; 1871ab64890Smrg char *args[6]; 1881ab64890Smrg while (isspace(*p)){ 1891ab64890Smrg ++p; 1901ab64890Smrg } 1911ab64890Smrg if (iscomment(*p)){ 1921ab64890Smrg continue; 1931ab64890Smrg } 1941ab64890Smrg 1951ab64890Smrg if (lc_count == lc_len) { 196c555af55Smrg int new_len = lc_len + OBJECT_INC_LEN; 197f2d49d05Smrg XI18NObjectsListRec *tmp = 198f2d49d05Smrg Xreallocarray(xi18n_objects_list, new_len, 199f2d49d05Smrg sizeof(XI18NObjectsListRec)); 200c555af55Smrg if (tmp == NULL) 201c555af55Smrg goto done; 202c555af55Smrg xi18n_objects_list = tmp; 203c555af55Smrg lc_len = new_len; 2041ab64890Smrg } 2051ab64890Smrg n = parse_line(p, args, 6); 2062f44462dSmrg 2071ab64890Smrg if (n == 3 || n == 5) { 2081ab64890Smrg if (!strcmp(args[0], "XLC")){ 2091ab64890Smrg xi18n_objects_list[lc_count].type = XLC_OBJECT; 2101ab64890Smrg } else if (!strcmp(args[0], "XOM")){ 2111ab64890Smrg xi18n_objects_list[lc_count].type = XOM_OBJECT; 2121ab64890Smrg } else if (!strcmp(args[0], "XIM")){ 2131ab64890Smrg xi18n_objects_list[lc_count].type = XIM_OBJECT; 2141ab64890Smrg } 2151ab64890Smrg xi18n_objects_list[lc_count].dl_name = strdup(args[1]); 2161ab64890Smrg xi18n_objects_list[lc_count].open = strdup(args[2]); 2171ab64890Smrg xi18n_objects_list[lc_count].dl_release = XI18N_DLREL; 2181ab64890Smrg xi18n_objects_list[lc_count].locale_name = strdup(lc_name); 2191ab64890Smrg xi18n_objects_list[lc_count].refcount = 0; 2201ab64890Smrg xi18n_objects_list[lc_count].dl_module = (void*)NULL; 2211ab64890Smrg if (n == 5) { 2221ab64890Smrg xi18n_objects_list[lc_count].im_register = strdup(args[3]); 2231ab64890Smrg xi18n_objects_list[lc_count].im_unregister = strdup(args[4]); 2241ab64890Smrg } else { 2251ab64890Smrg xi18n_objects_list[lc_count].im_register = NULL; 2261ab64890Smrg xi18n_objects_list[lc_count].im_unregister = NULL; 2271ab64890Smrg } 2281ab64890Smrg lc_count++; 2291ab64890Smrg } 2301ab64890Smrg } 231c555af55Smrg done: 2321ab64890Smrg fclose(fp); 2331ab64890Smrg} 2341ab64890Smrg 2351ab64890Smrgstatic char* 2361ab64890Smrg__lc_path(const char *dl_name, const char *lc_dir) 2371ab64890Smrg{ 2381ab64890Smrg char *path; 2391ab64890Smrg size_t len; 240dac667f7Smrg char *slash_p; 2411ab64890Smrg 2421ab64890Smrg /* 2431ab64890Smrg * reject this for possible security issue 2441ab64890Smrg */ 2451ab64890Smrg if (strstr (dl_name, "../")) 2461ab64890Smrg return NULL; 2471ab64890Smrg 2481ab64890Smrg len = (lc_dir ? strlen(lc_dir) : 0 ) + 2491ab64890Smrg (dl_name ? strlen(dl_name) : 0) + 10; 2501ab64890Smrg#if defined POSTLOCALELIBDIR 2511ab64890Smrg len += (strlen(POSTLOCALELIBDIR) + 1); 2521ab64890Smrg#endif 2531ab64890Smrg path = Xmalloc(len + 1); 2541ab64890Smrg 2551ab64890Smrg if (strchr(dl_name, '/') != NULL) { 2561ab64890Smrg slash_p = strrchr(lc_dir, '/'); 2571ab64890Smrg *slash_p = '\0'; 258dac667f7Smrg } else 259dac667f7Smrg slash_p = NULL; 260dac667f7Smrg 2611ab64890Smrg#if defined POSTLOCALELIBDIR 262dac667f7Smrg snprintf(path, len + 1, "%s/%s/%s.so.2", 263dac667f7Smrg lc_dir, POSTLOCALELIBDIR, dl_name); 264dac667f7Smrg#else 265dac667f7Smrg snprintf(path, len + 1, "%s/%s.so.2", lc_dir, dl_name); 2661ab64890Smrg#endif 267dac667f7Smrg 268dac667f7Smrg if (slash_p != NULL) 2691ab64890Smrg *slash_p = '/'; 270dac667f7Smrg 2711ab64890Smrg return path; 2721ab64890Smrg} 2731ab64890Smrg 2741ab64890Smrg/* We reference count dlopen() and dlclose() of modules; unfortunately, 2751ab64890Smrg * since XCloseIM, XCloseOM, XlcClose aren't wrapped, but directly 2761ab64890Smrg * call the close method of the object, we leak a reference count every 2771ab64890Smrg * time we open then close a module. Fixing this would require 2781ab64890Smrg * either creating proxy objects or hooks for close_im/close_om 2791ab64890Smrg * in XLCd 2801ab64890Smrg */ 2811ab64890Smrgstatic Bool 2821ab64890Smrgopen_object( 2831ab64890Smrg XI18NObjectsList object, 2841ab64890Smrg char *lc_dir) 2851ab64890Smrg{ 2861ab64890Smrg char *path; 2872f44462dSmrg 2881ab64890Smrg if (object->refcount == 0) { 2891ab64890Smrg path = __lc_path(object->dl_name, lc_dir); 2901ab64890Smrg if (!path) 2911ab64890Smrg return False; 2921ab64890Smrg object->dl_module = dlopen(path, RTLD_LAZY); 2931ab64890Smrg Xfree(path); 2941ab64890Smrg 2951ab64890Smrg if (!object->dl_module) 2961ab64890Smrg return False; 2971ab64890Smrg } 2981ab64890Smrg 2991ab64890Smrg object->refcount++; 3001ab64890Smrg return True; 3011ab64890Smrg} 3021ab64890Smrg 3031ab64890Smrgstatic void * 3041ab64890Smrgfetch_symbol( 3051ab64890Smrg XI18NObjectsList object, 3061ab64890Smrg char *symbol) 3071ab64890Smrg{ 3081ab64890Smrg void *result = NULL; 3091ab64890Smrg 3101ab64890Smrg if (symbol == NULL) 3111ab64890Smrg return NULL; 3121ab64890Smrg 3131ab64890Smrg result = try_both_dlsym(object->dl_module, symbol); 3141ab64890Smrg 3151ab64890Smrg return result; 3161ab64890Smrg} 3171ab64890Smrg 3181ab64890Smrgstatic void 3191ab64890Smrgclose_object(XI18NObjectsList object) 3201ab64890Smrg{ 3211ab64890Smrg object->refcount--; 3221ab64890Smrg if (object->refcount == 0) 3231ab64890Smrg { 3241ab64890Smrg dlclose(object->dl_module); 3251ab64890Smrg object->dl_module = NULL; 3261ab64890Smrg } 3271ab64890Smrg} 3281ab64890Smrg 3291ab64890Smrg 3301ab64890Smrgtypedef XLCd (*dynamicLoadProc)(const char *); 3311ab64890Smrg 3321ab64890SmrgXLCd 3331ab64890Smrg_XlcDynamicLoad(const char *lc_name) 3341ab64890Smrg{ 3351ab64890Smrg XLCd lcd = (XLCd)NULL; 3361ab64890Smrg dynamicLoadProc lc_loader = (dynamicLoadProc)NULL; 3371ab64890Smrg int count; 3381ab64890Smrg XI18NObjectsList objects_list; 3391ab64890Smrg char lc_dir[BUFSIZE], lc_lib_dir[BUFSIZE]; 3401ab64890Smrg 3411ab64890Smrg if (lc_name == NULL) return (XLCd)NULL; 3421ab64890Smrg 343c555af55Smrg if (_XlcLocaleDirName(lc_dir, BUFSIZE, lc_name) == NULL) 3441ab64890Smrg return (XLCd)NULL; 345c555af55Smrg if (_XlcLocaleLibDirName(lc_lib_dir, BUFSIZE, lc_name) == NULL) 3461ab64890Smrg return (XLCd)NULL; 3471ab64890Smrg 3481ab64890Smrg resolve_object(lc_dir, lc_name); 3491ab64890Smrg resolve_object(lc_lib_dir, lc_name); 3501ab64890Smrg 3511ab64890Smrg objects_list = xi18n_objects_list; 3521ab64890Smrg count = lc_count; 3531ab64890Smrg for (; count-- > 0; objects_list++) { 3541ab64890Smrg if (objects_list->type != XLC_OBJECT || 3551ab64890Smrg strcmp(objects_list->locale_name, lc_name)) continue; 3561ab64890Smrg if (!open_object (objects_list, lc_dir) && \ 3571ab64890Smrg !open_object (objects_list, lc_lib_dir)) 3581ab64890Smrg continue; 3591ab64890Smrg 3601ab64890Smrg lc_loader = (dynamicLoadProc)fetch_symbol (objects_list, objects_list->open); 3611ab64890Smrg if (!lc_loader) continue; 3621ab64890Smrg lcd = (*lc_loader)(lc_name); 3631ab64890Smrg if (lcd != (XLCd)NULL) { 3641ab64890Smrg break; 3651ab64890Smrg } 3662f44462dSmrg 3671ab64890Smrg close_object (objects_list); 3681ab64890Smrg } 3691ab64890Smrg return (XLCd)lcd; 3701ab64890Smrg} 3711ab64890Smrg 3721ab64890Smrg 3731ab64890Smrgtypedef XIM (*dynamicOpenProcp)(XLCd, Display *, XrmDatabase, char *, char *); 3741ab64890Smrg 3751ab64890Smrgstatic XIM 3761ab64890Smrg_XDynamicOpenIM(XLCd lcd, Display *display, XrmDatabase rdb, 3771ab64890Smrg char *res_name, char *res_class) 3781ab64890Smrg{ 3791ab64890Smrg XIM im = (XIM)NULL; 3801ab64890Smrg char lc_dir[BUFSIZE]; 3811ab64890Smrg char *lc_name; 3821ab64890Smrg dynamicOpenProcp im_openIM = (dynamicOpenProcp)NULL; 3831ab64890Smrg int count; 3841ab64890Smrg XI18NObjectsList objects_list = xi18n_objects_list; 3851ab64890Smrg 3861ab64890Smrg lc_name = lcd->core->name; 3871ab64890Smrg 3881ab64890Smrg if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return (XIM)0; 3891ab64890Smrg 3901ab64890Smrg count = lc_count; 3911ab64890Smrg for (; count-- > 0; objects_list++) { 3921ab64890Smrg if (objects_list->type != XIM_OBJECT || 3931ab64890Smrg strcmp(objects_list->locale_name, lc_name)) continue; 3941ab64890Smrg 3951ab64890Smrg if (!open_object (objects_list, lc_dir)) 3961ab64890Smrg continue; 3971ab64890Smrg 3981ab64890Smrg im_openIM = (dynamicOpenProcp)fetch_symbol(objects_list, objects_list->open); 3991ab64890Smrg if (!im_openIM) continue; 4001ab64890Smrg im = (*im_openIM)(lcd, display, rdb, res_name, res_class); 4011ab64890Smrg if (im != (XIM)NULL) { 4021ab64890Smrg break; 4031ab64890Smrg } 4042f44462dSmrg 4051ab64890Smrg close_object (objects_list); 4061ab64890Smrg } 4071ab64890Smrg return (XIM)im; 4081ab64890Smrg} 4091ab64890Smrg 4101ab64890Smrgtypedef Bool (*dynamicRegisterCBProcp)( 4111ab64890Smrg XLCd, Display *, XrmDatabase, char *, char *, XIDProc, XPointer); 4121ab64890Smrg 4131ab64890Smrgstatic Bool 4141ab64890Smrg_XDynamicRegisterIMInstantiateCallback( 4151ab64890Smrg XLCd lcd, 4161ab64890Smrg Display *display, 4171ab64890Smrg XrmDatabase rdb, 4181ab64890Smrg char *res_name, 4191ab64890Smrg char *res_class, 4201ab64890Smrg XIDProc callback, 4211ab64890Smrg XPointer client_data) 4221ab64890Smrg{ 4231ab64890Smrg char lc_dir[BUFSIZE]; 4241ab64890Smrg char *lc_name; 4251ab64890Smrg dynamicRegisterCBProcp im_registerIM = (dynamicRegisterCBProcp)NULL; 4261ab64890Smrg Bool ret_flag = False; 4271ab64890Smrg int count; 4281ab64890Smrg XI18NObjectsList objects_list = xi18n_objects_list; 4291ab64890Smrg 4301ab64890Smrg lc_name = lcd->core->name; 4311ab64890Smrg 4321ab64890Smrg if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return False; 4331ab64890Smrg 4341ab64890Smrg count = lc_count; 4351ab64890Smrg for (; count-- > 0; objects_list++) { 4361ab64890Smrg if (objects_list->type != XIM_OBJECT || 4371ab64890Smrg strcmp(objects_list->locale_name, lc_name)) continue; 4381ab64890Smrg 4391ab64890Smrg if (!open_object (objects_list, lc_dir)) 4401ab64890Smrg continue; 4411ab64890Smrg im_registerIM = (dynamicRegisterCBProcp)fetch_symbol(objects_list, 4421ab64890Smrg objects_list->im_register); 4431ab64890Smrg if (!im_registerIM) continue; 4441ab64890Smrg ret_flag = (*im_registerIM)(lcd, display, rdb, 4451ab64890Smrg res_name, res_class, 4461ab64890Smrg callback, client_data); 4471ab64890Smrg if (ret_flag) break; 4481ab64890Smrg 4491ab64890Smrg close_object (objects_list); 4501ab64890Smrg } 4511ab64890Smrg return (Bool)ret_flag; 4521ab64890Smrg} 4531ab64890Smrg 4541ab64890Smrgtypedef Bool (*dynamicUnregisterProcp)( 4551ab64890Smrg XLCd, Display *, XrmDatabase, char *, char *, XIDProc, XPointer); 4561ab64890Smrg 4571ab64890Smrgstatic Bool 4581ab64890Smrg_XDynamicUnRegisterIMInstantiateCallback( 4591ab64890Smrg XLCd lcd, 4601ab64890Smrg Display *display, 4611ab64890Smrg XrmDatabase rdb, 4621ab64890Smrg char *res_name, 4631ab64890Smrg char *res_class, 4641ab64890Smrg XIDProc callback, 4651ab64890Smrg XPointer client_data) 4661ab64890Smrg{ 4671ab64890Smrg char lc_dir[BUFSIZE]; 468c555af55Smrg const char *lc_name; 4691ab64890Smrg dynamicUnregisterProcp im_unregisterIM = (dynamicUnregisterProcp)NULL; 4701ab64890Smrg Bool ret_flag = False; 4711ab64890Smrg int count; 4721ab64890Smrg XI18NObjectsList objects_list = xi18n_objects_list; 4731ab64890Smrg 4741ab64890Smrg lc_name = lcd->core->name; 4751ab64890Smrg if (_XlcLocaleDirName(lc_dir, BUFSIZE, lc_name) == NULL) return False; 4761ab64890Smrg 4771ab64890Smrg count = lc_count; 4781ab64890Smrg for (; count-- > 0; objects_list++) { 4791ab64890Smrg if (objects_list->type != XIM_OBJECT || 4801ab64890Smrg strcmp(objects_list->locale_name, lc_name)) continue; 4811ab64890Smrg 4821ab64890Smrg if (!objects_list->refcount) /* Must already be opened */ 4831ab64890Smrg continue; 4841ab64890Smrg 4851ab64890Smrg im_unregisterIM = (dynamicUnregisterProcp)fetch_symbol(objects_list, 4861ab64890Smrg objects_list->im_unregister); 4871ab64890Smrg 4881ab64890Smrg if (!im_unregisterIM) continue; 4891ab64890Smrg ret_flag = (*im_unregisterIM)(lcd, display, rdb, 4901ab64890Smrg res_name, res_class, 4911ab64890Smrg callback, client_data); 4921ab64890Smrg if (ret_flag) { 4931ab64890Smrg close_object (objects_list); /* opened in RegisterIMInstantiateCallback */ 4941ab64890Smrg break; 4951ab64890Smrg } 4961ab64890Smrg } 4971ab64890Smrg return (Bool)ret_flag; 4981ab64890Smrg} 4991ab64890Smrg 5001ab64890SmrgBool 5011ab64890Smrg_XInitDynamicIM(XLCd lcd) 5021ab64890Smrg{ 5031ab64890Smrg if(lcd == (XLCd)NULL) 5041ab64890Smrg return False; 5051ab64890Smrg lcd->methods->open_im = _XDynamicOpenIM; 5061ab64890Smrg lcd->methods->register_callback = _XDynamicRegisterIMInstantiateCallback; 5071ab64890Smrg lcd->methods->unregister_callback = _XDynamicUnRegisterIMInstantiateCallback; 5081ab64890Smrg return True; 5091ab64890Smrg} 5101ab64890Smrg 5111ab64890Smrg 5121ab64890Smrgtypedef XOM (*dynamicIOpenProcp)( 5131ab64890Smrg XLCd, Display *, XrmDatabase, _Xconst char *, _Xconst char *); 5141ab64890Smrg 5151ab64890Smrgstatic XOM 5161ab64890Smrg_XDynamicOpenOM(XLCd lcd, Display *display, XrmDatabase rdb, 5171ab64890Smrg _Xconst char *res_name, _Xconst char *res_class) 5181ab64890Smrg{ 5191ab64890Smrg XOM om = (XOM)NULL; 5201ab64890Smrg int count; 5211ab64890Smrg char lc_dir[BUFSIZE]; 5221ab64890Smrg char *lc_name; 5231ab64890Smrg dynamicIOpenProcp om_openOM = (dynamicIOpenProcp)NULL; 5241ab64890Smrg XI18NObjectsList objects_list = xi18n_objects_list; 5251ab64890Smrg 5261ab64890Smrg lc_name = lcd->core->name; 5271ab64890Smrg 5281ab64890Smrg if (_XlcLocaleLibDirName(lc_dir, BUFSIZE, lc_name) == NULL) return (XOM)0; 5291ab64890Smrg 5301ab64890Smrg count = lc_count; 5311ab64890Smrg for (; count-- > 0; objects_list++) { 5321ab64890Smrg if (objects_list->type != XOM_OBJECT || 5331ab64890Smrg strcmp(objects_list->locale_name, lc_name)) continue; 5341ab64890Smrg if (!open_object (objects_list, lc_dir)) 5351ab64890Smrg continue; 5362f44462dSmrg 5371ab64890Smrg om_openOM = (dynamicIOpenProcp)fetch_symbol(objects_list, objects_list->open); 5381ab64890Smrg if (!om_openOM) continue; 5391ab64890Smrg om = (*om_openOM)(lcd, display, rdb, res_name, res_class); 5401ab64890Smrg if (om != (XOM)NULL) { 5411ab64890Smrg break; 5421ab64890Smrg } 5431ab64890Smrg close_object(objects_list); 5441ab64890Smrg } 5451ab64890Smrg return (XOM)om; 5461ab64890Smrg} 5471ab64890Smrg 5481ab64890SmrgBool 5491ab64890Smrg_XInitDynamicOM(XLCd lcd) 5501ab64890Smrg{ 5511ab64890Smrg if(lcd == (XLCd)NULL) 5521ab64890Smrg return False; 5531ab64890Smrg 5541ab64890Smrg lcd->methods->open_om = _XDynamicOpenOM; 5551ab64890Smrg 5561ab64890Smrg return True; 5571ab64890Smrg} 558