From: anthony Date: Tue, 3 Apr 2012 12:14:39 +0000 (+0000) Subject: fix -version and make read handle meta-chars X-Git-Tag: 7.0.1-0~5912 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0ea037a49d6f7f926e2cabb90c1ebcbf6b1c39bf;p=imagemagick fix -version and make read handle meta-chars --- diff --git a/MagickWand/magick-cli.c b/MagickWand/magick-cli.c index 35221d28a..9ef3489bf 100644 --- a/MagickWand/magick-cli.c +++ b/MagickWand/magick-cli.c @@ -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); } /* ------------- */ diff --git a/MagickWand/operation-private.h b/MagickWand/operation-private.h index 6847f3c51..09bfa285a 100644 --- a/MagickWand/operation-private.h +++ b/MagickWand/operation-private.h @@ -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. diff --git a/MagickWand/operation.c b/MagickWand/operation.c index 8a41690ad..78dd28335 100644 --- a/MagickWand/operation.c +++ b/MagickWand/operation.c @@ -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; iwand.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",