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