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 | % % |
Cristy | 28f7130 | 2016-03-31 16:09:35 -0400 | [diff] [blame] | 12 | % % |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 13 | % Perform "Magick" on Images via the Command Line Interface % |
| 14 | % % |
| 15 | % Dragon Computing % |
| 16 | % Anthony Thyssen % |
| 17 | % January 2012 % |
| 18 | % % |
| 19 | % % |
Cristy | 7ce65e7 | 2015-12-12 18:03:16 -0500 | [diff] [blame] | 20 | % Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization % |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 21 | % 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 | |
| 61 | static int MagickMain(int argc,char **argv) |
| 62 | { |
dirk | 56ccfef | 2016-04-28 11:36:16 +0200 | [diff] [blame] | 63 | #define MagickCommandSize(name,use_metadata,command) \ |
| 64 | { (name), sizeof(name)-1, (use_metadata), (command) } |
Cristy | 28f7130 | 2016-03-31 16:09:35 -0400 | [diff] [blame] | 65 | |
| 66 | typedef struct _CommandInfo |
| 67 | { |
Cristy | 98f1f12 | 2016-04-02 17:11:59 -0400 | [diff] [blame] | 68 | const char |
Cristy | d002b87 | 2016-04-02 18:09:51 -0400 | [diff] [blame] | 69 | *client_name; |
Cristy | 28f7130 | 2016-03-31 16:09:35 -0400 | [diff] [blame] | 70 | |
| 71 | size_t |
| 72 | extent; |
| 73 | |
dirk | 56ccfef | 2016-04-28 11:36:16 +0200 | [diff] [blame] | 74 | MagickBooleanType |
| 75 | use_metadata; |
| 76 | |
Cristy | 28f7130 | 2016-03-31 16:09:35 -0400 | [diff] [blame] | 77 | MagickCommand |
| 78 | command; |
| 79 | } CommandInfo; |
| 80 | |
Cristy | 17552bc | 2016-04-02 18:01:56 -0400 | [diff] [blame] | 81 | const CommandInfo |
Cristy | 28f7130 | 2016-03-31 16:09:35 -0400 | [diff] [blame] | 82 | MagickCommands[] = |
| 83 | { |
dirk | 56ccfef | 2016-04-28 11:36:16 +0200 | [diff] [blame] | 84 | MagickCommandSize("magick", MagickFalse, MagickImageCommand), |
| 85 | MagickCommandSize("convert", MagickFalse, ConvertImageCommand), |
Cristy | 12876e9 | 2016-05-07 19:31:33 -0400 | [diff] [blame] | 86 | MagickCommandSize("composite", MagickFalse, CompositeImageCommand), |
dirk | 56ccfef | 2016-04-28 11:36:16 +0200 | [diff] [blame] | 87 | 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) |
Cristy | 28f7130 | 2016-03-31 16:09:35 -0400 | [diff] [blame] | 96 | }; |
| 97 | |
Cristy | d002b87 | 2016-04-02 18:09:51 -0400 | [diff] [blame] | 98 | char |
dirk | 56ccfef | 2016-04-28 11:36:16 +0200 | [diff] [blame] | 99 | client_name[MagickPathExtent], |
| 100 | *metadata; |
Cristy | d002b87 | 2016-04-02 18:09:51 -0400 | [diff] [blame] | 101 | |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 102 | ExceptionInfo |
| 103 | *exception; |
| 104 | |
| 105 | ImageInfo |
| 106 | *image_info; |
| 107 | |
dirk | 2b000dd | 2016-04-03 19:30:15 +0200 | [diff] [blame] | 108 | int |
dirk | 0f6182f | 2016-04-28 11:53:54 +0200 | [diff] [blame] | 109 | exit_code, |
dirk | 2b000dd | 2016-04-03 19:30:15 +0200 | [diff] [blame] | 110 | offset; |
| 111 | |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 112 | MagickBooleanType |
| 113 | status; |
| 114 | |
Cristy | 28f7130 | 2016-03-31 16:09:35 -0400 | [diff] [blame] | 115 | register ssize_t |
| 116 | i; |
| 117 | |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 118 | MagickCoreGenesis(*argv,MagickTrue); |
| 119 | exception=AcquireExceptionInfo(); |
| 120 | image_info=AcquireImageInfo(); |
Cristy | d002b87 | 2016-04-02 18:09:51 -0400 | [diff] [blame] | 121 | GetPathComponent(argv[0],TailPath,client_name); |
Cristy | 78a72f5 | 2016-05-29 14:57:07 -0400 | [diff] [blame] | 122 | for (i=0; i < (ssize_t) (sizeof(MagickCommands)/sizeof(MagickCommands[0])); i++) |
Cristy | 28f7130 | 2016-03-31 16:09:35 -0400 | [diff] [blame] | 123 | { |
dirk | 2b000dd | 2016-04-03 19:30:15 +0200 | [diff] [blame] | 124 | offset=LocaleNCompare(MagickCommands[i].client_name,client_name, |
| 125 | MagickCommands[i].extent); |
| 126 | if (offset == 0) |
| 127 | break; |
| 128 | } |
Cristy | ff69ad3 | 2016-04-03 15:04:12 -0400 | [diff] [blame] | 129 | i%=(sizeof(MagickCommands)/sizeof(MagickCommands[0])); |
Cristy | b1e6ed0 | 2016-04-03 14:43:16 -0400 | [diff] [blame] | 130 | if ((i == 0) && (argc > 1)) |
dirk | 2b000dd | 2016-04-03 19:30:15 +0200 | [diff] [blame] | 131 | { |
Cristy | 78a72f5 | 2016-05-29 14:57:07 -0400 | [diff] [blame] | 132 | for (i=1; i < (ssize_t) (sizeof(MagickCommands)/sizeof(MagickCommands[0])); i++) |
Cristy | f87e0da | 2016-04-01 07:22:40 -0400 | [diff] [blame] | 133 | { |
dirk | 2b000dd | 2016-04-03 19:30:15 +0200 | [diff] [blame] | 134 | offset=LocaleCompare(MagickCommands[i].client_name,argv[1]); |
Cristy | f87e0da | 2016-04-01 07:22:40 -0400 | [diff] [blame] | 135 | if (offset == 0) |
| 136 | { |
| 137 | argc--; |
| 138 | argv++; |
| 139 | break; |
| 140 | } |
| 141 | } |
Cristy | ff69ad3 | 2016-04-03 15:04:12 -0400 | [diff] [blame] | 142 | i%=(sizeof(MagickCommands)/sizeof(MagickCommands[0])); |
dirk | 2b000dd | 2016-04-03 19:30:15 +0200 | [diff] [blame] | 143 | } |
dirk | 56ccfef | 2016-04-28 11:36:16 +0200 | [diff] [blame] | 144 | metadata=(char *) NULL; |
dirk | 2b000dd | 2016-04-03 19:30:15 +0200 | [diff] [blame] | 145 | status=MagickCommandGenesis(image_info,MagickCommands[i].command,argc,argv, |
dirk | 56ccfef | 2016-04-28 11:36:16 +0200 | [diff] [blame] | 146 | MagickCommands[i].use_metadata ? &metadata : (char **) NULL,exception); |
| 147 | if (metadata != (char *) NULL) |
Cristy | 0725d3a | 2016-05-18 08:11:31 -0400 | [diff] [blame] | 148 | { |
| 149 | (void) fputs(metadata,stdout); |
| 150 | metadata=DestroyString(metadata); |
| 151 | } |
dirk | 0f6182f | 2016-04-28 11:53:54 +0200 | [diff] [blame] | 152 | 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 | } |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 167 | image_info=DestroyImageInfo(image_info); |
| 168 | exception=DestroyExceptionInfo(exception); |
| 169 | MagickCoreTerminus(); |
dirk | 0f6182f | 2016-04-28 11:53:54 +0200 | [diff] [blame] | 170 | return(exit_code); |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 171 | } |
| 172 | |
cristy | 07a3cca | 2012-12-10 13:09:10 +0000 | [diff] [blame] | 173 | #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 174 | int main(int argc,char **argv) |
| 175 | { |
anthony | 00886dc | 2012-02-12 13:00:55 +0000 | [diff] [blame] | 176 | return(MagickMain(argc,argv)); |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 177 | } |
| 178 | #else |
| 179 | int 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); |
anthony | 00886dc | 2012-02-12 13:00:55 +0000 | [diff] [blame] | 191 | status=MagickMain(argc,utf8); |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 192 | for (i=0; i < argc; i++) |
| 193 | utf8[i]=DestroyString(utf8[i]); |
| 194 | utf8=(char **) RelinquishMagickMemory(utf8); |
dirk | 3c746fb | 2014-06-05 18:21:08 +0000 | [diff] [blame] | 195 | return(status); |
anthony | fa1e43d | 2012-02-12 12:55:45 +0000 | [diff] [blame] | 196 | } |
| 197 | #endif |