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>
51 int main(int argc, char **argv)
61 while ((c = getopt(argc, argv, "o:")) != EOF) {
65 outfile = strdup(optarg);
75 if (argv[c][0]=='-') {
76 if (argv[c][1]=='o') {
77 if ( ((c+1)<argc) && (argv[c+1]) ) {
78 outfile = strdup(argv[c+1]);
91 if (outfile == NULL) {
92 printf("You must specify output filename with -o\n");
96 printf("You must specify some files to pack, duh\n");
101 /* prepare to pack things - get sizes and calculate offsets */
102 printf("%u files to pack\n", num_entries);
103 datafile = calloc(num_entries, sizeof(DirEntry));
105 /* skip past the directory structure */
106 offset = 4 + (num_entries * 20);
108 for (i = 0; i < num_entries; i++) {
110 if (stat(argv[i], &dummy)) {
111 fprintf(stderr, "%s is not accessible: ", argv[i]);
115 if (strlen(argv[i]) > 12) {
116 fprintf(stderr, "filename %s is longer than 12 chars\n", argv[i]);
119 strncpy(datafile[i].filename, argv[i], 12);
120 datafile[i].size = dummy.st_size;
121 /* num_entries * (12 + 8) */
122 datafile[i].offset = offset;
123 offset += datafile[i].size;
126 /* here, we checked that all files are ok, and ready to roll the packfile */
127 fd = open(outfile, O_RDWR | O_CREAT | O_BINARY, 0644);
129 perror("opening packfile");
132 printf("Opened %s\n", outfile);
134 /* write number of entries in this data file */
135 write(fd, &num_entries, 4);
137 /* write the directory structure */
138 for (i = 0; i < num_entries; i++) {
139 write(fd, &datafile[i], 20);
142 /* write in the actual files */
143 for (i = 0; i < num_entries; i++) {
147 printf("adding %s ", argv[i]);
149 infd = open(argv[i], O_RDONLY | O_BINARY);
151 perror("opening file");
154 buf = malloc(datafile[i].size + 16);
155 read(infd, buf, datafile[i].size);
157 write(fd, buf, datafile[i].size);