comparison ffstools/tiffs-wrappers/tiffs-8m.c @ 728:8e7f6cca385b

tiffs-8m wrapper utility written
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 28 Aug 2020 05:03:54 +0000
parents
children
comparison
equal deleted inserted replaced
727:ed983d4040a8 728:8e7f6cca385b
1 /*
2 * tiffs-8m is a wrapper around tiffs similar to mokoffs: we pass the user's
3 * command along, together with any options, but insert the 64x15 FFS
4 * organization argument automatically, and translate -f into -o0x700000.
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, Oflag;
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:fOr:")) != EOF)
32 switch (c) {
33 case 'a':
34 aopt = optarg;
35 continue;
36 case 'f':
37 fflag++;
38 continue;
39 case 'O':
40 Oflag++;
41 continue;
42 case 'r':
43 ropt = optarg;
44 continue;
45 default:
46 usage: fprintf(stderr,
47 "usage: %s [global-options] <imgfile> <op> ...\n",
48 argv[0]);
49 exit(1);
50 }
51 if (argc - optind < 2)
52 goto usage;
53 imgfile = argv[optind++];
54 passon_argv = argv + optind;
55 passon_argc = argc - optind;
56
57 output_argc = passon_argc + 3;
58 if (fflag)
59 output_argc++;
60 if (Oflag)
61 output_argc++;
62 if (aopt)
63 output_argc += 2;
64 if (ropt)
65 output_argc += 2;
66 output_argv = malloc(sizeof(char *) * (output_argc + 1));
67 if (!output_argv) {
68 perror("malloc for tiffs argument list");
69 exit(1);
70 }
71 dp = output_argv;
72 *dp++ = "tiffs";
73 if (fflag)
74 *dp++ = "-o0x700000";
75 if (Oflag)
76 *dp++ = "-O";
77 if (aopt) {
78 *dp++ = "-a";
79 *dp++ = aopt;
80 }
81 if (ropt) {
82 *dp++ = "-r";
83 *dp++ = ropt;
84 }
85 *dp++ = imgfile;
86 *dp++ = "64x15";
87 for (sp = passon_argv; *sp; sp++)
88 *dp++ = *sp;
89 *dp = 0;
90 execvp(tiffs_prog_pathname, output_argv);
91 perror(tiffs_prog_pathname);
92 exit(1);
93 }