42#include "MagickWand/studio.h"
43#include "MagickWand/MagickWand.h"
44#include "MagickWand/wand.h"
45#include "MagickWand/magick-wand-private.h"
46#include "MagickWand/wandcli.h"
47#include "MagickWand/wandcli-private.h"
48#include "MagickCore/exception.h"
73WandExport
MagickCLI *AcquireMagickCLI(ImageInfo *image_info,
74 ExceptionInfo *exception)
79 CheckMagickCoreCompatibility();
80 cli_wand=(
MagickCLI *) AcquireCriticalMemory(
sizeof(*cli_wand));
81 cli_wand->wand.id=AcquireWandId();
82 (void) FormatLocaleString(cli_wand->wand.name,MagickPathExtent,
83 "%s-%.20g",
"MagickWandCLI", (
double) cli_wand->wand.id);
84 cli_wand->wand.images=NewImageList();
85 if ( image_info == (ImageInfo *) NULL)
86 cli_wand->wand.image_info=AcquireImageInfo();
88 cli_wand->wand.image_info=image_info;
89 if ( exception == (ExceptionInfo *) NULL)
90 cli_wand->wand.exception=AcquireExceptionInfo();
92 cli_wand->wand.exception=exception;
93 cli_wand->wand.debug=IsEventLogging();
94 cli_wand->wand.signature=MagickWandSignature;
97 cli_wand->draw_info=CloneDrawInfo(cli_wand->wand.image_info,(DrawInfo *) NULL);
98 cli_wand->quantize_info=AcquireQuantizeInfo(cli_wand->wand.image_info);
99 cli_wand->process_flags=MagickCommandOptionFlags;
100 cli_wand->command=(
const OptionInfo *) NULL;
101 cli_wand->image_list_stack=(
CLIStack *) NULL;
102 cli_wand->image_info_stack=(
CLIStack *) NULL;
107 cli_wand->location=
"from \"%s\"";
109 cli_wand->filename=
"unknown";
113 cli_wand->signature=MagickWandSignature;
114 if (cli_wand->wand.debug != MagickFalse)
115 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",cli_wand->wand.name);
145 assert(cli_wand->signature == MagickWandSignature);
146 assert(cli_wand->wand.signature == MagickWandSignature);
147 if (cli_wand->wand.debug != MagickFalse)
148 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",cli_wand->wand.name);
151 if (cli_wand->draw_info != (DrawInfo *) NULL )
152 cli_wand->draw_info=DestroyDrawInfo(cli_wand->draw_info);
153 if (cli_wand->quantize_info != (QuantizeInfo *) NULL )
154 cli_wand->quantize_info=DestroyQuantizeInfo(cli_wand->quantize_info);
155 while(cli_wand->image_list_stack != (
CLIStack *) NULL)
157 node=cli_wand->image_list_stack;
158 cli_wand->image_list_stack=node->next;
159 (void) DestroyImageList((Image *)node->data);
160 (void) RelinquishMagickMemory(node);
162 while(cli_wand->image_info_stack != (
CLIStack *) NULL)
164 node=cli_wand->image_info_stack;
165 cli_wand->image_info_stack=node->next;
166 (void) DestroyImageInfo((ImageInfo *)node->data);
167 (void) RelinquishMagickMemory(node);
169 cli_wand->signature=(~MagickWandSignature);
172 cli_wand->wand.images=DestroyImageList(cli_wand->wand.images);
173 if (cli_wand->wand.image_info != (ImageInfo *) NULL )
174 cli_wand->wand.image_info=DestroyImageInfo(cli_wand->wand.image_info);
175 if (cli_wand->wand.exception != (ExceptionInfo *) NULL )
176 cli_wand->wand.exception=DestroyExceptionInfo(cli_wand->wand.exception);
177 RelinquishWandId(cli_wand->wand.id);
178 cli_wand->wand.signature=(~MagickWandSignature);
179 cli_wand=(
MagickCLI *) RelinquishMagickMemory(cli_wand);
216WandExport MagickBooleanType CLICatchException(
MagickCLI *cli_wand,
217 const MagickBooleanType all_exceptions)
223 assert(cli_wand->signature == MagickWandSignature);
224 assert(cli_wand->wand.signature == MagickWandSignature);
225 if (cli_wand->wand.debug != MagickFalse)
226 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",cli_wand->wand.name);
233 status=cli_wand->wand.exception->severity > ErrorException ? MagickTrue :
236 if ((status == MagickFalse) || (all_exceptions != MagickFalse))
237 CatchException(cli_wand->wand.exception);
257WandExport MagickBooleanType CLILogEvent(
MagickCLI *cli_wand,
258 const LogEventType type,
const char *magick_module,
const char *function,
259 const size_t line,
const char *format,...)
262 new_format[MagickPathExtent];
270 if (IsEventLogging() == MagickFalse)
278 (void) FormatLocaleString(new_format,MagickPathExtent,cli_wand->location,
279 cli_wand->filename, cli_wand->line, cli_wand->column);
280 (void) ConcatenateMagickString(new_format,
" ",MagickPathExtent);
281 (void) ConcatenateMagickString(new_format,format,MagickPathExtent);
283 va_start(operands,format);
284 status=LogMagickEventList(type,magick_module,function,line,new_format,
305WandExport MagickBooleanType CLIThrowException(
MagickCLI *cli_wand,
306 const char *magick_module,
const char *function,
const size_t line,
307 const ExceptionType severity,
const char *tag,
const char *format,...)
310 new_format[MagickPathExtent];
326 (void) CopyMagickString(new_format,format,MagickPathExtent);
327 (void) ConcatenateMagickString(new_format,
" ",MagickPathExtent);
329 len=strlen(new_format);
330 (void) FormatLocaleString(new_format+len,MagickPathExtent-len,
331 cli_wand->location,cli_wand->filename,cli_wand->line,cli_wand->column);
333 va_start(operands,format);
334 status=ThrowMagickExceptionList(cli_wand->wand.exception,magick_module,
335 function,line,severity,tag,new_format,operands);