blob: bb3f95b8ed77535b2c389c3d75682a264db918b8 [file] [log] [blame]
anthonyfa1e43d2012-02-12 12:55:45 +00001/*
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% %
Cristy28f71302016-03-31 16:09:35 -040012% %
anthonyfa1e43d2012-02-12 12:55:45 +000013% Perform "Magick" on Images via the Command Line Interface %
14% %
15% Dragon Computing %
16% Anthony Thyssen %
17% January 2012 %
18% %
19% %
Cristy7ce65e72015-12-12 18:03:16 -050020% Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization %
anthonyfa1e43d2012-02-12 12:55:45 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36% Read CLI arguments, script files, and pipelines, to provide options that
37% manipulate images from many different formats.
38%
39*/
40
41/*
42 Include declarations.
43*/
44#include "MagickWand/studio.h"
45#include "MagickWand/MagickWand.h"
46
47/*
48%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49% %
50% %
51% %
52% M a i n %
53% %
54% %
55% %
56%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57%
58%
59*/
60
61static int MagickMain(int argc,char **argv)
62{
dirk56ccfef2016-04-28 11:36:16 +020063#define MagickCommandSize(name,use_metadata,command) \
64 { (name), sizeof(name)-1, (use_metadata), (command) }
Cristy28f71302016-03-31 16:09:35 -040065
66 typedef struct _CommandInfo
67 {
Cristy98f1f122016-04-02 17:11:59 -040068 const char
Cristyd002b872016-04-02 18:09:51 -040069 *client_name;
Cristy28f71302016-03-31 16:09:35 -040070
71 size_t
72 extent;
73
dirk56ccfef2016-04-28 11:36:16 +020074 MagickBooleanType
75 use_metadata;
76
Cristy28f71302016-03-31 16:09:35 -040077 MagickCommand
78 command;
79 } CommandInfo;
80
Cristy17552bc2016-04-02 18:01:56 -040081 const CommandInfo
Cristy28f71302016-03-31 16:09:35 -040082 MagickCommands[] =
83 {
dirk56ccfef2016-04-28 11:36:16 +020084 MagickCommandSize("magick", MagickFalse, MagickImageCommand),
85 MagickCommandSize("convert", MagickFalse, ConvertImageCommand),
Cristy12876e92016-05-07 19:31:33 -040086 MagickCommandSize("composite", MagickFalse, CompositeImageCommand),
dirk56ccfef2016-04-28 11:36:16 +020087 MagickCommandSize("identify", MagickTrue, IdentifyImageCommand),
88 MagickCommandSize("animate", MagickFalse, AnimateImageCommand),
89 MagickCommandSize("compare", MagickTrue, CompareImagesCommand),
90 MagickCommandSize("conjure", MagickFalse, ConjureImageCommand),
91 MagickCommandSize("display", MagickFalse, DisplayImageCommand),
92 MagickCommandSize("import", MagickFalse, ImportImageCommand),
93 MagickCommandSize("mogrify", MagickFalse, MogrifyImageCommand),
94 MagickCommandSize("montage", MagickFalse, MontageImageCommand),
95 MagickCommandSize("stream", MagickFalse, StreamImageCommand)
Cristy28f71302016-03-31 16:09:35 -040096 };
97
Cristyd002b872016-04-02 18:09:51 -040098 char
dirk56ccfef2016-04-28 11:36:16 +020099 client_name[MagickPathExtent],
100 *metadata;
Cristyd002b872016-04-02 18:09:51 -0400101
anthonyfa1e43d2012-02-12 12:55:45 +0000102 ExceptionInfo
103 *exception;
104
105 ImageInfo
106 *image_info;
107
dirk2b000dd2016-04-03 19:30:15 +0200108 int
dirk0f6182f2016-04-28 11:53:54 +0200109 exit_code,
dirk2b000dd2016-04-03 19:30:15 +0200110 offset;
111
anthonyfa1e43d2012-02-12 12:55:45 +0000112 MagickBooleanType
113 status;
114
Cristy28f71302016-03-31 16:09:35 -0400115 register ssize_t
116 i;
117
anthonyfa1e43d2012-02-12 12:55:45 +0000118 MagickCoreGenesis(*argv,MagickTrue);
119 exception=AcquireExceptionInfo();
120 image_info=AcquireImageInfo();
Cristyd002b872016-04-02 18:09:51 -0400121 GetPathComponent(argv[0],TailPath,client_name);
Cristy78a72f52016-05-29 14:57:07 -0400122 for (i=0; i < (ssize_t) (sizeof(MagickCommands)/sizeof(MagickCommands[0])); i++)
Cristy28f71302016-03-31 16:09:35 -0400123 {
dirk2b000dd2016-04-03 19:30:15 +0200124 offset=LocaleNCompare(MagickCommands[i].client_name,client_name,
125 MagickCommands[i].extent);
126 if (offset == 0)
127 break;
128 }
Cristyff69ad32016-04-03 15:04:12 -0400129 i%=(sizeof(MagickCommands)/sizeof(MagickCommands[0]));
Cristyb1e6ed02016-04-03 14:43:16 -0400130 if ((i == 0) && (argc > 1))
dirk2b000dd2016-04-03 19:30:15 +0200131 {
Cristy78a72f52016-05-29 14:57:07 -0400132 for (i=1; i < (ssize_t) (sizeof(MagickCommands)/sizeof(MagickCommands[0])); i++)
Cristyf87e0da2016-04-01 07:22:40 -0400133 {
dirk2b000dd2016-04-03 19:30:15 +0200134 offset=LocaleCompare(MagickCommands[i].client_name,argv[1]);
Cristyf87e0da2016-04-01 07:22:40 -0400135 if (offset == 0)
136 {
137 argc--;
138 argv++;
139 break;
140 }
141 }
Cristyff69ad32016-04-03 15:04:12 -0400142 i%=(sizeof(MagickCommands)/sizeof(MagickCommands[0]));
dirk2b000dd2016-04-03 19:30:15 +0200143 }
dirk56ccfef2016-04-28 11:36:16 +0200144 metadata=(char *) NULL;
dirk2b000dd2016-04-03 19:30:15 +0200145 status=MagickCommandGenesis(image_info,MagickCommands[i].command,argc,argv,
dirk56ccfef2016-04-28 11:36:16 +0200146 MagickCommands[i].use_metadata ? &metadata : (char **) NULL,exception);
147 if (metadata != (char *) NULL)
Cristy0725d3a2016-05-18 08:11:31 -0400148 {
149 (void) fputs(metadata,stdout);
150 metadata=DestroyString(metadata);
151 }
dirk0f6182f2016-04-28 11:53:54 +0200152 if (MagickCommands[i].command != CompareImagesCommand)
153 exit_code=status != MagickFalse ? 0 : 1;
154 else
155 {
156 if (status == MagickFalse)
157 exit_code=2;
158 else
159 {
160 const char
161 *option;
162
163 option=GetImageOption(image_info,"compare:dissimilar");
164 exit_code=IsStringTrue(option) ? 1 : 0;
165 }
166 }
anthonyfa1e43d2012-02-12 12:55:45 +0000167 image_info=DestroyImageInfo(image_info);
168 exception=DestroyExceptionInfo(exception);
169 MagickCoreTerminus();
dirk0f6182f2016-04-28 11:53:54 +0200170 return(exit_code);
anthonyfa1e43d2012-02-12 12:55:45 +0000171}
172
cristy07a3cca2012-12-10 13:09:10 +0000173#if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__)
anthonyfa1e43d2012-02-12 12:55:45 +0000174int main(int argc,char **argv)
175{
anthony00886dc2012-02-12 13:00:55 +0000176 return(MagickMain(argc,argv));
anthonyfa1e43d2012-02-12 12:55:45 +0000177}
178#else
179int wmain(int argc,wchar_t *argv[])
180{
181 char
182 **utf8;
183
184 int
185 status;
186
187 register int
188 i;
189
190 utf8=NTArgvToUTF8(argc,argv);
anthony00886dc2012-02-12 13:00:55 +0000191 status=MagickMain(argc,utf8);
anthonyfa1e43d2012-02-12 12:55:45 +0000192 for (i=0; i < argc; i++)
193 utf8[i]=DestroyString(utf8[i]);
194 utf8=(char **) RelinquishMagickMemory(utf8);
dirk3c746fb2014-06-05 18:21:08 +0000195 return(status);
anthonyfa1e43d2012-02-12 12:55:45 +0000196}
197#endif