root/WizardsToolkit/trunk/wizard/configure.c

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