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