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