cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % L OOO CCCC AAA L EEEEE % |
| 7 | % L O O C A A L E % |
| 8 | % L O O C AAAAA L EEE % |
| 9 | % L O O C A A L E % |
| 10 | % LLLLL OOO CCCC A A LLLLL EEEEE % |
| 11 | % % |
| 12 | % % |
| 13 | % MagickCore Image Locale Methods % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % July 2003 % |
| 18 | % % |
| 19 | % % |
cristy | 7e41fe8 | 2010-12-04 23:12:08 +0000 | [diff] [blame] | 20 | % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
| 26 | % http://www.imagemagick.org/script/license.php % |
| 27 | % % |
| 28 | % Unless required by applicable law or agreed to in writing, software % |
| 29 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 30 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 31 | % See the License for the specific language governing permissions and % |
| 32 | % limitations under the License. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | */ |
| 38 | |
| 39 | /* |
| 40 | Include declarations. |
| 41 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 42 | #include "MagickCore/studio.h" |
| 43 | #include "MagickCore/blob.h" |
| 44 | #include "MagickCore/client.h" |
| 45 | #include "MagickCore/configure.h" |
| 46 | #include "MagickCore/exception.h" |
| 47 | #include "MagickCore/exception-private.h" |
| 48 | #include "MagickCore/hashmap.h" |
| 49 | #include "MagickCore/locale_.h" |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 50 | #include "MagickCore/locale-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 51 | #include "MagickCore/log.h" |
| 52 | #include "MagickCore/memory_.h" |
| 53 | #include "MagickCore/semaphore.h" |
| 54 | #include "MagickCore/splay-tree.h" |
| 55 | #include "MagickCore/string_.h" |
cristy | 7832dc2 | 2011-09-05 01:21:53 +0000 | [diff] [blame] | 56 | #include "MagickCore/string-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 57 | #include "MagickCore/token.h" |
| 58 | #include "MagickCore/utility.h" |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 59 | #include "MagickCore/utility-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 60 | #include "MagickCore/xml-tree.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 61 | |
| 62 | /* |
| 63 | Define declarations. |
| 64 | */ |
| 65 | #define LocaleFilename "locale.xml" |
| 66 | #define MaxRecursionDepth 200 |
| 67 | |
| 68 | /* |
cristy | caa2ce5 | 2011-05-20 23:59:13 +0000 | [diff] [blame] | 69 | Typedef declarations. |
| 70 | */ |
| 71 | #if defined(__CYGWIN__) |
| 72 | typedef struct _locale_t *locale_t; |
| 73 | #endif |
| 74 | |
| 75 | /* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 76 | Static declarations. |
| 77 | */ |
| 78 | static const char |
| 79 | *LocaleMap = |
| 80 | "<?xml version=\"1.0\"?>" |
| 81 | "<localemap>" |
| 82 | " <locale name=\"C\">" |
| 83 | " <Exception>" |
| 84 | " <Message name=\"\">" |
| 85 | " </Message>" |
| 86 | " </Exception>" |
| 87 | " </locale>" |
| 88 | "</localemap>"; |
| 89 | |
| 90 | static SemaphoreInfo |
| 91 | *locale_semaphore = (SemaphoreInfo *) NULL; |
| 92 | |
| 93 | static SplayTreeInfo |
| 94 | *locale_list = (SplayTreeInfo *) NULL; |
| 95 | |
cristy | a723b6a | 2011-05-25 12:08:51 +0000 | [diff] [blame] | 96 | #if defined(MAGICKCORE_HAVE_STRTOD_L) |
cristy | a20c904 | 2011-05-19 13:22:18 +0000 | [diff] [blame] | 97 | static volatile locale_t |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 98 | c_locale = (locale_t) NULL; |
cristy | a723b6a | 2011-05-25 12:08:51 +0000 | [diff] [blame] | 99 | #endif |
cristy | 022ce73 | 2011-05-19 23:34:51 +0000 | [diff] [blame] | 100 | |
| 101 | static volatile MagickBooleanType |
| 102 | instantiate_locale = MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 103 | |
| 104 | /* |
| 105 | Forward declarations. |
| 106 | */ |
| 107 | static MagickBooleanType |
| 108 | InitializeLocaleList(ExceptionInfo *), |
| 109 | LoadLocaleLists(const char *,const char *,ExceptionInfo *); |
| 110 | |
cristy | a723b6a | 2011-05-25 12:08:51 +0000 | [diff] [blame] | 111 | #if defined(MAGICKCORE_HAVE_STRTOD_L) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 112 | /* |
| 113 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 114 | % % |
| 115 | % % |
| 116 | % % |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 117 | + A c q u i r e C L o c a l e % |
cristy | a20c904 | 2011-05-19 13:22:18 +0000 | [diff] [blame] | 118 | % % |
| 119 | % % |
| 120 | % % |
| 121 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 122 | % |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 123 | % AcquireCLocale() allocates the C locale object, or (locale_t) 0 with |
cristy | a20c904 | 2011-05-19 13:22:18 +0000 | [diff] [blame] | 124 | % errno set if it cannot be acquired. |
| 125 | % |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 126 | % The format of the AcquireCLocale method is: |
cristy | a20c904 | 2011-05-19 13:22:18 +0000 | [diff] [blame] | 127 | % |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 128 | % locale_t AcquireCLocale(void) |
cristy | a20c904 | 2011-05-19 13:22:18 +0000 | [diff] [blame] | 129 | % |
| 130 | */ |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 131 | static locale_t AcquireCLocale(void) |
cristy | a20c904 | 2011-05-19 13:22:18 +0000 | [diff] [blame] | 132 | { |
| 133 | #if defined(MAGICKCORE_HAVE_NEWLOCALE) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 134 | if (c_locale == (locale_t) NULL) |
| 135 | c_locale=newlocale(LC_ALL_MASK,"C",(locale_t) 0); |
cristy | a20c904 | 2011-05-19 13:22:18 +0000 | [diff] [blame] | 136 | #elif defined(MAGICKCORE_WINDOWS_SUPPORT) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 137 | if (c_locale == (locale_t) NULL) |
| 138 | c_locale=_create_locale(LC_ALL,"C"); |
cristy | a20c904 | 2011-05-19 13:22:18 +0000 | [diff] [blame] | 139 | #endif |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 140 | return(c_locale); |
| 141 | } |
cristy | a723b6a | 2011-05-25 12:08:51 +0000 | [diff] [blame] | 142 | #endif |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 143 | |
cristy | a723b6a | 2011-05-25 12:08:51 +0000 | [diff] [blame] | 144 | #if defined(MAGICKCORE_HAVE_STRTOD_L) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 145 | /* |
| 146 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 147 | % % |
| 148 | % % |
| 149 | % % |
| 150 | + D e s t r o y C L o c a l e % |
| 151 | % % |
| 152 | % % |
| 153 | % % |
| 154 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 155 | % |
| 156 | % DestroyCLocale() releases the resources allocated for a locale object |
| 157 | % returned by a call to the AcquireCLocale() method. |
| 158 | % |
| 159 | % The format of the DestroyCLocale method is: |
| 160 | % |
| 161 | % void DestroyCLocale(void) |
| 162 | % |
| 163 | */ |
| 164 | static void DestroyCLocale(void) |
| 165 | { |
| 166 | #if defined(MAGICKCORE_HAVE_NEWLOCALE) |
| 167 | if (c_locale != (locale_t) NULL) |
| 168 | freelocale(c_locale); |
| 169 | #elif defined(MAGICKCORE_WINDOWS_SUPPORT) |
| 170 | if (c_locale != (locale_t) NULL) |
| 171 | _free_locale(c_locale); |
| 172 | #endif |
| 173 | c_locale=(locale_t) NULL; |
cristy | a20c904 | 2011-05-19 13:22:18 +0000 | [diff] [blame] | 174 | } |
cristy | a723b6a | 2011-05-25 12:08:51 +0000 | [diff] [blame] | 175 | #endif |
cristy | a20c904 | 2011-05-19 13:22:18 +0000 | [diff] [blame] | 176 | |
| 177 | /* |
| 178 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 179 | % % |
| 180 | % % |
| 181 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 182 | % D e s t r o y L o c a l e O p t i o n s % |
| 183 | % % |
| 184 | % % |
| 185 | % % |
| 186 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 187 | % |
| 188 | % DestroyLocaleOptions() releases memory associated with an locale |
| 189 | % messages. |
| 190 | % |
| 191 | % The format of the DestroyProfiles method is: |
| 192 | % |
| 193 | % LinkedListInfo *DestroyLocaleOptions(Image *image) |
| 194 | % |
| 195 | % A description of each parameter follows: |
| 196 | % |
| 197 | % o image: the image. |
| 198 | % |
| 199 | */ |
| 200 | |
| 201 | static void *DestroyOptions(void *message) |
| 202 | { |
| 203 | return(DestroyStringInfo((StringInfo *) message)); |
| 204 | } |
| 205 | |
| 206 | MagickExport LinkedListInfo *DestroyLocaleOptions(LinkedListInfo *messages) |
| 207 | { |
| 208 | assert(messages != (LinkedListInfo *) NULL); |
| 209 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 210 | return(DestroyLinkedList(messages,DestroyOptions)); |
| 211 | } |
| 212 | |
| 213 | /* |
| 214 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 215 | % % |
| 216 | % % |
| 217 | % % |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 218 | + F o r m a t L o c a l e F i l e % |
cristy | a20c904 | 2011-05-19 13:22:18 +0000 | [diff] [blame] | 219 | % % |
| 220 | % % |
| 221 | % % |
| 222 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 223 | % |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 224 | % FormatLocaleFile() prints formatted output of a variable argument list to a |
| 225 | % file in the "C" locale. |
cristy | a20c904 | 2011-05-19 13:22:18 +0000 | [diff] [blame] | 226 | % |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 227 | % The format of the FormatLocaleFile method is: |
cristy | a20c904 | 2011-05-19 13:22:18 +0000 | [diff] [blame] | 228 | % |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 229 | % ssize_t FormatLocaleFile(FILE *file,const char *format,...) |
| 230 | % |
| 231 | % A description of each parameter follows. |
| 232 | % |
| 233 | % o file: the file. |
| 234 | % |
| 235 | % o format: A file describing the format to use to write the remaining |
| 236 | % arguments. |
cristy | a20c904 | 2011-05-19 13:22:18 +0000 | [diff] [blame] | 237 | % |
| 238 | */ |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 239 | |
cristy | 7832dc2 | 2011-09-05 01:21:53 +0000 | [diff] [blame] | 240 | MagickPrivate ssize_t FormatLocaleFileList(FILE *file, |
cristy | ba56db5 | 2011-05-20 02:08:11 +0000 | [diff] [blame] | 241 | const char *restrict format,va_list operands) |
cristy | a20c904 | 2011-05-19 13:22:18 +0000 | [diff] [blame] | 242 | { |
cristy | 20ec759 | 2011-05-29 01:28:05 +0000 | [diff] [blame] | 243 | ssize_t |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 244 | n; |
| 245 | |
cristy | 5d0cd95 | 2011-05-19 21:21:41 +0000 | [diff] [blame] | 246 | #if defined(MAGICKCORE_HAVE_VFPRINTF_L) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 247 | { |
| 248 | locale_t |
| 249 | locale; |
| 250 | |
| 251 | locale=AcquireCLocale(); |
| 252 | if (locale == (locale_t) NULL) |
cristy | 20ec759 | 2011-05-29 01:28:05 +0000 | [diff] [blame] | 253 | n=(ssize_t) vfprintf(file,format,operands); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 254 | else |
cristy | 26d7820 | 2011-05-21 00:59:34 +0000 | [diff] [blame] | 255 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) |
cristy | 20ec759 | 2011-05-29 01:28:05 +0000 | [diff] [blame] | 256 | n=(ssize_t) vfprintf_l(file,format,locale,operands); |
cristy | 26d7820 | 2011-05-21 00:59:34 +0000 | [diff] [blame] | 257 | #else |
cristy | 20ec759 | 2011-05-29 01:28:05 +0000 | [diff] [blame] | 258 | n=(ssize_t) vfprintf_l(file,locale,format,operands); |
cristy | 405905f | 2011-05-21 00:37:33 +0000 | [diff] [blame] | 259 | #endif |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 260 | } |
| 261 | #else |
| 262 | #if defined(MAGICKCORE_HAVE_USELOCALE) |
| 263 | { |
| 264 | locale_t |
| 265 | locale, |
| 266 | previous_locale; |
| 267 | |
| 268 | locale=AcquireCLocale(); |
| 269 | if (locale == (locale_t) NULL) |
cristy | 20ec759 | 2011-05-29 01:28:05 +0000 | [diff] [blame] | 270 | n=(ssize_t) vfprintf(file,format,operands); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 271 | else |
| 272 | { |
| 273 | previous_locale=uselocale(locale); |
cristy | 20ec759 | 2011-05-29 01:28:05 +0000 | [diff] [blame] | 274 | n=(ssize_t) vfprintf(file,format,operands); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 275 | uselocale(previous_locale); |
| 276 | } |
| 277 | } |
| 278 | #else |
cristy | 20ec759 | 2011-05-29 01:28:05 +0000 | [diff] [blame] | 279 | n=(ssize_t) vfprintf(file,format,operands); |
cristy | a20c904 | 2011-05-19 13:22:18 +0000 | [diff] [blame] | 280 | #endif |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 281 | #endif |
cristy | 3da0b40 | 2011-05-29 21:13:36 +0000 | [diff] [blame] | 282 | return(n); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 283 | } |
| 284 | |
cristy | ba56db5 | 2011-05-20 02:08:11 +0000 | [diff] [blame] | 285 | MagickExport ssize_t FormatLocaleFile(FILE *file,const char *restrict format, |
| 286 | ...) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 287 | { |
| 288 | ssize_t |
| 289 | n; |
| 290 | |
| 291 | va_list |
| 292 | operands; |
| 293 | |
| 294 | va_start(operands,format); |
cristy | 20ec759 | 2011-05-29 01:28:05 +0000 | [diff] [blame] | 295 | n=FormatLocaleFileList(file,format,operands); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 296 | va_end(operands); |
| 297 | return(n); |
| 298 | } |
| 299 | |
| 300 | /* |
| 301 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 302 | % % |
| 303 | % % |
| 304 | % % |
| 305 | + F o r m a t L o c a l e S t r i n g % |
| 306 | % % |
| 307 | % % |
| 308 | % % |
| 309 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 310 | % |
| 311 | % FormatLocaleString() prints formatted output of a variable argument list to |
| 312 | % a string buffer in the "C" locale. |
| 313 | % |
| 314 | % The format of the FormatLocaleString method is: |
| 315 | % |
| 316 | % ssize_t FormatLocaleString(char *string,const size_t length, |
| 317 | % const char *format,...) |
| 318 | % |
| 319 | % A description of each parameter follows. |
| 320 | % |
| 321 | % o string: FormatLocaleString() returns the formatted string in this |
| 322 | % character buffer. |
| 323 | % |
| 324 | % o length: the maximum length of the string. |
| 325 | % |
| 326 | % o format: A string describing the format to use to write the remaining |
| 327 | % arguments. |
| 328 | % |
| 329 | */ |
| 330 | |
cristy | 7832dc2 | 2011-09-05 01:21:53 +0000 | [diff] [blame] | 331 | MagickPrivate ssize_t FormatLocaleStringList(char *restrict string, |
cristy | ba56db5 | 2011-05-20 02:08:11 +0000 | [diff] [blame] | 332 | const size_t length,const char *restrict format,va_list operands) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 333 | { |
cristy | 20ec759 | 2011-05-29 01:28:05 +0000 | [diff] [blame] | 334 | ssize_t |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 335 | n; |
| 336 | |
| 337 | #if defined(MAGICKCORE_HAVE_VSNPRINTF_L) |
cristy | 405905f | 2011-05-21 00:37:33 +0000 | [diff] [blame] | 338 | { |
| 339 | locale_t |
| 340 | locale; |
| 341 | |
| 342 | locale=AcquireCLocale(); |
| 343 | if (locale == (locale_t) NULL) |
cristy | 20ec759 | 2011-05-29 01:28:05 +0000 | [diff] [blame] | 344 | n=(ssize_t) vsnprintf(string,length,format,operands); |
cristy | 405905f | 2011-05-21 00:37:33 +0000 | [diff] [blame] | 345 | else |
cristy | 26d7820 | 2011-05-21 00:59:34 +0000 | [diff] [blame] | 346 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) |
cristy | 20ec759 | 2011-05-29 01:28:05 +0000 | [diff] [blame] | 347 | n=(ssize_t) vsnprintf_l(string,length,format,locale,operands); |
cristy | 26d7820 | 2011-05-21 00:59:34 +0000 | [diff] [blame] | 348 | #else |
cristy | 20ec759 | 2011-05-29 01:28:05 +0000 | [diff] [blame] | 349 | n=(ssize_t) vsnprintf_l(string,length,locale,format,operands); |
cristy | 405905f | 2011-05-21 00:37:33 +0000 | [diff] [blame] | 350 | #endif |
| 351 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 352 | #elif defined(MAGICKCORE_HAVE_VSNPRINTF) |
| 353 | #if defined(MAGICKCORE_HAVE_USELOCALE) |
| 354 | { |
| 355 | locale_t |
| 356 | locale, |
| 357 | previous_locale; |
| 358 | |
| 359 | locale=AcquireCLocale(); |
| 360 | if (locale == (locale_t) NULL) |
cristy | 20ec759 | 2011-05-29 01:28:05 +0000 | [diff] [blame] | 361 | n=(ssize_t) vsnprintf(string,length,format,operands); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 362 | else |
| 363 | { |
| 364 | previous_locale=uselocale(locale); |
cristy | 20ec759 | 2011-05-29 01:28:05 +0000 | [diff] [blame] | 365 | n=(ssize_t) vsnprintf(string,length,format,operands); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 366 | uselocale(previous_locale); |
| 367 | } |
| 368 | } |
| 369 | #else |
cristy | 20ec759 | 2011-05-29 01:28:05 +0000 | [diff] [blame] | 370 | n=(ssize_t) vsnprintf(string,length,format,operands); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 371 | #endif |
| 372 | #else |
cristy | 20ec759 | 2011-05-29 01:28:05 +0000 | [diff] [blame] | 373 | n=(ssize_t) vsprintf(string,format,operands); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 374 | #endif |
| 375 | if (n < 0) |
| 376 | string[length-1]='\0'; |
cristy | 20ec759 | 2011-05-29 01:28:05 +0000 | [diff] [blame] | 377 | return(n); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 378 | } |
| 379 | |
cristy | ba56db5 | 2011-05-20 02:08:11 +0000 | [diff] [blame] | 380 | MagickExport ssize_t FormatLocaleString(char *restrict string, |
| 381 | const size_t length,const char *restrict format,...) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 382 | { |
| 383 | ssize_t |
| 384 | n; |
| 385 | |
| 386 | va_list |
| 387 | operands; |
| 388 | |
| 389 | va_start(operands,format); |
cristy | 20ec759 | 2011-05-29 01:28:05 +0000 | [diff] [blame] | 390 | n=FormatLocaleStringList(string,length,format,operands); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 391 | va_end(operands); |
| 392 | return(n); |
cristy | a20c904 | 2011-05-19 13:22:18 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | /* |
| 396 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 397 | % % |
| 398 | % % |
| 399 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 400 | + G e t L o c a l e I n f o _ % |
| 401 | % % |
| 402 | % % |
| 403 | % % |
| 404 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 405 | % |
| 406 | % GetLocaleInfo_() searches the locale list for the specified tag and if |
| 407 | % found returns attributes for that element. |
| 408 | % |
| 409 | % The format of the GetLocaleInfo method is: |
| 410 | % |
| 411 | % const LocaleInfo *GetLocaleInfo_(const char *tag, |
| 412 | % ExceptionInfo *exception) |
| 413 | % |
| 414 | % A description of each parameter follows: |
| 415 | % |
| 416 | % o tag: the locale tag. |
| 417 | % |
| 418 | % o exception: return any errors or warnings in this structure. |
| 419 | % |
| 420 | */ |
| 421 | MagickExport const LocaleInfo *GetLocaleInfo_(const char *tag, |
| 422 | ExceptionInfo *exception) |
| 423 | { |
| 424 | assert(exception != (ExceptionInfo *) NULL); |
| 425 | if ((locale_list == (SplayTreeInfo *) NULL) || |
| 426 | (instantiate_locale == MagickFalse)) |
| 427 | if (InitializeLocaleList(exception) == MagickFalse) |
| 428 | return((const LocaleInfo *) NULL); |
| 429 | if ((locale_list == (SplayTreeInfo *) NULL) || |
| 430 | (GetNumberOfNodesInSplayTree(locale_list) == 0)) |
| 431 | return((const LocaleInfo *) NULL); |
| 432 | if ((tag == (const char *) NULL) || (LocaleCompare(tag,"*") == 0)) |
| 433 | { |
| 434 | ResetSplayTreeIterator(locale_list); |
| 435 | return((const LocaleInfo *) GetNextValueInSplayTree(locale_list)); |
| 436 | } |
| 437 | return((const LocaleInfo *) GetValueFromSplayTree(locale_list,tag)); |
| 438 | } |
| 439 | |
| 440 | /* |
| 441 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 442 | % % |
| 443 | % % |
| 444 | % % |
| 445 | % G e t L o c a l e I n f o L i s t % |
| 446 | % % |
| 447 | % % |
| 448 | % % |
| 449 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 450 | % |
| 451 | % GetLocaleInfoList() returns any locale messages that match the |
| 452 | % specified pattern. |
| 453 | % |
| 454 | % The format of the GetLocaleInfoList function is: |
| 455 | % |
| 456 | % const LocaleInfo **GetLocaleInfoList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 457 | % size_t *number_messages,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 458 | % |
| 459 | % A description of each parameter follows: |
| 460 | % |
| 461 | % o pattern: Specifies a pointer to a text string containing a pattern. |
| 462 | % |
| 463 | % o number_messages: This integer returns the number of locale messages in |
| 464 | % the list. |
| 465 | % |
| 466 | % o exception: return any errors or warnings in this structure. |
| 467 | % |
| 468 | */ |
| 469 | |
| 470 | #if defined(__cplusplus) || defined(c_plusplus) |
| 471 | extern "C" { |
| 472 | #endif |
| 473 | |
| 474 | static int LocaleInfoCompare(const void *x,const void *y) |
| 475 | { |
| 476 | const LocaleInfo |
| 477 | **p, |
| 478 | **q; |
| 479 | |
| 480 | p=(const LocaleInfo **) x, |
| 481 | q=(const LocaleInfo **) y; |
| 482 | if (LocaleCompare((*p)->path,(*q)->path) == 0) |
| 483 | return(LocaleCompare((*p)->tag,(*q)->tag)); |
| 484 | return(LocaleCompare((*p)->path,(*q)->path)); |
| 485 | } |
| 486 | |
| 487 | #if defined(__cplusplus) || defined(c_plusplus) |
| 488 | } |
| 489 | #endif |
| 490 | |
| 491 | MagickExport const LocaleInfo **GetLocaleInfoList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 492 | size_t *number_messages,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 493 | { |
| 494 | const LocaleInfo |
| 495 | **messages; |
| 496 | |
| 497 | register const LocaleInfo |
| 498 | *p; |
| 499 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 500 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 501 | i; |
| 502 | |
| 503 | /* |
| 504 | Allocate locale list. |
| 505 | */ |
| 506 | assert(pattern != (char *) NULL); |
| 507 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 508 | assert(number_messages != (size_t *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 509 | *number_messages=0; |
| 510 | p=GetLocaleInfo_("*",exception); |
| 511 | if (p == (const LocaleInfo *) NULL) |
| 512 | return((const LocaleInfo **) NULL); |
| 513 | messages=(const LocaleInfo **) AcquireQuantumMemory((size_t) |
| 514 | GetNumberOfNodesInSplayTree(locale_list)+1UL,sizeof(*messages)); |
| 515 | if (messages == (const LocaleInfo **) NULL) |
| 516 | return((const LocaleInfo **) NULL); |
| 517 | /* |
| 518 | Generate locale list. |
| 519 | */ |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 520 | LockSemaphoreInfo(locale_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 521 | ResetSplayTreeIterator(locale_list); |
| 522 | p=(const LocaleInfo *) GetNextValueInSplayTree(locale_list); |
| 523 | for (i=0; p != (const LocaleInfo *) NULL; ) |
| 524 | { |
| 525 | if ((p->stealth == MagickFalse) && |
| 526 | (GlobExpression(p->tag,pattern,MagickTrue) != MagickFalse)) |
| 527 | messages[i++]=p; |
| 528 | p=(const LocaleInfo *) GetNextValueInSplayTree(locale_list); |
| 529 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 530 | UnlockSemaphoreInfo(locale_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 531 | qsort((void *) messages,(size_t) i,sizeof(*messages),LocaleInfoCompare); |
| 532 | messages[i]=(LocaleInfo *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 533 | *number_messages=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 534 | return(messages); |
| 535 | } |
| 536 | |
| 537 | /* |
| 538 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 539 | % % |
| 540 | % % |
| 541 | % % |
| 542 | % G e t L o c a l e L i s t % |
| 543 | % % |
| 544 | % % |
| 545 | % % |
| 546 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 547 | % |
| 548 | % GetLocaleList() returns any locale messages that match the specified |
| 549 | % pattern. |
| 550 | % |
| 551 | % The format of the GetLocaleList function is: |
| 552 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 553 | % char **GetLocaleList(const char *pattern,size_t *number_messages, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 554 | % Exceptioninfo *exception) |
| 555 | % |
| 556 | % A description of each parameter follows: |
| 557 | % |
| 558 | % o pattern: Specifies a pointer to a text string containing a pattern. |
| 559 | % |
| 560 | % o number_messages: This integer returns the number of messages in the |
| 561 | % list. |
| 562 | % |
| 563 | % o exception: return any errors or warnings in this structure. |
| 564 | % |
| 565 | */ |
| 566 | |
| 567 | #if defined(__cplusplus) || defined(c_plusplus) |
| 568 | extern "C" { |
| 569 | #endif |
| 570 | |
| 571 | static int LocaleTagCompare(const void *x,const void *y) |
| 572 | { |
| 573 | register char |
| 574 | **p, |
| 575 | **q; |
| 576 | |
| 577 | p=(char **) x; |
| 578 | q=(char **) y; |
| 579 | return(LocaleCompare(*p,*q)); |
| 580 | } |
| 581 | |
| 582 | #if defined(__cplusplus) || defined(c_plusplus) |
| 583 | } |
| 584 | #endif |
| 585 | |
| 586 | MagickExport char **GetLocaleList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 587 | size_t *number_messages,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 588 | { |
| 589 | char |
| 590 | **messages; |
| 591 | |
| 592 | register const LocaleInfo |
| 593 | *p; |
| 594 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 595 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 596 | i; |
| 597 | |
| 598 | /* |
| 599 | Allocate locale list. |
| 600 | */ |
| 601 | assert(pattern != (char *) NULL); |
| 602 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 603 | assert(number_messages != (size_t *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 604 | *number_messages=0; |
| 605 | p=GetLocaleInfo_("*",exception); |
| 606 | if (p == (const LocaleInfo *) NULL) |
| 607 | return((char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 608 | messages=(char **) AcquireQuantumMemory((size_t) |
| 609 | GetNumberOfNodesInSplayTree(locale_list)+1UL,sizeof(*messages)); |
| 610 | if (messages == (char **) NULL) |
| 611 | return((char **) NULL); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 612 | LockSemaphoreInfo(locale_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 613 | p=(const LocaleInfo *) GetNextValueInSplayTree(locale_list); |
| 614 | for (i=0; p != (const LocaleInfo *) NULL; ) |
| 615 | { |
| 616 | if ((p->stealth == MagickFalse) && |
| 617 | (GlobExpression(p->tag,pattern,MagickTrue) != MagickFalse)) |
| 618 | messages[i++]=ConstantString(p->tag); |
| 619 | p=(const LocaleInfo *) GetNextValueInSplayTree(locale_list); |
| 620 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 621 | UnlockSemaphoreInfo(locale_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 622 | qsort((void *) messages,(size_t) i,sizeof(*messages),LocaleTagCompare); |
| 623 | messages[i]=(char *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 624 | *number_messages=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 625 | return(messages); |
| 626 | } |
| 627 | |
| 628 | /* |
| 629 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 630 | % % |
| 631 | % % |
| 632 | % % |
| 633 | % G e t L o c a l e M e s s a g e % |
| 634 | % % |
| 635 | % % |
| 636 | % % |
| 637 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 638 | % |
| 639 | % GetLocaleMessage() returns a message in the current locale that matches the |
| 640 | % supplied tag. |
| 641 | % |
| 642 | % The format of the GetLocaleMessage method is: |
| 643 | % |
| 644 | % const char *GetLocaleMessage(const char *tag) |
| 645 | % |
| 646 | % A description of each parameter follows: |
| 647 | % |
| 648 | % o tag: Return a message that matches this tag in the current locale. |
| 649 | % |
| 650 | */ |
| 651 | MagickExport const char *GetLocaleMessage(const char *tag) |
| 652 | { |
| 653 | char |
| 654 | name[MaxTextExtent]; |
| 655 | |
| 656 | const LocaleInfo |
| 657 | *locale_info; |
| 658 | |
| 659 | ExceptionInfo |
| 660 | *exception; |
| 661 | |
| 662 | if ((tag == (const char *) NULL) || (*tag == '\0')) |
| 663 | return(tag); |
| 664 | exception=AcquireExceptionInfo(); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 665 | (void) FormatLocaleString(name,MaxTextExtent,"%s/",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 666 | locale_info=GetLocaleInfo_(name,exception); |
| 667 | exception=DestroyExceptionInfo(exception); |
| 668 | if (locale_info != (const LocaleInfo *) NULL) |
| 669 | return(locale_info->message); |
| 670 | return(tag); |
| 671 | } |
| 672 | |
| 673 | /* |
| 674 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 675 | % % |
| 676 | % % |
| 677 | % % |
| 678 | % G e t L o c a l e O p t i o n s % |
| 679 | % % |
| 680 | % % |
| 681 | % % |
| 682 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 683 | % |
| 684 | % GetLocaleOptions() returns any Magick configuration messages associated |
| 685 | % with the specified filename. |
| 686 | % |
| 687 | % The format of the GetLocaleOptions method is: |
| 688 | % |
| 689 | % LinkedListInfo *GetLocaleOptions(const char *filename, |
| 690 | % ExceptionInfo *exception) |
| 691 | % |
| 692 | % A description of each parameter follows: |
| 693 | % |
| 694 | % o filename: the locale file tag. |
| 695 | % |
| 696 | % o exception: return any errors or warnings in this structure. |
| 697 | % |
| 698 | */ |
| 699 | MagickExport LinkedListInfo *GetLocaleOptions(const char *filename, |
| 700 | ExceptionInfo *exception) |
| 701 | { |
| 702 | char |
| 703 | path[MaxTextExtent]; |
| 704 | |
| 705 | const char |
| 706 | *element; |
| 707 | |
| 708 | LinkedListInfo |
| 709 | *messages, |
| 710 | *paths; |
| 711 | |
| 712 | StringInfo |
| 713 | *xml; |
| 714 | |
| 715 | assert(filename != (const char *) NULL); |
| 716 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename); |
| 717 | assert(exception != (ExceptionInfo *) NULL); |
| 718 | (void) CopyMagickString(path,filename,MaxTextExtent); |
| 719 | /* |
| 720 | Load XML from configuration files to linked-list. |
| 721 | */ |
| 722 | messages=NewLinkedList(0); |
| 723 | paths=GetConfigurePaths(filename,exception); |
| 724 | if (paths != (LinkedListInfo *) NULL) |
| 725 | { |
| 726 | ResetLinkedListIterator(paths); |
| 727 | element=(const char *) GetNextValueInLinkedList(paths); |
| 728 | while (element != (const char *) NULL) |
| 729 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 730 | (void) FormatLocaleString(path,MaxTextExtent,"%s%s",element,filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 731 | (void) LogMagickEvent(LocaleEvent,GetMagickModule(), |
| 732 | "Searching for locale file: \"%s\"",path); |
| 733 | xml=ConfigureFileToStringInfo(path); |
| 734 | if (xml != (StringInfo *) NULL) |
| 735 | (void) AppendValueToLinkedList(messages,xml); |
| 736 | element=(const char *) GetNextValueInLinkedList(paths); |
| 737 | } |
| 738 | paths=DestroyLinkedList(paths,RelinquishMagickMemory); |
| 739 | } |
cristy | 0157aea | 2010-04-24 21:12:18 +0000 | [diff] [blame] | 740 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 741 | { |
| 742 | char |
| 743 | *blob; |
| 744 | |
| 745 | blob=(char *) NTResourceToBlob(filename); |
| 746 | if (blob != (char *) NULL) |
| 747 | { |
| 748 | xml=StringToStringInfo(blob); |
| 749 | (void) AppendValueToLinkedList(messages,xml); |
| 750 | blob=DestroyString(blob); |
| 751 | } |
| 752 | } |
| 753 | #endif |
| 754 | ResetLinkedListIterator(messages); |
| 755 | return(messages); |
| 756 | } |
| 757 | |
| 758 | /* |
| 759 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 760 | % % |
| 761 | % % |
| 762 | % % |
| 763 | % G e t L o c a l e V a l u e % |
| 764 | % % |
| 765 | % % |
| 766 | % % |
| 767 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 768 | % |
| 769 | % GetLocaleValue() returns the message associated with the locale info. |
| 770 | % |
| 771 | % The format of the GetLocaleValue method is: |
| 772 | % |
| 773 | % const char *GetLocaleValue(const LocaleInfo *locale_info) |
| 774 | % |
| 775 | % A description of each parameter follows: |
| 776 | % |
| 777 | % o locale_info: The locale info. |
| 778 | % |
| 779 | */ |
| 780 | MagickExport const char *GetLocaleValue(const LocaleInfo *locale_info) |
| 781 | { |
| 782 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 783 | assert(locale_info != (LocaleInfo *) NULL); |
| 784 | assert(locale_info->signature == MagickSignature); |
| 785 | return(locale_info->message); |
| 786 | } |
| 787 | |
| 788 | /* |
| 789 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 790 | % % |
| 791 | % % |
| 792 | % % |
| 793 | + I n i t i a l i z e L o c a l e L i s t % |
| 794 | % % |
| 795 | % % |
| 796 | % % |
| 797 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 798 | % |
| 799 | % InitializeLocaleList() initializes the locale list. |
| 800 | % |
| 801 | % The format of the InitializeLocaleList method is: |
| 802 | % |
| 803 | % MagickBooleanType InitializeLocaleList(ExceptionInfo *exception) |
| 804 | % |
| 805 | % A description of each parameter follows. |
| 806 | % |
| 807 | % o exception: return any errors or warnings in this structure. |
| 808 | % |
| 809 | */ |
| 810 | static MagickBooleanType InitializeLocaleList(ExceptionInfo *exception) |
| 811 | { |
| 812 | if ((locale_list == (SplayTreeInfo *) NULL) && |
| 813 | (instantiate_locale == MagickFalse)) |
| 814 | { |
cristy | 4e1dff6 | 2009-10-25 20:36:03 +0000 | [diff] [blame] | 815 | if (locale_semaphore == (SemaphoreInfo *) NULL) |
| 816 | AcquireSemaphoreInfo(&locale_semaphore); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 817 | LockSemaphoreInfo(locale_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 818 | if ((locale_list == (SplayTreeInfo *) NULL) && |
| 819 | (instantiate_locale == MagickFalse)) |
| 820 | { |
| 821 | char |
| 822 | *locale; |
| 823 | |
| 824 | register const char |
| 825 | *p; |
| 826 | |
| 827 | locale=(char *) NULL; |
| 828 | p=setlocale(LC_CTYPE,(const char *) NULL); |
| 829 | if (p != (const char *) NULL) |
| 830 | locale=ConstantString(p); |
| 831 | if (locale == (char *) NULL) |
| 832 | locale=GetEnvironmentValue("LC_ALL"); |
| 833 | if (locale == (char *) NULL) |
| 834 | locale=GetEnvironmentValue("LC_MESSAGES"); |
| 835 | if (locale == (char *) NULL) |
| 836 | locale=GetEnvironmentValue("LC_CTYPE"); |
| 837 | if (locale == (char *) NULL) |
| 838 | locale=GetEnvironmentValue("LANG"); |
| 839 | if (locale == (char *) NULL) |
| 840 | locale=ConstantString("C"); |
| 841 | (void) LoadLocaleLists(LocaleFilename,locale,exception); |
| 842 | locale=DestroyString(locale); |
| 843 | instantiate_locale=MagickTrue; |
| 844 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 845 | UnlockSemaphoreInfo(locale_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 846 | } |
| 847 | return(locale_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); |
| 848 | } |
| 849 | |
| 850 | /* |
| 851 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 852 | % % |
| 853 | % % |
| 854 | % % |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 855 | + I n t e r p r e t L o c a l e V a l u e % |
| 856 | % % |
| 857 | % % |
| 858 | % % |
| 859 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 860 | % |
| 861 | % InterpretLocaleValue() interprets the string as a floating point number in |
| 862 | % the "C" locale and returns its value as a double. If sentinal is not a null |
| 863 | % pointer, the method also sets the value pointed by sentinal to point to the |
| 864 | % first character after the number. |
| 865 | % |
| 866 | % The format of the InterpretLocaleValue method is: |
| 867 | % |
| 868 | % double InterpretLocaleValue(const char *value,char **sentinal) |
| 869 | % |
| 870 | % A description of each parameter follows: |
| 871 | % |
| 872 | % o value: the string value. |
| 873 | % |
| 874 | % o sentinal: if sentinal is not NULL, a pointer to the character after the |
| 875 | % last character used in the conversion is stored in the location |
| 876 | % referenced by sentinal. |
| 877 | % |
| 878 | */ |
cristy | ba56db5 | 2011-05-20 02:08:11 +0000 | [diff] [blame] | 879 | MagickExport double InterpretLocaleValue(const char *restrict string, |
| 880 | char **restrict sentinal) |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 881 | { |
| 882 | double |
| 883 | value; |
| 884 | |
| 885 | #if defined(MAGICKCORE_HAVE_STRTOD_L) |
| 886 | { |
| 887 | locale_t |
| 888 | locale; |
| 889 | |
| 890 | locale=AcquireCLocale(); |
| 891 | if (locale == (locale_t) NULL) |
| 892 | value=strtod(string,sentinal); |
| 893 | else |
| 894 | value=strtod_l(string,sentinal,locale); |
| 895 | } |
| 896 | #else |
| 897 | value=strtod(string,sentinal); |
| 898 | #endif |
| 899 | return(value); |
| 900 | } |
| 901 | |
| 902 | /* |
| 903 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 904 | % % |
| 905 | % % |
| 906 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 907 | % L i s t L o c a l e I n f o % |
| 908 | % % |
| 909 | % % |
| 910 | % % |
| 911 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 912 | % |
| 913 | % ListLocaleInfo() lists the locale info to a file. |
| 914 | % |
| 915 | % The format of the ListLocaleInfo method is: |
| 916 | % |
| 917 | % MagickBooleanType ListLocaleInfo(FILE *file,ExceptionInfo *exception) |
| 918 | % |
| 919 | % A description of each parameter follows. |
| 920 | % |
| 921 | % o file: An pointer to a FILE. |
| 922 | % |
| 923 | % o exception: return any errors or warnings in this structure. |
| 924 | % |
| 925 | */ |
| 926 | MagickExport MagickBooleanType ListLocaleInfo(FILE *file, |
| 927 | ExceptionInfo *exception) |
| 928 | { |
| 929 | const char |
| 930 | *path; |
| 931 | |
| 932 | const LocaleInfo |
| 933 | **locale_info; |
| 934 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 935 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 936 | i; |
| 937 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 938 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 939 | number_messages; |
| 940 | |
| 941 | if (file == (const FILE *) NULL) |
| 942 | file=stdout; |
| 943 | number_messages=0; |
| 944 | locale_info=GetLocaleInfoList("*",&number_messages,exception); |
| 945 | if (locale_info == (const LocaleInfo **) NULL) |
| 946 | return(MagickFalse); |
| 947 | path=(const char *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 948 | for (i=0; i < (ssize_t) number_messages; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 949 | { |
| 950 | if (locale_info[i]->stealth != MagickFalse) |
| 951 | continue; |
| 952 | if ((path == (const char *) NULL) || |
| 953 | (LocaleCompare(path,locale_info[i]->path) != 0)) |
| 954 | { |
| 955 | if (locale_info[i]->path != (char *) NULL) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 956 | (void) FormatLocaleFile(file,"\nPath: %s\n\n",locale_info[i]->path); |
| 957 | (void) FormatLocaleFile(file,"Tag/Message\n"); |
cristy | 1e60481 | 2011-05-19 18:07:50 +0000 | [diff] [blame] | 958 | (void) FormatLocaleFile(file, |
| 959 | "-------------------------------------------------" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 960 | "------------------------------\n"); |
| 961 | } |
| 962 | path=locale_info[i]->path; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 963 | (void) FormatLocaleFile(file,"%s\n",locale_info[i]->tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 964 | if (locale_info[i]->message != (char *) NULL) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 965 | (void) FormatLocaleFile(file," %s",locale_info[i]->message); |
| 966 | (void) FormatLocaleFile(file,"\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 967 | } |
| 968 | (void) fflush(file); |
| 969 | locale_info=(const LocaleInfo **) |
| 970 | RelinquishMagickMemory((void *) locale_info); |
| 971 | return(MagickTrue); |
| 972 | } |
| 973 | |
| 974 | /* |
| 975 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 976 | % % |
| 977 | % % |
| 978 | % % |
| 979 | + L o a d L o c a l e L i s t % |
| 980 | % % |
| 981 | % % |
| 982 | % % |
| 983 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 984 | % |
| 985 | % LoadLocaleList() loads the locale configuration file which provides a mapping |
| 986 | % between locale attributes and a locale name. |
| 987 | % |
| 988 | % The format of the LoadLocaleList method is: |
| 989 | % |
| 990 | % MagickBooleanType LoadLocaleList(const char *xml,const char *filename, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 991 | % const size_t depth,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 992 | % |
| 993 | % A description of each parameter follows: |
| 994 | % |
| 995 | % o xml: The locale list in XML format. |
| 996 | % |
| 997 | % o filename: The locale list filename. |
| 998 | % |
| 999 | % o depth: depth of <include /> statements. |
| 1000 | % |
| 1001 | % o exception: return any errors or warnings in this structure. |
| 1002 | % |
| 1003 | */ |
| 1004 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1005 | static void ChopLocaleComponents(char *path,const size_t components) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1006 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1007 | register char |
| 1008 | *p; |
| 1009 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 1010 | ssize_t |
| 1011 | count; |
| 1012 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1013 | if (*path == '\0') |
| 1014 | return; |
| 1015 | p=path+strlen(path)-1; |
| 1016 | if (*p == '/') |
| 1017 | *p='\0'; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1018 | for (count=0; (count < (ssize_t) components) && (p > path); p--) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1019 | if (*p == '/') |
| 1020 | { |
| 1021 | *p='\0'; |
| 1022 | count++; |
| 1023 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1024 | if (count < (ssize_t) components) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1025 | *path='\0'; |
| 1026 | } |
| 1027 | |
| 1028 | static void *DestroyLocaleNode(void *locale_info) |
| 1029 | { |
| 1030 | register LocaleInfo |
| 1031 | *p; |
| 1032 | |
| 1033 | p=(LocaleInfo *) locale_info; |
| 1034 | if (p->path != (char *) NULL) |
| 1035 | p->path=DestroyString(p->path); |
| 1036 | if (p->tag != (char *) NULL) |
| 1037 | p->tag=DestroyString(p->tag); |
| 1038 | if (p->message != (char *) NULL) |
| 1039 | p->message=DestroyString(p->message); |
| 1040 | return(RelinquishMagickMemory(p)); |
| 1041 | } |
| 1042 | |
cristy | 2359e74 | 2009-11-24 14:50:02 +0000 | [diff] [blame] | 1043 | static void LocaleFatalErrorHandler( |
| 1044 | const ExceptionType magick_unused(severity), |
| 1045 | const char *reason,const char *description) |
| 1046 | { |
| 1047 | if (reason == (char *) NULL) |
| 1048 | return; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1049 | (void) FormatLocaleFile(stderr,"%s: %s",GetClientName(),reason); |
cristy | 2359e74 | 2009-11-24 14:50:02 +0000 | [diff] [blame] | 1050 | if (description != (char *) NULL) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1051 | (void) FormatLocaleFile(stderr," (%s)",description); |
| 1052 | (void) FormatLocaleFile(stderr,".\n"); |
cristy | 2359e74 | 2009-11-24 14:50:02 +0000 | [diff] [blame] | 1053 | (void) fflush(stderr); |
| 1054 | exit(1); |
| 1055 | } |
| 1056 | |
| 1057 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1058 | static MagickBooleanType LoadLocaleList(const char *xml,const char *filename, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1059 | const char *locale,const size_t depth,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1060 | { |
| 1061 | char |
| 1062 | keyword[MaxTextExtent], |
| 1063 | message[MaxTextExtent], |
| 1064 | tag[MaxTextExtent], |
| 1065 | *token; |
| 1066 | |
| 1067 | const char |
| 1068 | *q; |
| 1069 | |
cristy | 909b647 | 2009-11-24 14:45:00 +0000 | [diff] [blame] | 1070 | FatalErrorHandler |
| 1071 | fatal_handler; |
| 1072 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1073 | LocaleInfo |
| 1074 | *locale_info; |
| 1075 | |
| 1076 | MagickBooleanType |
| 1077 | status; |
| 1078 | |
| 1079 | register char |
| 1080 | *p; |
| 1081 | |
| 1082 | /* |
| 1083 | Read the locale configure file. |
| 1084 | */ |
| 1085 | (void) LogMagickEvent(ConfigureEvent,GetMagickModule(), |
| 1086 | "Loading locale configure file \"%s\" ...",filename); |
| 1087 | if (xml == (const char *) NULL) |
| 1088 | return(MagickFalse); |
| 1089 | if (locale_list == (SplayTreeInfo *) NULL) |
| 1090 | { |
| 1091 | locale_list=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL, |
| 1092 | DestroyLocaleNode); |
| 1093 | if (locale_list == (SplayTreeInfo *) NULL) |
cristy | 909b647 | 2009-11-24 14:45:00 +0000 | [diff] [blame] | 1094 | return(MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1095 | } |
| 1096 | status=MagickTrue; |
| 1097 | locale_info=(LocaleInfo *) NULL; |
| 1098 | *tag='\0'; |
| 1099 | *message='\0'; |
| 1100 | *keyword='\0'; |
cristy | 2359e74 | 2009-11-24 14:50:02 +0000 | [diff] [blame] | 1101 | fatal_handler=SetFatalErrorHandler(LocaleFatalErrorHandler); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1102 | token=AcquireString(xml); |
| 1103 | for (q=(char *) xml; *q != '\0'; ) |
| 1104 | { |
| 1105 | /* |
| 1106 | Interpret XML. |
| 1107 | */ |
| 1108 | GetMagickToken(q,&q,token); |
| 1109 | if (*token == '\0') |
| 1110 | break; |
| 1111 | (void) CopyMagickString(keyword,token,MaxTextExtent); |
| 1112 | if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0) |
| 1113 | { |
| 1114 | /* |
| 1115 | Doctype element. |
| 1116 | */ |
| 1117 | while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0')) |
| 1118 | { |
| 1119 | GetMagickToken(q,&q,token); |
| 1120 | while (isspace((int) ((unsigned char) *q)) != 0) |
| 1121 | q++; |
| 1122 | } |
| 1123 | continue; |
| 1124 | } |
| 1125 | if (LocaleNCompare(keyword,"<!--",4) == 0) |
| 1126 | { |
| 1127 | /* |
| 1128 | Comment element. |
| 1129 | */ |
| 1130 | while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0')) |
| 1131 | { |
| 1132 | GetMagickToken(q,&q,token); |
| 1133 | while (isspace((int) ((unsigned char) *q)) != 0) |
| 1134 | q++; |
| 1135 | } |
| 1136 | continue; |
| 1137 | } |
| 1138 | if (LocaleCompare(keyword,"<include") == 0) |
| 1139 | { |
| 1140 | /* |
| 1141 | Include element. |
| 1142 | */ |
| 1143 | while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0')) |
| 1144 | { |
| 1145 | (void) CopyMagickString(keyword,token,MaxTextExtent); |
| 1146 | GetMagickToken(q,&q,token); |
| 1147 | if (*token != '=') |
| 1148 | continue; |
| 1149 | GetMagickToken(q,&q,token); |
| 1150 | if (LocaleCompare(keyword,"locale") == 0) |
| 1151 | { |
| 1152 | if (LocaleCompare(locale,token) != 0) |
| 1153 | break; |
| 1154 | continue; |
| 1155 | } |
| 1156 | if (LocaleCompare(keyword,"file") == 0) |
| 1157 | { |
| 1158 | if (depth > 200) |
| 1159 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 1160 | ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token); |
| 1161 | else |
| 1162 | { |
| 1163 | char |
| 1164 | path[MaxTextExtent], |
| 1165 | *xml; |
| 1166 | |
| 1167 | *path='\0'; |
| 1168 | GetPathComponent(filename,HeadPath,path); |
| 1169 | if (*path != '\0') |
| 1170 | (void) ConcatenateMagickString(path,DirectorySeparator, |
| 1171 | MaxTextExtent); |
| 1172 | if (*token == *DirectorySeparator) |
| 1173 | (void) CopyMagickString(path,token,MaxTextExtent); |
| 1174 | else |
| 1175 | (void) ConcatenateMagickString(path,token,MaxTextExtent); |
| 1176 | xml=FileToString(path,~0,exception); |
| 1177 | if (xml != (char *) NULL) |
| 1178 | { |
| 1179 | status=LoadLocaleList(xml,path,locale,depth+1,exception); |
| 1180 | xml=(char *) RelinquishMagickMemory(xml); |
| 1181 | } |
| 1182 | } |
| 1183 | } |
| 1184 | } |
| 1185 | continue; |
| 1186 | } |
| 1187 | if (LocaleCompare(keyword,"<locale") == 0) |
| 1188 | { |
| 1189 | /* |
| 1190 | Locale element. |
| 1191 | */ |
| 1192 | while ((*token != '>') && (*q != '\0')) |
| 1193 | { |
| 1194 | (void) CopyMagickString(keyword,token,MaxTextExtent); |
| 1195 | GetMagickToken(q,&q,token); |
| 1196 | if (*token != '=') |
| 1197 | continue; |
| 1198 | GetMagickToken(q,&q,token); |
| 1199 | } |
| 1200 | continue; |
| 1201 | } |
| 1202 | if (LocaleCompare(keyword,"</locale>") == 0) |
| 1203 | { |
| 1204 | ChopLocaleComponents(tag,1); |
| 1205 | (void) ConcatenateMagickString(tag,"/",MaxTextExtent); |
| 1206 | continue; |
| 1207 | } |
| 1208 | if (LocaleCompare(keyword,"<localemap>") == 0) |
| 1209 | continue; |
| 1210 | if (LocaleCompare(keyword,"</localemap>") == 0) |
| 1211 | continue; |
| 1212 | if (LocaleCompare(keyword,"<message") == 0) |
| 1213 | { |
| 1214 | /* |
| 1215 | Message element. |
| 1216 | */ |
| 1217 | while ((*token != '>') && (*q != '\0')) |
| 1218 | { |
| 1219 | (void) CopyMagickString(keyword,token,MaxTextExtent); |
| 1220 | GetMagickToken(q,&q,token); |
| 1221 | if (*token != '=') |
| 1222 | continue; |
| 1223 | GetMagickToken(q,&q,token); |
| 1224 | if (LocaleCompare(keyword,"name") == 0) |
| 1225 | { |
| 1226 | (void) ConcatenateMagickString(tag,token,MaxTextExtent); |
| 1227 | (void) ConcatenateMagickString(tag,"/",MaxTextExtent); |
| 1228 | } |
| 1229 | } |
| 1230 | for (p=(char *) q; (*q != '<') && (*q != '\0'); q++) ; |
| 1231 | while (isspace((int) ((unsigned char) *p)) != 0) |
| 1232 | p++; |
| 1233 | q--; |
| 1234 | while ((isspace((int) ((unsigned char) *q)) != 0) && (q > p)) |
| 1235 | q--; |
| 1236 | (void) CopyMagickString(message,p,(size_t) (q-p+2)); |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 1237 | locale_info=(LocaleInfo *) AcquireMagickMemory(sizeof(*locale_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1238 | if (locale_info == (LocaleInfo *) NULL) |
| 1239 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 1240 | (void) ResetMagickMemory(locale_info,0,sizeof(*locale_info)); |
| 1241 | locale_info->path=ConstantString(filename); |
| 1242 | locale_info->tag=ConstantString(tag); |
| 1243 | locale_info->message=ConstantString(message); |
| 1244 | locale_info->signature=MagickSignature; |
| 1245 | status=AddValueToSplayTree(locale_list,locale_info->tag,locale_info); |
| 1246 | if (status == MagickFalse) |
| 1247 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 1248 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
| 1249 | locale_info->tag); |
| 1250 | (void) ConcatenateMagickString(tag,message,MaxTextExtent); |
| 1251 | (void) ConcatenateMagickString(tag,"\n",MaxTextExtent); |
| 1252 | q++; |
| 1253 | continue; |
| 1254 | } |
| 1255 | if (LocaleCompare(keyword,"</message>") == 0) |
| 1256 | { |
| 1257 | ChopLocaleComponents(tag,2); |
| 1258 | (void) ConcatenateMagickString(tag,"/",MaxTextExtent); |
| 1259 | continue; |
| 1260 | } |
| 1261 | if (*keyword == '<') |
| 1262 | { |
| 1263 | /* |
| 1264 | Subpath element. |
| 1265 | */ |
| 1266 | if (*(keyword+1) == '?') |
| 1267 | continue; |
| 1268 | if (*(keyword+1) == '/') |
| 1269 | { |
| 1270 | ChopLocaleComponents(tag,1); |
| 1271 | if (*tag != '\0') |
| 1272 | (void) ConcatenateMagickString(tag,"/",MaxTextExtent); |
| 1273 | continue; |
| 1274 | } |
| 1275 | token[strlen(token)-1]='\0'; |
| 1276 | (void) CopyMagickString(token,token+1,MaxTextExtent); |
| 1277 | (void) ConcatenateMagickString(tag,token,MaxTextExtent); |
| 1278 | (void) ConcatenateMagickString(tag,"/",MaxTextExtent); |
| 1279 | continue; |
| 1280 | } |
| 1281 | GetMagickToken(q,(const char **) NULL,token); |
| 1282 | if (*token != '=') |
| 1283 | continue; |
| 1284 | } |
| 1285 | token=(char *) RelinquishMagickMemory(token); |
cristy | 909b647 | 2009-11-24 14:45:00 +0000 | [diff] [blame] | 1286 | (void) SetFatalErrorHandler(fatal_handler); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1287 | return(status); |
| 1288 | } |
| 1289 | |
| 1290 | /* |
| 1291 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1292 | % % |
| 1293 | % % |
| 1294 | % % |
| 1295 | % L o a d L o c a l e L i s t s % |
| 1296 | % % |
| 1297 | % % |
| 1298 | % % |
| 1299 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1300 | % |
| 1301 | % LoadLocaleList() loads one or more locale configuration file which |
| 1302 | % provides a mapping between locale attributes and a locale tag. |
| 1303 | % |
| 1304 | % The format of the LoadLocaleLists method is: |
| 1305 | % |
| 1306 | % MagickBooleanType LoadLocaleLists(const char *filename, |
| 1307 | % ExceptionInfo *exception) |
| 1308 | % |
| 1309 | % A description of each parameter follows: |
| 1310 | % |
| 1311 | % o filename: the font file tag. |
| 1312 | % |
| 1313 | % o locale: the actual locale. |
| 1314 | % |
| 1315 | % o exception: return any errors or warnings in this structure. |
| 1316 | % |
| 1317 | */ |
| 1318 | static MagickBooleanType LoadLocaleLists(const char *filename, |
| 1319 | const char *locale,ExceptionInfo *exception) |
| 1320 | { |
cristy | 6e3607c | 2011-09-13 13:59:17 +0000 | [diff] [blame^] | 1321 | #if defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1322 | return(LoadLocaleList(LocaleMap,"built-in",locale,0,exception)); |
| 1323 | #else |
| 1324 | const StringInfo |
| 1325 | *option; |
| 1326 | |
| 1327 | LinkedListInfo |
| 1328 | *options; |
| 1329 | |
| 1330 | MagickStatusType |
| 1331 | status; |
| 1332 | |
| 1333 | status=MagickFalse; |
| 1334 | options=GetLocaleOptions(filename,exception); |
| 1335 | option=(const StringInfo *) GetNextValueInLinkedList(options); |
| 1336 | while (option != (const StringInfo *) NULL) |
| 1337 | { |
| 1338 | status|=LoadLocaleList((const char *) GetStringInfoDatum(option), |
| 1339 | GetStringInfoPath(option),locale,0,exception); |
| 1340 | option=(const StringInfo *) GetNextValueInLinkedList(options); |
| 1341 | } |
| 1342 | options=DestroyLocaleOptions(options); |
| 1343 | if ((locale_list == (SplayTreeInfo *) NULL) || |
| 1344 | (GetNumberOfNodesInSplayTree(locale_list) == 0)) |
| 1345 | { |
| 1346 | options=GetLocaleOptions("english.xml",exception); |
| 1347 | option=(const StringInfo *) GetNextValueInLinkedList(options); |
| 1348 | while (option != (const StringInfo *) NULL) |
| 1349 | { |
| 1350 | status|=LoadLocaleList((const char *) GetStringInfoDatum(option), |
| 1351 | GetStringInfoPath(option),locale,0,exception); |
| 1352 | option=(const StringInfo *) GetNextValueInLinkedList(options); |
| 1353 | } |
| 1354 | options=DestroyLocaleOptions(options); |
| 1355 | } |
| 1356 | if ((locale_list == (SplayTreeInfo *) NULL) || |
| 1357 | (GetNumberOfNodesInSplayTree(locale_list) == 0)) |
| 1358 | status|=LoadLocaleList(LocaleMap,"built-in",locale,0,exception); |
| 1359 | return(status != 0 ? MagickTrue : MagickFalse); |
| 1360 | #endif |
| 1361 | } |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1362 | |
| 1363 | /* |
| 1364 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1365 | % % |
| 1366 | % % |
| 1367 | % % |
| 1368 | + L o c a l e C o m p o n e n t G e n e s i s % |
| 1369 | % % |
| 1370 | % % |
| 1371 | % % |
| 1372 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1373 | % |
| 1374 | % LocaleComponentGenesis() instantiates the locale component. |
| 1375 | % |
| 1376 | % The format of the LocaleComponentGenesis method is: |
| 1377 | % |
| 1378 | % MagickBooleanType LocaleComponentGenesis(void) |
| 1379 | % |
| 1380 | */ |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 1381 | MagickPrivate MagickBooleanType LocaleComponentGenesis(void) |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1382 | { |
cristy | 165b609 | 2009-10-26 13:52:10 +0000 | [diff] [blame] | 1383 | AcquireSemaphoreInfo(&locale_semaphore); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1384 | return(MagickTrue); |
| 1385 | } |
| 1386 | |
| 1387 | /* |
| 1388 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1389 | % % |
| 1390 | % % |
| 1391 | % % |
| 1392 | + L o c a l e C o m p o n e n t T e r m i n u s % |
| 1393 | % % |
| 1394 | % % |
| 1395 | % % |
| 1396 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1397 | % |
| 1398 | % LocaleComponentTerminus() destroys the locale component. |
| 1399 | % |
| 1400 | % The format of the LocaleComponentTerminus method is: |
| 1401 | % |
| 1402 | % LocaleComponentTerminus(void) |
| 1403 | % |
| 1404 | */ |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 1405 | MagickPrivate void LocaleComponentTerminus(void) |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1406 | { |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 1407 | if (locale_semaphore == (SemaphoreInfo *) NULL) |
| 1408 | AcquireSemaphoreInfo(&locale_semaphore); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1409 | LockSemaphoreInfo(locale_semaphore); |
cristy | a723b6a | 2011-05-25 12:08:51 +0000 | [diff] [blame] | 1410 | #if defined(MAGICKCORE_HAVE_STRTOD_L) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1411 | DestroyCLocale(); |
cristy | a723b6a | 2011-05-25 12:08:51 +0000 | [diff] [blame] | 1412 | #endif |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1413 | instantiate_locale=MagickFalse; |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1414 | UnlockSemaphoreInfo(locale_semaphore); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1415 | DestroySemaphoreInfo(&locale_semaphore); |
| 1416 | } |