#include "MagickWand/drawing-wand.h"
#include "MagickWand/identify.h"
#include "MagickWand/import.h"
+#include "MagickWand/operation.h"
#include "MagickWand/magick-cli.h"
#include "MagickWand/magick-property.h"
#include "MagickWand/magick-image.h"
#include "MagickWand/studio.h"
#include "MagickWand/MagickWand.h"
#include "MagickWand/magick-wand-private.h"
-#include "MagickWand/magick-cli-private.h"
-#include "MagickWand/magick-cli.h"
#include "MagickWand/operation.h"
+#include "MagickWand/operation-private.h"
+#include "MagickWand/magick-cli.h"
#include "MagickCore/memory_.h"
#include "MagickCore/string-private.h"
#include "MagickCore/utility-private.h"
MagickExceptionScript(OptionFatalError,"UnrecognizedOption",
option,option_line,option_column);
- // FUTURE: '-regard_warning' causes IM to exit more prematurely!
- // Note pipelined options may like more control over this level
- if (cli_wand->wand.exception->severity > ErrorException)
- {
- if (cli_wand->wand.exception->severity > ErrorException)
- //(regard_warnings != MagickFalse))
- break; /* FATAL - caller handles exception */
- CatchException(cli_wand->wand.exception); /* output warnings and clear!!! */
- }
+ if ( CLICatchException(cli_wand, MagickFalse) != MagickFalse )
+ break;
+
continue;
}
if ( (option_type & ListOperatorOptionFlag) != 0 )
CLIListOperatorImages(cli_wand, plus_alt_op, option+1, arg1, arg2);
- // FUTURE: '-regard_warning' causes IM to exit more prematurely!
- // Note pipelined options may like more control over this level
- if (cli_wand->wand.exception->severity > ErrorException)
- {
- if (cli_wand->wand.exception->severity > ErrorException)
- //(regard_warnings != MagickFalse))
- break; /* FATAL - caller handles exception */
- CatchException(cli_wand->wand.exception); /* output warnings and clear!!! */
- }
+ if ( CLICatchException(cli_wand, MagickFalse) != MagickFalse )
+ break;
}
+
#if MagickCommandDebug
(void) FormatLocaleFile(stderr, "Script End: %d\n", token_info.status);
#endif
MagickExceptionReturn(OptionFatalError,"UnrecognizedOption",
option,i);
- // FUTURE: '-regard_warning' causes IM to exit more prematurely!
- // Note pipelined options may like more control over this level
- if (cli_wand->wand.exception->severity > ErrorException)
- {
- if (cli_wand->wand.exception->severity > ErrorException)
- //(regard_warnings != MagickFalse))
- break; /* FATAL - caller handles exception */
- CatchException(cli_wand->wand.exception); /* output warnings and clear!!! */
- }
+ if ( CLICatchException(cli_wand, MagickFalse) != MagickFalse )
+ break;
+
continue;
}
if ( (option_type & DeprecateOptionFlag) != 0 )
- MagickExceptionContinue(OptionWarning,"DeprecatedOption",option,i);
- /* continue processing option anyway */
+ {
+ MagickExceptionContinue(OptionWarning,"DeprecatedOption",option,i);
+ if ( CLICatchException(cli_wand, MagickFalse) != MagickFalse )
+ break;
+ /* FALLTHRU - continue processing */
+ }
if ((i+count) >= end )
- MagickExceptionReturn(OptionError,"MissingArgument",option,i);
+ {
+ MagickExceptionReturn(OptionError,"MissingArgument",option,i);
+ if ( CLICatchException(cli_wand, MagickFalse) != MagickFalse )
+ break;
+ continue; /* unable to proceed */
+ }
if (*option=='+') plus_alt_op = MagickTrue;
if (*option!='+') arg1 = "true";
CLISpecialOperator(cli_wand,option,arg1);
}
+
if ( (option_type & SettingOptionFlags) != 0 )
{
CLISettingOptionInfo(cli_wand, option+1, arg1);
if ( (option_type & ListOperatorOptionFlag) != 0 )
CLIListOperatorImages(cli_wand, plus_alt_op, option+1, arg1, arg2);
- // FUTURE: '-regard_warning' causes IM to exit more prematurely!
- // Note pipelined options may like more control over this level
- if (cli_wand->wand.exception->severity > ErrorException)
- {
- if (cli_wand->wand.exception->severity > ErrorException)
- //(regard_warnings != MagickFalse))
- return; /* FATAL - caller handles exception */
- CatchException(cli_wand->wand.exception); /* output warnings and clear!!! */
- }
+ if ( CLICatchException(cli_wand, MagickFalse) != MagickFalse )
+ break;
+
}
+ if ( CLICatchException(cli_wand, MagickFalse) != MagickFalse )
+ return;
+
if ( ( process_flags & ProcessOutputFile ) == 0 )
return;
assert(end==argc-1);
/* Processing Command line, assuming output file as last option */
ProcessCommandOptions(cli_wand,argc-1,argv+1,MagickCommandOptionFlags);
-
/* recover original image_info - check we get the right image_info */
while (cli_wand->image_info_stack != (Stack *)NULL)
CLISpecialOperator(cli_wand,"}",(const char *)NULL);
+
assert(cli_wand->wand.image_info == image_info);
assert(cli_wand->wand.exception == exception);
extern "C" {
#endif
-typedef struct _MagickCLI
- MagickCLI;
-
typedef enum
{
/* What options should be processed */
--- /dev/null
+/*
+ Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization
+ dedicated to making software imaging solutions freely available.
+
+ You may not use this file except in compliance with the License.
+ obtain a copy of the License at
+
+ http://www.imagemagick.org/script/license.php
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ ImageMagick pixel wand API.
+*/
+#ifndef _OPERATION_PRIVATE_H
+#define _OPERATION_PRIVATE_H
+
+#if defined(__cplusplus) || defined(c_plusplus)
+extern "C" {
+#endif
+
+/* Define a generic stack linked list, for pushing and popping
+ user defined ImageInfo settings, and Image lists.
+ See '(' ')' and '-clone' CLI options.
+*/
+typedef struct _Stack
+{
+ struct _Stack *next;
+ void *data;
+} Stack;
+
+/* Note this defines an extension to the normal MagickWand
+ Which adds extra elements specific to the Shell API interface
+ while still allowing the Wand to be passed to MagickWand API
+ for specific operations.
+*/
+struct _MagickCLI /* CLI interface version of MagickWand */
+{
+ struct _MagickWand /* this must be the first structure */
+ wand;
+
+ QuantizeInfo
+ *quantize_info; /* for CLI API usage, not used by MagickWand API */
+
+ DrawInfo
+ *draw_info; /* for CLI API usage, not used by MagickWand API */
+
+ Stack
+ *image_list_stack, /* Stacks of Image Lists and Image Info settings */
+ *image_info_stack;
+
+ size_t
+ signature;
+};
+
+
+#if defined(__cplusplus) || defined(c_plusplus)
+}
+#endif
+
+#endif
#include "MagickWand/studio.h"
#include "MagickWand/MagickWand.h"
#include "MagickWand/magick-wand-private.h"
-#include "MagickWand/magick-cli-private.h"
#include "MagickWand/operation.h"
+#include "MagickWand/operation-private.h"
#include "MagickWand/wand.h"
#include "MagickCore/monitor-private.h"
#include "MagickCore/thread-private.h"
% %
% %
% %
++ C L I C a t c h E x c e p t i o n %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% CLICatchException() will report exceptions, either just non-fatal warnings
+% only, or all errors, according to 'all_execeptions' boolean argument.
+%
+% The function returns true is errors are fatal, in which case the caller
+% should abort and re-call with an 'all_exceptions' argument of true before
+% quitting.
+%
+% The cut-off level between fatal and non-fatal may be controlled by options
+% (FUTURE), but defaults to 'Error' exceptions.
+%
+% The format of the CLICatchException method is:
+%
+% MagickBooleanType CLICatchException(MagickCLI *cli_wand,
+% const MagickBooleanType all_exceptions );
+%
+*/
+WandExport MagickBooleanType CLICatchException(MagickCLI *cli_wand,
+ const MagickBooleanType all_exceptions )
+{
+ MagickBooleanType
+ status;
+ assert(cli_wand != (MagickCLI *) NULL);
+ assert(cli_wand->signature == WandSignature);
+ assert(cli_wand->wand.signature == WandSignature);
+ if (cli_wand->wand.debug != MagickFalse)
+ (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",cli_wand->wand.name);
+
+ // FUTURE: '-regard_warning' should make this more sensitive.
+ // Note pipelined options may like more control over this level
+
+ status = MagickFalse;
+ if (cli_wand->wand.exception->severity > ErrorException)
+ status = MagickTrue;
+
+ if ( status == MagickFalse || all_exceptions != MagickFalse )
+ CatchException(cli_wand->wand.exception); /* output and clear exceptions */
+
+ return(status);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+ C L I S e t t i n g O p t i o n I n f o %
% %
% %
% Options handled by this function are listed in CommandOptions[] of
% "option.c" that is one of "SettingOptionFlags" option flags.
%
-% The format of the WandSettingOptionInfo method is:
+% The format of the CLISettingOptionInfo method is:
%
% void CLISettingOptionInfo(MagickCLI *cli_wand,const char *option,
% const char *arg)
%
% Example usage...
%
-% CLISettingOptionInfo(cli_wand, "background", MagickTrue, "Red");
+% CLISettingOptionInfo(cli_wand, "background", "Red");
% CLISettingOptionInfo(cli_wand, "adjoin", "true");
% CLISettingOptionInfo(cli_wand, "adjoin", NULL);
%
% argc,argv
% i=index in argv
%
-% count=ParseCommandOption(MagickCommandOptions,MagickFalse,argv[i]);
-% flags=GetCommandOptionFlags(MagickCommandOptions,MagickFalse,argv[i]);
-% if ( (flags & SettingOptionFlags) != 0 )
+% option_info = GetCommandOptionInfo(argv[i]);
+% count=option_info->type;
+% option_type=option_info->flags;
+%
+% if ( (option_type & SettingOperatorOptionFlags) != 0 )
% CLISettingOptionInfo(cli_wand, argv[i]+1,
% (((*argv[i])!='-') ? (char *)NULL
% : (count>0) ? argv[i+1] : "true") );
% argc,argv
% i=index in argv
%
-% count=ParseCommandOption(MagickCommandOptions,MagickFalse,argv[i]);
-% flags=GetCommandOptionFlags(MagickCommandOptions,MagickFalse,argv[i]);
-% if ( (flags & SimpleOperatorOptionFlag) != 0 )
+% option_info = GetCommandOptionInfo(argv[i]);
+% count=option_info->type;
+% option_type=option_info->flags;
+%
+% if ( (option_type & SimpleOperatorOptionFlag) != 0 )
% CLISimpleOperatorImages(cli_wand,
% ((*argv[i])=='+')?MagickTrue:MagickFalse,argv[i]+1,
% count>=1 ? argv[i+1] : (char *)NULL,
% argc,argv
% i=index in argv
%
-% count=ParseCommandOption(MagickCommandOptions,MagickFalse,argv[i]);
-% flags=GetCommandOptionFlags(MagickCommandOptions,MagickFalse,argv[i]);
-% if ( (flags & ListOperatorOptionFlag) != 0 )
+% option_info = GetCommandOptionInfo(argv[i]);
+% count=option_info->type;
+% option_type=option_info->flags;
+%
+% if ( (option_type & ListOperatorOptionFlag) != 0 )
% CLIListOperatorImages(cli_wand,
% ((*argv[i])=='+')?MagickTrue:MagickFalse,argv[i]+1,
% count>=1 ? argv[i+1] : (char *)NULL,
% o option: The special option (with any switch char) to process
%
% o arg: Argument for option, if required
+%
+% Example Usage...
+%
+% CLISpecialOperator(cli_wand,"-read", "rose:");
+% if ( cli_wand->wand.exception->severity != UndefinedException ) {
+% CatchException(exception);
+% exit(1);
+% }
+%
+% Or for handling command line arguments EG: +/-option ["arg"]
+%
+% cli_wand
+% argc,argv
+% i=index in argv
+%
+% option_info = GetCommandOptionInfo(argv[i]);
+% count=option_info->type;
+% option_type=option_info->flags;
+%
+% if ( (option_type & SpecialOptionFlag) != 0 )
+% CLISpecialOperator(cli_wand,argv[i],
+% count>=1 ? argv[i+1] : (char *)NULL);
+% i += count+1;
%
*/
}
if ( LocaleCompare("-read",option) == 0 )
{
-#if 1
+#if 0
Image *
new_images;
extern "C" {
#endif
+typedef struct _MagickCLI
+ MagickCLI;
extern WandExport MagickCLI
*AcquireMagickCLI(ImageInfo *,ExceptionInfo *),
*DestroyMagickCLI(MagickCLI *);
+extern WandExport MagickBooleanType
+ CLICatchException(MagickCLI *,const MagickBooleanType);
+
extern WandExport void
CLISettingOptionInfo(MagickCLI *,const char *,const char *),
CLISimpleOperatorImages(MagickCLI *,const MagickBooleanType,