root/WizardsToolkit/branches/WizardsToolkit-1.0.6/wizard/configure.c

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