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 if ( fread(buf, 4, 1, mvlfile) != 1 ||
47 fread(&nfiles, 4, 1, mvlfile) != 1 ) {
48 printf("Error reading %s\n", argv[1]);
52 printf("%d files\n", nfiles);
53 if (nfiles > MAX_FILES) { // must be a bigendian mvl
54 fprintf(stderr, "warning: nfiles>%d, trying reverse byte order...",
59 nfiles = SWAPINT(nfiles);
60 printf("Extracting from: %s\n", argv[1]);
62 for (i = 0; i < nfiles; i++) {
63 if ( fread(filename[i], 13, 1, mvlfile) != 1 ||
64 fread(&len[i], 4, 1, mvlfile) != 1 ) {
65 printf("Error reading %s\n", argv[1]);
70 len[i] = SWAPINT(len[i]);
71 if (argc == 2 || !strcmp(argv[2], filename[i]))
72 printf("Filename: %s \tLength: %i\n", filename[i], len[i]);
76 for (i = 0; i < nfiles; i++) {
77 if (argc > 2 && strcmp(argv[2], filename[i]))
78 fseek(mvlfile, len[i], SEEK_CUR);
80 if (ftell(mvlfile) > statbuf.st_size) {
81 printf("Error, end of file\n");
84 buf = (char *)malloc(len[i]);
86 printf("Unable to allocate memory\n");
88 if ( fread(buf, len[i], 1, mvlfile) != 1 ) {
89 printf("Error reading %s\n", argv[1]);
93 writefile = fopen(filename[i], "wb");
94 fwrite(buf, len[i], 1, writefile);