1 2/* 3 * Copyright 1990, 1991 by OMRON Corporation, NTT Software Corporation, 4 * and Nippon Telegraph and Telephone Corporation 5 * 6 * Permission to use, copy, modify, distribute, and sell this software and its 7 * documentation for any purpose is hereby granted without fee, provided that 8 * the above copyright notice appear in all copies and that both that 9 * copyright notice and this permission notice appear in supporting 10 * documentation, and that the names of OMRON, NTT Software, and NTT 11 * not be used in advertising or publicity pertaining to distribution of the 12 * software without specific, written prior permission. OMRON, NTT Software, 13 * and NTT make no representations about the suitability of this 14 * software for any purpose. It is provided "as is" without express or 15 * implied warranty. 16 * 17 * OMRON, NTT SOFTWARE, AND NTT, DISCLAIM ALL WARRANTIES WITH REGARD 18 * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 19 * AND FITNESS, IN NO EVENT SHALL OMRON, NTT SOFTWARE, OR NTT, BE 20 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 21 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 22 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 23 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 24 * 25 * Authors: Li Yuhong OMRON Corporation 26 * Tetsuya Kato NTT Software Corporation 27 * Hiroshi Kuribayashi OMRON Corporation 28 * 29 */ 30/* 31 32Copyright 1987,1998 The Open Group 33 34Permission to use, copy, modify, distribute, and sell this software and its 35documentation for any purpose is hereby granted without fee, provided that 36the above copyright notice appear in all copies and that both that 37copyright notice and this permission notice appear in supporting 38documentation. 39 40The above copyright notice and this permission notice shall be included 41in all copies or substantial portions of the Software. 42 43THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 44OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 45MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 46IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 47OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 48ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 49OTHER DEALINGS IN THE SOFTWARE. 50 51Except as contained in this notice, the name of The Open Group shall 52not be used in advertising or otherwise to promote the sale, use or 53other dealings in this Software without prior written authorization 54from The Open Group. 55 56*/ 57 58#ifdef HAVE_CONFIG_H 59#include <config.h> 60#endif 61#include "Xlibint.h" 62#include "Xlcint.h" 63#include <X11/Xlocale.h> 64#include <X11/Xos.h> 65#include "XlcPubI.h" 66 67#define MAXLOCALE 64 /* buffer size of locale name */ 68 69 70#if defined(__APPLE__) || defined(__CYGWIN__) 71char * 72_Xsetlocale( 73 int category, 74 _Xconst char *name 75) 76{ 77 return setlocale(category, name); 78} 79#endif /* __APPLE__ || __CYGWIN__ */ 80 81/* 82 * _XlcMapOSLocaleName is an implementation dependent routine that derives 83 * the LC_CTYPE locale name as used in the sample implementation from that 84 * returned by setlocale. 85 * 86 * Should match the code in Xt ExtractLocaleName. 87 * 88 * This function name is a bit of a misnomer. Even the siname parameter 89 * name is a misnomer. On most modern operating systems this function is 90 * a no-op, simply returning the osname; but on older operating systems 91 * like Ultrix, or HPUX 9.x and earlier, when you set LANG=german.88591 92 * then the string returned by setlocale(LC_ALL, "") will look something 93 * like: "german.88591 german.88591 ... german.88591". Then this function 94 * will pick out the LC_CTYPE component and return a pointer to that. 95 */ 96 97char * 98_XlcMapOSLocaleName( 99 char *osname, 100 char *siname) 101{ 102#if defined(CSRG_BASED) || defined(sun) || defined(SVR4) || defined(WIN32) || defined(linux) 103# if defined(WIN32) 104# define SKIPCOUNT 1 105# define STARTCHAR '=' 106# define ENDCHAR ';' 107# define WHITEFILL 108# else 109# if defined(linux) 110# define STARTSTR "LC_CTYPE=" 111# define ENDCHAR ';' 112# else 113# if !defined(sun) || defined(SVR4) 114# define STARTCHAR '/' 115# define ENDCHAR '/' 116# endif 117# endif 118# endif 119 120 char *start; 121 char *end; 122 int len; 123# ifdef SKIPCOUNT 124 int n; 125# endif 126 127 start = osname; 128# ifdef SKIPCOUNT 129 for (n = SKIPCOUNT; 130 --n >= 0 && start && (start = strchr (start, STARTCHAR)); 131 start++) 132 ; 133 if (!start) 134 start = osname; 135# endif 136# ifdef STARTCHAR 137 if (start && (start = strchr (start, STARTCHAR))) 138# elif defined (STARTSTR) 139 if (start && (start = strstr (start,STARTSTR))) 140# endif 141 { 142# ifdef STARTCHAR 143 start++; 144# elif defined (STARTSTR) 145 start += strlen(STARTSTR); 146# endif 147 if ((end = strchr (start, ENDCHAR))) { 148 len = end - start; 149 if (len >= MAXLOCALE) 150 len = MAXLOCALE - 1; 151 strncpy(siname, start, (size_t) len); 152 *(siname + len) = '\0'; 153# ifdef WHITEFILL 154 for (start = siname; start = strchr(start, ' '); ) 155 *start++ = '-'; 156# endif 157 return siname; 158 } else /* if no ENDCHAR is found we are at the end of the line */ 159 return start; 160 } 161# ifdef WHITEFILL 162 if (strchr(osname, ' ')) { 163 len = strlen(osname); 164 if (len >= MAXLOCALE - 1) 165 len = MAXLOCALE - 1; 166 strncpy(siname, osname, len); 167 *(siname + len) = '\0'; 168 for (start = siname; start = strchr(start, ' '); ) 169 *start++ = '-'; 170 return siname; 171 } 172# endif 173# undef STARTCHAR 174# undef ENDCHAR 175# undef WHITEFILL 176#endif 177 return osname; 178} 179 180