From: anthony Date: Tue, 28 Feb 2012 12:48:29 +0000 (+0000) Subject: Re-arrangements for example test programs X-Git-Tag: 7.0.1-0~6112 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2052d27d92125fd91005c0a737a1a950d8163047;p=imagemagick Re-arrangements for example test programs --- diff --git a/MagickWand/MagickWand.h b/MagickWand/MagickWand.h index ee67e8824..aca44fdcc 100644 --- a/MagickWand/MagickWand.h +++ b/MagickWand/MagickWand.h @@ -157,6 +157,7 @@ typedef struct _MagickWand #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" diff --git a/MagickWand/magick-cli.c b/MagickWand/magick-cli.c index b59bc8b37..51302b2ff 100644 --- a/MagickWand/magick-cli.c +++ b/MagickWand/magick-cli.c @@ -49,9 +49,9 @@ #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" @@ -475,15 +475,9 @@ WandExport void ProcessScriptOptions(MagickCLI *cli_wand,int argc,char **argv) 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; } @@ -548,16 +542,10 @@ WandExport void ProcessScriptOptions(MagickCLI *cli_wand,int argc,char **argv) 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 @@ -718,25 +706,28 @@ WandExport void ProcessCommandOptions(MagickCLI *cli_wand,int argc, 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"; @@ -765,6 +756,7 @@ WandExport void ProcessCommandOptions(MagickCLI *cli_wand,int argc, CLISpecialOperator(cli_wand,option,arg1); } + if ( (option_type & SettingOptionFlags) != 0 ) { CLISettingOptionInfo(cli_wand, option+1, arg1); @@ -777,17 +769,14 @@ WandExport void ProcessCommandOptions(MagickCLI *cli_wand,int argc, 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); @@ -1011,10 +1000,10 @@ WandExport MagickBooleanType MagickImageCommand(ImageInfo *image_info, /* 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); diff --git a/MagickWand/magick-cli.h b/MagickWand/magick-cli.h index b72154099..4d9611bb8 100644 --- a/MagickWand/magick-cli.h +++ b/MagickWand/magick-cli.h @@ -22,9 +22,6 @@ extern "C" { #endif -typedef struct _MagickCLI - MagickCLI; - typedef enum { /* What options should be processed */ diff --git a/MagickWand/operation-private.h b/MagickWand/operation-private.h new file mode 100644 index 000000000..9cff0e395 --- /dev/null +++ b/MagickWand/operation-private.h @@ -0,0 +1,64 @@ +/* + 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 diff --git a/MagickWand/operation.c b/MagickWand/operation.c index 80ea2125f..e29c1b421 100644 --- a/MagickWand/operation.c +++ b/MagickWand/operation.c @@ -50,8 +50,8 @@ #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" @@ -496,6 +496,57 @@ WandExport MagickCLI *DestroyMagickCLI(MagickCLI *cli_wand) % % % % % % ++ 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); +} + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % + C L I S e t t i n g O p t i o n I n f o % % % % % @@ -513,7 +564,7 @@ WandExport MagickCLI *DestroyMagickCLI(MagickCLI *cli_wand) % 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) @@ -530,7 +581,7 @@ WandExport MagickCLI *DestroyMagickCLI(MagickCLI *cli_wand) % % Example usage... % -% CLISettingOptionInfo(cli_wand, "background", MagickTrue, "Red"); +% CLISettingOptionInfo(cli_wand, "background", "Red"); % CLISettingOptionInfo(cli_wand, "adjoin", "true"); % CLISettingOptionInfo(cli_wand, "adjoin", NULL); % @@ -539,9 +590,11 @@ WandExport MagickCLI *DestroyMagickCLI(MagickCLI *cli_wand) % 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") ); @@ -1535,9 +1588,11 @@ WandExport void CLISettingOptionInfo(MagickCLI *cli_wand,const char *option, % 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, @@ -3438,9 +3493,11 @@ WandExport void CLISimpleOperatorImages(MagickCLI *cli_wand, % 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, @@ -4170,6 +4227,29 @@ WandExport void CLIListOperatorImages(MagickCLI *cli_wand, % 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; % */ @@ -4368,7 +4448,7 @@ WandExport void CLISpecialOperator(MagickCLI *cli_wand, } if ( LocaleCompare("-read",option) == 0 ) { -#if 1 +#if 0 Image * new_images; diff --git a/MagickWand/operation.h b/MagickWand/operation.h index d586a14b0..67f717373 100644 --- a/MagickWand/operation.h +++ b/MagickWand/operation.h @@ -22,11 +22,16 @@ 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,