comparison ffstools/tiffs-wrappers/mokoffs.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
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 }