forked from wuyongzheng/gimgtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gimginfo.c
59 lines (51 loc) · 1.01 KB
/
gimginfo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "gimglib.h"
static void usage (void)
{
printf("Usage gimginfo [options] imgfile [subfile]\n");
}
int main (int argc, char **argv)
{
char *img_path = NULL;
char *subfile_name = NULL;
struct gimg_struct *img;
int i;
for (i = 1; i < argc; i ++) {
if (strcmp(argv[i], "-h") == 0 ||
strcmp(argv[i], "--help") == 0 ||
strcmp(argv[i], "-?") == 0) {
usage();
return 0;
} else if (argv[i][0] == '-') {
printf("unknown option %s\n", argv[i]);
usage();
return 1;
} else {
if (img_path == NULL)
img_path = argv[i];
else if (subfile_name == NULL)
subfile_name = argv[i];
else {
printf("only one subfile please.\n");
usage();
return 1;
}
}
}
if (img_path == NULL) {
printf("no img file specified\n");
usage();
return 1;
}
img = gimg_open(img_path, 0);
if (img == NULL) {
printf("failed to open or parse %s\n", img_path);
return 1;
}
if (subfile_name) {
dump_subfile(img, subfile_name);
} else {
dump_img(img);
}
gimg_close(img);
return 0;
}