comparison ffstools/tiffs-wrappers/pirffs.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 * pirffs is a wrapper around tiffs: we pass the user's command along,
3 * together with any options, but insert the 256x18 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 char **passon_argv;
18 int passon_argc;
19 int output_argc;
20 char **output_argv;
21
22 main(argc, argv)
23 char **argv;
24 {
25 extern int optind;
26 extern char *optarg;
27 int c;
28 char **sp, **dp;
29
30 while ((c = getopt(argc, argv, "+a:r:")) != EOF)
31 switch (c) {
32 case 'a':
33 aopt = optarg;
34 continue;
35 case 'r':
36 ropt = optarg;
37 continue;
38 default:
39 usage: fprintf(stderr,
40 "usage: %s [global-options] <imgfile> <op> ...\n",
41 argv[0]);
42 exit(1);
43 }
44 if (argc - optind < 2)
45 goto usage;
46 imgfile = argv[optind++];
47 passon_argv = argv + optind;
48 passon_argc = argc - optind;
49
50 output_argc = passon_argc + 3;
51 if (aopt)
52 output_argc += 2;
53 if (ropt)
54 output_argc += 2;
55 output_argv = malloc(sizeof(char *) * (output_argc + 1));
56 if (!output_argv) {
57 perror("malloc for tiffs argument list");
58 exit(1);
59 }
60 dp = output_argv;
61 *dp++ = "tiffs";
62 if (aopt) {
63 *dp++ = "-a";
64 *dp++ = aopt;
65 }
66 if (ropt) {
67 *dp++ = "-r";
68 *dp++ = ropt;
69 }
70 *dp++ = imgfile;
71 *dp++ = "256x18";
72 for (sp = passon_argv; *sp; sp++)
73 *dp++ = *sp;
74 *dp = 0;
75 execvp(tiffs_prog_pathname, output_argv);
76 perror(tiffs_prog_pathname);
77 exit(1);
78 }