]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/delegate.c
Added checks for exceptions.
[imagemagick] / MagickCore / delegate.c
index bfb4b5d8c3dacb453fe8831430c9b7a2280e73d3..04defce0e42d24e8471f9867faf5e74076baf9c8 100644 (file)
 %             MagickCore Methods to Read/Write/Invoke Delegates               %
 %                                                                             %
 %                             Software Design                                 %
-%                               John Cristy                                   %
+%                                  Cristy                                     %
 %                               October 1998                                  %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
@@ -58,6 +58,7 @@
 #include "MagickCore/hashmap.h"
 #include "MagickCore/list.h"
 #include "MagickCore/memory_.h"
+#include "MagickCore/nt-base-private.h"
 #include "MagickCore/policy.h"
 #include "MagickCore/resource_.h"
 #include "MagickCore/semaphore.h"
@@ -66,6 +67,7 @@
 #include "MagickCore/utility.h"
 #include "MagickCore/utility-private.h"
 #include "MagickCore/xml-tree.h"
+#include "MagickCore/xml-tree-private.h"
 \f
 /*
   Define declarations.
@@ -81,46 +83,46 @@ static const char
     "<delegatemap>"
     "  <delegate decode=\"autotrace\" stealth=\"True\" command=\"&quot;autotrace&quot; -output-format svg -output-file &quot;%o&quot; &quot;%i&quot;\"/>"
     "  <delegate decode=\"avi:decode\" stealth=\"True\" command=\"&quot;mplayer&quot; &quot;%i&quot; -really-quiet -ao null -vo png:z=3\"/>"
-    "  <delegate decode=\"browse\" stealth=\"True\" spawn=\"True\" command=\"&quot;xdg-open&quot; http://www.imagemagick.org/\"/>"
+    "  <delegate decode=\"browse\" stealth=\"True\" spawn=\"True\" command=\"&quot;xdg-open&quot; http://www.imagemagick.org/; rm &quot;%i&quot;\"/>"
     "  <delegate decode=\"cgm\" thread-support=\"False\" command=\"&quot;ralcgm&quot; -d ps -oC &lt; &quot;%i&quot; &gt; &quot;%o&quot; 2&gt; &quot;%u&quot;\"/>"
     "  <delegate decode=\"dng:decode\" command=\"&quot;/usr/bin/ufraw-batch&quot; --silent --wb=camera --black-point=auto --exposure=auto --create-id=also --out-type=ppm16 &quot;--output=%u.pnm&quot; &quot;%i&quot;\"/>"
     "  <delegate decode=\"edit\" stealth=\"True\" command=\"&quot;xterm&quot; -title &quot;Edit Image Comment&quot; -e vi &quot;%o&quot;\"/>"
-    "  <delegate decode=\"eps\" encode=\"pdf\" mode=\"bi\" command=\"&quot;gs&quot; -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 &quot;-sDEVICE=pdfwrite&quot; &quot;-sOutputFile=%o&quot; &quot;-f%i&quot;\"/>"
-    "  <delegate decode=\"eps\" encode=\"ps\" mode=\"bi\" command=\"&quot;gs&quot; -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 &quot;-sDEVICE=pswrite&quot; &quot;-sOutputFile=%o&quot; &quot;-f%i&quot;\"/>"
+    "  <delegate decode=\"eps\" encode=\"pdf\" mode=\"bi\" command=\"&quot;gs&quot; -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=pdfwrite&quot; &quot;-sOutputFile=%o&quot; &quot;-f%i&quot;\"/>"
+    "  <delegate decode=\"eps\" encode=\"ps\" mode=\"bi\" command=\"&quot;gs&quot; -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=pswrite&quot; &quot;-sOutputFile=%o&quot; &quot;-f%i&quot;\"/>"
     "  <delegate decode=\"fig\" command=\"&quot;fig2dev&quot; -L ps &quot;%i&quot; &quot;%o&quot;\"/>"
     "  <delegate decode=\"gplt\" command=\"&quot;echo&quot; &quot;set size 1.25,0.62     set terminal postscript portrait color solid; set output &quot;%o&quot;; load &quot;%i&quot;&quot; &gt; &quot;%u&quot;;&quot;gnuplot&quot; &quot;%u&quot;\"/>"
     "  <delegate decode=\"hpg\" command=\"&quot;hp2xx&quot; -q -m eps -f `basename &quot;%o&quot;` &quot;%i&quot;     mv -f `basename &quot;%o&quot;` &quot;%o&quot;\"/>"
-    "  <delegate decode=\"hpgl\" command=\"if [ -e hp2xx -o -e /usr/bin/hp2xx ]; then     hp2xx -q -m eps -f `basename &quot;%o&quot;` &quot;%i&quot;     mv -f `basename &quot;%o&quot;` &quot;%o   else     echo &quot;You need to install hp2xx to use HPGL files with ImageMagick.&quot;     exit 1   fi\"/>"
+    "  <delegate decode=\"hpgl\" command=\"&quot;hp2xx&quot; -q -m eps -f `basename &quot;%o&quot;` &quot;%i&quot;     mv -f `basename &quot;%o&quot;` &quot;%o&quot;\"/>"
     "  <delegate decode=\"htm\" command=\"&quot;html2ps&quot; -U -o &quot;%o&quot; &quot;%i&quot;\"/>"
     "  <delegate decode=\"html\" command=\"&quot;html2ps&quot; -U -o &quot;%o&quot; &quot;%i&quot;\"/>"
     "  <delegate decode=\"https\" command=\"&quot;wget&quot; -q -O &quot;%o&quot; &quot;https:%M&quot;\"/>"
     "  <delegate decode=\"ilbm\" command=\"&quot;ilbmtoppm&quot; &quot;%i&quot; &gt; &quot;%o&quot;\"/>"
     "  <delegate decode=\"man\" command=\"&quot;groff&quot; -man -Tps &quot;%i&quot; &gt; &quot;%o&quot;\"/>"
-    "  <delegate decode=\"mpeg:decode\" stealth=\"True\" command=\"&quot;ffmpeg&quot; --i &quot;%i&quot; -vcodec pam -an -f rawvideo -y &quot;%u0.pam&quot; 2;&gt; &quot;%Z&quot;\"/>"
-    "  <delegate decode=\"null\" encode=\"mpeg:encode\" stealth=\"True\" command=\"&quot;ffmpeg&quot; &quot;%M%%d.jpg&quot; &quot;%u.%m&quot; 2;&gt; &quot;%Z&quot;\"/>"
-    "  <delegate decode=\"pcl:color\" stealth=\"True\" command=\"&quot;pcl6&quot; -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 &quot;-sDEVICE=ppmraw&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;%s&quot;\"/>"
-    "  <delegate decode=\"pcl:cmyk\" stealth=\"True\" command=\"&quot;pcl6&quot; -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 &quot;-sDEVICE=bmpsep8&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;%s&quot;\"/>"
-    "  <delegate decode=\"pcl:mono\" stealth=\"True\" command=\"&quot;pcl6&quot; -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 &quot;-sDEVICE=pbmraw&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;%s&quot;\"/>"
-    "  <delegate decode=\"pdf\" encode=\"eps\" mode=\"bi\" command=\"&quot;gs&quot; -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 &quot;-sDEVICE=epswrite&quot; &quot;-sOutputFile=%o&quot; &quot;-f%i&quot;\"/>"
-    "  <delegate decode=\"pdf\" encode=\"ps\" mode=\"bi\" command=\"&quot;gs&quot; -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 &quot;-sDEVICE=pswrite&quot; &quot;-sOutputFile=%o&quot; &quot;-f%i&quot;\"/>"
+    "  <delegate decode=\"mpeg:decode\" stealth=\"True\" command=\"&quot;ffmpeg&quot; -v -1 -vframes %S -i &quot;%i&quot; -vcodec pam -an -f rawvideo -y &quot;%u.pam&quot; 2&gt; &quot;%Z&quot;\"/>"
+    "  <delegate decode=\"null\" encode=\"mpeg:encode\" stealth=\"True\" command=\"&quot;ffmpeg&quot; -v -1 -mbd rd -trellis 2 -cmp 2 -subcmp 2 -g 300 -i &quot;%M%%d.jpg&quot; &quot;%u.%m&quot; 2&gt; &quot;%Z&quot;\"/>"
+    "  <delegate decode=\"pcl:color\" stealth=\"True\" command=\"&quot;pcl6&quot; -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=ppmraw&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;%s&quot;\"/>"
+    "  <delegate decode=\"pcl:cmyk\" stealth=\"True\" command=\"&quot;pcl6&quot; -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=bmpsep8&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;%s&quot;\"/>"
+    "  <delegate decode=\"pcl:mono\" stealth=\"True\" command=\"&quot;pcl6&quot; -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=pbmraw&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;%s&quot;\"/>"
+    "  <delegate decode=\"pdf\" encode=\"eps\" mode=\"bi\" command=\"&quot;gs&quot; -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=epswrite&quot; &quot;-sOutputFile=%o&quot; &quot;-f%i&quot;\"/>"
+    "  <delegate decode=\"pdf\" encode=\"ps\" mode=\"bi\" command=\"&quot;gs&quot; -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=pswrite&quot; &quot;-sOutputFile=%o&quot; &quot;-f%i&quot;\"/>"
     "  <delegate decode=\"pnm\" encode=\"ilbm\" mode=\"encode\" command=\"&quot;ppmtoilbm&quot; -24if &quot;%i&quot; &gt; &quot;%o&quot;\"/>"
     "  <delegate decode=\"pnm\" encode=\"launch\" mode=\"encode\" command=\"&quot;gimp&quot; &quot;%i&quot;\"/>"
     "  <delegate decode=\"pov\" command=\"&quot;povray&quot; &quot;+i&quot;%i&quot;&quot; -D0 +o&quot;%o&quot; +fn%q +w%w +h%h +a -q9 -kfi&quot;%s&quot; -kff&quot;%n&quot;     &quot;convert&quot; -concatenate &quot;%o*.png&quot; &quot;%o&quot;\"/>"
-    "  <delegate decode=\"ps\" encode=\"eps\" mode=\"bi\" command=\"&quot;gs&quot; -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 &quot;-sDEVICE=epswrite&quot; &quot;-sOutputFile=%o&quot; &quot;-f%i&quot;\"/>"
-    "  <delegate decode=\"ps\" encode=\"pdf\" mode=\"bi\" command=\"&quot;gs&quot; -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 &quot;-sDEVICE=pdfwrite&quot; &quot;-sOutputFile=%o&quot; &quot;-f%i&quot;\"/>"
+    "  <delegate decode=\"ps\" encode=\"eps\" mode=\"bi\" command=\"&quot;gs&quot; -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=epswrite&quot; &quot;-sOutputFile=%o&quot; &quot;-f%i&quot;\"/>"
+    "  <delegate decode=\"ps\" encode=\"pdf\" mode=\"bi\" command=\"&quot;gs&quot; -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=pdfwrite&quot; &quot;-sOutputFile=%o&quot; &quot;-f%i&quot;\"/>"
     "  <delegate decode=\"ps\" encode=\"print\" mode=\"encode\" command=\"lpr &quot;%i&quot;\"/>"
-    "  <delegate decode=\"ps:alpha\" stealth=\"True\" command=\"&quot;gs&quot; -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 &quot;-sDEVICE=pngalpha&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;-f%s&quot; &quot;-f%s&quot;\"/>"
-    "  <delegate decode=\"ps:bbox\" stealth=\"True\" command=\"&quot;gs&quot; -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 &quot;-sDEVICE=bbox&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;-f%s&quot; &quot;-f%s&quot;\"/>"
-    "  <delegate decode=\"ps:cmyk\" stealth=\"True\" command=\"&quot;gs&quot; -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 &quot;-sDEVICE=bmpsep8&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;-f%s&quot; &quot;-f%s&quot;\"/>"
-    "  <delegate decode=\"ps:color\" stealth=\"True\" command=\"&quot;gs&quot; -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 &quot;-sDEVICE=pnmraw&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;-f%s&quot; &quot;-f%s&quot;\"/>"
-    "  <delegate decode=\"ps:mono\" stealth=\"True\" command=\"&quot;gs&quot; -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 &quot;-sDEVICE=pnmraw&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;-f%s&quot; &quot;-f%s&quot;\"/>"
+    "  <delegate decode=\"ps:alpha\" stealth=\"True\" command=\"&quot;gs&quot; -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=pngalpha&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;-f%s&quot; &quot;-f%s&quot;\"/>"
+    "  <delegate decode=\"ps:bbox\" stealth=\"True\" command=\"&quot;gs&quot; -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=bbox&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;-f%s&quot; &quot;-f%s&quot;\"/>"
+    "  <delegate decode=\"ps:cmyk\" stealth=\"True\" command=\"&quot;gs&quot; -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=bmpsep8&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;-f%s&quot; &quot;-f%s&quot;\"/>"
+    "  <delegate decode=\"ps:color\" stealth=\"True\" command=\"&quot;gs&quot; -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=pnmraw&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;-f%s&quot; &quot;-f%s&quot;\"/>"
+    "  <delegate decode=\"ps:mono\" stealth=\"True\" command=\"&quot;gs&quot; -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=pnmraw&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;-f%s&quot; &quot;-f%s&quot;\"/>"
     "  <delegate decode=\"rgba\" encode=\"rle\" mode=\"encode\" command=\"&quot;rawtorle&quot; -o &quot;%o&quot; -v &quot;%i&quot;\"/>"
     "  <delegate decode=\"scan\" command=\"&quot;scanimage&quot; -d &quot;%i&quot; &gt; &quot;%o&quot;\"/>"
-    "  <delegate encode=\"show\" spawn=\"True\" command=\"&quot;/usr/local/bin/display&quot; -immutable -delay 0 -window-group %g -title &quot;%l of %f&quot; &quot;temporary:%i&quot;\"/>"
+    "  <delegate encode=\"show\" spawn=\"True\" command=\"&quot;display&quot; -immutable -delay 0 -window-group %g -title &quot;%l of %f&quot; &quot;temporary:%i&quot;\"/>"
     "  <delegate decode=\"shtml\" command=\"&quot;html2ps&quot; -U -o &quot;%o&quot; &quot;%i&quot;\"/>"
     "  <delegate decode=\"svg\" command=\"&quot;rsvg&quot; &quot;%i&quot; &quot;%o&quot;\"/>"
     "  <delegate decode=\"txt\" encode=\"ps\" mode=\"bi\" command=\"&quot;enscript&quot; -o &quot;%o&quot; &quot;%i&quot;\"/>"
-    "  <delegate encode=\"win\" stealth=\"True\" spawn=\"True\" command=\"&quot;/usr/local/bin/display&quot; -immutable -delay 0 -window-group %g -title &quot;%l of %f&quot; &quot;temporary:%i&quot;\"/>"
+    "  <delegate encode=\"win\" stealth=\"True\" spawn=\"True\" command=\"&quot;display&quot; -immutable -delay 0 -window-group %g -title &quot;%l of %f&quot; &quot;temporary:%i&quot;\"/>"
     "  <delegate decode=\"wmf\" command=\"&quot;wmf2eps&quot; -o &quot;%o&quot; &quot;%i&quot;\"/>"
     "</delegatemap>";
 \f
@@ -128,27 +130,89 @@ static const char
   Global declaractions.
 */
 static LinkedListInfo
-  *delegate_list = (LinkedListInfo *) NULL;
+  *delegate_cache = (LinkedListInfo *) NULL;
 
 static SemaphoreInfo
   *delegate_semaphore = (SemaphoreInfo *) NULL;
-
-static volatile MagickBooleanType
-  instantiate_delegate = MagickFalse;
 \f
 /*
   Forward declaractions.
 */
 static MagickBooleanType
-  InitializeDelegateList(ExceptionInfo *),
-  LoadDelegateLists(const char *,ExceptionInfo *);
+  IsDelegateCacheInstantiated(ExceptionInfo *),
+  LoadDelegateCache(LinkedListInfo *,const char *,const char *,const size_t,
+    ExceptionInfo *);
 \f
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %                                                                             %
 %                                                                             %
 %                                                                             %
-+   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                         %
+%  A c q u i r e D e l e g a t e C a c h e                                    %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  AcquireDelegateCache() caches one or more delegate configurations which
+%  provides a mapping between delegate attributes and a delegate name.
+%
+%  The format of the AcquireDelegateCache method is:
+%
+%      LinkedListInfo *AcquireDelegateCache(const char *filename,
+%        ExceptionInfo *exception)
+%
+%  A description of each parameter follows:
+%
+%    o filename: the font file name.
+%
+%    o exception: return any errors or warnings in this structure.
+%
+*/
+static LinkedListInfo *AcquireDelegateCache(const char *filename,
+  ExceptionInfo *exception)
+{
+  LinkedListInfo
+    *delegate_cache;
+
+  MagickStatusType
+    status;
+
+  delegate_cache=NewLinkedList(0);
+  if (delegate_cache == (LinkedListInfo *) NULL)
+    ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
+  status=MagickTrue;
+#if !defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT)
+  {
+    const StringInfo
+      *option;
+
+    LinkedListInfo
+      *options;
+
+    options=GetConfigureOptions(filename,exception);
+    option=(const StringInfo *) GetNextValueInLinkedList(options);
+    while (option != (const StringInfo *) NULL)
+    {
+      status&=LoadDelegateCache(delegate_cache,(const char *)
+        GetStringInfoDatum(option),GetStringInfoPath(option),0,exception);
+      option=(const StringInfo *) GetNextValueInLinkedList(options);
+    }
+    options=DestroyConfigureOptions(options);
+  }
+#endif
+  if (IfMagickTrue(IsLinkedListEmpty(delegate_cache)))
+    status&=LoadDelegateCache(delegate_cache,DelegateMap,"built-in",0,
+      exception);
+  return(delegate_cache);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
++   D e l e g a t e C o m p o n e n t G e n e s i s                           %
 %                                                                             %
 %                                                                             %
 %                                                                             %
@@ -163,7 +227,8 @@ static MagickBooleanType
 */
 MagickPrivate MagickBooleanType DelegateComponentGenesis(void)
 {
-  AcquireSemaphoreInfo(&delegate_semaphore);
+  if (delegate_semaphore == (SemaphoreInfo *) NULL)
+    delegate_semaphore=AcquireSemaphoreInfo();
   return(MagickTrue);
 }
 \f
@@ -200,6 +265,8 @@ static void *DestroyDelegate(void *delegate_info)
     p->encode=DestroyString(p->encode);
   if (p->commands != (char *) NULL)
     p->commands=DestroyString(p->commands);
+  if (p->semaphore != (SemaphoreInfo *) NULL)
+    RelinquishSemaphoreInfo(&p->semaphore);
   p=(DelegateInfo *) RelinquishMagickMemory(p);
   return((void *) NULL);
 }
@@ -207,13 +274,12 @@ static void *DestroyDelegate(void *delegate_info)
 MagickPrivate void DelegateComponentTerminus(void)
 {
   if (delegate_semaphore == (SemaphoreInfo *) NULL)
-    AcquireSemaphoreInfo(&delegate_semaphore);
+    ActivateSemaphoreInfo(&delegate_semaphore);
   LockSemaphoreInfo(delegate_semaphore);
-  if (delegate_list != (LinkedListInfo *) NULL)
-    delegate_list=DestroyLinkedList(delegate_list,DestroyDelegate);
-  instantiate_delegate=MagickFalse;
+  if (delegate_cache != (LinkedListInfo *) NULL)
+    delegate_cache=DestroyLinkedList(delegate_cache,DestroyDelegate);
   UnlockSemaphoreInfo(delegate_semaphore);
-  DestroySemaphoreInfo(&delegate_semaphore);
+  RelinquishSemaphoreInfo(&delegate_semaphore);
 }
 \f
 /*
@@ -270,8 +336,9 @@ MagickExport char *GetDelegateCommand(const ImageInfo *image_info,Image *image,
   assert(image_info->signature == MagickSignature);
   assert(image != (Image *) NULL);
   assert(image->signature == MagickSignature);
-  if (image->debug != MagickFalse)
+  if( IfMagickTrue(image->debug) )
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+
   delegate_info=GetDelegateInfo(decode,encode,exception);
   if (delegate_info == (const DelegateInfo *) NULL)
     {
@@ -283,11 +350,12 @@ MagickExport char *GetDelegateCommand(const ImageInfo *image_info,Image *image,
   if (commands == (char **) NULL)
     {
       (void) ThrowMagickException(exception,GetMagickModule(),
-        ResourceLimitError,"MemoryAllocationFailed","`%s'",
-        decode ? decode : encode);
+        ResourceLimitError,"MemoryAllocationFailed","`%s'",decode ? decode :
+        encode);
       return((char *) NULL);
     }
-  command=InterpretImageProperties(image_info,image,commands[0],exception);
+  command=InterpretImageProperties((ImageInfo *) image_info,image,commands[0],
+    exception);
   if (command == (char *) NULL)
     (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
       "MemoryAllocationFailed","`%s'",commands[0]);
@@ -325,6 +393,7 @@ MagickExport char *GetDelegateCommand(const ImageInfo *image_info,Image *image,
 MagickExport const char *GetDelegateCommands(const DelegateInfo *delegate_info)
 {
   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
+
   assert(delegate_info != (DelegateInfo *) NULL);
   assert(delegate_info->signature == MagickSignature);
   return(delegate_info->commands);
@@ -366,35 +435,33 @@ MagickExport const DelegateInfo *GetDelegateInfo(const char *decode,
     *p;
 
   assert(exception != (ExceptionInfo *) NULL);
-  if ((delegate_list == (LinkedListInfo *) NULL) ||
-      (instantiate_delegate == MagickFalse))
-    if (InitializeDelegateList(exception) == MagickFalse)
-      return((const DelegateInfo *) NULL);
-  if ((delegate_list == (LinkedListInfo *) NULL) ||
-      (IsLinkedListEmpty(delegate_list) != MagickFalse))
+  if (IfMagickFalse(IsDelegateCacheInstantiated(exception)))
     return((const DelegateInfo *) NULL);
-  if ((LocaleCompare(decode,"*") == 0) && (LocaleCompare(encode,"*") == 0))
-    return((const DelegateInfo *) GetValueFromLinkedList(delegate_list,0));
   /*
     Search for named delegate.
   */
   LockSemaphoreInfo(delegate_semaphore);
-  ResetLinkedListIterator(delegate_list);
-  p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
+  ResetLinkedListIterator(delegate_cache);
+  p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
+  if ((LocaleCompare(decode,"*") == 0) && (LocaleCompare(encode,"*") == 0))
+    {
+      UnlockSemaphoreInfo(delegate_semaphore);
+      return(p);
+    }
   while (p != (const DelegateInfo *) NULL)
   {
     if (p->mode > 0)
       {
         if (LocaleCompare(p->decode,decode) == 0)
           break;
-        p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
+        p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
         continue;
       }
     if (p->mode < 0)
       {
         if (LocaleCompare(p->encode,encode) == 0)
           break;
-        p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
+        p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
         continue;
       }
     if (LocaleCompare(decode,p->decode) == 0)
@@ -406,11 +473,11 @@ MagickExport const DelegateInfo *GetDelegateInfo(const char *decode,
     if (LocaleCompare(decode,p->decode) == 0)
       if (LocaleCompare(encode,"*") == 0)
         break;
-    p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
+    p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
   }
   if (p != (const DelegateInfo *) NULL)
-    (void) InsertValueInLinkedList(delegate_list,0,
-      RemoveElementByValueFromLinkedList(delegate_list,p));
+    (void) InsertValueInLinkedList(delegate_cache,0,
+      RemoveElementByValueFromLinkedList(delegate_cache,p));
   UnlockSemaphoreInfo(delegate_semaphore);
   return(p);
 }
@@ -488,30 +555,31 @@ MagickExport const DelegateInfo **GetDelegateInfoList(const char *pattern,
   /*
     Allocate delegate list.
   */
+  assert(number_delegates != (size_t *) NULL);
   assert(pattern != (char *) NULL);
   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
-  assert(number_delegates != (size_t *) NULL);
+
   *number_delegates=0;
   p=GetDelegateInfo("*","*",exception);
   if (p == (const DelegateInfo *) NULL)
     return((const DelegateInfo **) NULL);
   delegates=(const DelegateInfo **) AcquireQuantumMemory((size_t)
-    GetNumberOfElementsInLinkedList(delegate_list)+1UL,sizeof(*delegates));
+    GetNumberOfElementsInLinkedList(delegate_cache)+1UL,sizeof(*delegates));
   if (delegates == (const DelegateInfo **) NULL)
     return((const DelegateInfo **) NULL);
   /*
     Generate delegate list.
   */
   LockSemaphoreInfo(delegate_semaphore);
-  ResetLinkedListIterator(delegate_list);
-  p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
+  ResetLinkedListIterator(delegate_cache);
+  p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
   for (i=0; p != (const DelegateInfo *) NULL; )
   {
-    if ((p->stealth == MagickFalse) &&
-        ((GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse) ||
-         (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse)))
+    if( IfMagickFalse(p->stealth) &&
+        ( IfMagickTrue(GlobExpression(p->decode,pattern,MagickFalse)) ||
+          IfMagickTrue(GlobExpression(p->encode,pattern,MagickFalse))) )
       delegates[i++]=p;
-    p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
+    p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
   }
   UnlockSemaphoreInfo(delegate_semaphore);
   qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateInfoCompare);
@@ -586,27 +654,28 @@ MagickExport char **GetDelegateList(const char *pattern,
   */
   assert(pattern != (char *) NULL);
   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
+
   assert(number_delegates != (size_t *) NULL);
   *number_delegates=0;
   p=GetDelegateInfo("*","*",exception);
   if (p == (const DelegateInfo *) NULL)
     return((char **) NULL);
   delegates=(char **) AcquireQuantumMemory((size_t)
-    GetNumberOfElementsInLinkedList(delegate_list)+1UL,sizeof(*delegates));
+    GetNumberOfElementsInLinkedList(delegate_cache)+1UL,sizeof(*delegates));
   if (delegates == (char **) NULL)
     return((char **) NULL);
   LockSemaphoreInfo(delegate_semaphore);
-  ResetLinkedListIterator(delegate_list);
-  p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
+  ResetLinkedListIterator(delegate_cache);
+  p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
   for (i=0; p != (const DelegateInfo *) NULL; )
   {
-    if ((p->stealth == MagickFalse) &&
-        (GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse))
+    if( IfMagickFalse(p->stealth) &&
+        IfMagickTrue(GlobExpression(p->decode,pattern,MagickFalse)) )
       delegates[i++]=ConstantString(p->decode);
-    if ((p->stealth == MagickFalse) &&
-        (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse))
+    if( IfMagickFalse(p->stealth) &&
+        IfMagickTrue(GlobExpression(p->encode,pattern,MagickFalse)) )
       delegates[i++]=ConstantString(p->encode);
-    p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list);
+    p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
   }
   UnlockSemaphoreInfo(delegate_semaphore);
   qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateCompare);
@@ -640,6 +709,7 @@ MagickExport char **GetDelegateList(const char *pattern,
 MagickExport ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
 {
   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
+
   assert(delegate_info != (DelegateInfo *) NULL);
   assert(delegate_info->signature == MagickSignature);
   return(delegate_info->mode);
@@ -673,6 +743,7 @@ MagickExport MagickBooleanType GetDelegateThreadSupport(
   const DelegateInfo *delegate_info)
 {
   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
+
   assert(delegate_info != (DelegateInfo *) NULL);
   assert(delegate_info->signature == MagickSignature);
   return(delegate_info->thread_support);
@@ -683,40 +754,36 @@ MagickExport MagickBooleanType GetDelegateThreadSupport(
 %                                                                             %
 %                                                                             %
 %                                                                             %
-+   I n i t i a l i z e D e l e g a t e L i s t                               %
++   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                     %
 %                                                                             %
 %                                                                             %
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  InitializeDelegateList() initializes the delegate list.
+%  IsDelegateCacheInstantiated() determines if the delegate cache is
+%  instantiated.  If not, it instantiates the cache and returns it.
 %
-%  The format of the InitializeDelegateList method is:
+%  The format of the IsDelegateInstantiated method is:
 %
-%      MagickBooleanType InitializeDelegateList(ExceptionInfo *exception)
+%      MagickBooleanType IsDelegateCacheInstantiated(ExceptionInfo *exception)
 %
 %  A description of each parameter follows.
 %
 %    o exception: return any errors or warnings in this structure.
 %
 */
-static MagickBooleanType InitializeDelegateList(ExceptionInfo *exception)
+static MagickBooleanType IsDelegateCacheInstantiated(ExceptionInfo *exception)
 {
-  if ((delegate_list == (LinkedListInfo *) NULL) &&
-      (instantiate_delegate == MagickFalse))
+  if (delegate_cache == (LinkedListInfo *) NULL)
     {
       if (delegate_semaphore == (SemaphoreInfo *) NULL)
-        AcquireSemaphoreInfo(&delegate_semaphore);
+        ActivateSemaphoreInfo(&delegate_semaphore);
       LockSemaphoreInfo(delegate_semaphore);
-      if ((delegate_list == (LinkedListInfo *) NULL) &&
-          (instantiate_delegate == MagickFalse))
-        {
-          (void) LoadDelegateLists(DelegateFilename,exception);
-          instantiate_delegate=MagickTrue;
-        }
+      if (delegate_cache == (LinkedListInfo *) NULL)
+        delegate_cache=AcquireDelegateCache(DelegateFilename,exception);
       UnlockSemaphoreInfo(delegate_semaphore);
     }
-  return(delegate_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
+  return(IsMagickNotNULL(delegate_cache));
 }
 \f
 /*
@@ -783,20 +850,17 @@ static MagickBooleanType CopyDelegateFile(const char *source,
     *buffer;
 
   /*
-    Return if destination file already exists and is not empty.
+    Copy source file to destination.
   */
   assert(source != (const char *) NULL);
   assert(destination != (char *) NULL);
   status=GetPathAttributes(destination,&attributes);
-  if ((status != MagickFalse) && (attributes.st_size != 0))
+  if( IfMagickTrue(status) && (attributes.st_size != 0))
     return(MagickTrue);
-  /*
-    Copy source file to destination.
-  */
-  destination_file=open(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
+  destination_file=open_utf8(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
   if (destination_file == -1)
     return(MagickFalse);
-  source_file=open(source,O_RDONLY | O_BINARY);
+  source_file=open_utf8(source,O_RDONLY | O_BINARY,0);
   if (source_file == -1)
     {
       (void) close(destination_file);
@@ -826,7 +890,7 @@ static MagickBooleanType CopyDelegateFile(const char *source,
   (void) close(destination_file);
   (void) close(source_file);
   buffer=(unsigned char *) RelinquishMagickMemory(buffer);
-  return(i != 0 ? MagickTrue : MagickFalse);
+  return(IsMagickTrue(i!=0));
 }
 
 MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
@@ -858,26 +922,27 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
   assert(image_info->signature == MagickSignature);
   assert(image != (Image *) NULL);
   assert(image->signature == MagickSignature);
-  if (image->debug != MagickFalse)
+  if( IfMagickTrue(image->debug) )
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+
   rights=ExecutePolicyRights;
-  if (IsRightsAuthorized(DelegatePolicyDomain,rights,decode) == MagickFalse)
+  if( IfMagickFalse(IsRightsAuthorized(DelegatePolicyDomain,rights,decode)) )
     {
       errno=EPERM;
       (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
         "NotAuthorized","`%s'",decode);
       return(MagickFalse);
     }
-  if (IsRightsAuthorized(DelegatePolicyDomain,rights,encode) == MagickFalse)
+  if( IfMagickFalse(IsRightsAuthorized(DelegatePolicyDomain,rights,encode)) )
     {
       errno=EPERM;
       (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
         "NotAuthorized","`%s'",encode);
       return(MagickFalse);
     }
-  temporary=(*image->filename == '\0') ? MagickTrue : MagickFalse;
-  if (temporary != MagickFalse)
-    if (AcquireUniqueFilename(image->filename) == MagickFalse)
+  temporary=IsMagickTrue(*image->filename == '\0');
+  if( IfMagickTrue(temporary) )
+    if( IfMagickFalse(AcquireUniqueFilename(image->filename)) )
       {
         ThrowFileException(exception,FileOpenError,
           "UnableToCreateTemporaryFile",image->filename);
@@ -886,7 +951,7 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
   delegate_info=GetDelegateInfo(decode,encode,exception);
   if (delegate_info == (DelegateInfo *) NULL)
     {
-      if (temporary != MagickFalse)
+      if( IfMagickTrue(temporary) )
         (void) RelinquishUniqueFileResource(image->filename);
       (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
         "NoTagFound","`%s'",decode ? decode : encode);
@@ -894,9 +959,9 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
     }
   if (*image_info->filename == '\0')
     {
-      if (AcquireUniqueFilename(image_info->filename) == MagickFalse)
+      if( IfMagickFalse(AcquireUniqueFilename(image_info->filename)) )
         {
-          if (temporary != MagickFalse)
+          if( IfMagickTrue(temporary) )
             (void) RelinquishUniqueFileResource(image->filename);
           ThrowFileException(exception,FileOpenError,
             "UnableToCreateTemporaryFile",image_info->filename);
@@ -904,8 +969,7 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
         }
       image_info->temporary=MagickTrue;
     }
-  if ((delegate_info->mode != 0) &&
-      (((decode != (const char *) NULL) &&
+  if ((delegate_info->mode != 0) && (((decode != (const char *) NULL) &&
         (delegate_info->encode != (char *) NULL)) ||
        ((encode != (const char *) NULL) &&
         (delegate_info->decode != (char *) NULL))))
@@ -922,15 +986,15 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
       /*
         Delegate requires a particular image format.
       */
-      if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
+      if( IfMagickFalse(AcquireUniqueFilename(image_info->unique)) )
         {
           ThrowFileException(exception,FileOpenError,
             "UnableToCreateTemporaryFile",image_info->unique);
           return(MagickFalse);
         }
-      if (AcquireUniqueFilename(image_info->zero) == MagickFalse)
+      if( IfMagickFalse(AcquireUniqueFilename(image_info->zero)) )
         {
-          (void) RelinquishUniqueFileResource(image_info->zero);
+          (void) RelinquishUniqueFileResource(image_info->unique);
           ThrowFileException(exception,FileOpenError,
             "UnableToCreateTemporaryFile",image_info->zero);
           return(MagickFalse);
@@ -941,7 +1005,7 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
         {
           (void) RelinquishUniqueFileResource(image_info->unique);
           (void) RelinquishUniqueFileResource(image_info->zero);
-          if (temporary != MagickFalse)
+          if( IfMagickTrue(temporary) )
             (void) RelinquishUniqueFileResource(image->filename);
           (void) ThrowMagickException(exception,GetMagickModule(),
             DelegateError,"DelegateFailed","`%s'",decode ? decode : encode);
@@ -967,18 +1031,18 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
         (void) FormatLocaleString(p->filename,MaxTextExtent,"%s:%s",
           delegate_info->decode,clone_info->filename);
         status=WriteImage(clone_info,p,exception);
-        if (status == MagickFalse)
+        if( IfMagickFalse(status) )
           {
             (void) RelinquishUniqueFileResource(image_info->unique);
             (void) RelinquishUniqueFileResource(image_info->zero);
-            if (temporary != MagickFalse)
+            if( IfMagickTrue(temporary) )
               (void) RelinquishUniqueFileResource(image->filename);
             clone_info=DestroyImageInfo(clone_info);
             (void) ThrowMagickException(exception,GetMagickModule(),
               DelegateError,"DelegateFailed","`%s'",decode ? decode : encode);
             return(MagickFalse);
           }
-        if (clone_info->adjoin != MagickFalse)
+        if( IfMagickTrue(clone_info->adjoin) )
           break;
       }
       (void) RelinquishUniqueFileResource(image_info->unique);
@@ -991,7 +1055,7 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
   commands=StringToList(delegate_info->commands);
   if (commands == (char **) NULL)
     {
-      if (temporary != MagickFalse)
+      if( IfMagickTrue(temporary) )
         (void) RelinquishUniqueFileResource(image->filename);
       (void) ThrowMagickException(exception,GetMagickModule(),
         ResourceLimitError,"MemoryAllocationFailed","`%s'",
@@ -1005,13 +1069,13 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
   for (i=0; commands[i] != (char *) NULL; i++)
   {
     status=AcquireUniqueSymbolicLink(output_filename,image_info->filename);
-    if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
+    if( IfMagickFalse(AcquireUniqueFilename(image_info->unique)) )
       {
         ThrowFileException(exception,FileOpenError,
           "UnableToCreateTemporaryFile",image_info->unique);
         break;
       }
-    if (AcquireUniqueFilename(image_info->zero) == MagickFalse)
+    if( IfMagickFalse(AcquireUniqueFilename(image_info->zero)) )
       {
         (void) RelinquishUniqueFileResource(image_info->unique);
         ThrowFileException(exception,FileOpenError,
@@ -1021,7 +1085,7 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
     if (LocaleCompare(decode,"SCAN") != 0)
       {
         status=AcquireUniqueSymbolicLink(input_filename,image->filename);
-        if (status == MagickFalse)
+        if( IfMagickFalse(status) )
           {
             ThrowFileException(exception,FileOpenError,
               "UnableToCreateTemporaryFile",input_filename);
@@ -1035,26 +1099,36 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
         /*
           Execute delegate.
         */
-        status=SystemCommand(delegate_info->spawn,image_info->verbose,command,
-          exception) != 0 ? MagickTrue : MagickFalse;
-        if (delegate_info->spawn != MagickFalse)
-          (void) sleep(2);
+        status=IsMagickTrue(SystemCommand(delegate_info->spawn,
+          image_info->verbose,command,exception) != 0);
+        if (IfMagickTrue(delegate_info->spawn))
+          {
+            ssize_t
+              count;
+
+            /*
+              Wait for input file to 'disappear', or maximum 10 seconds.
+            */
+            count=100;
+            while ((count-- > 0) && (access_utf8(image->filename,F_OK) == 0))
+              (void) MagickDelay(100);  /* sleep 0.1 seconds */
+          }
         command=DestroyString(command);
       }
     if (LocaleCompare(decode,"SCAN") != 0)
       {
-        if (CopyDelegateFile(image->filename,input_filename) == MagickFalse)
+        if( IfMagickFalse(CopyDelegateFile(image->filename,input_filename)) )
           (void) RelinquishUniqueFileResource(input_filename);
       }
-    if (CopyDelegateFile(image_info->filename,output_filename) == MagickFalse)
+    if( IfMagickFalse(CopyDelegateFile(image_info->filename,output_filename)) )
       (void) RelinquishUniqueFileResource(output_filename);
-    if (image_info->temporary != MagickFalse)
+    if( IfMagickTrue(image_info->temporary) )
       (void) RelinquishUniqueFileResource(image_info->filename);
     (void) RelinquishUniqueFileResource(image_info->unique);
     (void) RelinquishUniqueFileResource(image_info->zero);
     (void) RelinquishUniqueFileResource(image_info->filename);
     (void) RelinquishUniqueFileResource(image->filename);
-    if (status != MagickFalse)
+    if( IfMagickTrue(status) )
       {
         (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
           "DelegateFailed","`%s'",commands[i]);
@@ -1070,9 +1144,9 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
   for ( ; commands[i] != (char *) NULL; i++)
     commands[i]=DestroyString(commands[i]);
   commands=(char **) RelinquishMagickMemory(commands);
-  if (temporary != MagickFalse)
+  if( IfMagickTrue(temporary) )
     (void) RelinquishUniqueFileResource(image->filename);
-  return(status == MagickFalse ? MagickTrue : MagickFalse);
+  return(IsMagickFalse(status));
 }
 \f
 /*
@@ -1129,7 +1203,7 @@ MagickExport MagickBooleanType ListDelegateInfo(FILE *file,
   path=(const char *) NULL;
   for (i=0; i < (ssize_t) number_delegates; i++)
   {
-    if (delegate_info[i]->stealth != MagickFalse)
+    if( IfMagickTrue(delegate_info[i]->stealth) )
       continue;
     if ((path == (const char *) NULL) ||
         (LocaleCompare(path,delegate_info[i]->path) != 0))
@@ -1181,13 +1255,14 @@ MagickExport MagickBooleanType ListDelegateInfo(FILE *file,
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  LoadDelegateList() loads the delegate configuration file which provides a
+%  LoadDelegateCache() loads the delegate configurations which provides a
 %  mapping between delegate attributes and a delegate name.
 %
-%  The format of the LoadDelegateList method is:
+%  The format of the LoadDelegateCache method is:
 %
-%      MagickBooleanType LoadDelegateList(const char *xml,const char *filename,
-%        const size_t depth,ExceptionInfo *exception)
+%      MagickBooleanType LoadDelegateCache(LinkedListInfo *delegate_cache,
+%        const char *xml,const char *filename,const size_t depth,
+%        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -1200,8 +1275,9 @@ MagickExport MagickBooleanType ListDelegateInfo(FILE *file,
 %    o exception: return any errors or warnings in this structure.
 %
 */
-static MagickBooleanType LoadDelegateList(const char *xml,const char *filename,
-  const size_t depth,ExceptionInfo *exception)
+static MagickBooleanType LoadDelegateCache(LinkedListInfo *delegate_cache,
+  const char *xml,const char *filename,const size_t depth,
+  ExceptionInfo *exception)
 {
   char
     keyword[MaxTextExtent],
@@ -1223,16 +1299,6 @@ static MagickBooleanType LoadDelegateList(const char *xml,const char *filename,
     "Loading delegate configuration file \"%s\" ...",filename);
   if (xml == (const char *) NULL)
     return(MagickFalse);
-  if (delegate_list == (LinkedListInfo *) NULL)
-    {
-      delegate_list=NewLinkedList(0);
-      if (delegate_list == (LinkedListInfo *) NULL)
-        {
-          ThrowFileException(exception,ResourceLimitError,
-            "MemoryAllocationFailed",filename);
-          return(MagickFalse);
-        }
-    }
   status=MagickTrue;
   delegate_info=(DelegateInfo *) NULL;
   token=AcquireString(xml);
@@ -1294,10 +1360,11 @@ static MagickBooleanType LoadDelegateList(const char *xml,const char *filename,
                     (void) CopyMagickString(path,token,MaxTextExtent);
                   else
                     (void) ConcatenateMagickString(path,token,MaxTextExtent);
-                  xml=FileToString(path,~0,exception);
+                  xml=FileToXML(path,~0UL);
                   if (xml != (char *) NULL)
                     {
-                      status=LoadDelegateList(xml,path,depth+1,exception);
+                      status&=LoadDelegateCache(delegate_cache,xml,path,
+                        depth+1,exception);
                       xml=(char *) RelinquishMagickMemory(xml);
                     }
                 }
@@ -1316,6 +1383,7 @@ static MagickBooleanType LoadDelegateList(const char *xml,const char *filename,
           ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
         (void) ResetMagickMemory(delegate_info,0,sizeof(*delegate_info));
         delegate_info->path=ConstantString(filename);
+        delegate_info->thread_support=MagickTrue;
         delegate_info->signature=MagickSignature;
         continue;
       }
@@ -1323,12 +1391,13 @@ static MagickBooleanType LoadDelegateList(const char *xml,const char *filename,
       continue;
     if (LocaleCompare(keyword,"/>") == 0)
       {
-        status=AppendValueToLinkedList(delegate_list,delegate_info);
-        if (status == MagickFalse)
+        status=AppendValueToLinkedList(delegate_cache,delegate_info);
+        if( IfMagickFalse(status) )
           (void) ThrowMagickException(exception,GetMagickModule(),
             ResourceLimitError,"MemoryAllocationFailed","`%s'",
             delegate_info->commands);
         delegate_info=(DelegateInfo *) NULL;
+        continue;
       }
     GetMagickToken(q,(const char **) NULL,token);
     if (*token != '=')
@@ -1409,12 +1478,12 @@ static MagickBooleanType LoadDelegateList(const char *xml,const char *filename,
       {
         if (LocaleCompare((char *) keyword,"spawn") == 0)
           {
-            delegate_info->spawn=IsMagickTrue(token);
+            delegate_info->spawn=IsStringTrue(token);
             break;
           }
         if (LocaleCompare((char *) keyword,"stealth") == 0)
           {
-            delegate_info->stealth=IsMagickTrue(token);
+            delegate_info->stealth=IsStringTrue(token);
             break;
           }
         break;
@@ -1424,7 +1493,9 @@ static MagickBooleanType LoadDelegateList(const char *xml,const char *filename,
       {
         if (LocaleCompare((char *) keyword,"thread-support") == 0)
           {
-            delegate_info->thread_support=IsMagickTrue(token);
+            delegate_info->thread_support=IsStringTrue(token);
+            if (delegate_info->thread_support == MagickFalse)
+              delegate_info->semaphore=AcquireSemaphoreInfo();
             break;
           }
         break;
@@ -1436,61 +1507,3 @@ static MagickBooleanType LoadDelegateList(const char *xml,const char *filename,
   token=(char *) RelinquishMagickMemory(token);
   return(status);
 }
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%  L o a d D e l e g a t e L i s t s                                          %
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%  LoadDelegateList() loads one or more delegate configuration file which
-%  provides a mapping between delegate attributes and a delegate name.
-%
-%  The format of the LoadDelegateLists method is:
-%
-%      MagickBooleanType LoadDelegateLists(const char *filename,
-%        ExceptionInfo *exception)
-%
-%  A description of each parameter follows:
-%
-%    o filename: the font file name.
-%
-%    o exception: return any errors or warnings in this structure.
-%
-*/
-static MagickBooleanType LoadDelegateLists(const char *filename,
-  ExceptionInfo *exception)
-{
-#if defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT)
-  return(LoadDelegateList(DelegateMap,"built-in",0,exception));
-#else
-  const StringInfo
-    *option;
-
-  LinkedListInfo
-    *options;
-
-  MagickStatusType
-    status;
-
-  status=MagickFalse;
-  options=GetConfigureOptions(filename,exception);
-  option=(const StringInfo *) GetNextValueInLinkedList(options);
-  while (option != (const StringInfo *) NULL)
-  {
-    status|=LoadDelegateList((const char *) GetStringInfoDatum(option),
-      GetStringInfoPath(option),0,exception);
-    option=(const StringInfo *) GetNextValueInLinkedList(options);
-  }
-  options=DestroyConfigureOptions(options);
-  if ((delegate_list == (LinkedListInfo *) NULL) ||
-      (IsLinkedListEmpty(delegate_list) != MagickFalse))
-    status|=LoadDelegateList(DelegateMap,"built-in",0,exception);
-  return(status != 0 ? MagickTrue : MagickFalse);
-#endif
-}