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-2011 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 "magick/studio.h"
49 #include "magick/property.h"
50 #include "magick/blob.h"
51 #include "magick/client.h"
52 #include "magick/configure.h"
53 #include "magick/constitute.h"
54 #include "magick/delegate.h"
55 #include "magick/exception.h"
56 #include "magick/exception-private.h"
57 #include "magick/hashmap.h"
58 #include "magick/list.h"
59 #include "magick/memory_.h"
60 #include "magick/policy.h"
61 #include "magick/resource_.h"
62 #include "magick/semaphore.h"
63 #include "magick/string_.h"
64 #include "magick/token.h"
65 #include "magick/utility.h"
66 #include "magick/xml-tree.h"
71 #define DelegateFilename "delegates.xml"
77 *DelegateMap = (const char *)
78 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
80 " <delegate decode=\"autotrace\" stealth=\"True\" command=\""autotrace" -output-format svg -output-file "%o" "%i"\"/>"
81 " <delegate decode=\"avi:decode\" stealth=\"True\" command=\""mplayer" "%i" -really-quiet -ao null -vo png:z=3\"/>"
82 " <delegate decode=\"browse\" stealth=\"True\" spawn=\"True\" command=\""xdg-open" http://www.imagemagick.org/\"/>"
83 " <delegate decode=\"cgm\" thread-support=\"False\" command=\""ralcgm" -d ps -oC < "%i" > "%o" 2> "%u"\"/>"
84 " <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"\"/>"
85 " <delegate decode=\"edit\" stealth=\"True\" command=\""xterm" -title "Edit Image Comment" -e vi "%o"\"/>"
86 " <delegate decode=\"eps\" encode=\"pdf\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pdfwrite" "-sOutputFile=%o" "-f%i"\"/>"
87 " <delegate decode=\"eps\" encode=\"ps\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pswrite" "-sOutputFile=%o" "-f%i"\"/>"
88 " <delegate decode=\"fig\" command=\""fig2dev" -L ps "%i" "%o"\"/>"
89 " <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"\"/>"
90 " <delegate decode=\"hpg\" command=\""hp2xx" -q -m eps -f `basename "%o"` "%i" mv -f `basename "%o"` "%o"\"/>"
91 " <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\"/>"
92 " <delegate decode=\"htm\" command=\""html2ps" -U -o "%o" "%i"\"/>"
93 " <delegate decode=\"html\" command=\""html2ps" -U -o "%o" "%i"\"/>"
94 " <delegate decode=\"https\" command=\""wget" -q -O "%o" "https:%M"\"/>"
95 " <delegate decode=\"ilbm\" command=\""ilbmtoppm" "%i" > "%o"\"/>"
96 " <delegate decode=\"man\" command=\""groff" -man -Tps "%i" > "%o"\"/>"
97 " <delegate decode=\"mpeg:decode\" stealth=\"True\" command=\""ffmpeg" --i "%i" -vcodec pam -an -f rawvideo -y "%u0.pam" 2;> "%Z"\"/>"
98 " <delegate decode=\"null\" encode=\"mpeg:encode\" stealth=\"True\" command=\""ffmpeg" "%M%%d.jpg" "%u.%m" 2;> "%Z"\"/>"
99 " <delegate decode=\"pcl:color\" stealth=\"True\" command=\""pcl6" -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=ppmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "%s"\"/>"
100 " <delegate decode=\"pcl:cmyk\" stealth=\"True\" command=\""pcl6" -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=bmpsep8" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "%s"\"/>"
101 " <delegate decode=\"pcl:mono\" stealth=\"True\" command=\""pcl6" -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pbmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "%s"\"/>"
102 " <delegate decode=\"pdf\" encode=\"eps\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=epswrite" "-sOutputFile=%o" "-f%i"\"/>"
103 " <delegate decode=\"pdf\" encode=\"ps\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pswrite" "-sOutputFile=%o" "-f%i"\"/>"
104 " <delegate decode=\"pnm\" encode=\"ilbm\" mode=\"encode\" command=\""ppmtoilbm" -24if "%i" > "%o"\"/>"
105 " <delegate decode=\"pnm\" encode=\"launch\" mode=\"encode\" command=\""gimp" "%i"\"/>"
106 " <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"\"/>"
107 " <delegate decode=\"ps\" encode=\"eps\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=epswrite" "-sOutputFile=%o" "-f%i"\"/>"
108 " <delegate decode=\"ps\" encode=\"pdf\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pdfwrite" "-sOutputFile=%o" "-f%i"\"/>"
109 " <delegate decode=\"ps\" encode=\"print\" mode=\"encode\" command=\"lpr "%i"\"/>"
110 " <delegate decode=\"ps:alpha\" stealth=\"True\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pngalpha" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"\"/>"
111 " <delegate decode=\"ps:bbox\" stealth=\"True\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=bbox" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"\"/>"
112 " <delegate decode=\"ps:cmyk\" stealth=\"True\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=bmpsep8" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"\"/>"
113 " <delegate decode=\"ps:color\" stealth=\"True\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"\"/>"
114 " <delegate decode=\"ps:mono\" stealth=\"True\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"\"/>"
115 " <delegate decode=\"rgba\" encode=\"rle\" mode=\"encode\" command=\""rawtorle" -o "%o" -v "%i"\"/>"
116 " <delegate decode=\"scan\" command=\""scanimage" -d "%i" > "%o"\"/>"
117 " <delegate encode=\"show\" spawn=\"True\" command=\""/usr/local/bin/display" -immutable -delay 0 -window-group %g -title "%l of %f" "temporary:%i"\"/>"
118 " <delegate decode=\"shtml\" command=\""html2ps" -U -o "%o" "%i"\"/>"
119 " <delegate decode=\"svg\" command=\""rsvg" "%i" "%o"\"/>"
120 " <delegate decode=\"txt\" encode=\"ps\" mode=\"bi\" command=\""enscript" -o "%o" "%i"\"/>"
121 " <delegate encode=\"win\" stealth=\"True\" spawn=\"True\" command=\""/usr/local/bin/display" -immutable -delay 0 -window-group %g -title "%l of %f" "temporary:%i"\"/>"
122 " <delegate decode=\"wmf\" command=\""wmf2eps" -o "%o" "%i"\"/>"
126 Global declaractions.
128 static LinkedListInfo
129 *delegate_list = (LinkedListInfo *) NULL;
132 *delegate_semaphore = (SemaphoreInfo *) NULL;
134 static volatile MagickBooleanType
135 instantiate_delegate = MagickFalse;
138 Forward declaractions.
140 static MagickBooleanType
141 InitializeDelegateList(ExceptionInfo *),
142 LoadDelegateLists(const char *,ExceptionInfo *);
145 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149 + 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 %
153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155 % DelegateComponentGenesis() instantiates the delegate component.
157 % The format of the DelegateComponentGenesis method is:
159 % MagickBooleanType DelegateComponentGenesis(void)
162 MagickExport MagickBooleanType DelegateComponentGenesis(void)
164 AcquireSemaphoreInfo(&delegate_semaphore);
169 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173 % 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 %
177 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179 % DelegateComponentTerminus() destroys the delegate component.
181 % The format of the DelegateComponentTerminus method is:
183 % DelegateComponentTerminus(void)
187 static void *DestroyDelegate(void *delegate_info)
189 register DelegateInfo
192 p=(DelegateInfo *) delegate_info;
193 if (p->path != (char *) NULL)
194 p->path=DestroyString(p->path);
195 if (p->decode != (char *) NULL)
196 p->decode=DestroyString(p->decode);
197 if (p->encode != (char *) NULL)
198 p->encode=DestroyString(p->encode);
199 if (p->commands != (char *) NULL)
200 p->commands=DestroyString(p->commands);
201 p=(DelegateInfo *) RelinquishMagickMemory(p);
202 return((void *) NULL);
206 MagickExport void DelegateComponentTerminus(void)
208 if (delegate_semaphore == (SemaphoreInfo *) NULL)
209 AcquireSemaphoreInfo(&delegate_semaphore);
210 LockSemaphoreInfo(delegate_semaphore);
211 if (delegate_list != (LinkedListInfo *) NULL)
212 delegate_list=DestroyLinkedList(delegate_list,DestroyDelegate);
213 instantiate_delegate=MagickFalse;
214 UnlockSemaphoreInfo(delegate_semaphore);
215 DestroySemaphoreInfo(&delegate_semaphore);
219 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
223 % G e t D e l e g a t e C o m m a n d %
227 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
229 % GetDelegateCommand() replaces any embedded formatting characters with the
230 % appropriate image attribute and returns the resulting command.
232 % The format of the GetDelegateCommand method is:
234 % char *GetDelegateCommand(const ImageInfo *image_info,Image *image,
235 % const char *decode,const char *encode,ExceptionInfo *exception)
237 % A description of each parameter follows:
239 % o command: Method GetDelegateCommand returns the command associated
240 % with specified delegate tag.
242 % o image_info: the image info.
244 % o image: the image.
246 % o decode: Specifies the decode delegate we are searching for as a
249 % o encode: Specifies the encode delegate we are searching for as a
252 % o exception: return any errors or warnings in this structure.
255 MagickExport char *GetDelegateCommand(const ImageInfo *image_info,Image *image,
256 const char *decode,const char *encode,ExceptionInfo *exception)
268 assert(image_info != (ImageInfo *) NULL);
269 assert(image_info->signature == MagickSignature);
270 assert(image != (Image *) NULL);
271 assert(image->signature == MagickSignature);
272 if (image->debug != MagickFalse)
273 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
274 delegate_info=GetDelegateInfo(decode,encode,exception);
275 if (delegate_info == (const DelegateInfo *) NULL)
277 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
278 "NoTagFound","`%s'",decode ? decode : encode);
279 return((char *) NULL);
281 commands=StringToList(delegate_info->commands);
282 if (commands == (char **) NULL)
284 (void) ThrowMagickException(exception,GetMagickModule(),
285 ResourceLimitError,"MemoryAllocationFailed","`%s'",
286 decode ? decode : encode);
287 return((char *) NULL);
289 command=InterpretImageProperties(image_info,image,commands[0]);
290 if (command == (char *) NULL)
291 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
292 "MemoryAllocationFailed","`%s'",commands[0]);
294 Relinquish resources.
296 for (i=0; commands[i] != (char *) NULL; i++)
297 commands[i]=DestroyString(commands[i]);
298 commands=(char **) RelinquishMagickMemory(commands);
303 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
307 % G e t D e l e g a t e C o m m a n d s %
311 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
313 % GetDelegateCommands() returns the commands associated with a delegate.
315 % The format of the GetDelegateCommands method is:
317 % const char *GetDelegateCommands(const DelegateInfo *delegate_info)
319 % A description of each parameter follows:
321 % o delegate_info: The delegate info.
324 MagickExport const char *GetDelegateCommands(const DelegateInfo *delegate_info)
326 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
327 assert(delegate_info != (DelegateInfo *) NULL);
328 assert(delegate_info->signature == MagickSignature);
329 return(delegate_info->commands);
333 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
337 % G e t D e l e g a t e I n f o %
341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
343 % GetDelegateInfo() returns any delegates associated with the specified tag.
345 % The format of the GetDelegateInfo method is:
347 % const DelegateInfo *GetDelegateInfo(const char *decode,
348 % const char *encode,ExceptionInfo *exception)
350 % A description of each parameter follows:
352 % o decode: Specifies the decode delegate we are searching for as a
355 % o encode: Specifies the encode delegate we are searching for as a
358 % o exception: return any errors or warnings in this structure.
361 MagickExport const DelegateInfo *GetDelegateInfo(const char *decode,
362 const char *encode,ExceptionInfo *exception)
364 register const DelegateInfo
367 assert(exception != (ExceptionInfo *) NULL);
368 if ((delegate_list == (LinkedListInfo *) NULL) ||
369 (instantiate_delegate == MagickFalse))
370 if (InitializeDelegateList(exception) == MagickFalse)
371 return((const DelegateInfo *) NULL);
372 if ((delegate_list == (LinkedListInfo *) NULL) ||
373 (IsLinkedListEmpty(delegate_list) != MagickFalse))
374 return((const DelegateInfo *) NULL);
375 if ((LocaleCompare(decode,"*") == 0) && (LocaleCompare(encode,"*") == 0))
376 return((const DelegateInfo *) GetValueFromLinkedList(delegate_list,0));
378 Search for named delegate.
380 LockSemaphoreInfo(delegate_semaphore);
381 ResetLinkedListIterator(delegate_list);
382 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
383 while (p != (const DelegateInfo *) NULL)
387 if (LocaleCompare(p->decode,decode) == 0)
389 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
394 if (LocaleCompare(p->encode,encode) == 0)
396 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
399 if (LocaleCompare(decode,p->decode) == 0)
400 if (LocaleCompare(encode,p->encode) == 0)
402 if (LocaleCompare(decode,"*") == 0)
403 if (LocaleCompare(encode,p->encode) == 0)
405 if (LocaleCompare(decode,p->decode) == 0)
406 if (LocaleCompare(encode,"*") == 0)
408 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
410 if (p != (const DelegateInfo *) NULL)
411 (void) InsertValueInLinkedList(delegate_list,0,
412 RemoveElementByValueFromLinkedList(delegate_list,p));
413 UnlockSemaphoreInfo(delegate_semaphore);
418 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
422 % G e t D e l e g a t e I n f o L i s t %
426 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
428 % GetDelegateInfoList() returns any delegates that match the specified pattern.
430 % The delegate of the GetDelegateInfoList function is:
432 % const DelegateInfo **GetDelegateInfoList(const char *pattern,
433 % size_t *number_delegates,ExceptionInfo *exception)
435 % A description of each parameter follows:
437 % o pattern: Specifies a pointer to a text string containing a pattern.
439 % o number_delegates: This integer returns the number of delegates in the
442 % o exception: return any errors or warnings in this structure.
446 #if defined(__cplusplus) || defined(c_plusplus)
450 static int DelegateInfoCompare(const void *x,const void *y)
456 p=(const DelegateInfo **) x,
457 q=(const DelegateInfo **) y;
458 if (LocaleCompare((*p)->path,(*q)->path) == 0)
460 if ((*p)->decode == (char *) NULL)
461 if (((*p)->encode != (char *) NULL) &&
462 ((*q)->encode != (char *) NULL))
463 return(strcmp((*p)->encode,(*q)->encode));
464 if (((*p)->decode != (char *) NULL) &&
465 ((*q)->decode != (char *) NULL))
466 return(strcmp((*p)->decode,(*q)->decode));
468 return(LocaleCompare((*p)->path,(*q)->path));
471 #if defined(__cplusplus) || defined(c_plusplus)
475 MagickExport const DelegateInfo **GetDelegateInfoList(const char *pattern,
476 size_t *number_delegates,ExceptionInfo *exception)
481 register const DelegateInfo
488 Allocate delegate list.
490 assert(pattern != (char *) NULL);
491 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
492 assert(number_delegates != (size_t *) NULL);
494 p=GetDelegateInfo("*","*",exception);
495 if (p == (const DelegateInfo *) NULL)
496 return((const DelegateInfo **) NULL);
497 delegates=(const DelegateInfo **) AcquireQuantumMemory((size_t)
498 GetNumberOfElementsInLinkedList(delegate_list)+1UL,sizeof(*delegates));
499 if (delegates == (const DelegateInfo **) NULL)
500 return((const DelegateInfo **) NULL);
502 Generate delegate list.
504 LockSemaphoreInfo(delegate_semaphore);
505 ResetLinkedListIterator(delegate_list);
506 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
507 for (i=0; p != (const DelegateInfo *) NULL; )
509 if ((p->stealth == MagickFalse) &&
510 ((GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse) ||
511 (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse)))
513 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
515 UnlockSemaphoreInfo(delegate_semaphore);
516 qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateInfoCompare);
517 delegates[i]=(DelegateInfo *) NULL;
518 *number_delegates=(size_t) i;
523 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
527 % G e t D e l e g a t e L i s t %
531 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
533 % GetDelegateList() returns any image format delegates that match the
536 % The format of the GetDelegateList function is:
538 % char **GetDelegateList(const char *pattern,
539 % size_t *number_delegates,ExceptionInfo *exception)
541 % A description of each parameter follows:
543 % o pattern: Specifies a pointer to a text string containing a pattern.
545 % o number_delegates: This integer returns the number of delegates
548 % o exception: return any errors or warnings in this structure.
552 #if defined(__cplusplus) || defined(c_plusplus)
556 static int DelegateCompare(const void *x,const void *y)
564 return(LocaleCompare(*p,*q));
567 #if defined(__cplusplus) || defined(c_plusplus)
571 MagickExport char **GetDelegateList(const char *pattern,
572 size_t *number_delegates,ExceptionInfo *exception)
577 register const DelegateInfo
584 Allocate delegate list.
586 assert(pattern != (char *) NULL);
587 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
588 assert(number_delegates != (size_t *) NULL);
590 p=GetDelegateInfo("*","*",exception);
591 if (p == (const DelegateInfo *) NULL)
592 return((char **) NULL);
593 delegates=(char **) AcquireQuantumMemory((size_t)
594 GetNumberOfElementsInLinkedList(delegate_list)+1UL,sizeof(*delegates));
595 if (delegates == (char **) NULL)
596 return((char **) NULL);
597 LockSemaphoreInfo(delegate_semaphore);
598 ResetLinkedListIterator(delegate_list);
599 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
600 for (i=0; p != (const DelegateInfo *) NULL; )
602 if ((p->stealth == MagickFalse) &&
603 (GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse))
604 delegates[i++]=ConstantString(p->decode);
605 if ((p->stealth == MagickFalse) &&
606 (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse))
607 delegates[i++]=ConstantString(p->encode);
608 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
610 UnlockSemaphoreInfo(delegate_semaphore);
611 qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateCompare);
612 delegates[i]=(char *) NULL;
613 *number_delegates=(size_t) i;
618 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
622 % G e t D e l e g a t e M o d e %
626 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
628 % GetDelegateMode() returns the mode of the delegate.
630 % The format of the GetDelegateMode method is:
632 % ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
634 % A description of each parameter follows:
636 % o delegate_info: The delegate info.
639 MagickExport ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
641 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
642 assert(delegate_info != (DelegateInfo *) NULL);
643 assert(delegate_info->signature == MagickSignature);
644 return(delegate_info->mode);
648 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
652 + G e t D e l e g a t e T h r e a d S u p p o r t %
656 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
658 % GetDelegateThreadSupport() returns MagickTrue if the delegate supports
661 % The format of the GetDelegateThreadSupport method is:
663 % MagickBooleanType GetDelegateThreadSupport(
664 % const DelegateInfo *delegate_info)
666 % A description of each parameter follows:
668 % o delegate_info: The delegate info.
671 MagickExport MagickBooleanType GetDelegateThreadSupport(
672 const DelegateInfo *delegate_info)
674 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
675 assert(delegate_info != (DelegateInfo *) NULL);
676 assert(delegate_info->signature == MagickSignature);
677 return(delegate_info->thread_support);
681 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
685 + I n i t i a l i z e D e l e g a t e L i s t %
689 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
691 % InitializeDelegateList() initializes the delegate list.
693 % The format of the InitializeDelegateList method is:
695 % MagickBooleanType InitializeDelegateList(ExceptionInfo *exception)
697 % A description of each parameter follows.
699 % o exception: return any errors or warnings in this structure.
702 static MagickBooleanType InitializeDelegateList(ExceptionInfo *exception)
704 if ((delegate_list == (LinkedListInfo *) NULL) &&
705 (instantiate_delegate == MagickFalse))
707 if (delegate_semaphore == (SemaphoreInfo *) NULL)
708 AcquireSemaphoreInfo(&delegate_semaphore);
709 LockSemaphoreInfo(delegate_semaphore);
710 if ((delegate_list == (LinkedListInfo *) NULL) &&
711 (instantiate_delegate == MagickFalse))
713 (void) LoadDelegateLists(DelegateFilename,exception);
714 instantiate_delegate=MagickTrue;
716 UnlockSemaphoreInfo(delegate_semaphore);
718 return(delegate_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
722 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
726 % I n v o k e D e l e g a t e %
730 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
732 % InvokeDelegate replaces any embedded formatting characters with the
733 % appropriate image attribute and executes the resulting command. MagickFalse
734 % is returned if the commands execute with success otherwise MagickTrue.
736 % The format of the InvokeDelegate method is:
738 % MagickBooleanType InvokeDelegate(ImageInfo *image_info,Image *image,
739 % const char *decode,const char *encode,ExceptionInfo *exception)
741 % A description of each parameter follows:
743 % o image_info: the imageInfo.
745 % o image: the image.
747 % o exception: return any errors or warnings in this structure.
751 static inline size_t MagickMin(const size_t x,const size_t y)
758 static MagickBooleanType CopyDelegateFile(const char *source,
759 const char *destination)
785 Return if destination file already exists and is not empty.
787 assert(source != (const char *) NULL);
788 assert(destination != (char *) NULL);
789 status=GetPathAttributes(destination,&attributes);
790 if ((status != MagickFalse) && (attributes.st_size != 0))
793 Copy source file to destination.
795 destination_file=open(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
796 if (destination_file == -1)
798 source_file=open(source,O_RDONLY | O_BINARY);
799 if (source_file == -1)
801 (void) close(destination_file);
804 quantum=(size_t) MagickMaxBufferExtent;
805 if ((fstat(source_file,&attributes) == 0) && (attributes.st_size != 0))
806 quantum=MagickMin((size_t) attributes.st_size,MagickMaxBufferExtent);
807 buffer=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*buffer));
808 if (buffer == (unsigned char *) NULL)
810 (void) close(source_file);
811 (void) close(destination_file);
815 for (i=0; ; i+=count)
817 count=(ssize_t) read(source_file,buffer,quantum);
820 length=(size_t) count;
821 count=(ssize_t) write(destination_file,buffer,length);
822 if ((size_t) count != length)
825 (void) close(destination_file);
826 (void) close(source_file);
827 buffer=(unsigned char *) RelinquishMagickMemory(buffer);
828 return(i != 0 ? MagickTrue : MagickFalse);
831 MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
832 Image *image,const char *decode,const char *encode,ExceptionInfo *exception)
837 input_filename[MaxTextExtent],
838 output_filename[MaxTextExtent];
856 assert(image_info != (ImageInfo *) NULL);
857 assert(image_info->signature == MagickSignature);
858 assert(image != (Image *) NULL);
859 assert(image->signature == MagickSignature);
860 if (image->debug != MagickFalse)
861 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
862 rights=ExecutePolicyRights;
863 if (IsRightsAuthorized(DelegatePolicyDomain,rights,decode) == MagickFalse)
866 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
867 "NotAuthorized","`%s'",decode);
870 if (IsRightsAuthorized(DelegatePolicyDomain,rights,encode) == MagickFalse)
873 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
874 "NotAuthorized","`%s'",encode);
877 temporary=(*image->filename == '\0') ? MagickTrue : MagickFalse;
878 if (temporary != MagickFalse)
879 if (AcquireUniqueFilename(image->filename) == MagickFalse)
881 ThrowFileException(exception,FileOpenError,
882 "UnableToCreateTemporaryFile",image->filename);
885 delegate_info=GetDelegateInfo(decode,encode,exception);
886 if (delegate_info == (DelegateInfo *) NULL)
888 if (temporary != MagickFalse)
889 (void) RelinquishUniqueFileResource(image->filename);
890 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
891 "NoTagFound","`%s'",decode ? decode : encode);
894 if (*image_info->filename == '\0')
896 if (AcquireUniqueFilename(image_info->filename) == MagickFalse)
898 if (temporary != MagickFalse)
899 (void) RelinquishUniqueFileResource(image->filename);
900 ThrowFileException(exception,FileOpenError,
901 "UnableToCreateTemporaryFile",image_info->filename);
904 image_info->temporary=MagickTrue;
906 if ((delegate_info->mode != 0) &&
907 (((decode != (const char *) NULL) &&
908 (delegate_info->encode != (char *) NULL)) ||
909 ((encode != (const char *) NULL) &&
910 (delegate_info->decode != (char *) NULL))))
922 Delegate requires a particular image format.
924 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
926 ThrowFileException(exception,FileOpenError,
927 "UnableToCreateTemporaryFile",image_info->unique);
930 if (AcquireUniqueFilename(image_info->zero) == MagickFalse)
932 (void) RelinquishUniqueFileResource(image_info->zero);
933 ThrowFileException(exception,FileOpenError,
934 "UnableToCreateTemporaryFile",image_info->zero);
937 magick=InterpretImageProperties(image_info,image,decode != (char *) NULL ?
938 delegate_info->encode : delegate_info->decode);
939 if (magick == (char *) NULL)
941 (void) RelinquishUniqueFileResource(image_info->unique);
942 (void) RelinquishUniqueFileResource(image_info->zero);
943 if (temporary != MagickFalse)
944 (void) RelinquishUniqueFileResource(image->filename);
945 (void) ThrowMagickException(exception,GetMagickModule(),
946 DelegateError,"DelegateFailed","`%s'",decode ? decode : encode);
950 clone_info=CloneImageInfo(image_info);
951 (void) CopyMagickString((char *) clone_info->magick,magick,
953 if (LocaleCompare(magick,"NULL") != 0)
954 (void) CopyMagickString(image->magick,magick,MaxTextExtent);
955 magick=DestroyString(magick);
956 (void) FormatMagickString(clone_info->filename,MaxTextExtent,"%s:",
957 delegate_info->decode);
958 (void) SetImageInfo(clone_info,(unsigned int) GetImageListLength(image),
960 (void) CopyMagickString(clone_info->filename,image_info->filename,
962 (void) CopyMagickString(image_info->filename,image->filename,
964 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
966 (void) FormatMagickString(p->filename,MaxTextExtent,"%s:%s",
967 delegate_info->decode,clone_info->filename);
968 status=WriteImage(clone_info,p);
969 if (status == MagickFalse)
971 (void) RelinquishUniqueFileResource(image_info->unique);
972 (void) RelinquishUniqueFileResource(image_info->zero);
973 if (temporary != MagickFalse)
974 (void) RelinquishUniqueFileResource(image->filename);
975 clone_info=DestroyImageInfo(clone_info);
976 (void) ThrowMagickException(exception,GetMagickModule(),
977 DelegateError,"DelegateFailed","`%s'",decode ? decode : encode);
980 if (clone_info->adjoin != MagickFalse)
983 (void) RelinquishUniqueFileResource(image_info->unique);
984 (void) RelinquishUniqueFileResource(image_info->zero);
985 clone_info=DestroyImageInfo(clone_info);
990 commands=StringToList(delegate_info->commands);
991 if (commands == (char **) NULL)
993 if (temporary != MagickFalse)
994 (void) RelinquishUniqueFileResource(image->filename);
995 (void) ThrowMagickException(exception,GetMagickModule(),
996 ResourceLimitError,"MemoryAllocationFailed","`%s'",
997 decode ? decode : encode);
1000 command=(char *) NULL;
1002 (void) CopyMagickString(output_filename,image_info->filename,MaxTextExtent);
1003 (void) CopyMagickString(input_filename,image->filename,MaxTextExtent);
1004 for (i=0; commands[i] != (char *) NULL; i++)
1006 status=AcquireUniqueSymbolicLink(output_filename,image_info->filename);
1007 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1009 ThrowFileException(exception,FileOpenError,
1010 "UnableToCreateTemporaryFile",image_info->unique);
1013 if (AcquireUniqueFilename(image_info->zero) == MagickFalse)
1015 (void) RelinquishUniqueFileResource(image_info->unique);
1016 ThrowFileException(exception,FileOpenError,
1017 "UnableToCreateTemporaryFile",image_info->zero);
1020 if (LocaleCompare(decode,"SCAN") != 0)
1022 status=AcquireUniqueSymbolicLink(input_filename,image->filename);
1023 if (status == MagickFalse)
1025 ThrowFileException(exception,FileOpenError,
1026 "UnableToCreateTemporaryFile",input_filename);
1031 command=InterpretImageProperties(image_info,image,commands[i]);
1032 if (command != (char *) NULL)
1037 status=SystemCommand(delegate_info->spawn,image_info->verbose,command,
1038 exception) != 0 ? MagickTrue : MagickFalse;
1039 if (delegate_info->spawn != MagickFalse)
1041 command=DestroyString(command);
1043 if (LocaleCompare(decode,"SCAN") != 0)
1045 if (CopyDelegateFile(image->filename,input_filename) == MagickFalse)
1046 (void) RelinquishUniqueFileResource(input_filename);
1048 if (CopyDelegateFile(image_info->filename,output_filename) == MagickFalse)
1049 (void) RelinquishUniqueFileResource(output_filename);
1050 if (image_info->temporary != MagickFalse)
1051 (void) RelinquishUniqueFileResource(image_info->filename);
1052 (void) RelinquishUniqueFileResource(image_info->unique);
1053 (void) RelinquishUniqueFileResource(image_info->zero);
1054 (void) RelinquishUniqueFileResource(image_info->filename);
1055 (void) RelinquishUniqueFileResource(image->filename);
1056 if (status != MagickFalse)
1058 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1059 "DelegateFailed","`%s'",commands[i]);
1062 commands[i]=DestroyString(commands[i]);
1064 (void) CopyMagickString(image_info->filename,output_filename,MaxTextExtent);
1065 (void) CopyMagickString(image->filename,input_filename,MaxTextExtent);
1067 Relinquish resources.
1069 for ( ; commands[i] != (char *) NULL; i++)
1070 commands[i]=DestroyString(commands[i]);
1071 commands=(char **) RelinquishMagickMemory(commands);
1072 if (temporary != MagickFalse)
1073 (void) RelinquishUniqueFileResource(image->filename);
1074 return(status == MagickFalse ? MagickTrue : MagickFalse);
1078 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1082 % L i s t D e l e g a t e I n f o %
1086 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1088 % ListDelegateInfo() lists the image formats to a file.
1090 % The format of the ListDelegateInfo method is:
1092 % MagickBooleanType ListDelegateInfo(FILE *file,ExceptionInfo *exception)
1094 % A description of each parameter follows.
1096 % o file: An pointer to a FILE.
1098 % o exception: return any errors or warnings in this structure.
1101 MagickExport MagickBooleanType ListDelegateInfo(FILE *file,
1102 ExceptionInfo *exception)
1109 delegate[MaxTextExtent];
1123 if (file == (const FILE *) NULL)
1125 delegate_info=GetDelegateInfoList("*",&number_delegates,exception);
1126 if (delegate_info == (const DelegateInfo **) NULL)
1127 return(MagickFalse);
1128 path=(const char *) NULL;
1129 for (i=0; i < (ssize_t) number_delegates; i++)
1131 if (delegate_info[i]->stealth != MagickFalse)
1133 if ((path == (const char *) NULL) ||
1134 (LocaleCompare(path,delegate_info[i]->path) != 0))
1136 if (delegate_info[i]->path != (char *) NULL)
1137 (void) fprintf(file,"\nPath: %s\n\n",delegate_info[i]->path);
1138 (void) fprintf(file,"Delegate Command\n");
1139 (void) fprintf(file,"-------------------------------------------------"
1140 "------------------------------\n");
1142 path=delegate_info[i]->path;
1144 if (delegate_info[i]->encode != (char *) NULL)
1145 (void) CopyMagickString(delegate,delegate_info[i]->encode,MaxTextExtent);
1146 (void) ConcatenateMagickString(delegate," ",MaxTextExtent);
1148 commands=StringToList(delegate_info[i]->commands);
1149 if (commands == (char **) NULL)
1151 (void) fprintf(file,"%11s%c=%c%s ",delegate_info[i]->decode ?
1152 delegate_info[i]->decode : "",delegate_info[i]->mode <= 0 ? '<' : ' ',
1153 delegate_info[i]->mode >= 0 ? '>' : ' ',delegate);
1154 StripString(commands[0]);
1155 (void) fprintf(file,"\"%s\"\n",commands[0]);
1156 for (j=1; commands[j] != (char *) NULL; j++)
1158 StripString(commands[j]);
1159 (void) fprintf(file," \"%s\"\n",commands[j]);
1161 for (j=0; commands[j] != (char *) NULL; j++)
1162 commands[j]=DestroyString(commands[j]);
1163 commands=(char **) RelinquishMagickMemory(commands);
1165 (void) fflush(file);
1166 delegate_info=(const DelegateInfo **)
1167 RelinquishMagickMemory((void *) delegate_info);
1172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1176 + L o a d D e l e g a t e L i s t %
1180 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1182 % LoadDelegateList() loads the delegate configuration file which provides a
1183 % mapping between delegate attributes and a delegate name.
1185 % The format of the LoadDelegateList method is:
1187 % MagickBooleanType LoadDelegateList(const char *xml,const char *filename,
1188 % const size_t depth,ExceptionInfo *exception)
1190 % A description of each parameter follows:
1192 % o xml: The delegate list in XML format.
1194 % o filename: The delegate list filename.
1196 % o depth: depth of <include /> statements.
1198 % o exception: return any errors or warnings in this structure.
1201 static MagickBooleanType LoadDelegateList(const char *xml,const char *filename,
1202 const size_t depth,ExceptionInfo *exception)
1205 keyword[MaxTextExtent],
1218 Load the delegate map file.
1220 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1221 "Loading delegate configuration file \"%s\" ...",filename);
1222 if (xml == (const char *) NULL)
1223 return(MagickFalse);
1224 if (delegate_list == (LinkedListInfo *) NULL)
1226 delegate_list=NewLinkedList(0);
1227 if (delegate_list == (LinkedListInfo *) NULL)
1229 ThrowFileException(exception,ResourceLimitError,
1230 "MemoryAllocationFailed",filename);
1231 return(MagickFalse);
1235 delegate_info=(DelegateInfo *) NULL;
1236 token=AcquireString(xml);
1237 for (q=(const char *) xml; *q != '\0'; )
1242 GetMagickToken(q,&q,token);
1245 (void) CopyMagickString(keyword,token,MaxTextExtent);
1246 if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
1251 while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
1252 GetMagickToken(q,&q,token);
1255 if (LocaleNCompare(keyword,"<!--",4) == 0)
1260 while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
1261 GetMagickToken(q,&q,token);
1264 if (LocaleCompare(keyword,"<include") == 0)
1269 while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
1271 (void) CopyMagickString(keyword,token,MaxTextExtent);
1272 GetMagickToken(q,&q,token);
1275 GetMagickToken(q,&q,token);
1276 if (LocaleCompare(keyword,"file") == 0)
1279 (void) ThrowMagickException(exception,GetMagickModule(),
1280 ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token);
1284 path[MaxTextExtent],
1287 GetPathComponent(filename,HeadPath,path);
1289 (void) ConcatenateMagickString(path,DirectorySeparator,
1291 if (*token == *DirectorySeparator)
1292 (void) CopyMagickString(path,token,MaxTextExtent);
1294 (void) ConcatenateMagickString(path,token,MaxTextExtent);
1295 xml=FileToString(path,~0,exception);
1296 if (xml != (char *) NULL)
1298 status=LoadDelegateList(xml,path,depth+1,exception);
1299 xml=(char *) RelinquishMagickMemory(xml);
1306 if (LocaleCompare(keyword,"<delegate") == 0)
1311 delegate_info=(DelegateInfo *) AcquireMagickMemory(
1312 sizeof(*delegate_info));
1313 if (delegate_info == (DelegateInfo *) NULL)
1314 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
1315 (void) ResetMagickMemory(delegate_info,0,sizeof(*delegate_info));
1316 delegate_info->path=ConstantString(filename);
1317 delegate_info->signature=MagickSignature;
1320 if (delegate_info == (DelegateInfo *) NULL)
1322 if (LocaleCompare(keyword,"/>") == 0)
1324 status=AppendValueToLinkedList(delegate_list,delegate_info);
1325 if (status == MagickFalse)
1326 (void) ThrowMagickException(exception,GetMagickModule(),
1327 ResourceLimitError,"MemoryAllocationFailed","`%s'",
1328 delegate_info->commands);
1329 delegate_info=(DelegateInfo *) NULL;
1331 GetMagickToken(q,(const char **) NULL,token);
1334 GetMagickToken(q,&q,token);
1335 GetMagickToken(q,&q,token);
1341 if (LocaleCompare((char *) keyword,"command") == 0)
1346 commands=AcquireString(token);
1347 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
1348 if (strchr(commands,'@') != (char *) NULL)
1351 path[MaxTextExtent];
1353 NTGhostscriptEXE(path,MaxTextExtent);
1354 (void) SubstituteString((char **) &commands,"@PSDelegate@",
1356 (void) SubstituteString((char **) &commands,"\\","/");
1359 (void) SubstituteString((char **) &commands,"&","&");
1360 (void) SubstituteString((char **) &commands,""","\"");
1361 (void) SubstituteString((char **) &commands,">",">");
1362 (void) SubstituteString((char **) &commands,"<","<");
1363 delegate_info->commands=commands;
1371 if (LocaleCompare((char *) keyword,"decode") == 0)
1373 delegate_info->decode=ConstantString(token);
1374 delegate_info->mode=1;
1382 if (LocaleCompare((char *) keyword,"encode") == 0)
1384 delegate_info->encode=ConstantString(token);
1385 delegate_info->mode=(-1);
1393 if (LocaleCompare((char *) keyword,"mode") == 0)
1395 delegate_info->mode=1;
1396 if (LocaleCompare(token,"bi") == 0)
1397 delegate_info->mode=0;
1399 if (LocaleCompare(token,"encode") == 0)
1400 delegate_info->mode=(-1);
1408 if (LocaleCompare((char *) keyword,"spawn") == 0)
1410 delegate_info->spawn=IsMagickTrue(token);
1413 if (LocaleCompare((char *) keyword,"stealth") == 0)
1415 delegate_info->stealth=IsMagickTrue(token);
1423 if (LocaleCompare((char *) keyword,"thread-support") == 0)
1425 delegate_info->thread_support=IsMagickTrue(token);
1434 token=(char *) RelinquishMagickMemory(token);
1439 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1443 % L o a d D e l e g a t e L i s t s %
1447 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1449 % LoadDelegateList() loads one or more delegate configuration file which
1450 % provides a mapping between delegate attributes and a delegate name.
1452 % The format of the LoadDelegateLists method is:
1454 % MagickBooleanType LoadDelegateLists(const char *filename,
1455 % ExceptionInfo *exception)
1457 % A description of each parameter follows:
1459 % o filename: the font file name.
1461 % o exception: return any errors or warnings in this structure.
1464 static MagickBooleanType LoadDelegateLists(const char *filename,
1465 ExceptionInfo *exception)
1467 #if defined(MAGICKCORE_EMBEDDABLE_SUPPORT)
1468 return(LoadDelegateList(DelegateMap,"built-in",0,exception));
1480 options=GetConfigureOptions(filename,exception);
1481 option=(const StringInfo *) GetNextValueInLinkedList(options);
1482 while (option != (const StringInfo *) NULL)
1484 status|=LoadDelegateList((const char *) GetStringInfoDatum(option),
1485 GetStringInfoPath(option),0,exception);
1486 option=(const StringInfo *) GetNextValueInLinkedList(options);
1488 options=DestroyConfigureOptions(options);
1489 if ((delegate_list == (LinkedListInfo *) NULL) ||
1490 (IsLinkedListEmpty(delegate_list) != MagickFalse))
1491 status|=LoadDelegateList(DelegateMap,"built-in",0,exception);
1492 return(status != 0 ? MagickTrue : MagickFalse);