2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 % DDDD EEEEE L EEEEE GGGG AAA TTTTT EEEEE %
6 % D D E L E G A A T E %
7 % D D EEE L EEE G GG AAAAA T EEE %
8 % D D E L E G G A A T E %
9 % DDDD EEEEE LLLLL EEEEE GGG A A T EEEEE %
12 % MagickCore Methods to Read/Write/Invoke Delegates %
19 % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
20 % dedicated to making software imaging solutions freely available. %
22 % You may not use this file except in compliance with the License. You may %
23 % obtain a copy of the License at %
25 % http://www.imagemagick.org/script/license.php %
27 % Unless required by applicable law or agreed to in writing, software %
28 % distributed under the License is distributed on an "AS IS" BASIS, %
29 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
30 % See the License for the specific language governing permissions and %
31 % limitations under the License. %
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 % The Delegates methods associate a set of commands with a particular
36 % image format. ImageMagick uses delegates for formats it does not handle
39 % Thanks to Bob Friesenhahn for the initial inspiration and design of the
48 #include "MagickCore/studio.h"
49 #include "MagickCore/property.h"
50 #include "MagickCore/blob.h"
51 #include "MagickCore/client.h"
52 #include "MagickCore/configure.h"
53 #include "MagickCore/constitute.h"
54 #include "MagickCore/delegate.h"
55 #include "MagickCore/delegate-private.h"
56 #include "MagickCore/exception.h"
57 #include "MagickCore/exception-private.h"
58 #include "MagickCore/hashmap.h"
59 #include "MagickCore/list.h"
60 #include "MagickCore/memory_.h"
61 #include "MagickCore/policy.h"
62 #include "MagickCore/resource_.h"
63 #include "MagickCore/semaphore.h"
64 #include "MagickCore/string_.h"
65 #include "MagickCore/token.h"
66 #include "MagickCore/utility.h"
67 #include "MagickCore/utility-private.h"
68 #include "MagickCore/xml-tree.h"
73 #define DelegateFilename "delegates.xml"
79 *DelegateMap = (const char *)
80 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
82 " <delegate decode=\"autotrace\" stealth=\"True\" command=\""autotrace" -output-format svg -output-file "%o" "%i"\"/>"
83 " <delegate decode=\"avi:decode\" stealth=\"True\" command=\""mplayer" "%i" -really-quiet -ao null -vo png:z=3\"/>"
84 " <delegate decode=\"browse\" stealth=\"True\" spawn=\"True\" command=\""xdg-open" http://www.imagemagick.org/\"/>"
85 " <delegate decode=\"cgm\" thread-support=\"False\" command=\""ralcgm" -d ps -oC < "%i" > "%o" 2> "%u"\"/>"
86 " <delegate decode=\"dng:decode\" command=\""/usr/bin/ufraw-batch" --silent --wb=camera --black-point=auto --exposure=auto --create-id=also --out-type=ppm16 "--output=%u.pnm" "%i"\"/>"
87 " <delegate decode=\"edit\" stealth=\"True\" command=\""xterm" -title "Edit Image Comment" -e vi "%o"\"/>"
88 " <delegate decode=\"eps\" encode=\"pdf\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pdfwrite" "-sOutputFile=%o" "-f%i"\"/>"
89 " <delegate decode=\"eps\" encode=\"ps\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pswrite" "-sOutputFile=%o" "-f%i"\"/>"
90 " <delegate decode=\"fig\" command=\""fig2dev" -L ps "%i" "%o"\"/>"
91 " <delegate decode=\"gplt\" command=\""echo" "set size 1.25,0.62 set terminal postscript portrait color solid; set output "%o"; load "%i"" > "%u";"gnuplot" "%u"\"/>"
92 " <delegate decode=\"hpg\" command=\""hp2xx" -q -m eps -f `basename "%o"` "%i" mv -f `basename "%o"` "%o"\"/>"
93 " <delegate decode=\"hpgl\" command=\"if [ -e hp2xx -o -e /usr/bin/hp2xx ]; then hp2xx -q -m eps -f `basename "%o"` "%i" mv -f `basename "%o"` "%o else echo "You need to install hp2xx to use HPGL files with ImageMagick." exit 1 fi\"/>"
94 " <delegate decode=\"htm\" command=\""html2ps" -U -o "%o" "%i"\"/>"
95 " <delegate decode=\"html\" command=\""html2ps" -U -o "%o" "%i"\"/>"
96 " <delegate decode=\"https\" command=\""wget" -q -O "%o" "https:%M"\"/>"
97 " <delegate decode=\"ilbm\" command=\""ilbmtoppm" "%i" > "%o"\"/>"
98 " <delegate decode=\"man\" command=\""groff" -man -Tps "%i" > "%o"\"/>"
99 " <delegate decode=\"mpeg:decode\" stealth=\"True\" command=\""ffmpeg" -i "%i" -vcodec pam -an -f rawvideo -y "%u0.pam" 2;> "%Z"\"/>"
100 " <delegate decode=\"null\" encode=\"mpeg:encode\" stealth=\"True\" command=\""ffmpeg" "%M%%d.jpg" "%u.%m" 2;> "%Z"\"/>"
101 " <delegate decode=\"pcl:color\" stealth=\"True\" command=\""pcl6" -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=ppmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "%s"\"/>"
102 " <delegate decode=\"pcl:cmyk\" stealth=\"True\" command=\""pcl6" -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=bmpsep8" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "%s"\"/>"
103 " <delegate decode=\"pcl:mono\" stealth=\"True\" command=\""pcl6" -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pbmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "%s"\"/>"
104 " <delegate decode=\"pdf\" encode=\"eps\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=epswrite" "-sOutputFile=%o" "-f%i"\"/>"
105 " <delegate decode=\"pdf\" encode=\"ps\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pswrite" "-sOutputFile=%o" "-f%i"\"/>"
106 " <delegate decode=\"pnm\" encode=\"ilbm\" mode=\"encode\" command=\""ppmtoilbm" -24if "%i" > "%o"\"/>"
107 " <delegate decode=\"pnm\" encode=\"launch\" mode=\"encode\" command=\""gimp" "%i"\"/>"
108 " <delegate decode=\"pov\" command=\""povray" "+i"%i"" -D0 +o"%o" +fn%q +w%w +h%h +a -q9 -kfi"%s" -kff"%n" "convert" -concatenate "%o*.png" "%o"\"/>"
109 " <delegate decode=\"ps\" encode=\"eps\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=epswrite" "-sOutputFile=%o" "-f%i"\"/>"
110 " <delegate decode=\"ps\" encode=\"pdf\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pdfwrite" "-sOutputFile=%o" "-f%i"\"/>"
111 " <delegate decode=\"ps\" encode=\"print\" mode=\"encode\" command=\"lpr "%i"\"/>"
112 " <delegate decode=\"ps:alpha\" stealth=\"True\" command=\""gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pngalpha" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"\"/>"
113 " <delegate decode=\"ps:bbox\" stealth=\"True\" command=\""gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=bbox" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"\"/>"
114 " <delegate decode=\"ps:cmyk\" stealth=\"True\" command=\""gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=bmpsep8" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"\"/>"
115 " <delegate decode=\"ps:color\" stealth=\"True\" command=\""gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"\"/>"
116 " <delegate decode=\"ps:mono\" stealth=\"True\" command=\""gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"\"/>"
117 " <delegate decode=\"rgba\" encode=\"rle\" mode=\"encode\" command=\""rawtorle" -o "%o" -v "%i"\"/>"
118 " <delegate decode=\"scan\" command=\""scanimage" -d "%i" > "%o"\"/>"
119 " <delegate encode=\"show\" spawn=\"True\" command=\""/usr/local/bin/display" -immutable -delay 0 -window-group %g -title "%l of %f" "temporary:%i"\"/>"
120 " <delegate decode=\"shtml\" command=\""html2ps" -U -o "%o" "%i"\"/>"
121 " <delegate decode=\"svg\" command=\""rsvg" "%i" "%o"\"/>"
122 " <delegate decode=\"txt\" encode=\"ps\" mode=\"bi\" command=\""enscript" -o "%o" "%i"\"/>"
123 " <delegate encode=\"win\" stealth=\"True\" spawn=\"True\" command=\""/usr/local/bin/display" -immutable -delay 0 -window-group %g -title "%l of %f" "temporary:%i"\"/>"
124 " <delegate decode=\"wmf\" command=\""wmf2eps" -o "%o" "%i"\"/>"
128 Global declaractions.
130 static LinkedListInfo
131 *delegate_list = (LinkedListInfo *) NULL;
134 *delegate_semaphore = (SemaphoreInfo *) NULL;
136 static volatile MagickBooleanType
137 instantiate_delegate = MagickFalse;
140 Forward declaractions.
142 static MagickBooleanType
143 InitializeDelegateList(ExceptionInfo *),
144 LoadDelegateLists(const char *,ExceptionInfo *);
147 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
151 + D e l e g a t e C o m p o n e n t T e r m i n u s %
155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157 % DelegateComponentGenesis() instantiates the delegate component.
159 % The format of the DelegateComponentGenesis method is:
161 % MagickBooleanType DelegateComponentGenesis(void)
164 MagickPrivate MagickBooleanType DelegateComponentGenesis(void)
166 AcquireSemaphoreInfo(&delegate_semaphore);
171 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
175 % D e l e g a t e C o m p o n e n t T e r m i n u s %
179 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181 % DelegateComponentTerminus() destroys the delegate component.
183 % The format of the DelegateComponentTerminus method is:
185 % DelegateComponentTerminus(void)
189 static void *DestroyDelegate(void *delegate_info)
191 register DelegateInfo
194 p=(DelegateInfo *) delegate_info;
195 if (p->path != (char *) NULL)
196 p->path=DestroyString(p->path);
197 if (p->decode != (char *) NULL)
198 p->decode=DestroyString(p->decode);
199 if (p->encode != (char *) NULL)
200 p->encode=DestroyString(p->encode);
201 if (p->commands != (char *) NULL)
202 p->commands=DestroyString(p->commands);
203 p=(DelegateInfo *) RelinquishMagickMemory(p);
204 return((void *) NULL);
207 MagickPrivate void DelegateComponentTerminus(void)
209 if (delegate_semaphore == (SemaphoreInfo *) NULL)
210 AcquireSemaphoreInfo(&delegate_semaphore);
211 LockSemaphoreInfo(delegate_semaphore);
212 if (delegate_list != (LinkedListInfo *) NULL)
213 delegate_list=DestroyLinkedList(delegate_list,DestroyDelegate);
214 instantiate_delegate=MagickFalse;
215 UnlockSemaphoreInfo(delegate_semaphore);
216 DestroySemaphoreInfo(&delegate_semaphore);
220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224 % G e t D e l e g a t e C o m m a n d %
228 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
230 % GetDelegateCommand() replaces any embedded formatting characters with the
231 % appropriate image attribute and returns the resulting command.
233 % The format of the GetDelegateCommand method is:
235 % char *GetDelegateCommand(const ImageInfo *image_info,Image *image,
236 % const char *decode,const char *encode,ExceptionInfo *exception)
238 % A description of each parameter follows:
240 % o command: Method GetDelegateCommand returns the command associated
241 % with specified delegate tag.
243 % o image_info: the image info.
245 % o image: the image.
247 % o decode: Specifies the decode delegate we are searching for as a
250 % o encode: Specifies the encode delegate we are searching for as a
253 % o exception: return any errors or warnings in this structure.
256 MagickExport char *GetDelegateCommand(const ImageInfo *image_info,Image *image,
257 const char *decode,const char *encode,ExceptionInfo *exception)
269 assert(image_info != (ImageInfo *) NULL);
270 assert(image_info->signature == MagickSignature);
271 assert(image != (Image *) NULL);
272 assert(image->signature == MagickSignature);
273 if (image->debug != MagickFalse)
274 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
275 delegate_info=GetDelegateInfo(decode,encode,exception);
276 if (delegate_info == (const DelegateInfo *) NULL)
278 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
279 "NoTagFound","`%s'",decode ? decode : encode);
280 return((char *) NULL);
282 commands=StringToList(delegate_info->commands);
283 if (commands == (char **) NULL)
285 (void) ThrowMagickException(exception,GetMagickModule(),
286 ResourceLimitError,"MemoryAllocationFailed","`%s'",
287 decode ? decode : encode);
288 return((char *) NULL);
290 command=InterpretImageProperties(image_info,image,commands[0],exception);
291 if (command == (char *) NULL)
292 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
293 "MemoryAllocationFailed","`%s'",commands[0]);
295 Relinquish resources.
297 for (i=0; commands[i] != (char *) NULL; i++)
298 commands[i]=DestroyString(commands[i]);
299 commands=(char **) RelinquishMagickMemory(commands);
304 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
308 % G e t D e l e g a t e C o m m a n d s %
312 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
314 % GetDelegateCommands() returns the commands associated with a delegate.
316 % The format of the GetDelegateCommands method is:
318 % const char *GetDelegateCommands(const DelegateInfo *delegate_info)
320 % A description of each parameter follows:
322 % o delegate_info: The delegate info.
325 MagickExport const char *GetDelegateCommands(const DelegateInfo *delegate_info)
327 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
328 assert(delegate_info != (DelegateInfo *) NULL);
329 assert(delegate_info->signature == MagickSignature);
330 return(delegate_info->commands);
334 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
338 % G e t D e l e g a t e I n f o %
342 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
344 % GetDelegateInfo() returns any delegates associated with the specified tag.
346 % The format of the GetDelegateInfo method is:
348 % const DelegateInfo *GetDelegateInfo(const char *decode,
349 % const char *encode,ExceptionInfo *exception)
351 % A description of each parameter follows:
353 % o decode: Specifies the decode delegate we are searching for as a
356 % o encode: Specifies the encode delegate we are searching for as a
359 % o exception: return any errors or warnings in this structure.
362 MagickExport const DelegateInfo *GetDelegateInfo(const char *decode,
363 const char *encode,ExceptionInfo *exception)
365 register const DelegateInfo
368 assert(exception != (ExceptionInfo *) NULL);
369 if ((delegate_list == (LinkedListInfo *) NULL) ||
370 (instantiate_delegate == MagickFalse))
371 if (InitializeDelegateList(exception) == MagickFalse)
372 return((const DelegateInfo *) NULL);
373 if ((delegate_list == (LinkedListInfo *) NULL) ||
374 (IsLinkedListEmpty(delegate_list) != MagickFalse))
375 return((const DelegateInfo *) NULL);
376 if ((LocaleCompare(decode,"*") == 0) && (LocaleCompare(encode,"*") == 0))
377 return((const DelegateInfo *) GetValueFromLinkedList(delegate_list,0));
379 Search for named delegate.
381 LockSemaphoreInfo(delegate_semaphore);
382 ResetLinkedListIterator(delegate_list);
383 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
384 while (p != (const DelegateInfo *) NULL)
388 if (LocaleCompare(p->decode,decode) == 0)
390 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
395 if (LocaleCompare(p->encode,encode) == 0)
397 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
400 if (LocaleCompare(decode,p->decode) == 0)
401 if (LocaleCompare(encode,p->encode) == 0)
403 if (LocaleCompare(decode,"*") == 0)
404 if (LocaleCompare(encode,p->encode) == 0)
406 if (LocaleCompare(decode,p->decode) == 0)
407 if (LocaleCompare(encode,"*") == 0)
409 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
411 if (p != (const DelegateInfo *) NULL)
412 (void) InsertValueInLinkedList(delegate_list,0,
413 RemoveElementByValueFromLinkedList(delegate_list,p));
414 UnlockSemaphoreInfo(delegate_semaphore);
419 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
423 % G e t D e l e g a t e I n f o L i s t %
427 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
429 % GetDelegateInfoList() returns any delegates that match the specified pattern.
431 % The delegate of the GetDelegateInfoList function is:
433 % const DelegateInfo **GetDelegateInfoList(const char *pattern,
434 % size_t *number_delegates,ExceptionInfo *exception)
436 % A description of each parameter follows:
438 % o pattern: Specifies a pointer to a text string containing a pattern.
440 % o number_delegates: This integer returns the number of delegates in the
443 % o exception: return any errors or warnings in this structure.
447 #if defined(__cplusplus) || defined(c_plusplus)
451 static int DelegateInfoCompare(const void *x,const void *y)
457 p=(const DelegateInfo **) x,
458 q=(const DelegateInfo **) y;
459 if (LocaleCompare((*p)->path,(*q)->path) == 0)
461 if ((*p)->decode == (char *) NULL)
462 if (((*p)->encode != (char *) NULL) &&
463 ((*q)->encode != (char *) NULL))
464 return(strcmp((*p)->encode,(*q)->encode));
465 if (((*p)->decode != (char *) NULL) &&
466 ((*q)->decode != (char *) NULL))
467 return(strcmp((*p)->decode,(*q)->decode));
469 return(LocaleCompare((*p)->path,(*q)->path));
472 #if defined(__cplusplus) || defined(c_plusplus)
476 MagickExport const DelegateInfo **GetDelegateInfoList(const char *pattern,
477 size_t *number_delegates,ExceptionInfo *exception)
482 register const DelegateInfo
489 Allocate delegate list.
491 assert(pattern != (char *) NULL);
492 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
493 assert(number_delegates != (size_t *) NULL);
495 p=GetDelegateInfo("*","*",exception);
496 if (p == (const DelegateInfo *) NULL)
497 return((const DelegateInfo **) NULL);
498 delegates=(const DelegateInfo **) AcquireQuantumMemory((size_t)
499 GetNumberOfElementsInLinkedList(delegate_list)+1UL,sizeof(*delegates));
500 if (delegates == (const DelegateInfo **) NULL)
501 return((const DelegateInfo **) NULL);
503 Generate delegate list.
505 LockSemaphoreInfo(delegate_semaphore);
506 ResetLinkedListIterator(delegate_list);
507 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
508 for (i=0; p != (const DelegateInfo *) NULL; )
510 if ((p->stealth == MagickFalse) &&
511 ((GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse) ||
512 (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse)))
514 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
516 UnlockSemaphoreInfo(delegate_semaphore);
517 qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateInfoCompare);
518 delegates[i]=(DelegateInfo *) NULL;
519 *number_delegates=(size_t) i;
524 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
528 % G e t D e l e g a t e L i s t %
532 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
534 % GetDelegateList() returns any image format delegates that match the
537 % The format of the GetDelegateList function is:
539 % char **GetDelegateList(const char *pattern,
540 % size_t *number_delegates,ExceptionInfo *exception)
542 % A description of each parameter follows:
544 % o pattern: Specifies a pointer to a text string containing a pattern.
546 % o number_delegates: This integer returns the number of delegates
549 % o exception: return any errors or warnings in this structure.
553 #if defined(__cplusplus) || defined(c_plusplus)
557 static int DelegateCompare(const void *x,const void *y)
565 return(LocaleCompare(*p,*q));
568 #if defined(__cplusplus) || defined(c_plusplus)
572 MagickExport char **GetDelegateList(const char *pattern,
573 size_t *number_delegates,ExceptionInfo *exception)
578 register const DelegateInfo
585 Allocate delegate list.
587 assert(pattern != (char *) NULL);
588 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
589 assert(number_delegates != (size_t *) NULL);
591 p=GetDelegateInfo("*","*",exception);
592 if (p == (const DelegateInfo *) NULL)
593 return((char **) NULL);
594 delegates=(char **) AcquireQuantumMemory((size_t)
595 GetNumberOfElementsInLinkedList(delegate_list)+1UL,sizeof(*delegates));
596 if (delegates == (char **) NULL)
597 return((char **) NULL);
598 LockSemaphoreInfo(delegate_semaphore);
599 ResetLinkedListIterator(delegate_list);
600 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
601 for (i=0; p != (const DelegateInfo *) NULL; )
603 if ((p->stealth == MagickFalse) &&
604 (GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse))
605 delegates[i++]=ConstantString(p->decode);
606 if ((p->stealth == MagickFalse) &&
607 (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse))
608 delegates[i++]=ConstantString(p->encode);
609 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
611 UnlockSemaphoreInfo(delegate_semaphore);
612 qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateCompare);
613 delegates[i]=(char *) NULL;
614 *number_delegates=(size_t) i;
619 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
623 % G e t D e l e g a t e M o d e %
627 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
629 % GetDelegateMode() returns the mode of the delegate.
631 % The format of the GetDelegateMode method is:
633 % ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
635 % A description of each parameter follows:
637 % o delegate_info: The delegate info.
640 MagickExport ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
642 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
643 assert(delegate_info != (DelegateInfo *) NULL);
644 assert(delegate_info->signature == MagickSignature);
645 return(delegate_info->mode);
649 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
653 + G e t D e l e g a t e T h r e a d S u p p o r t %
657 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
659 % GetDelegateThreadSupport() returns MagickTrue if the delegate supports
662 % The format of the GetDelegateThreadSupport method is:
664 % MagickBooleanType GetDelegateThreadSupport(
665 % const DelegateInfo *delegate_info)
667 % A description of each parameter follows:
669 % o delegate_info: The delegate info.
672 MagickExport MagickBooleanType GetDelegateThreadSupport(
673 const DelegateInfo *delegate_info)
675 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
676 assert(delegate_info != (DelegateInfo *) NULL);
677 assert(delegate_info->signature == MagickSignature);
678 return(delegate_info->thread_support);
682 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
686 + I n i t i a l i z e D e l e g a t e L i s t %
690 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
692 % InitializeDelegateList() initializes the delegate list.
694 % The format of the InitializeDelegateList method is:
696 % MagickBooleanType InitializeDelegateList(ExceptionInfo *exception)
698 % A description of each parameter follows.
700 % o exception: return any errors or warnings in this structure.
703 static MagickBooleanType InitializeDelegateList(ExceptionInfo *exception)
705 if ((delegate_list == (LinkedListInfo *) NULL) &&
706 (instantiate_delegate == MagickFalse))
708 if (delegate_semaphore == (SemaphoreInfo *) NULL)
709 AcquireSemaphoreInfo(&delegate_semaphore);
710 LockSemaphoreInfo(delegate_semaphore);
711 if ((delegate_list == (LinkedListInfo *) NULL) &&
712 (instantiate_delegate == MagickFalse))
714 (void) LoadDelegateLists(DelegateFilename,exception);
715 instantiate_delegate=MagickTrue;
717 UnlockSemaphoreInfo(delegate_semaphore);
719 return(delegate_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
723 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
727 % I n v o k e D e l e g a t e %
731 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
733 % InvokeDelegate replaces any embedded formatting characters with the
734 % appropriate image attribute and executes the resulting command. MagickFalse
735 % is returned if the commands execute with success otherwise MagickTrue.
737 % The format of the InvokeDelegate method is:
739 % MagickBooleanType InvokeDelegate(ImageInfo *image_info,Image *image,
740 % const char *decode,const char *encode,ExceptionInfo *exception)
742 % A description of each parameter follows:
744 % o image_info: the imageInfo.
746 % o image: the image.
748 % o exception: return any errors or warnings in this structure.
752 static inline size_t MagickMin(const size_t x,const size_t y)
759 static MagickBooleanType CopyDelegateFile(const char *source,
760 const char *destination)
786 Copy source file to destination.
788 assert(source != (const char *) NULL);
789 assert(destination != (char *) NULL);
790 status=GetPathAttributes(destination,&attributes);
791 if ((status != MagickFalse) && (attributes.st_size != 0))
793 destination_file=open_utf8(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
794 if (destination_file == -1)
796 source_file=open_utf8(source,O_RDONLY | O_BINARY,0);
797 if (source_file == -1)
799 (void) close(destination_file);
802 quantum=(size_t) MagickMaxBufferExtent;
803 if ((fstat(source_file,&attributes) == 0) && (attributes.st_size != 0))
804 quantum=MagickMin((size_t) attributes.st_size,MagickMaxBufferExtent);
805 buffer=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*buffer));
806 if (buffer == (unsigned char *) NULL)
808 (void) close(source_file);
809 (void) close(destination_file);
813 for (i=0; ; i+=count)
815 count=(ssize_t) read(source_file,buffer,quantum);
818 length=(size_t) count;
819 count=(ssize_t) write(destination_file,buffer,length);
820 if ((size_t) count != length)
823 (void) close(destination_file);
824 (void) close(source_file);
825 buffer=(unsigned char *) RelinquishMagickMemory(buffer);
826 return(i != 0 ? MagickTrue : MagickFalse);
829 MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
830 Image *image,const char *decode,const char *encode,ExceptionInfo *exception)
835 input_filename[MaxTextExtent],
836 output_filename[MaxTextExtent];
854 assert(image_info != (ImageInfo *) NULL);
855 assert(image_info->signature == MagickSignature);
856 assert(image != (Image *) NULL);
857 assert(image->signature == MagickSignature);
858 if (image->debug != MagickFalse)
859 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
860 rights=ExecutePolicyRights;
861 if (IsRightsAuthorized(DelegatePolicyDomain,rights,decode) == MagickFalse)
864 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
865 "NotAuthorized","`%s'",decode);
868 if (IsRightsAuthorized(DelegatePolicyDomain,rights,encode) == MagickFalse)
871 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
872 "NotAuthorized","`%s'",encode);
875 temporary=(*image->filename == '\0') ? MagickTrue : MagickFalse;
876 if (temporary != MagickFalse)
877 if (AcquireUniqueFilename(image->filename) == MagickFalse)
879 ThrowFileException(exception,FileOpenError,
880 "UnableToCreateTemporaryFile",image->filename);
883 delegate_info=GetDelegateInfo(decode,encode,exception);
884 if (delegate_info == (DelegateInfo *) NULL)
886 if (temporary != MagickFalse)
887 (void) RelinquishUniqueFileResource(image->filename);
888 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
889 "NoTagFound","`%s'",decode ? decode : encode);
892 if (*image_info->filename == '\0')
894 if (AcquireUniqueFilename(image_info->filename) == MagickFalse)
896 if (temporary != MagickFalse)
897 (void) RelinquishUniqueFileResource(image->filename);
898 ThrowFileException(exception,FileOpenError,
899 "UnableToCreateTemporaryFile",image_info->filename);
902 image_info->temporary=MagickTrue;
904 if ((delegate_info->mode != 0) && (((decode != (const char *) NULL) &&
905 (delegate_info->encode != (char *) NULL)) ||
906 ((encode != (const char *) NULL) &&
907 (delegate_info->decode != (char *) NULL))))
919 Delegate requires a particular image format.
921 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
923 ThrowFileException(exception,FileOpenError,
924 "UnableToCreateTemporaryFile",image_info->unique);
927 if (AcquireUniqueFilename(image_info->zero) == MagickFalse)
929 (void) RelinquishUniqueFileResource(image_info->zero);
930 ThrowFileException(exception,FileOpenError,
931 "UnableToCreateTemporaryFile",image_info->zero);
934 magick=InterpretImageProperties(image_info,image,decode != (char *) NULL ?
935 delegate_info->encode : delegate_info->decode,exception);
936 if (magick == (char *) NULL)
938 (void) RelinquishUniqueFileResource(image_info->unique);
939 (void) RelinquishUniqueFileResource(image_info->zero);
940 if (temporary != MagickFalse)
941 (void) RelinquishUniqueFileResource(image->filename);
942 (void) ThrowMagickException(exception,GetMagickModule(),
943 DelegateError,"DelegateFailed","`%s'",decode ? decode : encode);
947 clone_info=CloneImageInfo(image_info);
948 (void) CopyMagickString((char *) clone_info->magick,magick,
950 if (LocaleCompare(magick,"NULL") != 0)
951 (void) CopyMagickString(image->magick,magick,MaxTextExtent);
952 magick=DestroyString(magick);
953 (void) FormatLocaleString(clone_info->filename,MaxTextExtent,"%s:",
954 delegate_info->decode);
955 (void) SetImageInfo(clone_info,(unsigned int) GetImageListLength(image),
957 (void) CopyMagickString(clone_info->filename,image_info->filename,
959 (void) CopyMagickString(image_info->filename,image->filename,
961 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
963 (void) FormatLocaleString(p->filename,MaxTextExtent,"%s:%s",
964 delegate_info->decode,clone_info->filename);
965 status=WriteImage(clone_info,p,exception);
966 if (status == MagickFalse)
968 (void) RelinquishUniqueFileResource(image_info->unique);
969 (void) RelinquishUniqueFileResource(image_info->zero);
970 if (temporary != MagickFalse)
971 (void) RelinquishUniqueFileResource(image->filename);
972 clone_info=DestroyImageInfo(clone_info);
973 (void) ThrowMagickException(exception,GetMagickModule(),
974 DelegateError,"DelegateFailed","`%s'",decode ? decode : encode);
977 if (clone_info->adjoin != MagickFalse)
980 (void) RelinquishUniqueFileResource(image_info->unique);
981 (void) RelinquishUniqueFileResource(image_info->zero);
982 clone_info=DestroyImageInfo(clone_info);
987 commands=StringToList(delegate_info->commands);
988 if (commands == (char **) NULL)
990 if (temporary != MagickFalse)
991 (void) RelinquishUniqueFileResource(image->filename);
992 (void) ThrowMagickException(exception,GetMagickModule(),
993 ResourceLimitError,"MemoryAllocationFailed","`%s'",
994 decode ? decode : encode);
997 command=(char *) NULL;
999 (void) CopyMagickString(output_filename,image_info->filename,MaxTextExtent);
1000 (void) CopyMagickString(input_filename,image->filename,MaxTextExtent);
1001 for (i=0; commands[i] != (char *) NULL; i++)
1003 status=AcquireUniqueSymbolicLink(output_filename,image_info->filename);
1004 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1006 ThrowFileException(exception,FileOpenError,
1007 "UnableToCreateTemporaryFile",image_info->unique);
1010 if (AcquireUniqueFilename(image_info->zero) == MagickFalse)
1012 (void) RelinquishUniqueFileResource(image_info->unique);
1013 ThrowFileException(exception,FileOpenError,
1014 "UnableToCreateTemporaryFile",image_info->zero);
1017 if (LocaleCompare(decode,"SCAN") != 0)
1019 status=AcquireUniqueSymbolicLink(input_filename,image->filename);
1020 if (status == MagickFalse)
1022 ThrowFileException(exception,FileOpenError,
1023 "UnableToCreateTemporaryFile",input_filename);
1028 command=InterpretImageProperties(image_info,image,commands[i],exception);
1029 if (command != (char *) NULL)
1034 status=SystemCommand(delegate_info->spawn,image_info->verbose,command,
1035 exception) != 0 ? MagickTrue : MagickFalse;
1036 if (delegate_info->spawn != MagickFalse)
1037 (void) sleep(2); /* FUTURE: A better way is needed! */
1038 command=DestroyString(command);
1040 if (LocaleCompare(decode,"SCAN") != 0)
1042 if (CopyDelegateFile(image->filename,input_filename) == MagickFalse)
1043 (void) RelinquishUniqueFileResource(input_filename);
1045 if (CopyDelegateFile(image_info->filename,output_filename) == MagickFalse)
1046 (void) RelinquishUniqueFileResource(output_filename);
1047 if (image_info->temporary != MagickFalse)
1048 (void) RelinquishUniqueFileResource(image_info->filename);
1049 (void) RelinquishUniqueFileResource(image_info->unique);
1050 (void) RelinquishUniqueFileResource(image_info->zero);
1051 (void) RelinquishUniqueFileResource(image_info->filename);
1052 (void) RelinquishUniqueFileResource(image->filename);
1053 if (status != MagickFalse)
1055 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1056 "DelegateFailed","`%s'",commands[i]);
1059 commands[i]=DestroyString(commands[i]);
1061 (void) CopyMagickString(image_info->filename,output_filename,MaxTextExtent);
1062 (void) CopyMagickString(image->filename,input_filename,MaxTextExtent);
1064 Relinquish resources.
1066 for ( ; commands[i] != (char *) NULL; i++)
1067 commands[i]=DestroyString(commands[i]);
1068 commands=(char **) RelinquishMagickMemory(commands);
1069 if (temporary != MagickFalse)
1070 (void) RelinquishUniqueFileResource(image->filename);
1071 return(status == MagickFalse ? MagickTrue : MagickFalse);
1075 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1079 % L i s t D e l e g a t e I n f o %
1083 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1085 % ListDelegateInfo() lists the image formats to a file.
1087 % The format of the ListDelegateInfo method is:
1089 % MagickBooleanType ListDelegateInfo(FILE *file,ExceptionInfo *exception)
1091 % A description of each parameter follows.
1093 % o file: An pointer to a FILE.
1095 % o exception: return any errors or warnings in this structure.
1098 MagickExport MagickBooleanType ListDelegateInfo(FILE *file,
1099 ExceptionInfo *exception)
1106 delegate[MaxTextExtent];
1120 if (file == (const FILE *) NULL)
1122 delegate_info=GetDelegateInfoList("*",&number_delegates,exception);
1123 if (delegate_info == (const DelegateInfo **) NULL)
1124 return(MagickFalse);
1125 path=(const char *) NULL;
1126 for (i=0; i < (ssize_t) number_delegates; i++)
1128 if (delegate_info[i]->stealth != MagickFalse)
1130 if ((path == (const char *) NULL) ||
1131 (LocaleCompare(path,delegate_info[i]->path) != 0))
1133 if (delegate_info[i]->path != (char *) NULL)
1134 (void) FormatLocaleFile(file,"\nPath: %s\n\n",delegate_info[i]->path);
1135 (void) FormatLocaleFile(file,"Delegate Command\n");
1136 (void) FormatLocaleFile(file,
1137 "-------------------------------------------------"
1138 "------------------------------\n");
1140 path=delegate_info[i]->path;
1142 if (delegate_info[i]->encode != (char *) NULL)
1143 (void) CopyMagickString(delegate,delegate_info[i]->encode,MaxTextExtent);
1144 (void) ConcatenateMagickString(delegate," ",MaxTextExtent);
1146 commands=StringToList(delegate_info[i]->commands);
1147 if (commands == (char **) NULL)
1149 (void) FormatLocaleFile(file,"%11s%c=%c%s ",delegate_info[i]->decode ?
1150 delegate_info[i]->decode : "",delegate_info[i]->mode <= 0 ? '<' : ' ',
1151 delegate_info[i]->mode >= 0 ? '>' : ' ',delegate);
1152 StripString(commands[0]);
1153 (void) FormatLocaleFile(file,"\"%s\"\n",commands[0]);
1154 for (j=1; commands[j] != (char *) NULL; j++)
1156 StripString(commands[j]);
1157 (void) FormatLocaleFile(file," \"%s\"\n",commands[j]);
1159 for (j=0; commands[j] != (char *) NULL; j++)
1160 commands[j]=DestroyString(commands[j]);
1161 commands=(char **) RelinquishMagickMemory(commands);
1163 (void) fflush(file);
1164 delegate_info=(const DelegateInfo **)
1165 RelinquishMagickMemory((void *) delegate_info);
1170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1174 + L o a d D e l e g a t e L i s t %
1178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1180 % LoadDelegateList() loads the delegate configuration file which provides a
1181 % mapping between delegate attributes and a delegate name.
1183 % The format of the LoadDelegateList method is:
1185 % MagickBooleanType LoadDelegateList(const char *xml,const char *filename,
1186 % const size_t depth,ExceptionInfo *exception)
1188 % A description of each parameter follows:
1190 % o xml: The delegate list in XML format.
1192 % o filename: The delegate list filename.
1194 % o depth: depth of <include /> statements.
1196 % o exception: return any errors or warnings in this structure.
1199 static MagickBooleanType LoadDelegateList(const char *xml,const char *filename,
1200 const size_t depth,ExceptionInfo *exception)
1203 keyword[MaxTextExtent],
1216 Load the delegate map file.
1218 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1219 "Loading delegate configuration file \"%s\" ...",filename);
1220 if (xml == (const char *) NULL)
1221 return(MagickFalse);
1222 if (delegate_list == (LinkedListInfo *) NULL)
1224 delegate_list=NewLinkedList(0);
1225 if (delegate_list == (LinkedListInfo *) NULL)
1227 ThrowFileException(exception,ResourceLimitError,
1228 "MemoryAllocationFailed",filename);
1229 return(MagickFalse);
1233 delegate_info=(DelegateInfo *) NULL;
1234 token=AcquireString(xml);
1235 for (q=(const char *) xml; *q != '\0'; )
1240 GetMagickToken(q,&q,token);
1243 (void) CopyMagickString(keyword,token,MaxTextExtent);
1244 if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
1249 while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
1250 GetMagickToken(q,&q,token);
1253 if (LocaleNCompare(keyword,"<!--",4) == 0)
1258 while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
1259 GetMagickToken(q,&q,token);
1262 if (LocaleCompare(keyword,"<include") == 0)
1267 while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
1269 (void) CopyMagickString(keyword,token,MaxTextExtent);
1270 GetMagickToken(q,&q,token);
1273 GetMagickToken(q,&q,token);
1274 if (LocaleCompare(keyword,"file") == 0)
1277 (void) ThrowMagickException(exception,GetMagickModule(),
1278 ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token);
1282 path[MaxTextExtent],
1285 GetPathComponent(filename,HeadPath,path);
1287 (void) ConcatenateMagickString(path,DirectorySeparator,
1289 if (*token == *DirectorySeparator)
1290 (void) CopyMagickString(path,token,MaxTextExtent);
1292 (void) ConcatenateMagickString(path,token,MaxTextExtent);
1293 xml=FileToString(path,~0,exception);
1294 if (xml != (char *) NULL)
1296 status=LoadDelegateList(xml,path,depth+1,exception);
1297 xml=(char *) RelinquishMagickMemory(xml);
1304 if (LocaleCompare(keyword,"<delegate") == 0)
1309 delegate_info=(DelegateInfo *) AcquireMagickMemory(
1310 sizeof(*delegate_info));
1311 if (delegate_info == (DelegateInfo *) NULL)
1312 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
1313 (void) ResetMagickMemory(delegate_info,0,sizeof(*delegate_info));
1314 delegate_info->path=ConstantString(filename);
1315 delegate_info->signature=MagickSignature;
1318 if (delegate_info == (DelegateInfo *) NULL)
1320 if (LocaleCompare(keyword,"/>") == 0)
1322 status=AppendValueToLinkedList(delegate_list,delegate_info);
1323 if (status == MagickFalse)
1324 (void) ThrowMagickException(exception,GetMagickModule(),
1325 ResourceLimitError,"MemoryAllocationFailed","`%s'",
1326 delegate_info->commands);
1327 delegate_info=(DelegateInfo *) NULL;
1329 GetMagickToken(q,(const char **) NULL,token);
1332 GetMagickToken(q,&q,token);
1333 GetMagickToken(q,&q,token);
1339 if (LocaleCompare((char *) keyword,"command") == 0)
1344 commands=AcquireString(token);
1345 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
1346 if (strchr(commands,'@') != (char *) NULL)
1349 path[MaxTextExtent];
1351 NTGhostscriptEXE(path,MaxTextExtent);
1352 (void) SubstituteString((char **) &commands,"@PSDelegate@",
1354 (void) SubstituteString((char **) &commands,"\\","/");
1357 (void) SubstituteString((char **) &commands,"&","&");
1358 (void) SubstituteString((char **) &commands,""","\"");
1359 (void) SubstituteString((char **) &commands,">",">");
1360 (void) SubstituteString((char **) &commands,"<","<");
1361 delegate_info->commands=commands;
1369 if (LocaleCompare((char *) keyword,"decode") == 0)
1371 delegate_info->decode=ConstantString(token);
1372 delegate_info->mode=1;
1380 if (LocaleCompare((char *) keyword,"encode") == 0)
1382 delegate_info->encode=ConstantString(token);
1383 delegate_info->mode=(-1);
1391 if (LocaleCompare((char *) keyword,"mode") == 0)
1393 delegate_info->mode=1;
1394 if (LocaleCompare(token,"bi") == 0)
1395 delegate_info->mode=0;
1397 if (LocaleCompare(token,"encode") == 0)
1398 delegate_info->mode=(-1);
1406 if (LocaleCompare((char *) keyword,"spawn") == 0)
1408 delegate_info->spawn=IsStringTrue(token);
1411 if (LocaleCompare((char *) keyword,"stealth") == 0)
1413 delegate_info->stealth=IsStringTrue(token);
1421 if (LocaleCompare((char *) keyword,"thread-support") == 0)
1423 delegate_info->thread_support=IsStringTrue(token);
1432 token=(char *) RelinquishMagickMemory(token);
1437 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1441 % L o a d D e l e g a t e L i s t s %
1445 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1447 % LoadDelegateList() loads one or more delegate configuration file which
1448 % provides a mapping between delegate attributes and a delegate name.
1450 % The format of the LoadDelegateLists method is:
1452 % MagickBooleanType LoadDelegateLists(const char *filename,
1453 % ExceptionInfo *exception)
1455 % A description of each parameter follows:
1457 % o filename: the font file name.
1459 % o exception: return any errors or warnings in this structure.
1462 static MagickBooleanType LoadDelegateLists(const char *filename,
1463 ExceptionInfo *exception)
1465 #if defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT)
1466 return(LoadDelegateList(DelegateMap,"built-in",0,exception));
1478 options=GetConfigureOptions(filename,exception);
1479 option=(const StringInfo *) GetNextValueInLinkedList(options);
1480 while (option != (const StringInfo *) NULL)
1482 status|=LoadDelegateList((const char *) GetStringInfoDatum(option),
1483 GetStringInfoPath(option),0,exception);
1484 option=(const StringInfo *) GetNextValueInLinkedList(options);
1486 options=DestroyConfigureOptions(options);
1487 if ((delegate_list == (LinkedListInfo *) NULL) ||
1488 (IsLinkedListEmpty(delegate_list) != MagickFalse))
1489 status|=LoadDelegateList(DelegateMap,"built-in",0,exception);
1490 return(status != 0 ? MagickTrue : MagickFalse);