13ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
23ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
43ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
53ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
63ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        EEEEE  X   X   CCCC  EEEEE  PPPP  TTTTT  IIIII   OOO   N   N         %
73ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        E       X X   C      E      P   P   T      I    O   O  NN  N         %
83ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        EEE      X    C      EEE    PPPP    T      I    O   O  N N N         %
93ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        E       X X   C      E      P       T      I    O   O  N  NN         %
103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        EEEEE   X  X   CCCC  EEEEE  P       T    IIIII   OOO   N   N         %
113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                        MagickCore Exception Methods                         %
143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                             Software Design                                 %
16de984cdc3631106b1cbbb8d3972b76a0fc27e8e8cristy%                                  Cristy                                     %
173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                July 1993                                    %
183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
207ce65e7125a4e1df1a274ce373c537a9df9c16cdCristy%  Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization      %
213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  dedicated to making software imaging solutions freely available.           %
223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  You may not use this file except in compliance with the License.  You may  %
243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  obtain a copy of the License at                                            %
253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    http://www.imagemagick.org/script/license.php                            %
273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  Unless required by applicable law or agreed to in writing, software        %
293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  distributed under the License is distributed on an "AS IS" BASIS,          %
303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  See the License for the specific language governing permissions and        %
323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  limitations under the License.                                             %
333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Include declarations.
423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
434c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/studio.h"
444c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/client.h"
454c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/exception.h"
464c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/exception-private.h"
47abed7e293f2e8a83e8036df7f2a3e1d9859e5fb2dirk#include "MagickCore/linked-list.h"
484c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/locale_.h"
494c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/log.h"
504c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/magick.h"
514c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/memory_.h"
524c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/string_.h"
534c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/utility.h"
54d1dd6e4fefa0810b9893e6ac9418f79c97c1b39acristy#include "MagickCore/utility-private.h"
553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Forward declarations.
583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(__cplusplus) || defined(c_plusplus)
603ed852eea50f9d4cd633efb8c2b054b8e33c253cristyextern "C" {
613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
633ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic void
643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DefaultErrorHandler(const ExceptionType,const char *,const char *),
653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DefaultFatalErrorHandler(const ExceptionType,const char *,const char *),
663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DefaultWarningHandler(const ExceptionType,const char *,const char *);
673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(__cplusplus) || defined(c_plusplus)
693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Global declarations.
743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
75e45e48b881038487d0bc94d92a16c1537616cc0aCristy#define MaxExceptions  128
76e45e48b881038487d0bc94d92a16c1537616cc0aCristy
77e45e48b881038487d0bc94d92a16c1537616cc0aCristy/*
78e45e48b881038487d0bc94d92a16c1537616cc0aCristy  Global declarations.
79e45e48b881038487d0bc94d92a16c1537616cc0aCristy*/
803ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic ErrorHandler
813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  error_handler = DefaultErrorHandler;
823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
833ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic FatalErrorHandler
843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  fatal_error_handler = DefaultFatalErrorHandler;
853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
863ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic WarningHandler
873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  warning_handler = DefaultWarningHandler;
883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   A c q u i r e E x c e p t i o n I n f o                                   %
953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
1003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  AcquireExceptionInfo() allocates the ExceptionInfo structure.
1013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
1023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the AcquireExceptionInfo method is:
1033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
1043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      ExceptionInfo *AcquireExceptionInfo(void)
1053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
1063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1073ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport ExceptionInfo *AcquireExceptionInfo(void)
1083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
1093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ExceptionInfo
1103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *exception;
1113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11273bd4a51b419e914565bdf204bf1540dc4c8ee26cristy  exception=(ExceptionInfo *) AcquireMagickMemory(sizeof(*exception));
1133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (exception == (ExceptionInfo *) NULL)
1143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
115e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk  InitializeExceptionInfo(exception);
1163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  exception->relinquish=MagickTrue;
1173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(exception);
1183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
1193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
120e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk/*l
1213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
1233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
1243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
1253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   C l e a r M a g i c k E x c e p t i o n                                   %
1263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
1273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
1283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
1293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
1313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  ClearMagickException() clears any exception that may not have been caught
1323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  yet.
1333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
1343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the ClearMagickException method is:
1353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
1363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      ClearMagickException(ExceptionInfo *exception)
1373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
1383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
1393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
1403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o exception: the exception info.
1413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
1423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1443ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic void *DestroyExceptionElement(void *exception)
1453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
1463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register ExceptionInfo
1473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p;
1483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  p=(ExceptionInfo *) exception;
1503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (p->reason != (char *) NULL)
1513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    p->reason=DestroyString(p->reason);
1523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (p->description != (char *) NULL)
1533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    p->description=DestroyString(p->description);
1543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  p=(ExceptionInfo *) RelinquishMagickMemory(p);
1553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return((void *) NULL);
1563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
1573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1583ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport void ClearMagickException(ExceptionInfo *exception)
1593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
1603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(exception != (ExceptionInfo *) NULL);
161e1c94d9d25db6b0dd7a5028ffee31d1057855d73cristy  assert(exception->signature == MagickCoreSignature);
1623efeece86a747d7cd4bc18ddb09791a2f5aee0addirk  if (exception->exceptions == (void *) NULL)
1633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
164f84a193d5f435588cd78d521fff3f1f852e227f8cristy  LockSemaphoreInfo(exception->semaphore);
1653efeece86a747d7cd4bc18ddb09791a2f5aee0addirk  ClearLinkedList((LinkedListInfo *) exception->exceptions,
166f135cd6da2ad8e3998222124b0a36ecaef8386c8cristy    DestroyExceptionElement);
1673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  exception->severity=UndefinedException;
1683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  exception->reason=(char *) NULL;
1693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  exception->description=(char *) NULL;
170f84a193d5f435588cd78d521fff3f1f852e227f8cristy  UnlockSemaphoreInfo(exception->semaphore);
1713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  errno=0;
1723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
1733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
1753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
1773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
1783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
1793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   C a t c h E x c e p t i o n                                               %
1803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
1813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
1823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
1833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
1853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  CatchException() returns if no exceptions is found otherwise it reports
1863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  the exception as a warning, error, or fatal depending on the severity.
1873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
1883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the CatchException method is:
1893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
1903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      CatchException(ExceptionInfo *exception)
1913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
1923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
1933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
1943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o exception: the exception info.
1953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
1963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1973ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport void CatchException(ExceptionInfo *exception)
1983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
1993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register const ExceptionInfo
2003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p;
2013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
202e45e48b881038487d0bc94d92a16c1537616cc0aCristy  ssize_t
203e45e48b881038487d0bc94d92a16c1537616cc0aCristy    i;
204e45e48b881038487d0bc94d92a16c1537616cc0aCristy
2053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(exception != (ExceptionInfo *) NULL);
206e1c94d9d25db6b0dd7a5028ffee31d1057855d73cristy  assert(exception->signature == MagickCoreSignature);
2073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (exception->exceptions  == (void *) NULL)
2083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
209f84a193d5f435588cd78d521fff3f1f852e227f8cristy  LockSemaphoreInfo(exception->semaphore);
2103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ResetLinkedListIterator((LinkedListInfo *) exception->exceptions);
2113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *)
2123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    exception->exceptions);
213e45e48b881038487d0bc94d92a16c1537616cc0aCristy  for (i=0; p != (const ExceptionInfo *) NULL; i++)
2143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
215e45e48b881038487d0bc94d92a16c1537616cc0aCristy    if (i < MaxExceptions)
216e45e48b881038487d0bc94d92a16c1537616cc0aCristy      {
217e45e48b881038487d0bc94d92a16c1537616cc0aCristy        if ((p->severity >= WarningException) && (p->severity < ErrorException))
218e45e48b881038487d0bc94d92a16c1537616cc0aCristy          MagickWarning(p->severity,p->reason,p->description);
219e45e48b881038487d0bc94d92a16c1537616cc0aCristy        if ((p->severity >= ErrorException) &&
220e45e48b881038487d0bc94d92a16c1537616cc0aCristy            (p->severity < FatalErrorException))
221e45e48b881038487d0bc94d92a16c1537616cc0aCristy          MagickError(p->severity,p->reason,p->description);
222e45e48b881038487d0bc94d92a16c1537616cc0aCristy      }
223e45e48b881038487d0bc94d92a16c1537616cc0aCristy    else
224e45e48b881038487d0bc94d92a16c1537616cc0aCristy      if (i == MaxExceptions)
225e45e48b881038487d0bc94d92a16c1537616cc0aCristy        MagickError(ResourceLimitError,"too many exceptions",
226e45e48b881038487d0bc94d92a16c1537616cc0aCristy          "exception processing is suspended");
22732cca407db0c7f1812b1809773513370b5813309cristy    if (p->severity >= FatalErrorException)
2283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      MagickFatalError(p->severity,p->reason,p->description);
2293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *)
2303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      exception->exceptions);
2313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
232f84a193d5f435588cd78d521fff3f1f852e227f8cristy  UnlockSemaphoreInfo(exception->semaphore);
2333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ClearMagickException(exception);
2343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
2353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
2373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy%                                                                             %
239c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy%                                                                             %
240c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy%                                                                             %
241c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy%   C l o n e E x c e p t i o n I n f o                                       %
242c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy%                                                                             %
243c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy%                                                                             %
244c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy%                                                                             %
245c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy%
247c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy%  CloneExceptionInfo() clones the ExceptionInfo structure.
248c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy%
249c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy%  The format of the CloneExceptionInfo method is:
250c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy%
251c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy%      ExceptionInfo *CloneException(ExceptionInfo *exception)
252c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy%
253c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy%  A description of each parameter follows:
254c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy%
255c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy%    o exception: the exception info.
256c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy%
257c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy*/
258c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristyMagickExport ExceptionInfo *CloneExceptionInfo(ExceptionInfo *exception)
259c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy{
260c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy  ExceptionInfo
261c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy    *clone_exception;
262c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy
263c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy  clone_exception=(ExceptionInfo *) AcquireMagickMemory(sizeof(*exception));
264c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy  if (clone_exception == (ExceptionInfo *) NULL)
265c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy    ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
266e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk  InitializeExceptionInfo(clone_exception);
267c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy  InheritException(clone_exception,exception);
2684592b2c7a40c37efd17aaa688be0d18fe953bd8fcristy  clone_exception->relinquish=MagickTrue;
269a0dfced3583f9d765af3ee2b45158baec0f6a2a4cristy  return(clone_exception);
270c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy}
271c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy
272c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy/*
273c82a27bb8e3138ff9bbf0f696663bdf3e704cedecristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy+   D e f a u l t E r r o r H a n d l e r                                     %
2783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  DefaultErrorHandler() displays an error reason.
2843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the DefaultErrorHandler method is:
2863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void MagickError(const ExceptionType severity,const char *reason,
2883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const char *description)
2893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
2913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o severity: Specifies the numeric error category.
2933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o reason: Specifies the reason to display before terminating the
2953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      program.
2963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o description: Specifies any description to the reason.
2983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
3003ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic void DefaultErrorHandler(const ExceptionType magick_unused(severity),
3013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char *reason,const char *description)
3023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
303348c837caadc66adf93e30b08aa1588c7036449fdirk  magick_unreferenced(severity);
304d2a7a2d4a46c82a8679688ae763ef9d7bb53ccd7dirk
3053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (reason == (char *) NULL)
3063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
307b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(stderr,"%s: %s",GetClientName(),reason);
3083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (description != (char *) NULL)
309b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(stderr," (%s)",description);
310b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(stderr,".\n");
3113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) fflush(stderr);
3123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
3133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
3143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
3153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
3173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
3183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
3193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy+   D e f a u l t F a t a l E r r o r H a n d l e r                           %
3203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
3213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
3223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
3233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
3253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  DefaultFatalErrorHandler() displays an error reason and then terminates the
3263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  program.
3273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
3283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the DefaultFatalErrorHandler method is:
3293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
3303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void MagickFatalError(const ExceptionType severity,const char *reason,
3313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const char *description)
3323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
3333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
3343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
3353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o severity: Specifies the numeric error category.
3363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
337b200b6c973701dcc4e43539e1da620fc25aa2c29cristy%    o reason: Specifies the reason to display before terminating the program.
3383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
3393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o description: Specifies any description to the reason.
3403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
3413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
342b200b6c973701dcc4e43539e1da620fc25aa2c29cristystatic void DefaultFatalErrorHandler(const ExceptionType severity,
3433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char *reason,const char *description)
3443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
3453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (reason == (char *) NULL)
3463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
347b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(stderr,"%s: %s",GetClientName(),reason);
3483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (description != (char *) NULL)
349b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(stderr," (%s)",description);
350b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(stderr,".\n");
3513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) fflush(stderr);
3523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  MagickCoreTerminus();
353b4d552cbf0187d092fc9f83fdca1ef6ce90206fbcristy  exit((int) (severity-FatalErrorException)+1);
3543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
3553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
3563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
3573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
3593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
3603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
3613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy+   D e f a u l t W a r n i n g H a n d l e r                                 %
3623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
3633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
3643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
3653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
3673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  DefaultWarningHandler() displays a warning reason.
3683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
3693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the DefaultWarningHandler method is:
3703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
3713b743bb1b7243007b41c2d143bd529c884069efccristy%      void DefaultWarningHandler(const ExceptionType severity,
3723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const char *reason,const char *description)
3733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
3743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
3753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
3763b743bb1b7243007b41c2d143bd529c884069efccristy%    o severity: Specifies the numeric warning category.
3773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
3783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o reason: Specifies the reason to display before terminating the
3793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      program.
3803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
3813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o description: Specifies any description to the reason.
3823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
3833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
3843ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic void DefaultWarningHandler(const ExceptionType magick_unused(severity),
3853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char *reason,const char *description)
3863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
387348c837caadc66adf93e30b08aa1588c7036449fdirk  magick_unreferenced(severity);
388d2a7a2d4a46c82a8679688ae763ef9d7bb53ccd7dirk
3893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (reason == (char *) NULL)
3903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
391b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(stderr,"%s: %s",GetClientName(),reason);
3923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (description != (char *) NULL)
393b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(stderr," (%s)",description);
394b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(stderr,".\n");
3953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) fflush(stderr);
3963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
3973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
3983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
3993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   D e s t r o y E x c e p t i o n I n f o                                   %
4043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  DestroyExceptionInfo() deallocates memory associated with an exception.
4103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the DestroyExceptionInfo method is:
4123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      ExceptionInfo *DestroyExceptionInfo(ExceptionInfo *exception)
4143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
4163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o exception: the exception info.
4183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
4203ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport ExceptionInfo *DestroyExceptionInfo(ExceptionInfo *exception)
4213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
4223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  MagickBooleanType
4233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    relinquish;
4243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(exception != (ExceptionInfo *) NULL);
426e1c94d9d25db6b0dd7a5028ffee31d1057855d73cristy  assert(exception->signature == MagickCoreSignature);
42778883b2620bba1a3572967ae6e04bcd5f42339d6cristy  if (exception->semaphore == (SemaphoreInfo *) NULL)
42804b11db5504ecdf205114ae7e9e68774a1ff0b9bcristy    ActivateSemaphoreInfo(&exception->semaphore);
429f84a193d5f435588cd78d521fff3f1f852e227f8cristy  LockSemaphoreInfo(exception->semaphore);
4303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  exception->severity=UndefinedException;
4313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (exception->relinquish != MagickFalse)
432cee811c0c5eb1f4f2f83453439e380c83e12ed1bdirk    {
433e1c94d9d25db6b0dd7a5028ffee31d1057855d73cristy      exception->signature=(~MagickCoreSignature);
434cee811c0c5eb1f4f2f83453439e380c83e12ed1bdirk      if (exception->exceptions != (void *) NULL)
435cee811c0c5eb1f4f2f83453439e380c83e12ed1bdirk        exception->exceptions=(void *) DestroyLinkedList((LinkedListInfo *)
436cee811c0c5eb1f4f2f83453439e380c83e12ed1bdirk          exception->exceptions,DestroyExceptionElement);
437cee811c0c5eb1f4f2f83453439e380c83e12ed1bdirk    }
438cee811c0c5eb1f4f2f83453439e380c83e12ed1bdirk  else if (exception->exceptions != (void *) NULL)
439cee811c0c5eb1f4f2f83453439e380c83e12ed1bdirk    ClearLinkedList((LinkedListInfo *) exception->exceptions,
440cee811c0c5eb1f4f2f83453439e380c83e12ed1bdirk      DestroyExceptionElement);
441cee811c0c5eb1f4f2f83453439e380c83e12ed1bdirk  relinquish=exception->relinquish;
442f84a193d5f435588cd78d521fff3f1f852e227f8cristy  UnlockSemaphoreInfo(exception->semaphore);
4433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (relinquish != MagickFalse)
444cee811c0c5eb1f4f2f83453439e380c83e12ed1bdirk    {
445cee811c0c5eb1f4f2f83453439e380c83e12ed1bdirk      RelinquishSemaphoreInfo(&exception->semaphore);
446cee811c0c5eb1f4f2f83453439e380c83e12ed1bdirk      exception=(ExceptionInfo *) RelinquishMagickMemory(exception);
447cee811c0c5eb1f4f2f83453439e380c83e12ed1bdirk    }
4483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(exception);
4493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
4503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
4523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   G e t E x c e p t i o n M e s s a g e                                     %
4573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  GetExceptionMessage() returns the error message defined by the specified
4633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  error code.
4643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the GetExceptionMessage method is:
4663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      char *GetExceptionMessage(const int error)
4683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
4703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o error: the error code.
4723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
4743ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport char *GetExceptionMessage(const int error)
4753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
4763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
477151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy    exception[MagickPathExtent];
4783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
479b56416944f1a142ac6fc387f125cbd3bf00ccd65cristy  *exception='\0';
4803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_STRERROR_R)
4817d4a1d61307140a43a65a85587eb9ee09a00d1bfcristy#if !defined(MAGICKCORE_STRERROR_R_CHAR_P)
4823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) strerror_r(error,exception,sizeof(exception));
4833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#else
484866a02f04bdc706d86be55b1182f9ac4c48ce03bcristy  (void) CopyMagickString(exception,strerror_r(error,exception,
485866a02f04bdc706d86be55b1182f9ac4c48ce03bcristy    sizeof(exception)),sizeof(exception));
486866a02f04bdc706d86be55b1182f9ac4c48ce03bcristy#endif
487866a02f04bdc706d86be55b1182f9ac4c48ce03bcristy#else
4883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) CopyMagickString(exception,strerror(error),sizeof(exception));
4893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
4903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(ConstantString(exception));
4913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
4923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
4943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   G e t L o c a l e E x c e p t i o n M e s s a g e                         %
4993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
5003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
5013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
5023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
5043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  GetLocaleExceptionMessage() converts a enumerated exception severity and tag
5053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  to a message in the current locale.
5063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
5073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the GetLocaleExceptionMessage method is:
5083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
5093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      const char *GetLocaleExceptionMessage(const ExceptionType severity,
5103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const char *tag)
5113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
5123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
5133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
5143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o severity: the severity of the exception.
5153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
5163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o tag: the message tag.
5173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
5183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
5193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
5203ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic const char *ExceptionSeverityToTag(const ExceptionType severity)
5213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
5223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  switch (severity)
5233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
5243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case ResourceLimitWarning: return("Resource/Limit/Warning/");
5253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case TypeWarning: return("Type/Warning/");
5263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case OptionWarning: return("Option/Warning/");
5273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case DelegateWarning: return("Delegate/Warning/");
5283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case MissingDelegateWarning: return("Missing/Delegate/Warning/");
5293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case CorruptImageWarning: return("Corrupt/Image/Warning/");
5303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case FileOpenWarning: return("File/Open/Warning/");
5313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case BlobWarning: return("Blob/Warning/");
5323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case StreamWarning: return("Stream/Warning/");
5333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case CacheWarning: return("Cache/Warning/");
5343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case CoderWarning: return("Coder/Warning/");
535992729daaa55bb5c0c49f54cc525f992e09ccae3cristy    case FilterWarning: return("Filter/Warning/");
5363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case ModuleWarning: return("Module/Warning/");
5373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case DrawWarning: return("Draw/Warning/");
5383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case ImageWarning: return("Image/Warning/");
5393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case WandWarning: return("Wand/Warning/");
5403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case XServerWarning: return("XServer/Warning/");
5413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case MonitorWarning: return("Monitor/Warning/");
5423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case RegistryWarning: return("Registry/Warning/");
5433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case ConfigureWarning: return("Configure/Warning/");
5443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case PolicyWarning: return("Policy/Warning/");
5453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case ResourceLimitError: return("Resource/Limit/Error/");
5463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case TypeError: return("Type/Error/");
5473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case OptionError: return("Option/Error/");
5483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case DelegateError: return("Delegate/Error/");
5493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case MissingDelegateError: return("Missing/Delegate/Error/");
5503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case CorruptImageError: return("Corrupt/Image/Error/");
5513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case FileOpenError: return("File/Open/Error/");
5523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case BlobError: return("Blob/Error/");
5533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case StreamError: return("Stream/Error/");
5543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case CacheError: return("Cache/Error/");
5553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case CoderError: return("Coder/Error/");
556992729daaa55bb5c0c49f54cc525f992e09ccae3cristy    case FilterError: return("Filter/Error/");
5573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case ModuleError: return("Module/Error/");
5583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case DrawError: return("Draw/Error/");
5593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case ImageError: return("Image/Error/");
5603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case WandError: return("Wand/Error/");
5613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case XServerError: return("XServer/Error/");
5623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case MonitorError: return("Monitor/Error/");
5633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case RegistryError: return("Registry/Error/");
5643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case ConfigureError: return("Configure/Error/");
5653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case PolicyError: return("Policy/Error/");
5663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case ResourceLimitFatalError: return("Resource/Limit/FatalError/");
5673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case TypeFatalError: return("Type/FatalError/");
5683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case OptionFatalError: return("Option/FatalError/");
5693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case DelegateFatalError: return("Delegate/FatalError/");
5703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case MissingDelegateFatalError: return("Missing/Delegate/FatalError/");
5713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case CorruptImageFatalError: return("Corrupt/Image/FatalError/");
5723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case FileOpenFatalError: return("File/Open/FatalError/");
5733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case BlobFatalError: return("Blob/FatalError/");
5743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case StreamFatalError: return("Stream/FatalError/");
5753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case CacheFatalError: return("Cache/FatalError/");
5763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case CoderFatalError: return("Coder/FatalError/");
577992729daaa55bb5c0c49f54cc525f992e09ccae3cristy    case FilterFatalError: return("Filter/FatalError/");
5783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case ModuleFatalError: return("Module/FatalError/");
5793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case DrawFatalError: return("Draw/FatalError/");
5803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case ImageFatalError: return("Image/FatalError/");
5813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case WandFatalError: return("Wand/FatalError/");
5823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case XServerFatalError: return("XServer/FatalError/");
5833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case MonitorFatalError: return("Monitor/FatalError/");
5843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case RegistryFatalError: return("Registry/FatalError/");
5853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case ConfigureFatalError: return("Configure/FatalError/");
5863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case PolicyFatalError: return("Policy/FatalError/");
5873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    default: break;
5883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
5893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return("");
5903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
5913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
5923ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport const char *GetLocaleExceptionMessage(const ExceptionType severity,
5933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char *tag)
5943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
5953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
596151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy    message[MagickPathExtent];
5973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
5983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char
5993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *locale_message;
6003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(tag != (const char *) NULL);
602151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) FormatLocaleString(message,MagickPathExtent,"Exception/%s%s",
6033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ExceptionSeverityToTag(severity),tag);
6043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  locale_message=GetLocaleMessage(message);
6053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (locale_message == (const char *) NULL)
6063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(tag);
6073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (locale_message == message)
6083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(tag);
6093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(locale_message);
6103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
6113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
6133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
6153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
6163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
6173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   I n h e r i t E x c e p t i o n                                           %
6183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
6193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
6203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
6213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
6233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  InheritException() inherits an exception from a related exception.
6243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
6253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the InheritException method is:
6263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
6273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      InheritException(ExceptionInfo *exception,const ExceptionInfo *relative)
6283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
6293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
6303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
6313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o exception: the exception info.
6323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
6333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o relative: the related exception info.
6343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
6353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
6363ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport void InheritException(ExceptionInfo *exception,
6373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const ExceptionInfo *relative)
6383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
6393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register const ExceptionInfo
6403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p;
6413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(exception != (ExceptionInfo *) NULL);
643e1c94d9d25db6b0dd7a5028ffee31d1057855d73cristy  assert(exception->signature == MagickCoreSignature);
6443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(relative != (ExceptionInfo *) NULL);
645e1c94d9d25db6b0dd7a5028ffee31d1057855d73cristy  assert(relative->signature == MagickCoreSignature);
646f078e391816b7033081339865c711a5547d6aecadirk  assert(exception != relative);
6473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (relative->exceptions == (void *) NULL)
6483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
64993670403847955b4bb6a820d62d1ac2c689fe84dcristy  LockSemaphoreInfo(relative->semaphore);
6503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ResetLinkedListIterator((LinkedListInfo *) relative->exceptions);
6513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *)
6523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    relative->exceptions);
6533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while (p != (const ExceptionInfo *) NULL)
6543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
6553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) ThrowException(exception,p->severity,p->reason,p->description);
6563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *)
6573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      relative->exceptions);
6583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
65993670403847955b4bb6a820d62d1ac2c689fe84dcristy  UnlockSemaphoreInfo(relative->semaphore);
6603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
6613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
6633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
6653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
6663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
667e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk%   I n i t i a l i z e t E x c e p t i o n I n f o                           %
668e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk%                                                                             %
669e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk%                                                                             %
670e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk%                                                                             %
671e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
672e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk%
673e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk%  InitializeExceptionInfo() initializes an exception to default values.
674e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk%
675e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk%  The format of the InitializeExceptionInfo method is:
676e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk%
677e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk%      InitializeExceptionInfo(ExceptionInfo *exception)
678e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk%
679e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk%  A description of each parameter follows:
680e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk%
681e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk%    o exception: the exception info.
682e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk%
683e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk*/
684e31feb8a39ea937a6328da579085cd2ee66ab4c0dirkMagickPrivate void InitializeExceptionInfo(ExceptionInfo *exception)
685e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk{
686e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk  assert(exception != (ExceptionInfo *) NULL);
687e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk  (void) ResetMagickMemory(exception,0,sizeof(*exception));
688e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk  exception->severity=UndefinedException;
689e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk  exception->exceptions=(void *) NewLinkedList(0);
690e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk  exception->semaphore=AcquireSemaphoreInfo();
691e1c94d9d25db6b0dd7a5028ffee31d1057855d73cristy  exception->signature=MagickCoreSignature;
692e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk}
693e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk
694e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk/*
695e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
696e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk%                                                                             %
697e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk%                                                                             %
698e31feb8a39ea937a6328da579085cd2ee66ab4c0dirk%                                                                             %
6993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   M a g i c k E r r o r                                                     %
7003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  MagickError() calls the exception handler methods with an error reason.
7063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the MagickError method is:
7083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void MagickError(const ExceptionType error,const char *reason,
7103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const char *description)
7113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
7133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o exception: Specifies the numeric error category.
7153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o reason: Specifies the reason to display before terminating the
7173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      program.
7183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o description: Specifies any description to the reason.
7203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
7223ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport void MagickError(const ExceptionType error,const char *reason,
7233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char *description)
7243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
7253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (error_handler != (ErrorHandler) NULL)
7263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (*error_handler)(error,reason,description);
7273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
7283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
7303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   M a g i c k F a t al E r r o r                                            %
7353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  MagickFatalError() calls the fatal exception handler methods with an error
7413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  reason.
7423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the MagickError method is:
7443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void MagickFatalError(const ExceptionType error,const char *reason,
7463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const char *description)
7473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
7493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o exception: Specifies the numeric error category.
7513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o reason: Specifies the reason to display before terminating the
7533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      program.
7543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o description: Specifies any description to the reason.
7563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
7583ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport void MagickFatalError(const ExceptionType error,const char *reason,
7593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char *description)
7603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
7613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (fatal_error_handler != (ErrorHandler) NULL)
7623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (*fatal_error_handler)(error,reason,description);
7633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
7643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
7663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   M a g i c k W a r n i n g                                                 %
7713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  MagickWarning() calls the warning handler methods with a warning reason.
7773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the MagickWarning method is:
7793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void MagickWarning(const ExceptionType warning,const char *reason,
7813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const char *description)
7823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
7843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o warning: the warning severity.
7863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o reason: Define the reason for the warning.
7883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o description: Describe the warning.
7903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
7923ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport void MagickWarning(const ExceptionType warning,const char *reason,
7933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char *description)
7943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
7953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (warning_handler != (WarningHandler) NULL)
7963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (*warning_handler)(warning,reason,description);
7973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
7983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
8003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   S e t E r r o r H a n d l e r                                             %
8053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  SetErrorHandler() sets the exception handler to the specified method
8113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  and returns the previous exception handler.
8123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the SetErrorHandler method is:
8143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      ErrorHandler SetErrorHandler(ErrorHandler handler)
8163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
8183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o handler: the method to handle errors.
8203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
8223ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport ErrorHandler SetErrorHandler(ErrorHandler handler)
8233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
8243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ErrorHandler
8253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    previous_handler;
8263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  previous_handler=error_handler;
8283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  error_handler=handler;
8293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(previous_handler);
8303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
8313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
8333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   S e t F a t a l E r r o r H a n d l e r                                   %
8383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  SetFatalErrorHandler() sets the fatal exception handler to the specified
8443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  method and returns the previous fatal exception handler.
8453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the SetErrorHandler method is:
8473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      ErrorHandler SetErrorHandler(ErrorHandler handler)
8493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
8513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o handler: the method to handle errors.
8533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
8553ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport FatalErrorHandler SetFatalErrorHandler(FatalErrorHandler handler)
8563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
8573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  FatalErrorHandler
8583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    previous_handler;
8593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  previous_handler=fatal_error_handler;
8613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  fatal_error_handler=handler;
8623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(previous_handler);
8633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
8643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
8663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   S e t W a r n i n g H a n d l e r                                         %
8713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  SetWarningHandler() sets the warning handler to the specified method
8773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  and returns the previous warning handler.
8783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the SetWarningHandler method is:
8803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      ErrorHandler SetWarningHandler(ErrorHandler handler)
8823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
8843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o handler: the method to handle warnings.
8863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
8883ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport WarningHandler SetWarningHandler(WarningHandler handler)
8893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
8903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  WarningHandler
8913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    previous_handler;
8923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  previous_handler=warning_handler;
8943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  warning_handler=handler;
8953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(previous_handler);
8963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
8973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
8993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   T h r o w E x c e p t i o n                                               %
9043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  ThrowException() throws an exception with the specified severity code,
9103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  reason, and optional description.
9113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the ThrowException method is:
9133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      MagickBooleanType ThrowException(ExceptionInfo *exception,
9153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const ExceptionType severity,const char *reason,
9163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const char *description)
9173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
9193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o exception: the exception info.
9213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o severity: the severity of the exception.
9233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o reason: the reason for the exception.
9253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o description: the exception description.
9273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
9293ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport MagickBooleanType ThrowException(ExceptionInfo *exception,
9303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const ExceptionType severity,const char *reason,const char *description)
9313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
9323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register ExceptionInfo
9333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p;
9343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(exception != (ExceptionInfo *) NULL);
936e1c94d9d25db6b0dd7a5028ffee31d1057855d73cristy  assert(exception->signature == MagickCoreSignature);
93793670403847955b4bb6a820d62d1ac2c689fe84dcristy  LockSemaphoreInfo(exception->semaphore);
9383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  p=(ExceptionInfo *) GetLastValueInLinkedList((LinkedListInfo *)
9393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    exception->exceptions);
9403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((p != (ExceptionInfo *) NULL) && (p->severity == severity) &&
9413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (LocaleCompare(exception->reason,reason) == 0) &&
9423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (LocaleCompare(exception->description,description) == 0))
94393670403847955b4bb6a820d62d1ac2c689fe84dcristy    {
94493670403847955b4bb6a820d62d1ac2c689fe84dcristy      UnlockSemaphoreInfo(exception->semaphore);
94593670403847955b4bb6a820d62d1ac2c689fe84dcristy      return(MagickTrue);
94693670403847955b4bb6a820d62d1ac2c689fe84dcristy    }
94773bd4a51b419e914565bdf204bf1540dc4c8ee26cristy  p=(ExceptionInfo *) AcquireMagickMemory(sizeof(*p));
9483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (p == (ExceptionInfo *) NULL)
94993670403847955b4bb6a820d62d1ac2c689fe84dcristy    {
95093670403847955b4bb6a820d62d1ac2c689fe84dcristy      UnlockSemaphoreInfo(exception->semaphore);
95193670403847955b4bb6a820d62d1ac2c689fe84dcristy      ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
95293670403847955b4bb6a820d62d1ac2c689fe84dcristy    }
9533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) ResetMagickMemory(p,0,sizeof(*p));
9543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  p->severity=severity;
9553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (reason != (const char *) NULL)
9563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    p->reason=ConstantString(reason);
9573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (description != (const char *) NULL)
9583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    p->description=ConstantString(description);
959e1c94d9d25db6b0dd7a5028ffee31d1057855d73cristy  p->signature=MagickCoreSignature;
9603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) AppendValueToLinkedList((LinkedListInfo *) exception->exceptions,p);
961992f537a471552415614fd4eddf5e30ec90cc2b6cristy  if (p->severity >= exception->severity)
962992f537a471552415614fd4eddf5e30ec90cc2b6cristy    {
963992f537a471552415614fd4eddf5e30ec90cc2b6cristy      exception->severity=p->severity;
964992f537a471552415614fd4eddf5e30ec90cc2b6cristy      exception->reason=p->reason;
965992f537a471552415614fd4eddf5e30ec90cc2b6cristy      exception->description=p->description;
966992f537a471552415614fd4eddf5e30ec90cc2b6cristy    }
96793670403847955b4bb6a820d62d1ac2c689fe84dcristy  UnlockSemaphoreInfo(exception->semaphore);
9683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(MagickTrue);
9693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
9703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
9723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   T h r o w M a g i c k E x c e p t i o n                                   %
9773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9825216f82250f6a3a9fe652a6534a46e0a69f5c6f7anthony%  ThrowMagickException logs an exception as determined by the log
9835216f82250f6a3a9fe652a6534a46e0a69f5c6f7anthony%  configuration file.  If an error occurs, MagickFalse is returned
9845216f82250f6a3a9fe652a6534a46e0a69f5c6f7anthony%  otherwise MagickTrue.
9853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the ThrowMagickException method is:
9873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      MagickBooleanType ThrowFileException(ExceptionInfo *exception,
989bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy%        const char *module,const char *function,const size_t line,
9903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const ExceptionType severity,const char *tag,const char *format,...)
9913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
9933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o exception: the exception info.
9953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o filename: the source module filename.
9973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o function: the function name.
9993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o line: the line number of the source module.
10013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o severity: Specifies the numeric error category.
10033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o tag: the locale tag.
10053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o format: the output format.
10073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
10093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
101093670403847955b4bb6a820d62d1ac2c689fe84dcristyMagickExport MagickBooleanType ThrowMagickExceptionList(
101193670403847955b4bb6a820d62d1ac2c689fe84dcristy  ExceptionInfo *exception,const char *module,const char *function,
101293670403847955b4bb6a820d62d1ac2c689fe84dcristy  const size_t line,const ExceptionType severity,const char *tag,
101393670403847955b4bb6a820d62d1ac2c689fe84dcristy  const char *format,va_list operands)
10143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
10153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
1016151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy    message[MagickPathExtent],
1017151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy    path[MagickPathExtent],
1018151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy    reason[MagickPathExtent];
10193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char
102132cca407db0c7f1812b1809773513370b5813309cristy    *locale,
102232cca407db0c7f1812b1809773513370b5813309cristy    *type;
10233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
10253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    n;
10263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  MagickBooleanType
10283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
10293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  size_t
10313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    length;
10323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(exception != (ExceptionInfo *) NULL);
1034e1c94d9d25db6b0dd7a5028ffee31d1057855d73cristy  assert(exception->signature == MagickCoreSignature);
10353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  locale=GetLocaleExceptionMessage(severity,tag);
1036151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) CopyMagickString(reason,locale,MagickPathExtent);
1037151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) ConcatenateMagickString(reason," ",MagickPathExtent);
10383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  length=strlen(reason);
10393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_VSNPRINTF)
1040151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  n=vsnprintf(reason+length,MagickPathExtent-length,format,operands);
10413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#else
10423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  n=vsprintf(reason+length,format,operands);
10433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
10443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (n < 0)
1045151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy    reason[MagickPathExtent-1]='\0';
10463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=LogMagickEvent(ExceptionEvent,module,function,line,"%s",reason);
10473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  GetPathComponent(module,TailPath,path);
104832cca407db0c7f1812b1809773513370b5813309cristy  type="undefined";
104932cca407db0c7f1812b1809773513370b5813309cristy  if ((severity >= WarningException) && (severity < ErrorException))
105032cca407db0c7f1812b1809773513370b5813309cristy    type="warning";
105132cca407db0c7f1812b1809773513370b5813309cristy  if ((severity >= ErrorException) && (severity < FatalErrorException))
105232cca407db0c7f1812b1809773513370b5813309cristy    type="error";
105332cca407db0c7f1812b1809773513370b5813309cristy  if (severity >= FatalErrorException)
105432cca407db0c7f1812b1809773513370b5813309cristy    type="fatal";
1055151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) FormatLocaleString(message,MagickPathExtent,"%s @ %s/%s/%s/%.20g",reason,
1056e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy    type,path,function,(double) line);
10573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) ThrowException(exception,severity,message,(char *) NULL);
10583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(status);
10593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
10603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10613ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport MagickBooleanType ThrowMagickException(ExceptionInfo *exception,
1062bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  const char *module,const char *function,const size_t line,
10633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const ExceptionType severity,const char *tag,const char *format,...)
10643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
10653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  MagickBooleanType
10663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
10673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  va_list
10693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    operands;
10703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  va_start(operands,format);
10723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=ThrowMagickExceptionList(exception,module,function,line,severity,tag,
10733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    format,operands);
10743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  va_end(operands);
10753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(status);
10763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
1077