]> granicus.if.org Git - imagemagick/commitdiff
Re-arrangements for example test programs
authoranthony <anthony@git.imagemagick.org>
Tue, 28 Feb 2012 12:48:29 +0000 (12:48 +0000)
committeranthony <anthony@git.imagemagick.org>
Tue, 28 Feb 2012 12:48:29 +0000 (12:48 +0000)
MagickWand/MagickWand.h
MagickWand/magick-cli.c
MagickWand/magick-cli.h
MagickWand/operation-private.h [new file with mode: 0644]
MagickWand/operation.c
MagickWand/operation.h

index ee67e8824a2e9033f95a0d26e6fe7d500ef6e824..aca44fdcc8b7fcefae8fb1798ee0d2616c598684 100644 (file)
@@ -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"
index b59bc8b3724c9952fe89ac48cd0828c81e35b74e..51302b2ffae3f41d9e33b271f3aff0ca669553e1 100644 (file)
@@ -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);
 
index b72154099fd2037507fb2247a995a24b66b7bb5b..4d9611bb87090a7094479cbc752881f223d200fd 100644 (file)
@@ -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 (file)
index 0000000..9cff0e3
--- /dev/null
@@ -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
index 80ea2125fab13c1f6718eec8b4d93ee6f667b4d1..e29c1b421aa55e31f97cc423cc0e731b40c9771a 100644 (file)
@@ -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);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
 +   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;
 
index d586a14b05dbb1fd1af2b44f9d3b2f7f25e39332..67f717373a115f0a5e6901eecc3f3d42306579ad 100644 (file)
 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,