3 * Copyright (C) 1998 Brainchild Design - http://brainchilddesign.com/
5 * Copyright (C) 2001 "timecop" <timecop@japan.co.jp>
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>
55 int main(int argc, char **argv)
65 while ((c = getopt(argc, argv, "o:")) != EOF) {
69 outfile = strdup(optarg);
79 if (argv[c][0]=='-') {
80 if (argv[c][1]=='o') {
81 if ( ((c+1)<argc) && (argv[c+1]) ) {
82 outfile = strdup(argv[c+1]);
95 if (outfile == NULL) {
96 printf("You must specify output filename with -o\n");
100 printf("You must specify some files to pack, duh\n");
105 /* prepare to pack things - get sizes and calculate offsets */
106 printf("%u files to pack\n", num_entries);
107 datafile = calloc(num_entries, sizeof(DirEntry));
109 /* skip past the directory structure */
110 offset = 4 + (num_entries * 20);
112 for (i = 0; i < num_entries; i++) {
114 if (stat(argv[i], &dummy)) {
115 fprintf(stderr, "%s is not accessible: ", argv[i]);
119 if (strlen(argv[i]) > 12) {
120 fprintf(stderr, "filename %s is longer than 12 chars\n", argv[i]);
123 strncpy(datafile[i].filename, argv[i], 12);
124 datafile[i].size = dummy.st_size;
125 /* num_entries * (12 + 8) */
126 datafile[i].offset = offset;
127 offset += datafile[i].size;
130 /* here, we checked that all files are ok, and ready to roll the packfile */
131 fd = open(outfile, O_RDWR | O_CREAT | O_BINARY, 0644);
133 perror("opening packfile");
136 printf("Opened %s\n", outfile);
138 /* write number of entries in this data file */
142 temp = (num_entries >> 0) & 0xff;
144 temp = (num_entries >> 8) & 0xff;
146 temp = (num_entries >> 16) & 0xff;
148 temp = (num_entries >> 24) & 0xff;
152 /* write the directory structure */
153 for (i = 0; i < num_entries; i++) {
156 write(fd, &datafile[i].filename, 12);
157 temp = (datafile[i].offset >> 0) & 0xff;
159 temp = (datafile[i].offset >> 8) & 0xff;
161 temp = (datafile[i].offset >> 16) & 0xff;
163 temp = (datafile[i].offset >> 24) & 0xff;
165 temp = (datafile[i].size >> 0) & 0xff;
167 temp = (datafile[i].size >> 8) & 0xff;
169 temp = (datafile[i].size >> 16) & 0xff;
171 temp = (datafile[i].size >> 24) & 0xff;
175 /* write in the actual files */
176 for (i = 0; i < num_entries; i++) {
180 printf("adding %s ", argv[i]);
182 infd = open(argv[i], O_RDONLY | O_BINARY);
184 perror("opening file");
187 buf = malloc(datafile[i].size + 16);
188 read(infd, buf, datafile[i].size);
190 write(fd, buf, datafile[i].size);