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-2010 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;
92 static MagickBooleanType
93 InitializeLocaleList(ExceptionInfo *),
94 LoadLocaleLists(const char *,const char *,ExceptionInfo *);
97 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 % D e s t r o y L o c a l e O p t i o n s %
105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 % DestroyLocaleOptions() releases memory associated with an locale
110 % The format of the DestroyProfiles method is:
112 % LinkedListInfo *DestroyLocaleOptions(Image *image)
114 % A description of each parameter follows:
116 % o image: the image.
120 static void *DestroyOptions(void *message)
122 return(DestroyStringInfo((StringInfo *) message));
125 MagickExport LinkedListInfo *DestroyLocaleOptions(LinkedListInfo *messages)
127 assert(messages != (LinkedListInfo *) NULL);
128 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
129 return(DestroyLinkedList(messages,DestroyOptions));
133 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137 + G e t L o c a l e I n f o _ %
141 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
143 % GetLocaleInfo_() searches the locale list for the specified tag and if
144 % found returns attributes for that element.
146 % The format of the GetLocaleInfo method is:
148 % const LocaleInfo *GetLocaleInfo_(const char *tag,
149 % ExceptionInfo *exception)
151 % A description of each parameter follows:
153 % o tag: the locale tag.
155 % o exception: return any errors or warnings in this structure.
158 MagickExport const LocaleInfo *GetLocaleInfo_(const char *tag,
159 ExceptionInfo *exception)
161 assert(exception != (ExceptionInfo *) NULL);
162 if ((locale_list == (SplayTreeInfo *) NULL) ||
163 (instantiate_locale == MagickFalse))
164 if (InitializeLocaleList(exception) == MagickFalse)
165 return((const LocaleInfo *) NULL);
166 if ((locale_list == (SplayTreeInfo *) NULL) ||
167 (GetNumberOfNodesInSplayTree(locale_list) == 0))
168 return((const LocaleInfo *) NULL);
169 if ((tag == (const char *) NULL) || (LocaleCompare(tag,"*") == 0))
171 ResetSplayTreeIterator(locale_list);
172 return((const LocaleInfo *) GetNextValueInSplayTree(locale_list));
174 return((const LocaleInfo *) GetValueFromSplayTree(locale_list,tag));
178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 % G e t L o c a l e I n f o L i s t %
186 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188 % GetLocaleInfoList() returns any locale messages that match the
191 % The format of the GetLocaleInfoList function is:
193 % const LocaleInfo **GetLocaleInfoList(const char *pattern,
194 % unsigned long *number_messages,ExceptionInfo *exception)
196 % A description of each parameter follows:
198 % o pattern: Specifies a pointer to a text string containing a pattern.
200 % o number_messages: This integer returns the number of locale messages in
203 % o exception: return any errors or warnings in this structure.
207 #if defined(__cplusplus) || defined(c_plusplus)
211 static int LocaleInfoCompare(const void *x,const void *y)
217 p=(const LocaleInfo **) x,
218 q=(const LocaleInfo **) y;
219 if (LocaleCompare((*p)->path,(*q)->path) == 0)
220 return(LocaleCompare((*p)->tag,(*q)->tag));
221 return(LocaleCompare((*p)->path,(*q)->path));
224 #if defined(__cplusplus) || defined(c_plusplus)
228 MagickExport const LocaleInfo **GetLocaleInfoList(const char *pattern,
229 unsigned long *number_messages,ExceptionInfo *exception)
234 register const LocaleInfo
241 Allocate locale list.
243 assert(pattern != (char *) NULL);
244 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
245 assert(number_messages != (unsigned long *) NULL);
247 p=GetLocaleInfo_("*",exception);
248 if (p == (const LocaleInfo *) NULL)
249 return((const LocaleInfo **) NULL);
250 messages=(const LocaleInfo **) AcquireQuantumMemory((size_t)
251 GetNumberOfNodesInSplayTree(locale_list)+1UL,sizeof(*messages));
252 if (messages == (const LocaleInfo **) NULL)
253 return((const LocaleInfo **) NULL);
255 Generate locale list.
257 LockSemaphoreInfo(locale_semaphore);
258 ResetSplayTreeIterator(locale_list);
259 p=(const LocaleInfo *) GetNextValueInSplayTree(locale_list);
260 for (i=0; p != (const LocaleInfo *) NULL; )
262 if ((p->stealth == MagickFalse) &&
263 (GlobExpression(p->tag,pattern,MagickTrue) != MagickFalse))
265 p=(const LocaleInfo *) GetNextValueInSplayTree(locale_list);
267 UnlockSemaphoreInfo(locale_semaphore);
268 qsort((void *) messages,(size_t) i,sizeof(*messages),LocaleInfoCompare);
269 messages[i]=(LocaleInfo *) NULL;
270 *number_messages=(unsigned long) i;
275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
279 % G e t L o c a l e L i s t %
283 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
285 % GetLocaleList() returns any locale messages that match the specified
288 % The format of the GetLocaleList function is:
290 % char **GetLocaleList(const char *pattern,unsigned long *number_messages,
291 % Exceptioninfo *exception)
293 % A description of each parameter follows:
295 % o pattern: Specifies a pointer to a text string containing a pattern.
297 % o number_messages: This integer returns the number of messages in the
300 % o exception: return any errors or warnings in this structure.
304 #if defined(__cplusplus) || defined(c_plusplus)
308 static int LocaleTagCompare(const void *x,const void *y)
316 return(LocaleCompare(*p,*q));
319 #if defined(__cplusplus) || defined(c_plusplus)
323 MagickExport char **GetLocaleList(const char *pattern,
324 unsigned long *number_messages,ExceptionInfo *exception)
329 register const LocaleInfo
336 Allocate locale list.
338 assert(pattern != (char *) NULL);
339 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
340 assert(number_messages != (unsigned long *) NULL);
342 p=GetLocaleInfo_("*",exception);
343 if (p == (const LocaleInfo *) NULL)
344 return((char **) NULL);
345 messages=(char **) AcquireQuantumMemory((size_t)
346 GetNumberOfNodesInSplayTree(locale_list)+1UL,sizeof(*messages));
347 if (messages == (char **) NULL)
348 return((char **) NULL);
349 LockSemaphoreInfo(locale_semaphore);
350 p=(const LocaleInfo *) GetNextValueInSplayTree(locale_list);
351 for (i=0; p != (const LocaleInfo *) NULL; )
353 if ((p->stealth == MagickFalse) &&
354 (GlobExpression(p->tag,pattern,MagickTrue) != MagickFalse))
355 messages[i++]=ConstantString(p->tag);
356 p=(const LocaleInfo *) GetNextValueInSplayTree(locale_list);
358 UnlockSemaphoreInfo(locale_semaphore);
359 qsort((void *) messages,(size_t) i,sizeof(*messages),LocaleTagCompare);
360 messages[i]=(char *) NULL;
361 *number_messages=(unsigned long) i;
366 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
370 % G e t L o c a l e M e s s a g e %
374 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
376 % GetLocaleMessage() returns a message in the current locale that matches the
379 % The format of the GetLocaleMessage method is:
381 % const char *GetLocaleMessage(const char *tag)
383 % A description of each parameter follows:
385 % o tag: Return a message that matches this tag in the current locale.
388 MagickExport const char *GetLocaleMessage(const char *tag)
399 if ((tag == (const char *) NULL) || (*tag == '\0'))
401 exception=AcquireExceptionInfo();
402 (void) FormatMagickString(name,MaxTextExtent,"%s/",tag);
403 locale_info=GetLocaleInfo_(name,exception);
404 exception=DestroyExceptionInfo(exception);
405 if (locale_info != (const LocaleInfo *) NULL)
406 return(locale_info->message);
411 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
415 % G e t L o c a l e O p t i o n s %
419 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
421 % GetLocaleOptions() returns any Magick configuration messages associated
422 % with the specified filename.
424 % The format of the GetLocaleOptions method is:
426 % LinkedListInfo *GetLocaleOptions(const char *filename,
427 % ExceptionInfo *exception)
429 % A description of each parameter follows:
431 % o filename: the locale file tag.
433 % o exception: return any errors or warnings in this structure.
436 MagickExport LinkedListInfo *GetLocaleOptions(const char *filename,
437 ExceptionInfo *exception)
452 assert(filename != (const char *) NULL);
453 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
454 assert(exception != (ExceptionInfo *) NULL);
455 (void) CopyMagickString(path,filename,MaxTextExtent);
457 Load XML from configuration files to linked-list.
459 messages=NewLinkedList(0);
460 paths=GetConfigurePaths(filename,exception);
461 if (paths != (LinkedListInfo *) NULL)
463 ResetLinkedListIterator(paths);
464 element=(const char *) GetNextValueInLinkedList(paths);
465 while (element != (const char *) NULL)
467 (void) FormatMagickString(path,MaxTextExtent,"%s%s",element,filename);
468 (void) LogMagickEvent(LocaleEvent,GetMagickModule(),
469 "Searching for locale file: \"%s\"",path);
470 xml=ConfigureFileToStringInfo(path);
471 if (xml != (StringInfo *) NULL)
472 (void) AppendValueToLinkedList(messages,xml);
473 element=(const char *) GetNextValueInLinkedList(paths);
475 paths=DestroyLinkedList(paths,RelinquishMagickMemory);
477 #if defined(__WINDOWS__)
482 blob=(char *) NTResourceToBlob(filename);
483 if (blob != (char *) NULL)
485 xml=StringToStringInfo(blob);
486 (void) AppendValueToLinkedList(messages,xml);
487 blob=DestroyString(blob);
491 ResetLinkedListIterator(messages);
496 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
500 % G e t L o c a l e V a l u e %
504 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
506 % GetLocaleValue() returns the message associated with the locale info.
508 % The format of the GetLocaleValue method is:
510 % const char *GetLocaleValue(const LocaleInfo *locale_info)
512 % A description of each parameter follows:
514 % o locale_info: The locale info.
517 MagickExport const char *GetLocaleValue(const LocaleInfo *locale_info)
519 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
520 assert(locale_info != (LocaleInfo *) NULL);
521 assert(locale_info->signature == MagickSignature);
522 return(locale_info->message);
526 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
530 + I n i t i a l i z e L o c a l e L i s t %
534 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
536 % InitializeLocaleList() initializes the locale list.
538 % The format of the InitializeLocaleList method is:
540 % MagickBooleanType InitializeLocaleList(ExceptionInfo *exception)
542 % A description of each parameter follows.
544 % o exception: return any errors or warnings in this structure.
547 static MagickBooleanType InitializeLocaleList(ExceptionInfo *exception)
549 if ((locale_list == (SplayTreeInfo *) NULL) &&
550 (instantiate_locale == MagickFalse))
552 if (locale_semaphore == (SemaphoreInfo *) NULL)
553 AcquireSemaphoreInfo(&locale_semaphore);
554 LockSemaphoreInfo(locale_semaphore);
555 if ((locale_list == (SplayTreeInfo *) NULL) &&
556 (instantiate_locale == MagickFalse))
564 locale=(char *) NULL;
565 p=setlocale(LC_CTYPE,(const char *) NULL);
566 if (p != (const char *) NULL)
567 locale=ConstantString(p);
568 if (locale == (char *) NULL)
569 locale=GetEnvironmentValue("LC_ALL");
570 if (locale == (char *) NULL)
571 locale=GetEnvironmentValue("LC_MESSAGES");
572 if (locale == (char *) NULL)
573 locale=GetEnvironmentValue("LC_CTYPE");
574 if (locale == (char *) NULL)
575 locale=GetEnvironmentValue("LANG");
576 if (locale == (char *) NULL)
577 locale=ConstantString("C");
578 (void) LoadLocaleLists(LocaleFilename,locale,exception);
579 locale=DestroyString(locale);
580 instantiate_locale=MagickTrue;
582 UnlockSemaphoreInfo(locale_semaphore);
584 return(locale_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse);
588 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
592 % L i s t L o c a l e I n f o %
596 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
598 % ListLocaleInfo() lists the locale info to a file.
600 % The format of the ListLocaleInfo method is:
602 % MagickBooleanType ListLocaleInfo(FILE *file,ExceptionInfo *exception)
604 % A description of each parameter follows.
606 % o file: An pointer to a FILE.
608 % o exception: return any errors or warnings in this structure.
611 MagickExport MagickBooleanType ListLocaleInfo(FILE *file,
612 ExceptionInfo *exception)
626 if (file == (const FILE *) NULL)
629 locale_info=GetLocaleInfoList("*",&number_messages,exception);
630 if (locale_info == (const LocaleInfo **) NULL)
632 path=(const char *) NULL;
633 for (i=0; i < (long) number_messages; i++)
635 if (locale_info[i]->stealth != MagickFalse)
637 if ((path == (const char *) NULL) ||
638 (LocaleCompare(path,locale_info[i]->path) != 0))
640 if (locale_info[i]->path != (char *) NULL)
641 (void) fprintf(file,"\nPath: %s\n\n",locale_info[i]->path);
642 (void) fprintf(file,"Tag/Message\n");
643 (void) fprintf(file,"-------------------------------------------------"
644 "------------------------------\n");
646 path=locale_info[i]->path;
647 (void) fprintf(file,"%s\n",locale_info[i]->tag);
648 if (locale_info[i]->message != (char *) NULL)
649 (void) fprintf(file," %s",locale_info[i]->message);
650 (void) fprintf(file,"\n");
653 locale_info=(const LocaleInfo **)
654 RelinquishMagickMemory((void *) locale_info);
659 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
663 + L o a d L o c a l e L i s t %
667 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
669 % LoadLocaleList() loads the locale configuration file which provides a mapping
670 % between locale attributes and a locale name.
672 % The format of the LoadLocaleList method is:
674 % MagickBooleanType LoadLocaleList(const char *xml,const char *filename,
675 % const unsigned long depth,ExceptionInfo *exception)
677 % A description of each parameter follows:
679 % o xml: The locale list in XML format.
681 % o filename: The locale list filename.
683 % o depth: depth of <include /> statements.
685 % o exception: return any errors or warnings in this structure.
689 static void ChopLocaleComponents(char *path,const unsigned long components)
699 p=path+strlen(path)-1;
702 for (count=0; (count < (long) components) && (p > path); p--)
708 if (count < (long) components)
712 static void *DestroyLocaleNode(void *locale_info)
717 p=(LocaleInfo *) locale_info;
718 if (p->path != (char *) NULL)
719 p->path=DestroyString(p->path);
720 if (p->tag != (char *) NULL)
721 p->tag=DestroyString(p->tag);
722 if (p->message != (char *) NULL)
723 p->message=DestroyString(p->message);
724 return(RelinquishMagickMemory(p));
727 static void LocaleFatalErrorHandler(
728 const ExceptionType magick_unused(severity),
729 const char *reason,const char *description)
731 if (reason == (char *) NULL)
733 (void) fprintf(stderr,"%s: %s",GetClientName(),reason);
734 if (description != (char *) NULL)
735 (void) fprintf(stderr," (%s)",description);
736 (void) fprintf(stderr,".\n");
737 (void) fflush(stderr);
742 static MagickBooleanType LoadLocaleList(const char *xml,const char *filename,
743 const char *locale,const unsigned long depth,ExceptionInfo *exception)
746 keyword[MaxTextExtent],
747 message[MaxTextExtent],
767 Read the locale configure file.
769 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
770 "Loading locale configure file \"%s\" ...",filename);
771 if (xml == (const char *) NULL)
773 if (locale_list == (SplayTreeInfo *) NULL)
775 locale_list=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL,
777 if (locale_list == (SplayTreeInfo *) NULL)
781 locale_info=(LocaleInfo *) NULL;
785 fatal_handler=SetFatalErrorHandler(LocaleFatalErrorHandler);
786 token=AcquireString(xml);
787 for (q=(char *) xml; *q != '\0'; )
792 GetMagickToken(q,&q,token);
795 (void) CopyMagickString(keyword,token,MaxTextExtent);
796 if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
801 while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
803 GetMagickToken(q,&q,token);
804 while (isspace((int) ((unsigned char) *q)) != 0)
809 if (LocaleNCompare(keyword,"<!--",4) == 0)
814 while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
816 GetMagickToken(q,&q,token);
817 while (isspace((int) ((unsigned char) *q)) != 0)
822 if (LocaleCompare(keyword,"<include") == 0)
827 while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
829 (void) CopyMagickString(keyword,token,MaxTextExtent);
830 GetMagickToken(q,&q,token);
833 GetMagickToken(q,&q,token);
834 if (LocaleCompare(keyword,"locale") == 0)
836 if (LocaleCompare(locale,token) != 0)
840 if (LocaleCompare(keyword,"file") == 0)
843 (void) ThrowMagickException(exception,GetMagickModule(),
844 ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token);
852 GetPathComponent(filename,HeadPath,path);
854 (void) ConcatenateMagickString(path,DirectorySeparator,
856 if (*token == *DirectorySeparator)
857 (void) CopyMagickString(path,token,MaxTextExtent);
859 (void) ConcatenateMagickString(path,token,MaxTextExtent);
860 xml=FileToString(path,~0,exception);
861 if (xml != (char *) NULL)
863 status=LoadLocaleList(xml,path,locale,depth+1,exception);
864 xml=(char *) RelinquishMagickMemory(xml);
871 if (LocaleCompare(keyword,"<locale") == 0)
876 while ((*token != '>') && (*q != '\0'))
878 (void) CopyMagickString(keyword,token,MaxTextExtent);
879 GetMagickToken(q,&q,token);
882 GetMagickToken(q,&q,token);
886 if (LocaleCompare(keyword,"</locale>") == 0)
888 ChopLocaleComponents(tag,1);
889 (void) ConcatenateMagickString(tag,"/",MaxTextExtent);
892 if (LocaleCompare(keyword,"<localemap>") == 0)
894 if (LocaleCompare(keyword,"</localemap>") == 0)
896 if (LocaleCompare(keyword,"<message") == 0)
901 while ((*token != '>') && (*q != '\0'))
903 (void) CopyMagickString(keyword,token,MaxTextExtent);
904 GetMagickToken(q,&q,token);
907 GetMagickToken(q,&q,token);
908 if (LocaleCompare(keyword,"name") == 0)
910 (void) ConcatenateMagickString(tag,token,MaxTextExtent);
911 (void) ConcatenateMagickString(tag,"/",MaxTextExtent);
914 for (p=(char *) q; (*q != '<') && (*q != '\0'); q++) ;
915 while (isspace((int) ((unsigned char) *p)) != 0)
918 while ((isspace((int) ((unsigned char) *q)) != 0) && (q > p))
920 (void) CopyMagickString(message,p,(size_t) (q-p+2));
921 locale_info=(LocaleInfo *) AcquireAlignedMemory(1,sizeof(*locale_info));
922 if (locale_info == (LocaleInfo *) NULL)
923 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
924 (void) ResetMagickMemory(locale_info,0,sizeof(*locale_info));
925 locale_info->path=ConstantString(filename);
926 locale_info->tag=ConstantString(tag);
927 locale_info->message=ConstantString(message);
928 locale_info->signature=MagickSignature;
929 status=AddValueToSplayTree(locale_list,locale_info->tag,locale_info);
930 if (status == MagickFalse)
931 (void) ThrowMagickException(exception,GetMagickModule(),
932 ResourceLimitError,"MemoryAllocationFailed","`%s'",
934 (void) ConcatenateMagickString(tag,message,MaxTextExtent);
935 (void) ConcatenateMagickString(tag,"\n",MaxTextExtent);
939 if (LocaleCompare(keyword,"</message>") == 0)
941 ChopLocaleComponents(tag,2);
942 (void) ConcatenateMagickString(tag,"/",MaxTextExtent);
950 if (*(keyword+1) == '?')
952 if (*(keyword+1) == '/')
954 ChopLocaleComponents(tag,1);
956 (void) ConcatenateMagickString(tag,"/",MaxTextExtent);
959 token[strlen(token)-1]='\0';
960 (void) CopyMagickString(token,token+1,MaxTextExtent);
961 (void) ConcatenateMagickString(tag,token,MaxTextExtent);
962 (void) ConcatenateMagickString(tag,"/",MaxTextExtent);
965 GetMagickToken(q,(const char **) NULL,token);
969 token=(char *) RelinquishMagickMemory(token);
970 (void) SetFatalErrorHandler(fatal_handler);
975 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
979 % L o a d L o c a l e L i s t s %
983 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
985 % LoadLocaleList() loads one or more locale configuration file which
986 % provides a mapping between locale attributes and a locale tag.
988 % The format of the LoadLocaleLists method is:
990 % MagickBooleanType LoadLocaleLists(const char *filename,
991 % ExceptionInfo *exception)
993 % A description of each parameter follows:
995 % o filename: the font file tag.
997 % o locale: the actual locale.
999 % o exception: return any errors or warnings in this structure.
1002 static MagickBooleanType LoadLocaleLists(const char *filename,
1003 const char *locale,ExceptionInfo *exception)
1005 #if defined(MAGICKCORE_EMBEDDABLE_SUPPORT)
1006 return(LoadLocaleList(LocaleMap,"built-in",locale,0,exception));
1018 options=GetLocaleOptions(filename,exception);
1019 option=(const StringInfo *) GetNextValueInLinkedList(options);
1020 while (option != (const StringInfo *) NULL)
1022 status|=LoadLocaleList((const char *) GetStringInfoDatum(option),
1023 GetStringInfoPath(option),locale,0,exception);
1024 option=(const StringInfo *) GetNextValueInLinkedList(options);
1026 options=DestroyLocaleOptions(options);
1027 if ((locale_list == (SplayTreeInfo *) NULL) ||
1028 (GetNumberOfNodesInSplayTree(locale_list) == 0))
1030 options=GetLocaleOptions("english.xml",exception);
1031 option=(const StringInfo *) GetNextValueInLinkedList(options);
1032 while (option != (const StringInfo *) NULL)
1034 status|=LoadLocaleList((const char *) GetStringInfoDatum(option),
1035 GetStringInfoPath(option),locale,0,exception);
1036 option=(const StringInfo *) GetNextValueInLinkedList(options);
1038 options=DestroyLocaleOptions(options);
1040 if ((locale_list == (SplayTreeInfo *) NULL) ||
1041 (GetNumberOfNodesInSplayTree(locale_list) == 0))
1042 status|=LoadLocaleList(LocaleMap,"built-in",locale,0,exception);
1043 return(status != 0 ? MagickTrue : MagickFalse);
1048 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1052 + L o c a l e C o m p o n e n t G e n e s i s %
1056 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1058 % LocaleComponentGenesis() instantiates the locale component.
1060 % The format of the LocaleComponentGenesis method is:
1062 % MagickBooleanType LocaleComponentGenesis(void)
1065 MagickExport MagickBooleanType LocaleComponentGenesis(void)
1067 AcquireSemaphoreInfo(&locale_semaphore);
1072 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1076 + L o c a l e C o m p o n e n t T e r m i n u s %
1080 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1082 % LocaleComponentTerminus() destroys the locale component.
1084 % The format of the LocaleComponentTerminus method is:
1086 % LocaleComponentTerminus(void)
1089 MagickExport void LocaleComponentTerminus(void)
1091 if (locale_semaphore == (SemaphoreInfo *) NULL)
1092 AcquireSemaphoreInfo(&locale_semaphore);
1093 LockSemaphoreInfo(locale_semaphore);
1094 if (locale_list != (SplayTreeInfo *) NULL)
1095 locale_list=DestroySplayTree(locale_list);
1096 instantiate_locale=MagickFalse;
1097 UnlockSemaphoreInfo(locale_semaphore);
1098 DestroySemaphoreInfo(&locale_semaphore);