2 * Written 1999 Jan 29 by Josh Cogliati
3 * Modified by Bradley Bell, 2002, 2003
4 * This program is licensed under the terms of the GPL, version 2 or later
14 #include <sys/types.h>
21 #define SWAPINT(x) (((x)<<24) | (((uint)(x)) >> 24) | (((x) &0x0000ff00) << 8) | (((x) & 0x00ff0000) >> 8))
24 main(int argc, char *argv[])
26 FILE *mvlfile, *readfile;
29 int i, nfiles = 0, len[MAX_FILES], tmp;
30 char filename[MAX_FILES][13];
35 printf("Usage: mvlcreate mvlfile\n"
36 "creates mvlfile using all the files in the current directory\n");
42 while ((ep = readdir(dp))) {
43 if (strlen(ep->d_name) > 12) {
44 fprintf(stderr, "error: filename %s too long! (12 chars max!)\n", ep->d_name);
47 memset(filename[nfiles], 0, 13);
48 strcpy(filename[nfiles], ep->d_name);
49 stat(filename[nfiles], &statbuf);
50 if(! S_ISDIR(statbuf.st_mode)) {
51 len[nfiles] = (int)statbuf.st_size;
52 printf("Filename: %s \tLength: %i\n", filename[nfiles], len[nfiles]);
59 printf("Creating: %s\n", argv[1]);
60 mvlfile = fopen(argv[1], "wb");
61 buf = (char *)malloc(4);
62 strncpy(buf, "DMVL", 4);
63 fwrite(buf, 4, 1, mvlfile);
67 #ifdef WORDS_BIGENDIAN
70 fwrite(&tmp, 4, 1, mvlfile);
72 for (i = 0; i < nfiles; i++) {
73 fwrite(filename[i], 13, 1, mvlfile);
75 #ifdef WORDS_BIGENDIAN
78 fwrite(&tmp, 4, 1, mvlfile);
81 for (i = 0; i < nfiles; i++) {
82 readfile = fopen(filename[i], "rb");
83 buf = (char *)malloc(len[i]);
85 printf("Unable to allocate memory\n");
87 fread(buf, len[i], 1, readfile);
88 fwrite(buf, len[i], 1, mvlfile);