2 * Written 1999 Jan 29 by Josh Cogliati
3 * Modified for mvl by Bradley Bell, 2002, 2003
4 * This program is licensed under the terms of the GPL, version 2 or later
10 #include <sys/types.h>
14 #define SWAPINT(x) (((x)<<24) | (((unsigned int)(x)) >> 24) | (((x) &0x0000ff00) << 8) | (((x) & 0x00ff0000) >> 8))
19 main(int argc, char *argv[])
21 FILE *mvlfile, *writefile;
22 int i, nfiles, len[MAX_FILES];
23 char filename[MAX_FILES][13];
29 if (argc > 1 && !strcmp(argv[1], "v")) {
36 printf("Usage: mvlextract [v] mvlfile [filename]\n"
37 "extracts all the files in mvlfile into the current directory\n"
39 " v View files, don't extract\n");
42 mvlfile = fopen(argv[1], "rb");
43 stat(argv[1], &statbuf);
44 printf("%i\n", (int)statbuf.st_size);
45 buf = (char *)malloc(4);
46 fread(buf, 4, 1, mvlfile);
47 fread(&nfiles, 4, 1, mvlfile);
48 printf("%d files\n", nfiles);
49 if (nfiles > MAX_FILES) { // must be a bigendian mvl
50 fprintf(stderr, "warning: nfiles>%d, trying reverse byte order...",
55 nfiles = SWAPINT(nfiles);
56 printf("Extracting from: %s\n", argv[1]);
58 for (i = 0; i < nfiles; i++) {
59 fread(filename[i], 13, 1, mvlfile);
60 fread(&len[i], 4, 1, mvlfile);
62 len[i] = SWAPINT(len[i]);
63 if (argc == 2 || !strcmp(argv[2], filename[i]))
64 printf("Filename: %s \tLength: %i\n", filename[i], len[i]);
68 for (i = 0; i < nfiles; i++) {
69 if (argc > 2 && strcmp(argv[2], filename[i]))
70 fseek(mvlfile, len[i], SEEK_CUR);
72 if (ftell(mvlfile) > statbuf.st_size) {
73 printf("Error, end of file\n");
76 buf = (char *)malloc(len[i]);
78 printf("Unable to allocate memory\n");
80 fread(buf, len[i], 1, mvlfile);
81 writefile = fopen(filename[i], "wb");
82 fwrite(buf, len[i], 1, writefile);