+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
++ C L I O p t i o n %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% CLIOption() Processes the given option using the given CLI Magick Wand.
+% The option arguments can be variable in number, though at this time no more
+% that two is actually used by any option (this may change). Excess options
+% are simply ignored.
+%
+% If the cli_wand->command pointer is non-null, then it is assumed that the
+% option has already been search for up from the CommandOptions[] table in
+% "MagickCore/options.c" using GetCommandOptionInfo(). If not set this
+% routine will do the lookup instead. The pointer is reset afterward.
+%
+% This action allows the caller to lookup and pre-handle any 'special'
+% options, (such as implicit reads) before calling this general option
+% handler to deal with 'standard' command line options.
+%
+% The format of the CLIOption method is:
+%
+% void CLIOption(MagickCLI *cli_wand,const char *option, ...)
+%
+% A description of each parameter follows:
+%
+% o cli_wand: the main CLI Wand to use.
+%
+% o option: The special option (with any switch char) to process
+%
+% o args: any required arguments for an option (variable number)
+%
+% Example Usage...
+%
+% CLIoption(cli_wand,"-read","rose:");
+% CLIoption(cli_wand,"-virtual-pixel","transparent");
+% CLIoption(cli_wand,"-distort","SRT:","30");
+% CLIoption(cli_wand,"-write","rotated_rose.png");
+%
+*/
+WandExport void CLIOption(MagickCLI *cli_wand,const char *option,...)
+{
+ const char
+ *arg1,
+ *arg2;
+
+ CommandOptionFlags
+ option_type;
+
+ assert(cli_wand != (MagickCLI *) NULL);
+ assert(cli_wand->signature == WandSignature);
+ assert(cli_wand->wand.signature == WandSignature);
+ if (IfMagickTrue(cli_wand->wand.debug))
+ (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",cli_wand->wand.name);
+
+ do { /* Break Code Block for error handling */
+
+ /* get information about option */
+ if ( cli_wand->command == (const OptionInfo *) NULL )
+ cli_wand->command = GetCommandOptionInfo(option);
+#if 0
+ (void) FormatLocaleFile(stderr, "CLIOption \"%s\" matched \"%s\"\n",
+ option, cli_wand->command->mnemonic );
+#endif
+ option_type=(CommandOptionFlags) cli_wand->command->flags;
+
+ if ( option_type == UndefinedOptionFlag )
+ CLIWandExceptionReturn(OptionFatalError,"UnrecognizedOption",option);
+
+ assert( LocaleCompare(cli_wand->command->mnemonic,option) == 0 );
+
+ /* depreciated options */
+ if ( (option_type & DeprecateOptionFlag) != 0 )
+ CLIWandExceptionBreak(OptionError,"DeprecatedOptionNoCode",option);
+
+ /* options that this module does not handle */
+ if ((option_type & (SpecialOptionFlag|GenesisOptionFlag)) != 0 )
+ CLIWandExceptionBreak(OptionFatalError,"InvalidUseOfOption",option);
+
+ /* Get argument strings from VarArgs
+ How can you determine arguments is enough was supplied? */
+ { size_t
+ count = cli_wand->command->type;
+
+ va_list
+ operands;
+
+ va_start(operands,option);
+
+ arg1=arg2=NULL;
+ if ( count >= 1 )
+ arg1=(const char *) va_arg(operands, const char *);
+ if ( count >= 2 )
+ arg2=(const char *) va_arg(operands, const char *);
+
+ va_end(operands);
+
+#if 0
+ (void) FormatLocaleFile(stderr,
+ "CLIOption: \"%s\" Count: %ld Flags: %04x Args: \"%s\" \"%s\"\n",
+ option,(long) count,option_type,arg1,arg2);
+#endif
+ }
+
+ /*
+ Call the appropriate option handler
+ */
+
+ /* FUTURE: this is temporary - get 'settings' to handle distribution of
+ settings to images attributes,proprieties,artifacts */
+ if ( cli_wand->wand.images != (Image *)NULL )
+ SyncImagesSettings(cli_wand->wand.image_info,cli_wand->wand.images,
+ cli_wand->wand.exception);
+
+ if ( (option_type & SettingOptionFlags) != 0 ) {
+ CLISettingOptionInfo(cli_wand, option, arg1, arg2);
+ // FUTURE: Sync Specific Settings into Image Properities (not global)
+ }
+
+ /* Operators that do not need images - read, write, stack, clone */
+ if ( (option_type & NoImageOperatorFlag) != 0)
+ CLINoImageOperator(cli_wand, option, arg1, arg2);
+
+ /* FUTURE: The not a setting part below is a temporary hack due to
+ * some options being both a Setting and a Simple operator.
+ * Specifically -monitor, -depth, and -colorspace */
+ if ( cli_wand->wand.images == (Image *)NULL )
+ if ( ((option_type & (SimpleOperatorFlag|ListOperatorFlag)) != 0 ) &&
+ ((option_type & SettingOptionFlags) == 0 )) /* temp hack */
+ CLIWandExceptionBreak(OptionError,"NoImagesFound",option);
+
+ /* Operators work on single images, and needs a loop over the images */
+ if ( (option_type & SimpleOperatorFlag) != 0)
+ CLISimpleOperatorImages(cli_wand, option, arg1, arg2);
+
+ /* Operators that work on the image list as a whole */
+ if ( (option_type & ListOperatorFlag) != 0 )
+ CLIListOperatorImages(cli_wand, option, arg1, arg2);
+
+ } while (0); /* end Break code block */
+
+ cli_wand->command = (const OptionInfo *) NULL; /* prevent re-use later */
+}