2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % CCCC OOO N N FFFFF IIIII GGGG U U RRRR EEEEE %
7 % C O O NN N F I G U U R R E %
8 % C O O N N N FFF I G GG U U RRRR EEE %
9 % C O O N NN F I G G U U R R E %
10 % CCCC OOO N N F IIIII GGG UUU R R EEEEE %
13 % MagickCore Image Configure Methods %
20 % Copyright 1999-2009 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/log.h"
50 #include "magick/memory_.h"
51 #include "magick/semaphore.h"
52 #include "magick/string_.h"
53 #include "magick/token.h"
54 #include "magick/utility.h"
55 #include "magick/xml-tree.h"
60 #define ConfigureFilename "configure.xml"
66 *ConfigureMap = (char *)
67 "<?xml version=\"1.0\"?>"
69 " <configure stealth=\"True\" />"
73 *configure_list = (LinkedListInfo *) NULL;
76 *configure_semaphore = (SemaphoreInfo *) NULL;
78 static volatile MagickBooleanType
79 instantiate_configure = MagickFalse;
84 static MagickBooleanType
85 InitializeConfigureList(ExceptionInfo *),
86 LoadConfigureLists(const char *,ExceptionInfo *);
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93 + D e s t r o y C o n f i g u r e F a c i l i t y %
97 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99 % DestroyConfigureFacility() destroys the configure facility.
101 % The format of the DestroyConfigureFacility method is:
103 % DestroyConfigureFacility(void)
107 static void *DestroyConfigureElement(void *configure_info)
109 register ConfigureInfo
112 p=(ConfigureInfo *) configure_info;
113 if (p->path != (char *) NULL)
114 p->path=DestroyString(p->path);
115 if (p->name != (char *) NULL)
116 p->name=DestroyString(p->name);
117 if (p->value != (char *) NULL)
118 p->value=DestroyString(p->value);
119 p=(ConfigureInfo *) RelinquishMagickMemory(p);
120 return((void *) NULL);
123 MagickExport void DestroyConfigureFacility(void)
125 AcquireSemaphoreInfo(&configure_semaphore);
126 if (configure_list != (LinkedListInfo *) NULL)
127 configure_list=DestroyLinkedList(configure_list,DestroyConfigureElement);
128 configure_list=(LinkedListInfo *) NULL;
129 instantiate_configure=MagickFalse;
130 RelinquishSemaphoreInfo(configure_semaphore);
131 DestroySemaphoreInfo(&configure_semaphore);
135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 % D e s t r o y C o n f i g u r e O p t i o n s %
143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145 % DestroyConfigureOptions() releases memory associated with an configure
148 % The format of the DestroyProfiles method is:
150 % LinkedListInfo *DestroyConfigureOptions(Image *image)
152 % A description of each parameter follows:
154 % o image: the image.
158 static void *DestroyOptions(void *option)
160 return(DestroyStringInfo((StringInfo *) option));
163 MagickExport LinkedListInfo *DestroyConfigureOptions(LinkedListInfo *options)
165 assert(options != (LinkedListInfo *) NULL);
166 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
167 return(DestroyLinkedList(options,DestroyOptions));
171 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
175 + G e t C o n f i g u r e I n f o %
179 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 % GetConfigureInfo() searches the configure list for the specified name and if
182 % found returns attributes for that element.
184 % The format of the GetConfigureInfo method is:
186 % const ConfigureInfo *GetConfigureInfo(const char *name,
187 % ExceptionInfo *exception)
189 % A description of each parameter follows:
191 % o configure_info: GetConfigureInfo() searches the configure list for the
192 % specified name and if found returns attributes for that element.
194 % o name: the configure name.
196 % o exception: return any errors or warnings in this structure.
199 MagickExport const ConfigureInfo *GetConfigureInfo(const char *name,
200 ExceptionInfo *exception)
202 register const ConfigureInfo
205 assert(exception != (ExceptionInfo *) NULL);
206 if ((configure_list == (LinkedListInfo *) NULL) ||
207 (instantiate_configure == MagickFalse))
208 if (InitializeConfigureList(exception) == MagickFalse)
209 return((const ConfigureInfo *) NULL);
210 if ((configure_list == (LinkedListInfo *) NULL) ||
211 (IsLinkedListEmpty(configure_list) != MagickFalse))
212 return((const ConfigureInfo *) NULL);
213 if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
214 return((const ConfigureInfo *) GetValueFromLinkedList(configure_list,0));
216 Search for configure tag.
218 AcquireSemaphoreInfo(&configure_semaphore);
219 ResetLinkedListIterator(configure_list);
220 p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list);
221 while (p != (const ConfigureInfo *) NULL)
223 if (LocaleCompare(name,p->name) == 0)
225 p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list);
227 if (p != (ConfigureInfo *) NULL)
228 (void) InsertValueInLinkedList(configure_list,0,
229 RemoveElementByValueFromLinkedList(configure_list,p));
230 RelinquishSemaphoreInfo(configure_semaphore);
235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239 % G e t C o n f i g u r e I n f o L i s t %
243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
245 % GetConfigureInfoList() returns any configure options that match the
248 % The format of the GetConfigureInfoList function is:
250 % const ConfigureInfo **GetConfigureInfoList(const char *pattern,
251 % unsigned long *number_options,ExceptionInfo *exception)
253 % A description of each parameter follows:
255 % o pattern: Specifies a pointer to a text string containing a pattern.
257 % o number_options: This integer returns the number of configure options in
260 % o exception: return any errors or warnings in this structure.
264 #if defined(__cplusplus) || defined(c_plusplus)
268 static int ConfigureInfoCompare(const void *x,const void *y)
274 p=(const ConfigureInfo **) x,
275 q=(const ConfigureInfo **) y;
276 if (LocaleCompare((*p)->path,(*q)->path) == 0)
277 return(LocaleCompare((*p)->name,(*q)->name));
278 return(LocaleCompare((*p)->path,(*q)->path));
281 #if defined(__cplusplus) || defined(c_plusplus)
285 MagickExport const ConfigureInfo **GetConfigureInfoList(const char *pattern,
286 unsigned long *number_options,ExceptionInfo *exception)
291 register const ConfigureInfo
298 Allocate configure list.
300 assert(pattern != (char *) NULL);
301 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
302 assert(number_options != (unsigned long *) NULL);
304 p=GetConfigureInfo("*",exception);
305 if (p == (const ConfigureInfo *) NULL)
306 return((const ConfigureInfo **) NULL);
307 options=(const ConfigureInfo **) AcquireQuantumMemory((size_t)
308 GetNumberOfElementsInLinkedList(configure_list)+1UL,sizeof(*options));
309 if (options == (const ConfigureInfo **) NULL)
310 return((const ConfigureInfo **) NULL);
312 Generate configure list.
314 AcquireSemaphoreInfo(&configure_semaphore);
315 ResetLinkedListIterator(configure_list);
316 p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list);
317 for (i=0; p != (const ConfigureInfo *) NULL; )
319 if ((p->stealth == MagickFalse) &&
320 (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
322 p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list);
324 RelinquishSemaphoreInfo(configure_semaphore);
325 qsort((void *) options,(size_t) i,sizeof(*options),ConfigureInfoCompare);
326 options[i]=(ConfigureInfo *) NULL;
327 *number_options=(unsigned long) i;
332 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
336 % G e t C o n f i g u r e L i s t %
340 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
342 % GetConfigureList() returns any configure options that match the specified
345 % The format of the GetConfigureList function is:
347 % char **GetConfigureList(const char *pattern,
348 % unsigned long *number_options,ExceptionInfo *exception)
350 % A description of each parameter follows:
352 % o pattern: Specifies a pointer to a text string containing a pattern.
354 % o number_options: This integer returns the number of options in the list.
356 % o exception: return any errors or warnings in this structure.
360 #if defined(__cplusplus) || defined(c_plusplus)
364 static int ConfigureCompare(const void *x,const void *y)
372 return(LocaleCompare(*p,*q));
375 #if defined(__cplusplus) || defined(c_plusplus)
379 MagickExport char **GetConfigureList(const char *pattern,
380 unsigned long *number_options,ExceptionInfo *exception)
385 register const ConfigureInfo
392 Allocate configure list.
394 assert(pattern != (char *) NULL);
395 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
396 assert(number_options != (unsigned long *) NULL);
398 p=GetConfigureInfo("*",exception);
399 if (p == (const ConfigureInfo *) NULL)
400 return((char **) NULL);
401 AcquireSemaphoreInfo(&configure_semaphore);
402 RelinquishSemaphoreInfo(configure_semaphore);
403 options=(char **) AcquireQuantumMemory((size_t)
404 GetNumberOfElementsInLinkedList(configure_list)+1UL,sizeof(*options));
405 if (options == (char **) NULL)
406 return((char **) NULL);
407 AcquireSemaphoreInfo(&configure_semaphore);
408 ResetLinkedListIterator(configure_list);
409 p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list);
410 for (i=0; p != (const ConfigureInfo *) NULL; )
412 if ((p->stealth == MagickFalse) &&
413 (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
414 options[i++]=ConstantString(p->name);
415 p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list);
417 RelinquishSemaphoreInfo(configure_semaphore);
418 qsort((void *) options,(size_t) i,sizeof(*options),ConfigureCompare);
419 options[i]=(char *) NULL;
420 *number_options=(unsigned long) i;
425 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
429 % G e t C o n f i g u r e O p t i o n %
433 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
435 % GetConfigureOption() returns the value associated with the configure option.
437 % The format of the GetConfigureOption method is:
439 % char *GetConfigureOption(const char *option)
441 % A description of each parameter follows:
443 % o configure_info: The configure info.
446 MagickExport char *GetConfigureOption(const char *option)
457 assert(option != (const char *) NULL);
458 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",option);
459 exception=AcquireExceptionInfo();
460 configure_info=GetConfigureInfo(option,exception);
461 exception=DestroyExceptionInfo(exception);
462 if (configure_info == (ConfigureInfo *) NULL)
463 return((char *) NULL);
464 value=GetConfigureValue(configure_info);
465 if ((value == (const char *) NULL) || (*value == '\0'))
466 return((char *) NULL);
467 return(ConstantString(value));
471 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
475 % G e t C o n f i g u r e O p t i o n s %
479 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
481 % GetConfigureOptions() returns any Magick configuration options associated
482 % with the specified filename.
484 % The format of the GetConfigureOptions method is:
486 % LinkedListInfo *GetConfigureOptions(const char *filename,
487 % ExceptionInfo *exception)
489 % A description of each parameter follows:
491 % o filename: the configure file name.
493 % o exception: return any errors or warnings in this structure.
496 MagickExport LinkedListInfo *GetConfigureOptions(const char *filename,
497 ExceptionInfo *exception)
512 assert(filename != (const char *) NULL);
513 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
514 assert(exception != (ExceptionInfo *) NULL);
515 (void) CopyMagickString(path,filename,MaxTextExtent);
517 Load XML from configuration files to linked-list.
519 options=NewLinkedList(0);
520 paths=GetConfigurePaths(filename,exception);
521 if (paths != (LinkedListInfo *) NULL)
523 ResetLinkedListIterator(paths);
524 element=(const char *) GetNextValueInLinkedList(paths);
525 while (element != (const char *) NULL)
527 (void) FormatMagickString(path,MaxTextExtent,"%s%s",element,filename);
528 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
529 "Searching for configure file: \"%s\"",path);
530 xml=ConfigureFileToStringInfo(path);
531 if (xml != (StringInfo *) NULL)
532 (void) AppendValueToLinkedList(options,xml);
533 element=(const char *) GetNextValueInLinkedList(paths);
535 paths=DestroyLinkedList(paths,RelinquishMagickMemory);
537 #if defined(__WINDOWS__)
542 blob=(char *) NTResourceToBlob(filename);
543 if (blob != (char *) NULL)
545 xml=StringToStringInfo(blob);
546 SetStringInfoPath(xml,filename);
547 (void) AppendValueToLinkedList(options,xml);
548 blob=DestroyString(blob);
552 if (GetNumberOfElementsInLinkedList(options) == 0)
553 (void) ThrowMagickException(exception,GetMagickModule(),ConfigureWarning,
554 "UnableToOpenConfigureFile","`%s'",filename);
555 ResetLinkedListIterator(options);
560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
564 % G e t C o n f i g u r e P a t h s %
568 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
570 % GetConfigurePaths() returns any Magick configuration paths associated
571 % with the specified filename.
573 % The format of the GetConfigurePaths method is:
575 % LinkedListInfo *GetConfigurePaths(const char *filename,
576 % ExceptionInfo *exception)
578 % A description of each parameter follows:
580 % o filename: the configure file name.
582 % o exception: return any errors or warnings in this structure.
585 MagickExport LinkedListInfo *GetConfigurePaths(const char *filename,
586 ExceptionInfo *exception)
594 assert(filename != (const char *) NULL);
595 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
596 assert(exception != (ExceptionInfo *) NULL);
597 (void) CopyMagickString(path,filename,MaxTextExtent);
598 paths=NewLinkedList(0);
604 Search $MAGICK_CONFIGURE_PATH.
606 configure_path=GetEnvironmentValue("MAGICK_CONFIGURE_PATH");
607 if (configure_path != (char *) NULL)
613 for (p=configure_path-1; p != (char *) NULL; )
615 (void) CopyMagickString(path,p+1,MaxTextExtent);
616 q=strchr(path,DirectoryListSeparator);
617 if (q != (char *) NULL)
619 q=path+strlen(path)-1;
620 if ((q >= path) && (*q != *DirectorySeparator))
621 (void) ConcatenateMagickString(path,DirectorySeparator,
623 (void) AppendValueToLinkedList(paths,ConstantString(path));
624 p=strchr(p+1,DirectoryListSeparator);
626 configure_path=DestroyString(configure_path);
629 #if defined(MAGICKCORE_INSTALLED_SUPPORT)
630 #if defined(MAGICKCORE_SHARE_CONFIGURE_PATH)
631 (void) AppendValueToLinkedList(paths,ConstantString(
632 MAGICKCORE_SHARE_CONFIGURE_PATH));
634 #if defined(MAGICKCORE_CONFIGURE_PATH)
635 (void) AppendValueToLinkedList(paths,ConstantString(
636 MAGICKCORE_CONFIGURE_PATH));
638 #if defined(MAGICKCORE_DOCUMENTATION_PATH)
639 (void) AppendValueToLinkedList(paths,ConstantString(
640 MAGICKCORE_DOCUMENTATION_PATH));
642 #if defined(MAGICKCORE_SHARE_PATH)
643 (void) AppendValueToLinkedList(paths,ConstantString(MAGICKCORE_SHARE_PATH));
645 #if defined(__WINDOWS__) && !(defined(MAGICKCORE_CONFIGURE_PATH) || defined(MAGICKCORE_SHARE_CONFIGURE_PATH))
654 Locate file via registry key.
656 registry_key="ConfigurePath";
657 key_value=NTRegistryKeyLookup(registry_key);
658 if (key_value != (unsigned char *) NULL)
660 (void) FormatMagickString(path,MaxTextExtent,"%s%s",(char *) key_value,
662 (void) AppendValueToLinkedList(paths,ConstantString(path));
663 key_value=(unsigned char *) RelinquishMagickMemory(key_value);
673 Search under MAGICK_HOME.
675 home=GetEnvironmentValue("MAGICK_HOME");
676 if (home != (char *) NULL)
678 #if !defined(MAGICKCORE_POSIX_SUPPORT)
679 (void) FormatMagickString(path,MaxTextExtent,"%s%s",home,
681 (void) AppendValueToLinkedList(paths,ConstantString(path));
683 (void) FormatMagickString(path,MaxTextExtent,"%s/lib/%s/",home,
684 MAGICKCORE_CONFIGURE_RELATIVE_PATH);
685 (void) AppendValueToLinkedList(paths,ConstantString(path));
686 (void) FormatMagickString(path,MaxTextExtent,"%s/share/%s/",home,
687 MAGICKCORE_SHARE_CONFIGURE_RELATIVE_PATH);
688 (void) AppendValueToLinkedList(paths,ConstantString(path));
690 home=DestroyString(home);
693 if (*GetClientPath() != '\0')
695 #if !defined(MAGICKCORE_POSIX_SUPPORT)
696 (void) FormatMagickString(path,MaxTextExtent,"%s%s",GetClientPath(),
698 (void) AppendValueToLinkedList(paths,ConstantString(path));
701 prefix[MaxTextExtent];
704 Search based on executable directory if directory is known.
706 (void) CopyMagickString(prefix,GetClientPath(),MaxTextExtent);
707 ChopPathComponents(prefix,1);
708 (void) FormatMagickString(path,MaxTextExtent,"%s/share/%s/",prefix,
709 MAGICKCORE_SHARE_CONFIGURE_RELATIVE_PATH);
710 (void) AppendValueToLinkedList(paths,ConstantString(path));
711 (void) FormatMagickString(path,MaxTextExtent,"%s/lib/%s/",prefix,
712 MAGICKCORE_CONFIGURE_RELATIVE_PATH);
713 (void) AppendValueToLinkedList(paths,ConstantString(path));
721 home=GetEnvironmentValue("HOME");
722 if (home == (char *) NULL)
723 home=GetEnvironmentValue("USERPROFILE");
724 if (home != (char *) NULL)
727 Search $HOME/.magick.
729 (void) FormatMagickString(path,MaxTextExtent,"%s%s.magick%s",home,
730 DirectorySeparator,DirectorySeparator);
731 (void) AppendValueToLinkedList(paths,ConstantString(path));
732 home=DestroyString(home);
735 #if defined(__WINDOWS__)
738 module_path[MaxTextExtent];
740 if ((NTGetModulePath("CORE_RL_magick_.dll",module_path) != MagickFalse) ||
741 (NTGetModulePath("CORE_DB_magick_.dll",module_path) != MagickFalse))
749 (void) FormatMagickString(path,MaxTextExtent,"%s%s",module_path,
751 element=(char *) RemoveElementByValueFromLinkedList(paths,path);
752 if (element != (char *) NULL)
753 element=DestroyString(element);
754 (void) AppendValueToLinkedList(paths,ConstantString(path));
756 if (NTGetModulePath("Magick.dll",module_path) != MagickFalse)
759 Search PerlMagick module path.
761 (void) FormatMagickString(path,MaxTextExtent,"%s%s",module_path,
763 (void) AppendValueToLinkedList(paths,ConstantString(path));
764 (void) FormatMagickString(path,MaxTextExtent,"%s%s",module_path,
765 "\\inc\\lib\\auto\\Image\\Magick\\");
766 (void) AppendValueToLinkedList(paths,ConstantString(path));
771 Search current directory.
773 (void) AppendValueToLinkedList(paths,ConstantString(""));
778 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
782 % G e t C o n f i g u r e V a l u e %
786 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
788 % GetConfigureValue() returns the value associated with the configure info.
790 % The format of the GetConfigureValue method is:
792 % const char *GetConfigureValue(const ConfigureInfo *configure_info)
794 % A description of each parameter follows:
796 % o configure_info: The configure info.
799 MagickExport const char *GetConfigureValue(const ConfigureInfo *configure_info)
801 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
802 assert(configure_info != (ConfigureInfo *) NULL);
803 assert(configure_info->signature == MagickSignature);
804 return(configure_info->value);
808 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
812 + I n i t i a l i z e C o n f i g u r e L i s t %
816 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
818 % InitializeConfigureList() initializes the configure list.
820 % The format of the InitializeConfigureList method is:
822 % MagickBooleanType InitializeConfigureList(ExceptionInfo *exception)
824 % A description of each parameter follows.
826 % o exception: return any errors or warnings in this structure.
829 static MagickBooleanType InitializeConfigureList(ExceptionInfo *exception)
831 if ((configure_list == (LinkedListInfo *) NULL) &&
832 (instantiate_configure == MagickFalse))
834 AcquireSemaphoreInfo(&configure_semaphore);
835 if ((configure_list == (LinkedListInfo *) NULL) &&
836 (instantiate_configure == MagickFalse))
838 (void) LoadConfigureLists(ConfigureFilename,exception);
839 instantiate_configure=MagickTrue;
841 RelinquishSemaphoreInfo(configure_semaphore);
843 return(configure_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
847 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
851 + I n s t a n t i a t e C o n f i g u r e F a c i l i t y %
855 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
857 % InstantiateConfigureFacility() instantiates the configure facility.
859 % The format of the InstantiateConfigureFacility method is:
861 % MagickBooleanType InstantiateConfigureFacility(void)
864 MagickExport MagickBooleanType InstantiateConfigureFacility(void)
866 AcquireSemaphoreInfo(&configure_semaphore);
867 RelinquishSemaphoreInfo(configure_semaphore);
872 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
876 % L i s t C o n f i g u r e I n f o %
880 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
882 % ListConfigureInfo() lists the configure info to a file.
884 % The format of the ListConfigureInfo method is:
886 % MagickBooleanType ListConfigureInfo(FILE *file,ExceptionInfo *exception)
888 % A description of each parameter follows.
890 % o file: An pointer to a FILE.
892 % o exception: return any errors or warnings in this structure.
895 MagickExport MagickBooleanType ListConfigureInfo(FILE *file,
896 ExceptionInfo *exception)
915 if (file == (const FILE *) NULL)
917 configure_info=GetConfigureInfoList("*",&number_options,exception);
918 if (configure_info == (const ConfigureInfo **) NULL)
920 path=(const char *) NULL;
921 for (i=0; i < (long) number_options; i++)
923 if (configure_info[i]->stealth != MagickFalse)
925 if ((path == (const char *) NULL) ||
926 (LocaleCompare(path,configure_info[i]->path) != 0))
928 if (configure_info[i]->path != (char *) NULL)
929 (void) fprintf(file,"\nPath: %s\n\n",configure_info[i]->path);
930 (void) fprintf(file,"Name Value\n");
931 (void) fprintf(file,"-------------------------------------------------"
932 "------------------------------\n");
934 path=configure_info[i]->path;
936 if (configure_info[i]->name != (char *) NULL)
937 name=configure_info[i]->name;
938 (void) fprintf(file,"%s",name);
939 for (j=(long) strlen(name); j <= 12; j++)
940 (void) fprintf(file," ");
941 (void) fprintf(file," ");
943 if (configure_info[i]->value != (char *) NULL)
944 value=configure_info[i]->value;
945 (void) fprintf(file,"%s",value);
946 (void) fprintf(file,"\n");
949 configure_info=(const ConfigureInfo **)
950 RelinquishMagickMemory((void *) configure_info);
955 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
959 + L o a d C o n f i g u r e L i s t %
963 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
965 % LoadConfigureList() loads the configure configuration file which provides a
966 % mapping between configure attributes and a configure name.
968 % The format of the LoadConfigureList method is:
970 % MagickBooleanType LoadConfigureList(const char *xml,const char *filename,
971 % const unsigned long depth,ExceptionInfo *exception)
973 % A description of each parameter follows:
975 % o xml: The configure list in XML format.
977 % o filename: The configure list filename.
979 % o depth: depth of <include /> statements.
981 % o exception: return any errors or warnings in this structure.
984 static MagickBooleanType LoadConfigureList(const char *xml,const char *filename,
985 const unsigned long depth,ExceptionInfo *exception)
988 keyword[MaxTextExtent],
1001 Load the configure map file.
1003 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1004 "Loading configure file \"%s\" ...",filename);
1005 if (configure_list == (LinkedListInfo *) NULL)
1007 configure_list=NewLinkedList(0);
1008 if (configure_list == (LinkedListInfo *) NULL)
1010 ThrowFileException(exception,ResourceLimitError,
1011 "MemoryAllocationFailed",filename);
1012 return(MagickFalse);
1016 configure_info=(ConfigureInfo *) NULL;
1017 if (xml == (char *) NULL)
1018 token=AcquireString(ConfigureMap);
1020 token=AcquireString((char *) xml);
1021 for (q=(char *) xml; *q != '\0'; )
1026 GetMagickToken(q,&q,token);
1029 (void) CopyMagickString(keyword,token,MaxTextExtent);
1030 if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
1035 while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
1036 GetMagickToken(q,&q,token);
1039 if (LocaleNCompare(keyword,"<!--",4) == 0)
1044 while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
1045 GetMagickToken(q,&q,token);
1048 if (LocaleCompare(keyword,"<include") == 0)
1053 while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
1055 (void) CopyMagickString(keyword,token,MaxTextExtent);
1056 GetMagickToken(q,&q,token);
1059 GetMagickToken(q,&q,token);
1060 if (LocaleCompare(keyword,"file") == 0)
1063 (void) ThrowMagickException(exception,GetMagickModule(),
1064 ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token);
1068 path[MaxTextExtent],
1071 GetPathComponent(filename,HeadPath,path);
1073 (void) ConcatenateMagickString(path,DirectorySeparator,
1075 if (*token == *DirectorySeparator)
1076 (void) CopyMagickString(path,token,MaxTextExtent);
1078 (void) ConcatenateMagickString(path,token,MaxTextExtent);
1079 xml=FileToString(path,~0,exception);
1080 if (xml != (char *) NULL)
1082 status=LoadConfigureList(xml,path,depth+1,exception);
1083 xml=(char *) RelinquishMagickMemory(xml);
1090 if (LocaleCompare(keyword,"<configure") == 0)
1095 configure_info=(ConfigureInfo *) AcquireMagickMemory(
1096 sizeof(*configure_info));
1097 if (configure_info == (ConfigureInfo *) NULL)
1098 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
1099 (void) ResetMagickMemory(configure_info,0,sizeof(*configure_info));
1100 configure_info->path=ConstantString(filename);
1101 configure_info->signature=MagickSignature;
1104 if (configure_info == (ConfigureInfo *) NULL)
1106 if (LocaleCompare(keyword,"/>") == 0)
1108 status=AppendValueToLinkedList(configure_list,configure_info);
1109 if (status == MagickFalse)
1110 (void) ThrowMagickException(exception,GetMagickModule(),
1111 ResourceLimitError,"MemoryAllocationFailed","`%s'",
1112 configure_info->name);
1113 configure_info=(ConfigureInfo *) NULL;
1116 Parse configure element.
1118 GetMagickToken(q,(const char **) NULL,token);
1121 GetMagickToken(q,&q,token);
1122 GetMagickToken(q,&q,token);
1128 if (LocaleCompare((char *) keyword,"name") == 0)
1130 configure_info->name=ConstantString(token);
1138 if (LocaleCompare((char *) keyword,"stealth") == 0)
1140 configure_info->stealth=IsMagickTrue(token);
1148 if (LocaleCompare((char *) keyword,"value") == 0)
1150 configure_info->value=ConstantString(token);
1159 token=(char *) RelinquishMagickMemory(token);
1164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1168 % L o a d C o n f i g u r e L i s t s %
1172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1174 % LoadConfigureList() loads one or more configure configuration files which
1175 % provides a mapping between configure attributes and a configure name.
1177 % The format of the LoadConfigureLists method is:
1179 % MagickBooleanType LoadConfigureLists(const char *filename,
1180 % ExceptionInfo *exception)
1182 % A description of each parameter follows:
1184 % o filename: the font file name.
1186 % o exception: return any errors or warnings in this structure.
1189 static MagickBooleanType LoadConfigureLists(const char *filename,
1190 ExceptionInfo *exception)
1192 #if defined(MAGICKCORE_EMBEDDABLE_SUPPORT)
1193 return(LoadConfigureList(ConfigureMap,"built-in",0,exception));
1205 options=GetConfigureOptions(filename,exception);
1206 option=(const StringInfo *) GetNextValueInLinkedList(options);
1207 while (option != (const StringInfo *) NULL)
1209 status|=LoadConfigureList((const char *) GetStringInfoDatum(option),
1210 GetStringInfoPath(option),0,exception);
1211 option=(const StringInfo *) GetNextValueInLinkedList(options);
1213 options=DestroyConfigureOptions(options);
1214 if ((configure_list == (LinkedListInfo *) NULL) ||
1215 (IsLinkedListEmpty(configure_list) != MagickFalse))
1216 status|=LoadConfigureList(ConfigureMap,"built-in",0,exception);
1217 return(status != 0 ? MagickTrue : MagickFalse);