cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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 | % MagickCore Image Configure Methods % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % July 2003 % |
| 18 | % % |
| 19 | % % |
cristy | 7e41fe8 | 2010-12-04 23:12:08 +0000 | [diff] [blame] | 20 | % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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.imagemagick.org/script/license.php % |
| 27 | % % |
| 28 | % Unless required by applicable law or agreed to in writing, software % |
| 29 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 30 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 31 | % See the License for the specific language governing permissions and % |
| 32 | % limitations under the License. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | */ |
| 38 | |
| 39 | /* |
| 40 | Include declarations. |
| 41 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 42 | #include "MagickCore/studio.h" |
| 43 | #include "MagickCore/blob.h" |
| 44 | #include "MagickCore/client.h" |
| 45 | #include "MagickCore/configure.h" |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 46 | #include "MagickCore/configure-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 47 | #include "MagickCore/exception.h" |
| 48 | #include "MagickCore/exception-private.h" |
| 49 | #include "MagickCore/hashmap.h" |
| 50 | #include "MagickCore/log.h" |
| 51 | #include "MagickCore/memory_.h" |
| 52 | #include "MagickCore/semaphore.h" |
| 53 | #include "MagickCore/string_.h" |
cristy | 7832dc2 | 2011-09-05 01:21:53 +0000 | [diff] [blame] | 54 | #include "MagickCore/string-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 55 | #include "MagickCore/token.h" |
| 56 | #include "MagickCore/utility.h" |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 57 | #include "MagickCore/utility-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 58 | #include "MagickCore/xml-tree.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 59 | |
| 60 | /* |
| 61 | Define declarations. |
| 62 | */ |
| 63 | #define ConfigureFilename "configure.xml" |
| 64 | |
| 65 | /* |
cristy | 54a531d | 2009-10-21 17:58:01 +0000 | [diff] [blame] | 66 | Typedef declarations. |
| 67 | */ |
| 68 | typedef struct _ConfigureMapInfo |
| 69 | { |
| 70 | const char |
| 71 | *name, |
| 72 | *value; |
| 73 | } ConfigureMapInfo; |
| 74 | |
| 75 | /* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 76 | Static declarations. |
| 77 | */ |
cristy | 54a531d | 2009-10-21 17:58:01 +0000 | [diff] [blame] | 78 | static const ConfigureMapInfo |
| 79 | ConfigureMap[] = |
| 80 | { |
cristy | c03a1b5 | 2009-10-23 15:43:36 +0000 | [diff] [blame] | 81 | { "NAME", "ImageMagick" } |
cristy | 54a531d | 2009-10-21 17:58:01 +0000 | [diff] [blame] | 82 | }; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 83 | |
| 84 | static LinkedListInfo |
| 85 | *configure_list = (LinkedListInfo *) NULL; |
| 86 | |
| 87 | static SemaphoreInfo |
| 88 | *configure_semaphore = (SemaphoreInfo *) NULL; |
| 89 | |
| 90 | static volatile MagickBooleanType |
| 91 | instantiate_configure = MagickFalse; |
| 92 | |
| 93 | /* |
| 94 | Forward declarations. |
| 95 | */ |
| 96 | static MagickBooleanType |
| 97 | InitializeConfigureList(ExceptionInfo *), |
| 98 | LoadConfigureLists(const char *,ExceptionInfo *); |
| 99 | |
| 100 | /* |
| 101 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 102 | % % |
| 103 | % % |
| 104 | % % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 105 | + 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 % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 106 | % % |
| 107 | % % |
| 108 | % % |
| 109 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 110 | % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 111 | % ConfigureComponentGenesis() instantiates the configure component. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 112 | % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 113 | % The format of the ConfigureComponentGenesis method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 114 | % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 115 | % MagickBooleanType ConfigureComponentGenesis(void) |
| 116 | % |
| 117 | */ |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 118 | MagickPrivate MagickBooleanType ConfigureComponentGenesis(void) |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 119 | { |
cristy | 165b609 | 2009-10-26 13:52:10 +0000 | [diff] [blame] | 120 | AcquireSemaphoreInfo(&configure_semaphore); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 121 | return(MagickTrue); |
| 122 | } |
| 123 | |
| 124 | /* |
| 125 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 126 | % % |
| 127 | % % |
| 128 | % % |
| 129 | + 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 % |
| 130 | % % |
| 131 | % % |
| 132 | % % |
| 133 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 134 | % |
| 135 | % ConfigureComponentTerminus() destroys the configure component. |
| 136 | % |
| 137 | % The format of the ConfigureComponentTerminus method is: |
| 138 | % |
| 139 | % ConfigureComponentTerminus(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 140 | % |
| 141 | */ |
| 142 | |
| 143 | static void *DestroyConfigureElement(void *configure_info) |
| 144 | { |
| 145 | register ConfigureInfo |
| 146 | *p; |
| 147 | |
| 148 | p=(ConfigureInfo *) configure_info; |
cristy | 54a531d | 2009-10-21 17:58:01 +0000 | [diff] [blame] | 149 | if (p->exempt == MagickFalse) |
| 150 | { |
| 151 | if (p->value != (char *) NULL) |
| 152 | p->value=DestroyString(p->value); |
| 153 | if (p->name != (char *) NULL) |
| 154 | p->name=DestroyString(p->name); |
| 155 | if (p->path != (char *) NULL) |
| 156 | p->path=DestroyString(p->path); |
| 157 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 158 | p=(ConfigureInfo *) RelinquishMagickMemory(p); |
| 159 | return((void *) NULL); |
| 160 | } |
| 161 | |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 162 | MagickPrivate void ConfigureComponentTerminus(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 163 | { |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 164 | if (configure_semaphore == (SemaphoreInfo *) NULL) |
| 165 | AcquireSemaphoreInfo(&configure_semaphore); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 166 | LockSemaphoreInfo(configure_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 167 | if (configure_list != (LinkedListInfo *) NULL) |
| 168 | configure_list=DestroyLinkedList(configure_list,DestroyConfigureElement); |
| 169 | configure_list=(LinkedListInfo *) NULL; |
| 170 | instantiate_configure=MagickFalse; |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 171 | UnlockSemaphoreInfo(configure_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 172 | DestroySemaphoreInfo(&configure_semaphore); |
| 173 | } |
| 174 | |
| 175 | /* |
| 176 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 177 | % % |
| 178 | % % |
| 179 | % % |
| 180 | % D e s t r o y C o n f i g u r e O p t i o n s % |
| 181 | % % |
| 182 | % % |
| 183 | % % |
| 184 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 185 | % |
| 186 | % DestroyConfigureOptions() releases memory associated with an configure |
| 187 | % options. |
| 188 | % |
| 189 | % The format of the DestroyProfiles method is: |
| 190 | % |
| 191 | % LinkedListInfo *DestroyConfigureOptions(Image *image) |
| 192 | % |
| 193 | % A description of each parameter follows: |
| 194 | % |
| 195 | % o image: the image. |
| 196 | % |
| 197 | */ |
| 198 | |
| 199 | static void *DestroyOptions(void *option) |
| 200 | { |
| 201 | return(DestroyStringInfo((StringInfo *) option)); |
| 202 | } |
| 203 | |
| 204 | MagickExport LinkedListInfo *DestroyConfigureOptions(LinkedListInfo *options) |
| 205 | { |
| 206 | assert(options != (LinkedListInfo *) NULL); |
| 207 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 208 | return(DestroyLinkedList(options,DestroyOptions)); |
| 209 | } |
| 210 | |
| 211 | /* |
| 212 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 213 | % % |
| 214 | % % |
| 215 | % % |
| 216 | + G e t C o n f i g u r e I n f o % |
| 217 | % % |
| 218 | % % |
| 219 | % % |
| 220 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 221 | % |
| 222 | % GetConfigureInfo() searches the configure list for the specified name and if |
| 223 | % found returns attributes for that element. |
| 224 | % |
| 225 | % The format of the GetConfigureInfo method is: |
| 226 | % |
| 227 | % const ConfigureInfo *GetConfigureInfo(const char *name, |
| 228 | % ExceptionInfo *exception) |
| 229 | % |
| 230 | % A description of each parameter follows: |
| 231 | % |
| 232 | % o configure_info: GetConfigureInfo() searches the configure list for the |
| 233 | % specified name and if found returns attributes for that element. |
| 234 | % |
| 235 | % o name: the configure name. |
| 236 | % |
| 237 | % o exception: return any errors or warnings in this structure. |
| 238 | % |
| 239 | */ |
| 240 | MagickExport const ConfigureInfo *GetConfigureInfo(const char *name, |
| 241 | ExceptionInfo *exception) |
| 242 | { |
| 243 | register const ConfigureInfo |
| 244 | *p; |
| 245 | |
| 246 | assert(exception != (ExceptionInfo *) NULL); |
| 247 | if ((configure_list == (LinkedListInfo *) NULL) || |
| 248 | (instantiate_configure == MagickFalse)) |
| 249 | if (InitializeConfigureList(exception) == MagickFalse) |
| 250 | return((const ConfigureInfo *) NULL); |
| 251 | if ((configure_list == (LinkedListInfo *) NULL) || |
| 252 | (IsLinkedListEmpty(configure_list) != MagickFalse)) |
| 253 | return((const ConfigureInfo *) NULL); |
| 254 | if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0)) |
| 255 | return((const ConfigureInfo *) GetValueFromLinkedList(configure_list,0)); |
| 256 | /* |
| 257 | Search for configure tag. |
| 258 | */ |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 259 | LockSemaphoreInfo(configure_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 260 | ResetLinkedListIterator(configure_list); |
| 261 | p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list); |
| 262 | while (p != (const ConfigureInfo *) NULL) |
| 263 | { |
| 264 | if (LocaleCompare(name,p->name) == 0) |
| 265 | break; |
| 266 | p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list); |
| 267 | } |
| 268 | if (p != (ConfigureInfo *) NULL) |
| 269 | (void) InsertValueInLinkedList(configure_list,0, |
| 270 | RemoveElementByValueFromLinkedList(configure_list,p)); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 271 | UnlockSemaphoreInfo(configure_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 272 | return(p); |
| 273 | } |
| 274 | |
| 275 | /* |
| 276 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 277 | % % |
| 278 | % % |
| 279 | % % |
| 280 | % G e t C o n f i g u r e I n f o L i s t % |
| 281 | % % |
| 282 | % % |
| 283 | % % |
| 284 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 285 | % |
| 286 | % GetConfigureInfoList() returns any configure options that match the |
| 287 | % specified pattern. |
| 288 | % |
| 289 | % The format of the GetConfigureInfoList function is: |
| 290 | % |
| 291 | % const ConfigureInfo **GetConfigureInfoList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 292 | % size_t *number_options,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 293 | % |
| 294 | % A description of each parameter follows: |
| 295 | % |
| 296 | % o pattern: Specifies a pointer to a text string containing a pattern. |
| 297 | % |
| 298 | % o number_options: This integer returns the number of configure options in |
| 299 | % the list. |
| 300 | % |
| 301 | % o exception: return any errors or warnings in this structure. |
| 302 | % |
| 303 | */ |
| 304 | |
| 305 | #if defined(__cplusplus) || defined(c_plusplus) |
| 306 | extern "C" { |
| 307 | #endif |
| 308 | |
| 309 | static int ConfigureInfoCompare(const void *x,const void *y) |
| 310 | { |
| 311 | const ConfigureInfo |
| 312 | **p, |
| 313 | **q; |
| 314 | |
| 315 | p=(const ConfigureInfo **) x, |
| 316 | q=(const ConfigureInfo **) y; |
| 317 | if (LocaleCompare((*p)->path,(*q)->path) == 0) |
| 318 | return(LocaleCompare((*p)->name,(*q)->name)); |
| 319 | return(LocaleCompare((*p)->path,(*q)->path)); |
| 320 | } |
| 321 | |
| 322 | #if defined(__cplusplus) || defined(c_plusplus) |
| 323 | } |
| 324 | #endif |
| 325 | |
| 326 | MagickExport const ConfigureInfo **GetConfigureInfoList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 327 | size_t *number_options,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 328 | { |
| 329 | const ConfigureInfo |
| 330 | **options; |
| 331 | |
| 332 | register const ConfigureInfo |
| 333 | *p; |
| 334 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 335 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 336 | i; |
| 337 | |
| 338 | /* |
| 339 | Allocate configure list. |
| 340 | */ |
| 341 | assert(pattern != (char *) NULL); |
| 342 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 343 | assert(number_options != (size_t *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 344 | *number_options=0; |
| 345 | p=GetConfigureInfo("*",exception); |
| 346 | if (p == (const ConfigureInfo *) NULL) |
| 347 | return((const ConfigureInfo **) NULL); |
| 348 | options=(const ConfigureInfo **) AcquireQuantumMemory((size_t) |
| 349 | GetNumberOfElementsInLinkedList(configure_list)+1UL,sizeof(*options)); |
| 350 | if (options == (const ConfigureInfo **) NULL) |
| 351 | return((const ConfigureInfo **) NULL); |
| 352 | /* |
| 353 | Generate configure list. |
| 354 | */ |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 355 | LockSemaphoreInfo(configure_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 356 | ResetLinkedListIterator(configure_list); |
| 357 | p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list); |
| 358 | for (i=0; p != (const ConfigureInfo *) NULL; ) |
| 359 | { |
| 360 | if ((p->stealth == MagickFalse) && |
| 361 | (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) |
| 362 | options[i++]=p; |
| 363 | p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list); |
| 364 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 365 | UnlockSemaphoreInfo(configure_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 366 | qsort((void *) options,(size_t) i,sizeof(*options),ConfigureInfoCompare); |
| 367 | options[i]=(ConfigureInfo *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 368 | *number_options=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 369 | return(options); |
| 370 | } |
| 371 | |
| 372 | /* |
| 373 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 374 | % % |
| 375 | % % |
| 376 | % % |
| 377 | % G e t C o n f i g u r e L i s t % |
| 378 | % % |
| 379 | % % |
| 380 | % % |
| 381 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 382 | % |
| 383 | % GetConfigureList() returns any configure options that match the specified |
| 384 | % pattern. |
| 385 | % |
| 386 | % The format of the GetConfigureList function is: |
| 387 | % |
| 388 | % char **GetConfigureList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 389 | % size_t *number_options,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 390 | % |
| 391 | % A description of each parameter follows: |
| 392 | % |
| 393 | % o pattern: Specifies a pointer to a text string containing a pattern. |
| 394 | % |
| 395 | % o number_options: This integer returns the number of options in the list. |
| 396 | % |
| 397 | % o exception: return any errors or warnings in this structure. |
| 398 | % |
| 399 | */ |
| 400 | |
| 401 | #if defined(__cplusplus) || defined(c_plusplus) |
| 402 | extern "C" { |
| 403 | #endif |
| 404 | |
| 405 | static int ConfigureCompare(const void *x,const void *y) |
| 406 | { |
| 407 | register char |
| 408 | **p, |
| 409 | **q; |
| 410 | |
| 411 | p=(char **) x; |
| 412 | q=(char **) y; |
| 413 | return(LocaleCompare(*p,*q)); |
| 414 | } |
| 415 | |
| 416 | #if defined(__cplusplus) || defined(c_plusplus) |
| 417 | } |
| 418 | #endif |
| 419 | |
| 420 | MagickExport char **GetConfigureList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 421 | size_t *number_options,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 422 | { |
| 423 | char |
| 424 | **options; |
| 425 | |
| 426 | register const ConfigureInfo |
| 427 | *p; |
| 428 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 429 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 430 | i; |
| 431 | |
| 432 | /* |
| 433 | Allocate configure list. |
| 434 | */ |
| 435 | assert(pattern != (char *) NULL); |
| 436 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 437 | assert(number_options != (size_t *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 438 | *number_options=0; |
| 439 | p=GetConfigureInfo("*",exception); |
| 440 | if (p == (const ConfigureInfo *) NULL) |
| 441 | return((char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 442 | options=(char **) AcquireQuantumMemory((size_t) |
| 443 | GetNumberOfElementsInLinkedList(configure_list)+1UL,sizeof(*options)); |
| 444 | if (options == (char **) NULL) |
| 445 | return((char **) NULL); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 446 | LockSemaphoreInfo(configure_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 447 | ResetLinkedListIterator(configure_list); |
| 448 | p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list); |
| 449 | for (i=0; p != (const ConfigureInfo *) NULL; ) |
| 450 | { |
| 451 | if ((p->stealth == MagickFalse) && |
| 452 | (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) |
| 453 | options[i++]=ConstantString(p->name); |
| 454 | p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list); |
| 455 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 456 | UnlockSemaphoreInfo(configure_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 457 | qsort((void *) options,(size_t) i,sizeof(*options),ConfigureCompare); |
| 458 | options[i]=(char *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 459 | *number_options=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 460 | return(options); |
| 461 | } |
| 462 | |
| 463 | /* |
| 464 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 465 | % % |
| 466 | % % |
| 467 | % % |
| 468 | % G e t C o n f i g u r e O p t i o n % |
| 469 | % % |
| 470 | % % |
| 471 | % % |
| 472 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 473 | % |
| 474 | % GetConfigureOption() returns the value associated with the configure option. |
| 475 | % |
| 476 | % The format of the GetConfigureOption method is: |
| 477 | % |
| 478 | % char *GetConfigureOption(const char *option) |
| 479 | % |
| 480 | % A description of each parameter follows: |
| 481 | % |
| 482 | % o configure_info: The configure info. |
| 483 | % |
| 484 | */ |
| 485 | MagickExport char *GetConfigureOption(const char *option) |
| 486 | { |
| 487 | const char |
| 488 | *value; |
| 489 | |
| 490 | const ConfigureInfo |
| 491 | *configure_info; |
| 492 | |
| 493 | ExceptionInfo |
| 494 | *exception; |
| 495 | |
| 496 | assert(option != (const char *) NULL); |
| 497 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",option); |
| 498 | exception=AcquireExceptionInfo(); |
| 499 | configure_info=GetConfigureInfo(option,exception); |
| 500 | exception=DestroyExceptionInfo(exception); |
| 501 | if (configure_info == (ConfigureInfo *) NULL) |
| 502 | return((char *) NULL); |
| 503 | value=GetConfigureValue(configure_info); |
| 504 | if ((value == (const char *) NULL) || (*value == '\0')) |
| 505 | return((char *) NULL); |
| 506 | return(ConstantString(value)); |
| 507 | } |
| 508 | |
| 509 | /* |
| 510 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 511 | % % |
| 512 | % % |
| 513 | % % |
| 514 | % G e t C o n f i g u r e O p t i o n s % |
| 515 | % % |
| 516 | % % |
| 517 | % % |
| 518 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 519 | % |
| 520 | % GetConfigureOptions() returns any Magick configuration options associated |
| 521 | % with the specified filename. |
| 522 | % |
| 523 | % The format of the GetConfigureOptions method is: |
| 524 | % |
| 525 | % LinkedListInfo *GetConfigureOptions(const char *filename, |
| 526 | % ExceptionInfo *exception) |
| 527 | % |
| 528 | % A description of each parameter follows: |
| 529 | % |
| 530 | % o filename: the configure file name. |
| 531 | % |
| 532 | % o exception: return any errors or warnings in this structure. |
| 533 | % |
| 534 | */ |
| 535 | MagickExport LinkedListInfo *GetConfigureOptions(const char *filename, |
| 536 | ExceptionInfo *exception) |
| 537 | { |
| 538 | char |
| 539 | path[MaxTextExtent]; |
| 540 | |
| 541 | const char |
| 542 | *element; |
| 543 | |
| 544 | LinkedListInfo |
| 545 | *options, |
| 546 | *paths; |
| 547 | |
| 548 | StringInfo |
| 549 | *xml; |
| 550 | |
| 551 | assert(filename != (const char *) NULL); |
| 552 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename); |
| 553 | assert(exception != (ExceptionInfo *) NULL); |
| 554 | (void) CopyMagickString(path,filename,MaxTextExtent); |
| 555 | /* |
| 556 | Load XML from configuration files to linked-list. |
| 557 | */ |
| 558 | options=NewLinkedList(0); |
| 559 | paths=GetConfigurePaths(filename,exception); |
| 560 | if (paths != (LinkedListInfo *) NULL) |
| 561 | { |
| 562 | ResetLinkedListIterator(paths); |
| 563 | element=(const char *) GetNextValueInLinkedList(paths); |
| 564 | while (element != (const char *) NULL) |
| 565 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 566 | (void) FormatLocaleString(path,MaxTextExtent,"%s%s",element,filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 567 | (void) LogMagickEvent(ConfigureEvent,GetMagickModule(), |
| 568 | "Searching for configure file: \"%s\"",path); |
| 569 | xml=ConfigureFileToStringInfo(path); |
| 570 | if (xml != (StringInfo *) NULL) |
| 571 | (void) AppendValueToLinkedList(options,xml); |
| 572 | element=(const char *) GetNextValueInLinkedList(paths); |
| 573 | } |
| 574 | paths=DestroyLinkedList(paths,RelinquishMagickMemory); |
| 575 | } |
cristy | 0157aea | 2010-04-24 21:12:18 +0000 | [diff] [blame] | 576 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 577 | { |
| 578 | char |
| 579 | *blob; |
| 580 | |
| 581 | blob=(char *) NTResourceToBlob(filename); |
| 582 | if (blob != (char *) NULL) |
| 583 | { |
| 584 | xml=StringToStringInfo(blob); |
| 585 | SetStringInfoPath(xml,filename); |
| 586 | (void) AppendValueToLinkedList(options,xml); |
| 587 | blob=DestroyString(blob); |
| 588 | } |
| 589 | } |
| 590 | #endif |
| 591 | if (GetNumberOfElementsInLinkedList(options) == 0) |
| 592 | (void) ThrowMagickException(exception,GetMagickModule(),ConfigureWarning, |
| 593 | "UnableToOpenConfigureFile","`%s'",filename); |
| 594 | ResetLinkedListIterator(options); |
| 595 | return(options); |
| 596 | } |
| 597 | |
| 598 | /* |
| 599 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 600 | % % |
| 601 | % % |
| 602 | % % |
| 603 | % G e t C o n f i g u r e P a t h s % |
| 604 | % % |
| 605 | % % |
| 606 | % % |
| 607 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 608 | % |
| 609 | % GetConfigurePaths() returns any Magick configuration paths associated |
| 610 | % with the specified filename. |
| 611 | % |
| 612 | % The format of the GetConfigurePaths method is: |
| 613 | % |
| 614 | % LinkedListInfo *GetConfigurePaths(const char *filename, |
| 615 | % ExceptionInfo *exception) |
| 616 | % |
| 617 | % A description of each parameter follows: |
| 618 | % |
| 619 | % o filename: the configure file name. |
| 620 | % |
| 621 | % o exception: return any errors or warnings in this structure. |
| 622 | % |
| 623 | */ |
| 624 | MagickExport LinkedListInfo *GetConfigurePaths(const char *filename, |
| 625 | ExceptionInfo *exception) |
| 626 | { |
cristy | 6c28ec0 | 2011-10-28 11:37:57 +0000 | [diff] [blame] | 627 | #define MagickCoreDLL "CORE_RL_MagickCore_.dll" |
| 628 | #define MagickCoreDebugDLL "CORE_DB_MagickCore_.dll" |
| 629 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 630 | char |
| 631 | path[MaxTextExtent]; |
| 632 | |
| 633 | LinkedListInfo |
| 634 | *paths; |
| 635 | |
| 636 | assert(filename != (const char *) NULL); |
| 637 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename); |
| 638 | assert(exception != (ExceptionInfo *) NULL); |
| 639 | (void) CopyMagickString(path,filename,MaxTextExtent); |
| 640 | paths=NewLinkedList(0); |
| 641 | { |
| 642 | char |
| 643 | *configure_path; |
| 644 | |
| 645 | /* |
| 646 | Search $MAGICK_CONFIGURE_PATH. |
| 647 | */ |
| 648 | configure_path=GetEnvironmentValue("MAGICK_CONFIGURE_PATH"); |
| 649 | if (configure_path != (char *) NULL) |
| 650 | { |
| 651 | register char |
| 652 | *p, |
| 653 | *q; |
| 654 | |
| 655 | for (p=configure_path-1; p != (char *) NULL; ) |
| 656 | { |
| 657 | (void) CopyMagickString(path,p+1,MaxTextExtent); |
| 658 | q=strchr(path,DirectoryListSeparator); |
| 659 | if (q != (char *) NULL) |
| 660 | *q='\0'; |
| 661 | q=path+strlen(path)-1; |
| 662 | if ((q >= path) && (*q != *DirectorySeparator)) |
| 663 | (void) ConcatenateMagickString(path,DirectorySeparator, |
| 664 | MaxTextExtent); |
| 665 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
| 666 | p=strchr(p+1,DirectoryListSeparator); |
| 667 | } |
| 668 | configure_path=DestroyString(configure_path); |
| 669 | } |
| 670 | } |
| 671 | #if defined(MAGICKCORE_INSTALLED_SUPPORT) |
cristy | 4f82071 | 2011-04-01 12:35:43 +0000 | [diff] [blame] | 672 | #if defined(MAGICKCORE_SHARE_PATH) |
cristy | 6c28ec0 | 2011-10-28 11:37:57 +0000 | [diff] [blame] | 673 | (void) AppendValueToLinkedList(paths,ConstantString(MAGICKCORE_SHARE_PATH)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 674 | #endif |
cristy | 670aa3c | 2011-11-03 00:54:00 +0000 | [diff] [blame^] | 675 | #if defined(MAGICKCORE_SHAREARCH_PATH) |
| 676 | (void) AppendValueToLinkedList(paths,ConstantString( |
| 677 | MAGICKCORE_SHAREARCH_PATH)); |
| 678 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 679 | #if defined(MAGICKCORE_CONFIGURE_PATH) |
| 680 | (void) AppendValueToLinkedList(paths,ConstantString( |
| 681 | MAGICKCORE_CONFIGURE_PATH)); |
| 682 | #endif |
| 683 | #if defined(MAGICKCORE_DOCUMENTATION_PATH) |
| 684 | (void) AppendValueToLinkedList(paths,ConstantString( |
| 685 | MAGICKCORE_DOCUMENTATION_PATH)); |
| 686 | #endif |
cristy | 4f82071 | 2011-04-01 12:35:43 +0000 | [diff] [blame] | 687 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !(defined(MAGICKCORE_CONFIGURE_PATH) || defined(MAGICKCORE_SHARE_PATH)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 688 | { |
| 689 | char |
| 690 | *registry_key; |
| 691 | |
| 692 | unsigned char |
| 693 | *key_value; |
| 694 | |
| 695 | /* |
| 696 | Locate file via registry key. |
| 697 | */ |
| 698 | registry_key="ConfigurePath"; |
| 699 | key_value=NTRegistryKeyLookup(registry_key); |
| 700 | if (key_value != (unsigned char *) NULL) |
| 701 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 702 | (void) FormatLocaleString(path,MaxTextExtent,"%s%s",(char *) key_value, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 703 | DirectorySeparator); |
| 704 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
| 705 | key_value=(unsigned char *) RelinquishMagickMemory(key_value); |
| 706 | } |
| 707 | } |
| 708 | #endif |
| 709 | #else |
| 710 | { |
| 711 | char |
| 712 | *home; |
| 713 | |
| 714 | /* |
| 715 | Search under MAGICK_HOME. |
| 716 | */ |
| 717 | home=GetEnvironmentValue("MAGICK_HOME"); |
| 718 | if (home != (char *) NULL) |
| 719 | { |
| 720 | #if !defined(MAGICKCORE_POSIX_SUPPORT) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 721 | (void) FormatLocaleString(path,MaxTextExtent,"%s%s",home, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 722 | DirectorySeparator); |
| 723 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
| 724 | #else |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 725 | (void) FormatLocaleString(path,MaxTextExtent,"%s/etc/%s/",home, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 726 | MAGICKCORE_CONFIGURE_RELATIVE_PATH); |
| 727 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 728 | (void) FormatLocaleString(path,MaxTextExtent,"%s/share/%s/",home, |
cristy | 4f82071 | 2011-04-01 12:35:43 +0000 | [diff] [blame] | 729 | MAGICKCORE_SHARE_RELATIVE_PATH); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 730 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
| 731 | #endif |
| 732 | home=DestroyString(home); |
| 733 | } |
| 734 | } |
| 735 | if (*GetClientPath() != '\0') |
| 736 | { |
| 737 | #if !defined(MAGICKCORE_POSIX_SUPPORT) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 738 | (void) FormatLocaleString(path,MaxTextExtent,"%s%s",GetClientPath(), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 739 | DirectorySeparator); |
| 740 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
| 741 | #else |
| 742 | char |
| 743 | prefix[MaxTextExtent]; |
| 744 | |
| 745 | /* |
| 746 | Search based on executable directory if directory is known. |
| 747 | */ |
| 748 | (void) CopyMagickString(prefix,GetClientPath(),MaxTextExtent); |
| 749 | ChopPathComponents(prefix,1); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 750 | (void) FormatLocaleString(path,MaxTextExtent,"%s/etc/%s/",prefix, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 751 | MAGICKCORE_CONFIGURE_RELATIVE_PATH); |
| 752 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 753 | (void) FormatLocaleString(path,MaxTextExtent,"%s/share/%s/",prefix, |
cristy | 4f82071 | 2011-04-01 12:35:43 +0000 | [diff] [blame] | 754 | MAGICKCORE_SHARE_RELATIVE_PATH); |
| 755 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 756 | #endif |
| 757 | } |
cristy | 51b1ac5 | 2010-10-30 02:27:14 +0000 | [diff] [blame] | 758 | /* |
| 759 | Search current directory. |
| 760 | */ |
| 761 | (void) AppendValueToLinkedList(paths,ConstantString("")); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 762 | #endif |
| 763 | { |
| 764 | char |
| 765 | *home; |
| 766 | |
| 767 | home=GetEnvironmentValue("HOME"); |
| 768 | if (home == (char *) NULL) |
| 769 | home=GetEnvironmentValue("USERPROFILE"); |
| 770 | if (home != (char *) NULL) |
| 771 | { |
| 772 | /* |
| 773 | Search $HOME/.magick. |
| 774 | */ |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 775 | (void) FormatLocaleString(path,MaxTextExtent,"%s%s.magick%s",home, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 776 | DirectorySeparator,DirectorySeparator); |
| 777 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
| 778 | home=DestroyString(home); |
| 779 | } |
| 780 | } |
cristy | 0157aea | 2010-04-24 21:12:18 +0000 | [diff] [blame] | 781 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 782 | { |
| 783 | char |
| 784 | module_path[MaxTextExtent]; |
| 785 | |
cristy | 6c28ec0 | 2011-10-28 11:37:57 +0000 | [diff] [blame] | 786 | if ((NTGetModulePath(MagickCoreDLL,module_path) != MagickFalse) || |
| 787 | (NTGetModulePath(MagickCoreDebugDLL,module_path) != MagickFalse)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 788 | { |
| 789 | char |
| 790 | *element; |
| 791 | |
| 792 | /* |
| 793 | Search module path. |
| 794 | */ |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 795 | (void) FormatLocaleString(path,MaxTextExtent,"%s%s",module_path, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 796 | DirectorySeparator); |
| 797 | element=(char *) RemoveElementByValueFromLinkedList(paths,path); |
| 798 | if (element != (char *) NULL) |
| 799 | element=DestroyString(element); |
| 800 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
| 801 | } |
| 802 | if (NTGetModulePath("Magick.dll",module_path) != MagickFalse) |
| 803 | { |
| 804 | /* |
| 805 | Search PerlMagick module path. |
| 806 | */ |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 807 | (void) FormatLocaleString(path,MaxTextExtent,"%s%s",module_path, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 808 | DirectorySeparator); |
| 809 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 810 | (void) FormatLocaleString(path,MaxTextExtent,"%s%s",module_path, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 811 | "\\inc\\lib\\auto\\Image\\Magick\\"); |
| 812 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
| 813 | } |
| 814 | } |
| 815 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 816 | return(paths); |
| 817 | } |
| 818 | |
| 819 | /* |
| 820 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 821 | % % |
| 822 | % % |
| 823 | % % |
| 824 | % G e t C o n f i g u r e V a l u e % |
| 825 | % % |
| 826 | % % |
| 827 | % % |
| 828 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 829 | % |
| 830 | % GetConfigureValue() returns the value associated with the configure info. |
| 831 | % |
| 832 | % The format of the GetConfigureValue method is: |
| 833 | % |
| 834 | % const char *GetConfigureValue(const ConfigureInfo *configure_info) |
| 835 | % |
| 836 | % A description of each parameter follows: |
| 837 | % |
| 838 | % o configure_info: The configure info. |
| 839 | % |
| 840 | */ |
| 841 | MagickExport const char *GetConfigureValue(const ConfigureInfo *configure_info) |
| 842 | { |
| 843 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 844 | assert(configure_info != (ConfigureInfo *) NULL); |
| 845 | assert(configure_info->signature == MagickSignature); |
| 846 | return(configure_info->value); |
| 847 | } |
| 848 | |
| 849 | /* |
| 850 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 851 | % % |
| 852 | % % |
| 853 | % % |
| 854 | + I n i t i a l i z e C o n f i g u r e L i s t % |
| 855 | % % |
| 856 | % % |
| 857 | % % |
| 858 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 859 | % |
| 860 | % InitializeConfigureList() initializes the configure list. |
| 861 | % |
| 862 | % The format of the InitializeConfigureList method is: |
| 863 | % |
| 864 | % MagickBooleanType InitializeConfigureList(ExceptionInfo *exception) |
| 865 | % |
| 866 | % A description of each parameter follows. |
| 867 | % |
| 868 | % o exception: return any errors or warnings in this structure. |
| 869 | % |
| 870 | */ |
| 871 | static MagickBooleanType InitializeConfigureList(ExceptionInfo *exception) |
| 872 | { |
| 873 | if ((configure_list == (LinkedListInfo *) NULL) && |
| 874 | (instantiate_configure == MagickFalse)) |
| 875 | { |
cristy | 4e1dff6 | 2009-10-25 20:36:03 +0000 | [diff] [blame] | 876 | if (configure_semaphore == (SemaphoreInfo *) NULL) |
| 877 | AcquireSemaphoreInfo(&configure_semaphore); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 878 | LockSemaphoreInfo(configure_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 879 | if ((configure_list == (LinkedListInfo *) NULL) && |
| 880 | (instantiate_configure == MagickFalse)) |
| 881 | { |
| 882 | (void) LoadConfigureLists(ConfigureFilename,exception); |
| 883 | instantiate_configure=MagickTrue; |
| 884 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 885 | UnlockSemaphoreInfo(configure_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 886 | } |
| 887 | return(configure_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); |
| 888 | } |
| 889 | |
| 890 | /* |
| 891 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 892 | % % |
| 893 | % % |
| 894 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 895 | % L i s t C o n f i g u r e I n f o % |
| 896 | % % |
| 897 | % % |
| 898 | % % |
| 899 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 900 | % |
| 901 | % ListConfigureInfo() lists the configure info to a file. |
| 902 | % |
| 903 | % The format of the ListConfigureInfo method is: |
| 904 | % |
| 905 | % MagickBooleanType ListConfigureInfo(FILE *file,ExceptionInfo *exception) |
| 906 | % |
| 907 | % A description of each parameter follows. |
| 908 | % |
| 909 | % o file: An pointer to a FILE. |
| 910 | % |
| 911 | % o exception: return any errors or warnings in this structure. |
| 912 | % |
| 913 | */ |
| 914 | MagickExport MagickBooleanType ListConfigureInfo(FILE *file, |
| 915 | ExceptionInfo *exception) |
| 916 | { |
| 917 | const char |
| 918 | *name, |
| 919 | *path, |
| 920 | *value; |
| 921 | |
| 922 | const ConfigureInfo |
| 923 | **configure_info; |
| 924 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 925 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 926 | i; |
| 927 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 928 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 929 | number_options; |
| 930 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 931 | ssize_t |
| 932 | j; |
| 933 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 934 | if (file == (const FILE *) NULL) |
| 935 | file=stdout; |
| 936 | configure_info=GetConfigureInfoList("*",&number_options,exception); |
| 937 | if (configure_info == (const ConfigureInfo **) NULL) |
| 938 | return(MagickFalse); |
| 939 | path=(const char *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 940 | for (i=0; i < (ssize_t) number_options; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 941 | { |
| 942 | if (configure_info[i]->stealth != MagickFalse) |
| 943 | continue; |
| 944 | if ((path == (const char *) NULL) || |
| 945 | (LocaleCompare(path,configure_info[i]->path) != 0)) |
| 946 | { |
| 947 | if (configure_info[i]->path != (char *) NULL) |
cristy | 1e60481 | 2011-05-19 18:07:50 +0000 | [diff] [blame] | 948 | (void) FormatLocaleFile(file,"\nPath: %s\n\n", |
| 949 | configure_info[i]->path); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 950 | (void) FormatLocaleFile(file,"Name Value\n"); |
cristy | 1e60481 | 2011-05-19 18:07:50 +0000 | [diff] [blame] | 951 | (void) FormatLocaleFile(file, |
| 952 | "-------------------------------------------------" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 953 | "------------------------------\n"); |
| 954 | } |
| 955 | path=configure_info[i]->path; |
| 956 | name="unknown"; |
| 957 | if (configure_info[i]->name != (char *) NULL) |
| 958 | name=configure_info[i]->name; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 959 | (void) FormatLocaleFile(file,"%s",name); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 960 | for (j=(ssize_t) strlen(name); j <= 12; j++) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 961 | (void) FormatLocaleFile(file," "); |
| 962 | (void) FormatLocaleFile(file," "); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 963 | value="unknown"; |
| 964 | if (configure_info[i]->value != (char *) NULL) |
| 965 | value=configure_info[i]->value; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 966 | (void) FormatLocaleFile(file,"%s",value); |
| 967 | (void) FormatLocaleFile(file,"\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 968 | } |
| 969 | (void) fflush(file); |
| 970 | configure_info=(const ConfigureInfo **) |
| 971 | RelinquishMagickMemory((void *) configure_info); |
| 972 | return(MagickTrue); |
| 973 | } |
| 974 | |
| 975 | /* |
| 976 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 977 | % % |
| 978 | % % |
| 979 | % % |
| 980 | + L o a d C o n f i g u r e L i s t % |
| 981 | % % |
| 982 | % % |
| 983 | % % |
| 984 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 985 | % |
| 986 | % LoadConfigureList() loads the configure configuration file which provides a |
| 987 | % mapping between configure attributes and a configure name. |
| 988 | % |
| 989 | % The format of the LoadConfigureList method is: |
| 990 | % |
| 991 | % MagickBooleanType LoadConfigureList(const char *xml,const char *filename, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 992 | % const size_t depth,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 993 | % |
| 994 | % A description of each parameter follows: |
| 995 | % |
| 996 | % o xml: The configure list in XML format. |
| 997 | % |
| 998 | % o filename: The configure list filename. |
| 999 | % |
| 1000 | % o depth: depth of <include /> statements. |
| 1001 | % |
| 1002 | % o exception: return any errors or warnings in this structure. |
| 1003 | % |
| 1004 | */ |
| 1005 | static MagickBooleanType LoadConfigureList(const char *xml,const char *filename, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1006 | const size_t depth,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1007 | { |
| 1008 | char |
| 1009 | keyword[MaxTextExtent], |
| 1010 | *token; |
| 1011 | |
| 1012 | ConfigureInfo |
| 1013 | *configure_info; |
| 1014 | |
| 1015 | const char |
| 1016 | *q; |
| 1017 | |
| 1018 | MagickBooleanType |
| 1019 | status; |
| 1020 | |
| 1021 | /* |
| 1022 | Load the configure map file. |
| 1023 | */ |
| 1024 | (void) LogMagickEvent(ConfigureEvent,GetMagickModule(), |
| 1025 | "Loading configure file \"%s\" ...",filename); |
| 1026 | if (configure_list == (LinkedListInfo *) NULL) |
| 1027 | { |
| 1028 | configure_list=NewLinkedList(0); |
| 1029 | if (configure_list == (LinkedListInfo *) NULL) |
| 1030 | { |
| 1031 | ThrowFileException(exception,ResourceLimitError, |
| 1032 | "MemoryAllocationFailed",filename); |
| 1033 | return(MagickFalse); |
| 1034 | } |
| 1035 | } |
| 1036 | status=MagickTrue; |
| 1037 | configure_info=(ConfigureInfo *) NULL; |
cristy | 54a531d | 2009-10-21 17:58:01 +0000 | [diff] [blame] | 1038 | token=AcquireString((char *) xml); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1039 | for (q=(char *) xml; *q != '\0'; ) |
| 1040 | { |
| 1041 | /* |
| 1042 | Interpret XML. |
| 1043 | */ |
| 1044 | GetMagickToken(q,&q,token); |
| 1045 | if (*token == '\0') |
| 1046 | break; |
| 1047 | (void) CopyMagickString(keyword,token,MaxTextExtent); |
| 1048 | if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0) |
| 1049 | { |
| 1050 | /* |
| 1051 | Doctype element. |
| 1052 | */ |
| 1053 | while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0')) |
| 1054 | GetMagickToken(q,&q,token); |
| 1055 | continue; |
| 1056 | } |
| 1057 | if (LocaleNCompare(keyword,"<!--",4) == 0) |
| 1058 | { |
| 1059 | /* |
| 1060 | Comment element. |
| 1061 | */ |
| 1062 | while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0')) |
| 1063 | GetMagickToken(q,&q,token); |
| 1064 | continue; |
| 1065 | } |
| 1066 | if (LocaleCompare(keyword,"<include") == 0) |
| 1067 | { |
| 1068 | /* |
| 1069 | Include element. |
| 1070 | */ |
| 1071 | while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0')) |
| 1072 | { |
| 1073 | (void) CopyMagickString(keyword,token,MaxTextExtent); |
| 1074 | GetMagickToken(q,&q,token); |
| 1075 | if (*token != '=') |
| 1076 | continue; |
| 1077 | GetMagickToken(q,&q,token); |
| 1078 | if (LocaleCompare(keyword,"file") == 0) |
| 1079 | { |
| 1080 | if (depth > 200) |
| 1081 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 1082 | ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token); |
| 1083 | else |
| 1084 | { |
| 1085 | char |
| 1086 | path[MaxTextExtent], |
| 1087 | *xml; |
| 1088 | |
| 1089 | GetPathComponent(filename,HeadPath,path); |
| 1090 | if (*path != '\0') |
| 1091 | (void) ConcatenateMagickString(path,DirectorySeparator, |
| 1092 | MaxTextExtent); |
| 1093 | if (*token == *DirectorySeparator) |
| 1094 | (void) CopyMagickString(path,token,MaxTextExtent); |
| 1095 | else |
| 1096 | (void) ConcatenateMagickString(path,token,MaxTextExtent); |
| 1097 | xml=FileToString(path,~0,exception); |
| 1098 | if (xml != (char *) NULL) |
| 1099 | { |
| 1100 | status=LoadConfigureList(xml,path,depth+1,exception); |
| 1101 | xml=(char *) RelinquishMagickMemory(xml); |
| 1102 | } |
| 1103 | } |
| 1104 | } |
| 1105 | } |
| 1106 | continue; |
| 1107 | } |
| 1108 | if (LocaleCompare(keyword,"<configure") == 0) |
| 1109 | { |
| 1110 | /* |
| 1111 | Configure element. |
| 1112 | */ |
| 1113 | configure_info=(ConfigureInfo *) AcquireMagickMemory( |
| 1114 | sizeof(*configure_info)); |
| 1115 | if (configure_info == (ConfigureInfo *) NULL) |
| 1116 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 1117 | (void) ResetMagickMemory(configure_info,0,sizeof(*configure_info)); |
| 1118 | configure_info->path=ConstantString(filename); |
cristy | 54a531d | 2009-10-21 17:58:01 +0000 | [diff] [blame] | 1119 | configure_info->exempt=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1120 | configure_info->signature=MagickSignature; |
| 1121 | continue; |
| 1122 | } |
| 1123 | if (configure_info == (ConfigureInfo *) NULL) |
| 1124 | continue; |
| 1125 | if (LocaleCompare(keyword,"/>") == 0) |
| 1126 | { |
| 1127 | status=AppendValueToLinkedList(configure_list,configure_info); |
| 1128 | if (status == MagickFalse) |
| 1129 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 1130 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
| 1131 | configure_info->name); |
| 1132 | configure_info=(ConfigureInfo *) NULL; |
| 1133 | } |
| 1134 | /* |
| 1135 | Parse configure element. |
| 1136 | */ |
| 1137 | GetMagickToken(q,(const char **) NULL,token); |
| 1138 | if (*token != '=') |
| 1139 | continue; |
| 1140 | GetMagickToken(q,&q,token); |
| 1141 | GetMagickToken(q,&q,token); |
| 1142 | switch (*keyword) |
| 1143 | { |
| 1144 | case 'N': |
| 1145 | case 'n': |
| 1146 | { |
| 1147 | if (LocaleCompare((char *) keyword,"name") == 0) |
| 1148 | { |
| 1149 | configure_info->name=ConstantString(token); |
| 1150 | break; |
| 1151 | } |
| 1152 | break; |
| 1153 | } |
| 1154 | case 'S': |
| 1155 | case 's': |
| 1156 | { |
| 1157 | if (LocaleCompare((char *) keyword,"stealth") == 0) |
| 1158 | { |
| 1159 | configure_info->stealth=IsMagickTrue(token); |
| 1160 | break; |
| 1161 | } |
| 1162 | break; |
| 1163 | } |
| 1164 | case 'V': |
| 1165 | case 'v': |
| 1166 | { |
| 1167 | if (LocaleCompare((char *) keyword,"value") == 0) |
| 1168 | { |
| 1169 | configure_info->value=ConstantString(token); |
| 1170 | break; |
| 1171 | } |
| 1172 | break; |
| 1173 | } |
| 1174 | default: |
| 1175 | break; |
| 1176 | } |
| 1177 | } |
| 1178 | token=(char *) RelinquishMagickMemory(token); |
| 1179 | return(status); |
| 1180 | } |
| 1181 | |
| 1182 | /* |
| 1183 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1184 | % % |
| 1185 | % % |
| 1186 | % % |
| 1187 | % L o a d C o n f i g u r e L i s t s % |
| 1188 | % % |
| 1189 | % % |
| 1190 | % % |
| 1191 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1192 | % |
| 1193 | % LoadConfigureList() loads one or more configure configuration files which |
| 1194 | % provides a mapping between configure attributes and a configure name. |
| 1195 | % |
| 1196 | % The format of the LoadConfigureLists method is: |
| 1197 | % |
| 1198 | % MagickBooleanType LoadConfigureLists(const char *filename, |
| 1199 | % ExceptionInfo *exception) |
| 1200 | % |
| 1201 | % A description of each parameter follows: |
| 1202 | % |
| 1203 | % o filename: the font file name. |
| 1204 | % |
| 1205 | % o exception: return any errors or warnings in this structure. |
| 1206 | % |
| 1207 | */ |
| 1208 | static MagickBooleanType LoadConfigureLists(const char *filename, |
| 1209 | ExceptionInfo *exception) |
| 1210 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1211 | const StringInfo |
| 1212 | *option; |
| 1213 | |
| 1214 | LinkedListInfo |
| 1215 | *options; |
| 1216 | |
| 1217 | MagickStatusType |
| 1218 | status; |
| 1219 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1220 | register ssize_t |
cristy | 54a531d | 2009-10-21 17:58:01 +0000 | [diff] [blame] | 1221 | i; |
| 1222 | |
| 1223 | /* |
| 1224 | Load built-in configure map. |
| 1225 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1226 | status=MagickFalse; |
cristy | 54a531d | 2009-10-21 17:58:01 +0000 | [diff] [blame] | 1227 | if (configure_list == (LinkedListInfo *) NULL) |
| 1228 | { |
| 1229 | configure_list=NewLinkedList(0); |
| 1230 | if (configure_list == (LinkedListInfo *) NULL) |
| 1231 | { |
| 1232 | ThrowFileException(exception,ResourceLimitError, |
| 1233 | "MemoryAllocationFailed",filename); |
| 1234 | return(MagickFalse); |
| 1235 | } |
| 1236 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1237 | for (i=0; i < (ssize_t) (sizeof(ConfigureMap)/sizeof(*ConfigureMap)); i++) |
cristy | 54a531d | 2009-10-21 17:58:01 +0000 | [diff] [blame] | 1238 | { |
| 1239 | ConfigureInfo |
| 1240 | *configure_info; |
| 1241 | |
| 1242 | register const ConfigureMapInfo |
| 1243 | *p; |
| 1244 | |
| 1245 | p=ConfigureMap+i; |
| 1246 | configure_info=(ConfigureInfo *) AcquireMagickMemory( |
| 1247 | sizeof(*configure_info)); |
| 1248 | if (configure_info == (ConfigureInfo *) NULL) |
| 1249 | { |
| 1250 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 1251 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
| 1252 | configure_info->name); |
| 1253 | continue; |
| 1254 | } |
| 1255 | (void) ResetMagickMemory(configure_info,0,sizeof(*configure_info)); |
| 1256 | configure_info->path=(char *) "[built-in]"; |
| 1257 | configure_info->name=(char *) p->name; |
| 1258 | configure_info->value=(char *) p->value; |
| 1259 | configure_info->exempt=MagickTrue; |
| 1260 | configure_info->signature=MagickSignature; |
| 1261 | status=AppendValueToLinkedList(configure_list,configure_info); |
| 1262 | if (status == MagickFalse) |
| 1263 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 1264 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
| 1265 | configure_info->name); |
| 1266 | } |
| 1267 | /* |
| 1268 | Load external configure map. |
| 1269 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1270 | options=GetConfigureOptions(filename,exception); |
| 1271 | option=(const StringInfo *) GetNextValueInLinkedList(options); |
| 1272 | while (option != (const StringInfo *) NULL) |
| 1273 | { |
| 1274 | status|=LoadConfigureList((const char *) GetStringInfoDatum(option), |
| 1275 | GetStringInfoPath(option),0,exception); |
| 1276 | option=(const StringInfo *) GetNextValueInLinkedList(options); |
| 1277 | } |
| 1278 | options=DestroyConfigureOptions(options); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1279 | return(status != 0 ? MagickTrue : MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1280 | } |