]> granicus.if.org Git - imagemagick/commitdiff
fix -version and make read handle meta-chars
authoranthony <anthony@git.imagemagick.org>
Tue, 3 Apr 2012 12:14:39 +0000 (12:14 +0000)
committeranthony <anthony@git.imagemagick.org>
Tue, 3 Apr 2012 12:14:39 +0000 (12:14 +0000)
MagickWand/magick-cli.c
MagickWand/operation-private.h
MagickWand/operation.c

index 35221d28a22e27324d643c153dd069f381134a51..9ef3489bf869ca0523ed6e246043f7020befc694 100644 (file)
@@ -369,7 +369,8 @@ next_token:
 %
 %    o argv: A text array containing the command line arguments.
 %
-%    o process_flags: What type of arguments we are allowed to process
+%    o process_flags: What type of arguments will be processed, ignored
+%                     or return errors.
 %
 %    o index: index in the argv array to start processing from
 %
@@ -585,7 +586,7 @@ next_argument:
 %
 %    o argv: A text array containing the command line arguments.
 %
-%    o metadata: any metadata is returned here.
+%    o metadata: any metadata (for VBS) is returned here.
 %         (for compatibilty with MagickCommandGenisis())
 %
 %    o exception: return any errors or warnings in this structure.
@@ -594,19 +595,11 @@ next_argument:
 
 static MagickBooleanType MagickUsage(void)
 {
-  printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
-  printf("Copyright: %s\n",GetMagickCopyright());
-  printf("Features: %s\n\n",GetMagickFeatures());
-  printf("\n");
-
   printf("Usage: %s [(options|images) ...] output_image\n", GetClientName());
   printf("       %s -script filename [script args...]\n", GetClientName());
-  printf("       ... | %s -script - | ...\n", GetClientName());
   printf("\n");
-
   printf("  For more information on usage, options, examples, and technqiues\n");
   printf("  see the ImageMagick website at\n    %s\n", MagickAuthoritativeURL);
-  printf("  Or the web pages in ImageMagick Sources\n");
   return(MagickFalse);
 }
 
@@ -661,15 +654,15 @@ WandExport MagickBooleanType MagickImageCommand(ImageInfo *image_info,
   const char
     *option;
 
+  ProcessOptionFlags
+    process_flags = MagickCommandOptionFlags;
+
   /* For specific OS command line requirements */
   ReadCommandlLine(argc,&argv);
 
 #if 0
-  /* FUTURE: This does not make sense!  Remove it.
-     Only "-read" needs to expand file name glob patterns
-  */
   status=ExpandFilenames(&argc,&argv);
-  if ( IfMagickFalse(status))
+  if ( IfMagickFalse(status) )
     ThrowConvertException(ResourceLimitError,"MemoryAllocationFailed",
       GetExceptionMessage(errno));
 #endif
@@ -680,14 +673,14 @@ WandExport MagickBooleanType MagickImageCommand(ImageInfo *image_info,
   GetPathComponent(argv[0],TailPath,cli_wand->wand.name);
   ConcatenateMagickString(cli_wand->wand.name,"-CLI",MaxTextExtent);
 
-#if 0
   /* "convert" command - give a "depreciation" warning" */
-  if ( (LocaleCompare("convert",argv[0]+strlen((argv[0])-7) == 0) ||
+  if ( (LocaleCompare("convert",argv[0]+strlen((argv[0])-7)) == 0) ||
        (LocaleNCompare("convert",argv[0],7) == 0) ||
        (LocaleNCompare("lt-convert",argv[0],10) == 0) ) {
-       /* output warning */
+    process_flags = ConvertCommandOptionFlags;
+    /*(void) FormatLocaleFile(stderr,"WARNING: %s\n",
+             "The convert is depreciated in IMv7, use \"magick\"\n");*/
   }
-#endif
 
   /* Special Case:  If command name ends with "script" then run it as is
      a "-script" option is implied.  This allows you to name the "magick"
@@ -712,22 +705,23 @@ WandExport MagickBooleanType MagickImageCommand(ImageInfo *image_info,
 
   /* not enough arguments -- including -help */
   if (argc < 3) {
+    CLISpecialOperator(cli_wand, "-version", (char *)NULL);
     MagickUsage();
     goto Magick_Command_Exit;
   }
 
-  /* Special "concatenate option (hidden) for delegate usage */
-  if (LocaleCompare("-concatenate",argv[1]) == 0) {
-    ConcatenateImages(argc,argv,exception);
-    goto Magick_Command_Exit;
-  }
-
   /* List Information and Abort */
   if (LocaleCompare("-list",argv[1]) == 0) {
     CLISpecialOperator(cli_wand, argv[1], argv[2]);
     goto Magick_Command_Exit;
   }
 
+  /* Special "concatenate option (hidden) for delegate usage */
+  if (LocaleCompare("-concatenate",argv[1]) == 0) {
+    ConcatenateImages(argc,argv,exception);
+    goto Magick_Command_Exit;
+  }
+
   /* ------------- */
   /* The Main Call */
 
@@ -741,9 +735,7 @@ WandExport MagickBooleanType MagickImageCommand(ImageInfo *image_info,
   }
   else {
     /* Normal Command Line, assumes output file as last option */
-    ProcessCommandOptions(cli_wand,argc,argv,1,
-       (LocaleCompare("magick",argv[0]+strlen(argv[0])-6) == 0)?
-           MagickCommandOptionFlags : ConvertCommandOptionFlags);
+    ProcessCommandOptions(cli_wand,argc,argv,1, process_flags);
   }
   /* ------------- */
 
index 6847f3c51a1adabdde590d17a6197a0c07f680c8..09bfa285a70a26a6767e9e7ed320e37b14fc9219 100644 (file)
@@ -41,6 +41,9 @@ extern "C" {
 #define CLIWandExceptArgBreak(severity,tag,option,arg) \
    { CLIWandExceptionArg(severity,tag,option,arg); break; }
 
+#define CLIWandExceptArgReturn(severity,tag,option,arg) \
+   { CLIWandExceptionArg(severity,tag,option,arg); return; }
+
 
 /* Define a generic stack linked list, for pushing and popping
    user defined ImageInfo settings, and Image lists.
index 8a41690ad138be58158072c2cd6ef2d08b9b45f1..78dd2833580a7dacfcd031269bfcb7d655b91759 100644 (file)
@@ -4372,47 +4372,45 @@ WandExport void CLIListOperatorImages(MagickCLI *cli_wand,
           _images=smush_image;
           break;
         }
-      if (LocaleCompare("swap",option+1) == 0)
-        {
-          Image
-            *p,
-            *q,
-            *swap;
+      if (LocaleCompare("swap",option+1) == 0) {
+        Image
+          *p,
+          *q,
+          *swap;
+
+        ssize_t
+          index,
+          swap_index;
+
+        index=-1;
+        swap_index=-2;
+        if (IfNormalOp) {
+          GeometryInfo
+            geometry_info;
 
-          ssize_t
-            index,
-            swap_index;
+          MagickStatusType
+            flags;
 
+          swap_index=(-1);
           if (IfMagickFalse(IsGeometry(arg1)))
             CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg1);
-          index=-1;
-          swap_index=-2;
-          if (IfNormalOp)
-            {
-              GeometryInfo
-                geometry_info;
-
-              MagickStatusType
-                flags;
-
-              swap_index=(-1);
-              flags=ParseGeometry(arg1,&geometry_info);
-              index=(ssize_t) geometry_info.rho;
-              if ((flags & SigmaValue) != 0)
-                swap_index=(ssize_t) geometry_info.sigma;
-            }
-          p=GetImageFromList(_images,index);
-          q=GetImageFromList(_images,swap_index);
-          if ((p == (Image *) NULL) || (q == (Image *) NULL))
-            CLIWandExceptArgBreak(OptionError,"NoSuchImage",option,arg1);
-          if (p == q)
-            break;  /* same image - no-op - not an error */
-          swap=CloneImage(p,0,0,MagickTrue,_exception);
-          ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,_exception));
-          ReplaceImageInList(&q,swap);
-          _images=GetFirstImageInList(q);
-          break;
-        }
+          flags=ParseGeometry(arg1,&geometry_info);
+          index=(ssize_t) geometry_info.rho;
+          if ((flags & SigmaValue) != 0)
+            swap_index=(ssize_t) geometry_info.sigma;
+        }
+        p=GetImageFromList(_images,index);
+        q=GetImageFromList(_images,swap_index);
+        if ((p == (Image *) NULL) || (q == (Image *) NULL))
+          CLIWandExceptArgBreak(OptionError,"NoSuchImage",option,arg1);
+        if (p == q)
+          break;  /* same image - no-op - not an error */
+        swap=CloneImage(p,0,0,MagickTrue,_exception);
+        ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,_exception));
+        ReplaceImageInList(&q,swap);
+        _images=GetFirstImageInList(q);
+        break;
+      }
       CLIWandExceptionBreak(OptionError,"UnrecognizedOption",option);
     }
     case 'w':
@@ -4547,25 +4545,34 @@ WandExport void CLISpecialOperator(MagickCLI *cli_wand,
     Image Reading
   */
   if ( ( LocaleCompare("read",option+1) == 0 ) ||
-       ( LocaleCompare("--",option) == 0 ) ) {
-/*
-      int argc = 1
-      char **argv = &arg1;
-      MagickBooleanType
-        status=ExpandFilenames(&argc,&argv);
-
-      if (IfMagickFalse(status))
-        ThrowConvertException(ResourceLimitError,"MemoryAllocationFailed",
-             GetExceptionMessage(errno));
-      ...loop over images to read...
-*/
+     ( LocaleCompare("--",option) == 0 ) ) {
+    int
+      argc;
+    char
+      **argv;
+
+    ssize_t
+      i;
+
+    /* Expand the filename argument (meta-characters or "@filelist" ) */
+    argc = 1;
+    argv = &arg1;
+    MagickBooleanType
+      status=ExpandFilenames(&argc,&argv);
+
+    if (IfMagickFalse(status))
+      CLIWandExceptArgReturn(ResourceLimitError,"MemoryAllocationFailed",
+          option,GetExceptionMessage(errno));
+
+    /* loop over expanded list reading images */
+    for (i=0; i<argc; i++) {
 #if !USE_WAND_METHODS
       Image *
         new_images;
       if (IfMagickTrue(cli_wand->wand.image_info->ping))
-        new_images=PingImages(cli_wand->wand.image_info,arg1,_exception);
+        new_images=PingImages(cli_wand->wand.image_info,argv[i],_exception);
       else
-        new_images=ReadImages(cli_wand->wand.image_info,arg1,_exception);
+        new_images=ReadImages(cli_wand->wand.image_info,argv[i],_exception);
       AppendImageToList(&cli_wand->wand.images, new_images);
 #else
       /* read images using MagickWand method - no ping */
@@ -4574,8 +4581,11 @@ WandExport void CLISpecialOperator(MagickCLI *cli_wand,
       MagickReadImage(&cli_wand->wand,arg1);
       MagickSetFirstIterator(&cli_wand->wand);
 #endif
-      return;
     }
+    /* FUTURE: how do I free the expanded filename arguments??? */
+
+    return;
+  }
   /*
     Parenthesis and Brace operations
   */
@@ -4718,7 +4728,7 @@ WandExport void CLISpecialOperator(MagickCLI *cli_wand,
   /*
     Informational Operations
   */
-  if (LocaleCompare("verbose",option+1) == 0) {
+  if (LocaleCompare("version",option+1) == 0) {
       (void) FormatLocaleFile(stdout,"Version: %s\n",
         GetMagickVersion((size_t *) NULL));
       (void) FormatLocaleFile(stdout,"Copyright: %s\n",