configure.c

Go to the documentation of this file.
00001 /*
00002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00003 %                                                                             %
00004 %                                                                             %
00005 %                                                                             %
00006 %          CCCC   OOO   N   N  FFFFF  IIIII   GGGG  U   U  RRRR   EEEEE       %
00007 %         C      O   O  NN  N  F        I    G      U   U  R   R  E           %
00008 %         C      O   O  N N N  FFF      I    G GG   U   U  RRRR   EEE         %
00009 %         C      O   O  N  NN  F        I    G   G  U   U  R R    E           %
00010 %          CCCC   OOO   N   N  F      IIIII   GGG    UUU   R  R   EEEEE       %
00011 %                                                                             %
00012 %                                                                             %
00013 %                      MagickCore Image Configure Methods                     %
00014 %                                                                             %
00015 %                              Software Design                                %
00016 %                                John Cristy                                  %
00017 %                                 July 2003                                   %
00018 %                                                                             %
00019 %                                                                             %
00020 %  Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization      %
00021 %  dedicated to making software imaging solutions freely available.           %
00022 %                                                                             %
00023 %  You may not use this file except in compliance with the License.  You may  %
00024 %  obtain a copy of the License at                                            %
00025 %                                                                             %
00026 %    http://www.imagemagick.org/script/license.php                            %
00027 %                                                                             %
00028 %  Unless required by applicable law or agreed to in writing, software        %
00029 %  distributed under the License is distributed on an "AS IS" BASIS,          %
00030 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
00031 %  See the License for the specific language governing permissions and        %
00032 %  limitations under the License.                                             %
00033 %                                                                             %
00034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00035 %
00036 %
00037 */
00038 
00039 /*
00040   Include declarations.
00041 */
00042 #include "magick/studio.h"
00043 #include "magick/blob.h"
00044 #include "magick/client.h"
00045 #include "magick/configure.h"
00046 #include "magick/exception.h"
00047 #include "magick/exception-private.h"
00048 #include "magick/hashmap.h"
00049 #include "magick/log.h"
00050 #include "magick/memory_.h"
00051 #include "magick/semaphore.h"
00052 #include "magick/string_.h"
00053 #include "magick/token.h"
00054 #include "magick/utility.h"
00055 #include "magick/xml-tree.h"
00056 
00057 /*
00058   Define declarations.
00059 */
00060 #define ConfigureFilename  "configure.xml"
00061 
00062 /*
00063   Static declarations.
00064 */
00065 static const char
00066   *ConfigureMap = (char *)
00067     "<?xml version=\"1.0\"?>"
00068     "<configuremap>"
00069     "  <configure stealth=\"True\" />"
00070     "</configuremap>";
00071 
00072 static LinkedListInfo
00073   *configure_list = (LinkedListInfo *) NULL;
00074 
00075 static SemaphoreInfo
00076   *configure_semaphore = (SemaphoreInfo *) NULL;
00077 
00078 static volatile MagickBooleanType
00079   instantiate_configure = MagickFalse;
00080 
00081 /*
00082   Forward declarations.
00083 */
00084 static MagickBooleanType
00085   InitializeConfigureList(ExceptionInfo *),
00086   LoadConfigureLists(const char *,ExceptionInfo *);
00087 
00088 /*
00089 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00090 %                                                                             %
00091 %                                                                             %
00092 %                                                                             %
00093 +   D e s t r o y C o n f i g u r e L i s t                                   %
00094 %                                                                             %
00095 %                                                                             %
00096 %                                                                             %
00097 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00098 %
00099 %  DestroyConfigureList() deallocates memory associated with the configure list.
00100 %
00101 %  The format of the DestroyConfigureList method is:
00102 %
00103 %      DestroyConfigureList(void)
00104 %
00105 */
00106 
00107 static void *DestroyConfigureElement(void *configure_info)
00108 {
00109   register ConfigureInfo
00110     *p;
00111 
00112   p=(ConfigureInfo *) configure_info;
00113   if (p->path != (char *) NULL)
00114     p->path=DestroyString(p->path);
00115   if (p->name != (char *) NULL)
00116     p->name=DestroyString(p->name);
00117   if (p->value != (char *) NULL)
00118     p->value=DestroyString(p->value);
00119   p=(ConfigureInfo *) RelinquishMagickMemory(p);
00120   return((void *) NULL);
00121 }
00122 
00123 MagickExport void DestroyConfigureList(void)
00124 {
00125   AcquireSemaphoreInfo(&configure_semaphore);
00126   if (configure_list != (LinkedListInfo *) NULL)
00127     configure_list=DestroyLinkedList(configure_list,DestroyConfigureElement);
00128   configure_list=(LinkedListInfo *) NULL;
00129   instantiate_configure=MagickFalse;
00130   RelinquishSemaphoreInfo(configure_semaphore);
00131   DestroySemaphoreInfo(&configure_semaphore);
00132 }
00133 
00134 /*
00135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00136 %                                                                             %
00137 %                                                                             %
00138 %                                                                             %
00139 %   D e s t r o y C o n f i g u r e O p t i o n s                             %
00140 %                                                                             %
00141 %                                                                             %
00142 %                                                                             %
00143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00144 %
00145 %  DestroyConfigureOptions() releases memory associated with an configure
00146 %  options.
00147 %
00148 %  The format of the DestroyProfiles method is:
00149 %
00150 %      LinkedListInfo *DestroyConfigureOptions(Image *image)
00151 %
00152 %  A description of each parameter follows:
00153 %
00154 %    o image: the image.
00155 %
00156 */
00157 
00158 static void *DestroyOptions(void *option)
00159 {
00160   return(DestroyStringInfo((StringInfo *) option));
00161 }
00162 
00163 MagickExport LinkedListInfo *DestroyConfigureOptions(LinkedListInfo *options)
00164 {
00165   assert(options != (LinkedListInfo *) NULL);
00166   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00167   return(DestroyLinkedList(options,DestroyOptions));
00168 }
00169 
00170 /*
00171 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00172 %                                                                             %
00173 %                                                                             %
00174 %                                                                             %
00175 +   G e t C o n f i g u r e I n f o                                           %
00176 %                                                                             %
00177 %                                                                             %
00178 %                                                                             %
00179 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00180 %
00181 %  GetConfigureInfo() searches the configure list for the specified name and if
00182 %  found returns attributes for that element.
00183 %
00184 %  The format of the GetConfigureInfo method is:
00185 %
00186 %      const ConfigureInfo *GetConfigureInfo(const char *name,
00187 %        ExceptionInfo *exception)
00188 %
00189 %  A description of each parameter follows:
00190 %
00191 %    o configure_info: GetConfigureInfo() searches the configure list for the
00192 %      specified name and if found returns attributes for that element.
00193 %
00194 %    o name: the configure name.
00195 %
00196 %    o exception: return any errors or warnings in this structure.
00197 %
00198 */
00199 MagickExport const ConfigureInfo *GetConfigureInfo(const char *name,
00200   ExceptionInfo *exception)
00201 {
00202   register const ConfigureInfo
00203     *p;
00204 
00205   assert(exception != (ExceptionInfo *) NULL);
00206   if ((configure_list == (LinkedListInfo *) NULL) ||
00207       (instantiate_configure == MagickFalse))
00208     if (InitializeConfigureList(exception) == MagickFalse)
00209       return((const ConfigureInfo *) NULL);
00210   if ((configure_list == (LinkedListInfo *) NULL) ||
00211       (IsLinkedListEmpty(configure_list) != MagickFalse))
00212     return((const ConfigureInfo *) NULL);
00213   if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
00214     return((const ConfigureInfo *) GetValueFromLinkedList(configure_list,0));
00215   /*
00216     Search for configure tag.
00217   */
00218   AcquireSemaphoreInfo(&configure_semaphore);
00219   ResetLinkedListIterator(configure_list);
00220   p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list);
00221   while (p != (const ConfigureInfo *) NULL)
00222   {
00223     if (LocaleCompare(name,p->name) == 0)
00224       break;
00225     p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list);
00226   }
00227   if (p != (ConfigureInfo *) NULL)
00228     (void) InsertValueInLinkedList(configure_list,0,
00229       RemoveElementByValueFromLinkedList(configure_list,p));
00230   RelinquishSemaphoreInfo(configure_semaphore);
00231   return(p);
00232 }
00233 
00234 /*
00235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00236 %                                                                             %
00237 %                                                                             %
00238 %                                                                             %
00239 %   G e t C o n f i g u r e I n f o L i s t                                   %
00240 %                                                                             %
00241 %                                                                             %
00242 %                                                                             %
00243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00244 %
00245 %  GetConfigureInfoList() returns any configure options that match the
00246 %  specified pattern.
00247 %
00248 %  The format of the GetConfigureInfoList function is:
00249 %
00250 %      const ConfigureInfo **GetConfigureInfoList(const char *pattern,
00251 %        unsigned long *number_options,ExceptionInfo *exception)
00252 %
00253 %  A description of each parameter follows:
00254 %
00255 %    o pattern: Specifies a pointer to a text string containing a pattern.
00256 %
00257 %    o number_options:  This integer returns the number of configure options in
00258 %    the list.
00259 %
00260 %    o exception: return any errors or warnings in this structure.
00261 %
00262 */
00263 
00264 #if defined(__cplusplus) || defined(c_plusplus)
00265 extern "C" {
00266 #endif
00267 
00268 static int ConfigureInfoCompare(const void *x,const void *y)
00269 {
00270   const ConfigureInfo
00271     **p,
00272     **q;
00273 
00274   p=(const ConfigureInfo **) x,
00275   q=(const ConfigureInfo **) y;
00276   if (LocaleCompare((*p)->path,(*q)->path) == 0)
00277     return(LocaleCompare((*p)->name,(*q)->name));
00278   return(LocaleCompare((*p)->path,(*q)->path));
00279 }
00280 
00281 #if defined(__cplusplus) || defined(c_plusplus)
00282 }
00283 #endif
00284 
00285 MagickExport const ConfigureInfo **GetConfigureInfoList(const char *pattern,
00286   unsigned long *number_options,ExceptionInfo *exception)
00287 {
00288   const ConfigureInfo
00289     **options;
00290 
00291   register const ConfigureInfo
00292     *p;
00293 
00294   register long
00295     i;
00296 
00297   /*
00298     Allocate configure list.
00299   */
00300   assert(pattern != (char *) NULL);
00301   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
00302   assert(number_options != (unsigned long *) NULL);
00303   *number_options=0;
00304   p=GetConfigureInfo("*",exception);
00305   if (p == (const ConfigureInfo *) NULL)
00306     return((const ConfigureInfo **) NULL);
00307   options=(const ConfigureInfo **) AcquireQuantumMemory((size_t)
00308     GetNumberOfElementsInLinkedList(configure_list)+1UL,sizeof(*options));
00309   if (options == (const ConfigureInfo **) NULL)
00310     return((const ConfigureInfo **) NULL);
00311   /*
00312     Generate configure list.
00313   */
00314   AcquireSemaphoreInfo(&configure_semaphore);
00315   ResetLinkedListIterator(configure_list);
00316   p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list);
00317   for (i=0; p != (const ConfigureInfo *) NULL; )
00318   {
00319     if ((p->stealth == MagickFalse) &&
00320         (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
00321       options[i++]=p;
00322     p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list);
00323   }
00324   RelinquishSemaphoreInfo(configure_semaphore);
00325   qsort((void *) options,(size_t) i,sizeof(*options),ConfigureInfoCompare);
00326   options[i]=(ConfigureInfo *) NULL;
00327   *number_options=(unsigned long) i;
00328   return(options);
00329 }
00330 
00331 /*
00332 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00333 %                                                                             %
00334 %                                                                             %
00335 %                                                                             %
00336 %   G e t C o n f i g u r e L i s t                                           %
00337 %                                                                             %
00338 %                                                                             %
00339 %                                                                             %
00340 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00341 %
00342 %  GetConfigureList() returns any configure options that match the specified
00343 %  pattern.
00344 %
00345 %  The format of the GetConfigureList function is:
00346 %
00347 %      char **GetConfigureList(const char *pattern,
00348 %        unsigned long *number_options,ExceptionInfo *exception)
00349 %
00350 %  A description of each parameter follows:
00351 %
00352 %    o pattern: Specifies a pointer to a text string containing a pattern.
00353 %
00354 %    o number_options:  This integer returns the number of options in the list.
00355 %
00356 %    o exception: return any errors or warnings in this structure.
00357 %
00358 */
00359 
00360 #if defined(__cplusplus) || defined(c_plusplus)
00361 extern "C" {
00362 #endif
00363 
00364 static int ConfigureCompare(const void *x,const void *y)
00365 {
00366   register char
00367     **p,
00368     **q;
00369 
00370   p=(char **) x;
00371   q=(char **) y;
00372   return(LocaleCompare(*p,*q));
00373 }
00374 
00375 #if defined(__cplusplus) || defined(c_plusplus)
00376 }
00377 #endif
00378 
00379 MagickExport char **GetConfigureList(const char *pattern,
00380   unsigned long *number_options,ExceptionInfo *exception)
00381 {
00382   char
00383     **options;
00384 
00385   register const ConfigureInfo
00386     *p;
00387 
00388   register long
00389     i;
00390 
00391   /*
00392     Allocate configure list.
00393   */
00394   assert(pattern != (char *) NULL);
00395   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
00396   assert(number_options != (unsigned long *) NULL);
00397   *number_options=0;
00398   p=GetConfigureInfo("*",exception);
00399   if (p == (const ConfigureInfo *) NULL)
00400     return((char **) NULL);
00401   AcquireSemaphoreInfo(&configure_semaphore);
00402   RelinquishSemaphoreInfo(configure_semaphore);
00403   options=(char **) AcquireQuantumMemory((size_t)
00404     GetNumberOfElementsInLinkedList(configure_list)+1UL,sizeof(*options));
00405   if (options == (char **) NULL)
00406     return((char **) NULL);
00407   AcquireSemaphoreInfo(&configure_semaphore);
00408   ResetLinkedListIterator(configure_list);
00409   p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list);
00410   for (i=0; p != (const ConfigureInfo *) NULL; )
00411   {
00412     if ((p->stealth == MagickFalse) &&
00413         (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
00414       options[i++]=ConstantString(p->name);
00415     p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list);
00416   }
00417   RelinquishSemaphoreInfo(configure_semaphore);
00418   qsort((void *) options,(size_t) i,sizeof(*options),ConfigureCompare);
00419   options[i]=(char *) NULL;
00420   *number_options=(unsigned long) i;
00421   return(options);
00422 }
00423 
00424 /*
00425 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00426 %                                                                             %
00427 %                                                                             %
00428 %                                                                             %
00429 %   G e t C o n f i g u r e O p t i o n                                       %
00430 %                                                                             %
00431 %                                                                             %
00432 %                                                                             %
00433 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00434 %
00435 %  GetConfigureOption() returns the value associated with the configure option.
00436 %
00437 %  The format of the GetConfigureOption method is:
00438 %
00439 %      char *GetConfigureOption(const char *option)
00440 %
00441 %  A description of each parameter follows:
00442 %
00443 %    o configure_info:  The configure info.
00444 %
00445 */
00446 MagickExport char *GetConfigureOption(const char *option)
00447 {
00448   const char
00449     *value;
00450 
00451   const ConfigureInfo
00452     *configure_info;
00453 
00454   ExceptionInfo
00455     *exception;
00456 
00457   assert(option != (const char *) NULL);
00458   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",option);
00459   exception=AcquireExceptionInfo();
00460   configure_info=GetConfigureInfo(option,exception);
00461   exception=DestroyExceptionInfo(exception);
00462   if (configure_info == (ConfigureInfo *) NULL)
00463     return((char *) NULL);
00464   value=GetConfigureValue(configure_info);
00465   if ((value == (const char *) NULL) || (*value == '\0'))
00466     return((char *) NULL);
00467   return(ConstantString(value));
00468 }
00469 
00470 /*
00471 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00472 %                                                                             %
00473 %                                                                             %
00474 %                                                                             %
00475 %  G e t C o n f i g u r e O p t i o n s                                      %
00476 %                                                                             %
00477 %                                                                             %
00478 %                                                                             %
00479 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00480 %
00481 %  GetConfigureOptions() returns any Magick configuration options associated
00482 %  with the specified filename.
00483 %
00484 %  The format of the GetConfigureOptions method is:
00485 %
00486 %      LinkedListInfo *GetConfigureOptions(const char *filename,
00487 %        ExceptionInfo *exception)
00488 %
00489 %  A description of each parameter follows:
00490 %
00491 %    o filename: the configure file name.
00492 %
00493 %    o exception: return any errors or warnings in this structure.
00494 %
00495 */
00496 MagickExport LinkedListInfo *GetConfigureOptions(const char *filename,
00497   ExceptionInfo *exception)
00498 {
00499   char
00500     path[MaxTextExtent];
00501 
00502   const char
00503     *element;
00504 
00505   LinkedListInfo
00506     *options,
00507     *paths;
00508 
00509   StringInfo
00510     *xml;
00511 
00512   assert(filename != (const char *) NULL);
00513   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
00514   assert(exception != (ExceptionInfo *) NULL);
00515   (void) CopyMagickString(path,filename,MaxTextExtent);
00516   /*
00517     Load XML from configuration files to linked-list.
00518   */
00519   options=NewLinkedList(0);
00520   paths=GetConfigurePaths(filename,exception);
00521   if (paths != (LinkedListInfo *) NULL)
00522     {
00523       ResetLinkedListIterator(paths);
00524       element=(const char *) GetNextValueInLinkedList(paths);
00525       while (element != (const char *) NULL)
00526       {
00527         (void) FormatMagickString(path,MaxTextExtent,"%s%s",element,filename);
00528         (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
00529           "Searching for configure file: \"%s\"",path);
00530         xml=ConfigureFileToStringInfo(path);
00531         if (xml != (StringInfo *) NULL)
00532           (void) AppendValueToLinkedList(options,xml);
00533         element=(const char *) GetNextValueInLinkedList(paths);
00534       }
00535       paths=DestroyLinkedList(paths,RelinquishMagickMemory);
00536     }
00537 #if defined(__WINDOWS__)
00538   {
00539     char
00540       *blob;
00541 
00542     blob=(char *) NTResourceToBlob(filename);
00543     if (blob != (char *) NULL)
00544       {
00545         xml=StringToStringInfo(blob);
00546         SetStringInfoPath(xml,filename);
00547         (void) AppendValueToLinkedList(options,xml);
00548         blob=DestroyString(blob);
00549       }
00550   }
00551 #endif
00552   if (GetNumberOfElementsInLinkedList(options) == 0)
00553     (void) ThrowMagickException(exception,GetMagickModule(),ConfigureWarning,
00554       "UnableToOpenConfigureFile","`%s'",filename);
00555   ResetLinkedListIterator(options);
00556   return(options);
00557 }
00558 
00559 /*
00560 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00561 %                                                                             %
00562 %                                                                             %
00563 %                                                                             %
00564 %  G e t C o n f i g u r e P a t h s                                          %
00565 %                                                                             %
00566 %                                                                             %
00567 %                                                                             %
00568 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00569 %
00570 %  GetConfigurePaths() returns any Magick configuration paths associated
00571 %  with the specified filename.
00572 %
00573 %  The format of the GetConfigurePaths method is:
00574 %
00575 %      LinkedListInfo *GetConfigurePaths(const char *filename,
00576 %        ExceptionInfo *exception)
00577 %
00578 %  A description of each parameter follows:
00579 %
00580 %    o filename: the configure file name.
00581 %
00582 %    o exception: return any errors or warnings in this structure.
00583 %
00584 */
00585 MagickExport LinkedListInfo *GetConfigurePaths(const char *filename,
00586   ExceptionInfo *exception)
00587 {
00588   char
00589     path[MaxTextExtent];
00590 
00591   LinkedListInfo
00592     *paths;
00593 
00594   assert(filename != (const char *) NULL);
00595   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
00596   assert(exception != (ExceptionInfo *) NULL);
00597   (void) CopyMagickString(path,filename,MaxTextExtent);
00598   paths=NewLinkedList(0);
00599   {
00600     char
00601       *configure_path;
00602 
00603     /*
00604       Search $MAGICK_CONFIGURE_PATH.
00605     */
00606     configure_path=GetEnvironmentValue("MAGICK_CONFIGURE_PATH");
00607     if (configure_path != (char *) NULL)
00608       {
00609         register char
00610           *p,
00611           *q;
00612 
00613         for (p=configure_path-1; p != (char *) NULL; )
00614         {
00615           (void) CopyMagickString(path,p+1,MaxTextExtent);
00616           q=strchr(path,DirectoryListSeparator);
00617           if (q != (char *) NULL)
00618             *q='\0';
00619           q=path+strlen(path)-1;
00620           if ((q >= path) && (*q != *DirectorySeparator))
00621             (void) ConcatenateMagickString(path,DirectorySeparator,
00622               MaxTextExtent);
00623           (void) AppendValueToLinkedList(paths,ConstantString(path));
00624           p=strchr(p+1,DirectoryListSeparator);
00625         }
00626         configure_path=DestroyString(configure_path);
00627       }
00628   }
00629 #if defined(MAGICKCORE_INSTALLED_SUPPORT)
00630 #if defined(MAGICKCORE_SHARE_CONFIGURE_PATH)
00631   (void) AppendValueToLinkedList(paths,ConstantString(
00632     MAGICKCORE_SHARE_CONFIGURE_PATH));
00633 #endif
00634 #if defined(MAGICKCORE_CONFIGURE_PATH)
00635   (void) AppendValueToLinkedList(paths,ConstantString(
00636     MAGICKCORE_CONFIGURE_PATH));
00637 #endif
00638 #if defined(MAGICKCORE_DOCUMENTATION_PATH)
00639   (void) AppendValueToLinkedList(paths,ConstantString(
00640     MAGICKCORE_DOCUMENTATION_PATH));
00641 #endif
00642 #if defined(MAGICKCORE_SHARE_PATH)
00643   (void) AppendValueToLinkedList(paths,ConstantString(MAGICKCORE_SHARE_PATH));
00644 #endif
00645 #if defined(__WINDOWS__) && !(defined(MAGICKCORE_CONFIGURE_PATH) || defined(MAGICKCORE_SHARE_CONFIGURE_PATH))
00646   {
00647     char
00648       *registry_key;
00649 
00650     unsigned char
00651       *key_value;
00652 
00653     /*
00654       Locate file via registry key.
00655     */
00656     registry_key="ConfigurePath";
00657     key_value=NTRegistryKeyLookup(registry_key);
00658     if (key_value != (unsigned char *) NULL)
00659       {
00660         (void) FormatMagickString(path,MaxTextExtent,"%s%s",(char *) key_value,
00661           DirectorySeparator);
00662         (void) AppendValueToLinkedList(paths,ConstantString(path));
00663         key_value=(unsigned char *) RelinquishMagickMemory(key_value);
00664       }
00665   }
00666 #endif
00667 #else
00668   {
00669     char
00670       *home;
00671 
00672     /*
00673       Search under MAGICK_HOME.
00674     */
00675     home=GetEnvironmentValue("MAGICK_HOME");
00676     if (home != (char *) NULL)
00677       {
00678 #if !defined(MAGICKCORE_POSIX_SUPPORT)
00679         (void) FormatMagickString(path,MaxTextExtent,"%s%s",home,
00680           DirectorySeparator);
00681         (void) AppendValueToLinkedList(paths,ConstantString(path));
00682 #else
00683         (void) FormatMagickString(path,MaxTextExtent,"%s/lib/%s/",home,
00684           MAGICKCORE_CONFIGURE_RELATIVE_PATH);
00685         (void) AppendValueToLinkedList(paths,ConstantString(path));
00686         (void) FormatMagickString(path,MaxTextExtent,"%s/share/%s/",home,
00687           MAGICKCORE_SHARE_CONFIGURE_RELATIVE_PATH);
00688         (void) AppendValueToLinkedList(paths,ConstantString(path));
00689 #endif
00690         home=DestroyString(home);
00691       }
00692     }
00693   if (*GetClientPath() != '\0')
00694     {
00695 #if !defined(MAGICKCORE_POSIX_SUPPORT)
00696       (void) FormatMagickString(path,MaxTextExtent,"%s%s",GetClientPath(),
00697         DirectorySeparator);
00698       (void) AppendValueToLinkedList(paths,ConstantString(path));
00699 #else
00700       char
00701         prefix[MaxTextExtent];
00702 
00703       /*
00704         Search based on executable directory if directory is known.
00705       */
00706       (void) CopyMagickString(prefix,GetClientPath(),MaxTextExtent);
00707       ChopPathComponents(prefix,1);
00708       (void) FormatMagickString(path,MaxTextExtent,"%s/share/%s/",prefix,
00709         MAGICKCORE_SHARE_CONFIGURE_RELATIVE_PATH);
00710       (void) AppendValueToLinkedList(paths,ConstantString(path));
00711       (void) FormatMagickString(path,MaxTextExtent,"%s/lib/%s/",prefix,
00712         MAGICKCORE_CONFIGURE_RELATIVE_PATH);
00713       (void) AppendValueToLinkedList(paths,ConstantString(path));
00714 #endif
00715     }
00716 #endif
00717   {
00718     char
00719       *home;
00720 
00721     home=GetEnvironmentValue("HOME");
00722     if (home == (char *) NULL)
00723       home=GetEnvironmentValue("USERPROFILE");
00724     if (home != (char *) NULL)
00725       {
00726         /*
00727           Search $HOME/.magick.
00728         */
00729         (void) FormatMagickString(path,MaxTextExtent,"%s%s.magick%s",home,
00730           DirectorySeparator,DirectorySeparator);
00731         (void) AppendValueToLinkedList(paths,ConstantString(path));
00732         home=DestroyString(home);
00733       }
00734   }
00735 #if defined(__WINDOWS__)
00736   {
00737     char
00738       module_path[MaxTextExtent];
00739 
00740     if ((NTGetModulePath("CORE_RL_magick_.dll",module_path) != MagickFalse) ||
00741         (NTGetModulePath("CORE_DB_magick_.dll",module_path) != MagickFalse))
00742       {
00743         char
00744           *element;
00745 
00746         /*
00747           Search module path.
00748         */
00749         (void) FormatMagickString(path,MaxTextExtent,"%s%s",module_path,
00750           DirectorySeparator);
00751         element=(char *) RemoveElementByValueFromLinkedList(paths,path);
00752         if (element != (char *) NULL)
00753           element=DestroyString(element);
00754         (void) AppendValueToLinkedList(paths,ConstantString(path));
00755       }
00756     if (NTGetModulePath("Magick.dll",module_path) != MagickFalse)
00757       {
00758         /*
00759           Search PerlMagick module path.
00760         */
00761         (void) FormatMagickString(path,MaxTextExtent,"%s%s",module_path,
00762           DirectorySeparator);
00763         (void) AppendValueToLinkedList(paths,ConstantString(path));
00764         (void) FormatMagickString(path,MaxTextExtent,"%s%s",module_path,
00765           "\\inc\\lib\\auto\\Image\\Magick\\");
00766         (void) AppendValueToLinkedList(paths,ConstantString(path));
00767       }
00768   }
00769 #endif
00770   /*
00771     Search current directory.
00772   */
00773   (void) AppendValueToLinkedList(paths,ConstantString(""));
00774   return(paths);
00775 }
00776 
00777 /*
00778 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00779 %                                                                             %
00780 %                                                                             %
00781 %                                                                             %
00782 %   G e t C o n f i g u r e V a l u e                                         %
00783 %                                                                             %
00784 %                                                                             %
00785 %                                                                             %
00786 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00787 %
00788 %  GetConfigureValue() returns the value associated with the configure info.
00789 %
00790 %  The format of the GetConfigureValue method is:
00791 %
00792 %      const char *GetConfigureValue(const ConfigureInfo *configure_info)
00793 %
00794 %  A description of each parameter follows:
00795 %
00796 %    o configure_info:  The configure info.
00797 %
00798 */
00799 MagickExport const char *GetConfigureValue(const ConfigureInfo *configure_info)
00800 {
00801   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00802   assert(configure_info != (ConfigureInfo *) NULL);
00803   assert(configure_info->signature == MagickSignature);
00804   return(configure_info->value);
00805 }
00806 
00807 /*
00808 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00809 %                                                                             %
00810 %                                                                             %
00811 %                                                                             %
00812 +   I n i t i a l i z e C o n f i g u r e L i s t                             %
00813 %                                                                             %
00814 %                                                                             %
00815 %                                                                             %
00816 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00817 %
00818 %  InitializeConfigureList() initializes the configure list.
00819 %
00820 %  The format of the InitializeConfigureList method is:
00821 %
00822 %      MagickBooleanType InitializeConfigureList(ExceptionInfo *exception)
00823 %
00824 %  A description of each parameter follows.
00825 %
00826 %    o exception: return any errors or warnings in this structure.
00827 %
00828 */
00829 static MagickBooleanType InitializeConfigureList(ExceptionInfo *exception)
00830 {
00831   if ((configure_list == (LinkedListInfo *) NULL) &&
00832       (instantiate_configure == MagickFalse))
00833     {
00834       AcquireSemaphoreInfo(&configure_semaphore);
00835       if ((configure_list == (LinkedListInfo *) NULL) &&
00836           (instantiate_configure == MagickFalse))
00837         {
00838           (void) LoadConfigureLists(ConfigureFilename,exception);
00839           instantiate_configure=MagickTrue;
00840         }
00841       RelinquishSemaphoreInfo(configure_semaphore);
00842     }
00843   return(configure_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
00844 }
00845 
00846 /*
00847 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00848 %                                                                             %
00849 %                                                                             %
00850 %                                                                             %
00851 %  L i s t C o n f i g u r e I n f o                                          %
00852 %                                                                             %
00853 %                                                                             %
00854 %                                                                             %
00855 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00856 %
00857 %  ListConfigureInfo() lists the configure info to a file.
00858 %
00859 %  The format of the ListConfigureInfo method is:
00860 %
00861 %      MagickBooleanType ListConfigureInfo(FILE *file,ExceptionInfo *exception)
00862 %
00863 %  A description of each parameter follows.
00864 %
00865 %    o file:  An pointer to a FILE.
00866 %
00867 %    o exception: return any errors or warnings in this structure.
00868 %
00869 */
00870 MagickExport MagickBooleanType ListConfigureInfo(FILE *file,
00871   ExceptionInfo *exception)
00872 {
00873   const char
00874     *name,
00875     *path,
00876     *value;
00877 
00878   const ConfigureInfo
00879     **configure_info;
00880 
00881   long
00882     j;
00883 
00884   register long
00885     i;
00886 
00887   unsigned long
00888     number_options;
00889 
00890   if (file == (const FILE *) NULL)
00891     file=stdout;
00892   configure_info=GetConfigureInfoList("*",&number_options,exception);
00893   if (configure_info == (const ConfigureInfo **) NULL)
00894     return(MagickFalse);
00895   path=(const char *) NULL;
00896   for (i=0; i < (long) number_options; i++)
00897   {
00898     if (configure_info[i]->stealth != MagickFalse)
00899       continue;
00900     if ((path == (const char *) NULL) ||
00901         (LocaleCompare(path,configure_info[i]->path) != 0))
00902       {
00903         if (configure_info[i]->path != (char *) NULL)
00904           (void) fprintf(file,"\nPath: %s\n\n",configure_info[i]->path);
00905         (void) fprintf(file,"Name          Value\n");
00906         (void) fprintf(file,"-------------------------------------------------"
00907           "------------------------------\n");
00908       }
00909     path=configure_info[i]->path;
00910     name="unknown";
00911     if (configure_info[i]->name != (char *) NULL)
00912       name=configure_info[i]->name;
00913     (void) fprintf(file,"%s",name);
00914     for (j=(long) strlen(name); j <= 12; j++)
00915       (void) fprintf(file," ");
00916     (void) fprintf(file," ");
00917     value="unknown";
00918     if (configure_info[i]->value != (char *) NULL)
00919       value=configure_info[i]->value;
00920     (void) fprintf(file,"%s",value);
00921     (void) fprintf(file,"\n");
00922   }
00923   (void) fflush(file);
00924   configure_info=(const ConfigureInfo **)
00925     RelinquishMagickMemory((void *) configure_info);
00926   return(MagickTrue);
00927 }
00928 
00929 /*
00930 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00931 %                                                                             %
00932 %                                                                             %
00933 %                                                                             %
00934 +   L o a d C o n f i g u r e L i s t                                         %
00935 %                                                                             %
00936 %                                                                             %
00937 %                                                                             %
00938 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00939 %
00940 %  LoadConfigureList() loads the configure configuration file which provides a
00941 %  mapping between configure attributes and a configure name.
00942 %
00943 %  The format of the LoadConfigureList method is:
00944 %
00945 %      MagickBooleanType LoadConfigureList(const char *xml,const char *filename,
00946 %        const unsigned long depth,ExceptionInfo *exception)
00947 %
00948 %  A description of each parameter follows:
00949 %
00950 %    o xml:  The configure list in XML format.
00951 %
00952 %    o filename:  The configure list filename.
00953 %
00954 %    o depth: depth of <include /> statements.
00955 %
00956 %    o exception: return any errors or warnings in this structure.
00957 %
00958 */
00959 static MagickBooleanType LoadConfigureList(const char *xml,const char *filename,
00960   const unsigned long depth,ExceptionInfo *exception)
00961 {
00962   char
00963     keyword[MaxTextExtent],
00964     *token;
00965 
00966   ConfigureInfo
00967     *configure_info;
00968 
00969   const char
00970     *q;
00971 
00972   MagickBooleanType
00973     status;
00974 
00975   /*
00976     Load the configure map file.
00977   */
00978   (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
00979     "Loading configure file \"%s\" ...",filename);
00980   if (configure_list == (LinkedListInfo *) NULL)
00981     {
00982       configure_list=NewLinkedList(0);
00983       if (configure_list == (LinkedListInfo *) NULL)
00984         {
00985           ThrowFileException(exception,ResourceLimitError,
00986             "MemoryAllocationFailed",filename);
00987           return(MagickFalse);
00988         }
00989     }
00990   status=MagickTrue;
00991   configure_info=(ConfigureInfo *) NULL;
00992   if (xml == (char *) NULL)
00993     token=AcquireString(ConfigureMap);
00994   else
00995     token=AcquireString((char *) xml);
00996   for (q=(char *) xml; *q != '\0'; )
00997   {
00998     /*
00999       Interpret XML.
01000     */
01001     GetMagickToken(q,&q,token);
01002     if (*token == '\0')
01003       break;
01004     (void) CopyMagickString(keyword,token,MaxTextExtent);
01005     if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
01006       {
01007         /*
01008           Doctype element.
01009         */
01010         while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
01011           GetMagickToken(q,&q,token);
01012         continue;
01013       }
01014     if (LocaleNCompare(keyword,"<!--",4) == 0)
01015       {
01016         /*
01017           Comment element.
01018         */
01019         while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
01020           GetMagickToken(q,&q,token);
01021         continue;
01022       }
01023     if (LocaleCompare(keyword,"<include") == 0)
01024       {
01025         /*
01026           Include element.
01027         */
01028         while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
01029         {
01030           (void) CopyMagickString(keyword,token,MaxTextExtent);
01031           GetMagickToken(q,&q,token);
01032           if (*token != '=')
01033             continue;
01034           GetMagickToken(q,&q,token);
01035           if (LocaleCompare(keyword,"file") == 0)
01036             {
01037               if (depth > 200)
01038                 (void) ThrowMagickException(exception,GetMagickModule(),
01039                   ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token);
01040               else
01041                 {
01042                   char
01043                     path[MaxTextExtent],
01044                     *xml;
01045 
01046                   GetPathComponent(filename,HeadPath,path);
01047                   if (*path != '\0')
01048                     (void) ConcatenateMagickString(path,DirectorySeparator,
01049                       MaxTextExtent);
01050                   if (*token == *DirectorySeparator)
01051                     (void) CopyMagickString(path,token,MaxTextExtent);
01052                   else
01053                     (void) ConcatenateMagickString(path,token,MaxTextExtent);
01054                   xml=FileToString(path,~0,exception);
01055                   if (xml != (char *) NULL)
01056                     {
01057                       status=LoadConfigureList(xml,path,depth+1,exception);
01058                       xml=(char *) RelinquishMagickMemory(xml);
01059                     }
01060                 }
01061             }
01062         }
01063         continue;
01064       }
01065     if (LocaleCompare(keyword,"<configure") == 0)
01066       {
01067         /*
01068           Configure element.
01069         */
01070         configure_info=(ConfigureInfo *) AcquireMagickMemory(
01071           sizeof(*configure_info));
01072         if (configure_info == (ConfigureInfo *) NULL)
01073           ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
01074         (void) ResetMagickMemory(configure_info,0,sizeof(*configure_info));
01075         configure_info->path=ConstantString(filename);
01076         configure_info->signature=MagickSignature;
01077         continue;
01078       }
01079     if (configure_info == (ConfigureInfo *) NULL)
01080       continue;
01081     if (LocaleCompare(keyword,"/>") == 0)
01082       {
01083         status=AppendValueToLinkedList(configure_list,configure_info);
01084         if (status == MagickFalse)
01085           (void) ThrowMagickException(exception,GetMagickModule(),
01086             ResourceLimitError,"MemoryAllocationFailed","`%s'",
01087             configure_info->name);
01088         configure_info=(ConfigureInfo *) NULL;
01089       }
01090     /*
01091       Parse configure element.
01092     */
01093     GetMagickToken(q,(const char **) NULL,token);
01094     if (*token != '=')
01095       continue;
01096     GetMagickToken(q,&q,token);
01097     GetMagickToken(q,&q,token);
01098     switch (*keyword)
01099     {
01100       case 'N':
01101       case 'n':
01102       {
01103         if (LocaleCompare((char *) keyword,"name") == 0)
01104           {
01105             configure_info->name=ConstantString(token);
01106             break;
01107           }
01108         break;
01109       }
01110       case 'S':
01111       case 's':
01112       {
01113         if (LocaleCompare((char *) keyword,"stealth") == 0)
01114           {
01115             configure_info->stealth=IsMagickTrue(token);
01116             break;
01117           }
01118         break;
01119       }
01120       case 'V':
01121       case 'v':
01122       {
01123         if (LocaleCompare((char *) keyword,"value") == 0)
01124           {
01125             configure_info->value=ConstantString(token);
01126             break;
01127           }
01128         break;
01129       }
01130       default:
01131         break;
01132     }
01133   }
01134   token=(char *) RelinquishMagickMemory(token);
01135   return(status);
01136 }
01137 
01138 /*
01139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01140 %                                                                             %
01141 %                                                                             %
01142 %                                                                             %
01143 %  L o a d C o n f i g u r e L i s t s                                        %
01144 %                                                                             %
01145 %                                                                             %
01146 %                                                                             %
01147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
01148 %
01149 %  LoadConfigureList() loads one or more configure configuration files which
01150 %  provides a mapping between configure attributes and a configure name.
01151 %
01152 %  The format of the LoadConfigureLists method is:
01153 %
01154 %      MagickBooleanType LoadConfigureLists(const char *filename,
01155 %        ExceptionInfo *exception)
01156 %
01157 %  A description of each parameter follows:
01158 %
01159 %    o filename: the font file name.
01160 %
01161 %    o exception: return any errors or warnings in this structure.
01162 %
01163 */
01164 static MagickBooleanType LoadConfigureLists(const char *filename,
01165   ExceptionInfo *exception)
01166 {
01167 #if defined(MAGICKCORE_EMBEDDABLE_SUPPORT)
01168   return(LoadConfigureList(ConfigureMap,"built-in",0,exception));
01169 #else
01170   const StringInfo
01171     *option;
01172 
01173   LinkedListInfo
01174     *options;
01175 
01176   MagickStatusType
01177     status;
01178 
01179   status=MagickFalse;
01180   options=GetConfigureOptions(filename,exception);
01181   option=(const StringInfo *) GetNextValueInLinkedList(options);
01182   while (option != (const StringInfo *) NULL)
01183   {
01184     status|=LoadConfigureList((const char *) GetStringInfoDatum(option),
01185       GetStringInfoPath(option),0,exception);
01186     option=(const StringInfo *) GetNextValueInLinkedList(options);
01187   }
01188   options=DestroyConfigureOptions(options);
01189   if ((configure_list == (LinkedListInfo *) NULL) ||
01190       (IsLinkedListEmpty(configure_list) != MagickFalse))
01191     status|=LoadConfigureList(ConfigureMap,"built-in",0,exception);
01192   return(status != 0 ? MagickTrue : MagickFalse);
01193 #endif
01194 }

Generated on Thu Jul 2 12:03:14 2009 for MagickCore by  doxygen 1.5.8