00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #include "wand/studio.h"
00049 #include "wand/MagickWand.h"
00050 #include "wand/mogrify-private.h"
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 static MagickBooleanType ConjureUsage(void)
00091 {
00092 const char
00093 **p;
00094
00095 static const char
00096 *miscellaneous[]=
00097 {
00098 "-debug events display copious debugging information",
00099 "-help print program options",
00100 "-list type print a list of supported option arguments",
00101 "-log format format of debugging information",
00102 "-version print version information",
00103 (char *) NULL
00104 },
00105 *settings[]=
00106 {
00107 "-monitor monitor progress",
00108 "-quiet suppress all warning messages",
00109 "-regard-warnings pay attention to warning messages",
00110 "-seed value seed a new sequence of pseudo-random numbers",
00111 "-verbose print detailed information about the image",
00112 (char *) NULL
00113 };
00114
00115 (void) printf("Version: %s\n",GetMagickVersion((unsigned long *) NULL));
00116 (void) printf("Copyright: %s\n",GetMagickCopyright());
00117 (void) printf("Features: %s\n\n",GetMagickFeatures());
00118 (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
00119 GetClientName());
00120 (void) printf("\nImage Settings:\n");
00121 for (p=settings; *p != (char *) NULL; p++)
00122 (void) printf(" %s\n",*p);
00123 (void) printf("\nMiscellaneous Options:\n");
00124 for (p=miscellaneous; *p != (char *) NULL; p++)
00125 (void) printf(" %s\n",*p);
00126 (void) printf("\nIn additiion, define any key value pairs required by "
00127 "your script. For\nexample,\n\n");
00128 (void) printf(" conjure -size 100x100 -color blue -foo bar script.msl\n");
00129 return(MagickFalse);
00130 }
00131
00132 WandExport MagickBooleanType ConjureImageCommand(ImageInfo *image_info,
00133 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
00134 {
00135 #define DestroyConjure() \
00136 { \
00137 image=DestroyImageList(image); \
00138 for (i=0; i < (long) argc; i++) \
00139 argv[i]=DestroyString(argv[i]); \
00140 argv=(char **) RelinquishMagickMemory(argv); \
00141 }
00142 #define ThrowConjureException(asperity,tag,option) \
00143 { \
00144 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
00145 option); \
00146 DestroyConjure(); \
00147 return(MagickFalse); \
00148 }
00149 #define ThrowConjureInvalidArgumentException(option,argument) \
00150 { \
00151 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
00152 "InvalidArgument","`%s': %s",option,argument); \
00153 DestroyConjure(); \
00154 return(MagickFalse); \
00155 }
00156
00157 char
00158 *option;
00159
00160 Image
00161 *image;
00162
00163 long
00164 number_images;
00165
00166 MagickStatusType
00167 status;
00168
00169 register long
00170 i;
00171
00172
00173
00174
00175 assert(image_info != (ImageInfo *) NULL);
00176 assert(image_info->signature == MagickSignature);
00177 if (image_info->debug != MagickFalse)
00178 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
00179 assert(exception != (ExceptionInfo *) NULL);
00180 if (argc < 2)
00181 {
00182 (void) ConjureUsage();
00183 return(MagickTrue);
00184 }
00185 image=NewImageList();
00186 number_images=0;
00187 option=(char *) NULL;
00188 (void) respect_parenthesis;
00189
00190
00191
00192 ReadCommandlLine(argc,&argv);
00193 status=ExpandFilenames(&argc,&argv);
00194 if (status == MagickFalse)
00195 ThrowConjureException(ResourceLimitError,"MemoryAllocationFailed",
00196 GetExceptionMessage(errno));
00197 for (i=1; i < (long) argc; i++)
00198 {
00199 option=argv[i];
00200 if (IsMagickOption(option) != MagickFalse)
00201 {
00202 if (LocaleCompare("concurrent",option+1) == 0)
00203 break;
00204 if (LocaleCompare("debug",option+1) == 0)
00205 {
00206 long
00207 event;
00208
00209 if (*option == '+')
00210 break;
00211 i++;
00212 if (i == (long) argc)
00213 ThrowConjureException(OptionError,"MissingArgument",option);
00214 event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
00215 if (event < 0)
00216 ThrowConjureException(OptionError,"UnrecognizedEventType",
00217 argv[i]);
00218 (void) SetLogEventMask(argv[i]);
00219 continue;
00220 }
00221 if (LocaleCompare("duration",option+1) == 0)
00222 {
00223 if (*option == '+')
00224 break;
00225 i++;
00226 if (i == (long) (argc-1))
00227 ThrowConjureException(OptionError,"MissingArgument",option);
00228 if (IsGeometry(argv[i]) == MagickFalse)
00229 ThrowConjureInvalidArgumentException(option,argv[i]);
00230 continue;
00231 }
00232 if ((LocaleCompare("help",option+1) == 0) ||
00233 (LocaleCompare("-help",option+1) == 0))
00234 {
00235 if (*option == '-')
00236 return(ConjureUsage());
00237 continue;
00238 }
00239 if (LocaleCompare("log",option+1) == 0)
00240 {
00241 if (*option == '-')
00242 {
00243 i++;
00244 if (i == (long) argc)
00245 ThrowConjureException(OptionError,"MissingLogFormat",option);
00246 (void) SetLogFormat(argv[i]);
00247 }
00248 continue;
00249 }
00250 if (LocaleCompare("monitor",option+1) == 0)
00251 continue;
00252 if (LocaleCompare("quiet",option+1) == 0)
00253 continue;
00254 if (LocaleCompare("regard-warnings",option+1) == 0)
00255 break;
00256 if (LocaleCompare("seed",option+1) == 0)
00257 {
00258 if (*option == '+')
00259 break;
00260 i++;
00261 if (i == (long) (argc-1))
00262 ThrowConjureException(OptionError,"MissingArgument",option);
00263 if (IsGeometry(argv[i]) == MagickFalse)
00264 ThrowConjureInvalidArgumentException(option,argv[i]);
00265 break;
00266 }
00267 if (LocaleCompare("verbose",option+1) == 0)
00268 {
00269 image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
00270 continue;
00271 }
00272 if ((LocaleCompare("version",option+1) == 0) ||
00273 (LocaleCompare("-version",option+1) == 0))
00274 {
00275 (void) fprintf(stdout,"Version: %s\n",
00276 GetMagickVersion((unsigned long *) NULL));
00277 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
00278 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
00279 return(MagickFalse);
00280 }
00281
00282
00283
00284 (void) DeleteImageOption(image_info,option+1);
00285 status=SetImageOption(image_info,option+1,argv[i+1]);
00286 if (status == MagickFalse)
00287 ThrowConjureException(ImageError,"UnableToPersistKey",option);
00288 i++;
00289 continue;
00290 }
00291
00292
00293
00294 (void) DeleteImageOption(image_info,"filename");
00295 status=SetImageOption(image_info,"filename",argv[i]);
00296 if (status == MagickFalse)
00297 ThrowConjureException(ImageError,"UnableToPersistKey",argv[i]);
00298 (void) FormatMagickString(image_info->filename,MaxTextExtent,"msl:%s",
00299 argv[i]);
00300 image=ReadImages(image_info,exception);
00301 CatchException(exception);
00302 if (image != (Image *) NULL)
00303 image=DestroyImageList(image);
00304 status=image != (Image *) NULL ? MagickTrue : MagickFalse;
00305 number_images++;
00306 }
00307 if (i != argc)
00308 ThrowConjureException(OptionError,"MissingAnImageFilename",argv[i]);
00309 if (number_images == 0)
00310 ThrowConjureException(OptionError,"MissingAnImageFilename",argv[argc-1]);
00311 if (image != (Image *) NULL)
00312 image=DestroyImageList(image);
00313 for (i=0; i < (long) argc; i++)
00314 argv[i]=DestroyString(argv[i]);
00315 argv=(char **) RelinquishMagickMemory(argv);
00316 return(status != 0 ? MagickTrue : MagickFalse);
00317 }