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;
96 cli_wand->draw_info=CloneDrawInfo(cli_wand->wand.image_info,
98 if (cli_wand->draw_info->image_info != (ImageInfo *) NULL)
99 cli_wand->draw_info->image_info =
100 DestroyImageInfo(cli_wand->draw_info->image_info);
101 cli_wand->quantize_info=AcquireQuantizeInfo(cli_wand->wand.image_info);
102 cli_wand->process_flags=MagickCommandOptionFlags;
103 cli_wand->command=(
const OptionInfo *) NULL;
104 cli_wand->image_list_stack=(
CLIStack *) NULL;
105 cli_wand->image_info_stack=(
CLIStack *) NULL;
109 cli_wand->location=
"from \"%s\"";
111 cli_wand->filename=
"unknown";
114 cli_wand->signature=MagickWandSignature;
115 if (cli_wand->wand.debug != MagickFalse)
116 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",cli_wand->wand.name);
146 assert(cli_wand->signature == MagickWandSignature);
147 assert(cli_wand->wand.signature == MagickWandSignature);
148 if (cli_wand->wand.debug != MagickFalse)
149 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",cli_wand->wand.name);
152 if (cli_wand->draw_info != (DrawInfo *) NULL )
153 cli_wand->draw_info=DestroyDrawInfo(cli_wand->draw_info);
154 if (cli_wand->quantize_info != (QuantizeInfo *) NULL )
155 cli_wand->quantize_info=DestroyQuantizeInfo(cli_wand->quantize_info);
156 while(cli_wand->image_list_stack != (
CLIStack *) NULL)
158 node=cli_wand->image_list_stack;
159 cli_wand->image_list_stack=node->next;
160 (void) DestroyImageList((Image *)node->data);
161 (void) RelinquishMagickMemory(node);
163 while(cli_wand->image_info_stack != (
CLIStack *) NULL)
165 node=cli_wand->image_info_stack;
166 cli_wand->image_info_stack=node->next;
167 (void) DestroyImageInfo((ImageInfo *)node->data);
168 (void) RelinquishMagickMemory(node);
170 cli_wand->signature=(~MagickWandSignature);
173 cli_wand->wand.images=DestroyImageList(cli_wand->wand.images);
174 if (cli_wand->wand.image_info != (ImageInfo *) NULL )
175 cli_wand->wand.image_info=DestroyImageInfo(cli_wand->wand.image_info);
176 if (cli_wand->wand.exception != (ExceptionInfo *) NULL )
177 cli_wand->wand.exception=DestroyExceptionInfo(cli_wand->wand.exception);
178 RelinquishWandId(cli_wand->wand.id);
179 cli_wand->wand.signature=(~MagickWandSignature);
180 cli_wand=(
MagickCLI *) RelinquishMagickMemory(cli_wand);
217WandExport MagickBooleanType CLICatchException(
MagickCLI *cli_wand,
218 const MagickBooleanType all_exceptions)
224 assert(cli_wand->signature == MagickWandSignature);
225 assert(cli_wand->wand.signature == MagickWandSignature);
226 if (cli_wand->wand.debug != MagickFalse)
227 (void) LogMagickEvent(WandEvent,GetMagickModule(),
"%s",cli_wand->wand.name);
234 status=cli_wand->wand.exception->severity > ErrorException ? MagickTrue :
237 if ((status == MagickFalse) || (all_exceptions != MagickFalse))
238 CatchException(cli_wand->wand.exception);
258WandExport MagickBooleanType CLILogEvent(
MagickCLI *cli_wand,
259 const LogEventType type,
const char *magick_module,
const char *function,
260 const size_t line,
const char *format,...)
263 new_format[MagickPathExtent];
271 if (IsEventLogging() == MagickFalse)
279 (void) FormatLocaleString(new_format,MagickPathExtent,cli_wand->location,
280 cli_wand->filename, cli_wand->line, cli_wand->column);
281 (void) ConcatenateMagickString(new_format,
" ",MagickPathExtent);
282 (void) ConcatenateMagickString(new_format,format,MagickPathExtent);
284 va_start(operands,format);
285 status=LogMagickEventList(type,magick_module,function,line,new_format,
306WandExport MagickBooleanType CLIThrowException(
MagickCLI *cli_wand,
307 const char *magick_module,
const char *function,
const size_t line,
308 const ExceptionType severity,
const char *tag,
const char *format,...)
311 new_format[MagickPathExtent];
327 (void) CopyMagickString(new_format,format,MagickPathExtent);
328 (void) ConcatenateMagickString(new_format,
" ",MagickPathExtent);
330 len=strlen(new_format);
331 (void) FormatLocaleString(new_format+len,MagickPathExtent-len,
332 cli_wand->location,cli_wand->filename,cli_wand->line,cli_wand->column);
334 va_start(operands,format);
335 status=ThrowMagickExceptionList(cli_wand->wand.exception,magick_module,
336 function,line,severity,tag,new_format,operands);