comparison ffstools/tiffs-wrappers/mokoffs.c @ 244:48a254ca4493

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