added mvl utilities
authorBradley Bell <btb@icculus.org>
Mon, 26 Aug 2002 08:06:28 +0000 (08:06 +0000)
committerBradley Bell <btb@icculus.org>
Mon, 26 Aug 2002 08:06:28 +0000 (08:06 +0000)
utilities/Makefile.am
utilities/mvlcreate.c [new file with mode: 0644]
utilities/mvlextract.c [new file with mode: 0644]

index 313cc56..a61d1eb 100644 (file)
@@ -1,9 +1,13 @@
-bin_PROGRAMS = hogcreate hogextract txb2txt txt2txb
+bin_PROGRAMS = hogcreate hogextract mvlcreate mvlextract txb2tex tex2txb
 
 hogcreate_SOURCES = hogcreate.c
 
 hogextract_SOURCES = hogextract.c
 
-txb2txt_SOURCES = txb2txt.c
+mvlcreate_SOURCES = mvlcreate.c
 
-txt2txb_SOURCES = txt2txb.c
+mvlextract_SOURCES = mvlextract.c
+
+txb2tex_SOURCES = txb2tex.c
+
+tex2txb_SOURCES = tex2txb.c
diff --git a/utilities/mvlcreate.c b/utilities/mvlcreate.c
new file mode 100644 (file)
index 0000000..2649d5f
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Written 1999 Jan 29 by Josh Cogliati
+ * I grant this program to public domain.
+ *
+ * Modified for mvl by Bradley Bell, 2002
+ * All modifications under GPL, version 2 or later
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <dirent.h>
+
+#define MAX_FILES 256
+
+int
+main(int argc, char *argv[])
+{
+       FILE *mvlfile, *readfile;
+       DIR *dp;
+       struct dirent *ep;
+       int i, nfiles = 0, len[MAX_FILES];
+       char filename[MAX_FILES][13];
+       char *buf;
+       struct stat statbuf;
+
+       if (argc != 2) {
+               printf("Usage: mvlcreate mvlfile\n"
+                      "creates mvlfile using all the files in the current directory\n");
+               exit(0);
+       }
+
+       dp = opendir("./");
+       if (dp != NULL) {
+               while ((ep = readdir(dp))) {
+                       strcpy(filename[i], ep->d_name);
+                       stat(filename[i], &statbuf);
+                       if(! S_ISDIR(statbuf.st_mode)) {
+                               nfiles++;
+                               len[i] = (int)statbuf.st_size;
+                               printf("Filename: %s \tLength: %i\n", filename[i], len[i]);
+                       }
+               }
+       }
+       closedir(dp);
+
+       printf("Creating: %s\n", argv[1]);
+       mvlfile = fopen(argv[1], "w");
+       buf = (char *)malloc(4);
+       strncpy(buf, "DMVL", 4);
+       fwrite(buf, 4, 1, mvlfile);
+       free(buf);
+
+       fwrite(&nfiles, 4, 1, mvlfile);
+
+       for (i = 0; i < nfiles; i++) {
+               fwrite(filename[i], 13, 1, mvlfile);
+               fwrite(&len[i], 4, 1, mvlfile);
+       }
+
+       for (i = 0; i < nfiles; i++) {
+               readfile = fopen(filename[i], "r");
+               buf = (char *)malloc(len[i]);
+               if (buf == NULL) {
+                       printf("Unable to allocate memory\n");
+               } else {
+                       fread(buf, statbuf.st_size, 1, readfile);
+                       fwrite(buf, statbuf.st_size, 1, mvlfile);
+               }
+               fclose(readfile);
+       }
+
+       fclose(mvlfile);
+
+       return 0;
+}
diff --git a/utilities/mvlextract.c b/utilities/mvlextract.c
new file mode 100644 (file)
index 0000000..971a335
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Written 1999 Jan 29 by Josh Cogliati
+ * I grant this program to public domain.
+ *
+ * Modified for mvl by Bradley Bell, 2002
+ * All modifications under GPL, version 2 or later
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#define MAX_FILES 256
+
+int
+main(int argc, char *argv[])
+{
+       FILE *mvlfile, *writefile;
+       int i, nfiles, len[MAX_FILES];
+       char filename[MAX_FILES][13];
+       char *buf;
+       struct stat statbuf;
+       int v = 0;
+
+       if (argc > 1 && !strcmp(argv[1], "v")) {
+               v = 1;
+               argc--;
+               argv++;
+       }
+
+       if (argc != 2) {
+               printf("Usage: mvlextract [v] mvlfile\n"
+                      "extracts all the files in mvlfile into the current directory\n"
+                          "Options:\n"
+                          "  v    View files, don't extract\n");
+               exit(0);
+       }
+       mvlfile = fopen(argv[1], "r");
+       stat(argv[1], &statbuf);
+       printf("%i\n", (int)statbuf.st_size);
+       buf = (char *)malloc(4);
+       fread(buf, 4, 1, mvlfile);
+       fread(&nfiles, 4, 1, mvlfile);
+       printf("Extracting from: %s\n", argv[1]);
+       free(buf);
+       for (i = 0; i < nfiles; i++) {
+               fread(filename[i], 13, 1, mvlfile);
+               fread(&len[i], 4, 1, mvlfile);
+               printf("Filename: %s \tLength: %i\n", filename[i], len[i]);
+       }
+
+       if (!v) {
+               for (i = 0; i < nfiles; i++) {
+                       if (ftell(mvlfile) > statbuf.st_size) {
+                               printf("Error, end of file\n");
+                               exit(1);
+                       }
+                       buf = (char *)malloc(len[i]);
+                       if (buf == NULL) {
+                               printf("Unable to allocate memory\n");
+                       } else {
+                               fread(buf, len[i], 1, mvlfile);
+                               writefile = fopen(filename[i], "w");
+                               fwrite(buf, len[i], 1, writefile);
+                               fclose(writefile);
+                               free(buf);
+                       }
+               }
+       }
+       fclose(mvlfile);
+
+       return 0;
+}