annotate ffstools/tiffs-wrappers/mokoffs.c @ 843:7666dd5df2bc

gsm-fw: libgdi.a added to the link with CONFIG_INCLUDE_PS gtamodem-gsm build almost passes, now only CST is missing
author Space Falcon <falcon@ivan.Harhan.ORG>
date Sat, 25 Apr 2015 19:49:37 +0000
parents 48a254ca4493
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
244
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * mokoffs is a wrapper around tiffs: we pass the user's command along,
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * together with any options, but insert the 64x7 FFS organization argument
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 * automatically.
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 */
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdio.h>
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdlib.h>
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <string.h>
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <strings.h>
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <unistd.h>
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 extern char tiffs_prog_pathname[];
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 char *imgfile;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 char *aopt, *ropt;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 int fflag;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 char **passon_argv;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 int passon_argc;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 int output_argc;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 char **output_argv;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 main(argc, argv)
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 char **argv;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 {
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 extern int optind;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 extern char *optarg;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 int c;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 char **sp, **dp;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 while ((c = getopt(argc, argv, "+a:fr:")) != EOF)
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 switch (c) {
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 case 'a':
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 aopt = optarg;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 continue;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 case 'f':
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 fflag++;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 continue;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 case 'r':
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 ropt = optarg;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 continue;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 default:
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 usage: fprintf(stderr,
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 "usage: %s [global-options] <imgfile> <op> ...\n",
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 argv[0]);
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 exit(1);
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 }
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 if (argc - optind < 2)
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 goto usage;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 imgfile = argv[optind++];
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 passon_argv = argv + optind;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 passon_argc = argc - optind;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 output_argc = passon_argc + 3;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 if (fflag)
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 output_argc++;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 if (aopt)
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 output_argc += 2;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 if (ropt)
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 output_argc += 2;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 output_argv = malloc(sizeof(char *) * (output_argc + 1));
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 if (!output_argv) {
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 perror("malloc for tiffs argument list");
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 exit(1);
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 }
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 dp = output_argv;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 *dp++ = "tiffs";
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 if (fflag)
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 *dp++ = "-o0x380000";
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 if (aopt) {
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 *dp++ = "-a";
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 *dp++ = aopt;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 }
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 if (ropt) {
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 *dp++ = "-r";
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 *dp++ = ropt;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 }
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 *dp++ = imgfile;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 *dp++ = "64x7";
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 for (sp = passon_argv; *sp; sp++)
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 *dp++ = *sp;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 *dp = 0;
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 execvp(tiffs_prog_pathname, output_argv);
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 perror(tiffs_prog_pathname);
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 exit(1);
48a254ca4493 TIFFS IVA: mokoffs wrapper written
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 }