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-2017 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 % https://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/artifact.h"
50 #include "MagickCore/attribute.h"
51 #include "MagickCore/blob.h"
52 #include "MagickCore/client.h"
53 #include "MagickCore/configure.h"
54 #include "MagickCore/constitute.h"
55 #include "MagickCore/delegate.h"
56 #include "MagickCore/delegate-private.h"
57 #include "MagickCore/exception.h"
58 #include "MagickCore/exception-private.h"
59 #include "MagickCore/fx-private.h"
60 #include "MagickCore/image-private.h"
61 #include "MagickCore/linked-list.h"
62 #include "MagickCore/list.h"
63 #include "MagickCore/memory_.h"
64 #include "MagickCore/nt-base-private.h"
65 #include "MagickCore/option.h"
66 #include "MagickCore/policy.h"
67 #include "MagickCore/property.h"
68 #include "MagickCore/resource_.h"
69 #include "MagickCore/semaphore.h"
70 #include "MagickCore/signature.h"
71 #include "MagickCore/string_.h"
72 #include "MagickCore/token.h"
73 #include "MagickCore/token-private.h"
74 #include "MagickCore/utility.h"
75 #include "MagickCore/utility-private.h"
76 #include "MagickCore/xml-tree.h"
77 #include "MagickCore/xml-tree-private.h"
82 #define DelegateFilename "delegates.xml"
88 *DelegateMap = (const char *)
89 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
91 " <delegate decode=\"autotrace\" stealth=\"True\" command=\""autotrace" -output-format svg -output-file "%o" "%i"\"/>"
92 " <delegate decode=\"avi:decode\" stealth=\"True\" command=\""mplayer" "%i" -really-quiet -ao null -vo png:z=3\"/>"
93 " <delegate decode=\"browse\" stealth=\"True\" spawn=\"True\" command=\""xdg-open" http://www.imagemagick.org/; rm "%i"\"/>"
94 " <delegate decode=\"cgm\" thread-support=\"False\" command=\""ralcgm" -d ps -oC < "%i" > "%o" 2> "%u"\"/>"
95 " <delegate decode=\"dng:decode\" command=\""ufraw-batch" --silent --create-id=also --out-type=png --out-depth=16 "--output=%u.png" "%i"\"/>"
96 " <delegate decode=\"edit\" stealth=\"True\" command=\""xterm" -title "Edit Image Comment" -e vi "%o"\"/>"
97 " <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"\"/>"
98 " <delegate decode=\"eps\" encode=\"ps\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=ps2write" "-sOutputFile=%o" "-f%i"\"/>"
99 " <delegate decode=\"fig\" command=\""fig2dev" -L ps "%i" "%o"\"/>"
100 " <delegate decode=\"hpg\" command=\""hp2xx" -q -m eps -f `basename "%o"` "%i" mv -f `basename "%o"` "%o"\"/>"
101 " <delegate decode=\"hpgl\" command=\""hp2xx" -q -m eps -f `basename "%o"` "%i" mv -f `basename "%o"` "%o"\"/>"
102 " <delegate decode=\"htm\" command=\""html2ps" -U -o "%o" "%i"\"/>"
103 " <delegate decode=\"html\" command=\""html2ps" -U -o "%o" "%i"\"/>"
104 " <delegate decode=\"https\" command=\""curl" -s -k -L -o "%o" "https:%M"\"/>"
105 " <delegate decode=\"ilbm\" command=\""ilbmtoppm" "%i" > "%o"\"/>"
106 " <delegate decode=\"man\" command=\""groff" -man -Tps "%i" > "%o"\"/>"
107 " <delegate decode=\"mpeg:decode\" stealth=\"True\" command=\""ffmpeg" -nostdin -v -1 -vframes %S -i "%i" -vcodec pam -an -f rawvideo -y "%u.pam" 2> "%Z"\"/>"
108 " <delegate decode=\"null\" encode=\"mpeg:encode\" stealth=\"True\" command=\""ffmpeg" -nostdin -v -1 -mbd rd -trellis 2 -cmp 2 -subcmp 2 -g 300 -i "%M%%d.jpg" "%u.%m" 2> "%Z"\"/>"
109 " <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"\"/>"
110 " <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"\"/>"
111 " <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"\"/>"
112 " <delegate decode=\"pdf\" encode=\"eps\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=eps2write" "-sOutputFile=%o" "-f%i"\"/>"
113 " <delegate decode=\"pdf\" encode=\"ps\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=ps2write" "-sOutputFile=%o" "-f%i"\"/>"
114 " <delegate decode=\"pnm\" encode=\"ilbm\" mode=\"encode\" command=\""ppmtoilbm" -24if "%i" > "%o"\"/>"
115 " <delegate decode=\"pnm\" encode=\"launch\" mode=\"encode\" command=\""gimp" "%i"\"/>"
116 " <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"\"/>"
117 " <delegate decode=\"ps\" encode=\"eps\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=eps2write" "-sOutputFile=%o" "-f%i"\"/>"
118 " <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"\"/>"
119 " <delegate decode=\"ps\" encode=\"print\" mode=\"encode\" command=\"lpr "%i"\"/>"
120 " <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"\"/>"
121 " <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"\"/>"
122 " <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"\"/>"
123 " <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"\"/>"
124 " <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"\"/>"
125 " <delegate decode=\"rgba\" encode=\"rle\" mode=\"encode\" command=\""rawtorle" -o "%o" -v "%i"\"/>"
126 " <delegate decode=\"scan\" command=\""scanimage" -d "%i" > "%o"\"/>"
127 " <delegate encode=\"show\" spawn=\"True\" command=\""display" -immutable -delay 0 -title "%M" "%i"\"/>"
128 " <delegate decode=\"shtml\" command=\""html2ps" -U -o "%o" "%i"\"/>"
129 " <delegate decode=\"svg\" command=\""rsvg" "%i" "%o"\"/>"
130 " <delegate decode=\"txt\" encode=\"ps\" mode=\"bi\" command=\""enscript" -o "%o" "%i"\"/>"
131 " <delegate encode=\"win\" stealth=\"True\" spawn=\"True\" command=\""display" -immutable -delay 0 -title "%M" "%i"\"/>"
132 " <delegate decode=\"wmf\" command=\""wmf2eps" -o "%o" "%i"\"/>"
136 Global declaractions.
138 static LinkedListInfo
139 *delegate_cache = (LinkedListInfo *) NULL;
142 *delegate_semaphore = (SemaphoreInfo *) NULL;
145 Forward declaractions.
147 static MagickBooleanType
148 IsDelegateCacheInstantiated(ExceptionInfo *),
149 LoadDelegateCache(LinkedListInfo *,const char *,const char *,const size_t,
153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157 % A c q u i r e D e l e g a t e C a c h e %
161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163 % AcquireDelegateCache() caches one or more delegate configurations which
164 % provides a mapping between delegate attributes and a delegate name.
166 % The format of the AcquireDelegateCache method is:
168 % LinkedListInfo *AcquireDelegateCache(const char *filename,
169 % ExceptionInfo *exception)
171 % A description of each parameter follows:
173 % o filename: the font file name.
175 % o exception: return any errors or warnings in this structure.
178 static LinkedListInfo *AcquireDelegateCache(const char *filename,
179 ExceptionInfo *exception)
187 cache=NewLinkedList(0);
188 if (cache == (LinkedListInfo *) NULL)
189 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
191 #if !defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT)
199 options=GetConfigureOptions(filename,exception);
200 option=(const StringInfo *) GetNextValueInLinkedList(options);
201 while (option != (const StringInfo *) NULL)
203 status&=LoadDelegateCache(cache,(const char *)
204 GetStringInfoDatum(option),GetStringInfoPath(option),0,exception);
205 option=(const StringInfo *) GetNextValueInLinkedList(options);
207 options=DestroyConfigureOptions(options);
210 if (IsLinkedListEmpty(cache) != MagickFalse)
211 status&=LoadDelegateCache(cache,DelegateMap,"built-in",0,exception);
216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
220 + D e l e g a t e C o m p o n e n t G e n e s i s %
224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226 % DelegateComponentGenesis() instantiates the delegate component.
228 % The format of the DelegateComponentGenesis method is:
230 % MagickBooleanType DelegateComponentGenesis(void)
233 MagickPrivate MagickBooleanType DelegateComponentGenesis(void)
235 if (delegate_semaphore == (SemaphoreInfo *) NULL)
236 delegate_semaphore=AcquireSemaphoreInfo();
241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
245 % 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 %
249 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
251 % DelegateComponentTerminus() destroys the delegate component.
253 % The format of the DelegateComponentTerminus method is:
255 % DelegateComponentTerminus(void)
259 static void *DestroyDelegate(void *delegate_info)
261 register DelegateInfo
264 p=(DelegateInfo *) delegate_info;
265 if (p->path != (char *) NULL)
266 p->path=DestroyString(p->path);
267 if (p->decode != (char *) NULL)
268 p->decode=DestroyString(p->decode);
269 if (p->encode != (char *) NULL)
270 p->encode=DestroyString(p->encode);
271 if (p->commands != (char *) NULL)
272 p->commands=DestroyString(p->commands);
273 if (p->semaphore != (SemaphoreInfo *) NULL)
274 RelinquishSemaphoreInfo(&p->semaphore);
275 p=(DelegateInfo *) RelinquishMagickMemory(p);
276 return((void *) NULL);
279 MagickPrivate void DelegateComponentTerminus(void)
281 if (delegate_semaphore == (SemaphoreInfo *) NULL)
282 ActivateSemaphoreInfo(&delegate_semaphore);
283 LockSemaphoreInfo(delegate_semaphore);
284 if (delegate_cache != (LinkedListInfo *) NULL)
285 delegate_cache=DestroyLinkedList(delegate_cache,DestroyDelegate);
286 UnlockSemaphoreInfo(delegate_semaphore);
287 RelinquishSemaphoreInfo(&delegate_semaphore);
291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
295 + E x t e r n a l D e l e g a t e C o m m a n d %
299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
301 % ExternalDelegateCommand() executes the specified command and waits until it
302 % terminates. The returned value is the exit status of the command.
304 % The format of the ExternalDelegateCommand method is:
306 % int ExternalDelegateCommand(const MagickBooleanType asynchronous,
307 % const MagickBooleanType verbose,const char *command,
308 % char *message,ExceptionInfo *exception)
310 % A description of each parameter follows:
312 % o asynchronous: a value other than 0 executes the parent program
313 % concurrently with the new child process.
315 % o verbose: a value other than 0 prints the executed command before it is
318 % o command: this string is the command to execute.
320 % o message: an option buffer to receive any message posted to stdout or
323 % o exception: return any errors here.
326 MagickExport int ExternalDelegateCommand(const MagickBooleanType asynchronous,
327 const MagickBooleanType verbose,const char *command,char *message,
328 ExceptionInfo *exception)
348 arguments=StringToArgv(command,&number_arguments);
349 if (arguments == (char **) NULL)
351 if (*arguments[1] == '\0')
353 for (i=0; i < (ssize_t) number_arguments; i++)
354 arguments[i]=DestroyString(arguments[i]);
355 arguments=(char **) RelinquishMagickMemory(arguments);
358 rights=ExecutePolicyRights;
359 domain=DelegatePolicyDomain;
360 if (IsRightsAuthorized(domain,rights,arguments[1]) == MagickFalse)
363 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
364 "NotAuthorized","`%s'",arguments[1]);
365 for (i=0; i < (ssize_t) number_arguments; i++)
366 arguments[i]=DestroyString(arguments[i]);
367 arguments=(char **) RelinquishMagickMemory(arguments);
370 if (verbose != MagickFalse)
372 (void) FormatLocaleFile(stderr,"%s\n",command);
373 (void) fflush(stderr);
375 sanitize_command=SanitizeString(command);
376 if (asynchronous != MagickFalse)
377 (void) ConcatenateMagickString(sanitize_command,"&",MagickPathExtent);
378 if (message != (char *) NULL)
380 #if defined(MAGICKCORE_POSIX_SUPPORT)
381 #if !defined(MAGICKCORE_HAVE_EXECVP)
382 status=system(sanitize_command);
384 if ((asynchronous != MagickFalse) ||
385 (strpbrk(sanitize_command,"&;<>|") != (char *) NULL))
386 status=system(sanitize_command);
393 Call application directly rather than from a shell.
395 child_pid=(pid_t) fork();
396 if (child_pid == (pid_t) -1)
397 status=system(sanitize_command);
401 status=execvp(arguments[1],arguments+1);
413 pid=(pid_t) waitpid(child_pid,&child_status,0);
418 if (WIFEXITED(child_status) != 0)
419 status=WEXITSTATUS(child_status);
421 if (WIFSIGNALED(child_status))
427 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
433 If a command shell is executed we need to change the forward slashes in
434 files to a backslash. We need to do this to keep Windows happy when we
435 want to 'move' a file.
437 TODO: This won't work if one of the delegate parameters has a forward
440 p=strstr(sanitize_command, "cmd.exe /c");
441 if (p != (char*) NULL)
444 for (; *p != '\0'; p++)
446 *p=*DirectorySeparator;
449 status=NTSystemCommand(sanitize_command,message);
450 #elif defined(macintosh)
451 status=MACSystemCommand(sanitize_command);
453 status=system(sanitize_command);
455 # error No suitable system() method.
459 if ((message != (char *) NULL) && (*message != '\0'))
460 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
461 "FailedToExecuteCommand","`%s' (%s)",sanitize_command,message);
463 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
464 "FailedToExecuteCommand","`%s' (%d)",sanitize_command,status);
466 sanitize_command=DestroyString(sanitize_command);
467 for (i=0; i < (ssize_t) number_arguments; i++)
468 arguments[i]=DestroyString(arguments[i]);
469 arguments=(char **) RelinquishMagickMemory(arguments);
474 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
478 % G e t D e l e g a t e C o m m a n d %
482 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
484 % GetDelegateCommand() replaces any embedded formatting characters with the
485 % appropriate image attribute and returns the resulting command.
487 % The format of the GetDelegateCommand method is:
489 % char *GetDelegateCommand(const ImageInfo *image_info,Image *image,
490 % const char *decode,const char *encode,ExceptionInfo *exception)
492 % A description of each parameter follows:
494 % o command: Method GetDelegateCommand returns the command associated
495 % with specified delegate tag.
497 % o image_info: the image info.
499 % o image: the image.
501 % o decode: Specifies the decode delegate we are searching for as a
504 % o encode: Specifies the encode delegate we are searching for as a
507 % o exception: return any errors or warnings in this structure.
511 static char *GetMagickPropertyLetter(ImageInfo *image_info,Image *image,
512 const char letter,ExceptionInfo *exception)
514 #define WarnNoImageReturn(format,letter) \
515 if (image == (Image *) NULL) \
517 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
518 "NoImageForProperty",format,letter); \
521 #define WarnNoImageInfoReturn(format,letter) \
522 if (image_info == (ImageInfo *) NULL) \
524 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
525 "NoImageInfoForProperty",format,letter); \
530 value[MagickPathExtent];
535 if ((image != (Image *) NULL) && (image->debug != MagickFalse))
536 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
538 if ((image_info != (ImageInfo *) NULL) &&
539 (image_info->debug != MagickFalse))
540 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-images");
542 Get properties that are directly defined by images.
544 *value='\0'; /* formatted string */
545 string=(const char *) value;
548 case 'a': /* authentication passphase */
550 WarnNoImageInfoReturn("\"%%%c\"",letter);
551 string=GetImageOption(image_info,"authenticate");
554 case 'b': /* image size read in - in bytes */
556 WarnNoImageReturn("\"%%%c\"",letter);
557 (void) FormatMagickSize(image->extent,MagickFalse,"B",MagickPathExtent,
559 if (image->extent == 0)
560 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,"B",
561 MagickPathExtent,value);
564 case 'd': /* Directory component of filename */
566 WarnNoImageReturn("\"%%%c\"",letter);
567 GetPathComponent(image->magick_filename,HeadPath,value);
570 case 'e': /* Filename extension (suffix) of image file */
572 WarnNoImageReturn("\"%%%c\"",letter);
573 GetPathComponent(image->magick_filename,ExtensionPath,value);
576 case 'f': /* Filename without directory component */
578 WarnNoImageReturn("\"%%%c\"",letter);
579 GetPathComponent(image->magick_filename,TailPath,value);
582 case 'g': /* Image geometry, canvas and offset %Wx%H+%X+%Y */
584 WarnNoImageReturn("\"%%%c\"",letter);
585 (void) FormatLocaleString(value,MagickPathExtent,
586 "%.20gx%.20g%+.20g%+.20g",(double) image->page.width,(double)
587 image->page.height,(double) image->page.x,(double) image->page.y);
590 case 'h': /* Image height (current) */
592 WarnNoImageReturn("\"%%%c\"",letter);
593 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
594 (image->rows != 0 ? image->rows : image->magick_rows));
597 case 'i': /* Filename last used for an image (read or write) */
599 WarnNoImageReturn("\"%%%c\"",letter);
600 string=image->filename;
603 case 'm': /* Image format (file magick) */
605 WarnNoImageReturn("\"%%%c\"",letter);
606 string=image->magick;
609 case 'n': /* Number of images in the list. */
611 if (image != (Image *) NULL)
612 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
613 GetImageListLength(image));
616 case 'o': /* Output Filename */
618 WarnNoImageInfoReturn("\"%%%c\"",letter);
619 string=image_info->filename;
622 case 'p': /* Image index in current image list */
624 WarnNoImageReturn("\"%%%c\"",letter);
625 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
626 GetImageIndexInList(image));
629 case 'q': /* Quantum depth of image in memory */
631 WarnNoImageReturn("\"%%%c\"",letter);
632 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
633 MAGICKCORE_QUANTUM_DEPTH);
636 case 'r': /* Image storage class, colorspace, and alpha enabled. */
641 WarnNoImageReturn("\"%%%c\"",letter);
642 colorspace=image->colorspace;
643 if (SetImageGray(image,exception) != MagickFalse)
644 colorspace=GRAYColorspace; /* FUTURE: this is IMv6 not IMv7 */
645 (void) FormatLocaleString(value,MagickPathExtent,"%s %s %s",
646 CommandOptionToMnemonic(MagickClassOptions,(ssize_t)
647 image->storage_class),CommandOptionToMnemonic(MagickColorspaceOptions,
648 (ssize_t) colorspace),image->alpha_trait != UndefinedPixelTrait ?
652 case 's': /* Image scene number */
654 WarnNoImageReturn("\"%%%c\"",letter);
655 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
659 case 't': /* Base filename without directory or extention */
661 WarnNoImageReturn("\"%%%c\"",letter);
662 GetPathComponent(image->magick_filename,BasePath,value);
665 case 'u': /* Unique filename */
667 WarnNoImageInfoReturn("\"%%%c\"",letter);
668 string=image_info->unique;
671 case 'w': /* Image width (current) */
673 WarnNoImageReturn("\"%%%c\"",letter);
674 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
675 (image->columns != 0 ? image->columns : image->magick_columns));
678 case 'x': /* Image horizontal resolution (with units) */
680 WarnNoImageReturn("\"%%%c\"",letter);
681 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
682 fabs(image->resolution.x) > MagickEpsilon ? image->resolution.x : 72.0);
685 case 'y': /* Image vertical resolution (with units) */
687 WarnNoImageReturn("\"%%%c\"",letter);
688 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
689 fabs(image->resolution.y) > MagickEpsilon ? image->resolution.y : 72.0);
692 case 'z': /* Image depth as read in */
694 WarnNoImageReturn("\"%%%c\"",letter);
695 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
696 (double) image->depth);
699 case 'A': /* Image alpha channel */
701 WarnNoImageReturn("\"%%%c\"",letter);
702 string=CommandOptionToMnemonic(MagickPixelTraitOptions,(ssize_t)
706 case 'C': /* Image compression method. */
708 WarnNoImageReturn("\"%%%c\"",letter);
709 string=CommandOptionToMnemonic(MagickCompressOptions,
710 (ssize_t) image->compression);
713 case 'D': /* Image dispose method. */
715 WarnNoImageReturn("\"%%%c\"",letter);
716 string=CommandOptionToMnemonic(MagickDisposeOptions,
717 (ssize_t) image->dispose);
723 Magick filename - filename given incl. coder & read mods.
725 WarnNoImageReturn("\"%%%c\"",letter);
726 (void) CopyMagickString(value,image->magick_filename,MagickPathExtent);
729 case 'G': /* Image size as geometry = "%wx%h" */
731 WarnNoImageReturn("\"%%%c\"",letter);
732 (void) FormatLocaleString(value,MagickPathExtent,"%.20gx%.20g",
733 (double) image->magick_columns,(double) image->magick_rows);
736 case 'H': /* layer canvas height */
738 WarnNoImageReturn("\"%%%c\"",letter);
739 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
740 (double) image->page.height);
743 case 'M': /* Magick filename - filename given incl. coder & read mods */
745 WarnNoImageReturn("\"%%%c\"",letter);
746 string=image->magick_filename;
749 case 'O': /* layer canvas offset with sign = "+%X+%Y" */
751 WarnNoImageReturn("\"%%%c\"",letter);
752 (void) FormatLocaleString(value,MagickPathExtent,"%+ld%+ld",(long)
753 image->page.x,(long) image->page.y);
756 case 'P': /* layer canvas page size = "%Wx%H" */
758 WarnNoImageReturn("\"%%%c\"",letter);
759 (void) FormatLocaleString(value,MagickPathExtent,"%.20gx%.20g",
760 (double) image->page.width,(double) image->page.height);
763 case 'Q': /* image compression quality */
765 WarnNoImageReturn("\"%%%c\"",letter);
766 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
767 (image->quality == 0 ? 92 : image->quality));
770 case 'S': /* Number of scenes in image list. */
772 WarnNoImageInfoReturn("\"%%%c\"",letter);
773 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
774 (image_info->number_scenes == 0 ? 2147483647 :
775 image_info->number_scenes));
778 case 'T': /* image time delay for animations */
780 WarnNoImageReturn("\"%%%c\"",letter);
781 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
785 case 'U': /* Image resolution units. */
787 WarnNoImageReturn("\"%%%c\"",letter);
788 string=CommandOptionToMnemonic(MagickResolutionOptions,
789 (ssize_t) image->units);
792 case 'W': /* layer canvas width */
794 WarnNoImageReturn("\"%%%c\"",letter);
795 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
799 case 'X': /* layer canvas X offset */
801 WarnNoImageReturn("\"%%%c\"",letter);
802 (void) FormatLocaleString(value,MagickPathExtent,"%+.20g",(double)
806 case 'Y': /* layer canvas Y offset */
808 WarnNoImageReturn("\"%%%c\"",letter);
809 (void) FormatLocaleString(value,MagickPathExtent,"%+.20g",(double)
813 case '%': /* percent escaped */
818 case '@': /* Trim bounding box, without actually trimming! */
823 WarnNoImageReturn("\"%%%c\"",letter);
824 page=GetImageBoundingBox(image,exception);
825 (void) FormatLocaleString(value,MagickPathExtent,
826 "%.20gx%.20g%+.20g%+.20g",(double) page.width,(double) page.height,
827 (double) page.x,(double) page.y);
835 WarnNoImageReturn("\"%%%c\"",letter);
836 (void) SignatureImage(image,exception);
837 string=GetImageProperty(image,"signature",exception);
841 return(SanitizeString(string));
844 static char *InterpretDelegateProperties(ImageInfo *image_info,
845 Image *image,const char *embed_text,ExceptionInfo *exception)
847 #define ExtendInterpretText(string_length) \
848 DisableMSCWarning(4127) \
850 size_t length=(string_length); \
851 if ((size_t) (q-interpret_text+length+1) >= extent) \
854 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
855 MaxTextExtent,sizeof(*interpret_text)); \
856 if (interpret_text == (char *) NULL) \
857 return((char *) NULL); \
858 q=interpret_text+strlen(interpret_text); \
863 #define AppendKeyValue2Text(key,value)\
864 DisableMSCWarning(4127) \
866 size_t length=strlen(key)+strlen(value)+2; \
867 if ((size_t) (q-interpret_text+length+1) >= extent) \
870 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
871 MaxTextExtent,sizeof(*interpret_text)); \
872 if (interpret_text == (char *) NULL) \
873 return((char *) NULL); \
874 q=interpret_text+strlen(interpret_text); \
876 q+=FormatLocaleString(q,extent,"%s=%s\n",(key),(value)); \
880 #define AppendString2Text(string) \
881 DisableMSCWarning(4127) \
883 size_t length=strlen((string)); \
884 if ((size_t) (q-interpret_text+length+1) >= extent) \
887 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
888 MaxTextExtent,sizeof(*interpret_text)); \
889 if (interpret_text == (char *) NULL) \
890 return((char *) NULL); \
891 q=interpret_text+strlen(interpret_text); \
893 (void) CopyMagickString(q,(string),extent); \
903 *q; /* current position in interpret_text */
906 *p; /* position in embed_text string being expanded */
909 extent; /* allocated length of interpret_text */
914 assert(image == NULL || image->signature == MagickCoreSignature);
915 assert(image_info == NULL || image_info->signature == MagickCoreSignature);
916 if ((image != (Image *) NULL) && (image->debug != MagickFalse))
917 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
919 if ((image_info != (ImageInfo *) NULL) && (image_info->debug != MagickFalse))
920 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-image");
921 if (embed_text == (const char *) NULL)
922 return(ConstantString(""));
924 while ((isspace((int) ((unsigned char) *p)) != 0) && (*p != '\0'))
927 return(ConstantString(""));
929 Translate any embedded format characters.
931 interpret_text=AcquireString(embed_text); /* new string with extra space */
932 extent=MagickPathExtent; /* allocated space in string */
933 number=MagickFalse; /* is last char a number? */
934 for (q=interpret_text; *p!='\0';
935 number=isdigit(*p) ? MagickTrue : MagickFalse,p++)
938 Interpret escape characters (e.g. Filename: %M).
941 ExtendInterpretText(MagickPathExtent);
950 case 'r': /* convert to RETURN */
956 case 'n': /* convert to NEWLINE */
962 case '\n': /* EOL removal UNIX,MacOSX */
967 case '\r': /* EOL removal DOS,Windows */
970 if (*p == '\n') /* return-newline EOL */
984 if (LocaleNCompare("<",p,4) == 0)
990 if (LocaleNCompare(">",p,4) == 0)
996 if (LocaleNCompare("&",p,5) == 0)
1006 break; /* continue to next set of handlers */
1009 *q++=(*p); /* any thing else is 'as normal' */
1013 p++; /* advance beyond the percent */
1015 Doubled Percent - or percent at end of string.
1017 if ((*p == '\0') || (*p == '\'') || (*p == '"'))
1025 Single letter escapes %c.
1027 if (number != MagickFalse)
1030 But only if not preceeded by a number!
1032 *q++='%'; /* do NOT substitute the percent */
1033 p--; /* back up one */
1036 string=GetMagickPropertyLetter(image_info,image,*p, exception);
1037 if (string != (char *) NULL)
1039 AppendString2Text(string);
1040 string=DestroyString(string);
1043 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
1044 "UnknownImageProperty","\"%%%c\"",*p);
1047 return(interpret_text);
1050 MagickExport char *GetDelegateCommand(const ImageInfo *image_info,Image *image,
1051 const char *decode,const char *encode,ExceptionInfo *exception)
1063 assert(image_info != (ImageInfo *) NULL);
1064 assert(image_info->signature == MagickCoreSignature);
1065 assert(image != (Image *) NULL);
1066 assert(image->signature == MagickCoreSignature);
1067 if (image->debug != MagickFalse)
1068 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1070 delegate_info=GetDelegateInfo(decode,encode,exception);
1071 if (delegate_info == (const DelegateInfo *) NULL)
1073 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1074 "NoTagFound","`%s'",decode ? decode : encode);
1075 return((char *) NULL);
1077 commands=StringToList(delegate_info->commands);
1078 if (commands == (char **) NULL)
1080 (void) ThrowMagickException(exception,GetMagickModule(),
1081 ResourceLimitError,"MemoryAllocationFailed","`%s'",decode ? decode :
1083 return((char *) NULL);
1085 command=InterpretDelegateProperties((ImageInfo *) image_info,image,
1086 commands[0],exception);
1087 if (command == (char *) NULL)
1088 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
1089 "MemoryAllocationFailed","`%s'",commands[0]);
1091 Relinquish resources.
1093 for (i=0; commands[i] != (char *) NULL; i++)
1094 commands[i]=DestroyString(commands[i]);
1095 commands=(char **) RelinquishMagickMemory(commands);
1100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1104 % G e t D e l e g a t e C o m m a n d s %
1108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1110 % GetDelegateCommands() returns the commands associated with a delegate.
1112 % The format of the GetDelegateCommands method is:
1114 % const char *GetDelegateCommands(const DelegateInfo *delegate_info)
1116 % A description of each parameter follows:
1118 % o delegate_info: The delegate info.
1121 MagickExport const char *GetDelegateCommands(const DelegateInfo *delegate_info)
1123 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1125 assert(delegate_info != (DelegateInfo *) NULL);
1126 assert(delegate_info->signature == MagickCoreSignature);
1127 return(delegate_info->commands);
1131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1135 % G e t D e l e g a t e I n f o %
1139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1141 % GetDelegateInfo() returns any delegates associated with the specified tag.
1143 % The format of the GetDelegateInfo method is:
1145 % const DelegateInfo *GetDelegateInfo(const char *decode,
1146 % const char *encode,ExceptionInfo *exception)
1148 % A description of each parameter follows:
1150 % o decode: Specifies the decode delegate we are searching for as a
1153 % o encode: Specifies the encode delegate we are searching for as a
1156 % o exception: return any errors or warnings in this structure.
1159 MagickExport const DelegateInfo *GetDelegateInfo(const char *decode,
1160 const char *encode,ExceptionInfo *exception)
1162 register const DelegateInfo
1165 assert(exception != (ExceptionInfo *) NULL);
1166 if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1167 return((const DelegateInfo *) NULL);
1169 Search for named delegate.
1171 LockSemaphoreInfo(delegate_semaphore);
1172 ResetLinkedListIterator(delegate_cache);
1173 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1174 if ((LocaleCompare(decode,"*") == 0) && (LocaleCompare(encode,"*") == 0))
1176 UnlockSemaphoreInfo(delegate_semaphore);
1179 while (p != (const DelegateInfo *) NULL)
1183 if (LocaleCompare(p->decode,decode) == 0)
1185 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1190 if (LocaleCompare(p->encode,encode) == 0)
1192 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1195 if (LocaleCompare(decode,p->decode) == 0)
1196 if (LocaleCompare(encode,p->encode) == 0)
1198 if (LocaleCompare(decode,"*") == 0)
1199 if (LocaleCompare(encode,p->encode) == 0)
1201 if (LocaleCompare(decode,p->decode) == 0)
1202 if (LocaleCompare(encode,"*") == 0)
1204 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1206 if (p != (const DelegateInfo *) NULL)
1207 (void) InsertValueInLinkedList(delegate_cache,0,
1208 RemoveElementByValueFromLinkedList(delegate_cache,p));
1209 UnlockSemaphoreInfo(delegate_semaphore);
1214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1218 % G e t D e l e g a t e I n f o L i s t %
1222 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1224 % GetDelegateInfoList() returns any delegates that match the specified pattern.
1226 % The delegate of the GetDelegateInfoList function is:
1228 % const DelegateInfo **GetDelegateInfoList(const char *pattern,
1229 % size_t *number_delegates,ExceptionInfo *exception)
1231 % A description of each parameter follows:
1233 % o pattern: Specifies a pointer to a text string containing a pattern.
1235 % o number_delegates: This integer returns the number of delegates in the
1238 % o exception: return any errors or warnings in this structure.
1242 #if defined(__cplusplus) || defined(c_plusplus)
1246 static int DelegateInfoCompare(const void *x,const void *y)
1255 p=(const DelegateInfo **) x,
1256 q=(const DelegateInfo **) y;
1257 cmp=LocaleCompare((*p)->path,(*q)->path);
1260 if ((*p)->decode == (char *) NULL)
1261 if (((*p)->encode != (char *) NULL) &&
1262 ((*q)->encode != (char *) NULL))
1263 return(strcmp((*p)->encode,(*q)->encode));
1264 if (((*p)->decode != (char *) NULL) &&
1265 ((*q)->decode != (char *) NULL))
1266 return(strcmp((*p)->decode,(*q)->decode));
1271 #if defined(__cplusplus) || defined(c_plusplus)
1275 MagickExport const DelegateInfo **GetDelegateInfoList(const char *pattern,
1276 size_t *number_delegates,ExceptionInfo *exception)
1281 register const DelegateInfo
1288 Allocate delegate list.
1290 assert(number_delegates != (size_t *) NULL);
1291 assert(pattern != (char *) NULL);
1292 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
1294 *number_delegates=0;
1295 p=GetDelegateInfo("*","*",exception);
1296 if (p == (const DelegateInfo *) NULL)
1297 return((const DelegateInfo **) NULL);
1298 delegates=(const DelegateInfo **) AcquireQuantumMemory((size_t)
1299 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,sizeof(*delegates));
1300 if (delegates == (const DelegateInfo **) NULL)
1301 return((const DelegateInfo **) NULL);
1303 Generate delegate list.
1305 LockSemaphoreInfo(delegate_semaphore);
1306 ResetLinkedListIterator(delegate_cache);
1307 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1308 for (i=0; p != (const DelegateInfo *) NULL; )
1310 if( (p->stealth == MagickFalse) &&
1311 ( GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse ||
1312 GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse) )
1314 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1316 UnlockSemaphoreInfo(delegate_semaphore);
1317 qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateInfoCompare);
1318 delegates[i]=(DelegateInfo *) NULL;
1319 *number_delegates=(size_t) i;
1324 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1328 % G e t D e l e g a t e L i s t %
1332 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1334 % GetDelegateList() returns any image format delegates that match the
1335 % specified pattern.
1337 % The format of the GetDelegateList function is:
1339 % char **GetDelegateList(const char *pattern,
1340 % size_t *number_delegates,ExceptionInfo *exception)
1342 % A description of each parameter follows:
1344 % o pattern: Specifies a pointer to a text string containing a pattern.
1346 % o number_delegates: This integer returns the number of delegates
1349 % o exception: return any errors or warnings in this structure.
1353 #if defined(__cplusplus) || defined(c_plusplus)
1357 static int DelegateCompare(const void *x,const void *y)
1363 p=(const char **) x;
1364 q=(const char **) y;
1365 return(LocaleCompare(*p,*q));
1368 #if defined(__cplusplus) || defined(c_plusplus)
1372 MagickExport char **GetDelegateList(const char *pattern,
1373 size_t *number_delegates,ExceptionInfo *exception)
1378 register const DelegateInfo
1385 Allocate delegate list.
1387 assert(pattern != (char *) NULL);
1388 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
1390 assert(number_delegates != (size_t *) NULL);
1391 *number_delegates=0;
1392 p=GetDelegateInfo("*","*",exception);
1393 if (p == (const DelegateInfo *) NULL)
1394 return((char **) NULL);
1395 delegates=(char **) AcquireQuantumMemory((size_t)
1396 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,sizeof(*delegates));
1397 if (delegates == (char **) NULL)
1398 return((char **) NULL);
1399 LockSemaphoreInfo(delegate_semaphore);
1400 ResetLinkedListIterator(delegate_cache);
1401 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1402 for (i=0; p != (const DelegateInfo *) NULL; )
1404 if( (p->stealth == MagickFalse) &&
1405 GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse )
1406 delegates[i++]=ConstantString(p->decode);
1407 if( (p->stealth == MagickFalse) &&
1408 GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse )
1409 delegates[i++]=ConstantString(p->encode);
1410 p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1412 UnlockSemaphoreInfo(delegate_semaphore);
1413 qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateCompare);
1414 delegates[i]=(char *) NULL;
1415 *number_delegates=(size_t) i;
1420 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1424 % G e t D e l e g a t e M o d e %
1428 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1430 % GetDelegateMode() returns the mode of the delegate.
1432 % The format of the GetDelegateMode method is:
1434 % ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
1436 % A description of each parameter follows:
1438 % o delegate_info: The delegate info.
1441 MagickExport ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
1443 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1445 assert(delegate_info != (DelegateInfo *) NULL);
1446 assert(delegate_info->signature == MagickCoreSignature);
1447 return(delegate_info->mode);
1451 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1455 + G e t D e l e g a t e T h r e a d S u p p o r t %
1459 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1461 % GetDelegateThreadSupport() returns MagickTrue if the delegate supports
1464 % The format of the GetDelegateThreadSupport method is:
1466 % MagickBooleanType GetDelegateThreadSupport(
1467 % const DelegateInfo *delegate_info)
1469 % A description of each parameter follows:
1471 % o delegate_info: The delegate info.
1474 MagickExport MagickBooleanType GetDelegateThreadSupport(
1475 const DelegateInfo *delegate_info)
1477 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1479 assert(delegate_info != (DelegateInfo *) NULL);
1480 assert(delegate_info->signature == MagickCoreSignature);
1481 return(delegate_info->thread_support);
1485 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1489 + I s D e l e g a t e C a c h e I n s t a n t i a t e d %
1493 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1495 % IsDelegateCacheInstantiated() determines if the delegate cache is
1496 % instantiated. If not, it instantiates the cache and returns it.
1498 % The format of the IsDelegateInstantiated method is:
1500 % MagickBooleanType IsDelegateCacheInstantiated(ExceptionInfo *exception)
1502 % A description of each parameter follows.
1504 % o exception: return any errors or warnings in this structure.
1507 static MagickBooleanType IsDelegateCacheInstantiated(ExceptionInfo *exception)
1509 if (delegate_cache == (LinkedListInfo *) NULL)
1511 if (delegate_semaphore == (SemaphoreInfo *) NULL)
1512 ActivateSemaphoreInfo(&delegate_semaphore);
1513 LockSemaphoreInfo(delegate_semaphore);
1514 if (delegate_cache == (LinkedListInfo *) NULL)
1515 delegate_cache=AcquireDelegateCache(DelegateFilename,exception);
1516 UnlockSemaphoreInfo(delegate_semaphore);
1518 return(delegate_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
1522 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1526 % I n v o k e D e l e g a t e %
1530 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1532 % InvokeDelegate replaces any embedded formatting characters with the
1533 % appropriate image attribute and executes the resulting command. MagickFalse
1534 % is returned if the commands execute with success otherwise MagickTrue.
1536 % The format of the InvokeDelegate method is:
1538 % MagickBooleanType InvokeDelegate(ImageInfo *image_info,Image *image,
1539 % const char *decode,const char *encode,ExceptionInfo *exception)
1541 % A description of each parameter follows:
1543 % o image_info: the imageInfo.
1545 % o image: the image.
1547 % o exception: return any errors or warnings in this structure.
1551 static MagickBooleanType CopyDelegateFile(const char *source,
1552 const char *destination,const MagickBooleanType overwrite)
1578 Copy source file to destination.
1580 assert(source != (const char *) NULL);
1581 assert(destination != (char *) NULL);
1582 if (overwrite == MagickFalse)
1584 status=GetPathAttributes(destination,&attributes);
1585 if (status != MagickFalse)
1588 destination_file=open_utf8(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
1589 if (destination_file == -1)
1590 return(MagickFalse);
1591 source_file=open_utf8(source,O_RDONLY | O_BINARY,0);
1592 if (source_file == -1)
1594 (void) close(destination_file);
1595 return(MagickFalse);
1597 quantum=(size_t) MagickMaxBufferExtent;
1598 if ((fstat(source_file,&attributes) == 0) && (attributes.st_size > 0))
1599 quantum=MagickMin((size_t) attributes.st_size,MagickMaxBufferExtent);
1600 buffer=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*buffer));
1601 if (buffer == (unsigned char *) NULL)
1603 (void) close(source_file);
1604 (void) close(destination_file);
1605 return(MagickFalse);
1608 for (i=0; ; i+=count)
1610 count=(ssize_t) read(source_file,buffer,quantum);
1613 length=(size_t) count;
1614 count=(ssize_t) write(destination_file,buffer,length);
1615 if ((size_t) count != length)
1618 (void) close(destination_file);
1619 (void) close(source_file);
1620 buffer=(unsigned char *) RelinquishMagickMemory(buffer);
1621 return(i != 0 ? MagickTrue : MagickFalse);
1624 MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
1625 Image *image,const char *decode,const char *encode,ExceptionInfo *exception)
1630 input_filename[MagickPathExtent],
1631 output_filename[MagickPathExtent];
1649 assert(image_info != (ImageInfo *) NULL);
1650 assert(image_info->signature == MagickCoreSignature);
1651 assert(image != (Image *) NULL);
1652 assert(image->signature == MagickCoreSignature);
1653 if (image->debug != MagickFalse)
1654 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1655 rights=ExecutePolicyRights;
1656 if (IsRightsAuthorized(DelegatePolicyDomain,rights,decode) == MagickFalse)
1659 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1660 "NotAuthorized","`%s'",decode);
1661 return(MagickFalse);
1663 if (IsRightsAuthorized(DelegatePolicyDomain,rights,encode) == MagickFalse)
1666 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1667 "NotAuthorized","`%s'",encode);
1668 return(MagickFalse);
1670 temporary=*image->filename == '\0' ? MagickTrue : MagickFalse;
1671 if ((temporary != MagickFalse) && (AcquireUniqueFilename(image->filename) ==
1674 ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile",
1676 return(MagickFalse);
1678 delegate_info=GetDelegateInfo(decode,encode,exception);
1679 if (delegate_info == (DelegateInfo *) NULL)
1681 if (temporary != MagickFalse)
1682 (void) RelinquishUniqueFileResource(image->filename);
1683 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1684 "NoTagFound","`%s'",decode ? decode : encode);
1685 return(MagickFalse);
1687 if (*image_info->filename == '\0')
1689 if (AcquireUniqueFilename(image_info->filename) == MagickFalse)
1691 if (temporary != MagickFalse)
1692 (void) RelinquishUniqueFileResource(image->filename);
1693 ThrowFileException(exception,FileOpenError,
1694 "UnableToCreateTemporaryFile",image_info->filename);
1695 return(MagickFalse);
1697 image_info->temporary=MagickTrue;
1699 if ((delegate_info->mode != 0) && (((decode != (const char *) NULL) &&
1700 (delegate_info->encode != (char *) NULL)) ||
1701 ((encode != (const char *) NULL) &&
1702 (delegate_info->decode != (char *) NULL))))
1714 Delegate requires a particular image format.
1716 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1718 ThrowFileException(exception,FileOpenError,
1719 "UnableToCreateTemporaryFile",image_info->unique);
1720 return(MagickFalse);
1722 magick=InterpretImageProperties(image_info,image,decode != (char *) NULL ?
1723 delegate_info->encode : delegate_info->decode,exception);
1724 if (magick == (char *) NULL)
1726 (void) RelinquishUniqueFileResource(image_info->unique);
1727 if (temporary != MagickFalse)
1728 (void) RelinquishUniqueFileResource(image->filename);
1729 (void) ThrowMagickException(exception,GetMagickModule(),
1730 DelegateError,"DelegateFailed","`%s'",decode ? decode : encode);
1731 return(MagickFalse);
1733 LocaleUpper(magick);
1734 clone_info=CloneImageInfo(image_info);
1735 (void) CopyMagickString((char *) clone_info->magick,magick,
1737 if (LocaleCompare(magick,"NULL") != 0)
1738 (void) CopyMagickString(image->magick,magick,MagickPathExtent);
1739 magick=DestroyString(magick);
1740 (void) FormatLocaleString(clone_info->filename,MagickPathExtent,"%s:",
1741 delegate_info->decode);
1742 (void) SetImageInfo(clone_info,(unsigned int) GetImageListLength(image),
1744 (void) CopyMagickString(clone_info->filename,image_info->filename,
1746 (void) CopyMagickString(image_info->filename,image->filename,
1748 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1750 (void) FormatLocaleString(p->filename,MagickPathExtent,"%s:%s",
1751 delegate_info->decode,clone_info->filename);
1752 status=WriteImage(clone_info,p,exception);
1753 if (status == MagickFalse)
1755 (void) RelinquishUniqueFileResource(image_info->unique);
1756 if (temporary != MagickFalse)
1757 (void) RelinquishUniqueFileResource(image->filename);
1758 clone_info=DestroyImageInfo(clone_info);
1759 (void) ThrowMagickException(exception,GetMagickModule(),
1760 DelegateError,"DelegateFailed","`%s'",decode ? decode : encode);
1761 return(MagickFalse);
1763 if (clone_info->adjoin != MagickFalse)
1766 (void) RelinquishUniqueFileResource(image_info->unique);
1767 clone_info=DestroyImageInfo(clone_info);
1772 commands=StringToList(delegate_info->commands);
1773 if (commands == (char **) NULL)
1775 if (temporary != MagickFalse)
1776 (void) RelinquishUniqueFileResource(image->filename);
1777 (void) ThrowMagickException(exception,GetMagickModule(),
1778 ResourceLimitError,"MemoryAllocationFailed","`%s'",
1779 decode ? decode : encode);
1780 return(MagickFalse);
1782 command=(char *) NULL;
1784 (void) CopyMagickString(output_filename,image_info->filename,
1786 (void) CopyMagickString(input_filename,image->filename,MagickPathExtent);
1787 for (i=0; commands[i] != (char *) NULL; i++)
1789 (void) AcquireUniqueSymbolicLink(output_filename,image_info->filename);
1790 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1792 ThrowFileException(exception,FileOpenError,
1793 "UnableToCreateTemporaryFile",image_info->unique);
1796 if (LocaleCompare(decode,"SCAN") != 0)
1798 status=AcquireUniqueSymbolicLink(input_filename,image->filename);
1799 if (status == MagickFalse)
1801 ThrowFileException(exception,FileOpenError,
1802 "UnableToCreateTemporaryFile",input_filename);
1807 command=InterpretDelegateProperties(image_info,image,commands[i],exception);
1808 if (command != (char *) NULL)
1813 if (ExternalDelegateCommand(delegate_info->spawn,image_info->verbose,
1814 command,(char *) NULL,exception) != 0)
1816 if (delegate_info->spawn != MagickFalse)
1822 Wait for input file to 'disappear', or maximum 2 seconds.
1825 while ((count-- > 0) && (access_utf8(image->filename,F_OK) == 0))
1826 (void) MagickDelay(100); /* sleep 0.1 seconds */
1828 command=DestroyString(command);
1830 if (LocaleCompare(decode,"SCAN") != 0)
1832 if (CopyDelegateFile(image->filename,input_filename,MagickFalse) == MagickFalse)
1833 (void) RelinquishUniqueFileResource(input_filename);
1835 if ((strcmp(input_filename,output_filename) != 0) &&
1836 (CopyDelegateFile(image_info->filename,output_filename,MagickTrue) == MagickFalse))
1837 (void) RelinquishUniqueFileResource(output_filename);
1838 if (image_info->temporary != MagickFalse)
1839 (void) RelinquishUniqueFileResource(image_info->filename);
1840 (void) RelinquishUniqueFileResource(image_info->unique);
1841 (void) RelinquishUniqueFileResource(image_info->filename);
1842 (void) RelinquishUniqueFileResource(image->filename);
1843 if (status == MagickFalse)
1845 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1846 "DelegateFailed","`%s'",commands[i]);
1849 commands[i]=DestroyString(commands[i]);
1851 (void) CopyMagickString(image_info->filename,output_filename,
1853 (void) CopyMagickString(image->filename,input_filename,MagickPathExtent);
1855 Relinquish resources.
1857 for ( ; commands[i] != (char *) NULL; i++)
1858 commands[i]=DestroyString(commands[i]);
1859 commands=(char **) RelinquishMagickMemory(commands);
1860 if (temporary != MagickFalse)
1861 (void) RelinquishUniqueFileResource(image->filename);
1866 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1870 % L i s t D e l e g a t e I n f o %
1874 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1876 % ListDelegateInfo() lists the image formats to a file.
1878 % The format of the ListDelegateInfo method is:
1880 % MagickBooleanType ListDelegateInfo(FILE *file,ExceptionInfo *exception)
1882 % A description of each parameter follows.
1884 % o file: An pointer to a FILE.
1886 % o exception: return any errors or warnings in this structure.
1889 MagickExport MagickBooleanType ListDelegateInfo(FILE *file,
1890 ExceptionInfo *exception)
1897 delegate[MagickPathExtent];
1911 if (file == (const FILE *) NULL)
1913 delegate_info=GetDelegateInfoList("*",&number_delegates,exception);
1914 if (delegate_info == (const DelegateInfo **) NULL)
1915 return(MagickFalse);
1916 path=(const char *) NULL;
1917 for (i=0; i < (ssize_t) number_delegates; i++)
1919 if (delegate_info[i]->stealth != MagickFalse)
1921 if ((path == (const char *) NULL) ||
1922 (LocaleCompare(path,delegate_info[i]->path) != 0))
1924 if (delegate_info[i]->path != (char *) NULL)
1925 (void) FormatLocaleFile(file,"\nPath: %s\n\n",delegate_info[i]->path);
1926 (void) FormatLocaleFile(file,"Delegate Command\n");
1927 (void) FormatLocaleFile(file,
1928 "-------------------------------------------------"
1929 "------------------------------\n");
1931 path=delegate_info[i]->path;
1933 if (delegate_info[i]->encode != (char *) NULL)
1934 (void) CopyMagickString(delegate,delegate_info[i]->encode,
1936 (void) ConcatenateMagickString(delegate," ",MagickPathExtent);
1938 commands=StringToList(delegate_info[i]->commands);
1939 if (commands == (char **) NULL)
1941 (void) FormatLocaleFile(file,"%11s%c=%c%s ",delegate_info[i]->decode ?
1942 delegate_info[i]->decode : "",delegate_info[i]->mode <= 0 ? '<' : ' ',
1943 delegate_info[i]->mode >= 0 ? '>' : ' ',delegate);
1944 StripString(commands[0]);
1945 (void) FormatLocaleFile(file,"\"%s\"\n",commands[0]);
1946 for (j=1; commands[j] != (char *) NULL; j++)
1948 StripString(commands[j]);
1949 (void) FormatLocaleFile(file," \"%s\"\n",commands[j]);
1951 for (j=0; commands[j] != (char *) NULL; j++)
1952 commands[j]=DestroyString(commands[j]);
1953 commands=(char **) RelinquishMagickMemory(commands);
1955 (void) fflush(file);
1956 delegate_info=(const DelegateInfo **)
1957 RelinquishMagickMemory((void *) delegate_info);
1962 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1966 + L o a d D e l e g a t e C a c h e %
1970 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1972 % LoadDelegateCache() loads the delegate configurations which provides a
1973 % mapping between delegate attributes and a delegate name.
1975 % The format of the LoadDelegateCache method is:
1977 % MagickBooleanType LoadDelegateCache(LinkedListInfo *cache,
1978 % const char *xml,const char *filename,const size_t depth,
1979 % ExceptionInfo *exception)
1981 % A description of each parameter follows:
1983 % o xml: The delegate list in XML format.
1985 % o filename: The delegate list filename.
1987 % o depth: depth of <include /> statements.
1989 % o exception: return any errors or warnings in this structure.
1992 static MagickBooleanType LoadDelegateCache(LinkedListInfo *cache,
1993 const char *xml,const char *filename,const size_t depth,
1994 ExceptionInfo *exception)
1997 keyword[MagickPathExtent],
2013 Load the delegate map file.
2015 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
2016 "Loading delegate configuration file \"%s\" ...",filename);
2017 if (xml == (const char *) NULL)
2018 return(MagickFalse);
2020 delegate_info=(DelegateInfo *) NULL;
2021 token=AcquireString(xml);
2022 extent=strlen(token)+MagickPathExtent;
2023 for (q=(const char *) xml; *q != '\0'; )
2028 GetNextToken(q,&q,extent,token);
2031 (void) CopyMagickString(keyword,token,MagickPathExtent);
2032 if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
2037 while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
2038 GetNextToken(q,&q,extent,token);
2041 if (LocaleNCompare(keyword,"<!--",4) == 0)
2046 while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
2047 GetNextToken(q,&q,extent,token);
2050 if (LocaleCompare(keyword,"<include") == 0)
2055 while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
2057 (void) CopyMagickString(keyword,token,MagickPathExtent);
2058 GetNextToken(q,&q,extent,token);
2061 GetNextToken(q,&q,extent,token);
2062 if (LocaleCompare(keyword,"file") == 0)
2065 (void) ThrowMagickException(exception,GetMagickModule(),
2066 ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token);
2070 path[MagickPathExtent],
2073 GetPathComponent(filename,HeadPath,path);
2075 (void) ConcatenateMagickString(path,DirectorySeparator,
2077 if (*token == *DirectorySeparator)
2078 (void) CopyMagickString(path,token,MagickPathExtent);
2080 (void) ConcatenateMagickString(path,token,MagickPathExtent);
2081 file_xml=FileToXML(path,~0UL);
2082 if (file_xml != (char *) NULL)
2084 status&=LoadDelegateCache(cache,file_xml,path,
2086 file_xml=DestroyString(file_xml);
2093 if (LocaleCompare(keyword,"<delegate") == 0)
2098 delegate_info=(DelegateInfo *) AcquireMagickMemory(
2099 sizeof(*delegate_info));
2100 if (delegate_info == (DelegateInfo *) NULL)
2101 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
2102 (void) ResetMagickMemory(delegate_info,0,sizeof(*delegate_info));
2103 delegate_info->path=ConstantString(filename);
2104 delegate_info->thread_support=MagickTrue;
2105 delegate_info->signature=MagickCoreSignature;
2108 if (delegate_info == (DelegateInfo *) NULL)
2110 if ((LocaleCompare(keyword,"/>") == 0) ||
2111 (LocaleCompare(keyword,"</policy>") == 0))
2113 status=AppendValueToLinkedList(cache,delegate_info);
2114 if (status == MagickFalse)
2115 (void) ThrowMagickException(exception,GetMagickModule(),
2116 ResourceLimitError,"MemoryAllocationFailed","`%s'",
2117 delegate_info->commands);
2118 delegate_info=(DelegateInfo *) NULL;
2121 GetNextToken(q,(const char **) NULL,extent,token);
2124 GetNextToken(q,&q,extent,token);
2125 GetNextToken(q,&q,extent,token);
2131 if (LocaleCompare((char *) keyword,"command") == 0)
2136 commands=AcquireString(token);
2137 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
2138 if (strchr(commands,'@') != (char *) NULL)
2141 path[MagickPathExtent];
2143 NTGhostscriptEXE(path,MagickPathExtent);
2144 (void) SubstituteString((char **) &commands,"@PSDelegate@",
2146 (void) SubstituteString((char **) &commands,"\\","/");
2148 (void) SubstituteString((char **) &commands,""","\"");
2150 (void) SubstituteString((char **) &commands,""","'");
2152 (void) SubstituteString((char **) &commands,"&","&");
2153 (void) SubstituteString((char **) &commands,">",">");
2154 (void) SubstituteString((char **) &commands,"<","<");
2155 delegate_info->commands=commands;
2163 if (LocaleCompare((char *) keyword,"decode") == 0)
2165 delegate_info->decode=ConstantString(token);
2166 delegate_info->mode=1;
2174 if (LocaleCompare((char *) keyword,"encode") == 0)
2176 delegate_info->encode=ConstantString(token);
2177 delegate_info->mode=(-1);
2185 if (LocaleCompare((char *) keyword,"mode") == 0)
2187 delegate_info->mode=1;
2188 if (LocaleCompare(token,"bi") == 0)
2189 delegate_info->mode=0;
2191 if (LocaleCompare(token,"encode") == 0)
2192 delegate_info->mode=(-1);
2200 if (LocaleCompare((char *) keyword,"spawn") == 0)
2202 delegate_info->spawn=IsStringTrue(token);
2205 if (LocaleCompare((char *) keyword,"stealth") == 0)
2207 delegate_info->stealth=IsStringTrue(token);
2215 if (LocaleCompare((char *) keyword,"thread-support") == 0)
2217 delegate_info->thread_support=IsStringTrue(token);
2218 if (delegate_info->thread_support == MagickFalse)
2219 delegate_info->semaphore=AcquireSemaphoreInfo();
2228 token=(char *) RelinquishMagickMemory(token);
2229 return(status != 0 ? MagickTrue : MagickFalse);