2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % L OOO CCCC AAA L EEEEE %
8 % L O O C AAAAA L EEE %
10 % LLLLL OOO CCCC A A LLLLL EEEEE %
13 % MagickCore Image Locale Methods %
20 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
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. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "magick/studio.h"
43 #include "magick/blob.h"
44 #include "magick/client.h"
45 #include "magick/configure.h"
46 #include "magick/exception.h"
47 #include "magick/exception-private.h"
48 #include "magick/hashmap.h"
49 #include "magick/locale_.h"
50 #include "magick/log.h"
51 #include "magick/memory_.h"
52 #include "magick/semaphore.h"
53 #include "magick/splay-tree.h"
54 #include "magick/string_.h"
55 #include "magick/token.h"
56 #include "magick/utility.h"
57 #include "magick/xml-tree.h"
62 #define LocaleFilename "locale.xml"
63 #define MaxRecursionDepth 200
70 "<?xml version=\"1.0\"?>"
72 " <locale name=\"C\">"
74 " <Message name=\"\">"
81 *locale_semaphore = (SemaphoreInfo *) NULL;
84 *locale_list = (SplayTreeInfo *) NULL;
86 static volatile MagickBooleanType
87 instantiate_locale = MagickFalse;
89 static volatile locale_t
90 locale_cache = (locale_t) NULL;
95 static MagickBooleanType
96 InitializeLocaleList(ExceptionInfo *),
97 LoadLocaleLists(const char *,const char *,ExceptionInfo *);
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 + A c q u i r e M a g i c k L o c a l e %
108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110 % AcquireMagickLocale() allocates the C locale object, or (locale_t) 0 with
111 % errno set if it cannot be acquired.
113 % The format of the AcquireMagickLocale method is:
115 % locale_t AcquireMagickLocale(void)
118 MagickExport locale_t AcquireMagickLocale(void)
120 #if defined(MAGICKCORE_HAVE_NEWLOCALE)
121 if (locale_cache == (locale_t) NULL)
122 locale_cache=newlocale(LC_ALL_MASK,"C",(locale_t) 0);
123 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
124 if (locale_cache == (locale_t) NULL)
125 locale_cache=_create_locale(LC_ALL,"C");
127 return(locale_cache);
131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 % D e s t r o y L o c a l e O p t i o n s %
139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 % DestroyLocaleOptions() releases memory associated with an locale
144 % The format of the DestroyProfiles method is:
146 % LinkedListInfo *DestroyLocaleOptions(Image *image)
148 % A description of each parameter follows:
150 % o image: the image.
154 static void *DestroyOptions(void *message)
156 return(DestroyStringInfo((StringInfo *) message));
159 MagickExport LinkedListInfo *DestroyLocaleOptions(LinkedListInfo *messages)
161 assert(messages != (LinkedListInfo *) NULL);
162 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
163 return(DestroyLinkedList(messages,DestroyOptions));
167 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171 + D e s t r o y M a g i c k L o c a l e %
175 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177 % DestroyMagickLocale() releases the resources allocated for a locale object
178 % returned by a call to the AcquireMagickLocale() method.
180 % The format of the DestroyMagickLocale method is:
182 % void DestroyMagickLocale(void)
185 MagickExport void DestroyMagickLocale(void)
187 #if defined(MAGICKCORE_HAVE_NEWLOCALE)
188 if (locale_cache != (locale_t) NULL)
189 freelocale(locale_cache);
190 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
191 if (locale_cache != (locale_t) NULL)
192 _free_locale(locale_cache);
194 locale_cache=(locale_t) NULL;
198 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202 + G e t L o c a l e I n f o _ %
206 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208 % GetLocaleInfo_() searches the locale list for the specified tag and if
209 % found returns attributes for that element.
211 % The format of the GetLocaleInfo method is:
213 % const LocaleInfo *GetLocaleInfo_(const char *tag,
214 % ExceptionInfo *exception)
216 % A description of each parameter follows:
218 % o tag: the locale tag.
220 % o exception: return any errors or warnings in this structure.
223 MagickExport const LocaleInfo *GetLocaleInfo_(const char *tag,
224 ExceptionInfo *exception)
226 assert(exception != (ExceptionInfo *) NULL);
227 if ((locale_list == (SplayTreeInfo *) NULL) ||
228 (instantiate_locale == MagickFalse))
229 if (InitializeLocaleList(exception) == MagickFalse)
230 return((const LocaleInfo *) NULL);
231 if ((locale_list == (SplayTreeInfo *) NULL) ||
232 (GetNumberOfNodesInSplayTree(locale_list) == 0))
233 return((const LocaleInfo *) NULL);
234 if ((tag == (const char *) NULL) || (LocaleCompare(tag,"*") == 0))
236 ResetSplayTreeIterator(locale_list);
237 return((const LocaleInfo *) GetNextValueInSplayTree(locale_list));
239 return((const LocaleInfo *) GetValueFromSplayTree(locale_list,tag));
243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247 % G e t L o c a l e I n f o L i s t %
251 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
253 % GetLocaleInfoList() returns any locale messages that match the
256 % The format of the GetLocaleInfoList function is:
258 % const LocaleInfo **GetLocaleInfoList(const char *pattern,
259 % size_t *number_messages,ExceptionInfo *exception)
261 % A description of each parameter follows:
263 % o pattern: Specifies a pointer to a text string containing a pattern.
265 % o number_messages: This integer returns the number of locale messages in
268 % o exception: return any errors or warnings in this structure.
272 #if defined(__cplusplus) || defined(c_plusplus)
276 static int LocaleInfoCompare(const void *x,const void *y)
282 p=(const LocaleInfo **) x,
283 q=(const LocaleInfo **) y;
284 if (LocaleCompare((*p)->path,(*q)->path) == 0)
285 return(LocaleCompare((*p)->tag,(*q)->tag));
286 return(LocaleCompare((*p)->path,(*q)->path));
289 #if defined(__cplusplus) || defined(c_plusplus)
293 MagickExport const LocaleInfo **GetLocaleInfoList(const char *pattern,
294 size_t *number_messages,ExceptionInfo *exception)
299 register const LocaleInfo
306 Allocate locale list.
308 assert(pattern != (char *) NULL);
309 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
310 assert(number_messages != (size_t *) NULL);
312 p=GetLocaleInfo_("*",exception);
313 if (p == (const LocaleInfo *) NULL)
314 return((const LocaleInfo **) NULL);
315 messages=(const LocaleInfo **) AcquireQuantumMemory((size_t)
316 GetNumberOfNodesInSplayTree(locale_list)+1UL,sizeof(*messages));
317 if (messages == (const LocaleInfo **) NULL)
318 return((const LocaleInfo **) NULL);
320 Generate locale list.
322 LockSemaphoreInfo(locale_semaphore);
323 ResetSplayTreeIterator(locale_list);
324 p=(const LocaleInfo *) GetNextValueInSplayTree(locale_list);
325 for (i=0; p != (const LocaleInfo *) NULL; )
327 if ((p->stealth == MagickFalse) &&
328 (GlobExpression(p->tag,pattern,MagickTrue) != MagickFalse))
330 p=(const LocaleInfo *) GetNextValueInSplayTree(locale_list);
332 UnlockSemaphoreInfo(locale_semaphore);
333 qsort((void *) messages,(size_t) i,sizeof(*messages),LocaleInfoCompare);
334 messages[i]=(LocaleInfo *) NULL;
335 *number_messages=(size_t) i;
340 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
344 % G e t L o c a l e L i s t %
348 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
350 % GetLocaleList() returns any locale messages that match the specified
353 % The format of the GetLocaleList function is:
355 % char **GetLocaleList(const char *pattern,size_t *number_messages,
356 % Exceptioninfo *exception)
358 % A description of each parameter follows:
360 % o pattern: Specifies a pointer to a text string containing a pattern.
362 % o number_messages: This integer returns the number of messages in the
365 % o exception: return any errors or warnings in this structure.
369 #if defined(__cplusplus) || defined(c_plusplus)
373 static int LocaleTagCompare(const void *x,const void *y)
381 return(LocaleCompare(*p,*q));
384 #if defined(__cplusplus) || defined(c_plusplus)
388 MagickExport char **GetLocaleList(const char *pattern,
389 size_t *number_messages,ExceptionInfo *exception)
394 register const LocaleInfo
401 Allocate locale list.
403 assert(pattern != (char *) NULL);
404 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
405 assert(number_messages != (size_t *) NULL);
407 p=GetLocaleInfo_("*",exception);
408 if (p == (const LocaleInfo *) NULL)
409 return((char **) NULL);
410 messages=(char **) AcquireQuantumMemory((size_t)
411 GetNumberOfNodesInSplayTree(locale_list)+1UL,sizeof(*messages));
412 if (messages == (char **) NULL)
413 return((char **) NULL);
414 LockSemaphoreInfo(locale_semaphore);
415 p=(const LocaleInfo *) GetNextValueInSplayTree(locale_list);
416 for (i=0; p != (const LocaleInfo *) NULL; )
418 if ((p->stealth == MagickFalse) &&
419 (GlobExpression(p->tag,pattern,MagickTrue) != MagickFalse))
420 messages[i++]=ConstantString(p->tag);
421 p=(const LocaleInfo *) GetNextValueInSplayTree(locale_list);
423 UnlockSemaphoreInfo(locale_semaphore);
424 qsort((void *) messages,(size_t) i,sizeof(*messages),LocaleTagCompare);
425 messages[i]=(char *) NULL;
426 *number_messages=(size_t) i;
431 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
435 % G e t L o c a l e M e s s a g e %
439 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
441 % GetLocaleMessage() returns a message in the current locale that matches the
444 % The format of the GetLocaleMessage method is:
446 % const char *GetLocaleMessage(const char *tag)
448 % A description of each parameter follows:
450 % o tag: Return a message that matches this tag in the current locale.
453 MagickExport const char *GetLocaleMessage(const char *tag)
464 if ((tag == (const char *) NULL) || (*tag == '\0'))
466 exception=AcquireExceptionInfo();
467 (void) FormatMagickString(name,MaxTextExtent,"%s/",tag);
468 locale_info=GetLocaleInfo_(name,exception);
469 exception=DestroyExceptionInfo(exception);
470 if (locale_info != (const LocaleInfo *) NULL)
471 return(locale_info->message);
476 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
480 % G e t L o c a l e O p t i o n s %
484 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
486 % GetLocaleOptions() returns any Magick configuration messages associated
487 % with the specified filename.
489 % The format of the GetLocaleOptions method is:
491 % LinkedListInfo *GetLocaleOptions(const char *filename,
492 % ExceptionInfo *exception)
494 % A description of each parameter follows:
496 % o filename: the locale file tag.
498 % o exception: return any errors or warnings in this structure.
501 MagickExport LinkedListInfo *GetLocaleOptions(const char *filename,
502 ExceptionInfo *exception)
517 assert(filename != (const char *) NULL);
518 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
519 assert(exception != (ExceptionInfo *) NULL);
520 (void) CopyMagickString(path,filename,MaxTextExtent);
522 Load XML from configuration files to linked-list.
524 messages=NewLinkedList(0);
525 paths=GetConfigurePaths(filename,exception);
526 if (paths != (LinkedListInfo *) NULL)
528 ResetLinkedListIterator(paths);
529 element=(const char *) GetNextValueInLinkedList(paths);
530 while (element != (const char *) NULL)
532 (void) FormatMagickString(path,MaxTextExtent,"%s%s",element,filename);
533 (void) LogMagickEvent(LocaleEvent,GetMagickModule(),
534 "Searching for locale file: \"%s\"",path);
535 xml=ConfigureFileToStringInfo(path);
536 if (xml != (StringInfo *) NULL)
537 (void) AppendValueToLinkedList(messages,xml);
538 element=(const char *) GetNextValueInLinkedList(paths);
540 paths=DestroyLinkedList(paths,RelinquishMagickMemory);
542 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
547 blob=(char *) NTResourceToBlob(filename);
548 if (blob != (char *) NULL)
550 xml=StringToStringInfo(blob);
551 (void) AppendValueToLinkedList(messages,xml);
552 blob=DestroyString(blob);
556 ResetLinkedListIterator(messages);
561 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
565 % G e t L o c a l e V a l u e %
569 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
571 % GetLocaleValue() returns the message associated with the locale info.
573 % The format of the GetLocaleValue method is:
575 % const char *GetLocaleValue(const LocaleInfo *locale_info)
577 % A description of each parameter follows:
579 % o locale_info: The locale info.
582 MagickExport const char *GetLocaleValue(const LocaleInfo *locale_info)
584 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
585 assert(locale_info != (LocaleInfo *) NULL);
586 assert(locale_info->signature == MagickSignature);
587 return(locale_info->message);
591 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
595 + I n i t i a l i z e L o c a l e L i s t %
599 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
601 % InitializeLocaleList() initializes the locale list.
603 % The format of the InitializeLocaleList method is:
605 % MagickBooleanType InitializeLocaleList(ExceptionInfo *exception)
607 % A description of each parameter follows.
609 % o exception: return any errors or warnings in this structure.
612 static MagickBooleanType InitializeLocaleList(ExceptionInfo *exception)
614 if ((locale_list == (SplayTreeInfo *) NULL) &&
615 (instantiate_locale == MagickFalse))
617 if (locale_semaphore == (SemaphoreInfo *) NULL)
618 AcquireSemaphoreInfo(&locale_semaphore);
619 LockSemaphoreInfo(locale_semaphore);
620 if ((locale_list == (SplayTreeInfo *) NULL) &&
621 (instantiate_locale == MagickFalse))
629 locale=(char *) NULL;
630 p=setlocale(LC_CTYPE,(const char *) NULL);
631 if (p != (const char *) NULL)
632 locale=ConstantString(p);
633 if (locale == (char *) NULL)
634 locale=GetEnvironmentValue("LC_ALL");
635 if (locale == (char *) NULL)
636 locale=GetEnvironmentValue("LC_MESSAGES");
637 if (locale == (char *) NULL)
638 locale=GetEnvironmentValue("LC_CTYPE");
639 if (locale == (char *) NULL)
640 locale=GetEnvironmentValue("LANG");
641 if (locale == (char *) NULL)
642 locale=ConstantString("C");
643 (void) LoadLocaleLists(LocaleFilename,locale,exception);
644 locale=DestroyString(locale);
645 instantiate_locale=MagickTrue;
647 UnlockSemaphoreInfo(locale_semaphore);
649 return(locale_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse);
653 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
657 % L i s t L o c a l e I n f o %
661 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
663 % ListLocaleInfo() lists the locale info to a file.
665 % The format of the ListLocaleInfo method is:
667 % MagickBooleanType ListLocaleInfo(FILE *file,ExceptionInfo *exception)
669 % A description of each parameter follows.
671 % o file: An pointer to a FILE.
673 % o exception: return any errors or warnings in this structure.
676 MagickExport MagickBooleanType ListLocaleInfo(FILE *file,
677 ExceptionInfo *exception)
691 if (file == (const FILE *) NULL)
694 locale_info=GetLocaleInfoList("*",&number_messages,exception);
695 if (locale_info == (const LocaleInfo **) NULL)
697 path=(const char *) NULL;
698 for (i=0; i < (ssize_t) number_messages; i++)
700 if (locale_info[i]->stealth != MagickFalse)
702 if ((path == (const char *) NULL) ||
703 (LocaleCompare(path,locale_info[i]->path) != 0))
705 if (locale_info[i]->path != (char *) NULL)
706 (void) fprintf(file,"\nPath: %s\n\n",locale_info[i]->path);
707 (void) fprintf(file,"Tag/Message\n");
708 (void) fprintf(file,"-------------------------------------------------"
709 "------------------------------\n");
711 path=locale_info[i]->path;
712 (void) fprintf(file,"%s\n",locale_info[i]->tag);
713 if (locale_info[i]->message != (char *) NULL)
714 (void) fprintf(file," %s",locale_info[i]->message);
715 (void) fprintf(file,"\n");
718 locale_info=(const LocaleInfo **)
719 RelinquishMagickMemory((void *) locale_info);
724 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
728 + L o a d L o c a l e L i s t %
732 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
734 % LoadLocaleList() loads the locale configuration file which provides a mapping
735 % between locale attributes and a locale name.
737 % The format of the LoadLocaleList method is:
739 % MagickBooleanType LoadLocaleList(const char *xml,const char *filename,
740 % const size_t depth,ExceptionInfo *exception)
742 % A description of each parameter follows:
744 % o xml: The locale list in XML format.
746 % o filename: The locale list filename.
748 % o depth: depth of <include /> statements.
750 % o exception: return any errors or warnings in this structure.
754 static void ChopLocaleComponents(char *path,const size_t components)
764 p=path+strlen(path)-1;
767 for (count=0; (count < (ssize_t) components) && (p > path); p--)
773 if (count < (ssize_t) components)
777 static void *DestroyLocaleNode(void *locale_info)
782 p=(LocaleInfo *) locale_info;
783 if (p->path != (char *) NULL)
784 p->path=DestroyString(p->path);
785 if (p->tag != (char *) NULL)
786 p->tag=DestroyString(p->tag);
787 if (p->message != (char *) NULL)
788 p->message=DestroyString(p->message);
789 return(RelinquishMagickMemory(p));
792 static void LocaleFatalErrorHandler(
793 const ExceptionType magick_unused(severity),
794 const char *reason,const char *description)
796 if (reason == (char *) NULL)
798 (void) fprintf(stderr,"%s: %s",GetClientName(),reason);
799 if (description != (char *) NULL)
800 (void) fprintf(stderr," (%s)",description);
801 (void) fprintf(stderr,".\n");
802 (void) fflush(stderr);
807 static MagickBooleanType LoadLocaleList(const char *xml,const char *filename,
808 const char *locale,const size_t depth,ExceptionInfo *exception)
811 keyword[MaxTextExtent],
812 message[MaxTextExtent],
832 Read the locale configure file.
834 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
835 "Loading locale configure file \"%s\" ...",filename);
836 if (xml == (const char *) NULL)
838 if (locale_list == (SplayTreeInfo *) NULL)
840 locale_list=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL,
842 if (locale_list == (SplayTreeInfo *) NULL)
846 locale_info=(LocaleInfo *) NULL;
850 fatal_handler=SetFatalErrorHandler(LocaleFatalErrorHandler);
851 token=AcquireString(xml);
852 for (q=(char *) xml; *q != '\0'; )
857 GetMagickToken(q,&q,token);
860 (void) CopyMagickString(keyword,token,MaxTextExtent);
861 if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
866 while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
868 GetMagickToken(q,&q,token);
869 while (isspace((int) ((unsigned char) *q)) != 0)
874 if (LocaleNCompare(keyword,"<!--",4) == 0)
879 while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
881 GetMagickToken(q,&q,token);
882 while (isspace((int) ((unsigned char) *q)) != 0)
887 if (LocaleCompare(keyword,"<include") == 0)
892 while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
894 (void) CopyMagickString(keyword,token,MaxTextExtent);
895 GetMagickToken(q,&q,token);
898 GetMagickToken(q,&q,token);
899 if (LocaleCompare(keyword,"locale") == 0)
901 if (LocaleCompare(locale,token) != 0)
905 if (LocaleCompare(keyword,"file") == 0)
908 (void) ThrowMagickException(exception,GetMagickModule(),
909 ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token);
917 GetPathComponent(filename,HeadPath,path);
919 (void) ConcatenateMagickString(path,DirectorySeparator,
921 if (*token == *DirectorySeparator)
922 (void) CopyMagickString(path,token,MaxTextExtent);
924 (void) ConcatenateMagickString(path,token,MaxTextExtent);
925 xml=FileToString(path,~0,exception);
926 if (xml != (char *) NULL)
928 status=LoadLocaleList(xml,path,locale,depth+1,exception);
929 xml=(char *) RelinquishMagickMemory(xml);
936 if (LocaleCompare(keyword,"<locale") == 0)
941 while ((*token != '>') && (*q != '\0'))
943 (void) CopyMagickString(keyword,token,MaxTextExtent);
944 GetMagickToken(q,&q,token);
947 GetMagickToken(q,&q,token);
951 if (LocaleCompare(keyword,"</locale>") == 0)
953 ChopLocaleComponents(tag,1);
954 (void) ConcatenateMagickString(tag,"/",MaxTextExtent);
957 if (LocaleCompare(keyword,"<localemap>") == 0)
959 if (LocaleCompare(keyword,"</localemap>") == 0)
961 if (LocaleCompare(keyword,"<message") == 0)
966 while ((*token != '>') && (*q != '\0'))
968 (void) CopyMagickString(keyword,token,MaxTextExtent);
969 GetMagickToken(q,&q,token);
972 GetMagickToken(q,&q,token);
973 if (LocaleCompare(keyword,"name") == 0)
975 (void) ConcatenateMagickString(tag,token,MaxTextExtent);
976 (void) ConcatenateMagickString(tag,"/",MaxTextExtent);
979 for (p=(char *) q; (*q != '<') && (*q != '\0'); q++) ;
980 while (isspace((int) ((unsigned char) *p)) != 0)
983 while ((isspace((int) ((unsigned char) *q)) != 0) && (q > p))
985 (void) CopyMagickString(message,p,(size_t) (q-p+2));
986 locale_info=(LocaleInfo *) AcquireMagickMemory(sizeof(*locale_info));
987 if (locale_info == (LocaleInfo *) NULL)
988 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
989 (void) ResetMagickMemory(locale_info,0,sizeof(*locale_info));
990 locale_info->path=ConstantString(filename);
991 locale_info->tag=ConstantString(tag);
992 locale_info->message=ConstantString(message);
993 locale_info->signature=MagickSignature;
994 status=AddValueToSplayTree(locale_list,locale_info->tag,locale_info);
995 if (status == MagickFalse)
996 (void) ThrowMagickException(exception,GetMagickModule(),
997 ResourceLimitError,"MemoryAllocationFailed","`%s'",
999 (void) ConcatenateMagickString(tag,message,MaxTextExtent);
1000 (void) ConcatenateMagickString(tag,"\n",MaxTextExtent);
1004 if (LocaleCompare(keyword,"</message>") == 0)
1006 ChopLocaleComponents(tag,2);
1007 (void) ConcatenateMagickString(tag,"/",MaxTextExtent);
1010 if (*keyword == '<')
1015 if (*(keyword+1) == '?')
1017 if (*(keyword+1) == '/')
1019 ChopLocaleComponents(tag,1);
1021 (void) ConcatenateMagickString(tag,"/",MaxTextExtent);
1024 token[strlen(token)-1]='\0';
1025 (void) CopyMagickString(token,token+1,MaxTextExtent);
1026 (void) ConcatenateMagickString(tag,token,MaxTextExtent);
1027 (void) ConcatenateMagickString(tag,"/",MaxTextExtent);
1030 GetMagickToken(q,(const char **) NULL,token);
1034 token=(char *) RelinquishMagickMemory(token);
1035 (void) SetFatalErrorHandler(fatal_handler);
1040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1044 % L o a d L o c a l e L i s t s %
1048 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1050 % LoadLocaleList() loads one or more locale configuration file which
1051 % provides a mapping between locale attributes and a locale tag.
1053 % The format of the LoadLocaleLists method is:
1055 % MagickBooleanType LoadLocaleLists(const char *filename,
1056 % ExceptionInfo *exception)
1058 % A description of each parameter follows:
1060 % o filename: the font file tag.
1062 % o locale: the actual locale.
1064 % o exception: return any errors or warnings in this structure.
1067 static MagickBooleanType LoadLocaleLists(const char *filename,
1068 const char *locale,ExceptionInfo *exception)
1070 #if defined(MAGICKCORE_EMBEDDABLE_SUPPORT)
1071 return(LoadLocaleList(LocaleMap,"built-in",locale,0,exception));
1083 options=GetLocaleOptions(filename,exception);
1084 option=(const StringInfo *) GetNextValueInLinkedList(options);
1085 while (option != (const StringInfo *) NULL)
1087 status|=LoadLocaleList((const char *) GetStringInfoDatum(option),
1088 GetStringInfoPath(option),locale,0,exception);
1089 option=(const StringInfo *) GetNextValueInLinkedList(options);
1091 options=DestroyLocaleOptions(options);
1092 if ((locale_list == (SplayTreeInfo *) NULL) ||
1093 (GetNumberOfNodesInSplayTree(locale_list) == 0))
1095 options=GetLocaleOptions("english.xml",exception);
1096 option=(const StringInfo *) GetNextValueInLinkedList(options);
1097 while (option != (const StringInfo *) NULL)
1099 status|=LoadLocaleList((const char *) GetStringInfoDatum(option),
1100 GetStringInfoPath(option),locale,0,exception);
1101 option=(const StringInfo *) GetNextValueInLinkedList(options);
1103 options=DestroyLocaleOptions(options);
1105 if ((locale_list == (SplayTreeInfo *) NULL) ||
1106 (GetNumberOfNodesInSplayTree(locale_list) == 0))
1107 status|=LoadLocaleList(LocaleMap,"built-in",locale,0,exception);
1108 return(status != 0 ? MagickTrue : MagickFalse);
1113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1117 + L o c a l e C o m p o n e n t G e n e s i s %
1121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1123 % LocaleComponentGenesis() instantiates the locale component.
1125 % The format of the LocaleComponentGenesis method is:
1127 % MagickBooleanType LocaleComponentGenesis(void)
1130 MagickExport MagickBooleanType LocaleComponentGenesis(void)
1132 AcquireSemaphoreInfo(&locale_semaphore);
1137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1141 + L o c a l e C o m p o n e n t T e r m i n u s %
1145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1147 % LocaleComponentTerminus() destroys the locale component.
1149 % The format of the LocaleComponentTerminus method is:
1151 % LocaleComponentTerminus(void)
1154 MagickExport void LocaleComponentTerminus(void)
1156 if (locale_semaphore == (SemaphoreInfo *) NULL)
1157 AcquireSemaphoreInfo(&locale_semaphore);
1158 LockSemaphoreInfo(locale_semaphore);
1159 DestroyMagickLocale();
1160 instantiate_locale=MagickFalse;
1161 UnlockSemaphoreInfo(locale_semaphore);
1162 DestroySemaphoreInfo(&locale_semaphore);