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-2014 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'",decode ? decode :
289 return((char *) NULL);
291 command=InterpretImageProperties((ImageInfo *) 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(),"...");
331 assert(delegate_info != (DelegateInfo *) NULL);
332 assert(delegate_info->signature == MagickSignature);
333 return(delegate_info->commands);
337 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
341 % G e t D e l e g a t e I n f o %
345 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
347 % GetDelegateInfo() returns any delegates associated with the specified tag.
349 % The format of the GetDelegateInfo method is:
351 % const DelegateInfo *GetDelegateInfo(const char *decode,
352 % const char *encode,ExceptionInfo *exception)
354 % A description of each parameter follows:
356 % o decode: Specifies the decode delegate we are searching for as a
359 % o encode: Specifies the encode delegate we are searching for as a
362 % o exception: return any errors or warnings in this structure.
365 MagickExport const DelegateInfo *GetDelegateInfo(const char *decode,
366 const char *encode,ExceptionInfo *exception)
368 register const DelegateInfo
371 assert(exception != (ExceptionInfo *) NULL);
372 if ((delegate_list == (LinkedListInfo *) NULL) ||
373 (IfMagickFalse(instantiate_delegate)))
374 if( IfMagickFalse(InitializeDelegateList(exception)) )
375 return((const DelegateInfo *) NULL);
376 if ((delegate_list == (LinkedListInfo *) NULL) ||
377 (IfMagickTrue(IsLinkedListEmpty(delegate_list))))
378 return((const DelegateInfo *) NULL);
379 if ((LocaleCompare(decode,"*") == 0) && (LocaleCompare(encode,"*") == 0))
380 return((const DelegateInfo *) GetValueFromLinkedList(delegate_list,0));
382 Search for named delegate.
384 LockSemaphoreInfo(delegate_semaphore);
385 ResetLinkedListIterator(delegate_list);
386 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
387 while (p != (const DelegateInfo *) NULL)
391 if (LocaleCompare(p->decode,decode) == 0)
393 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
398 if (LocaleCompare(p->encode,encode) == 0)
400 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
403 if (LocaleCompare(decode,p->decode) == 0)
404 if (LocaleCompare(encode,p->encode) == 0)
406 if (LocaleCompare(decode,"*") == 0)
407 if (LocaleCompare(encode,p->encode) == 0)
409 if (LocaleCompare(decode,p->decode) == 0)
410 if (LocaleCompare(encode,"*") == 0)
412 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
414 if (p != (const DelegateInfo *) NULL)
415 (void) InsertValueInLinkedList(delegate_list,0,
416 RemoveElementByValueFromLinkedList(delegate_list,p));
417 UnlockSemaphoreInfo(delegate_semaphore);
422 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
426 % G e t D e l e g a t e I n f o L i s t %
430 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
432 % GetDelegateInfoList() returns any delegates that match the specified pattern.
434 % The delegate of the GetDelegateInfoList function is:
436 % const DelegateInfo **GetDelegateInfoList(const char *pattern,
437 % size_t *number_delegates,ExceptionInfo *exception)
439 % A description of each parameter follows:
441 % o pattern: Specifies a pointer to a text string containing a pattern.
443 % o number_delegates: This integer returns the number of delegates in the
446 % o exception: return any errors or warnings in this structure.
450 #if defined(__cplusplus) || defined(c_plusplus)
454 static int DelegateInfoCompare(const void *x,const void *y)
460 p=(const DelegateInfo **) x,
461 q=(const DelegateInfo **) y;
462 if (LocaleCompare((*p)->path,(*q)->path) == 0)
464 if ((*p)->decode == (char *) NULL)
465 if (((*p)->encode != (char *) NULL) &&
466 ((*q)->encode != (char *) NULL))
467 return(strcmp((*p)->encode,(*q)->encode));
468 if (((*p)->decode != (char *) NULL) &&
469 ((*q)->decode != (char *) NULL))
470 return(strcmp((*p)->decode,(*q)->decode));
472 return(LocaleCompare((*p)->path,(*q)->path));
475 #if defined(__cplusplus) || defined(c_plusplus)
479 MagickExport const DelegateInfo **GetDelegateInfoList(const char *pattern,
480 size_t *number_delegates,ExceptionInfo *exception)
485 register const DelegateInfo
492 Allocate delegate list.
494 assert(number_delegates != (size_t *) NULL);
495 assert(pattern != (char *) NULL);
496 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
499 p=GetDelegateInfo("*","*",exception);
500 if (p == (const DelegateInfo *) NULL)
501 return((const DelegateInfo **) NULL);
502 delegates=(const DelegateInfo **) AcquireQuantumMemory((size_t)
503 GetNumberOfElementsInLinkedList(delegate_list)+1UL,sizeof(*delegates));
504 if (delegates == (const DelegateInfo **) NULL)
505 return((const DelegateInfo **) NULL);
507 Generate delegate list.
509 LockSemaphoreInfo(delegate_semaphore);
510 ResetLinkedListIterator(delegate_list);
511 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
512 for (i=0; p != (const DelegateInfo *) NULL; )
514 if( IfMagickFalse(p->stealth) &&
515 ( IfMagickTrue(GlobExpression(p->decode,pattern,MagickFalse)) ||
516 IfMagickTrue(GlobExpression(p->encode,pattern,MagickFalse))) )
518 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
520 UnlockSemaphoreInfo(delegate_semaphore);
521 qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateInfoCompare);
522 delegates[i]=(DelegateInfo *) NULL;
523 *number_delegates=(size_t) i;
528 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
532 % G e t D e l e g a t e L i s t %
536 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
538 % GetDelegateList() returns any image format delegates that match the
541 % The format of the GetDelegateList function is:
543 % char **GetDelegateList(const char *pattern,
544 % size_t *number_delegates,ExceptionInfo *exception)
546 % A description of each parameter follows:
548 % o pattern: Specifies a pointer to a text string containing a pattern.
550 % o number_delegates: This integer returns the number of delegates
553 % o exception: return any errors or warnings in this structure.
557 #if defined(__cplusplus) || defined(c_plusplus)
561 static int DelegateCompare(const void *x,const void *y)
569 return(LocaleCompare(*p,*q));
572 #if defined(__cplusplus) || defined(c_plusplus)
576 MagickExport char **GetDelegateList(const char *pattern,
577 size_t *number_delegates,ExceptionInfo *exception)
582 register const DelegateInfo
589 Allocate delegate list.
591 assert(pattern != (char *) NULL);
592 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
594 assert(number_delegates != (size_t *) NULL);
596 p=GetDelegateInfo("*","*",exception);
597 if (p == (const DelegateInfo *) NULL)
598 return((char **) NULL);
599 delegates=(char **) AcquireQuantumMemory((size_t)
600 GetNumberOfElementsInLinkedList(delegate_list)+1UL,sizeof(*delegates));
601 if (delegates == (char **) NULL)
602 return((char **) NULL);
603 LockSemaphoreInfo(delegate_semaphore);
604 ResetLinkedListIterator(delegate_list);
605 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
606 for (i=0; p != (const DelegateInfo *) NULL; )
608 if( IfMagickFalse(p->stealth) &&
609 IfMagickTrue(GlobExpression(p->decode,pattern,MagickFalse)) )
610 delegates[i++]=ConstantString(p->decode);
611 if( IfMagickFalse(p->stealth) &&
612 IfMagickTrue(GlobExpression(p->encode,pattern,MagickFalse)) )
613 delegates[i++]=ConstantString(p->encode);
614 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
616 UnlockSemaphoreInfo(delegate_semaphore);
617 qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateCompare);
618 delegates[i]=(char *) NULL;
619 *number_delegates=(size_t) i;
624 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
628 % G e t D e l e g a t e M o d e %
632 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
634 % GetDelegateMode() returns the mode of the delegate.
636 % The format of the GetDelegateMode method is:
638 % ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
640 % A description of each parameter follows:
642 % o delegate_info: The delegate info.
645 MagickExport ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
647 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
649 assert(delegate_info != (DelegateInfo *) NULL);
650 assert(delegate_info->signature == MagickSignature);
651 return(delegate_info->mode);
655 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
659 + G e t D e l e g a t e T h r e a d S u p p o r t %
663 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
665 % GetDelegateThreadSupport() returns MagickTrue if the delegate supports
668 % The format of the GetDelegateThreadSupport method is:
670 % MagickBooleanType GetDelegateThreadSupport(
671 % const DelegateInfo *delegate_info)
673 % A description of each parameter follows:
675 % o delegate_info: The delegate info.
678 MagickExport MagickBooleanType GetDelegateThreadSupport(
679 const DelegateInfo *delegate_info)
681 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
683 assert(delegate_info != (DelegateInfo *) NULL);
684 assert(delegate_info->signature == MagickSignature);
685 return(delegate_info->thread_support);
689 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
693 + I n i t i a l i z e D e l e g a t e L i s t %
697 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
699 % InitializeDelegateList() initializes the delegate list.
701 % The format of the InitializeDelegateList method is:
703 % MagickBooleanType InitializeDelegateList(ExceptionInfo *exception)
705 % A description of each parameter follows.
707 % o exception: return any errors or warnings in this structure.
710 static MagickBooleanType InitializeDelegateList(ExceptionInfo *exception)
712 if ((delegate_list == (LinkedListInfo *) NULL) &&
713 IfMagickFalse(instantiate_delegate))
715 if (delegate_semaphore == (SemaphoreInfo *) NULL)
716 AcquireSemaphoreInfo(&delegate_semaphore);
717 LockSemaphoreInfo(delegate_semaphore);
718 if ((delegate_list == (LinkedListInfo *) NULL) &&
719 IfMagickFalse(instantiate_delegate))
721 (void) LoadDelegateLists(DelegateFilename,exception);
722 instantiate_delegate=MagickTrue;
724 UnlockSemaphoreInfo(delegate_semaphore);
726 return(IsMagickNotNULL(delegate_list));
730 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
734 % I n v o k e D e l e g a t e %
738 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
740 % InvokeDelegate replaces any embedded formatting characters with the
741 % appropriate image attribute and executes the resulting command. MagickFalse
742 % is returned if the commands execute with success otherwise MagickTrue.
744 % The format of the InvokeDelegate method is:
746 % MagickBooleanType InvokeDelegate(ImageInfo *image_info,Image *image,
747 % const char *decode,const char *encode,ExceptionInfo *exception)
749 % A description of each parameter follows:
751 % o image_info: the imageInfo.
753 % o image: the image.
755 % o exception: return any errors or warnings in this structure.
759 static inline size_t MagickMin(const size_t x,const size_t y)
766 static MagickBooleanType CopyDelegateFile(const char *source,
767 const char *destination)
793 Copy source file to destination.
795 assert(source != (const char *) NULL);
796 assert(destination != (char *) NULL);
797 status=GetPathAttributes(destination,&attributes);
798 if( IfMagickTrue(status) && (attributes.st_size != 0))
800 destination_file=open_utf8(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
801 if (destination_file == -1)
803 source_file=open_utf8(source,O_RDONLY | O_BINARY,0);
804 if (source_file == -1)
806 (void) close(destination_file);
809 quantum=(size_t) MagickMaxBufferExtent;
810 if ((fstat(source_file,&attributes) == 0) && (attributes.st_size != 0))
811 quantum=MagickMin((size_t) attributes.st_size,MagickMaxBufferExtent);
812 buffer=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*buffer));
813 if (buffer == (unsigned char *) NULL)
815 (void) close(source_file);
816 (void) close(destination_file);
820 for (i=0; ; i+=count)
822 count=(ssize_t) read(source_file,buffer,quantum);
825 length=(size_t) count;
826 count=(ssize_t) write(destination_file,buffer,length);
827 if ((size_t) count != length)
830 (void) close(destination_file);
831 (void) close(source_file);
832 buffer=(unsigned char *) RelinquishMagickMemory(buffer);
833 return(IsMagickTrue(i!=0));
836 MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
837 Image *image,const char *decode,const char *encode,ExceptionInfo *exception)
842 input_filename[MaxTextExtent],
843 output_filename[MaxTextExtent];
861 assert(image_info != (ImageInfo *) NULL);
862 assert(image_info->signature == MagickSignature);
863 assert(image != (Image *) NULL);
864 assert(image->signature == MagickSignature);
865 if( IfMagickTrue(image->debug) )
866 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
868 rights=ExecutePolicyRights;
869 if( IfMagickFalse(IsRightsAuthorized(DelegatePolicyDomain,rights,decode)) )
872 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
873 "NotAuthorized","`%s'",decode);
876 if( IfMagickFalse(IsRightsAuthorized(DelegatePolicyDomain,rights,encode)) )
879 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
880 "NotAuthorized","`%s'",encode);
883 temporary=IsMagickTrue(*image->filename == '\0');
884 if( IfMagickTrue(temporary) )
885 if( IfMagickFalse(AcquireUniqueFilename(image->filename)) )
887 ThrowFileException(exception,FileOpenError,
888 "UnableToCreateTemporaryFile",image->filename);
891 delegate_info=GetDelegateInfo(decode,encode,exception);
892 if (delegate_info == (DelegateInfo *) NULL)
894 if( IfMagickTrue(temporary) )
895 (void) RelinquishUniqueFileResource(image->filename);
896 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
897 "NoTagFound","`%s'",decode ? decode : encode);
900 if (*image_info->filename == '\0')
902 if( IfMagickFalse(AcquireUniqueFilename(image_info->filename)) )
904 if( IfMagickTrue(temporary) )
905 (void) RelinquishUniqueFileResource(image->filename);
906 ThrowFileException(exception,FileOpenError,
907 "UnableToCreateTemporaryFile",image_info->filename);
910 image_info->temporary=MagickTrue;
912 if ((delegate_info->mode != 0) && (((decode != (const char *) NULL) &&
913 (delegate_info->encode != (char *) NULL)) ||
914 ((encode != (const char *) NULL) &&
915 (delegate_info->decode != (char *) NULL))))
927 Delegate requires a particular image format.
929 if( IfMagickFalse(AcquireUniqueFilename(image_info->unique)) )
931 ThrowFileException(exception,FileOpenError,
932 "UnableToCreateTemporaryFile",image_info->unique);
935 if( IfMagickFalse(AcquireUniqueFilename(image_info->zero)) )
937 (void) RelinquishUniqueFileResource(image_info->unique);
938 ThrowFileException(exception,FileOpenError,
939 "UnableToCreateTemporaryFile",image_info->zero);
942 magick=InterpretImageProperties(image_info,image,decode != (char *) NULL ?
943 delegate_info->encode : delegate_info->decode,exception);
944 if (magick == (char *) NULL)
946 (void) RelinquishUniqueFileResource(image_info->unique);
947 (void) RelinquishUniqueFileResource(image_info->zero);
948 if( IfMagickTrue(temporary) )
949 (void) RelinquishUniqueFileResource(image->filename);
950 (void) ThrowMagickException(exception,GetMagickModule(),
951 DelegateError,"DelegateFailed","`%s'",decode ? decode : encode);
955 clone_info=CloneImageInfo(image_info);
956 (void) CopyMagickString((char *) clone_info->magick,magick,
958 if (LocaleCompare(magick,"NULL") != 0)
959 (void) CopyMagickString(image->magick,magick,MaxTextExtent);
960 magick=DestroyString(magick);
961 (void) FormatLocaleString(clone_info->filename,MaxTextExtent,"%s:",
962 delegate_info->decode);
963 (void) SetImageInfo(clone_info,(unsigned int) GetImageListLength(image),
965 (void) CopyMagickString(clone_info->filename,image_info->filename,
967 (void) CopyMagickString(image_info->filename,image->filename,
969 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
971 (void) FormatLocaleString(p->filename,MaxTextExtent,"%s:%s",
972 delegate_info->decode,clone_info->filename);
973 status=WriteImage(clone_info,p,exception);
974 if( IfMagickFalse(status) )
976 (void) RelinquishUniqueFileResource(image_info->unique);
977 (void) RelinquishUniqueFileResource(image_info->zero);
978 if( IfMagickTrue(temporary) )
979 (void) RelinquishUniqueFileResource(image->filename);
980 clone_info=DestroyImageInfo(clone_info);
981 (void) ThrowMagickException(exception,GetMagickModule(),
982 DelegateError,"DelegateFailed","`%s'",decode ? decode : encode);
985 if( IfMagickTrue(clone_info->adjoin) )
988 (void) RelinquishUniqueFileResource(image_info->unique);
989 (void) RelinquishUniqueFileResource(image_info->zero);
990 clone_info=DestroyImageInfo(clone_info);
995 commands=StringToList(delegate_info->commands);
996 if (commands == (char **) NULL)
998 if( IfMagickTrue(temporary) )
999 (void) RelinquishUniqueFileResource(image->filename);
1000 (void) ThrowMagickException(exception,GetMagickModule(),
1001 ResourceLimitError,"MemoryAllocationFailed","`%s'",
1002 decode ? decode : encode);
1003 return(MagickFalse);
1005 command=(char *) NULL;
1007 (void) CopyMagickString(output_filename,image_info->filename,MaxTextExtent);
1008 (void) CopyMagickString(input_filename,image->filename,MaxTextExtent);
1009 for (i=0; commands[i] != (char *) NULL; i++)
1011 status=AcquireUniqueSymbolicLink(output_filename,image_info->filename);
1012 if( IfMagickFalse(AcquireUniqueFilename(image_info->unique)) )
1014 ThrowFileException(exception,FileOpenError,
1015 "UnableToCreateTemporaryFile",image_info->unique);
1018 if( IfMagickFalse(AcquireUniqueFilename(image_info->zero)) )
1020 (void) RelinquishUniqueFileResource(image_info->unique);
1021 ThrowFileException(exception,FileOpenError,
1022 "UnableToCreateTemporaryFile",image_info->zero);
1025 if (LocaleCompare(decode,"SCAN") != 0)
1027 status=AcquireUniqueSymbolicLink(input_filename,image->filename);
1028 if( IfMagickFalse(status) )
1030 ThrowFileException(exception,FileOpenError,
1031 "UnableToCreateTemporaryFile",input_filename);
1036 command=InterpretImageProperties(image_info,image,commands[i],exception);
1037 if (command != (char *) NULL)
1042 status=IsMagickTrue(SystemCommand(delegate_info->spawn,
1043 image_info->verbose,command,exception) != 0);
1044 if (IfMagickTrue(delegate_info->spawn))
1050 Wait for input file to 'disappear', or maximum 10 seconds.
1053 while ((count-- > 0) && (access_utf8(image->filename,F_OK) == 0))
1054 (void) MagickDelay(100); /* sleep 0.1 seconds */
1056 command=DestroyString(command);
1058 if (LocaleCompare(decode,"SCAN") != 0)
1060 if( IfMagickFalse(CopyDelegateFile(image->filename,input_filename)) )
1061 (void) RelinquishUniqueFileResource(input_filename);
1063 if( IfMagickFalse(CopyDelegateFile(image_info->filename,output_filename)) )
1064 (void) RelinquishUniqueFileResource(output_filename);
1065 if( IfMagickTrue(image_info->temporary) )
1066 (void) RelinquishUniqueFileResource(image_info->filename);
1067 (void) RelinquishUniqueFileResource(image_info->unique);
1068 (void) RelinquishUniqueFileResource(image_info->zero);
1069 (void) RelinquishUniqueFileResource(image_info->filename);
1070 (void) RelinquishUniqueFileResource(image->filename);
1071 if( IfMagickTrue(status) )
1073 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1074 "DelegateFailed","`%s'",commands[i]);
1077 commands[i]=DestroyString(commands[i]);
1079 (void) CopyMagickString(image_info->filename,output_filename,MaxTextExtent);
1080 (void) CopyMagickString(image->filename,input_filename,MaxTextExtent);
1082 Relinquish resources.
1084 for ( ; commands[i] != (char *) NULL; i++)
1085 commands[i]=DestroyString(commands[i]);
1086 commands=(char **) RelinquishMagickMemory(commands);
1087 if( IfMagickTrue(temporary) )
1088 (void) RelinquishUniqueFileResource(image->filename);
1089 return(IsMagickFalse(status));
1093 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1097 % L i s t D e l e g a t e I n f o %
1101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1103 % ListDelegateInfo() lists the image formats to a file.
1105 % The format of the ListDelegateInfo method is:
1107 % MagickBooleanType ListDelegateInfo(FILE *file,ExceptionInfo *exception)
1109 % A description of each parameter follows.
1111 % o file: An pointer to a FILE.
1113 % o exception: return any errors or warnings in this structure.
1116 MagickExport MagickBooleanType ListDelegateInfo(FILE *file,
1117 ExceptionInfo *exception)
1124 delegate[MaxTextExtent];
1138 if (file == (const FILE *) NULL)
1140 delegate_info=GetDelegateInfoList("*",&number_delegates,exception);
1141 if (delegate_info == (const DelegateInfo **) NULL)
1142 return(MagickFalse);
1143 path=(const char *) NULL;
1144 for (i=0; i < (ssize_t) number_delegates; i++)
1146 if( IfMagickTrue(delegate_info[i]->stealth) )
1148 if ((path == (const char *) NULL) ||
1149 (LocaleCompare(path,delegate_info[i]->path) != 0))
1151 if (delegate_info[i]->path != (char *) NULL)
1152 (void) FormatLocaleFile(file,"\nPath: %s\n\n",delegate_info[i]->path);
1153 (void) FormatLocaleFile(file,"Delegate Command\n");
1154 (void) FormatLocaleFile(file,
1155 "-------------------------------------------------"
1156 "------------------------------\n");
1158 path=delegate_info[i]->path;
1160 if (delegate_info[i]->encode != (char *) NULL)
1161 (void) CopyMagickString(delegate,delegate_info[i]->encode,MaxTextExtent);
1162 (void) ConcatenateMagickString(delegate," ",MaxTextExtent);
1164 commands=StringToList(delegate_info[i]->commands);
1165 if (commands == (char **) NULL)
1167 (void) FormatLocaleFile(file,"%11s%c=%c%s ",delegate_info[i]->decode ?
1168 delegate_info[i]->decode : "",delegate_info[i]->mode <= 0 ? '<' : ' ',
1169 delegate_info[i]->mode >= 0 ? '>' : ' ',delegate);
1170 StripString(commands[0]);
1171 (void) FormatLocaleFile(file,"\"%s\"\n",commands[0]);
1172 for (j=1; commands[j] != (char *) NULL; j++)
1174 StripString(commands[j]);
1175 (void) FormatLocaleFile(file," \"%s\"\n",commands[j]);
1177 for (j=0; commands[j] != (char *) NULL; j++)
1178 commands[j]=DestroyString(commands[j]);
1179 commands=(char **) RelinquishMagickMemory(commands);
1181 (void) fflush(file);
1182 delegate_info=(const DelegateInfo **)
1183 RelinquishMagickMemory((void *) delegate_info);
1188 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1192 + L o a d D e l e g a t e L i s t %
1196 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1198 % LoadDelegateList() loads the delegate configuration file which provides a
1199 % mapping between delegate attributes and a delegate name.
1201 % The format of the LoadDelegateList method is:
1203 % MagickBooleanType LoadDelegateList(const char *xml,const char *filename,
1204 % const size_t depth,ExceptionInfo *exception)
1206 % A description of each parameter follows:
1208 % o xml: The delegate list in XML format.
1210 % o filename: The delegate list filename.
1212 % o depth: depth of <include /> statements.
1214 % o exception: return any errors or warnings in this structure.
1217 static MagickBooleanType LoadDelegateList(const char *xml,const char *filename,
1218 const size_t depth,ExceptionInfo *exception)
1221 keyword[MaxTextExtent],
1234 Load the delegate map file.
1236 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
1237 "Loading delegate configuration file \"%s\" ...",filename);
1238 if (xml == (const char *) NULL)
1239 return(MagickFalse);
1240 if (delegate_list == (LinkedListInfo *) NULL)
1242 delegate_list=NewLinkedList(0);
1243 if (delegate_list == (LinkedListInfo *) NULL)
1245 ThrowFileException(exception,ResourceLimitError,
1246 "MemoryAllocationFailed",filename);
1247 return(MagickFalse);
1251 delegate_info=(DelegateInfo *) NULL;
1252 token=AcquireString(xml);
1253 for (q=(const char *) xml; *q != '\0'; )
1258 GetMagickToken(q,&q,token);
1261 (void) CopyMagickString(keyword,token,MaxTextExtent);
1262 if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
1267 while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
1268 GetMagickToken(q,&q,token);
1271 if (LocaleNCompare(keyword,"<!--",4) == 0)
1276 while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
1277 GetMagickToken(q,&q,token);
1280 if (LocaleCompare(keyword,"<include") == 0)
1285 while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
1287 (void) CopyMagickString(keyword,token,MaxTextExtent);
1288 GetMagickToken(q,&q,token);
1291 GetMagickToken(q,&q,token);
1292 if (LocaleCompare(keyword,"file") == 0)
1295 (void) ThrowMagickException(exception,GetMagickModule(),
1296 ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token);
1300 path[MaxTextExtent],
1303 GetPathComponent(filename,HeadPath,path);
1305 (void) ConcatenateMagickString(path,DirectorySeparator,
1307 if (*token == *DirectorySeparator)
1308 (void) CopyMagickString(path,token,MaxTextExtent);
1310 (void) ConcatenateMagickString(path,token,MaxTextExtent);
1311 xml=FileToString(path,~0UL,exception);
1312 if (xml != (char *) NULL)
1314 status=LoadDelegateList(xml,path,depth+1,exception);
1315 xml=(char *) RelinquishMagickMemory(xml);
1322 if (LocaleCompare(keyword,"<delegate") == 0)
1327 delegate_info=(DelegateInfo *) AcquireMagickMemory(
1328 sizeof(*delegate_info));
1329 if (delegate_info == (DelegateInfo *) NULL)
1330 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
1331 (void) ResetMagickMemory(delegate_info,0,sizeof(*delegate_info));
1332 delegate_info->path=ConstantString(filename);
1333 delegate_info->signature=MagickSignature;
1336 if (delegate_info == (DelegateInfo *) NULL)
1338 if (LocaleCompare(keyword,"/>") == 0)
1340 status=AppendValueToLinkedList(delegate_list,delegate_info);
1341 if( IfMagickFalse(status) )
1342 (void) ThrowMagickException(exception,GetMagickModule(),
1343 ResourceLimitError,"MemoryAllocationFailed","`%s'",
1344 delegate_info->commands);
1345 delegate_info=(DelegateInfo *) NULL;
1348 GetMagickToken(q,(const char **) NULL,token);
1351 GetMagickToken(q,&q,token);
1352 GetMagickToken(q,&q,token);
1358 if (LocaleCompare((char *) keyword,"command") == 0)
1363 commands=AcquireString(token);
1364 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
1365 if (strchr(commands,'@') != (char *) NULL)
1368 path[MaxTextExtent];
1370 NTGhostscriptEXE(path,MaxTextExtent);
1371 (void) SubstituteString((char **) &commands,"@PSDelegate@",
1373 (void) SubstituteString((char **) &commands,"\\","/");
1376 (void) SubstituteString((char **) &commands,"&","&");
1377 (void) SubstituteString((char **) &commands,""","\"");
1378 (void) SubstituteString((char **) &commands,">",">");
1379 (void) SubstituteString((char **) &commands,"<","<");
1380 delegate_info->commands=commands;
1388 if (LocaleCompare((char *) keyword,"decode") == 0)
1390 delegate_info->decode=ConstantString(token);
1391 delegate_info->mode=1;
1399 if (LocaleCompare((char *) keyword,"encode") == 0)
1401 delegate_info->encode=ConstantString(token);
1402 delegate_info->mode=(-1);
1410 if (LocaleCompare((char *) keyword,"mode") == 0)
1412 delegate_info->mode=1;
1413 if (LocaleCompare(token,"bi") == 0)
1414 delegate_info->mode=0;
1416 if (LocaleCompare(token,"encode") == 0)
1417 delegate_info->mode=(-1);
1425 if (LocaleCompare((char *) keyword,"spawn") == 0)
1427 delegate_info->spawn=IsStringTrue(token);
1430 if (LocaleCompare((char *) keyword,"stealth") == 0)
1432 delegate_info->stealth=IsStringTrue(token);
1440 if (LocaleCompare((char *) keyword,"thread-support") == 0)
1442 delegate_info->thread_support=IsStringTrue(token);
1451 token=(char *) RelinquishMagickMemory(token);
1456 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1460 % L o a d D e l e g a t e L i s t s %
1464 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1466 % LoadDelegateList() loads one or more delegate configuration file which
1467 % provides a mapping between delegate attributes and a delegate name.
1469 % The format of the LoadDelegateLists method is:
1471 % MagickBooleanType LoadDelegateLists(const char *filename,
1472 % ExceptionInfo *exception)
1474 % A description of each parameter follows:
1476 % o filename: the font file name.
1478 % o exception: return any errors or warnings in this structure.
1481 static MagickBooleanType LoadDelegateLists(const char *filename,
1482 ExceptionInfo *exception)
1484 #if defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT)
1485 return(LoadDelegateList(DelegateMap,"built-in",0,exception));
1497 options=GetConfigureOptions(filename,exception);
1498 option=(const StringInfo *) GetNextValueInLinkedList(options);
1499 while (option != (const StringInfo *) NULL)
1501 status&=LoadDelegateList((const char *) GetStringInfoDatum(option),
1502 GetStringInfoPath(option),0,exception);
1503 option=(const StringInfo *) GetNextValueInLinkedList(options);
1505 options=DestroyConfigureOptions(options);
1506 if ((delegate_list == (LinkedListInfo *) NULL) ||
1507 (IfMagickTrue(IsLinkedListEmpty(delegate_list))))
1508 status&=LoadDelegateList(DelegateMap,"built-in",0,exception);
1509 return(IsMagickTrue(status!=0));