]> icculus.org git repositories - btb/d2x.git/blob - utilities/mvlcreate.c
use the orientation parameter of g3_draw_bitmap
[btb/d2x.git] / utilities / mvlcreate.c
1 /*
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
5  */
6
7 #ifdef HAVE_CONFIG_H
8 #include <conf.h>
9 #endif
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <sys/types.h>
15 #include <sys/stat.h>
16 #include <fcntl.h>
17 #include <dirent.h>
18
19 #define MAX_FILES 256
20
21 #define SWAPINT(x)   (((x)<<24) | (((uint)(x)) >> 24) | (((x) &0x0000ff00) << 8) | (((x) & 0x00ff0000) >> 8))
22
23 int
24 main(int argc, char *argv[])
25 {
26         FILE *mvlfile, *readfile;
27         DIR *dp;
28         struct dirent *ep;
29         int i, nfiles = 0, len[MAX_FILES], tmp;
30         char filename[MAX_FILES][13];
31         char *buf;
32         struct stat statbuf;
33
34         if (argc != 2) {
35                 printf("Usage: mvlcreate mvlfile\n"
36                        "creates mvlfile using all the files in the current directory\n");
37                 exit(0);
38         }
39
40         dp = opendir("./");
41         if (dp != NULL) {
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);
45                                 return 1;
46                         }
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]);
53                                 nfiles++;
54                         }
55                 }
56         }
57         closedir(dp);
58
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);
64         free(buf);
65
66         tmp = nfiles;
67 #ifdef WORDS_BIGENDIAN
68         tmp = SWAPINT(tmp);
69 #endif
70         fwrite(&tmp, 4, 1, mvlfile);
71
72         for (i = 0; i < nfiles; i++) {
73                 fwrite(filename[i], 13, 1, mvlfile);
74                 tmp = len[i];
75 #ifdef WORDS_BIGENDIAN
76                 tmp = SWAPINT(tmp);
77 #endif
78                 fwrite(&tmp, 4, 1, mvlfile);
79         }
80
81         for (i = 0; i < nfiles; i++) {
82                 readfile = fopen(filename[i], "rb");
83                 buf = (char *)malloc(len[i]);
84                 if (buf == NULL) {
85                         printf("Unable to allocate memory\n");
86                 } else {
87                         fread(buf, len[i], 1, readfile);
88                         fwrite(buf, len[i], 1, mvlfile);
89                 }
90                 fclose(readfile);
91         }
92
93         fclose(mvlfile);
94
95         return 0;
96 }