/src/graphicsmagick/magick/magic.c
Line | Count | Source |
1 | | /* |
2 | | % Copyright (C) 2003-2025 GraphicsMagick Group |
3 | | % Copyright (C) 2002 ImageMagick Studio |
4 | | % |
5 | | % This program is covered by multiple licenses, which are described in |
6 | | % Copyright.txt. You should have received a copy of Copyright.txt with this |
7 | | % package; otherwise see http://www.graphicsmagick.org/www/Copyright.html. |
8 | | % |
9 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
10 | | % % |
11 | | % % |
12 | | % M M AAA GGGG IIIII CCCC % |
13 | | % MM MM A A G I C % |
14 | | % M M M AAAAA G GGG I C % |
15 | | % M M A A G G I C % |
16 | | % M M A A GGGG IIIII CCCC % |
17 | | % % |
18 | | % % |
19 | | % GraphicsMagick Image Magic Methods % |
20 | | % % |
21 | | % % |
22 | | % Software Design % |
23 | | % Bob Friesenhahn % |
24 | | % July 2000 % |
25 | | % % |
26 | | % % |
27 | | % % |
28 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
29 | | % |
30 | | % |
31 | | */ |
32 | | |
33 | | /* |
34 | | Include declarations. |
35 | | */ |
36 | | #include "magick/studio.h" |
37 | | #include "magick/magic.h" |
38 | | #include "magick/utility.h" |
39 | | |
40 | | /* |
41 | | Define declarations. |
42 | | */ |
43 | | |
44 | | /* |
45 | | Static declarations. |
46 | | */ |
47 | | static const struct |
48 | | { |
49 | | const char |
50 | | name[10]; |
51 | | |
52 | | const unsigned char |
53 | | * const magic; |
54 | | |
55 | | const char |
56 | | * description; |
57 | | |
58 | | unsigned short |
59 | | name_size, |
60 | | description_size, |
61 | | length, |
62 | | offset; |
63 | | } |
64 | | StaticMagic[] = |
65 | | { |
66 | | #define MAGIC(name,description,offset,magic) {name,(const unsigned char *)magic,description,sizeof(name)-1,sizeof(description)-1,sizeof(magic)-1,offset} |
67 | | MAGIC("WEBP", "WebP Image Format", 8, "WEBP"), |
68 | | MAGIC("AVIF", "AV1 image", 4, "ftypavif"), /* "image/avif" */ |
69 | | MAGIC("AVIF", "AV1 image sequence", 4, "ftypavis"), /* "image/avif-sequence" */ |
70 | | /* MAGIC("AVI", "", 0, "RIFF"), */ |
71 | | MAGIC("8BIMWTEXT", "Photoshop resource wide text format", 0, "8\000B\000I\000M\000#"), |
72 | | MAGIC("8BIMTEXT", "Photoshop resource text format", 0, "8BIM#"), |
73 | | MAGIC("8BIM", "Photoshop resource format", 0, "8BIM"), |
74 | | MAGIC("BMP", "BMP (OS/2 struct bitmap array)", 0, "BA"), |
75 | | MAGIC("BMP", "BMP (Windows 3.1x, 95, NT, ...)", 0, "BM"), |
76 | | MAGIC("BMP", "BMP (OS/2 struct color icon)", 0, "CI"), |
77 | | MAGIC("BMP", "BMP (OS/2 const color pointer)", 0, "CP"), |
78 | | MAGIC("BMP", "BMP (OS/2 struct icon)", 0, "IC"), |
79 | | MAGIC("BMP", "BMP (OS/2 pointer)", 0, "PI"), |
80 | | MAGIC("CALS", "CALS (MIL-STD-1840) Type 1 image", 21, "version: MIL-STD-1840"), |
81 | | MAGIC("CALS", "CALS (MIL-STD-1840) Type 1 image", 0, "srcdocid:"), |
82 | | MAGIC("CALS", "CALS (MIL-STD-1840) Type 1 image", 9, "srcdocid:"), |
83 | | MAGIC("CALS", "CALS (MIL-STD-1840) Type 1 image", 8, "rorient:"), |
84 | | MAGIC("CGM", "Computer Graphics Metaformat", 0, "BEGMF"), |
85 | | MAGIC("CIN", "Kodak Cineon Image File", 0, "\200\052\137\327"), |
86 | | MAGIC("DCM", "DICOM medical image", 128, "DICM"), |
87 | | MAGIC("DCX", "ZSoft IBM PC multi-page Paintbrush", 0, "\261\150\336\72"), |
88 | | MAGIC("DIB", "Microsoft DIB", 0, "\050\000"), |
89 | | MAGIC("DOT", "Graphviz DOT", 0, "digraph"), |
90 | | MAGIC("DPX", "SMPTE 268M-2003 (DPX 2.0) (BE)", 0, "SDPX"), |
91 | | MAGIC("DPX", "SMPTE 268M-2003 (DPX 2.0) (LE)", 0, "XPDS"), |
92 | | MAGIC("EMF", "Microsoft EMF", 40, "\040\105\115\106\000\000\001\000"), |
93 | | MAGIC("EPT", "Adobe Encapsulated PostScript (with preview)", 0, "\305\320\323\306"), |
94 | | MAGIC("FAX", "Group 3 FAX", 0, "DFAX"), |
95 | | MAGIC("FIG", "Xfig", 0, "#FIG"), |
96 | | MAGIC("FITS", "Flexible Image Transport System", 0, "IT0"), |
97 | | MAGIC("FITS", "Flexible Image Transport System", 0, "SIMPLE"), |
98 | | MAGIC("FPX", "FlashPIX", 0, "\320\317\021\340"), |
99 | | MAGIC("GIF", "CompuServe graphics interchange format", 0, "GIF8"), |
100 | | /* See libheif/libheif/api/libheif/heif_brands.h and .cc for libheif support */ |
101 | | /* The mappings of HEIF brand identifiers to magic identifiers is subject to change */ |
102 | | /* https://nokiatech.github.io/heif/technical.html */ |
103 | | MAGIC("HEIC", "HEVC image - HEVC (H.265) Main or Main Still profile (`heic`)", 4, "ftypheic"), /* MIME "image/heic */ |
104 | | MAGIC("HEIC", "HEVC image - HEVC (H.265) Main 10 profile (`heix`)", 4, "ftypheix"), /* MIME "image/heic */ |
105 | | MAGIC("HEIC", "HEVC image sequence - HEVC (H.265) Main profile (`hevc`)", 4, "ftyphevc"), /* MIME "image/heic-sequence" */ |
106 | | MAGIC("HEIC", "HEVC image sequence - HEVC (H.265) Main 10 profile (`hevx`)", 4, "ftyphevx"), /* MIME "image/heic-sequence" */ |
107 | | MAGIC("HEIC", "HEVC layered image - HEVC (H.265) Main or Multiview Main profile (`heim`)", 4, "ftypheim"), /* MIME "image/heic" */ |
108 | | MAGIC("HEIC", "HEVC layered image - HEVC (H.265) Main, Main 10, Scalable Main or Scalable Main 10 profile (`heis`)", 4, "ftypheis"), /* MIME "image/heic */ |
109 | | MAGIC("HEIC", "HEVC layered image sequence - HEVC (H.265) Main or Multiview Main profile (`hevm`)", 4, "ftyphevm"), /* "MIME image/heic-sequence" */ |
110 | | MAGIC("HEIC", "HEVC layered image sequence - HEVC (H.265) Main, Main 10, Scalable Main or Scalable Main 10 profile (`hevs`)", 4, "ftyphevs"), /* MIME "image/heic-sequence" */ |
111 | | MAGIC("HEIF", "HEIF image structural brand (`mif1`)", 4, "ftypmif1"), /* MIME "image/heif" */ /* mif1heichevc */ |
112 | | MAGIC("HEIF", "HEIF image structural brand (`mif2`)", 4, "ftypmif2"), |
113 | | MAGIC("HEIF", "HEIF image structural brand (`mif3`) - low-overhead (ftyp+mini) structure", 4, "ftypmif3"), /* "mif3avif", "mif3heic" */ |
114 | | MAGIC("HEIF", "HEIF image sequence structural brand (`msf1`)", 4, "ftypmsf1"), /* MIME "image/heif-sequence" */ |
115 | | MAGIC("HEIF", "VVC image (`vvic`)", 4, "ftypvvic"), |
116 | | MAGIC("HEIF", "VVC image sequence (`vvis`)", 4, "ftypvvis"), |
117 | | MAGIC("HEIF", "EVC baseline image (`evbi`)", 4, "ftypevbi"), |
118 | | MAGIC("HEIF", "EVC main profile image (`evmi`)", 4, "ftypevbi"), |
119 | | MAGIC("HEIF", "EVC baseline image sequence (`evbs`)", 4, "ftypevbs"), |
120 | | MAGIC("HEIF", "EVC main profile image sequence (`evms`)", 4, "ftypevms"), |
121 | | MAGIC("HEIF", "JPEG image (`jpeg`)", 4, "ftypjpeg"), |
122 | | MAGIC("HEIF", "JPEG image sequence (`jpgs`)", 4, "ftypjpgs"), |
123 | | MAGIC("HEIF", "JPEG 2000 image (`j2ki`)", 4, "ftypj2ki"), /* MIME "image/hej2k" */ |
124 | | MAGIC("HEIF", "JPEG 2000 image sequence (`j2is`)", 4, "ftypj2is"), /* MIME "image/j2is" */ |
125 | | MAGIC("HEIF", "Multi-image application format (`miaf`)", 4, "ftypmiaf"), |
126 | | MAGIC("HEIF", "Single picture file, a single intra-coded picture (`1pic`)", 4, "ftyp1pic"), |
127 | | MAGIC("HEIF", "H.264 AVCI (`avci`)", 4, "ftypavci"), |
128 | | MAGIC("HEIF", "H.264 AVCS (`avcs`)", 4, "ftypavcs"), |
129 | | MAGIC("HEIF", "H.264 ISO8 (`iso8`)", 4, "ftypiso8"), |
130 | | MAGIC("HEIF", "HEIF", 4, "ftyp"), /* Last-ditch catch-all for HEIF files */ |
131 | | /* MAGIC("HDF", "Heirarchical Data Format", 1, "HDF"), */ |
132 | | MAGIC("HPGL", "HP Graphics Language", 0, "IN;"), |
133 | | MAGIC("HTML", "Hypertext Markup Language", 1, "HTML"), |
134 | | MAGIC("HTML", "Hypertext Markup Language", 1, "html"), |
135 | | MAGIC("ILBM", "", 8, "ILBM"), |
136 | | MAGIC("IPTCWTEXT", "IPTC Newsphoto wide text format", 0, "\062\000#\000\060\000=\000\042\000&\000#\000\060\000;\000&\000#\000\062\000;\000\042\000"), |
137 | | MAGIC("IPTCTEXT", "IPTC Newsphoto text format", 0, "2#0=\042�\042"), |
138 | | MAGIC("IPTC", "IPTC Newsphoto", 0, "\034\002"), |
139 | | MAGIC("JNG", "JPEG Network Graphics", 0, "\213JNG\r\n\032\n"), |
140 | | MAGIC("JPEG", "Joint Photographic Experts Group JFIF", 0, "\377\330\377"), |
141 | | MAGIC("JPC", "JPEG-2000 Code Stream Syntax", 0, "\377\117"), |
142 | | MAGIC("JP2", "JPEG-2000 JP2 File Format", 4, "\152\120\040\040\015"), |
143 | | MAGIC("JXL", "JPEG XL Image Format", 0, "\xff\x0a"), |
144 | | MAGIC("JXL", "JPEG XL Image Format", 0, "\x00\x00\x00\x0c\x4a\x58\x4c\x20\x0d\x0a\x87\x0a"), |
145 | | MAGIC("MAT", "MATLAB Level 4.0-7.0 image format", 0, "MATLAB 5.0 MAT-file,"), |
146 | | MAGIC("MIFF", "Magick Image File Format", 0, "Id=ImageMagick"), |
147 | | MAGIC("MIFF", "Magick Image File Format", 0, "id=ImageMagick"), |
148 | | MAGIC("MNG", "Multiple-image Network Graphics", 0, "\212MNG\r\n\032\n"), |
149 | | MAGIC("MPC", "Magick Persistent Cache image", 0, "id=MagickCache"), |
150 | | MAGIC("MPEG", "MPEG Video Stream", 0, "\000\000\001\263"), |
151 | | MAGIC("PCD", "Adobe Photo CD", 2048, "PCD_"), |
152 | | MAGIC("PCL", "HP Page Control Language", 0, "\033E\033"), |
153 | | MAGIC("PCX", "ZSoft IBM PC Paintbrush", 0, "\012\002"), |
154 | | MAGIC("PCX", "ZSoft IBM PC Paintbrush", 0, "\012\005"), |
155 | | MAGIC("PDB", "Palm Database ImageViewer Format", 60, "vIMGView"), |
156 | | MAGIC("PDF", "Portable Document Format", 0, "%PDF-"), |
157 | | MAGIC("PFA", "Postscript Type 1 font (ASCII)", 0, "%!PS-AdobeFont-1.0"), |
158 | | MAGIC("PFB", "Postscript Type 1 font (binary)", 6, "%!PS-AdobeFont-1.0"), |
159 | | MAGIC("PGX", "JPEG-2000 VM Format (ML)", 0, "PG ML"), |
160 | | MAGIC("PGX", "JPEG-2000 VM Format (LM)", 0, "PG LM"), |
161 | | MAGIC("PICT", "Apple Macintosh QuickDraw/PICT", 522, "\000\021\002\377\014\000"), |
162 | | MAGIC("PNG", "Portable Network Graphics", 0, "\211PNG\r\n\032\n"), |
163 | | MAGIC("PBM", "Portable bitmap file format (text)", 0, "P1"), |
164 | | MAGIC("PGM", "Portable graymap file format (text)", 0, "P2"), |
165 | | MAGIC("PPM", "Portable pixmap file format (text)", 0, "P3"), |
166 | | MAGIC("PBM", "Portable bitmap file format (binary)", 0, "P4"), |
167 | | MAGIC("PGM", "Portable graymap file format (binary)", 0, "P5"), |
168 | | MAGIC("PPM", "Portable pixmap file format (binary)", 0, "P6"), |
169 | | MAGIC("P7", "XV Thumbnail (P7 332)", 0, "P7 332"), /* XV Thumbnail */ |
170 | | MAGIC("PAM", "XV Thumbnail (P7)", 0, "P7"), /* Should be listed after "P7 332" */ |
171 | | MAGIC("PS", "Adobe Encapsulated Postscript 3.0", 0, "%!PS-Adobe-3.0 EPSF-3.0"), |
172 | | MAGIC("PS", "Adobe Encapsulated Postscript 2.1", 0, "%!PS-Adobe-3.0 EPSF-2.1"), |
173 | | MAGIC("PS", "Adobe Encapsulated Postscript 2.0", 0, "%!PS-Adobe-2.0 EPSF-2.0"), |
174 | | MAGIC("PS", "Adobe Encapsulated Postscript 1.2", 0, "%!PS-Adobe-2.0 EPSF-1.2"), |
175 | | MAGIC("PS", "Adobe Postscript 3.0", 0, "%!PS-Adobe-3.0"), |
176 | | MAGIC("PS", "Adobe Postscript 2.0", 0, "%!PS-Adobe-2.0"), |
177 | | MAGIC("PS", "Adobe Postscript 2.1", 0, "%!PS-Adobe-2.1"), |
178 | | MAGIC("PS", "Adobe Postscript 1.0", 0, "%!PS-Adobe-1.0"), |
179 | | MAGIC("PS", "Adobe Postscript", 0, "%!"), /* Generic */ |
180 | | MAGIC("PS", "Adobe Postscript", 0, "\004%!"), /* EOT character. Maybe used when printing. */ |
181 | | MAGIC("PS", "Adobe Encapsulated PostScript Interchange (EPT)", 0, "\305\320\323\306"), /* aka EPT */ |
182 | | MAGIC("PSD", "Photoshop PSD", 0, "8BPS"), |
183 | | MAGIC("PWP", "Seattle Film Works", 0, "SFW95"), |
184 | | MAGIC("RAD", "Radiance", 0, "#?RADIANCE"), |
185 | | MAGIC("RAD", "Radiance", 0, "VIEW= "), |
186 | | MAGIC("RLE", "Utah Run length encoded image", 0, "\122\314"), |
187 | | MAGIC("SCT", "Scitex HandShake", 0, "CT"), |
188 | | MAGIC("SFW", "Seattle Film Work", 0, "SFW94"), |
189 | | MAGIC("SGI", "Irix RGB image", 0, "\001\332"), |
190 | | MAGIC("SUN", "SUN Rasterfile", 0, "\131\246\152\225"), |
191 | | MAGIC("SVG", "Scalable Vector Graphics", 1, "?XML"), |
192 | | MAGIC("SVG", "Scalable Vector Graphics", 1, "?xml"), |
193 | | MAGIC("TIFF", "Tagged Image File Format (BE Classic)", 0, "\115\115\000\052"), |
194 | | MAGIC("TIFF", "Tagged Image File Format (LE Classic)", 0, "\111\111\052\000"), |
195 | | MAGIC("TOPOL", "TopoL X Image", 0, " "), |
196 | | MAGIC("BIGTIFF", "Tagged Image File Format (BE Big)", 0, "\115\115\000\053\000\010\000\000"), |
197 | | MAGIC("BIGTIFF", "Tagged Image File Format (LE Big)", 0, "\111\111\053\000\010\000\000\000"), |
198 | | MAGIC("VICAR", "VICAR rasterfile format (LBLSIZE)", 0, "LBLSIZE"), |
199 | | MAGIC("VICAR", "VICAR rasterfile format (NJPL1I)", 0, "NJPL1I"), |
200 | | MAGIC("VIFF","Khoros Visualization image", 0, "\253\001"), |
201 | | MAGIC("WMF", "Windows Meta File", 0, "\327\315\306\232"), |
202 | | MAGIC("WMF", "Windows Meta File", 0, "\001\000\011\000"), |
203 | | MAGIC("WPG", "Word Perfect Graphics", 0, "\377WPC"), |
204 | | MAGIC("XBM", "X Windows system bitmap", 0, "#define"), |
205 | | MAGIC("XCF", "GIMP XCF", 0, "gimp xcf"), |
206 | | MAGIC("XPM", "X Windows system pixmap", 1, "* XPM *"), |
207 | | MAGIC("XWD", "X Windows system window dump", 4, "\007\000\000"), |
208 | | MAGIC("XWD", "X Windows system window dump", 5, "\000\000\007") |
209 | | }; |
210 | | |
211 | | /* |
212 | | Forward declarations. |
213 | | */ |
214 | | |
215 | | /* |
216 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
217 | | % % |
218 | | % % |
219 | | % % |
220 | | + D e s t r o y M a g i c I n f o % |
221 | | % % |
222 | | % % |
223 | | % % |
224 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
225 | | % |
226 | | % Method DestroyMagicInfo deallocates memory associated with the magic list. |
227 | | % |
228 | | % The format of the DestroyMagicInfo method is: |
229 | | % |
230 | | % DestroyMagicInfo(void) |
231 | | % |
232 | | % |
233 | | */ |
234 | | MagickExport void |
235 | | DestroyMagicInfo(void) |
236 | 0 | { |
237 | 0 | } |
238 | | |
239 | | /* |
240 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
241 | | % % |
242 | | % % |
243 | | % % |
244 | | + G e t M a g i c k F i l e F o r m a t % |
245 | | % % |
246 | | % % |
247 | | % % |
248 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
249 | | % |
250 | | % Method GetMagickFileFormat inspects the provided image file/blob header |
251 | | % bytes and sets/updates the provided file format string buffer. The value |
252 | | % MagickPass is returned if the format was successfully identified. The |
253 | | % value MagickFail is returned if the format was not identified or an |
254 | | % exception occurred. |
255 | | % |
256 | | % |
257 | | % The format of the GetMagickFileFormat method is: |
258 | | % |
259 | | % MagickPassFail GetMagickFileFormat( |
260 | | % const unsigned char *header, const size_t header_length, |
261 | | % char *postulate, const size_t postulate_length, |
262 | | % ExceptionInfo *exception) |
263 | | % |
264 | | % A description of each parameter follows: |
265 | | % |
266 | | % o header: A binary string representing the first several |
267 | | % thousand bytes of the file/blob header to test. |
268 | | % |
269 | | % o header_length: The length of the binary signature. Currently |
270 | | % 2*MaxTextExtent (4106 bytes). |
271 | | % |
272 | | % o format: Format buffer. Updated with actual format if it can be |
273 | | % determined. |
274 | | % |
275 | | % o format_length: Format buffer length. |
276 | | % |
277 | | % o exception: Return any errors or warnings in this structure. |
278 | | % |
279 | | % |
280 | | */ |
281 | | MagickExport MagickPassFail |
282 | | GetMagickFileFormat(const unsigned char *header, const size_t header_length, |
283 | | char *format, const size_t format_length, |
284 | | ExceptionInfo *exception) |
285 | 10.8M | { |
286 | 10.8M | register unsigned int |
287 | 10.8M | i; |
288 | | |
289 | 10.8M | MagickPassFail |
290 | 10.8M | status=MagickFail; |
291 | | |
292 | 10.8M | ARG_NOT_USED(exception); |
293 | | |
294 | 10.8M | if (!((header == (const unsigned char *) NULL) || (header_length == 0) || |
295 | 10.8M | (format_length < 2))) |
296 | 10.8M | { |
297 | | /* |
298 | | Search for requested magic. |
299 | | */ |
300 | 980M | for (i=0; i < ArraySize(StaticMagic); i++) |
301 | 979M | { |
302 | 979M | if ((size_t) StaticMagic[i].offset+StaticMagic[i].length <= header_length) |
303 | 907M | { |
304 | 907M | if ((header[StaticMagic[i].offset] == StaticMagic[i].magic[0]) && |
305 | 25.2M | (memcmp(header+StaticMagic[i].offset,StaticMagic[i].magic, |
306 | 25.2M | StaticMagic[i].length) == 0)) |
307 | 9.47M | { |
308 | 9.47M | if (strlcpy(format,StaticMagic[i].name,format_length) < format_length) |
309 | 9.47M | { |
310 | 9.47M | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
311 | 9.47M | "Magick: %s (\"%s\")", |
312 | 9.47M | StaticMagic[i].name, |
313 | 9.47M | StaticMagic[i].description); |
314 | 9.47M | status=MagickPass; |
315 | 9.47M | } |
316 | 9.47M | break; |
317 | 9.47M | } |
318 | 907M | } |
319 | 979M | } |
320 | 10.8M | } |
321 | 10.8M | return status; |
322 | 10.8M | } |
323 | | |
324 | | /* |
325 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
326 | | % % |
327 | | % % |
328 | | % % |
329 | | + I n i t i a l i z e M a g i c I n f o % |
330 | | % % |
331 | | % % |
332 | | % % |
333 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
334 | | % |
335 | | % Method InitializeMagicInfo initializes the file header magic detection |
336 | | % facility. |
337 | | % |
338 | | % The format of the InitializeMagicInfo method is: |
339 | | % |
340 | | % MagickPassFail InitializeMagicInfo(void) |
341 | | % |
342 | | % |
343 | | */ |
344 | | MagickExport MagickPassFail |
345 | | InitializeMagicInfo(void) |
346 | 0 | { |
347 | 0 | return MagickPass; |
348 | 0 | } |
349 | | |
350 | | /* |
351 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
352 | | % % |
353 | | % % |
354 | | % % |
355 | | % L i s t M a g i c I n f o % |
356 | | % % |
357 | | % % |
358 | | % % |
359 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
360 | | % |
361 | | % Method ListMagicInfo lists the magic info to a file. |
362 | | % |
363 | | % The format of the ListMagicInfo method is: |
364 | | % |
365 | | % unsigned int ListMagicInfo(FILE *file,ExceptionInfo *exception) |
366 | | % |
367 | | % A description of each parameter follows. |
368 | | % |
369 | | % o file: An pointer to a FILE. |
370 | | % |
371 | | % o exception: Return any errors or warnings in this structure. |
372 | | % |
373 | | % |
374 | | */ |
375 | | MagickExport MagickPassFail |
376 | | ListMagicInfo(FILE *file,ExceptionInfo *exception) |
377 | 0 | { |
378 | 0 | #define NAME_HEADER "Name" |
379 | 0 | #define DESCRIPTION_HEADER "Description" |
380 | 0 | #define OFFSET_HEADER "Offset" |
381 | 0 | #define TARGET_HEADER "Target" |
382 | 0 | #define OFFSET_TARGET_HEADER "Offset Target" |
383 | |
|
384 | 0 | const size_t |
385 | 0 | description_size=sizeof(DESCRIPTION_HEADER)-1, |
386 | 0 | name_size=sizeof(NAME_HEADER)-1, |
387 | 0 | offset_size=sizeof(OFFSET_HEADER)-1, |
388 | 0 | target_size=sizeof(TARGET_HEADER)-1; |
389 | |
|
390 | 0 | size_t |
391 | 0 | description_size_max=description_size, |
392 | 0 | name_size_max=name_size, |
393 | 0 | offset_size_max=offset_size, |
394 | 0 | target_size_max=Max(target_size,16); |
395 | |
|
396 | 0 | register size_t |
397 | 0 | i, |
398 | 0 | j; |
399 | |
|
400 | 0 | for (i=0; i < ArraySize(StaticMagic); i++) |
401 | 0 | { |
402 | 0 | if (description_size_max < StaticMagic[i].description_size) |
403 | 0 | description_size_max = StaticMagic[i].description_size; |
404 | 0 | if (name_size_max < StaticMagic[i].name_size) |
405 | 0 | name_size_max = StaticMagic[i].name_size; |
406 | | /* The following does not account for control code expansion */ |
407 | 0 | if (target_size_max < StaticMagic[i].length) |
408 | 0 | target_size_max = StaticMagic[i].length; |
409 | 0 | } |
410 | |
|
411 | 0 | ARG_NOT_USED(exception); |
412 | |
|
413 | 0 | if (file == (const FILE *) NULL) |
414 | 0 | file=stdout; |
415 | |
|
416 | 0 | (void) fprintf(file,"%s",NAME_HEADER); |
417 | 0 | for (j=name_size; j <= name_size_max; j++) |
418 | 0 | (void) fprintf(file," "); |
419 | |
|
420 | 0 | (void) fprintf(file,"%s",DESCRIPTION_HEADER); |
421 | 0 | for (j=description_size; j <= description_size_max; j++) |
422 | 0 | (void) fprintf(file," "); |
423 | |
|
424 | 0 | (void) fprintf(file,"%s",OFFSET_HEADER); |
425 | 0 | for (j=offset_size; j <= offset_size_max; j++) |
426 | 0 | (void) fprintf(file," "); |
427 | |
|
428 | 0 | (void) fprintf(file,"%s",TARGET_HEADER); |
429 | 0 | for (j=target_size; j <= target_size_max; j++) |
430 | 0 | (void) fprintf(file," "); |
431 | 0 | (void) fprintf(file,"\n"); |
432 | |
|
433 | 0 | for (j=0; j <= (name_size_max+1+description_size_max+1+offset_size_max+1+target_size_max+1); j++) |
434 | 0 | (void) fprintf(file,"-"); |
435 | 0 | (void) fprintf(file,"\n"); |
436 | |
|
437 | 0 | for (i=0; i < ArraySize(StaticMagic); i++) |
438 | 0 | { |
439 | 0 | register const unsigned char |
440 | 0 | *c; |
441 | |
|
442 | 0 | (void) fprintf(file,"%.*s",(int) name_size_max,StaticMagic[i].name); |
443 | 0 | for (j= (unsigned int) strlen(StaticMagic[i].name); j <= name_size_max; j++) |
444 | 0 | (void) fprintf(file," "); |
445 | 0 | (void) fprintf(file,"%.*s",(int) description_size_max,StaticMagic[i].description); |
446 | 0 | for (j= (unsigned int) strlen(StaticMagic[i].description); j <= description_size_max; j++) |
447 | 0 | (void) fprintf(file," "); |
448 | 0 | (void) fprintf(file,"%6u ",StaticMagic[i].offset); |
449 | |
|
450 | 0 | (void) fprintf(file,"\""); |
451 | 0 | c=StaticMagic[i].magic; |
452 | 0 | for (j=0; j < StaticMagic[i].length; j++) |
453 | 0 | { |
454 | | /* else if ('\b' == c[j]) */ |
455 | | /* (void) fprintf(file,"\\b"); */ |
456 | | /* else if ('\f' == c[j]) */ |
457 | | /* (void) fprintf(file,"\\f"); */ |
458 | 0 | if ('\n' == c[j]) |
459 | 0 | (void) fprintf(file,"\\n"); |
460 | 0 | else if ('\r' == c[j]) |
461 | 0 | (void) fprintf(file,"\\r"); |
462 | 0 | else if ('\t' == c[j]) |
463 | 0 | (void) fprintf(file,"\\t"); |
464 | | /* else if ('\v' == c[j]) */ |
465 | | /* (void) fprintf(file,"\\v"); */ |
466 | | /* else if ('\a' == c[j]) */ |
467 | | /* (void) fprintf(file,"\\a"); */ |
468 | 0 | else if ('\\' == c[j]) |
469 | 0 | (void) fprintf(file,"\\"); |
470 | 0 | else if ('\?' == c[j]) |
471 | 0 | (void) fprintf(file,"\\?"); |
472 | 0 | else if ('"' == c[j]) |
473 | 0 | (void) fprintf(file,"\\\""); |
474 | 0 | else if (isprint((int) c[j])) |
475 | 0 | (void) fprintf(file,"%c",(int) c[j]); |
476 | 0 | else |
477 | 0 | { |
478 | 0 | (void) fprintf(file,"\\%03o",c[j]); |
479 | 0 | } |
480 | 0 | } |
481 | 0 | (void) fprintf(file,"\"\n"); |
482 | 0 | } |
483 | 0 | (void) fflush(file); |
484 | 0 | return(MagickPass); |
485 | 0 | } |