Debian Codegraph @

src/checkit_tiff_risk.c

raw
1 /* 'checkit_tiff' is a conformance checker for baseline TIFFs
2 *
3 * author: Andreas Romeyke, 2015-2022
4 * licensed under conditions of libtiff
5 * (see http://libtiff.maptools.org/misc.html)
6 *
7 */
8
9 #include "check.h"
10 #include "check_helper.h"
11 #include "risk_analyzer.h"
12 #include <ctype.h>
13 #include <stdio.h>
14 #ifdef __unix__
15 #else
16 /* #include <sys\stat.h> */
17 #include <sys/stat.h>
18 #endif
19
20 /** help function */
21 static void help (void) {
22 printf ("checkit_tiff_risk\n");
23 printf("licensed under conditions of libtiff (see http://libtiff.maptools.org/misc.html)\n\n");
24 printf ("call it with:\n");
25 printf ("\tcheckit_tiff_risk [-m|-h|-s] <tifffile>\n");
26 printf ("\nwhere <tifffile> is the tiff file\n");
27 printf ("\t-h this help\n");
28 printf ("\t-m prints a memory map\n");
29 printf ("\t-s prints statistics\n");
30 printf ("example:\n\tcheckit_tiff -m tiffs_should_pass/minimal_valid.tiff\n");
31 printf ("\n");
32 }
33
34
35 /* *********** main ************* */
36 int main(int argc, char * argv[]) {
37 int c;
38 int flag_print_map = UNFLAGGED;
39 int flag_print_stats = UNFLAGGED;
40 while ((c = getopt (argc, argv, "hms")) != -1) {
41 switch (c)
42 {
43 case 'h': /* help */
44 help();
45 exit (0);
46 case 'm': /* mem map */
47 flag_print_map = FLAGGED;
48 break;
49 case 's': /* stats */
50 flag_print_stats = FLAGGED;
51 break;
52 case '?': /* something goes wrong */
53 if (isprint (optopt)) {
54 fprintf (stderr, "Unknown option `-%c'.\n", optopt);
55 return (-1);
56 } else if (0 !=optopt) {
57 fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt);
58 return (-1);
59 }
60 break;
61 default:
62 abort();
63 }
64
65
66 }
67 if (argc - optind != 1) {
68 help();
69 fprintf( stderr, "%s needs at least one arguments, example:\n\t %s tiffs_should_pass/minimal_valid.tiff\n", argv[0], argv[0]);
70 exit (EXIT_FAILURE);
71 }
72 const char *tiff_file=argv[optind];
73 ctiff_t * ctif = initialize_ctif( tiff_file, is_filep );
74 parse_header_and_endianess( ctif );
75 uint32 offset;
76 ret_t res=get_first_IFD(ctif, &offset);
77 if (res.returncode == is_valid) {
78 mem_map_t * memmap_p = scan_mem_map(ctif);
79 if (FLAGGED == flag_print_map) {
80 print_mem_map ( memmap_p );
81 }
82 if (FLAGGED == flag_print_stats) {
83 print_mem_stats( memmap_p );
84 }
85 return (EXIT_SUCCESS);
86 } else {
87 return (EXIT_FAILURE);
88 }
89 }
90
91 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 smarttab expandtab :*/