annotate ffstools/tiffs-wrappers/pirffs.c @ 275:cedf09b6b5ac

started laying the foundation for fc-fsio host utility
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 23 Feb 2014 20:27:15 +0000
parents 872d92404b6a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
246
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * pirffs is a wrapper around tiffs: we pass the user's command along,
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * together with any options, but insert the 256x18 FFS organization argument
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 * automatically.
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 */
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdio.h>
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdlib.h>
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <string.h>
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <strings.h>
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <unistd.h>
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 extern char tiffs_prog_pathname[];
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 char *imgfile;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 char *aopt, *ropt;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 char **passon_argv;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 int passon_argc;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 int output_argc;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 char **output_argv;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 main(argc, argv)
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 char **argv;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 {
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 extern int optind;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 extern char *optarg;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 int c;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 char **sp, **dp;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 while ((c = getopt(argc, argv, "+a:r:")) != EOF)
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 switch (c) {
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 case 'a':
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 aopt = optarg;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 continue;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 case 'r':
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 ropt = optarg;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 continue;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 default:
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 usage: fprintf(stderr,
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 "usage: %s [global-options] <imgfile> <op> ...\n",
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 argv[0]);
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 exit(1);
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 }
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 if (argc - optind < 2)
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 goto usage;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 imgfile = argv[optind++];
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 passon_argv = argv + optind;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 passon_argc = argc - optind;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 output_argc = passon_argc + 3;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 if (aopt)
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 output_argc += 2;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 if (ropt)
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 output_argc += 2;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 output_argv = malloc(sizeof(char *) * (output_argc + 1));
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 if (!output_argv) {
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 perror("malloc for tiffs argument list");
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 exit(1);
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 }
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 dp = output_argv;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 *dp++ = "tiffs";
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 if (aopt) {
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 *dp++ = "-a";
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 *dp++ = aopt;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 }
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 if (ropt) {
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 *dp++ = "-r";
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 *dp++ = ropt;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 }
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 *dp++ = imgfile;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 *dp++ = "256x18";
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 for (sp = passon_argv; *sp; sp++)
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 *dp++ = *sp;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 *dp = 0;
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 execvp(tiffs_prog_pathname, output_argv);
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 perror(tiffs_prog_pathname);
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 exit(1);
872d92404b6a ffstools: pirffs wrapper
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 }