changeset 728:8e7f6cca385b

tiffs-8m wrapper utility written
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 28 Aug 2020 05:03:54 +0000
parents ed983d4040a8
children f917441aa8bc
files .hgignore ffstools/tiffs-wrappers/Makefile ffstools/tiffs-wrappers/tiffs-8m.c
diffstat 3 files changed, 99 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Fri Aug 28 03:45:03 2020 +0000
+++ b/.hgignore	Fri Aug 28 05:03:54 2020 +0000
@@ -19,6 +19,7 @@
 ^ffstools/tiffs-rd/tiffs$
 ^ffstools/tiffs-wrappers/mokoffs$
 ^ffstools/tiffs-wrappers/pirffs$
+^ffstools/tiffs-wrappers/tiffs-8m$
 
 ^loadtools/fc-buzplay$
 ^loadtools/fc-compalram$
--- a/ffstools/tiffs-wrappers/Makefile	Fri Aug 28 03:45:03 2020 +0000
+++ b/ffstools/tiffs-wrappers/Makefile	Fri Aug 28 05:03:54 2020 +0000
@@ -1,6 +1,6 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	mokoffs pirffs
+PROGS=	mokoffs pirffs tiffs-8m
 
 INSTALL_PREFIX=	/opt/freecalypso
 
@@ -8,6 +8,7 @@
 
 MOKOFFS_OBJS=	installpath.o mokoffs.o
 PIRFFS_OBJS=	installpath.o pirffs.o
+TIFFS8M_OBJS=	installpath.o tiffs-8m.o
 
 all:	${PROGS}
 
@@ -17,6 +18,9 @@
 pirffs:		${PIRFFS_OBJS}
 	${CC} ${CFLAGS} -o $@ ${PIRFFS_OBJS}
 
+tiffs-8m:	${TIFFS8M_OBJS}
+	${CC} ${CFLAGS} -o $@ ${TIFFS8M_OBJS}
+
 install:	${PROGS}
 	mkdir -p ${INSTBIN}
 	install -c ${PROGS} ${INSTBIN}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ffstools/tiffs-wrappers/tiffs-8m.c	Fri Aug 28 05:03:54 2020 +0000
@@ -0,0 +1,93 @@
+/*
+ * tiffs-8m is a wrapper around tiffs similar to mokoffs: we pass the user's
+ * command along, together with any options, but insert the 64x15 FFS
+ * organization argument automatically, and translate -f into -o0x700000.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <unistd.h>
+
+extern char tiffs_prog_pathname[];
+
+char *imgfile;
+char *aopt, *ropt;
+int fflag, Oflag;
+char **passon_argv;
+int passon_argc;
+int output_argc;
+char **output_argv;
+
+main(argc, argv)
+	char **argv;
+{
+	extern int optind;
+	extern char *optarg;
+	int c;
+	char **sp, **dp;
+
+	while ((c = getopt(argc, argv, "+a:fOr:")) != EOF)
+		switch (c) {
+		case 'a':
+			aopt = optarg;
+			continue;
+		case 'f':
+			fflag++;
+			continue;
+		case 'O':
+			Oflag++;
+			continue;
+		case 'r':
+			ropt = optarg;
+			continue;
+		default:
+usage:			fprintf(stderr,
+			"usage: %s [global-options] <imgfile> <op> ...\n",
+				argv[0]);
+			exit(1);
+		}
+	if (argc - optind < 2)
+		goto usage;
+	imgfile = argv[optind++];
+	passon_argv = argv + optind;
+	passon_argc = argc - optind;
+
+	output_argc = passon_argc + 3;
+	if (fflag)
+		output_argc++;
+	if (Oflag)
+		output_argc++;
+	if (aopt)
+		output_argc += 2;
+	if (ropt)
+		output_argc += 2;
+	output_argv = malloc(sizeof(char *) * (output_argc + 1));
+	if (!output_argv) {
+		perror("malloc for tiffs argument list");
+		exit(1);
+	}
+	dp = output_argv;
+	*dp++ = "tiffs";
+	if (fflag)
+		*dp++ = "-o0x700000";
+	if (Oflag)
+		*dp++ = "-O";
+	if (aopt) {
+		*dp++ = "-a";
+		*dp++ = aopt;
+	}
+	if (ropt) {
+		*dp++ = "-r";
+		*dp++ = ropt;
+	}
+	*dp++ = imgfile;
+	*dp++ = "64x15";
+	for (sp = passon_argv; *sp; sp++)
+		*dp++ = *sp;
+	*dp = 0;
+	execvp(tiffs_prog_pathname, output_argv);
+	perror(tiffs_prog_pathname);
+	exit(1);
+}