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/; rm "%i"\"/>"
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=2 "-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=2 "-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=\""hp2xx" -q -m eps -f `basename "%o"` "%i" mv -f `basename "%o"` "%o"\"/>"
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" -v -1 -vframes %S -i "%i" -vcodec pam -an -f rawvideo -y "%u.pam" 2> "%Z"\"/>"
100 " <delegate decode=\"null\" encode=\"mpeg:encode\" stealth=\"True\" command=\""ffmpeg" -v -1 -mbd rd -trellis 2 -cmp 2 -subcmp 2 -g 300 -i "%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=2 "-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=2 "-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=2 "-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=2 "-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=2 "-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=2 "-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=2 "-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=2 "-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=2 "-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=2 "-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=2 "-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=2 "-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=\""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=\""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( IfMagickTrue(image->debug) )
274 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
276 delegate_info=GetDelegateInfo(decode,encode,exception);
277 if (delegate_info == (const DelegateInfo *) NULL)
279 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
280 "NoTagFound","'%s'",decode ? decode : encode);
281 return((char *) NULL);
283 commands=StringToList(delegate_info->commands);
284 if (commands == (char **) NULL)
286 (void) ThrowMagickException(exception,GetMagickModule(),
287 ResourceLimitError,"MemoryAllocationFailed","'%s'",
288 decode ? decode : encode);
289 return((char *) NULL);
291 command=InterpretImageProperties(image_info,image,commands[0],exception);
292 if (command == (char *) NULL)
293 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
294 "MemoryAllocationFailed","'%s'",commands[0]);
296 Relinquish resources.
298 for (i=0; commands[i] != (char *) NULL; i++)
299 commands[i]=DestroyString(commands[i]);
300 commands=(char **) RelinquishMagickMemory(commands);
305 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
309 % G e t D e l e g a t e C o m m a n d s %
313 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
315 % GetDelegateCommands() returns the commands associated with a delegate.
317 % The format of the GetDelegateCommands method is:
319 % const char *GetDelegateCommands(const DelegateInfo *delegate_info)
321 % A description of each parameter follows:
323 % o delegate_info: The delegate info.
326 MagickExport const char *GetDelegateCommands(const DelegateInfo *delegate_info)
328 (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 (IfMagickFalse(instantiate_delegate)))
373 if( IfMagickFalse(InitializeDelegateList(exception)) )
374 return((const DelegateInfo *) NULL);
375 if ((delegate_list == (LinkedListInfo *) NULL) ||
376 (IfMagickTrue(IsLinkedListEmpty(delegate_list))))
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(number_delegates != (size_t *) NULL);
494 assert(pattern != (char *) NULL);
495 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
498 p=GetDelegateInfo("*","*",exception);
499 if (p == (const DelegateInfo *) NULL)
500 return((const DelegateInfo **) NULL);
501 delegates=(const DelegateInfo **) AcquireQuantumMemory((size_t)
502 GetNumberOfElementsInLinkedList(delegate_list)+1UL,sizeof(*delegates));
503 if (delegates == (const DelegateInfo **) NULL)
504 return((const DelegateInfo **) NULL);
506 Generate delegate list.
508 LockSemaphoreInfo(delegate_semaphore);
509 ResetLinkedListIterator(delegate_list);
510 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
511 for (i=0; p != (const DelegateInfo *) NULL; )
513 if( IfMagickFalse(p->stealth) &&
514 ( IfMagickTrue(GlobExpression(p->decode,pattern,MagickFalse)) ||
515 IfMagickTrue(GlobExpression(p->encode,pattern,MagickFalse))) )
517 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
519 UnlockSemaphoreInfo(delegate_semaphore);
520 qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateInfoCompare);
521 delegates[i]=(DelegateInfo *) NULL;
522 *number_delegates=(size_t) i;
527 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
531 % G e t D e l e g a t e L i s t %
535 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
537 % GetDelegateList() returns any image format delegates that match the
540 % The format of the GetDelegateList function is:
542 % char **GetDelegateList(const char *pattern,
543 % size_t *number_delegates,ExceptionInfo *exception)
545 % A description of each parameter follows:
547 % o pattern: Specifies a pointer to a text string containing a pattern.
549 % o number_delegates: This integer returns the number of delegates
552 % o exception: return any errors or warnings in this structure.
556 #if defined(__cplusplus) || defined(c_plusplus)
560 static int DelegateCompare(const void *x,const void *y)
568 return(LocaleCompare(*p,*q));
571 #if defined(__cplusplus) || defined(c_plusplus)
575 MagickExport char **GetDelegateList(const char *pattern,
576 size_t *number_delegates,ExceptionInfo *exception)
581 register const DelegateInfo
588 Allocate delegate list.
590 assert(pattern != (char *) NULL);
591 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
593 assert(number_delegates != (size_t *) NULL);
595 p=GetDelegateInfo("*","*",exception);
596 if (p == (const DelegateInfo *) NULL)
597 return((char **) NULL);
598 delegates=(char **) AcquireQuantumMemory((size_t)
599 GetNumberOfElementsInLinkedList(delegate_list)+1UL,sizeof(*delegates));
600 if (delegates == (char **) NULL)
601 return((char **) NULL);
602 LockSemaphoreInfo(delegate_semaphore);
603 ResetLinkedListIterator(delegate_list);
604 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
605 for (i=0; p != (const DelegateInfo *) NULL; )
607 if( IfMagickFalse(p->stealth) &&
608 IfMagickTrue(GlobExpression(p->decode,pattern,MagickFalse)) )
609 delegates[i++]=ConstantString(p->decode);
610 if( IfMagickFalse(p->stealth) &&
611 IfMagickTrue(GlobExpression(p->encode,pattern,MagickFalse)) )
612 delegates[i++]=ConstantString(p->encode);
613 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
615 UnlockSemaphoreInfo(delegate_semaphore);
616 qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateCompare);
617 delegates[i]=(char *) NULL;
618 *number_delegates=(size_t) i;
623 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
627 % G e t D e l e g a t e M o d e %
631 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
633 % GetDelegateMode() returns the mode of the delegate.
635 % The format of the GetDelegateMode method is:
637 % ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
639 % A description of each parameter follows:
641 % o delegate_info: The delegate info.
644 MagickExport ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
646 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
648 assert(delegate_info != (DelegateInfo *) NULL);
649 assert(delegate_info->signature == MagickSignature);
650 return(delegate_info->mode);
654 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
658 + G e t D e l e g a t e T h r e a d S u p p o r t %
662 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
664 % GetDelegateThreadSupport() returns MagickTrue if the delegate supports
667 % The format of the GetDelegateThreadSupport method is:
669 % MagickBooleanType GetDelegateThreadSupport(
670 % const DelegateInfo *delegate_info)
672 % A description of each parameter follows:
674 % o delegate_info: The delegate info.
677 MagickExport MagickBooleanType GetDelegateThreadSupport(
678 const DelegateInfo *delegate_info)
680 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
682 assert(delegate_info != (DelegateInfo *) NULL);
683 assert(delegate_info->signature == MagickSignature);
684 return(delegate_info->thread_support);
688 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
692 + I n i t i a l i z e D e l e g a t e L i s t %
696 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
698 % InitializeDelegateList() initializes the delegate list.
700 % The format of the InitializeDelegateList method is:
702 % MagickBooleanType InitializeDelegateList(ExceptionInfo *exception)
704 % A description of each parameter follows.
706 % o exception: return any errors or warnings in this structure.
709 static MagickBooleanType InitializeDelegateList(ExceptionInfo *exception)
711 if ((delegate_list == (LinkedListInfo *) NULL) &&
712 IfMagickFalse(instantiate_delegate))
714 if (delegate_semaphore == (SemaphoreInfo *) NULL)
715 AcquireSemaphoreInfo(&delegate_semaphore);
716 LockSemaphoreInfo(delegate_semaphore);
717 if ((delegate_list == (LinkedListInfo *) NULL) &&
718 IfMagickFalse(instantiate_delegate))
720 (void) LoadDelegateLists(DelegateFilename,exception);
721 instantiate_delegate=MagickTrue;
723 UnlockSemaphoreInfo(delegate_semaphore);
725 return(IsMagickNotNULL(delegate_list));
729 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
733 % I n v o k e D e l e g a t e %
737 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
739 % InvokeDelegate replaces any embedded formatting characters with the
740 % appropriate image attribute and executes the resulting command. MagickFalse
741 % is returned if the commands execute with success otherwise MagickTrue.
743 % The format of the InvokeDelegate method is:
745 % MagickBooleanType InvokeDelegate(ImageInfo *image_info,Image *image,
746 % const char *decode,const char *encode,ExceptionInfo *exception)
748 % A description of each parameter follows:
750 % o image_info: the imageInfo.
752 % o image: the image.
754 % o exception: return any errors or warnings in this structure.
758 static inline size_t MagickMin(const size_t x,const size_t y)
765 static MagickBooleanType CopyDelegateFile(const char *source,
766 const char *destination)
792 Copy source file to destination.
794 assert(source != (const char *) NULL);
795 assert(destination != (char *) NULL);
796 status=GetPathAttributes(destination,&attributes);
797 if( IfMagickTrue(status) && (attributes.st_size != 0))
799 destination_file=open_utf8(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
800 if (destination_file == -1)
802 source_file=open_utf8(source,O_RDONLY | O_BINARY,0);
803 if (source_file == -1)
805 (void) close(destination_file);
808 quantum=(size_t) MagickMaxBufferExtent;
809 if ((fstat(source_file,&attributes) == 0) && (attributes.st_size != 0))
810 quantum=MagickMin((size_t) attributes.st_size,MagickMaxBufferExtent);
811 buffer=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*buffer));
812 if (buffer == (unsigned char *) NULL)
814 (void) close(source_file);
815 (void) close(destination_file);
819 for (i=0; ; i+=count)
821 count=(ssize_t) read(source_file,buffer,quantum);
824 length=(size_t) count;
825 count=(ssize_t) write(destination_file,buffer,length);
826 if ((size_t) count != length)
829 (void) close(destination_file);
830 (void) close(source_file);
831 buffer=(unsigned char *) RelinquishMagickMemory(buffer);
832 return(IsMagickTrue(i!=0));
835 MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
836 Image *image,const char *decode,const char *encode,ExceptionInfo *exception)
841 input_filename[MaxTextExtent],
842 output_filename[MaxTextExtent];
860 assert(image_info != (ImageInfo *) NULL);
861 assert(image_info->signature == MagickSignature);
862 assert(image != (Image *) NULL);
863 assert(image->signature == MagickSignature);
864 if( IfMagickTrue(image->debug) )
865 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
867 rights=ExecutePolicyRights;
868 if( IfMagickFalse(IsRightsAuthorized(DelegatePolicyDomain,rights,decode)) )
871 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
872 "NotAuthorized","'%s'",decode);
875 if( IfMagickFalse(IsRightsAuthorized(DelegatePolicyDomain,rights,encode)) )
878 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
879 "NotAuthorized","'%s'",encode);
882 temporary=IsMagickTrue(*image->filename == '\0');
883 if( IfMagickTrue(temporary) )
884 if( IfMagickFalse(AcquireUniqueFilename(image->filename)) )
886 ThrowFileException(exception,FileOpenError,
887 "UnableToCreateTemporaryFile",image->filename);
890 delegate_info=GetDelegateInfo(decode,encode,exception);
891 if (delegate_info == (DelegateInfo *) NULL)
893 if( IfMagickTrue(temporary) )
894 (void) RelinquishUniqueFileResource(image->filename);
895 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
896 "NoTagFound","'%s'",decode ? decode : encode);
899 if (*image_info->filename == '\0')
901 if( IfMagickFalse(AcquireUniqueFilename(image_info->filename)) )
903 if( IfMagickTrue(temporary) )
904 (void) RelinquishUniqueFileResource(image->filename);
905 ThrowFileException(exception,FileOpenError,
906 "UnableToCreateTemporaryFile",image_info->filename);
909 image_info->temporary=MagickTrue;
911 if ((delegate_info->mode != 0) && (((decode != (const char *) NULL) &&
912 (delegate_info->encode != (char *) NULL)) ||
913 ((encode != (const char *) NULL) &&
914 (delegate_info->decode != (char *) NULL))))
926 Delegate requires a particular image format.
928 if( IfMagickFalse(AcquireUniqueFilename(image_info->unique)) )
930 ThrowFileException(exception,FileOpenError,
931 "UnableToCreateTemporaryFile",image_info->unique);
934 if( IfMagickFalse(AcquireUniqueFilename(image_info->zero)) )
936 (void) RelinquishUniqueFileResource(image_info->unique);
937 ThrowFileException(exception,FileOpenError,
938 "UnableToCreateTemporaryFile",image_info->zero);
941 magick=InterpretImageProperties(image_info,image,decode != (char *) NULL ?
942 delegate_info->encode : delegate_info->decode,exception);
943 if (magick == (char *) NULL)
945 (void) RelinquishUniqueFileResource(image_info->unique);
946 (void) RelinquishUniqueFileResource(image_info->zero);
947 if( IfMagickTrue(temporary) )
948 (void) RelinquishUniqueFileResource(image->filename);
949 (void) ThrowMagickException(exception,GetMagickModule(),
950 DelegateError,"DelegateFailed","'%s'",decode ? decode : encode);
954 clone_info=CloneImageInfo(image_info);
955 (void) CopyMagickString((char *) clone_info->magick,magick,
957 if (LocaleCompare(magick,"NULL") != 0)
958 (void) CopyMagickString(image->magick,magick,MaxTextExtent);
959 magick=DestroyString(magick);
960 (void) FormatLocaleString(clone_info->filename,MaxTextExtent,"%s:",
961 delegate_info->decode);
962 (void) SetImageInfo(clone_info,(unsigned int) GetImageListLength(image),
964 (void) CopyMagickString(clone_info->filename,image_info->filename,
966 (void) CopyMagickString(image_info->filename,image->filename,
968 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
970 (void) FormatLocaleString(p->filename,MaxTextExtent,"%s:%s",
971 delegate_info->decode,clone_info->filename);
972 status=WriteImage(clone_info,p,exception);
973 if( IfMagickFalse(status) )
975 (void) RelinquishUniqueFileResource(image_info->unique);
976 (void) RelinquishUniqueFileResource(image_info->zero);
977 if( IfMagickTrue(temporary) )
978 (void) RelinquishUniqueFileResource(image->filename);
979 clone_info=DestroyImageInfo(clone_info);
980 (void) ThrowMagickException(exception,GetMagickModule(),
981 DelegateError,"DelegateFailed","'%s'",decode ? decode : encode);
984 if( IfMagickTrue(clone_info->adjoin) )
987 (void) RelinquishUniqueFileResource(image_info->unique);
988 (void) RelinquishUniqueFileResource(image_info->zero);
989 clone_info=DestroyImageInfo(clone_info);
994 commands=StringToList(delegate_info->commands);
995 if (commands == (char **) NULL)
997 if( IfMagickTrue(temporary) )
998 (void) RelinquishUniqueFileResource(image->filename);
999 (void) ThrowMagickException(exception,GetMagickModule(),
1000 ResourceLimitError,"MemoryAllocationFailed","'%s'",
1001 decode ? decode : encode);
1002 return(MagickFalse);
1004 command=(char *) NULL;
1006 (void) CopyMagickString(output_filename,image_info->filename,MaxTextExtent);
1007 (void) CopyMagickString(input_filename,image->filename,MaxTextExtent);
1008 for (i=0; commands[i] != (char *) NULL; i++)
1010 status=AcquireUniqueSymbolicLink(output_filename,image_info->filename);
1011 if( IfMagickFalse(AcquireUniqueFilename(image_info->unique)) )
1013 ThrowFileException(exception,FileOpenError,
1014 "UnableToCreateTemporaryFile",image_info->unique);
1017 if( IfMagickFalse(AcquireUniqueFilename(image_info->zero)) )
1019 (void) RelinquishUniqueFileResource(image_info->unique);
1020 ThrowFileException(exception,FileOpenError,
1021 "UnableToCreateTemporaryFile",image_info->zero);
1024 if (LocaleCompare(decode,"SCAN") != 0)
1026 status=AcquireUniqueSymbolicLink(input_filename,image->filename);
1027 if( IfMagickFalse(status) )
1029 ThrowFileException(exception,FileOpenError,
1030 "UnableToCreateTemporaryFile",input_filename);
1035 command=InterpretImageProperties(image_info,image,commands[i],exception);
1036 if (command != (char *) NULL)
1041 status=IsMagickTrue(SystemCommand(delegate_info->spawn,
1042 image_info->verbose,command,exception) != 0);
1043 if (IfMagickTrue(delegate_info->spawn))
1049 Wait for input file to 'disappear', or maximum 5 secs.
1052 while ((count-- > 0) && (access_utf8(image->filename,F_OK) == 0))
1053 (void) MagickDelay(100); /* sleep 0.1 seconds */
1055 command=DestroyString(command);
1057 if (LocaleCompare(decode,"SCAN") != 0)
1059 if( IfMagickFalse(CopyDelegateFile(image->filename,input_filename)) )
1060 (void) RelinquishUniqueFileResource(input_filename);
1062 if( IfMagickFalse(CopyDelegateFile(image_info->filename,output_filename)) )
1063 (void) RelinquishUniqueFileResource(output_filename);
1064 if( IfMagickTrue(image_info->temporary) )
1065 (void) RelinquishUniqueFileResource(image_info->filename);
1066 (void) RelinquishUniqueFileResource(image_info->unique);
1067 (void) RelinquishUniqueFileResource(image_info->zero);
1068 (void) RelinquishUniqueFileResource(image_info->filename);
1069 (void) RelinquishUniqueFileResource(image->filename);
1070 if( IfMagickTrue(status) )
1072 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1073 "DelegateFailed","'%s'",commands[i]);
1076 commands[i]=DestroyString(commands[i]);
1078 (void) CopyMagickString(image_info->filename,output_filename,MaxTextExtent);
1079 (void) CopyMagickString(image->filename,input_filename,MaxTextExtent);
1081 Relinquish resources.
1083 for ( ; commands[i] != (char *) NULL; i++)
1084 commands[i]=DestroyString(commands[i]);
1085 commands=(char **) RelinquishMagickMemory(commands);
1086 if( IfMagickTrue(temporary) )
1087 (void) RelinquishUniqueFileResource(image->filename);
1088 return(IsMagickFalse(status));
1092 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1096 % L i s t D e l e g a t e I n f o %
1100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1102 % ListDelegateInfo() lists the image formats to a file.
1104 % The format of the ListDelegateInfo method is:
1106 % MagickBooleanType ListDelegateInfo(FILE *file,ExceptionInfo *exception)
1108 % A description of each parameter follows.
1110 % o file: An pointer to a FILE.
1112 % o exception: return any errors or warnings in this structure.
1115 MagickExport MagickBooleanType ListDelegateInfo(FILE *file,
1116 ExceptionInfo *exception)
1123 delegate[MaxTextExtent];
1137 if (file == (const FILE *) NULL)
1139 delegate_info=GetDelegateInfoList("*",&number_delegates,exception);
1140 if (delegate_info == (const DelegateInfo **) NULL)
1141 return(MagickFalse);
1142 path=(const char *) NULL;
1143 for (i=0; i < (ssize_t) number_delegates; i++)
1145 if( IfMagickTrue(delegate_info[i]->stealth) )
1147 if ((path == (const char *) NULL) ||
1148 (LocaleCompare(path,delegate_info[i]->path) != 0))
1150 if (delegate_info[i]->path != (char *) NULL)
1151 (void) FormatLocaleFile(file,"\nPath: %s\n\n",delegate_info[i]->path);
1152 (void) FormatLocaleFile(file,"Delegate Command\n");
1153 (void) FormatLocaleFile(file,
1154 "-------------------------------------------------"
1155 "------------------------------\n");
1157 path=delegate_info[i]->path;
1159 if (delegate_info[i]->encode != (char *) NULL)
1160 (void) CopyMagickString(delegate,delegate_info[i]->encode,MaxTextExtent);
1161 (void) ConcatenateMagickString(delegate," ",MaxTextExtent);
1163 commands=StringToList(delegate_info[i]->commands);
1164 if (commands == (char **) NULL)
1166 (void) FormatLocaleFile(file,"%11s%c=%c%s ",delegate_info[i]->decode ?
1167 delegate_info[i]->decode : "",delegate_info[i]->mode <= 0 ? '<' : ' ',
1168 delegate_info[i]->mode >= 0 ? '>' : ' ',delegate);
1169 StripString(commands[0]);
1170 (void) FormatLocaleFile(file,"\"%s\"\n",commands[0]);
1171 for (j=1; commands[j] != (char *) NULL; j++)
1173 StripString(commands[j]);
1174 (void) FormatLocaleFile(file," \"%s\"\n",commands[j]);
1176 for (j=0; commands[j] != (char *) NULL; j++)
1177 commands[j]=DestroyString(commands[j]);
1178 commands=(char **) RelinquishMagickMemory(commands);
1180 (void) fflush(file);
1181 delegate_info=(const DelegateInfo **)
1182 RelinquishMagickMemory((void *) delegate_info);
1187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1191 + L o a d D e l e g a t e L i s t %
1195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1197 % LoadDelegateList() loads the delegate configuration file which provides a
1198 % mapping between delegate attributes and a delegate name.
1200 % The format of the LoadDelegateList method is:
1202 % MagickBooleanType LoadDelegateList(const char *xml,const char *filename,
1203 % const size_t depth,ExceptionInfo *exception)
1205 % A description of each parameter follows:
1207 % o xml: The delegate list in XML format.
1209 % o filename: The delegate list filename.
1211 % o depth: depth of <include /> statements.
1213 % o exception: return any errors or warnings in this structure.
1216 static MagickBooleanType LoadDelegateList(const char *xml,const char *filename,
1217 const size_t depth,ExceptionInfo *exception)
1220 keyword[MaxTextExtent],
1233 Load the delegate map file.
1235 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1236 "Loading delegate configuration file \"%s\" ...",filename);
1237 if (xml == (const char *) NULL)
1238 return(MagickFalse);
1239 if (delegate_list == (LinkedListInfo *) NULL)
1241 delegate_list=NewLinkedList(0);
1242 if (delegate_list == (LinkedListInfo *) NULL)
1244 ThrowFileException(exception,ResourceLimitError,
1245 "MemoryAllocationFailed",filename);
1246 return(MagickFalse);
1250 delegate_info=(DelegateInfo *) NULL;
1251 token=AcquireString(xml);
1252 for (q=(const char *) xml; *q != '\0'; )
1257 GetMagickToken(q,&q,token);
1260 (void) CopyMagickString(keyword,token,MaxTextExtent);
1261 if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
1266 while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
1267 GetMagickToken(q,&q,token);
1270 if (LocaleNCompare(keyword,"<!--",4) == 0)
1275 while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
1276 GetMagickToken(q,&q,token);
1279 if (LocaleCompare(keyword,"<include") == 0)
1284 while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
1286 (void) CopyMagickString(keyword,token,MaxTextExtent);
1287 GetMagickToken(q,&q,token);
1290 GetMagickToken(q,&q,token);
1291 if (LocaleCompare(keyword,"file") == 0)
1294 (void) ThrowMagickException(exception,GetMagickModule(),
1295 ConfigureError,"IncludeElementNestedTooDeeply","'%s'",token);
1299 path[MaxTextExtent],
1302 GetPathComponent(filename,HeadPath,path);
1304 (void) ConcatenateMagickString(path,DirectorySeparator,
1306 if (*token == *DirectorySeparator)
1307 (void) CopyMagickString(path,token,MaxTextExtent);
1309 (void) ConcatenateMagickString(path,token,MaxTextExtent);
1310 xml=FileToString(path,~0,exception);
1311 if (xml != (char *) NULL)
1313 status=LoadDelegateList(xml,path,depth+1,exception);
1314 xml=(char *) RelinquishMagickMemory(xml);
1321 if (LocaleCompare(keyword,"<delegate") == 0)
1326 delegate_info=(DelegateInfo *) AcquireMagickMemory(
1327 sizeof(*delegate_info));
1328 if (delegate_info == (DelegateInfo *) NULL)
1329 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
1330 (void) ResetMagickMemory(delegate_info,0,sizeof(*delegate_info));
1331 delegate_info->path=ConstantString(filename);
1332 delegate_info->signature=MagickSignature;
1335 if (delegate_info == (DelegateInfo *) NULL)
1337 if (LocaleCompare(keyword,"/>") == 0)
1339 status=AppendValueToLinkedList(delegate_list,delegate_info);
1340 if( IfMagickFalse(status) )
1341 (void) ThrowMagickException(exception,GetMagickModule(),
1342 ResourceLimitError,"MemoryAllocationFailed","'%s'",
1343 delegate_info->commands);
1344 delegate_info=(DelegateInfo *) NULL;
1346 GetMagickToken(q,(const char **) NULL,token);
1349 GetMagickToken(q,&q,token);
1350 GetMagickToken(q,&q,token);
1356 if (LocaleCompare((char *) keyword,"command") == 0)
1361 commands=AcquireString(token);
1362 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
1363 if (strchr(commands,'@') != (char *) NULL)
1366 path[MaxTextExtent];
1368 NTGhostscriptEXE(path,MaxTextExtent);
1369 (void) SubstituteString((char **) &commands,"@PSDelegate@",
1371 (void) SubstituteString((char **) &commands,"\\","/");
1374 (void) SubstituteString((char **) &commands,"&","&");
1375 (void) SubstituteString((char **) &commands,""","\"");
1376 (void) SubstituteString((char **) &commands,">",">");
1377 (void) SubstituteString((char **) &commands,"<","<");
1378 delegate_info->commands=commands;
1386 if (LocaleCompare((char *) keyword,"decode") == 0)
1388 delegate_info->decode=ConstantString(token);
1389 delegate_info->mode=1;
1397 if (LocaleCompare((char *) keyword,"encode") == 0)
1399 delegate_info->encode=ConstantString(token);
1400 delegate_info->mode=(-1);
1408 if (LocaleCompare((char *) keyword,"mode") == 0)
1410 delegate_info->mode=1;
1411 if (LocaleCompare(token,"bi") == 0)
1412 delegate_info->mode=0;
1414 if (LocaleCompare(token,"encode") == 0)
1415 delegate_info->mode=(-1);
1423 if (LocaleCompare((char *) keyword,"spawn") == 0)
1425 delegate_info->spawn=IsStringTrue(token);
1428 if (LocaleCompare((char *) keyword,"stealth") == 0)
1430 delegate_info->stealth=IsStringTrue(token);
1438 if (LocaleCompare((char *) keyword,"thread-support") == 0)
1440 delegate_info->thread_support=IsStringTrue(token);
1449 token=(char *) RelinquishMagickMemory(token);
1454 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1458 % L o a d D e l e g a t e L i s t s %
1462 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1464 % LoadDelegateList() loads one or more delegate configuration file which
1465 % provides a mapping between delegate attributes and a delegate name.
1467 % The format of the LoadDelegateLists method is:
1469 % MagickBooleanType LoadDelegateLists(const char *filename,
1470 % ExceptionInfo *exception)
1472 % A description of each parameter follows:
1474 % o filename: the font file name.
1476 % o exception: return any errors or warnings in this structure.
1479 static MagickBooleanType LoadDelegateLists(const char *filename,
1480 ExceptionInfo *exception)
1482 #if defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT)
1483 return(LoadDelegateList(DelegateMap,"built-in",0,exception));
1495 options=GetConfigureOptions(filename,exception);
1496 option=(const StringInfo *) GetNextValueInLinkedList(options);
1497 while (option != (const StringInfo *) NULL)
1499 status|=LoadDelegateList((const char *) GetStringInfoDatum(option),
1500 GetStringInfoPath(option),0,exception);
1501 option=(const StringInfo *) GetNextValueInLinkedList(options);
1503 options=DestroyConfigureOptions(options);
1504 if ((delegate_list == (LinkedListInfo *) NULL) ||
1505 (IfMagickTrue(IsLinkedListEmpty(delegate_list))))
1506 status|=LoadDelegateList(DelegateMap,"built-in",0,exception);
1507 return(IsMagickTrue(status!=0));