anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % M M AAA GGGG IIIII CCCC K K % |
| 7 | % MM MM A A G I C K K % |
| 8 | % M M M AAAAA G GGG I C KKK % |
| 9 | % M M A A G G I C K K % |
| 10 | % M M A A GGGG IIIII CCCC K K % |
| 11 | % % |
| 12 | % CCCC L IIIII % |
| 13 | % C L I % |
| 14 | % C L I % |
| 15 | % C L I % |
| 16 | % CCCC LLLLL IIIII % |
| 17 | % % |
| 18 | % Perform "Magick" on Images via the Command Line Interface % |
| 19 | % % |
| 20 | % Dragon Computing % |
| 21 | % Anthony Thyssen % |
| 22 | % January 2012 % |
| 23 | % % |
| 24 | % % |
| 25 | % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization % |
| 26 | % dedicated to making software imaging solutions freely available. % |
| 27 | % % |
| 28 | % You may not use this file except in compliance with the License. You may % |
| 29 | % obtain a copy of the License at % |
| 30 | % % |
| 31 | % http://www.imagemagick.org/script/license.php % |
| 32 | % % |
| 33 | % Unless required by applicable law or agreed to in writing, software % |
| 34 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 35 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 36 | % See the License for the specific language governing permissions and % |
| 37 | % limitations under the License. % |
| 38 | % % |
| 39 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 40 | % |
| 41 | % Read CLI arguments, script files, and pipelines, to provide options that |
| 42 | % manipulate images from many different formats. |
| 43 | % |
| 44 | */ |
| 45 | |
| 46 | /* |
| 47 | Include declarations. |
| 48 | */ |
| 49 | #include "MagickWand/studio.h" |
| 50 | #include "MagickWand/MagickWand.h" |
| 51 | #include "MagickWand/magick-wand-private.h" |
anthony | 756cd0d | 2012-04-08 12:41:44 +0000 | [diff] [blame] | 52 | #include "MagickWand/wandcli.h" |
| 53 | #include "MagickWand/wandcli-private.h" |
anthony | 43f425d | 2012-02-26 12:58:58 +0000 | [diff] [blame] | 54 | #include "MagickWand/operation.h" |
anthony | 2052d27 | 2012-02-28 12:48:29 +0000 | [diff] [blame] | 55 | #include "MagickWand/magick-cli.h" |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 56 | #include "MagickWand/script-token.h" |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 57 | #include "MagickCore/utility-private.h" |
anthony | 5216f82 | 2012-04-10 13:02:37 +0000 | [diff] [blame] | 58 | #include "MagickCore/exception-private.h" |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 59 | #include "MagickCore/version.h" |
| 60 | |
anthony | 43f425d | 2012-02-26 12:58:58 +0000 | [diff] [blame] | 61 | /* verbose debugging, |
anthony | f125a5e | 2012-04-03 13:14:42 +0000 | [diff] [blame] | 62 | 3 - option type details |
| 63 | 9 - output options/artifacts/propertys |
anthony | 24aa882 | 2012-03-11 00:56:06 +0000 | [diff] [blame] | 64 | */ |
anthony | ce51b4a | 2012-04-06 02:32:25 +0000 | [diff] [blame] | 65 | #define MagickCommandDebug 0 |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 66 | |
anthony | 24aa882 | 2012-03-11 00:56:06 +0000 | [diff] [blame] | 67 | |
anthony | f125a5e | 2012-04-03 13:14:42 +0000 | [diff] [blame] | 68 | #if MagickCommandDebug >= 9 |
anthony | 8226e72 | 2012-04-05 14:25:46 +0000 | [diff] [blame] | 69 | /* |
| 70 | Temporary Debugging Information |
| 71 | FUTURE: these should be able to be printed out using 'percent escapes' |
| 72 | Actually 'Properities' can already be output with "%[*]" |
| 73 | */ |
anthony | 24aa882 | 2012-03-11 00:56:06 +0000 | [diff] [blame] | 74 | static void OutputOptions(ImageInfo *image_info) |
| 75 | { |
| 76 | const char |
| 77 | *option, |
| 78 | *value; |
| 79 | |
anthony | f125a5e | 2012-04-03 13:14:42 +0000 | [diff] [blame] | 80 | (void) FormatLocaleFile(stdout," Global Options:\n"); |
anthony | 24aa882 | 2012-03-11 00:56:06 +0000 | [diff] [blame] | 81 | ResetImageOptionIterator(image_info); |
| 82 | while ((option=GetNextImageOption(image_info)) != (const char *) NULL ) { |
| 83 | (void) FormatLocaleFile(stdout," %s: ",option); |
| 84 | value=GetImageOption(image_info,option); |
| 85 | if (value != (const char *) NULL) |
| 86 | (void) FormatLocaleFile(stdout,"%s\n",value); |
| 87 | } |
anthony | 5216f82 | 2012-04-10 13:02:37 +0000 | [diff] [blame] | 88 | ResetImageOptionIterator(image_info); |
anthony | 24aa882 | 2012-03-11 00:56:06 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | static void OutputArtifacts(Image *image) |
| 92 | { |
| 93 | const char |
| 94 | *artifact, |
| 95 | *value; |
| 96 | |
| 97 | (void) FormatLocaleFile(stdout," Image Artifacts:\n"); |
| 98 | ResetImageArtifactIterator(image); |
| 99 | while ((artifact=GetNextImageArtifact(image)) != (const char *) NULL ) { |
| 100 | (void) FormatLocaleFile(stdout," %s: ",artifact); |
| 101 | value=GetImageArtifact(image,artifact); |
| 102 | if (value != (const char *) NULL) |
| 103 | (void) FormatLocaleFile(stdout,"%s\n",value); |
| 104 | } |
| 105 | ResetImageArtifactIterator(image); |
| 106 | } |
anthony | f125a5e | 2012-04-03 13:14:42 +0000 | [diff] [blame] | 107 | |
| 108 | static void OutputProperties(Image *image,ExceptionInfo *exception) |
| 109 | { |
| 110 | const char |
| 111 | *property, |
| 112 | *value; |
| 113 | |
| 114 | (void) FormatLocaleFile(stdout," Image Properity:\n"); |
| 115 | ResetImagePropertyIterator(image); |
| 116 | while ((property=GetNextImageProperty(image)) != (const char *) NULL ) { |
| 117 | (void) FormatLocaleFile(stdout," %s: ",property); |
| 118 | value=GetImageProperty(image,property,exception); |
| 119 | if (value != (const char *) NULL) |
| 120 | (void) FormatLocaleFile(stdout,"%s\n",value); |
| 121 | } |
| 122 | ResetImagePropertyIterator(image); |
| 123 | } |
anthony | 24aa882 | 2012-03-11 00:56:06 +0000 | [diff] [blame] | 124 | #endif |
| 125 | |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 126 | |
| 127 | /* |
| 128 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 129 | % % |
| 130 | % % |
| 131 | % % |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 132 | + P r o c e s s S c r i p t O p t i o n s % |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 133 | % % |
| 134 | % % |
| 135 | % % |
| 136 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 137 | % |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 138 | % ProcessScriptOptions() reads options and processes options as they are |
| 139 | % found in the given file, or pipeline. The filename to open and read |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 140 | % options is given as the 'index' argument of the argument array given. |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 141 | % |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 142 | % Other arguments following index may be read by special script options |
| 143 | % as settings (strings), images, or as operations to be processed in various |
| 144 | % ways. How they are treated is up to the script being processed. |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 145 | % |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 146 | % Note that a script not 'return' to the command line processing, nor can |
| 147 | % they call (and return from) other scripts. At least not at this time. |
| 148 | % |
| 149 | % There are no 'ProcessOptionFlags' control flags at this time. |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 150 | % |
| 151 | % The format of the ProcessScriptOptions method is: |
| 152 | % |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 153 | % void ProcessScriptOptions(MagickCLI *cli_wand,int argc,char **argv, |
| 154 | % int index) |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 155 | % |
| 156 | % A description of each parameter follows: |
| 157 | % |
anthony | 43f425d | 2012-02-26 12:58:58 +0000 | [diff] [blame] | 158 | % o cli_wand: the main CLI Wand to use. |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 159 | % |
| 160 | % o argc: the number of elements in the argument vector. |
| 161 | % |
| 162 | % o argv: A text array containing the command line arguments. |
| 163 | % |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 164 | % o index: offset for argc to CLI argumnet count |
| 165 | % |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 166 | */ |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 167 | WandExport void ProcessScriptOptions(MagickCLI *cli_wand,int argc,char **argv, |
| 168 | int index) |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 169 | { |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 170 | ScriptTokenInfo |
| 171 | *token_info; |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 172 | |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 173 | CommandOptionFlags |
| 174 | option_type; |
| 175 | |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 176 | int |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 177 | count; |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 178 | |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 179 | char |
| 180 | *option, |
| 181 | *arg1, |
| 182 | *arg2; |
| 183 | |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 184 | assert(argc>index); /* at least one argument - script name */ |
| 185 | assert(argv != (char **)NULL); |
| 186 | assert(argv[index] != (char *)NULL); |
| 187 | assert(argv[argc-1] != (char *)NULL); |
anthony | 43f425d | 2012-02-26 12:58:58 +0000 | [diff] [blame] | 188 | assert(cli_wand != (MagickCLI *) NULL); |
| 189 | assert(cli_wand->signature == WandSignature); |
| 190 | if (cli_wand->wand.debug != MagickFalse) |
| 191 | (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",cli_wand->wand.name); |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 192 | |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 193 | /* open file script or stream, and set up tokenizer */ |
| 194 | token_info = AcquireScriptTokenInfo(argv[index]); |
anthony | 8ac75b5 | 2012-03-18 11:56:44 +0000 | [diff] [blame] | 195 | if (token_info == (ScriptTokenInfo *) NULL) { |
anthony | 5216f82 | 2012-04-10 13:02:37 +0000 | [diff] [blame] | 196 | CLIWandExceptionFile(OptionFatalError,"UnableToOpenScript",argv[index]); |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 197 | return; |
| 198 | } |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 199 | |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 200 | /* define the error location string for use in exceptions |
anthony | 5216f82 | 2012-04-10 13:02:37 +0000 | [diff] [blame] | 201 | order of localtion format escapes: filename, line, column */ |
| 202 | cli_wand->location="in \"%s\" at line %u,column %u"; |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 203 | if ( LocaleCompare("-", argv[index]) == 0 ) |
| 204 | cli_wand->filename="stdin"; |
| 205 | else |
| 206 | cli_wand->filename=argv[index]; |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 207 | |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 208 | /* Process Options from Script */ |
| 209 | option = arg1 = arg2 = (char*)NULL; |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 210 | while (1) { |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 211 | |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 212 | /* Get a option */ |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 213 | { MagickBooleanType status = GetScriptToken(token_info); |
| 214 | cli_wand->line=token_info->token_line; |
| 215 | cli_wand->column=token_info->token_column; |
anthony | 84d4279 | 2012-03-30 14:08:38 +0000 | [diff] [blame] | 216 | if( IfMagickFalse(status) ) |
| 217 | break; /* error or end of options */ |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 218 | } |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 219 | |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 220 | /* save option details */ |
| 221 | CloneString(&option,token_info->token); |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 222 | |
| 223 | { /* get option type and argument count */ |
| 224 | const OptionInfo *option_info = GetCommandOptionInfo(option); |
| 225 | count=option_info->type; |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 226 | option_type=(CommandOptionFlags) option_info->flags; |
anthony | f125a5e | 2012-04-03 13:14:42 +0000 | [diff] [blame] | 227 | #if 0 |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 228 | (void) FormatLocaleFile(stderr, "Script: %u,%u: \"%s\" matched \"%s\"\n", |
| 229 | cli_wand->line, cli_wand->line, option, option_info->mnemonic ); |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 230 | #endif |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 231 | } |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 232 | |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 233 | /* handle a undefined option - image read? */ |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 234 | if ( option_type == UndefinedOptionFlag || |
| 235 | (option_type & NonMagickOptionFlag) != 0 ) { |
anthony | f125a5e | 2012-04-03 13:14:42 +0000 | [diff] [blame] | 236 | #if MagickCommandDebug >= 3 |
| 237 | (void) FormatLocaleFile(stderr, "Script %u,%u Non-Option: \"%s\"\n", |
| 238 | cli_wand->line, cli_wand->line, option); |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 239 | #endif |
anthony | 756cd0d | 2012-04-08 12:41:44 +0000 | [diff] [blame] | 240 | if ( IfMagickFalse(IsCommandOption(option))) { |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 241 | /* non-option -- treat as a image read */ |
| 242 | CLISpecialOperator(cli_wand,"-read",option); |
anthony | 756cd0d | 2012-04-08 12:41:44 +0000 | [diff] [blame] | 243 | goto next_token; |
| 244 | } |
| 245 | if ( LocaleCompare(option,"-script") == 0 ) { |
| 246 | option_type=SpecialOptionFlag; |
| 247 | count=1; |
| 248 | /* fall thru - collect one argument */ |
| 249 | } |
| 250 | else { |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 251 | CLIWandExceptionBreak(OptionFatalError,"UnrecognizedOption",option); |
anthony | 756cd0d | 2012-04-08 12:41:44 +0000 | [diff] [blame] | 252 | goto next_token; |
| 253 | } |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 254 | } |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 255 | |
| 256 | if ( count >= 1 ) { |
anthony | 84d4279 | 2012-03-30 14:08:38 +0000 | [diff] [blame] | 257 | if( IfMagickFalse(GetScriptToken(token_info)) ) |
anthony | 24aa882 | 2012-03-11 00:56:06 +0000 | [diff] [blame] | 258 | CLIWandException(OptionFatalError,"MissingArgument",option); |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 259 | CloneString(&arg1,token_info->token); |
| 260 | } |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 261 | else |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 262 | CloneString(&arg1,(char *)NULL); |
anthony | 2052d27 | 2012-02-28 12:48:29 +0000 | [diff] [blame] | 263 | |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 264 | if ( count >= 2 ) { |
anthony | 84d4279 | 2012-03-30 14:08:38 +0000 | [diff] [blame] | 265 | if( IfMagickFalse(GetScriptToken(token_info)) ) |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 266 | CLIWandExceptionBreak(OptionFatalError,"MissingArgument",option); |
| 267 | CloneString(&arg2,token_info->token); |
| 268 | } |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 269 | else |
| 270 | CloneString(&arg2,(char *)NULL); |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 271 | |
anthony | b1d483a | 2012-04-14 12:53:56 +0000 | [diff] [blame] | 272 | /* |
| 273 | Process Options |
| 274 | */ |
anthony | f125a5e | 2012-04-03 13:14:42 +0000 | [diff] [blame] | 275 | #if MagickCommandDebug >= 3 |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 276 | (void) FormatLocaleFile(stderr, |
anthony | f125a5e | 2012-04-03 13:14:42 +0000 | [diff] [blame] | 277 | "Script %u,%u Option: \"%s\" Count: %d Flags: %04x Args: \"%s\" \"%s\"\n", |
| 278 | cli_wand->line,cli_wand->line,option,count,option_type,arg1,arg2); |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 279 | #endif |
anthony | b1d483a | 2012-04-14 12:53:56 +0000 | [diff] [blame] | 280 | /* Hard Depreciated Options, no code to execute - error */ |
| 281 | if ( (option_type & DeprecateOptionFlag) != 0 ) { |
| 282 | CLIWandException(OptionError,"DeprecatedOptionNoCode",option); |
| 283 | if ( CLICatchException(cli_wand, MagickFalse) != MagickFalse ) |
| 284 | break; |
| 285 | goto next_token; |
| 286 | } |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 287 | |
anthony | b1d483a | 2012-04-14 12:53:56 +0000 | [diff] [blame] | 288 | /* MagickCommandGenesis() options have no place in a magick script */ |
anthony | 8226e72 | 2012-04-05 14:25:46 +0000 | [diff] [blame] | 289 | if ( (option_type & GenesisOptionFlag) != 0 ) { |
anthony | 8226e72 | 2012-04-05 14:25:46 +0000 | [diff] [blame] | 290 | CLIWandExceptionBreak(OptionError,"InvalidUseOfOption",option); |
| 291 | goto next_token; |
| 292 | } |
anthony | a3ef4ed | 2012-03-17 06:52:53 +0000 | [diff] [blame] | 293 | |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 294 | if ( (option_type & SpecialOptionFlag) != 0 ) { |
anthony | 8226e72 | 2012-04-05 14:25:46 +0000 | [diff] [blame] | 295 | if ( LocaleCompare(option,"-exit") == 0 ) { |
| 296 | break; /* forced end of script */ |
| 297 | } |
anthony | 756cd0d | 2012-04-08 12:41:44 +0000 | [diff] [blame] | 298 | else if ( LocaleCompare(option,"-script") == 0 ) { |
| 299 | /* FUTURE: call new script from this script */ |
anthony | 8226e72 | 2012-04-05 14:25:46 +0000 | [diff] [blame] | 300 | CLIWandExceptionBreak(OptionError,"InvalidUseOfOption",option); |
| 301 | goto next_token; |
| 302 | } |
anthony | b1d483a | 2012-04-14 12:53:56 +0000 | [diff] [blame] | 303 | /* FUTURE: handle special script-argument options here */ |
anthony | 8226e72 | 2012-04-05 14:25:46 +0000 | [diff] [blame] | 304 | /* handle any other special operators now */ |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 305 | CLISpecialOperator(cli_wand,option,arg1); |
| 306 | } |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 307 | |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 308 | if ( (option_type & SettingOptionFlags) != 0 ) { |
anthony | e5fcd36 | 2012-04-09 04:02:09 +0000 | [diff] [blame] | 309 | CLISettingOptionInfo(cli_wand, option, arg1, arg2); |
anthony | 24aa882 | 2012-03-11 00:56:06 +0000 | [diff] [blame] | 310 | // FUTURE: Sync Specific Settings into Image Properities (not global) |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 311 | } |
anthony | b1d483a | 2012-04-14 12:53:56 +0000 | [diff] [blame] | 312 | |
| 313 | /* FUTURE: The not a setting part below is a temporary hack to stop gap |
| 314 | * measure for options that are BOTH settings and optional 'Simple/List' |
anthony | df32372 | 2012-04-16 01:17:38 +0000 | [diff] [blame] | 315 | * operators. Specifically -monitor, -depth, and -colorspace */ |
anthony | b1d483a | 2012-04-14 12:53:56 +0000 | [diff] [blame] | 316 | if ( cli_wand->wand.images == (Image *)NULL ) { |
| 317 | if (((option_type & ImageRequiredFlags) != 0 ) && |
| 318 | ((option_type & SettingOptionFlags) == 0 )) /* temp hack */ |
| 319 | CLIWandException(OptionError,"NoImagesFound",option); |
| 320 | goto next_token; |
| 321 | } |
| 322 | |
| 323 | /* FUTURE: this is temporary - get 'settings' to handle |
| 324 | distribution of settings to images attributes,proprieties,artifacts */ |
| 325 | SyncImagesSettings(cli_wand->wand.image_info,cli_wand->wand.images, |
| 326 | cli_wand->wand.exception); |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 327 | |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 328 | if ( (option_type & SimpleOperatorOptionFlag) != 0) |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 329 | CLISimpleOperatorImages(cli_wand, option, arg1, arg2); |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 330 | |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 331 | if ( (option_type & ListOperatorOptionFlag) != 0 ) |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 332 | CLIListOperatorImages(cli_wand, option, arg1, arg2); |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 333 | |
anthony | 24aa882 | 2012-03-11 00:56:06 +0000 | [diff] [blame] | 334 | next_token: |
anthony | f125a5e | 2012-04-03 13:14:42 +0000 | [diff] [blame] | 335 | #if MagickCommandDebug >= 9 |
anthony | 24aa882 | 2012-03-11 00:56:06 +0000 | [diff] [blame] | 336 | OutputOptions(cli_wand->wand.image_info); |
anthony | f125a5e | 2012-04-03 13:14:42 +0000 | [diff] [blame] | 337 | if ( cli_wand->wand.images != (Image *)NULL ) { |
anthony | 24aa882 | 2012-03-11 00:56:06 +0000 | [diff] [blame] | 338 | OutputArtifacts(cli_wand->wand.images); |
anthony | f125a5e | 2012-04-03 13:14:42 +0000 | [diff] [blame] | 339 | OutputProperties(cli_wand->wand.images,cli_wand->wand.exception); |
| 340 | } |
anthony | 24aa882 | 2012-03-11 00:56:06 +0000 | [diff] [blame] | 341 | #endif |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 342 | if ( CLICatchException(cli_wand, MagickFalse) != MagickFalse ) |
| 343 | break; |
| 344 | } |
| 345 | |
anthony | f125a5e | 2012-04-03 13:14:42 +0000 | [diff] [blame] | 346 | #if MagickCommandDebug >= 3 |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 347 | (void) FormatLocaleFile(stderr, "Script End: %d\n", token_info->status); |
| 348 | #endif |
| 349 | switch( token_info->status ) { |
| 350 | case TokenStatusOK: |
| 351 | case TokenStatusEOF: |
anthony | 8226e72 | 2012-04-05 14:25:46 +0000 | [diff] [blame] | 352 | if (cli_wand->image_list_stack != (Stack *)NULL) |
| 353 | CLIWandException(OptionError,"UnbalancedParenthesis", "(eof)"); |
| 354 | else if (cli_wand->image_info_stack != (Stack *)NULL) |
| 355 | CLIWandException(OptionError,"UnbalancedBraces", "(eof)"); |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 356 | break; |
| 357 | case TokenStatusBadQuotes: |
| 358 | /* Ensure last token has a sane length for error report */ |
| 359 | if( strlen(token_info->token) > INITAL_TOKEN_LENGTH-1 ) { |
| 360 | token_info->token[INITAL_TOKEN_LENGTH-4] = '.'; |
| 361 | token_info->token[INITAL_TOKEN_LENGTH-3] = '.'; |
| 362 | token_info->token[INITAL_TOKEN_LENGTH-2] = '.'; |
| 363 | token_info->token[INITAL_TOKEN_LENGTH-1] = '\0'; |
| 364 | } |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 365 | CLIWandException(OptionFatalError,"ScriptUnbalancedQuotes", |
| 366 | token_info->token); |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 367 | break; |
| 368 | case TokenStatusMemoryFailed: |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 369 | CLIWandException(OptionFatalError,"ScriptTokenMemoryFailed",""); |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 370 | break; |
| 371 | case TokenStatusBinary: |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 372 | CLIWandException(OptionFatalError,"ScriptIsBinary",""); |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 373 | break; |
| 374 | } |
| 375 | |
| 376 | /* Clean up */ |
| 377 | token_info = DestroyScriptTokenInfo(token_info); |
| 378 | |
| 379 | CloneString(&option,(char *)NULL); |
| 380 | CloneString(&arg1,(char *)NULL); |
| 381 | CloneString(&arg2,(char *)NULL); |
| 382 | |
| 383 | return; |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | /* |
| 387 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 388 | % % |
| 389 | % % |
| 390 | % % |
| 391 | + P r o c e s s C o m m a n d O p t i o n s % |
| 392 | % % |
| 393 | % % |
| 394 | % % |
| 395 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 396 | % |
| 397 | % ProcessCommandOptions() reads and processes arguments in the given |
| 398 | % command line argument array. The array does not contain the command |
| 399 | % being processed, only the options. |
| 400 | % |
| 401 | % The 'process_flags' can be used to control and limit option processing. |
| 402 | % For example, to only process one option, or how unknown and special options |
| 403 | % are to be handled, and if the last argument in array is to be regarded as a |
| 404 | % final image write argument (filename or special coder). |
| 405 | % |
| 406 | % The format of the ProcessCommandOptions method is: |
| 407 | % |
anthony | 43f425d | 2012-02-26 12:58:58 +0000 | [diff] [blame] | 408 | % int ProcessCommandOptions(MagickCLI *cli_wand,int argc,char **argv, |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 409 | % int index, ProcessOptionFlags process_flags ) |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 410 | % |
| 411 | % A description of each parameter follows: |
| 412 | % |
anthony | 43f425d | 2012-02-26 12:58:58 +0000 | [diff] [blame] | 413 | % o cli_wand: the main CLI Wand to use. |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 414 | % |
| 415 | % o argc: the number of elements in the argument vector. |
| 416 | % |
| 417 | % o argv: A text array containing the command line arguments. |
| 418 | % |
anthony | 0ea037a | 2012-04-03 12:14:39 +0000 | [diff] [blame] | 419 | % o process_flags: What type of arguments will be processed, ignored |
| 420 | % or return errors. |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 421 | % |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 422 | % o index: index in the argv array to start processing from |
| 423 | % |
| 424 | % The function returns the index ot the next option to be processed. This |
| 425 | % is really only releven if process_flags contains a ProcessOneOptionOnly |
| 426 | % flag. |
| 427 | % |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 428 | */ |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 429 | WandExport int ProcessCommandOptions(MagickCLI *cli_wand, int argc, |
anthony | 5216f82 | 2012-04-10 13:02:37 +0000 | [diff] [blame] | 430 | char **argv, int index ) |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 431 | { |
| 432 | const char |
| 433 | *option, |
| 434 | *arg1, |
| 435 | *arg2; |
| 436 | |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 437 | int |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 438 | i, |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 439 | end, |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 440 | count; |
| 441 | |
| 442 | CommandOptionFlags |
anthony | 686b1a3 | 2012-02-15 14:50:53 +0000 | [diff] [blame] | 443 | option_type; |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 444 | |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 445 | assert(argc>=index); /* you may have no arguments left! */ |
| 446 | assert(argv != (char **)NULL); |
| 447 | assert(argv[index] != (char *)NULL); |
| 448 | assert(argv[argc-1] != (char *)NULL); |
anthony | 43f425d | 2012-02-26 12:58:58 +0000 | [diff] [blame] | 449 | assert(cli_wand != (MagickCLI *) NULL); |
| 450 | assert(cli_wand->signature == WandSignature); |
| 451 | if (cli_wand->wand.debug != MagickFalse) |
| 452 | (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",cli_wand->wand.name); |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 453 | |
anthony | 92c93bd | 2012-03-19 14:02:47 +0000 | [diff] [blame] | 454 | /* define the error location string for use in exceptions |
anthony | 5216f82 | 2012-04-10 13:02:37 +0000 | [diff] [blame] | 455 | order of localtion format escapes: filename, line, column */ |
| 456 | cli_wand->location="at %s argument %u"; |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 457 | cli_wand->filename="CLI"; |
| 458 | |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 459 | end = argc; |
anthony | 5216f82 | 2012-04-10 13:02:37 +0000 | [diff] [blame] | 460 | if ( (cli_wand->process_flags & ProcessImpliedWrite) != 0 ) |
| 461 | end--; /* the last arument is an implied write, do not process directly */ |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 462 | |
| 463 | for (i=index; i < end; i += count +1) { |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 464 | /* Finished processing one option? */ |
anthony | 5216f82 | 2012-04-10 13:02:37 +0000 | [diff] [blame] | 465 | if ( (cli_wand->process_flags & ProcessOneOptionOnly) != 0 && i != index ) |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 466 | return(i); |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 467 | |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 468 | option=argv[i]; |
anthony | 5216f82 | 2012-04-10 13:02:37 +0000 | [diff] [blame] | 469 | cli_wand->line=i; /* note the argument for this option */ |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 470 | |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 471 | { const OptionInfo *option_info = GetCommandOptionInfo(argv[i]); |
| 472 | count=option_info->type; |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 473 | option_type=(CommandOptionFlags) option_info->flags; |
anthony | f125a5e | 2012-04-03 13:14:42 +0000 | [diff] [blame] | 474 | #if 0 |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 475 | (void) FormatLocaleFile(stderr, "CLI %d: \"%s\" matched \"%s\"\n", |
| 476 | i, argv[i], option_info->mnemonic ); |
anthony | 686b1a3 | 2012-02-15 14:50:53 +0000 | [diff] [blame] | 477 | #endif |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 478 | } |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 479 | |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 480 | if ( option_type == UndefinedOptionFlag || |
| 481 | (option_type & NonMagickOptionFlag) != 0 ) { |
anthony | f125a5e | 2012-04-03 13:14:42 +0000 | [diff] [blame] | 482 | #if MagickCommandDebug >= 3 |
| 483 | (void) FormatLocaleFile(stderr, "CLI %d Non-Option: \"%s\"\n", i, option); |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 484 | #endif |
anthony | 756cd0d | 2012-04-08 12:41:44 +0000 | [diff] [blame] | 485 | if ( IfMagickFalse(IsCommandOption(option)) ) { |
anthony | 5216f82 | 2012-04-10 13:02:37 +0000 | [diff] [blame] | 486 | if ( (cli_wand->process_flags & ProcessNonOptionImageRead) != 0 ) |
anthony | 756cd0d | 2012-04-08 12:41:44 +0000 | [diff] [blame] | 487 | /* non-option -- treat as a image read */ |
| 488 | CLISpecialOperator(cli_wand,"-read",option); |
| 489 | else |
| 490 | CLIWandException(OptionFatalError,"UnrecognizedOption",option); |
| 491 | goto next_argument; |
| 492 | } |
anthony | 5216f82 | 2012-04-10 13:02:37 +0000 | [diff] [blame] | 493 | if ( ((cli_wand->process_flags & ProcessScriptOption) != 0) && |
anthony | 756cd0d | 2012-04-08 12:41:44 +0000 | [diff] [blame] | 494 | (LocaleCompare(option,"-script") == 0) ) { |
| 495 | /* Call Script from CLI, with a filename as a zeroth argument. |
| 496 | NOTE: -script may need to use 'implict write filename' so it |
| 497 | must be handled here to prevent 'missing argument' error. |
| 498 | */ |
| 499 | ProcessScriptOptions(cli_wand,argc,argv,i+1); |
| 500 | return(argc); /* Script does not return to CLI -- Yet -- FUTURE */ |
| 501 | } |
| 502 | CLIWandException(OptionFatalError,"UnrecognizedOption",option); |
anthony | 24aa882 | 2012-03-11 00:56:06 +0000 | [diff] [blame] | 503 | goto next_argument; |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 504 | } |
| 505 | |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 506 | if ((i+count) >= end ) { |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 507 | CLIWandException(OptionFatalError,"MissingArgument",option); |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 508 | if ( CLICatchException(cli_wand, MagickFalse) != MagickFalse ) |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 509 | return(end); |
anthony | 24aa882 | 2012-03-11 00:56:06 +0000 | [diff] [blame] | 510 | goto next_argument; /* no more arguments unable to proceed */ |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | arg1 = ( count >= 1 ) ? argv[i+1] : (char *)NULL; |
| 514 | arg2 = ( count >= 2 ) ? argv[i+2] : (char *)NULL; |
| 515 | |
anthony | b1d483a | 2012-04-14 12:53:56 +0000 | [diff] [blame] | 516 | /* |
| 517 | Process Known Options |
| 518 | */ |
anthony | f125a5e | 2012-04-03 13:14:42 +0000 | [diff] [blame] | 519 | #if MagickCommandDebug >= 3 |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 520 | (void) FormatLocaleFile(stderr, |
anthony | f125a5e | 2012-04-03 13:14:42 +0000 | [diff] [blame] | 521 | "CLI %u Option: \"%s\" Count: %d Flags: %04x Args: \"%s\" \"%s\"\n", |
| 522 | i,option,count,option_type,arg1,arg2); |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 523 | #endif |
anthony | b1d483a | 2012-04-14 12:53:56 +0000 | [diff] [blame] | 524 | /* Hard Depreciated Options, no code to execute - error */ |
anthony | 8226e72 | 2012-04-05 14:25:46 +0000 | [diff] [blame] | 525 | if ( (option_type & DeprecateOptionFlag) != 0 ) { |
anthony | 975a8d7 | 2012-04-12 13:54:36 +0000 | [diff] [blame] | 526 | CLIWandException(OptionError,"DeprecatedOptionNoCode",option); |
| 527 | goto next_argument; |
anthony | 8226e72 | 2012-04-05 14:25:46 +0000 | [diff] [blame] | 528 | } |
anthony | b1d483a | 2012-04-14 12:53:56 +0000 | [diff] [blame] | 529 | |
| 530 | /* Ignore MagickCommandGenesis() only option on CLI */ |
| 531 | if ( (option_type & GenesisOptionFlag) != 0 ) |
anthony | 8226e72 | 2012-04-05 14:25:46 +0000 | [diff] [blame] | 532 | goto next_argument; |
anthony | 8226e72 | 2012-04-05 14:25:46 +0000 | [diff] [blame] | 533 | |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 534 | if ( (option_type & SpecialOptionFlag) != 0 ) { |
anthony | 5216f82 | 2012-04-10 13:02:37 +0000 | [diff] [blame] | 535 | if ( (cli_wand->process_flags & ProcessExitOption) != 0 |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 536 | && LocaleCompare(option,"-exit") == 0 ) |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 537 | return(i+count); |
anthony | 8226e72 | 2012-04-05 14:25:46 +0000 | [diff] [blame] | 538 | /* handle any other special operators now */ |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 539 | CLISpecialOperator(cli_wand,option,arg1); |
| 540 | } |
| 541 | |
| 542 | if ( (option_type & SettingOptionFlags) != 0 ) { |
anthony | e5fcd36 | 2012-04-09 04:02:09 +0000 | [diff] [blame] | 543 | CLISettingOptionInfo(cli_wand, option, arg1, arg2); |
anthony | 756cd0d | 2012-04-08 12:41:44 +0000 | [diff] [blame] | 544 | // FUTURE: Sync individual Settings into images (no SyncImageSettings()) |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 545 | } |
anthony | b1d483a | 2012-04-14 12:53:56 +0000 | [diff] [blame] | 546 | |
| 547 | /* FUTURE: The not a setting part below is a temporary hack to stop gap |
| 548 | * measure for options that are BOTH settings and optional 'Simple/List' |
anthony | df32372 | 2012-04-16 01:17:38 +0000 | [diff] [blame] | 549 | * operators. Specifically -monitor, -depth, and -colorspace */ |
anthony | b1d483a | 2012-04-14 12:53:56 +0000 | [diff] [blame] | 550 | if ( cli_wand->wand.images == (Image *)NULL ) { |
| 551 | if (((option_type & ImageRequiredFlags) != 0 ) && |
| 552 | ((option_type & SettingOptionFlags) == 0 ) ) /* temp hack */ |
| 553 | CLIWandException(OptionError,"NoImagesFound",option); |
| 554 | goto next_argument; |
| 555 | } |
| 556 | |
| 557 | /* FUTURE: this is temporary - get 'settings' to handle |
| 558 | distribution of settings to images attributes,proprieties,artifacts */ |
| 559 | SyncImagesSettings(cli_wand->wand.image_info,cli_wand->wand.images, |
anthony | eff71f5 | 2012-03-29 12:59:09 +0000 | [diff] [blame] | 560 | cli_wand->wand.exception); |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 561 | |
| 562 | if ( (option_type & SimpleOperatorOptionFlag) != 0) |
| 563 | CLISimpleOperatorImages(cli_wand, option, arg1, arg2); |
| 564 | |
| 565 | if ( (option_type & ListOperatorOptionFlag) != 0 ) |
| 566 | CLIListOperatorImages(cli_wand, option, arg1, arg2); |
| 567 | |
anthony | 24aa882 | 2012-03-11 00:56:06 +0000 | [diff] [blame] | 568 | next_argument: |
anthony | f125a5e | 2012-04-03 13:14:42 +0000 | [diff] [blame] | 569 | #if MagickCommandDebug >= 9 |
anthony | 24aa882 | 2012-03-11 00:56:06 +0000 | [diff] [blame] | 570 | OutputOptions(cli_wand->wand.image_info); |
anthony | f125a5e | 2012-04-03 13:14:42 +0000 | [diff] [blame] | 571 | if ( cli_wand->wand.images != (Image *)NULL ) { |
anthony | 24aa882 | 2012-03-11 00:56:06 +0000 | [diff] [blame] | 572 | OutputArtifacts(cli_wand->wand.images); |
anthony | f125a5e | 2012-04-03 13:14:42 +0000 | [diff] [blame] | 573 | OutputProperties(cli_wand->wand.images,cli_wand->wand.exception); |
| 574 | } |
anthony | 24aa882 | 2012-03-11 00:56:06 +0000 | [diff] [blame] | 575 | #endif |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 576 | if ( CLICatchException(cli_wand, MagickFalse) != MagickFalse ) |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 577 | return(i+count); |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 578 | } |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 579 | assert(i==end); |
anthony | 2052d27 | 2012-02-28 12:48:29 +0000 | [diff] [blame] | 580 | |
anthony | 5216f82 | 2012-04-10 13:02:37 +0000 | [diff] [blame] | 581 | if ( (cli_wand->process_flags & ProcessImpliedWrite) == 0 ) |
| 582 | return(end); /* no implied write -- just return to caller */ |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 583 | |
anthony | 5216f82 | 2012-04-10 13:02:37 +0000 | [diff] [blame] | 584 | assert(end==argc-1); /* end should not include last argument */ |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 585 | |
| 586 | /* |
anthony | 43f425d | 2012-02-26 12:58:58 +0000 | [diff] [blame] | 587 | Implicit Write of images to final CLI argument |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 588 | */ |
| 589 | option=argv[i]; |
anthony | 799889a | 2012-03-11 11:00:32 +0000 | [diff] [blame] | 590 | cli_wand->line=i; |
anthony | 686b1a3 | 2012-02-15 14:50:53 +0000 | [diff] [blame] | 591 | |
anthony | f125a5e | 2012-04-03 13:14:42 +0000 | [diff] [blame] | 592 | #if MagickCommandDebug >= 3 |
| 593 | (void) FormatLocaleFile(stderr, "CLI %d Write File: \"%s\"\n", i, option ); |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 594 | #endif |
| 595 | |
anthony | 8226e72 | 2012-04-05 14:25:46 +0000 | [diff] [blame] | 596 | /* check that stacks are empty */ |
| 597 | if (cli_wand->image_list_stack != (Stack *)NULL) |
| 598 | CLIWandException(OptionError,"UnbalancedParenthesis", "(eof)"); |
| 599 | else if (cli_wand->image_info_stack != (Stack *)NULL) |
| 600 | CLIWandException(OptionError,"UnbalancedBraces", "(eof)"); |
| 601 | if ( CLICatchException(cli_wand, MagickFalse) != MagickFalse ) |
| 602 | return(argc); |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 603 | |
anthony | 8226e72 | 2012-04-05 14:25:46 +0000 | [diff] [blame] | 604 | /* This is a valid 'do no write' option - no images needed */ |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 605 | if (LocaleCompare(option,"-exit") == 0 ) |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 606 | return(argc); /* just exit, no image write */ |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 607 | |
anthony | 8226e72 | 2012-04-05 14:25:46 +0000 | [diff] [blame] | 608 | /* If filename looks like an option -- produce an error */ |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 609 | if (IsCommandOption(option) != MagickFalse) { |
| 610 | CLIWandException(OptionError,"MissingOutputFilename",option); |
| 611 | return(argc); |
| 612 | } |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 613 | |
anthony | 8226e72 | 2012-04-05 14:25:46 +0000 | [diff] [blame] | 614 | CLISpecialOperator(cli_wand,"-write",option); |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 615 | return(argc); |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | /* |
| 619 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 620 | % % |
| 621 | % % |
| 622 | % % |
| 623 | + M a g i c k I m a g e C o m m a n d % |
| 624 | % % |
| 625 | % % |
| 626 | % % |
| 627 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 628 | % |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 629 | % MagickImageCommand() Handle special use CLI arguments and prepare a |
anthony | 43f425d | 2012-02-26 12:58:58 +0000 | [diff] [blame] | 630 | % CLI MagickCLI to process the command line or directly specified script. |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 631 | % |
| 632 | % This is essentualy interface function between the MagickCore library |
anthony | 43f425d | 2012-02-26 12:58:58 +0000 | [diff] [blame] | 633 | % initialization function MagickCommandGenesis(), and the option MagickCLI |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 634 | % processing functions ProcessCommandOptions() or ProcessScriptOptions() |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 635 | % |
| 636 | % The format of the MagickImageCommand method is: |
| 637 | % |
| 638 | % MagickBooleanType MagickImageCommand(ImageInfo *image_info, |
| 639 | % int argc, char **argv, char **metadata, ExceptionInfo *exception) |
| 640 | % |
| 641 | % A description of each parameter follows: |
| 642 | % |
| 643 | % o image_info: the starting image_info structure |
| 644 | % (for compatibilty with MagickCommandGenisis()) |
| 645 | % |
| 646 | % o argc: the number of elements in the argument vector. |
| 647 | % |
| 648 | % o argv: A text array containing the command line arguments. |
| 649 | % |
anthony | 0ea037a | 2012-04-03 12:14:39 +0000 | [diff] [blame] | 650 | % o metadata: any metadata (for VBS) is returned here. |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 651 | % (for compatibilty with MagickCommandGenisis()) |
| 652 | % |
| 653 | % o exception: return any errors or warnings in this structure. |
| 654 | % |
| 655 | */ |
| 656 | |
anthony | 40b6015 | 2012-04-04 06:13:37 +0000 | [diff] [blame] | 657 | static void MagickUsage(MagickBooleanType verbose) |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 658 | { |
anthony | e5fcd36 | 2012-04-09 04:02:09 +0000 | [diff] [blame] | 659 | const char |
| 660 | *name; |
| 661 | |
| 662 | size_t |
| 663 | len; |
| 664 | |
| 665 | name=GetClientName(); |
| 666 | len=strlen(name); |
| 667 | |
anthony | d22bf40 | 2012-04-10 01:32:03 +0000 | [diff] [blame] | 668 | if (len>=7 && LocaleCompare("convert",name+len-7) == 0) { |
anthony | e5fcd36 | 2012-04-09 04:02:09 +0000 | [diff] [blame] | 669 | /* convert usage */ |
| 670 | (void) FormatLocaleFile(stdout, |
| 671 | "Usage: %s [{option}|{image}...] {output_image}\n",name); |
| 672 | (void) FormatLocaleFile(stdout, |
anthony | d22bf40 | 2012-04-10 01:32:03 +0000 | [diff] [blame] | 673 | " %s -help|-version|-usage|-list {option}\n\n",name); |
| 674 | return; |
| 675 | } |
| 676 | else if (len>=6 && LocaleCompare("script",name+len-6) == 0) { |
| 677 | /* magick-script usage */ |
| 678 | (void) FormatLocaleFile(stdout, |
| 679 | "Usage: %s {filename} [{script_args}...]\n",name); |
anthony | e5fcd36 | 2012-04-09 04:02:09 +0000 | [diff] [blame] | 680 | } |
| 681 | else { |
| 682 | /* magick usage */ |
| 683 | (void) FormatLocaleFile(stdout, |
| 684 | "Usage: %s [{option}|{image}...] {output_image}\n",name); |
| 685 | (void) FormatLocaleFile(stdout, |
anthony | 40b6015 | 2012-04-04 06:13:37 +0000 | [diff] [blame] | 686 | " %s [{option}|{image}...] -script {filename} [{script_args}...]\n", |
anthony | e5fcd36 | 2012-04-09 04:02:09 +0000 | [diff] [blame] | 687 | name); |
anthony | e5fcd36 | 2012-04-09 04:02:09 +0000 | [diff] [blame] | 688 | } |
anthony | d22bf40 | 2012-04-10 01:32:03 +0000 | [diff] [blame] | 689 | (void) FormatLocaleFile(stdout, |
| 690 | " %s -help|-version|-usage|-list {option}\n\n",name); |
anthony | 40b6015 | 2012-04-04 06:13:37 +0000 | [diff] [blame] | 691 | |
| 692 | if (IfMagickFalse(verbose)) |
| 693 | return; |
| 694 | |
anthony | d22bf40 | 2012-04-10 01:32:03 +0000 | [diff] [blame] | 695 | (void) FormatLocaleFile(stdout,"%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", |
anthony | 40b6015 | 2012-04-04 06:13:37 +0000 | [diff] [blame] | 696 | "All options are performed in a strict 'as you see them' order\n", |
| 697 | "You must read-in images before you can operate on them.\n", |
| 698 | "\n", |
| 699 | "Magick Script files can use any of the following forms...\n", |
| 700 | " #!/path/to/magick -script\n", |
| 701 | "or\n", |
| 702 | " #!/bin/sh\n", |
| 703 | " :; exec magick -script \"$0\" \"$@\"; exit 10\n", |
| 704 | " # Magick script from here...\n", |
| 705 | "or\n", |
| 706 | " #!/usr/bin/env magick-script\n", |
| 707 | "The latter two forms do not require the path to the command hard coded.\n", |
| 708 | "Note: \"magick-script\" needs to be linked to the \"magick\" command.\n", |
| 709 | "\n", |
| 710 | "For more information on usage, options, examples, and techniques\n", |
| 711 | "see the ImageMagick website at ", MagickAuthoritativeURL); |
| 712 | |
| 713 | return; |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | /* |
| 717 | Concatanate given file arguments to the given output argument. |
| 718 | Used for a special -concatenate option used for specific 'delegates'. |
| 719 | The option is not formally documented. |
| 720 | |
| 721 | magick -concatenate files... output |
| 722 | |
| 723 | This is much like the UNIX "cat" command, but for both UNIX and Windows, |
| 724 | however the last argument provides the output filename. |
| 725 | */ |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 726 | static MagickBooleanType ConcatenateImages(int argc,char **argv, |
anthony | 5216f82 | 2012-04-10 13:02:37 +0000 | [diff] [blame] | 727 | ExceptionInfo *exception ) |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 728 | { |
| 729 | FILE |
| 730 | *input, |
| 731 | *output; |
| 732 | |
| 733 | int |
| 734 | c; |
| 735 | |
| 736 | register ssize_t |
| 737 | i; |
| 738 | |
| 739 | output=fopen_utf8(argv[argc-1],"wb"); |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 740 | if (output == (FILE *) NULL) { |
anthony | 5216f82 | 2012-04-10 13:02:37 +0000 | [diff] [blame] | 741 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile",argv[argc-1]); |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 742 | return(MagickFalse); |
| 743 | } |
| 744 | for (i=2; i < (ssize_t) (argc-1); i++) { |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 745 | input=fopen_utf8(argv[i],"rb"); |
| 746 | if (input == (FILE *) NULL) |
| 747 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile",argv[i]); |
| 748 | for (c=fgetc(input); c != EOF; c=fgetc(input)) |
| 749 | (void) fputc((char) c,output); |
| 750 | (void) fclose(input); |
| 751 | (void) remove_utf8(argv[i]); |
| 752 | } |
| 753 | (void) fclose(output); |
| 754 | return(MagickTrue); |
| 755 | } |
| 756 | |
| 757 | WandExport MagickBooleanType MagickImageCommand(ImageInfo *image_info, |
| 758 | int argc,char **argv,char **metadata,ExceptionInfo *exception) |
| 759 | { |
anthony | 43f425d | 2012-02-26 12:58:58 +0000 | [diff] [blame] | 760 | MagickCLI |
| 761 | *cli_wand; |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 762 | |
anthony | e5fcd36 | 2012-04-09 04:02:09 +0000 | [diff] [blame] | 763 | size_t |
| 764 | len; |
| 765 | |
anthony | 4cb3726 | 2012-03-18 11:18:45 +0000 | [diff] [blame] | 766 | /* For specific OS command line requirements */ |
| 767 | ReadCommandlLine(argc,&argv); |
| 768 | |
| 769 | #if 0 |
anthony | 4cb3726 | 2012-03-18 11:18:45 +0000 | [diff] [blame] | 770 | status=ExpandFilenames(&argc,&argv); |
anthony | 0ea037a | 2012-04-03 12:14:39 +0000 | [diff] [blame] | 771 | if ( IfMagickFalse(status) ) |
anthony | 4cb3726 | 2012-03-18 11:18:45 +0000 | [diff] [blame] | 772 | ThrowConvertException(ResourceLimitError,"MemoryAllocationFailed", |
| 773 | GetExceptionMessage(errno)); |
| 774 | #endif |
anthony | eff71f5 | 2012-03-29 12:59:09 +0000 | [diff] [blame] | 775 | |
anthony | 668f43a | 2012-02-20 14:55:32 +0000 | [diff] [blame] | 776 | /* Initialize special "CLI Wand" to hold images and settings (empty) */ |
anthony | 43f425d | 2012-02-26 12:58:58 +0000 | [diff] [blame] | 777 | cli_wand=AcquireMagickCLI(image_info,exception); |
anthony | 8226e72 | 2012-04-05 14:25:46 +0000 | [diff] [blame] | 778 | cli_wand->line=1; |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 779 | |
anthony | eff71f5 | 2012-03-29 12:59:09 +0000 | [diff] [blame] | 780 | GetPathComponent(argv[0],TailPath,cli_wand->wand.name); |
anthony | e5fcd36 | 2012-04-09 04:02:09 +0000 | [diff] [blame] | 781 | SetClientName(cli_wand->wand.name); |
anthony | eff71f5 | 2012-03-29 12:59:09 +0000 | [diff] [blame] | 782 | ConcatenateMagickString(cli_wand->wand.name,"-CLI",MaxTextExtent); |
| 783 | |
anthony | e5fcd36 | 2012-04-09 04:02:09 +0000 | [diff] [blame] | 784 | len=strlen(argv[0]); /* precaution */ |
| 785 | |
anthony | eff71f5 | 2012-03-29 12:59:09 +0000 | [diff] [blame] | 786 | /* "convert" command - give a "depreciation" warning" */ |
anthony | e5fcd36 | 2012-04-09 04:02:09 +0000 | [diff] [blame] | 787 | if (len>=7 && LocaleCompare("convert",argv[0]+len-7) == 0) { |
anthony | 5216f82 | 2012-04-10 13:02:37 +0000 | [diff] [blame] | 788 | cli_wand->process_flags = ConvertCommandOptionFlags; |
anthony | 0ea037a | 2012-04-03 12:14:39 +0000 | [diff] [blame] | 789 | /*(void) FormatLocaleFile(stderr,"WARNING: %s\n", |
| 790 | "The convert is depreciated in IMv7, use \"magick\"\n");*/ |
anthony | eff71f5 | 2012-03-29 12:59:09 +0000 | [diff] [blame] | 791 | } |
anthony | eff71f5 | 2012-03-29 12:59:09 +0000 | [diff] [blame] | 792 | |
anthony | 8226e72 | 2012-04-05 14:25:46 +0000 | [diff] [blame] | 793 | /* Special Case: If command name ends with "script" implied "-script" */ |
anthony | e5fcd36 | 2012-04-09 04:02:09 +0000 | [diff] [blame] | 794 | if (len>=6 && LocaleCompare("script",argv[0]+len-6) == 0) { |
anthony | d22bf40 | 2012-04-10 01:32:03 +0000 | [diff] [blame] | 795 | if (argc >= 2 && ( (*(argv[1]) != '-') || (strlen(argv[1]) == 1) )) { |
anthony | e5fcd36 | 2012-04-09 04:02:09 +0000 | [diff] [blame] | 796 | GetPathComponent(argv[1],TailPath,cli_wand->wand.name); |
| 797 | ProcessScriptOptions(cli_wand,argc,argv,1); |
| 798 | goto Magick_Command_Cleanup; |
| 799 | } |
anthony | 52bef75 | 2012-03-27 13:54:47 +0000 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | /* Special Case: Version Information and Abort */ |
| 803 | if (argc == 2) { |
anthony | 5216f82 | 2012-04-10 13:02:37 +0000 | [diff] [blame] | 804 | if (LocaleCompare("-version",argv[1]) == 0) { |
anthony | 52bef75 | 2012-03-27 13:54:47 +0000 | [diff] [blame] | 805 | CLISpecialOperator(cli_wand, "-version", (char *)NULL); |
| 806 | goto Magick_Command_Exit; |
| 807 | } |
anthony | 5216f82 | 2012-04-10 13:02:37 +0000 | [diff] [blame] | 808 | if ((LocaleCompare("-help",argv[1]) == 0) || /* GNU standard option */ |
| 809 | (LocaleCompare("--help",argv[1]) == 0) ) { |
anthony | 40b6015 | 2012-04-04 06:13:37 +0000 | [diff] [blame] | 810 | MagickUsage(MagickFalse); |
| 811 | goto Magick_Command_Exit; |
| 812 | } |
anthony | 5216f82 | 2012-04-10 13:02:37 +0000 | [diff] [blame] | 813 | if (LocaleCompare("-usage",argv[1]) == 0) { |
anthony | 40b6015 | 2012-04-04 06:13:37 +0000 | [diff] [blame] | 814 | CLISpecialOperator(cli_wand, "-version", (char *)NULL); |
| 815 | MagickUsage(MagickTrue); |
| 816 | goto Magick_Command_Exit; |
| 817 | } |
anthony | 52bef75 | 2012-03-27 13:54:47 +0000 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | /* not enough arguments -- including -help */ |
| 821 | if (argc < 3) { |
anthony | 40b6015 | 2012-04-04 06:13:37 +0000 | [diff] [blame] | 822 | (void) FormatLocaleFile(stderr, |
| 823 | "Error: Invalid argument or not enough arguments\n\n"); |
| 824 | MagickUsage(MagickFalse); |
anthony | 52bef75 | 2012-03-27 13:54:47 +0000 | [diff] [blame] | 825 | goto Magick_Command_Exit; |
| 826 | } |
| 827 | |
anthony | 52bef75 | 2012-03-27 13:54:47 +0000 | [diff] [blame] | 828 | /* List Information and Abort */ |
| 829 | if (LocaleCompare("-list",argv[1]) == 0) { |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 830 | CLISpecialOperator(cli_wand, argv[1], argv[2]); |
anthony | 52bef75 | 2012-03-27 13:54:47 +0000 | [diff] [blame] | 831 | goto Magick_Command_Exit; |
| 832 | } |
| 833 | |
anthony | 0ea037a | 2012-04-03 12:14:39 +0000 | [diff] [blame] | 834 | /* Special "concatenate option (hidden) for delegate usage */ |
| 835 | if (LocaleCompare("-concatenate",argv[1]) == 0) { |
| 836 | ConcatenateImages(argc,argv,exception); |
| 837 | goto Magick_Command_Exit; |
| 838 | } |
| 839 | |
anthony | 52bef75 | 2012-03-27 13:54:47 +0000 | [diff] [blame] | 840 | /* ------------- */ |
| 841 | /* The Main Call */ |
| 842 | |
| 843 | if (LocaleCompare("-script",argv[1]) == 0) { |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 844 | /* Start processing directly from script, no pre-script options |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 845 | Replace wand command name with script name |
| 846 | First argument in the argv array is the script name to read. |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 847 | */ |
| 848 | GetPathComponent(argv[2],TailPath,cli_wand->wand.name); |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 849 | ProcessScriptOptions(cli_wand,argc,argv,2); |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 850 | } |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 851 | else { |
anthony | 52bef75 | 2012-03-27 13:54:47 +0000 | [diff] [blame] | 852 | /* Normal Command Line, assumes output file as last option */ |
anthony | 5216f82 | 2012-04-10 13:02:37 +0000 | [diff] [blame] | 853 | ProcessCommandOptions(cli_wand,argc,argv,1); |
anthony | 0b46ebe | 2012-03-06 04:15:35 +0000 | [diff] [blame] | 854 | } |
anthony | 52bef75 | 2012-03-27 13:54:47 +0000 | [diff] [blame] | 855 | /* ------------- */ |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 856 | |
anthony | 4cb3726 | 2012-03-18 11:18:45 +0000 | [diff] [blame] | 857 | Magick_Command_Cleanup: |
anthony | 5216f82 | 2012-04-10 13:02:37 +0000 | [diff] [blame] | 858 | /* recover original image_info and clean up stacks |
| 859 | FUTURE: "-reset stacks" option */ |
anthony | 8226e72 | 2012-04-05 14:25:46 +0000 | [diff] [blame] | 860 | while (cli_wand->image_list_stack != (Stack *)NULL) |
| 861 | CLISpecialOperator(cli_wand,")",(const char *)NULL); |
anthony | 43f425d | 2012-02-26 12:58:58 +0000 | [diff] [blame] | 862 | while (cli_wand->image_info_stack != (Stack *)NULL) |
| 863 | CLISpecialOperator(cli_wand,"}",(const char *)NULL); |
anthony | 2052d27 | 2012-02-28 12:48:29 +0000 | [diff] [blame] | 864 | |
anthony | 1cdc5b7 | 2012-03-03 02:31:18 +0000 | [diff] [blame] | 865 | /* assert we have recovered the original structures */ |
anthony | 43f425d | 2012-02-26 12:58:58 +0000 | [diff] [blame] | 866 | assert(cli_wand->wand.image_info == image_info); |
| 867 | assert(cli_wand->wand.exception == exception); |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 868 | |
| 869 | /* Handle metadata for ImageMagickObject COM object for Windows VBS */ |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 870 | if (metadata != (char **) NULL) { |
| 871 | const char |
| 872 | *format; |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 873 | |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 874 | char |
| 875 | *text; |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 876 | |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 877 | format="%w,%h,%m"; // Get this from image_info Option splaytree |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 878 | |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 879 | text=InterpretImageProperties(image_info,cli_wand->wand.images,format, |
| 880 | exception); |
| 881 | if (text == (char *) NULL) |
| 882 | ThrowMagickException(exception,GetMagickModule(),ResourceLimitError, |
| 883 | "MemoryAllocationFailed","`%s'", GetExceptionMessage(errno)); |
| 884 | else { |
| 885 | (void) ConcatenateString(&(*metadata),text); |
| 886 | text=DestroyString(text); |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 887 | } |
anthony | afa3dfc | 2012-03-03 11:31:30 +0000 | [diff] [blame] | 888 | } |
anthony | 4cb3726 | 2012-03-18 11:18:45 +0000 | [diff] [blame] | 889 | |
anthony | 52bef75 | 2012-03-27 13:54:47 +0000 | [diff] [blame] | 890 | Magick_Command_Exit: |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 891 | /* Destroy the special CLI Wand */ |
anthony | 43f425d | 2012-02-26 12:58:58 +0000 | [diff] [blame] | 892 | cli_wand->wand.image_info = (ImageInfo *)NULL; /* not these */ |
| 893 | cli_wand->wand.exception = (ExceptionInfo *)NULL; |
| 894 | cli_wand=DestroyMagickCLI(cli_wand); |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 895 | |
anthony | c2b913e | 2012-03-31 00:22:33 +0000 | [diff] [blame] | 896 | return(IsMagickTrue(exception->severity > ErrorException)); |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 897 | } |