3 * Copyright (C) 1998 Brainchild Design - http://brainchilddesign.com/
5 * Copyright (C) 2001 tarzeau@space.ch
7 * Copyright (C) 2002 Florian Schulze - crow@icculus.org
9 * Portions of this code are from the MPEG software simulation group
10 * idct implementation. This code will be replaced with a new
11 * implementation soon.
13 * This file is part of Jump'n'Bump.
15 * Jump'n'Bump is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * Jump'n'Bump is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #include <sys/types.h>
41 typedef unsigned int u_int32_t;
50 int main(int argc, char **argv)
60 while ((c = getopt(argc, argv, "o:")) != EOF) {
64 outfile = strdup(optarg);
74 if (argv[c][0]=='-') {
75 if (argv[c][1]=='o') {
76 if ( ((c+1)<argc) && (argv[c+1]) ) {
77 outfile = strdup(argv[c+1]);
90 if (outfile == NULL) {
91 printf("You must specify output filename with -o\n");
95 printf("You must specify some files to pack, duh\n");
100 /* prepare to pack things - get sizes and calculate offsets */
101 printf("%u files to pack\n", num_entries);
102 datafile = calloc(num_entries, sizeof(DirEntry));
104 /* skip past the directory structure */
105 offset = 4 + (num_entries * 20);
107 for (i = 0; i < num_entries; i++) {
109 if (stat(argv[i], &dummy)) {
110 fprintf(stderr, "%s is not accessible: ", argv[i]);
114 if (strlen(argv[i]) > 12) {
115 fprintf(stderr, "filename %s is longer than 12 chars\n", argv[i]);
118 strncpy(datafile[i].filename, argv[i], 12);
119 datafile[i].size = dummy.st_size;
120 /* num_entries * (12 + 8) */
121 datafile[i].offset = offset;
122 offset += datafile[i].size;
125 /* here, we checked that all files are ok, and ready to roll the packfile */
126 fd = open(outfile, O_RDWR | O_CREAT | O_BINARY, 0644);
128 perror("opening packfile");
131 printf("Opened %s\n", outfile);
133 /* write number of entries in this data file */
134 write(fd, &num_entries, 4);
136 /* write the directory structure */
137 for (i = 0; i < num_entries; i++) {
138 write(fd, &datafile[i], 20);
141 /* write in the actual files */
142 for (i = 0; i < num_entries; i++) {
146 printf("adding %s ", argv[i]);
148 infd = open(argv[i], O_RDONLY | O_BINARY);
150 perror("opening file");
153 buf = malloc(datafile[i].size + 16);
154 read(infd, buf, datafile[i].size);
156 write(fd, buf, datafile[i].size);