| 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 |
|
| 32 |
Copyright 1987,1998 The Open Group |
| 33 |
|
| 34 |
Permission to use, copy, modify, distribute, and sell this software and its |
| 35 |
documentation for any purpose is hereby granted without fee, provided that |
| 36 |
the above copyright notice appear in all copies and that both that |
| 37 |
copyright notice and this permission notice appear in supporting |
| 38 |
documentation. |
| 39 |
|
| 40 |
The above copyright notice and this permission notice shall be included |
| 41 |
in all copies or substantial portions of the Software. |
| 42 |
|
| 43 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 44 |
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 45 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 46 |
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 47 |
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 48 |
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 49 |
OTHER DEALINGS IN THE SOFTWARE. |
| 50 |
|
| 51 |
Except as contained in this notice, the name of The Open Group shall |
| 52 |
not be used in advertising or otherwise to promote the sale, use or |
| 53 |
other dealings in this Software without prior written authorization |
| 54 |
from 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 <nx-X11/Xlocale.h> |
| 64 |
#include <nx-X11/Xos.h> |
| 65 |
#include "XlcPubI.h" |
| 66 |
|
| 67 |
#define MAXLOCALE 64 /* buffer size of locale name */ |
| 68 |
|
| 69 |
|
| 70 |
#if defined(__DARWIN__) || defined(__APPLE__) || defined(__CYGWIN__) |
| 71 |
char * |
| 72 |
_Xsetlocale( |
| 73 |
int category, |
| 74 |
_Xconst char *name |
| 75 |
) |
| 76 |
{ |
| 77 |
return setlocale(category, name); |
| 78 |
} |
| 79 |
#endif /* __DARWIN__ || __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 |
|
| 97 |
char * |
| 98 |
_XlcMapOSLocaleName( |
| 99 |
char *osname, |
| 100 |
char *siname) |
| 101 |
{ |
| 102 |
|
| 103 |
/* FIXME: correct indentation levels after ancient platform clean-up */ |
| 104 |
|
| 105 |
#if defined(CSRG_BASED) || defined(sun) || defined(SVR4) || defined(ultrix) || defined(WIN32) || defined(linux) |
| 106 |
# ifdef ultrix |
| 107 |
# define SKIPCOUNT 2 |
| 108 |
# define STARTCHAR '\001' |
| 109 |
# define ENDCHAR '\001' |
| 110 |
# else |
| 111 |
# if defined(WIN32) |
| 112 |
# define SKIPCOUNT 1 |
| 113 |
# define STARTCHAR '=' |
| 114 |
# define ENDCHAR ';' |
| 115 |
# define WHITEFILL |
| 116 |
# else |
| 117 |
# if defined(linux) |
| 118 |
# define STARTSTR "LC_CTYPE=" |
| 119 |
# define ENDCHAR ';' |
| 120 |
# else |
| 121 |
# if !defined(sun) || defined(SVR4) |
| 122 |
# define STARTCHAR '/' |
| 123 |
# define ENDCHAR '/' |
| 124 |
# endif |
| 125 |
# endif |
| 126 |
# endif |
| 127 |
# endif |
| 128 |
|
| 129 |
char *start; |
| 130 |
char *end; |
| 131 |
int len; |
| 132 |
# ifdef SKIPCOUNT |
| 133 |
int n; |
| 134 |
# endif |
| 135 |
|
| 136 |
start = osname; |
| 137 |
# ifdef SKIPCOUNT |
| 138 |
for (n = SKIPCOUNT; |
| 139 |
--n >= 0 && start && (start = strchr (start, STARTCHAR)); |
| 140 |
start++) |
| 141 |
; |
| 142 |
if (!start) |
| 143 |
start = osname; |
| 144 |
# endif |
| 145 |
# ifdef STARTCHAR |
| 146 |
if (start && (start = strchr (start, STARTCHAR))) |
| 147 |
# elif defined (STARTSTR) |
| 148 |
if (start && (start = strstr (start,STARTSTR))) |
| 149 |
# endif |
| 150 |
{ |
| 151 |
# ifdef STARTCHAR |
| 152 |
start++; |
| 153 |
# elif defined (STARTSTR) |
| 154 |
start += strlen(STARTSTR); |
| 155 |
# endif |
| 156 |
if ((end = strchr (start, ENDCHAR))) { |
| 157 |
len = end - start; |
| 158 |
if (len >= MAXLOCALE) |
| 159 |
len = MAXLOCALE - 1; |
| 160 |
strncpy(siname, start, (size_t) len); |
| 161 |
*(siname + len) = '\0'; |
| 162 |
# ifdef WHITEFILL |
| 163 |
for (start = siname; start = strchr(start, ' '); ) |
| 164 |
*start++ = '-'; |
| 165 |
# endif |
| 166 |
return siname; |
| 167 |
} else /* if no ENDCHAR is found we are at the end of the line */ |
| 168 |
return start; |
| 169 |
} |
| 170 |
# ifdef WHITEFILL |
| 171 |
if (strchr(osname, ' ')) { |
| 172 |
len = strlen(osname); |
| 173 |
if (len >= MAXLOCALE - 1) |
| 174 |
len = MAXLOCALE - 1; |
| 175 |
strncpy(siname, osname, len); |
| 176 |
*(siname + len) = '\0'; |
| 177 |
for (start = siname; start = strchr(start, ' '); ) |
| 178 |
*start++ = '-'; |
| 179 |
return siname; |
| 180 |
} |
| 181 |
# endif |
| 182 |
# undef STARTCHAR |
| 183 |
# undef ENDCHAR |
| 184 |
# undef WHITEFILL |
| 185 |
#endif |
| 186 |
return osname; |
| 187 |
} |
| 188 |
|