MagickCore 7.0.10
configure.c
Go to the documentation of this file.
1/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
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 %
11% %
12% %
13% Wizards's Toolkit Configure Methods %
14% %
15% Software Design %
16% Cristy %
17% July 2003 %
18% %
19% %
20% Copyright @ 1999 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% https://imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37*/
38
39/*
40 Include declarations.
41*/
42#include "wizard/studio.h"
43#include "wizard/blob.h"
44#include "wizard/client.h"
45#include "wizard/configure.h"
46#include "wizard/exception.h"
48#include "wizard/hashmap.h"
49#include "wizard/log.h"
50#include "wizard/memory_.h"
51#include "wizard/semaphore.h"
52#include "wizard/string_.h"
53#include "wizard/token.h"
54#include "wizard/utility.h"
55#include "wizard/xml-tree.h"
57
58/*
59 Define declarations.
60*/
61#define ConfigureFilename "configure.xml"
62
63/*
64 Typedef declarations.
65*/
66typedef struct _ConfigureMapInfo
67{
68 const char
72
73/*
74 Static declarations.
75*/
76static const ConfigureMapInfo
78 {
79 { "NAME", "ImageMagick" }
80 };
81
82static LinkedListInfo
84
85static SemaphoreInfo
87
88/*
89 Forward declarations.
90*/
93 LoadConfigureCache(LinkedListInfo *,const char *,const char *,const size_t,
95
96/*
97%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98% %
99% %
100% %
101% A c q u i r e C o n f i g u r e C a c h e %
102% %
103% %
104% %
105%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106%
107% AcquireConfigureCache() caches one or more configure configurations which
108% provides a mapping between configure attributes and a configure name.
109%
110% The format of the AcquireConfigureCache method is:
111%
112% LinkedListInfo *AcquireConfigureCache(const char *filename,
113% ExceptionInfo *exception)
114%
115% A description of each parameter follows:
116%
117% o filename: The font file name.
118%
119% o exception: Return any errors or warnings in this structure.
120%
121*/
122static LinkedListInfo *AcquireConfigureCache(const char *filename,
123 ExceptionInfo *exception)
124{
125 char
126 path[WizardPathExtent];
127
128 const StringInfo
129 *option;
130
133 *options;
134
135 ssize_t
136 i;
137
139 status;
140
141 /*
142 Load built-in configure map.
143 */
145 if (configure_cache == (LinkedListInfo *) NULL)
146 ThrowFatalException(ResourceFatalError,"memory allocation failed `%s`");
147 status=WizardTrue;
148 for (i=0; i < (ssize_t) (sizeof(ConfigureMap)/sizeof(*ConfigureMap)); i++)
149 {
151 *configure_info;
152
153 const ConfigureMapInfo
154 *p;
155
156 p=ConfigureMap+i;
157 configure_info=(ConfigureInfo *) AcquireWizardMemory(
158 sizeof(*configure_info));
159 if (configure_info == (ConfigureInfo *) NULL)
160 {
162 "memory allocation failed `%s'",strerror(errno));
163 continue;
164 }
165 (void) memset(configure_info,0,sizeof(*configure_info));
166 configure_info->path=(char *) "[built-in]";
167 configure_info->name=(char *) p->name;
168 configure_info->value=(char *) p->value;
169 configure_info->exempt=WizardTrue;
170 configure_info->signature=WizardSignature;
171 status=AppendValueToLinkedList(configure_cache,configure_info);
172 if (status == WizardFalse)
174 "memory allocation failed `%s'",strerror(errno));
175 }
176 /*
177 Load external configure map.
178 */
179 *path='\0';
180 options=GetConfigureOptions(filename,exception);
181 option=(const StringInfo *) GetNextValueInLinkedList(options);
182 while (option != (const StringInfo *) NULL)
183 {
185 status&=LoadConfigureCache(configure_cache,(const char *)
186 GetStringInfoDatum(option),GetStringInfoPath(option),0,exception);
187 option=(const StringInfo *) GetNextValueInLinkedList(options);
188 }
189 options=DestroyConfigureOptions(options);
190 return(configure_cache);
191}
192
193/*
194%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195% %
196% %
197% %
198+ C o n f i g u r e C o m p o n e n t G e n e s i s %
199% %
200% %
201% %
202%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203%
204% ConfigureComponentGenesis() instantiates the configure component.
205%
206% The format of the ConfigureComponentGenesis method is:
207%
208% WizardBooleanType ConfigureComponentGenesis(void)
209%
210*/
212{
213 if (configure_semaphore == (SemaphoreInfo *) NULL)
215 return(WizardTrue);
216}
217
218/*
219%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
220% %
221% %
222% %
223+ C o n f i g u r e C o m p o n e n t T e r m i n u s %
224% %
225% %
226% %
227%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
228%
229% ConfigureComponentTerminus() deallocates memory associated with the
230% configure list.
231%
232% The format of the ConfigureComponentTerminus method is:
233%
234% ConfigureComponentTerminus(void)
235%
236*/
237
238static void *DestroyConfigureElement(void *configure_info)
239{
241 *p;
242
243 p=(ConfigureInfo *) configure_info;
244 if (p->exempt == WizardFalse)
245 {
246 if (p->value != (char *) NULL)
247 p->value=(char *) RelinquishWizardMemory(p->value);
248 if (p->name != (char *) NULL)
249 p->name=(char *) RelinquishWizardMemory(p->name);
250 if (p->path != (char *) NULL)
251 p->path=(char *) RelinquishWizardMemory(p->path);
252 }
254 return((void *) NULL);
255}
256
258{
259 if (configure_semaphore == (SemaphoreInfo *) NULL)
262 if (configure_cache != (LinkedListInfo *) NULL)
267}
268
269/*
270%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
271% %
272% %
273% %
274% D e s t r o y C o n f i g u r e O p t i o n s %
275% %
276% %
277% %
278%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
279%
280% DestroyConfigureOptions() releases memory associated with an configure
281% options.
282%
283% The format of the DestroyProfiles method is:
284%
285% LinkedListInfo *DestroyConfigureOptions(Image *image)
286%
287% A description of each parameter follows:
288%
289% o image: The image.
290%
291*/
292
293static void *DestroyOptions(void *option)
294{
295 return(DestroyStringInfo((StringInfo *) option));
296}
297
299{
300 assert(options != (LinkedListInfo *) NULL);
301 return(DestroyLinkedList(options,DestroyOptions));
302}
303
304/*
305%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
306% %
307% %
308% %
309+ G e t C o n f i g u r e I n f o %
310% %
311% %
312% %
313%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
314%
315% GetConfigureInfo() searches the configure list for the specified name and if
316% found returns attributes for that element.
317%
318% The format of the GetConfigureInfo method is:
319%
320% const ConfigureInfo *GetConfigureInfo(const char *name,
321% ExceptionInfo *exception)
322%
323% A description of each parameter follows:
324%
325% o configure_info: GetConfigureInfo() searches the configure list for the
326% specified name and if found returns attributes for that element.
327%
328% o name: The configure name.
329%
330% o exception: Return any errors or warnings in this structure.
331%
332*/
334 ExceptionInfo *exception)
335{
336 const ConfigureInfo
337 *p;
338
339 assert(exception != (ExceptionInfo *) NULL);
341 return((const ConfigureInfo *) NULL);
342 /*
343 Search for named configure.
344 */
348 if ((name == (const char *) NULL) || (strcasecmp(name,"*") == 0))
349 {
351 return(p);
352 }
353 while (p != (const ConfigureInfo *) NULL)
354 {
355 if (strcasecmp(name,p->name) == 0)
356 break;
358 }
359 if (p == (ConfigureInfo *) NULL)
361 "no such configure list `%s'",name);
362 else
366 return(p);
367}
368
369/*
370%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
371% %
372% %
373% %
374% G e t C o n f i g u r e I n f o L i s t %
375% %
376% %
377% %
378%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
379%
380% GetConfigureInfoList() returns any configure options that match the
381% specified pattern.
382%
383% The format of the GetConfigureInfoList function is:
384%
385% const ConfigureInfo **GetConfigureInfoList(const char *pattern,
386% size_t *number_options,ExceptionInfo *exception)
387%
388% A description of each parameter follows:
389%
390% o pattern: Specifies a pointer to a text string containing a pattern.
391%
392% o number_options: This integer returns the number of configure options in
393% the list.
394%
395% o exception: Return any errors or warnings in this structure.
396%
397*/
398
399#if defined(__cplusplus) || defined(c_plusplus)
400extern "C" {
401#endif
402
403static int ConfigureInfoCompare(const void *x,const void *y)
404{
405 const ConfigureInfo
406 **p,
407 **q;
408
409 p=(const ConfigureInfo **) x,
410 q=(const ConfigureInfo **) y;
411 if (strcasecmp((*p)->path,(*q)->path) == 0)
412 return(strcasecmp((*p)->name,(*q)->name));
413 return(strcasecmp((*p)->path,(*q)->path));
414}
415
416#if defined(__cplusplus) || defined(c_plusplus)
417}
418#endif
419
421 size_t *number_options,ExceptionInfo *exception)
422{
423 const ConfigureInfo
424 **options;
425
426 const ConfigureInfo
427 *p;
428
429 ssize_t
430 i;
431
432 /*
433 Allocate configure list.
434 */
435 assert(pattern != (char *) NULL);
436 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"%s",pattern);
437 assert(number_options != (size_t *) NULL);
438 *number_options=0;
439 p=GetConfigureInfo("*",exception);
440 if (p == (const ConfigureInfo *) NULL)
441 return((const ConfigureInfo **) NULL);
442 options=(const ConfigureInfo **) AcquireQuantumMemory((size_t)
444 if (options == (const ConfigureInfo **) NULL)
445 return((const ConfigureInfo **) NULL);
446 /*
447 Generate configure list.
448 */
452 for (i=0; p != (const ConfigureInfo *) NULL; )
453 {
454 if ((p->stealth == WizardFalse) &&
456 options[i++]=p;
458 }
460 qsort((void *) options,(size_t) i,sizeof(*options),ConfigureInfoCompare);
461 options[i]=(ConfigureInfo *) NULL;
462 *number_options=(size_t) i;
463 return(options);
464}
465
466/*
467%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
468% %
469% %
470% %
471% G e t C o n f i g u r e L i s t %
472% %
473% %
474% %
475%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
476%
477% GetConfigureList() returns any configure options that match the specified
478% pattern.
479%
480% The format of the GetConfigureList function is:
481%
482% char **GetConfigureList(const char *pattern,
483% size_t *number_options,ExceptionInfo *exception)
484%
485% A description of each parameter follows:
486%
487% o pattern: Specifies a pointer to a text string containing a pattern.
488%
489% o number_options: This integer returns the number of options in the list.
490%
491% o exception: Return any errors or warnings in this structure.
492%
493*/
494
495#if defined(__cplusplus) || defined(c_plusplus)
496extern "C" {
497#endif
498
499static int ConfigureCompare(const void *x,const void *y)
500{
501 char
502 **p,
503 **q;
504
505 p=(char **) x;
506 q=(char **) y;
507 return(strcasecmp(*p,*q));
508}
509
510#if defined(__cplusplus) || defined(c_plusplus)
511}
512#endif
513
514WizardExport char **GetConfigureList(const char *pattern,
515 size_t *number_options,ExceptionInfo *exception)
516{
517 char
518 **options;
519
520 const ConfigureInfo
521 *p;
522
523 ssize_t
524 i;
525
526 /*
527 Allocate configure list.
528 */
529 assert(pattern != (char *) NULL);
530 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"%s",pattern);
531 assert(number_options != (size_t *) NULL);
532 *number_options=0;
533 p=GetConfigureInfo("*",exception);
534 if (p == (const ConfigureInfo *) NULL)
535 return((char **) NULL);
538 options=(char **) AcquireQuantumMemory((size_t)
540 if (options == (char **) NULL)
541 return((char **) NULL);
545 for (i=0; p != (const ConfigureInfo *) NULL; )
546 {
547 if ((p->stealth == WizardFalse) &&
549 options[i++]=ConstantString(p->name);
551 }
553 qsort((void *) options,(size_t) i,sizeof(*options),ConfigureCompare);
554 options[i]=(char *) NULL;
555 *number_options=(size_t) i;
556 return(options);
557}
558
559/*
560%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
561% %
562% %
563% %
564% G e t C o n f i g u r e O p t i o n s %
565% %
566% %
567% %
568%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
569%
570% GetConfigureOptions() returns any Wizard configuration options associated
571% with the specified filename.
572%
573% The format of the GetConfigureOptions method is:
574%
575% LinkedListInfo *GetConfigureOptions(const char *filename,
576% ExceptionInfo *exception)
577%
578% A description of each parameter follows:
579%
580% o filename: The configure file name.
581%
582% o exception: Return any errors or warnings in this structure.
583%
584*/
586 ExceptionInfo *exception)
587{
588 char
589 path[WizardPathExtent];
590
591 const char
592 *element;
593
595 *options,
596 *paths;
597
599 *xml;
600
601 assert(filename != (const char *) NULL);
602 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"%s",filename);
603 assert(exception != (ExceptionInfo *) NULL);
604 (void) CopyWizardString(path,filename,WizardPathExtent);
605 /*
606 Load XML from configuration files to linked-list.
607 */
608 options=NewLinkedList(0);
609 paths=GetConfigurePaths(filename,exception);
610 if (paths != (LinkedListInfo *) NULL)
611 {
613 element=(const char *) GetNextValueInLinkedList(paths);
614 while (element != (const char *) NULL)
615 {
616 (void) FormatLocaleString(path,WizardPathExtent,"%s%s",element,filename);
618 "Searching for configure file: \"%s\"",path);
620 if (xml != (StringInfo *) NULL)
621 (void) AppendValueToLinkedList(options,xml);
622 element=(const char *) GetNextValueInLinkedList(paths);
623 }
625 }
626#if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT)
627 {
628 char
629 *blob;
630
631 blob=(char *) NTResourceToBlob(filename);
632 if (blob != (char *) NULL)
633 {
634 xml=AcquireStringInfo(0);
635 SetStringInfoLength(xml,strlen(blob)+1);
636 SetStringInfoDatum(xml,blob);
637 SetStringInfoPath(xml,filename);
638 (void) AppendValueToLinkedList(options,xml);
639 }
640 }
641#endif
642 if (GetNumberOfElementsInLinkedList(options) == 0)
644 "unable to open configure file `%s'",filename);
646 return(options);
647}
648
649/*
650%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
651% %
652% %
653% %
654% G e t C o n f i g u r e P a t h s %
655% %
656% %
657% %
658%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
659%
660% GetConfigurePaths() returns any Wizard configuration paths associated
661% with the specified filename.
662%
663% The format of the GetConfigurePaths method is:
664%
665% LinkedListInfo *GetConfigurePaths(const char *filename,
666% ExceptionInfo *exception)
667%
668% A description of each parameter follows:
669%
670% o filename: The configure file name.
671%
672% o exception: Return any errors or warnings in this structure.
673%
674*/
676 ExceptionInfo *exception)
677{
678#define RegistryKey "ConfigurePath"
679#define WizardsToolkitDLL "Wizard's Toolkit.dll"
680
681 char
682 path[WizardPathExtent];
683
685 *paths;
686
687 assert(filename != (const char *) NULL);
688 (void) LogWizardEvent(TraceEvent,GetWizardModule(),"%s",filename);
689 assert(exception != (ExceptionInfo *) NULL);
690 (void) CopyWizardString(path,filename,WizardPathExtent);
691 paths=NewLinkedList(0);
692 {
693 char
694 *configure_path;
695
696 char
697 *q;
698
699 const char
700 *p;
701
702 /*
703 Search WIZARD_CONFIGURE_PATH.
704 */
705 configure_path=GetEnvironmentValue("WIZARD_CONFIGURE_PATH");
706 if (configure_path != (char *) NULL)
707 {
708 for (p=configure_path-1; p != (char *) NULL; )
709 {
710 (void) CopyWizardString(path,p+1,WizardPathExtent);
711 q=strchr(path,DirectoryListSeparator);
712 if (q != (char *) NULL)
713 *q='\0';
714 q=path+strlen(path)-1;
715 if ((q >= path) && (*q != *DirectorySeparator))
718 (void) AppendValueToLinkedList(paths,AcquireString(path));
719 p=strchr(p+1,DirectoryListSeparator);
720 }
721 configure_path=(char *) RelinquishWizardMemory(configure_path);
722 }
723 }
724#if defined(WIZARDSTOOLKIT_INSTALLED_SUPPORT)
725#if defined(WIZARDSTOOLKIT_CONFIGURE_PATH)
728#endif
729#if defined(WIZARDSTOOLKIT_SHARE_PATH)
732#endif
733#if defined(WIZARDSTOOLKIT_SHAREARCH_PATH)
735 WIZARDSTOOLKIT_SHAREARCH_PATH));
736#endif
737#if defined(WIZARDSTOOLKIT_DOCUMENTATION_PATH)
740#endif
741#if defined(WIZARDSTOOLKIT_SHARE_PATH)
744#endif
745#if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT) && !(defined(WIZARDSTOOLKIT_CONFIGURE_PATH) || defined(WIZARDSTOOLKIT_SHARE_PATH))
746 {
747 unsigned char
748 *key_value;
749
750 /*
751 Locate file via registry key.
752 */
753 key_value=NTRegistryKeyLookup(RegistryKey);
754 if (key_value != (unsigned char *) NULL)
755 {
756 (void) FormatLocaleString(path,WizardPathExtent,"%s%s",(char *) key_value,
758 (void) AppendValueToLinkedList(paths,ConstantString(path));
759 key_value=(unsigned char *) RelinquishWizardMemory(key_value);
760 }
761 }
762#endif
763#else
764 {
765 char
766 *home;
767
768 /*
769 Search under WIZARD_HOME.
770 */
771 home=GetEnvironmentValue("WIZARD_HOME");
772 if (home != (char *) NULL)
773 {
774#if !defined(WIZARDSTOOLKIT_POSIX_SUPPORT)
776 "%s%s.config%sWizardsToolkit%s",home,DirectorySeparator,
778 (void) AppendValueToLinkedList(paths,AcquireString(path));
779#else
780 (void) FormatLocaleString(path,WizardPathExtent,"%s/etc/%s/",home,
782 (void) AppendValueToLinkedList(paths,AcquireString(path));
783 (void) FormatLocaleString(path,WizardPathExtent,"%s/share/%s/",home,
785 (void) AppendValueToLinkedList(paths,AcquireString(path));
786 (void) FormatLocaleString(path,WizardPathExtent,"%s",
787 WIZARDSTOOLKIT_SHAREARCH_PATH);
788 (void) AppendValueToLinkedList(paths,AcquireString(path));
789#endif
790 home=(char *) RelinquishWizardMemory(home);
791 }
792 }
793 if (*GetClientPath() != '\0')
794 {
795#if !defined(WIZARDSTOOLKIT_POSIX_SUPPORT)
798 (void) AppendValueToLinkedList(paths,AcquireString(path));
799#else
800 char
801 prefix[WizardPathExtent];
802
803 /*
804 Search based on executable directory if directory is known.
805 */
807 ChopPathComponents(prefix,1);
808 (void) FormatLocaleString(path,WizardPathExtent,"%s/etc/%s/",prefix,
810 (void) AppendValueToLinkedList(paths,AcquireString(path));
811 (void) FormatLocaleString(path,WizardPathExtent,"%s/share/%s/",prefix,
813 (void) AppendValueToLinkedList(paths,AcquireString(path));
814 (void) FormatLocaleString(path,WizardPathExtent,"%s",
815 WIZARDSTOOLKIT_SHAREARCH_PATH);
816 (void) AppendValueToLinkedList(paths,AcquireString(path));
817#endif
818 }
819 /*
820 Search current directory.
821 */
822 (void) AppendValueToLinkedList(paths,AcquireString(""));
823#endif
824 {
825 char
826 *home;
827
828 home=GetEnvironmentValue("XDG_CONFIG_HOME");
829 if (home == (char *) NULL)
830 home=GetEnvironmentValue("LOCALAPPDATA");
831 if (home == (char *) NULL)
832 home=GetEnvironmentValue("APPDATA");
833 if (home == (char *) NULL)
834 home=GetEnvironmentValue("USERPROFILE");
835 if (home != (char *) NULL)
836 {
837 /*
838 Search $XDG_CONFIG_HOME/ImageMagick.
839 */
841 "%s%sWizardsToolkit%s%s",home,DirectorySeparator,DirectorySeparator,
842 filename);
843 (void) AppendValueToLinkedList(paths,ConstantString(path));
844 home=DestroyString(home);
845 }
846 home=GetEnvironmentValue("HOME");
847 if (home != (char *) NULL)
848 {
849 /*
850 Search $HOME/.config/WizardsToolkit.
851 */
853 "%s%s.config%sWizardsToolkit%s",home,DirectorySeparator,
855 (void) AppendValueToLinkedList(paths,AcquireString(path));
856 home=(char *) RelinquishWizardMemory(home);
857 }
858 }
859#if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT)
860 {
861 char
862 module_path[WizardPathExtent];
863
864 if (NTGetModulePath(WizardsToolkitDLL,module_path) != WizardFalse)
865 {
866 unsigned char
867 *key_value;
868
869 /*
870 Search module path.
871 */
872 (void) FormatLocaleString(path,WizardPathExtent,"%s%s",module_path,
874 key_value=NTRegistryKeyLookup(RegistryKey);
875 if (key_value == (unsigned char *) NULL)
876 (void) AppendValueToLinkedList(paths,ConstantString(path));
877 else
878 key_value=(unsigned char *) RelinquishWizardMemory(key_value);
879 }
880 }
881#endif
882 return(paths);
883}
884
885/*
886%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
887% %
888% %
889% %
890% G e t C o n f i g u r e V a l u e %
891% %
892% %
893% %
894%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
895%
896% GetConfigureValue() returns the value associated with the configure info.
897%
898% The format of the GetConfigureValue method is:
899%
900% const char *GetConfigureValue(const ConfigureInfo *configure_info)
901%
902% A description of each parameter follows:
903%
904% o configure_info: The configure info.
905%
906*/
907WizardExport const char *GetConfigureValue(const ConfigureInfo *configure_info)
908{
910 assert(configure_info != (ConfigureInfo *) NULL);
911 assert(configure_info->signature == WizardSignature);
912 return(configure_info->value);
913}
914
915/*
916%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
917% %
918% %
919% %
920+ I s C o n f i g u r e L i s t I n s t a n t i a t e d %
921% %
922% %
923% %
924%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
925%
926% IsConfigureCacheInstantiated() determines if the configure list is
927% instantiated. If not, it instantiates the list and returns it.
928%
929% The format of the IsConfigureInstantiated method is:
930%
931% WizardBooleanType IsConfigureCacheInstantiated(ExceptionInfo *exception)
932%
933% A description of each parameter follows.
934%
935% o exception: Return any errors or warnings in this structure.
936%
937*/
939{
940 if (configure_cache == (LinkedListInfo *) NULL)
941 {
942 if (configure_semaphore == (SemaphoreInfo *) NULL)
945 if (configure_cache == (LinkedListInfo *) NULL)
948 }
950}
951
952/*
953%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
954% %
955% %
956% %
957% L i s t C o n f i g u r e I n f o %
958% %
959% %
960% %
961%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
962%
963% ListConfigureInfo() lists the configure info to a file.
964%
965% The format of the ListConfigureInfo method is:
966%
967% WizardBooleanType ListConfigureInfo(FILE *file,ExceptionInfo *exception)
968%
969% A description of each parameter follows.
970%
971% o file: An pointer to a FILE.
972%
973% o exception: Return any errors or warnings in this structure.
974%
975*/
977 ExceptionInfo *exception)
978{
979 const char
980 *name,
981 *path,
982 *value;
983
984 const ConfigureInfo
985 **configure_info;
986
987 ssize_t
988 j;
989
990 ssize_t
991 i;
992
993 size_t
994 number_options;
995
996 if (file == (FILE *) NULL)
997 file=stdout;
998 configure_info=GetConfigureInfoList("*",&number_options,exception);
999 if (configure_info == (const ConfigureInfo **) NULL)
1000 return(WizardFalse);
1001 path=(const char *) NULL;
1002 for (i=0; i < (ssize_t) number_options; i++)
1003 {
1004 if (configure_info[i]->stealth != WizardFalse)
1005 continue;
1006 if ((path == (const char *) NULL) ||
1007 (strcasecmp(path,configure_info[i]->path) != 0))
1008 {
1009 if (configure_info[i]->path != (char *) NULL)
1010 (void) fprintf(file,"\nPath: %s\n\n",configure_info[i]->path);
1011 (void) fprintf(file,"Name Value\n");
1012 (void) fprintf(file,"-------------------------------------------------"
1013 "------------------------------\n");
1014 }
1015 path=configure_info[i]->path;
1016 name="unknown";
1017 if (configure_info[i]->name != (char *) NULL)
1018 name=configure_info[i]->name;
1019 (void) fprintf(file,"%s",name);
1020 for (j=(ssize_t) strlen(name); j <= 12; j++)
1021 (void) fprintf(file," ");
1022 (void) fprintf(file," ");
1023 value="unknown";
1024 if (configure_info[i]->value != (char *) NULL)
1025 value=configure_info[i]->value;
1026 (void) fprintf(file,"%s",value);
1027 (void) fprintf(file,"\n");
1028 }
1029 (void) fflush(file);
1030 configure_info=(const ConfigureInfo **) RelinquishWizardMemory((void *)
1031 configure_info);
1032 return(WizardTrue);
1033}
1034
1035/*
1036%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1037% %
1038% %
1039% %
1040+ L o a d C o n f i g u r e L i s t %
1041% %
1042% %
1043% %
1044%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1045%
1046% LoadConfigureCache() loads the configure configurations which provides a
1047% mapping between configure attributes and a configure name.
1048%
1049% The format of the LoadConfigureCache method is:
1050%
1051% WizardBooleanType LoadConfigureCache(LinkedListInfo *configure_cache,
1052% const char *xml,const char *filename,const size_t depth,
1053% ExceptionInfo *exception)
1054%
1055% A description of each parameter follows:
1056%
1057% o xml: The configure list in XML format.
1058%
1059% o filename: The configure list filename.
1060%
1061% o depth: depth of <include /> statements.
1062%
1063% o exception: Return any errors or warnings in this structure.
1064%
1065*/
1067 const char *xml,const char *filename,const size_t depth,
1068 ExceptionInfo *exception)
1069{
1070 const char
1071 *attribute;
1072
1074 *configure_info = (ConfigureInfo *) NULL;
1075
1077 status;
1078
1080 *configure,
1081 *configure_map,
1082 *include;
1083
1084 /*
1085 Load the configure map file.
1086 */
1088 "Loading configure map \"%s\" ...",filename);
1089 if (xml == (const char *) NULL)
1090 return(WizardFalse);
1091 configure_map=NewXMLTree(xml,exception);
1092 if (configure_map == (XMLTreeInfo *) NULL)
1093 return(WizardFalse);
1094 status=WizardFalse;
1095 include=GetXMLTreeChild(configure_map,"include");
1096 while (include != (XMLTreeInfo *) NULL)
1097 {
1098 /*
1099 Process include element.
1100 */
1101 attribute=GetXMLTreeAttribute(include,"file");
1102 if (attribute != (const char *) NULL)
1103 {
1104 if (depth > 200)
1105 (void) ThrowWizardException(exception,GetWizardModule(),
1106 ConfigureError,"include element nested too deeply `%s'",filename);
1107 else
1108 {
1109 char
1110 path[WizardPathExtent],
1111 *xml;
1112
1113 GetPathComponent(filename,HeadPath,path);
1114 if (*path != '\0')
1117 (void) ConcatenateWizardString(path,attribute,WizardPathExtent);
1118 xml=FileToXML(path,~0UL);
1119 status&=LoadConfigureCache(configure_cache,xml,path,depth+1,
1120 exception);
1121 xml=(char *) RelinquishWizardMemory(xml);
1122 }
1123 }
1124 include=GetNextXMLTreeTag(include);
1125 }
1126 configure=GetXMLTreeChild(configure_map,"configure");
1127 while (configure != (XMLTreeInfo *) NULL)
1128 {
1129 const char
1130 *attribute;
1131
1132 /*
1133 Process configure element.
1134 */
1135 configure_info=(ConfigureInfo *) AcquireWizardMemory(
1136 sizeof(*configure_info));
1137 if (configure_info == (ConfigureInfo *) NULL)
1138 ThrowFatalException(ResourceFatalError,"memory allocation failed `%s`");
1139 (void) memset(configure_info,0,sizeof(*configure_info));
1140 configure_info->path=ConstantString(filename);
1141 configure_info->exempt=WizardFalse;
1142 configure_info->signature=WizardSignature;
1143 attribute=GetXMLTreeAttribute(configure,"name");
1144 if (attribute != (const char *) NULL)
1145 configure_info->name=ConstantString(attribute);
1146 attribute=GetXMLTreeAttribute(configure,"stealth");
1147 if (attribute != (const char *) NULL)
1148 configure_info->stealth=IsWizardTrue(attribute);
1149 attribute=GetXMLTreeAttribute(configure,"value");
1150 if (attribute != (const char *) NULL)
1151 configure_info->value=ConstantString(attribute);
1152 status=AppendValueToLinkedList(configure_cache,configure_info);
1153 if (status == WizardFalse)
1154 (void) ThrowWizardException(exception,GetWizardModule(),
1155 ResourceFatalError,"memory allocation failed `%s`",strerror(errno));
1156 configure=GetNextXMLTreeTag(configure);
1157 }
1158 configure_map=DestroyXMLTree(configure_map);
1159 return(status != 0 ? WizardTrue : WizardFalse);
1160}
WizardExport const char * GetClientPath(void)
Definition client.c:87
static void * DestroyConfigureElement(void *configure_info)
Definition configure.c:238
static int ConfigureInfoCompare(const void *x, const void *y)
Definition configure.c:403
WizardExport WizardBooleanType ConfigureComponentGenesis(void)
Definition configure.c:211
static void * DestroyOptions(void *option)
Definition configure.c:293
#define RegistryKey
static LinkedListInfo * configure_cache
Definition configure.c:83
static int ConfigureCompare(const void *x, const void *y)
Definition configure.c:499
WizardExport const char * GetConfigureValue(const ConfigureInfo *configure_info)
Definition configure.c:907
WizardExport LinkedListInfo * DestroyConfigureOptions(LinkedListInfo *options)
Definition configure.c:298
WizardExport LinkedListInfo * GetConfigureOptions(const char *filename, ExceptionInfo *exception)
Definition configure.c:585
#define ConfigureFilename
Definition configure.c:61
struct _ConfigureMapInfo ConfigureMapInfo
static WizardBooleanType IsConfigureCacheInstantiated(ExceptionInfo *)
Definition configure.c:938
WizardExport const ConfigureInfo ** GetConfigureInfoList(const char *pattern, size_t *number_options, ExceptionInfo *exception)
Definition configure.c:420
WizardExport void ConfigureComponentTerminus(void)
Definition configure.c:257
static const ConfigureMapInfo ConfigureMap[]
Definition configure.c:77
static WizardBooleanType LoadConfigureCache(LinkedListInfo *, const char *, const char *, const size_t, ExceptionInfo *)
Definition configure.c:1066
WizardExport const ConfigureInfo * GetConfigureInfo(const char *name, ExceptionInfo *exception)
Definition configure.c:333
WizardExport LinkedListInfo * GetConfigurePaths(const char *filename, ExceptionInfo *exception)
Definition configure.c:675
static LinkedListInfo * AcquireConfigureCache(const char *filename, ExceptionInfo *exception)
Definition configure.c:122
WizardExport char ** GetConfigureList(const char *pattern, size_t *number_options, ExceptionInfo *exception)
Definition configure.c:514
WizardExport WizardBooleanType ListConfigureInfo(FILE *file, ExceptionInfo *exception)
Definition configure.c:976
static SemaphoreInfo * configure_semaphore
Definition configure.c:86
#define WizardsToolkitDLL
#define ThrowFatalException(severity, tag)
WizardExport WizardBooleanType ThrowWizardException(ExceptionInfo *exception, const char *module, const char *function, const size_t line, const ExceptionType severity, const char *format,...)
Definition exception.c:1029
@ OptionWarning
Definition exception.h:63
@ ResourceFatalError
Definition exception.h:121
@ ConfigureError
Definition exception.h:88
@ ConfigureWarning
Definition exception.h:68
@ ResourceError
Definition exception.h:101
WizardExport void ResetLinkedListIterator(LinkedListInfo *list_info)
Definition hashmap.c:1919
WizardExport size_t GetNumberOfElementsInLinkedList(const LinkedListInfo *list_info)
Definition hashmap.c:678
WizardExport WizardBooleanType AppendValueToLinkedList(LinkedListInfo *list_info, const void *value)
Definition hashmap.c:149
WizardExport WizardBooleanType InsertValueInLinkedList(LinkedListInfo *list_info, const size_t index, const void *value)
Definition hashmap.c:991
WizardExport void * RemoveElementByValueFromLinkedList(LinkedListInfo *list_info, const void *value)
Definition hashmap.c:1595
WizardExport LinkedListInfo * NewLinkedList(const size_t capacity)
Definition hashmap.c:1362
WizardExport void * GetNextValueInLinkedList(LinkedListInfo *list_info)
Definition hashmap.c:605
WizardExport LinkedListInfo * DestroyLinkedList(LinkedListInfo *list_info, void *(*relinquish_value)(void *))
Definition hashmap.c:397
WizardExport ssize_t FormatLocaleString(char *string, const size_t length, const char *format,...)
Definition locale.c:465
WizardBooleanType LogWizardEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
Definition log.c:1390
@ TraceEvent
Definition log.h:39
@ ConfigureEvent
Definition log.h:44
#define GetWizardModule()
Definition log.h:30
WizardExport void * AcquireWizardMemory(const size_t size)
Definition memory.c:586
WizardExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
Definition memory.c:657
WizardExport void * RelinquishWizardMemory(void *memory)
Definition memory.c:1039
#define WizardExport
#define WizardPathExtent
#define WizardSignature
WizardExport void RelinquishSemaphoreInfo(SemaphoreInfo **semaphore_info)
Definition semaphore.c:338
WizardExport SemaphoreInfo * AcquireSemaphoreInfo(void)
Definition semaphore.c:156
WizardExport void LockSemaphoreInfo(SemaphoreInfo *semaphore_info)
Definition semaphore.c:282
WizardExport void UnlockSemaphoreInfo(SemaphoreInfo *semaphore_info)
Definition semaphore.c:437
WizardExport void ActivateSemaphoreInfo(SemaphoreInfo **semaphore_info)
Definition semaphore.c:247
WizardExport void SetStringInfoLength(StringInfo *string_info, const size_t length)
Definition string.c:1865
WizardExport char * DestroyString(char *string)
Definition string.c:830
WizardExport void SetStringInfoPath(StringInfo *string_info, const char *path)
Definition string.c:1907
WizardExport char * ConstantString(const char *source)
Definition string.c:655
WizardExport size_t ConcatenateWizardString(char *destination, const char *source, const size_t length)
Definition string.c:478
WizardExport StringInfo * AcquireStringInfo(const size_t length)
Definition string.c:179
WizardExport StringInfo * ConfigureFileToStringInfo(const char *filename)
Definition string.c:546
WizardExport char * AcquireString(const char *source)
Definition string.c:133
WizardExport void SetStringInfoDatum(StringInfo *string_info, const unsigned char *source)
Definition string.c:1832
WizardExport unsigned char * GetStringInfoDatum(const StringInfo *string_info)
Definition string.c:1251
WizardExport char * GetEnvironmentValue(const char *name)
Definition string.c:1177
WizardExport size_t CopyWizardString(char *destination, const char *source, const size_t length)
Definition string.c:762
WizardExport const char * GetStringInfoPath(const StringInfo *string_info)
Definition string.c:1309
WizardExport StringInfo * DestroyStringInfo(StringInfo *string_info)
Definition string.c:857
size_t signature
Definition configure.h:39
WizardBooleanType stealth
Definition configure.h:36
WizardBooleanType exempt
Definition configure.h:35
const char * name
Definition configure.c:69
const char * value
Definition configure.c:70
#define DirectorySeparator
Definition studio.h:239
#define DirectoryListSeparator
Definition studio.h:240
WizardExport WizardBooleanType GlobExpression(const char *expression, const char *pattern, const WizardBooleanType case_insensitive)
Definition token.c:259
WizardExport void ChopPathComponents(char *, const size_t)
WizardExport WizardBooleanType IsWizardTrue(const char *value)
Definition utility.c:910
WizardExport void GetPathComponent(const char *path, PathType type, char *component)
Definition utility.c:415
@ HeadPath
Definition utility.h:30
#define WIZARDSTOOLKIT_SHARE_RELATIVE_PATH
#define WIZARDSTOOLKIT_DOCUMENTATION_PATH
#define WIZARDSTOOLKIT_CONFIGURE_RELATIVE_PATH
#define WIZARDSTOOLKIT_CONFIGURE_PATH
#define WIZARDSTOOLKIT_SHARE_PATH
WizardBooleanType
Definition wizard-type.h:26
@ WizardTrue
Definition wizard-type.h:28
@ WizardFalse
Definition wizard-type.h:27
unsigned int WizardStatusType
Definition wizard-type.h:42
WizardPrivate char * FileToXML(const char *, const size_t)
Definition xml-tree.c:633
WizardExport XMLTreeInfo * DestroyXMLTree(XMLTreeInfo *xml_info)
Definition xml-tree.c:593
WizardExport const char * GetXMLTreeAttribute(XMLTreeInfo *xml_info, const char *tag)
Definition xml-tree.c:812
WizardExport XMLTreeInfo * NewXMLTree(const char *xml, ExceptionInfo *exception)
Definition xml-tree.c:1988
WizardExport XMLTreeInfo * GetNextXMLTreeTag(XMLTreeInfo *xml_info)
Definition xml-tree.c:778
WizardExport XMLTreeInfo * GetXMLTreeChild(XMLTreeInfo *xml_info, const char *tag)
Definition xml-tree.c:927