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