11ab64890Smrg 21ab64890Smrg/* 31ab64890Smrg * Copyright 1990, 1991 by OMRON Corporation, NTT Software Corporation, 41ab64890Smrg * and Nippon Telegraph and Telephone Corporation 51ab64890Smrg * 61ab64890Smrg * Permission to use, copy, modify, distribute, and sell this software and its 71ab64890Smrg * documentation for any purpose is hereby granted without fee, provided that 81ab64890Smrg * the above copyright notice appear in all copies and that both that 91ab64890Smrg * copyright notice and this permission notice appear in supporting 101ab64890Smrg * documentation, and that the names of OMRON, NTT Software, and NTT 111ab64890Smrg * not be used in advertising or publicity pertaining to distribution of the 121ab64890Smrg * software without specific, written prior permission. OMRON, NTT Software, 131ab64890Smrg * and NTT make no representations about the suitability of this 141ab64890Smrg * software for any purpose. It is provided "as is" without express or 151ab64890Smrg * implied warranty. 161ab64890Smrg * 171ab64890Smrg * OMRON, NTT SOFTWARE, AND NTT, DISCLAIM ALL WARRANTIES WITH REGARD 181ab64890Smrg * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 191ab64890Smrg * AND FITNESS, IN NO EVENT SHALL OMRON, NTT SOFTWARE, OR NTT, BE 2061b2299dSmrg * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 211ab64890Smrg * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 221ab64890Smrg * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 231ab64890Smrg * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 241ab64890Smrg * 251ab64890Smrg * Authors: Li Yuhong OMRON Corporation 261ab64890Smrg * Tetsuya Kato NTT Software Corporation 271ab64890Smrg * Hiroshi Kuribayashi OMRON Corporation 2861b2299dSmrg * 291ab64890Smrg */ 301ab64890Smrg/* 311ab64890Smrg 321ab64890SmrgCopyright 1987,1998 The Open Group 331ab64890Smrg 341ab64890SmrgPermission to use, copy, modify, distribute, and sell this software and its 351ab64890Smrgdocumentation for any purpose is hereby granted without fee, provided that 361ab64890Smrgthe above copyright notice appear in all copies and that both that 371ab64890Smrgcopyright notice and this permission notice appear in supporting 381ab64890Smrgdocumentation. 391ab64890Smrg 401ab64890SmrgThe above copyright notice and this permission notice shall be included 411ab64890Smrgin all copies or substantial portions of the Software. 421ab64890Smrg 431ab64890SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 441ab64890SmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 451ab64890SmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 461ab64890SmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 471ab64890SmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 481ab64890SmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 491ab64890SmrgOTHER DEALINGS IN THE SOFTWARE. 501ab64890Smrg 511ab64890SmrgExcept as contained in this notice, the name of The Open Group shall 521ab64890Smrgnot be used in advertising or otherwise to promote the sale, use or 531ab64890Smrgother dealings in this Software without prior written authorization 541ab64890Smrgfrom The Open Group. 551ab64890Smrg 561ab64890Smrg*/ 571ab64890Smrg 581ab64890Smrg#ifdef HAVE_CONFIG_H 591ab64890Smrg#include <config.h> 601ab64890Smrg#endif 611ab64890Smrg#include "Xlibint.h" 621ab64890Smrg#include "Xlcint.h" 631ab64890Smrg#include <X11/Xlocale.h> 641ab64890Smrg#include <X11/Xos.h> 651ab64890Smrg#include "XlcPubI.h" 661ab64890Smrg 671ab64890Smrg#define MAXLOCALE 64 /* buffer size of locale name */ 681ab64890Smrg 691ab64890Smrg 70b4ee4795Smrg#if defined(__APPLE__) || defined(__CYGWIN__) 711ab64890Smrgchar * 721ab64890Smrg_Xsetlocale( 731ab64890Smrg int category, 741ab64890Smrg _Xconst char *name 751ab64890Smrg) 761ab64890Smrg{ 771ab64890Smrg return setlocale(category, name); 781ab64890Smrg} 79b4ee4795Smrg#endif /* __APPLE__ || __CYGWIN__ */ 801ab64890Smrg 811ab64890Smrg/* 821ab64890Smrg * _XlcMapOSLocaleName is an implementation dependent routine that derives 831ab64890Smrg * the LC_CTYPE locale name as used in the sample implementation from that 841ab64890Smrg * returned by setlocale. 851ab64890Smrg * 861ab64890Smrg * Should match the code in Xt ExtractLocaleName. 8761b2299dSmrg * 881ab64890Smrg * This function name is a bit of a misnomer. Even the siname parameter 8961b2299dSmrg * name is a misnomer. On most modern operating systems this function is 9061b2299dSmrg * a no-op, simply returning the osname; but on older operating systems 9161b2299dSmrg * like Ultrix, or HPUX 9.x and earlier, when you set LANG=german.88591 9261b2299dSmrg * then the string returned by setlocale(LC_ALL, "") will look something 931ab64890Smrg * like: "german.88591 german.88591 ... german.88591". Then this function 941ab64890Smrg * will pick out the LC_CTYPE component and return a pointer to that. 951ab64890Smrg */ 961ab64890Smrg 971ab64890Smrgchar * 981ab64890Smrg_XlcMapOSLocaleName( 991ab64890Smrg char *osname, 1001ab64890Smrg char *siname) 1011ab64890Smrg{ 102ebe525bcSmrg#if defined(CSRG_BASED) || defined(sun) || defined(SVR4) || defined(WIN32) || defined(linux) 103ebe525bcSmrg# if defined(WIN32) 104ebe525bcSmrg# define SKIPCOUNT 1 105ebe525bcSmrg# define STARTCHAR '=' 106ebe525bcSmrg# define ENDCHAR ';' 107ebe525bcSmrg# define WHITEFILL 1081ab64890Smrg# else 109ebe525bcSmrg# if defined(linux) 110ebe525bcSmrg# define STARTSTR "LC_CTYPE=" 111ebe525bcSmrg# define ENDCHAR ';' 1121ab64890Smrg# else 113ebe525bcSmrg# if !defined(sun) || defined(SVR4) 114ebe525bcSmrg# define STARTCHAR '/' 115ebe525bcSmrg# define ENDCHAR '/' 1161ab64890Smrg# endif 1171ab64890Smrg# endif 1181ab64890Smrg# endif 1191ab64890Smrg 1201ab64890Smrg char *start; 1211ab64890Smrg char *end; 1221ab64890Smrg int len; 1231ab64890Smrg# ifdef SKIPCOUNT 1241ab64890Smrg int n; 1251ab64890Smrg# endif 1261ab64890Smrg 1271ab64890Smrg start = osname; 1281ab64890Smrg# ifdef SKIPCOUNT 1291ab64890Smrg for (n = SKIPCOUNT; 1301ab64890Smrg --n >= 0 && start && (start = strchr (start, STARTCHAR)); 1311ab64890Smrg start++) 1321ab64890Smrg ; 1331ab64890Smrg if (!start) 1341ab64890Smrg start = osname; 1351ab64890Smrg# endif 1361ab64890Smrg# ifdef STARTCHAR 13761b2299dSmrg if (start && (start = strchr (start, STARTCHAR))) 1381ab64890Smrg# elif defined (STARTSTR) 1391ab64890Smrg if (start && (start = strstr (start,STARTSTR))) 1401ab64890Smrg# endif 1411ab64890Smrg { 1421ab64890Smrg# ifdef STARTCHAR 1431ab64890Smrg start++; 1441ab64890Smrg# elif defined (STARTSTR) 1451ab64890Smrg start += strlen(STARTSTR); 1461ab64890Smrg# endif 1471ab64890Smrg if ((end = strchr (start, ENDCHAR))) { 1481ab64890Smrg len = end - start; 1491ab64890Smrg if (len >= MAXLOCALE) 1501ab64890Smrg len = MAXLOCALE - 1; 1519c019ec5Smaya strncpy(siname, start, (size_t) len); 1521ab64890Smrg *(siname + len) = '\0'; 1531ab64890Smrg# ifdef WHITEFILL 1541ab64890Smrg for (start = siname; start = strchr(start, ' '); ) 1551ab64890Smrg *start++ = '-'; 1561ab64890Smrg# endif 1571ab64890Smrg return siname; 1581ab64890Smrg } else /* if no ENDCHAR is found we are at the end of the line */ 1591ab64890Smrg return start; 1601ab64890Smrg } 1611ab64890Smrg# ifdef WHITEFILL 1621ab64890Smrg if (strchr(osname, ' ')) { 1631ab64890Smrg len = strlen(osname); 1641ab64890Smrg if (len >= MAXLOCALE - 1) 1651ab64890Smrg len = MAXLOCALE - 1; 1661ab64890Smrg strncpy(siname, osname, len); 1671ab64890Smrg *(siname + len) = '\0'; 1681ab64890Smrg for (start = siname; start = strchr(start, ' '); ) 1691ab64890Smrg *start++ = '-'; 1701ab64890Smrg return siname; 1711ab64890Smrg } 1721ab64890Smrg# endif 1731ab64890Smrg# undef STARTCHAR 1741ab64890Smrg# undef ENDCHAR 1751ab64890Smrg# undef WHITEFILL 1761ab64890Smrg#endif 1771ab64890Smrg return osname; 1781ab64890Smrg} 1791ab64890Smrg 180