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-2010 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=\"hdr\" command=\""ra_pfm" "%i" "%o"\"/>"
91 " <delegate decode=\"hpg\" command=\""hp2xx" -q -m eps -f `basename "%o"` "%i" mv -f `basename "%o"` "%o"\"/>"
92 " <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\"/>"
93 " <delegate decode=\"htm\" command=\""html2ps" -U -o "%o" "%i"\"/>"
94 " <delegate decode=\"html\" command=\""html2ps" -U -o "%o" "%i"\"/>"
95 " <delegate decode=\"https\" command=\""wget" -q -O "%o" "https:%M"\"/>"
96 " <delegate decode=\"ilbm\" command=\""ilbmtoppm" "%i" > "%o"\"/>"
97 " <delegate decode=\"man\" command=\""groff" -man -Tps "%i" > "%o"\"/>"
98 " <delegate decode=\"mpeg:decode\" stealth=\"True\" command=\""ffmpeg" --i "%i" -vcodec pam -an -f rawvideo -y "%u0.pam" 2;> "%Z"\"/>"
99 " <delegate decode=\"null\" encode=\"mpeg:encode\" stealth=\"True\" command=\""ffmpeg" "%M%%d.jpg" "%u.%m" 2;> "%Z"\"/>"
100 " <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"\"/>"
101 " <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"\"/>"
102 " <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"\"/>"
103 " <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"\"/>"
104 " <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"\"/>"
105 " <delegate decode=\"pic\" command=\""ra_pfm" "%i" "%o"\"/>"
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 -dPARANOIDSAFE -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 -dPARANOIDSAFE -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 -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"\"/>"
113 " <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"\"/>"
114 " <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"\"/>"
115 " <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"\"/>"
116 " <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"\"/>"
117 " <delegate decode=\"rad\" command=\""ra_pfm" "%i" "%o"\"/>"
118 " <delegate decode=\"rgba\" encode=\"rle\" mode=\"encode\" command=\""rawtorle" -o "%o" -v "%i"\"/>"
119 " <delegate decode=\"scan\" command=\""scanimage" -d "%i" > "%o"\"/>"
120 " <delegate encode=\"show\" spawn=\"True\" command=\""/usr/local/bin/display" -immutable -delay 0 -window-group %g -title "%l of %f" "temporary:%i"\"/>"
121 " <delegate decode=\"shtml\" command=\""html2ps" -U -o "%o" "%i"\"/>"
122 " <delegate decode=\"svg\" command=\""rsvg" "%i" "%o"\"/>"
123 " <delegate decode=\"txt\" encode=\"ps\" mode=\"bi\" command=\""enscript" -o "%o" "%i"\"/>"
124 " <delegate encode=\"win\" stealth=\"True\" spawn=\"True\" command=\""/usr/local/bin/display" -immutable -delay 0 -window-group %g -title "%l of %f" "temporary:%i"\"/>"
125 " <delegate decode=\"wmf\" command=\""wmf2eps" -o "%o" "%i"\"/>"
129 Global declaractions.
131 static LinkedListInfo
132 *delegate_list = (LinkedListInfo *) NULL;
135 *delegate_semaphore = (SemaphoreInfo *) NULL;
137 static volatile MagickBooleanType
138 instantiate_delegate = MagickFalse;
141 Forward declaractions.
143 static MagickBooleanType
144 InitializeDelegateList(ExceptionInfo *),
145 LoadDelegateLists(const char *,ExceptionInfo *);
148 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152 + 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 %
156 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158 % DelegateComponentGenesis() instantiates the delegate component.
160 % The format of the DelegateComponentGenesis method is:
162 % MagickBooleanType DelegateComponentGenesis(void)
165 MagickExport MagickBooleanType DelegateComponentGenesis(void)
167 AcquireSemaphoreInfo(&delegate_semaphore);
172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
176 % 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 %
180 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 % DelegateComponentTerminus() destroys the delegate component.
184 % The format of the DelegateComponentTerminus method is:
186 % DelegateComponentTerminus(void)
190 static void *DestroyDelegate(void *delegate_info)
192 register DelegateInfo
195 p=(DelegateInfo *) delegate_info;
196 if (p->path != (char *) NULL)
197 p->path=DestroyString(p->path);
198 if (p->decode != (char *) NULL)
199 p->decode=DestroyString(p->decode);
200 if (p->encode != (char *) NULL)
201 p->encode=DestroyString(p->encode);
202 if (p->commands != (char *) NULL)
203 p->commands=DestroyString(p->commands);
204 p=(DelegateInfo *) RelinquishMagickMemory(p);
205 return((void *) NULL);
209 MagickExport void DelegateComponentTerminus(void)
211 if (delegate_semaphore == (SemaphoreInfo *) NULL)
212 AcquireSemaphoreInfo(&delegate_semaphore);
213 LockSemaphoreInfo(delegate_semaphore);
214 if (delegate_list != (LinkedListInfo *) NULL)
215 delegate_list=DestroyLinkedList(delegate_list,DestroyDelegate);
216 instantiate_delegate=MagickFalse;
217 UnlockSemaphoreInfo(delegate_semaphore);
218 DestroySemaphoreInfo(&delegate_semaphore);
222 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226 % G e t D e l e g a t e C o m m a n d %
230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232 % GetDelegateCommand() replaces any embedded formatting characters with the
233 % appropriate image attribute and returns the resulting command.
235 % The format of the GetDelegateCommand method is:
237 % char *GetDelegateCommand(const ImageInfo *image_info,Image *image,
238 % const char *decode,const char *encode,ExceptionInfo *exception)
240 % A description of each parameter follows:
242 % o command: Method GetDelegateCommand returns the command associated
243 % with specified delegate tag.
245 % o image_info: the image info.
247 % o image: the image.
249 % o decode: Specifies the decode delegate we are searching for as a
252 % o encode: Specifies the encode delegate we are searching for as a
255 % o exception: return any errors or warnings in this structure.
258 MagickExport char *GetDelegateCommand(const ImageInfo *image_info,Image *image,
259 const char *decode,const char *encode,ExceptionInfo *exception)
271 assert(image_info != (ImageInfo *) NULL);
272 assert(image_info->signature == MagickSignature);
273 assert(image != (Image *) NULL);
274 assert(image->signature == MagickSignature);
275 if (image->debug != MagickFalse)
276 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
277 delegate_info=GetDelegateInfo(decode,encode,exception);
278 if (delegate_info == (const DelegateInfo *) NULL)
280 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
281 "NoTagFound","`%s'",decode ? decode : encode);
282 return((char *) NULL);
284 commands=StringToList(delegate_info->commands);
285 if (commands == (char **) NULL)
287 (void) ThrowMagickException(exception,GetMagickModule(),
288 ResourceLimitError,"MemoryAllocationFailed","`%s'",
289 decode ? decode : encode);
290 return((char *) NULL);
292 command=InterpretImageProperties(image_info,image,commands[0]);
293 if (command == (char *) NULL)
294 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
295 "MemoryAllocationFailed","`%s'",commands[0]);
297 Relinquish resources.
299 for (i=0; commands[i] != (char *) NULL; i++)
300 commands[i]=DestroyString(commands[i]);
301 commands=(char **) RelinquishMagickMemory(commands);
306 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
310 % G e t D e l e g a t e C o m m a n d s %
314 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
316 % GetDelegateCommands() returns the commands associated with a delegate.
318 % The format of the GetDelegateCommands method is:
320 % const char *GetDelegateCommands(const DelegateInfo *delegate_info)
322 % A description of each parameter follows:
324 % o delegate_info: The delegate info.
327 MagickExport const char *GetDelegateCommands(const DelegateInfo *delegate_info)
329 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
330 assert(delegate_info != (DelegateInfo *) NULL);
331 assert(delegate_info->signature == MagickSignature);
332 return(delegate_info->commands);
336 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
340 % G e t D e l e g a t e I n f o %
344 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
346 % GetDelegateInfo() returns any delegates associated with the specified tag.
348 % The format of the GetDelegateInfo method is:
350 % const DelegateInfo *GetDelegateInfo(const char *decode,
351 % const char *encode,ExceptionInfo *exception)
353 % A description of each parameter follows:
355 % o decode: Specifies the decode delegate we are searching for as a
358 % o encode: Specifies the encode delegate we are searching for as a
361 % o exception: return any errors or warnings in this structure.
364 MagickExport const DelegateInfo *GetDelegateInfo(const char *decode,
365 const char *encode,ExceptionInfo *exception)
367 register const DelegateInfo
370 assert(exception != (ExceptionInfo *) NULL);
371 if ((delegate_list == (LinkedListInfo *) NULL) ||
372 (instantiate_delegate == MagickFalse))
373 if (InitializeDelegateList(exception) == MagickFalse)
374 return((const DelegateInfo *) NULL);
375 if ((delegate_list == (LinkedListInfo *) NULL) ||
376 (IsLinkedListEmpty(delegate_list) != MagickFalse))
377 return((const DelegateInfo *) NULL);
378 if ((LocaleCompare(decode,"*") == 0) && (LocaleCompare(encode,"*") == 0))
379 return((const DelegateInfo *) GetValueFromLinkedList(delegate_list,0));
381 Search for named delegate.
383 LockSemaphoreInfo(delegate_semaphore);
384 ResetLinkedListIterator(delegate_list);
385 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
386 while (p != (const DelegateInfo *) NULL)
390 if (LocaleCompare(p->decode,decode) == 0)
392 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
397 if (LocaleCompare(p->encode,encode) == 0)
399 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
402 if (LocaleCompare(decode,p->decode) == 0)
403 if (LocaleCompare(encode,p->encode) == 0)
405 if (LocaleCompare(decode,"*") == 0)
406 if (LocaleCompare(encode,p->encode) == 0)
408 if (LocaleCompare(decode,p->decode) == 0)
409 if (LocaleCompare(encode,"*") == 0)
411 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
413 if (p != (const DelegateInfo *) NULL)
414 (void) InsertValueInLinkedList(delegate_list,0,
415 RemoveElementByValueFromLinkedList(delegate_list,p));
416 UnlockSemaphoreInfo(delegate_semaphore);
421 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
425 % G e t D e l e g a t e I n f o L i s t %
429 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
431 % GetDelegateInfoList() returns any delegates that match the specified pattern.
433 % The delegate of the GetDelegateInfoList function is:
435 % const DelegateInfo **GetDelegateInfoList(const char *pattern,
436 % size_t *number_delegates,ExceptionInfo *exception)
438 % A description of each parameter follows:
440 % o pattern: Specifies a pointer to a text string containing a pattern.
442 % o number_delegates: This integer returns the number of delegates in the
445 % o exception: return any errors or warnings in this structure.
449 #if defined(__cplusplus) || defined(c_plusplus)
453 static int DelegateInfoCompare(const void *x,const void *y)
459 p=(const DelegateInfo **) x,
460 q=(const DelegateInfo **) y;
461 if (LocaleCompare((*p)->path,(*q)->path) == 0)
463 if ((*p)->decode == (char *) NULL)
464 if (((*p)->encode != (char *) NULL) &&
465 ((*q)->encode != (char *) NULL))
466 return(strcmp((*p)->encode,(*q)->encode));
467 if (((*p)->decode != (char *) NULL) &&
468 ((*q)->decode != (char *) NULL))
469 return(strcmp((*p)->decode,(*q)->decode));
471 return(LocaleCompare((*p)->path,(*q)->path));
474 #if defined(__cplusplus) || defined(c_plusplus)
478 MagickExport const DelegateInfo **GetDelegateInfoList(const char *pattern,
479 size_t *number_delegates,ExceptionInfo *exception)
484 register const DelegateInfo
491 Allocate delegate list.
493 assert(pattern != (char *) NULL);
494 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
495 assert(number_delegates != (size_t *) NULL);
497 p=GetDelegateInfo("*","*",exception);
498 if (p == (const DelegateInfo *) NULL)
499 return((const DelegateInfo **) NULL);
500 delegates=(const DelegateInfo **) AcquireQuantumMemory((size_t)
501 GetNumberOfElementsInLinkedList(delegate_list)+1UL,sizeof(*delegates));
502 if (delegates == (const DelegateInfo **) NULL)
503 return((const DelegateInfo **) NULL);
505 Generate delegate list.
507 LockSemaphoreInfo(delegate_semaphore);
508 ResetLinkedListIterator(delegate_list);
509 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
510 for (i=0; p != (const DelegateInfo *) NULL; )
512 if ((p->stealth == MagickFalse) &&
513 ((GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse) ||
514 (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse)))
516 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
518 UnlockSemaphoreInfo(delegate_semaphore);
519 qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateInfoCompare);
520 delegates[i]=(DelegateInfo *) NULL;
521 *number_delegates=(size_t) i;
526 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
530 % G e t D e l e g a t e L i s t %
534 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
536 % GetDelegateList() returns any image format delegates that match the
539 % The format of the GetDelegateList function is:
541 % char **GetDelegateList(const char *pattern,
542 % size_t *number_delegates,ExceptionInfo *exception)
544 % A description of each parameter follows:
546 % o pattern: Specifies a pointer to a text string containing a pattern.
548 % o number_delegates: This integer returns the number of delegates
551 % o exception: return any errors or warnings in this structure.
555 #if defined(__cplusplus) || defined(c_plusplus)
559 static int DelegateCompare(const void *x,const void *y)
567 return(LocaleCompare(*p,*q));
570 #if defined(__cplusplus) || defined(c_plusplus)
574 MagickExport char **GetDelegateList(const char *pattern,
575 size_t *number_delegates,ExceptionInfo *exception)
580 register const DelegateInfo
587 Allocate delegate list.
589 assert(pattern != (char *) NULL);
590 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
591 assert(number_delegates != (size_t *) NULL);
593 p=GetDelegateInfo("*","*",exception);
594 if (p == (const DelegateInfo *) NULL)
595 return((char **) NULL);
596 delegates=(char **) AcquireQuantumMemory((size_t)
597 GetNumberOfElementsInLinkedList(delegate_list)+1UL,sizeof(*delegates));
598 if (delegates == (char **) NULL)
599 return((char **) NULL);
600 LockSemaphoreInfo(delegate_semaphore);
601 ResetLinkedListIterator(delegate_list);
602 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
603 for (i=0; p != (const DelegateInfo *) NULL; )
605 if ((p->stealth == MagickFalse) &&
606 (GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse))
607 delegates[i++]=ConstantString(p->decode);
608 if ((p->stealth == MagickFalse) &&
609 (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse))
610 delegates[i++]=ConstantString(p->encode);
611 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
613 UnlockSemaphoreInfo(delegate_semaphore);
614 qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateCompare);
615 delegates[i]=(char *) NULL;
616 *number_delegates=(size_t) i;
621 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
625 % G e t D e l e g a t e M o d e %
629 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
631 % GetDelegateMode() returns the mode of the delegate.
633 % The format of the GetDelegateMode method is:
635 % ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
637 % A description of each parameter follows:
639 % o delegate_info: The delegate info.
642 MagickExport ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
644 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
645 assert(delegate_info != (DelegateInfo *) NULL);
646 assert(delegate_info->signature == MagickSignature);
647 return(delegate_info->mode);
651 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
655 + G e t D e l e g a t e T h r e a d S u p p o r t %
659 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
661 % GetDelegateThreadSupport() returns MagickTrue if the delegate supports
664 % The format of the GetDelegateThreadSupport method is:
666 % MagickBooleanType GetDelegateThreadSupport(
667 % const DelegateInfo *delegate_info)
669 % A description of each parameter follows:
671 % o delegate_info: The delegate info.
674 MagickExport MagickBooleanType GetDelegateThreadSupport(
675 const DelegateInfo *delegate_info)
677 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
678 assert(delegate_info != (DelegateInfo *) NULL);
679 assert(delegate_info->signature == MagickSignature);
680 return(delegate_info->thread_support);
684 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
688 + I n i t i a l i z e D e l e g a t e L i s t %
692 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
694 % InitializeDelegateList() initializes the delegate list.
696 % The format of the InitializeDelegateList method is:
698 % MagickBooleanType InitializeDelegateList(ExceptionInfo *exception)
700 % A description of each parameter follows.
702 % o exception: return any errors or warnings in this structure.
705 static MagickBooleanType InitializeDelegateList(ExceptionInfo *exception)
707 if ((delegate_list == (LinkedListInfo *) NULL) &&
708 (instantiate_delegate == MagickFalse))
710 if (delegate_semaphore == (SemaphoreInfo *) NULL)
711 AcquireSemaphoreInfo(&delegate_semaphore);
712 LockSemaphoreInfo(delegate_semaphore);
713 if ((delegate_list == (LinkedListInfo *) NULL) &&
714 (instantiate_delegate == MagickFalse))
716 (void) LoadDelegateLists(DelegateFilename,exception);
717 instantiate_delegate=MagickTrue;
719 UnlockSemaphoreInfo(delegate_semaphore);
721 return(delegate_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
725 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
729 % I n v o k e D e l e g a t e %
733 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
735 % InvokeDelegate replaces any embedded formatting characters with the
736 % appropriate image attribute and executes the resulting command. MagickFalse
737 % is returned if the commands execute with success otherwise MagickTrue.
739 % The format of the InvokeDelegate method is:
741 % MagickBooleanType InvokeDelegate(ImageInfo *image_info,Image *image,
742 % const char *decode,const char *encode,ExceptionInfo *exception)
744 % A description of each parameter follows:
746 % o image_info: the imageInfo.
748 % o image: the image.
750 % o exception: return any errors or warnings in this structure.
754 static inline size_t MagickMin(const size_t x,const size_t y)
761 static MagickBooleanType CopyDelegateFile(const char *source,
762 const char *destination)
788 Return if destination file already exists and is not empty.
790 assert(source != (const char *) NULL);
791 assert(destination != (char *) NULL);
792 status=GetPathAttributes(destination,&attributes);
793 if ((status != MagickFalse) && (attributes.st_size != 0))
796 Copy source file to destination.
798 destination_file=open(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
799 if (destination_file == -1)
801 source_file=open(source,O_RDONLY | O_BINARY);
802 if (source_file == -1)
804 (void) close(destination_file);
807 quantum=(size_t) MagickMaxBufferExtent;
808 if ((fstat(source_file,&attributes) == 0) && (attributes.st_size != 0))
809 quantum=MagickMin((size_t) attributes.st_size,MagickMaxBufferExtent);
810 buffer=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*buffer));
811 if (buffer == (unsigned char *) NULL)
813 (void) close(source_file);
814 (void) close(destination_file);
818 for (i=0; ; i+=count)
820 count=(ssize_t) read(source_file,buffer,quantum);
823 length=(size_t) count;
824 count=(ssize_t) write(destination_file,buffer,length);
825 if ((size_t) count != length)
828 (void) close(destination_file);
829 (void) close(source_file);
830 buffer=(unsigned char *) RelinquishMagickMemory(buffer);
831 return(i != 0 ? MagickTrue : MagickFalse);
834 MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
835 Image *image,const char *decode,const char *encode,ExceptionInfo *exception)
840 input_filename[MaxTextExtent],
841 output_filename[MaxTextExtent];
859 assert(image_info != (ImageInfo *) NULL);
860 assert(image_info->signature == MagickSignature);
861 assert(image != (Image *) NULL);
862 assert(image->signature == MagickSignature);
863 if (image->debug != MagickFalse)
864 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
865 rights=ExecutePolicyRights;
866 if (IsRightsAuthorized(DelegatePolicyDomain,rights,decode) == MagickFalse)
869 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
870 "NotAuthorized","`%s'",decode);
873 if (IsRightsAuthorized(DelegatePolicyDomain,rights,encode) == MagickFalse)
876 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
877 "NotAuthorized","`%s'",encode);
880 temporary=(*image->filename == '\0') ? MagickTrue : MagickFalse;
881 if (temporary != MagickFalse)
882 if (AcquireUniqueFilename(image->filename) == MagickFalse)
884 ThrowFileException(exception,FileOpenError,
885 "UnableToCreateTemporaryFile",image->filename);
888 delegate_info=GetDelegateInfo(decode,encode,exception);
889 if (delegate_info == (DelegateInfo *) NULL)
891 if (temporary != MagickFalse)
892 (void) RelinquishUniqueFileResource(image->filename);
893 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
894 "NoTagFound","`%s'",decode ? decode : encode);
897 if (*image_info->filename == '\0')
899 if (AcquireUniqueFilename(image_info->filename) == MagickFalse)
901 if (temporary != MagickFalse)
902 (void) RelinquishUniqueFileResource(image->filename);
903 ThrowFileException(exception,FileOpenError,
904 "UnableToCreateTemporaryFile",image_info->filename);
907 image_info->temporary=MagickTrue;
909 if ((delegate_info->mode != 0) &&
910 (((decode != (const char *) NULL) &&
911 (delegate_info->encode != (char *) NULL)) ||
912 ((encode != (const char *) NULL) &&
913 (delegate_info->decode != (char *) NULL))))
925 Delegate requires a particular image format.
927 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
929 ThrowFileException(exception,FileOpenError,
930 "UnableToCreateTemporaryFile",image_info->unique);
933 if (AcquireUniqueFilename(image_info->zero) == MagickFalse)
935 (void) RelinquishUniqueFileResource(image_info->zero);
936 ThrowFileException(exception,FileOpenError,
937 "UnableToCreateTemporaryFile",image_info->zero);
940 magick=InterpretImageProperties(image_info,image,decode != (char *) NULL ?
941 delegate_info->encode : delegate_info->decode);
942 if (magick == (char *) NULL)
944 (void) RelinquishUniqueFileResource(image_info->unique);
945 (void) RelinquishUniqueFileResource(image_info->zero);
946 if (temporary != MagickFalse)
947 (void) RelinquishUniqueFileResource(image->filename);
948 (void) ThrowMagickException(exception,GetMagickModule(),
949 DelegateError,"DelegateFailed","`%s'",decode ? decode : encode);
953 clone_info=CloneImageInfo(image_info);
954 (void) CopyMagickString((char *) clone_info->magick,magick,
956 if (LocaleCompare(magick,"NULL") != 0)
957 (void) CopyMagickString(image->magick,magick,MaxTextExtent);
958 magick=DestroyString(magick);
959 (void) FormatMagickString(clone_info->filename,MaxTextExtent,"%s:",
960 delegate_info->decode);
961 (void) SetImageInfo(clone_info,(unsigned int) GetImageListLength(image),
963 (void) CopyMagickString(clone_info->filename,image_info->filename,
965 (void) CopyMagickString(image_info->filename,image->filename,
967 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
969 (void) FormatMagickString(p->filename,MaxTextExtent,"%s:%s",
970 delegate_info->decode,clone_info->filename);
971 status=WriteImage(clone_info,p);
972 if (status == MagickFalse)
974 (void) RelinquishUniqueFileResource(image_info->unique);
975 (void) RelinquishUniqueFileResource(image_info->zero);
976 if (temporary != MagickFalse)
977 (void) RelinquishUniqueFileResource(image->filename);
978 clone_info=DestroyImageInfo(clone_info);
979 (void) ThrowMagickException(exception,GetMagickModule(),
980 DelegateError,"DelegateFailed","`%s'",decode ? decode : encode);
983 if (clone_info->adjoin != MagickFalse)
986 (void) RelinquishUniqueFileResource(image_info->unique);
987 (void) RelinquishUniqueFileResource(image_info->zero);
988 clone_info=DestroyImageInfo(clone_info);
993 commands=StringToList(delegate_info->commands);
994 if (commands == (char **) NULL)
996 if (temporary != MagickFalse)
997 (void) RelinquishUniqueFileResource(image->filename);
998 (void) ThrowMagickException(exception,GetMagickModule(),
999 ResourceLimitError,"MemoryAllocationFailed","`%s'",
1000 decode ? decode : encode);
1001 return(MagickFalse);
1003 command=(char *) NULL;
1005 (void) CopyMagickString(output_filename,image_info->filename,MaxTextExtent);
1006 (void) CopyMagickString(input_filename,image->filename,MaxTextExtent);
1007 for (i=0; commands[i] != (char *) NULL; i++)
1009 status=AcquireUniqueSymbolicLink(output_filename,image_info->filename);
1010 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1012 ThrowFileException(exception,FileOpenError,
1013 "UnableToCreateTemporaryFile",image_info->unique);
1016 if (AcquireUniqueFilename(image_info->zero) == MagickFalse)
1018 (void) RelinquishUniqueFileResource(image_info->unique);
1019 ThrowFileException(exception,FileOpenError,
1020 "UnableToCreateTemporaryFile",image_info->zero);
1023 if (LocaleCompare(decode,"SCAN") != 0)
1025 status=AcquireUniqueSymbolicLink(input_filename,image->filename);
1026 if (status == MagickFalse)
1028 ThrowFileException(exception,FileOpenError,
1029 "UnableToCreateTemporaryFile",input_filename);
1034 command=InterpretImageProperties(image_info,image,commands[i]);
1035 if (command != (char *) NULL)
1040 status=SystemCommand(delegate_info->spawn,image_info->verbose,command,
1041 exception) != 0 ? MagickTrue : MagickFalse;
1042 if (delegate_info->spawn != MagickFalse)
1044 command=DestroyString(command);
1046 if (LocaleCompare(decode,"SCAN") != 0)
1048 if (CopyDelegateFile(image->filename,input_filename) == MagickFalse)
1049 (void) RelinquishUniqueFileResource(input_filename);
1051 if (CopyDelegateFile(image_info->filename,output_filename) == MagickFalse)
1052 (void) RelinquishUniqueFileResource(output_filename);
1053 if (image_info->temporary != MagickFalse)
1054 (void) RelinquishUniqueFileResource(image_info->filename);
1055 (void) RelinquishUniqueFileResource(image_info->unique);
1056 (void) RelinquishUniqueFileResource(image_info->zero);
1057 (void) RelinquishUniqueFileResource(image_info->filename);
1058 (void) RelinquishUniqueFileResource(image->filename);
1059 if (status != MagickFalse)
1061 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1062 "DelegateFailed","`%s'",commands[i]);
1065 commands[i]=DestroyString(commands[i]);
1067 (void) CopyMagickString(image_info->filename,output_filename,MaxTextExtent);
1068 (void) CopyMagickString(image->filename,input_filename,MaxTextExtent);
1070 Relinquish resources.
1072 for ( ; commands[i] != (char *) NULL; i++)
1073 commands[i]=DestroyString(commands[i]);
1074 commands=(char **) RelinquishMagickMemory(commands);
1075 if (temporary != MagickFalse)
1076 (void) RelinquishUniqueFileResource(image->filename);
1077 return(status == MagickFalse ? MagickTrue : MagickFalse);
1081 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1085 % L i s t D e l e g a t e I n f o %
1089 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1091 % ListDelegateInfo() lists the image formats to a file.
1093 % The format of the ListDelegateInfo method is:
1095 % MagickBooleanType ListDelegateInfo(FILE *file,ExceptionInfo *exception)
1097 % A description of each parameter follows.
1099 % o file: An pointer to a FILE.
1101 % o exception: return any errors or warnings in this structure.
1104 MagickExport MagickBooleanType ListDelegateInfo(FILE *file,
1105 ExceptionInfo *exception)
1112 delegate[MaxTextExtent];
1126 if (file == (const FILE *) NULL)
1128 delegate_info=GetDelegateInfoList("*",&number_delegates,exception);
1129 if (delegate_info == (const DelegateInfo **) NULL)
1130 return(MagickFalse);
1131 path=(const char *) NULL;
1132 for (i=0; i < (ssize_t) number_delegates; i++)
1134 if (delegate_info[i]->stealth != MagickFalse)
1136 if ((path == (const char *) NULL) ||
1137 (LocaleCompare(path,delegate_info[i]->path) != 0))
1139 if (delegate_info[i]->path != (char *) NULL)
1140 (void) fprintf(file,"\nPath: %s\n\n",delegate_info[i]->path);
1141 (void) fprintf(file,"Delegate Command\n");
1142 (void) fprintf(file,"-------------------------------------------------"
1143 "------------------------------\n");
1145 path=delegate_info[i]->path;
1147 if (delegate_info[i]->encode != (char *) NULL)
1148 (void) CopyMagickString(delegate,delegate_info[i]->encode,MaxTextExtent);
1149 (void) ConcatenateMagickString(delegate," ",MaxTextExtent);
1151 commands=StringToList(delegate_info[i]->commands);
1152 if (commands == (char **) NULL)
1154 (void) fprintf(file,"%11s%c=%c%s ",delegate_info[i]->decode ?
1155 delegate_info[i]->decode : "",delegate_info[i]->mode <= 0 ? '<' : ' ',
1156 delegate_info[i]->mode >= 0 ? '>' : ' ',delegate);
1157 StripString(commands[0]);
1158 (void) fprintf(file,"\"%s\"\n",commands[0]);
1159 for (j=1; commands[j] != (char *) NULL; j++)
1161 StripString(commands[j]);
1162 (void) fprintf(file," \"%s\"\n",commands[j]);
1164 for (j=0; commands[j] != (char *) NULL; j++)
1165 commands[j]=DestroyString(commands[j]);
1166 commands=(char **) RelinquishMagickMemory(commands);
1168 (void) fflush(file);
1169 delegate_info=(const DelegateInfo **)
1170 RelinquishMagickMemory((void *) delegate_info);
1175 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1179 + L o a d D e l e g a t e L i s t %
1183 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1185 % LoadDelegateList() loads the delegate configuration file which provides a
1186 % mapping between delegate attributes and a delegate name.
1188 % The format of the LoadDelegateList method is:
1190 % MagickBooleanType LoadDelegateList(const char *xml,const char *filename,
1191 % const size_t depth,ExceptionInfo *exception)
1193 % A description of each parameter follows:
1195 % o xml: The delegate list in XML format.
1197 % o filename: The delegate list filename.
1199 % o depth: depth of <include /> statements.
1201 % o exception: return any errors or warnings in this structure.
1204 static MagickBooleanType LoadDelegateList(const char *xml,const char *filename,
1205 const size_t depth,ExceptionInfo *exception)
1208 keyword[MaxTextExtent],
1221 Load the delegate map file.
1223 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1224 "Loading delegate configuration file \"%s\" ...",filename);
1225 if (xml == (const char *) NULL)
1226 return(MagickFalse);
1227 if (delegate_list == (LinkedListInfo *) NULL)
1229 delegate_list=NewLinkedList(0);
1230 if (delegate_list == (LinkedListInfo *) NULL)
1232 ThrowFileException(exception,ResourceLimitError,
1233 "MemoryAllocationFailed",filename);
1234 return(MagickFalse);
1238 delegate_info=(DelegateInfo *) NULL;
1239 token=AcquireString(xml);
1240 for (q=(const char *) xml; *q != '\0'; )
1245 GetMagickToken(q,&q,token);
1248 (void) CopyMagickString(keyword,token,MaxTextExtent);
1249 if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
1254 while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
1255 GetMagickToken(q,&q,token);
1258 if (LocaleNCompare(keyword,"<!--",4) == 0)
1263 while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
1264 GetMagickToken(q,&q,token);
1267 if (LocaleCompare(keyword,"<include") == 0)
1272 while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
1274 (void) CopyMagickString(keyword,token,MaxTextExtent);
1275 GetMagickToken(q,&q,token);
1278 GetMagickToken(q,&q,token);
1279 if (LocaleCompare(keyword,"file") == 0)
1282 (void) ThrowMagickException(exception,GetMagickModule(),
1283 ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token);
1287 path[MaxTextExtent],
1290 GetPathComponent(filename,HeadPath,path);
1292 (void) ConcatenateMagickString(path,DirectorySeparator,
1294 if (*token == *DirectorySeparator)
1295 (void) CopyMagickString(path,token,MaxTextExtent);
1297 (void) ConcatenateMagickString(path,token,MaxTextExtent);
1298 xml=FileToString(path,~0,exception);
1299 if (xml != (char *) NULL)
1301 status=LoadDelegateList(xml,path,depth+1,exception);
1302 xml=(char *) RelinquishMagickMemory(xml);
1309 if (LocaleCompare(keyword,"<delegate") == 0)
1314 delegate_info=(DelegateInfo *) AcquireMagickMemory(
1315 sizeof(*delegate_info));
1316 if (delegate_info == (DelegateInfo *) NULL)
1317 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
1318 (void) ResetMagickMemory(delegate_info,0,sizeof(*delegate_info));
1319 delegate_info->path=ConstantString(filename);
1320 delegate_info->signature=MagickSignature;
1323 if (delegate_info == (DelegateInfo *) NULL)
1325 if (LocaleCompare(keyword,"/>") == 0)
1327 status=AppendValueToLinkedList(delegate_list,delegate_info);
1328 if (status == MagickFalse)
1329 (void) ThrowMagickException(exception,GetMagickModule(),
1330 ResourceLimitError,"MemoryAllocationFailed","`%s'",
1331 delegate_info->commands);
1332 delegate_info=(DelegateInfo *) NULL;
1334 GetMagickToken(q,(const char **) NULL,token);
1337 GetMagickToken(q,&q,token);
1338 GetMagickToken(q,&q,token);
1344 if (LocaleCompare((char *) keyword,"command") == 0)
1349 commands=AcquireString(token);
1350 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
1351 if (strchr(commands,'@') != (char *) NULL)
1354 path[MaxTextExtent];
1356 NTGhostscriptEXE(path,MaxTextExtent);
1357 (void) SubstituteString((char **) &commands,"@PSDelegate@",
1359 (void) SubstituteString((char **) &commands,"\\","/");
1362 (void) SubstituteString((char **) &commands,"&","&");
1363 (void) SubstituteString((char **) &commands,""","\"");
1364 (void) SubstituteString((char **) &commands,">",">");
1365 (void) SubstituteString((char **) &commands,"<","<");
1366 delegate_info->commands=commands;
1374 if (LocaleCompare((char *) keyword,"decode") == 0)
1376 delegate_info->decode=ConstantString(token);
1377 delegate_info->mode=1;
1385 if (LocaleCompare((char *) keyword,"encode") == 0)
1387 delegate_info->encode=ConstantString(token);
1388 delegate_info->mode=(-1);
1396 if (LocaleCompare((char *) keyword,"mode") == 0)
1398 delegate_info->mode=1;
1399 if (LocaleCompare(token,"bi") == 0)
1400 delegate_info->mode=0;
1402 if (LocaleCompare(token,"encode") == 0)
1403 delegate_info->mode=(-1);
1411 if (LocaleCompare((char *) keyword,"spawn") == 0)
1413 delegate_info->spawn=IsMagickTrue(token);
1416 if (LocaleCompare((char *) keyword,"stealth") == 0)
1418 delegate_info->stealth=IsMagickTrue(token);
1426 if (LocaleCompare((char *) keyword,"thread-support") == 0)
1428 delegate_info->thread_support=IsMagickTrue(token);
1437 token=(char *) RelinquishMagickMemory(token);
1442 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1446 % L o a d D e l e g a t e L i s t s %
1450 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1452 % LoadDelegateList() loads one or more delegate configuration file which
1453 % provides a mapping between delegate attributes and a delegate name.
1455 % The format of the LoadDelegateLists method is:
1457 % MagickBooleanType LoadDelegateLists(const char *filename,
1458 % ExceptionInfo *exception)
1460 % A description of each parameter follows:
1462 % o filename: the font file name.
1464 % o exception: return any errors or warnings in this structure.
1467 static MagickBooleanType LoadDelegateLists(const char *filename,
1468 ExceptionInfo *exception)
1470 #if defined(MAGICKCORE_EMBEDDABLE_SUPPORT)
1471 return(LoadDelegateList(DelegateMap,"built-in",0,exception));
1483 options=GetConfigureOptions(filename,exception);
1484 option=(const StringInfo *) GetNextValueInLinkedList(options);
1485 while (option != (const StringInfo *) NULL)
1487 status|=LoadDelegateList((const char *) GetStringInfoDatum(option),
1488 GetStringInfoPath(option),0,exception);
1489 option=(const StringInfo *) GetNextValueInLinkedList(options);
1491 options=DestroyConfigureOptions(options);
1492 if ((delegate_list == (LinkedListInfo *) NULL) ||
1493 (IsLinkedListEmpty(delegate_list) != MagickFalse))
1494 status|=LoadDelegateList(DelegateMap,"built-in",0,exception);
1495 return(status != 0 ? MagickTrue : MagickFalse);