annotate system/visarc.cc @ 51:cbb301016a4e

* oops... finishing what was started and not said with the other patch: fixing memory leaks
author thib
date Fri, 17 Apr 2009 18:40:39 +0000
parents 3a6aaeab7b4e
children 15a18fbe6f21
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
223b71206888 Initial import
thib
parents:
diff changeset
1 #define CMDNAME "visarc"
223b71206888 Initial import
thib
parents:
diff changeset
2 #define VERSION "1.00"
223b71206888 Initial import
thib
parents:
diff changeset
3
223b71206888 Initial import
thib
parents:
diff changeset
4 /*****************************************
223b71206888 Initial import
thib
parents:
diff changeset
5 ** Visual Arts の圧縮書庫ファイルを
223b71206888 Initial import
thib
parents:
diff changeset
6 ** 展開する
223b71206888 Initial import
thib
parents:
diff changeset
7 **
223b71206888 Initial import
thib
parents:
diff changeset
8 ** usage : visarc x <arcfile> <file> [<file> ...]
223b71206888 Initial import
thib
parents:
diff changeset
9 ** visarc l <arcfile>
223b71206888 Initial import
thib
parents:
diff changeset
10 ** visarc g <arcfile> <graphic file>
223b71206888 Initial import
thib
parents:
diff changeset
11 ** visarc m <arcfile> <mask file>
223b71206888 Initial import
thib
parents:
diff changeset
12 **
223b71206888 Initial import
thib
parents:
diff changeset
13 ******************************************
223b71206888 Initial import
thib
parents:
diff changeset
14 */
223b71206888 Initial import
thib
parents:
diff changeset
15 /*
223b71206888 Initial import
thib
parents:
diff changeset
16 *
223b71206888 Initial import
thib
parents:
diff changeset
17 * Copyright (C) 2000- Kazunori Ueno(JAGARL) <jagarl@creator.club.ne.jp>
223b71206888 Initial import
thib
parents:
diff changeset
18 *
223b71206888 Initial import
thib
parents:
diff changeset
19 * This program is free software; you can redistribute it and/or modify
223b71206888 Initial import
thib
parents:
diff changeset
20 * it under the terms of the GNU General Public License as published by
223b71206888 Initial import
thib
parents:
diff changeset
21 * the Free Software Foundation; either version 2 of the License, or
223b71206888 Initial import
thib
parents:
diff changeset
22 * (at your option) any later version.
223b71206888 Initial import
thib
parents:
diff changeset
23 *
223b71206888 Initial import
thib
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful,
223b71206888 Initial import
thib
parents:
diff changeset
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
223b71206888 Initial import
thib
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
223b71206888 Initial import
thib
parents:
diff changeset
27 * GNU General Public License for more details.
223b71206888 Initial import
thib
parents:
diff changeset
28 *
27
3a6aaeab7b4e * Fixed a typo in Jagarl's name
thib
parents: 0
diff changeset
29 * You should have received a copy of the GNU General Public License along
3a6aaeab7b4e * Fixed a typo in Jagarl's name
thib
parents: 0
diff changeset
30 * with this program; if not, write to the Free Software Foundation, Inc.,
3a6aaeab7b4e * Fixed a typo in Jagarl's name
thib
parents: 0
diff changeset
31 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0
223b71206888 Initial import
thib
parents:
diff changeset
32 *
223b71206888 Initial import
thib
parents:
diff changeset
33 */
223b71206888 Initial import
thib
parents:
diff changeset
34
223b71206888 Initial import
thib
parents:
diff changeset
35 #ifdef HAVE_CONFIG_H
223b71206888 Initial import
thib
parents:
diff changeset
36 # include "config.h"
223b71206888 Initial import
thib
parents:
diff changeset
37 #endif
223b71206888 Initial import
thib
parents:
diff changeset
38
223b71206888 Initial import
thib
parents:
diff changeset
39 #include <stdio.h>
223b71206888 Initial import
thib
parents:
diff changeset
40 #include <unistd.h>
223b71206888 Initial import
thib
parents:
diff changeset
41 #include <string.h>
223b71206888 Initial import
thib
parents:
diff changeset
42
223b71206888 Initial import
thib
parents:
diff changeset
43 // use only file subsystem
223b71206888 Initial import
thib
parents:
diff changeset
44 #include "file.h"
223b71206888 Initial import
thib
parents:
diff changeset
45 #include "file_impl.h"
223b71206888 Initial import
thib
parents:
diff changeset
46 // #include "file.cc"
223b71206888 Initial import
thib
parents:
diff changeset
47
223b71206888 Initial import
thib
parents:
diff changeset
48 #ifdef HAVE_LIBPNG
223b71206888 Initial import
thib
parents:
diff changeset
49 #include <png.h>
223b71206888 Initial import
thib
parents:
diff changeset
50 #endif
223b71206888 Initial import
thib
parents:
diff changeset
51
223b71206888 Initial import
thib
parents:
diff changeset
52 void usage(void) {
223b71206888 Initial import
thib
parents:
diff changeset
53 fprintf(stderr, "usage : visarc <cmd> <arcfile> [<file1> [<file2> [...] ]]\n");
223b71206888 Initial import
thib
parents:
diff changeset
54 fprintf(stderr, " cmd : x : extract\n");
223b71206888 Initial import
thib
parents:
diff changeset
55 fprintf(stderr, " l : list all files\n");
223b71206888 Initial import
thib
parents:
diff changeset
56 fprintf(stderr, "\n");
223b71206888 Initial import
thib
parents:
diff changeset
57 #ifdef HAVE_LIBPNG
223b71206888 Initial import
thib
parents:
diff changeset
58 fprintf(stderr, "usage2: visarc <cmd> <pdt-file> [<output-file>]\n");
223b71206888 Initial import
thib
parents:
diff changeset
59 fprintf(stderr, " cmd p : unpack pdt file and save as png file\n");
223b71206888 Initial import
thib
parents:
diff changeset
60 #endif /* HAVE_LIBPNG */
223b71206888 Initial import
thib
parents:
diff changeset
61 fprintf(stderr, "\n");
223b71206888 Initial import
thib
parents:
diff changeset
62 }
223b71206888 Initial import
thib
parents:
diff changeset
63
223b71206888 Initial import
thib
parents:
diff changeset
64 void List(char* path) {
223b71206888 Initial import
thib
parents:
diff changeset
65 ARCFILE* file;
223b71206888 Initial import
thib
parents:
diff changeset
66 FILE* f = fopen(path, "rb");
223b71206888 Initial import
thib
parents:
diff changeset
67 if (f == 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
68 char header[32];
223b71206888 Initial import
thib
parents:
diff changeset
69 fread(header, 32, 1, f);
223b71206888 Initial import
thib
parents:
diff changeset
70 fclose(f);
223b71206888 Initial import
thib
parents:
diff changeset
71 char magic_raf[8] = {'C','A','P','F',1,0,0,0};
223b71206888 Initial import
thib
parents:
diff changeset
72 if (strncmp(header, "PACL", 4) == 0) file = new ARCFILE(path);
223b71206888 Initial import
thib
parents:
diff changeset
73 else file = new SCN2kFILE(path);
223b71206888 Initial import
thib
parents:
diff changeset
74 file->Init();
223b71206888 Initial import
thib
parents:
diff changeset
75 file->ListFiles(stdout);
223b71206888 Initial import
thib
parents:
diff changeset
76 delete file;
223b71206888 Initial import
thib
parents:
diff changeset
77 return;
223b71206888 Initial import
thib
parents:
diff changeset
78 }
223b71206888 Initial import
thib
parents:
diff changeset
79
223b71206888 Initial import
thib
parents:
diff changeset
80 void ExtractOne(ARCFILE* arc, char* file) {
223b71206888 Initial import
thib
parents:
diff changeset
81 ARCINFO* info = arc->Find(file,"");
223b71206888 Initial import
thib
parents:
diff changeset
82 if (info == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
83 fprintf(stderr, "Cannot find file %s in archive\n",file);
223b71206888 Initial import
thib
parents:
diff changeset
84 return;
223b71206888 Initial import
thib
parents:
diff changeset
85 }
223b71206888 Initial import
thib
parents:
diff changeset
86 FILE* out = fopen(file, "w");
223b71206888 Initial import
thib
parents:
diff changeset
87 if (out == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
88 delete info;
223b71206888 Initial import
thib
parents:
diff changeset
89 fprintf(stderr, "Cannot open output file %s\n",file);
223b71206888 Initial import
thib
parents:
diff changeset
90 return;
223b71206888 Initial import
thib
parents:
diff changeset
91 }
223b71206888 Initial import
thib
parents:
diff changeset
92
223b71206888 Initial import
thib
parents:
diff changeset
93 fprintf(stdout, "Extracting %s ... ",file);
223b71206888 Initial import
thib
parents:
diff changeset
94 int size = info->Size();
223b71206888 Initial import
thib
parents:
diff changeset
95 const char* data = info->Read();
223b71206888 Initial import
thib
parents:
diff changeset
96 fwrite(data, size, 1, out);
223b71206888 Initial import
thib
parents:
diff changeset
97 fclose(out);
223b71206888 Initial import
thib
parents:
diff changeset
98 fprintf(stdout, "done\n");
223b71206888 Initial import
thib
parents:
diff changeset
99 delete info;
223b71206888 Initial import
thib
parents:
diff changeset
100 return;
223b71206888 Initial import
thib
parents:
diff changeset
101 }
223b71206888 Initial import
thib
parents:
diff changeset
102
223b71206888 Initial import
thib
parents:
diff changeset
103 void Extract(char* path, char** files, int fnum) {
223b71206888 Initial import
thib
parents:
diff changeset
104 ARCFILE* file;
223b71206888 Initial import
thib
parents:
diff changeset
105 FILE* f = fopen(path, "rb");
223b71206888 Initial import
thib
parents:
diff changeset
106 if (f == 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
107 char header[32];
223b71206888 Initial import
thib
parents:
diff changeset
108 fread(header, 32, 1, f);
223b71206888 Initial import
thib
parents:
diff changeset
109 fclose(f);
223b71206888 Initial import
thib
parents:
diff changeset
110 char magic_raf[8] = {'C','A','P','F',1,0,0,0};
223b71206888 Initial import
thib
parents:
diff changeset
111 if (strncmp(header, "PACL", 4) == 0) file = new ARCFILE(path);
223b71206888 Initial import
thib
parents:
diff changeset
112 else file = new SCN2kFILE(path);
223b71206888 Initial import
thib
parents:
diff changeset
113 file->Init();
223b71206888 Initial import
thib
parents:
diff changeset
114 if (files != 0 && fnum != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
115 int i; for (i=0; i<fnum; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
116 ExtractOne(file, files[i]);
223b71206888 Initial import
thib
parents:
diff changeset
117 }
223b71206888 Initial import
thib
parents:
diff changeset
118 } else {
223b71206888 Initial import
thib
parents:
diff changeset
119 file->InitList();
223b71206888 Initial import
thib
parents:
diff changeset
120 char* path; while( (path=file->ListItem()) != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
121 ExtractOne(file, path);
223b71206888 Initial import
thib
parents:
diff changeset
122 }
223b71206888 Initial import
thib
parents:
diff changeset
123 }
223b71206888 Initial import
thib
parents:
diff changeset
124 delete file;
223b71206888 Initial import
thib
parents:
diff changeset
125 return;
223b71206888 Initial import
thib
parents:
diff changeset
126 }
223b71206888 Initial import
thib
parents:
diff changeset
127
223b71206888 Initial import
thib
parents:
diff changeset
128 void ChangeExt(char* path, char* new_ext, char* buf) {
223b71206888 Initial import
thib
parents:
diff changeset
129 char* name = strrchr(path, DIR_SPLIT);
223b71206888 Initial import
thib
parents:
diff changeset
130 if (name == 0) name = path;
223b71206888 Initial import
thib
parents:
diff changeset
131 else name++;
223b71206888 Initial import
thib
parents:
diff changeset
132 int path_len = name - path;
223b71206888 Initial import
thib
parents:
diff changeset
133
223b71206888 Initial import
thib
parents:
diff changeset
134 char* ext = strrchr(name, '.');
223b71206888 Initial import
thib
parents:
diff changeset
135 int ext_len;
223b71206888 Initial import
thib
parents:
diff changeset
136 if (ext) ext_len = ext - name;
223b71206888 Initial import
thib
parents:
diff changeset
137 else ext_len = strlen(name);
223b71206888 Initial import
thib
parents:
diff changeset
138
223b71206888 Initial import
thib
parents:
diff changeset
139 strncpy(buf, path, path_len+ext_len);
223b71206888 Initial import
thib
parents:
diff changeset
140 strcpy(buf+path_len+ext_len, new_ext);
223b71206888 Initial import
thib
parents:
diff changeset
141 }
223b71206888 Initial import
thib
parents:
diff changeset
142
223b71206888 Initial import
thib
parents:
diff changeset
143 char* ReadFile(char* fname, int* len) {
223b71206888 Initial import
thib
parents:
diff changeset
144 FILE* in = fopen(fname, "rb");
223b71206888 Initial import
thib
parents:
diff changeset
145 if (in == 0) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
146 fseek(in,0,2); size_t s = ftell(in); fseek(in,0,0);
223b71206888 Initial import
thib
parents:
diff changeset
147 char* buf = new char[s];
223b71206888 Initial import
thib
parents:
diff changeset
148 fread(buf,s,1,in);
223b71206888 Initial import
thib
parents:
diff changeset
149 fclose(in);
223b71206888 Initial import
thib
parents:
diff changeset
150 if (len) *len = s;
223b71206888 Initial import
thib
parents:
diff changeset
151 return buf;
223b71206888 Initial import
thib
parents:
diff changeset
152 }
223b71206888 Initial import
thib
parents:
diff changeset
153
223b71206888 Initial import
thib
parents:
diff changeset
154
223b71206888 Initial import
thib
parents:
diff changeset
155 #ifdef HAVE_LIBPNG
223b71206888 Initial import
thib
parents:
diff changeset
156 void create_png(FILE* stream, char* path, char* desc, int width, int height, char* data) {
223b71206888 Initial import
thib
parents:
diff changeset
157 png_structp png_ptr;
223b71206888 Initial import
thib
parents:
diff changeset
158 png_infop info_ptr;
223b71206888 Initial import
thib
parents:
diff changeset
159
223b71206888 Initial import
thib
parents:
diff changeset
160 /* create struct */
223b71206888 Initial import
thib
parents:
diff changeset
161 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
223b71206888 Initial import
thib
parents:
diff changeset
162 if (png_ptr == NULL) return;
223b71206888 Initial import
thib
parents:
diff changeset
163
223b71206888 Initial import
thib
parents:
diff changeset
164 /* initialize information */
223b71206888 Initial import
thib
parents:
diff changeset
165 info_ptr = png_create_info_struct(png_ptr);
223b71206888 Initial import
thib
parents:
diff changeset
166 if (info_ptr == NULL) {
223b71206888 Initial import
thib
parents:
diff changeset
167 png_destroy_write_struct(&png_ptr, (png_infop*)NULL);
223b71206888 Initial import
thib
parents:
diff changeset
168 return;
223b71206888 Initial import
thib
parents:
diff changeset
169 }
223b71206888 Initial import
thib
parents:
diff changeset
170
223b71206888 Initial import
thib
parents:
diff changeset
171 if (setjmp(png_jmpbuf(png_ptr))) {
223b71206888 Initial import
thib
parents:
diff changeset
172 /* error occured !! */
223b71206888 Initial import
thib
parents:
diff changeset
173 png_destroy_write_struct(&png_ptr,&info_ptr);
223b71206888 Initial import
thib
parents:
diff changeset
174 fprintf(stderr, "Get error while processing PNG from file %s\n",path);
223b71206888 Initial import
thib
parents:
diff changeset
175 return;
223b71206888 Initial import
thib
parents:
diff changeset
176 }
223b71206888 Initial import
thib
parents:
diff changeset
177
223b71206888 Initial import
thib
parents:
diff changeset
178 /* initialize I/O (for stream) */
223b71206888 Initial import
thib
parents:
diff changeset
179 png_init_io(png_ptr, stream);
223b71206888 Initial import
thib
parents:
diff changeset
180
223b71206888 Initial import
thib
parents:
diff changeset
181 /* initialize headers */
223b71206888 Initial import
thib
parents:
diff changeset
182 png_set_IHDR(png_ptr, info_ptr,
223b71206888 Initial import
thib
parents:
diff changeset
183 width, height, 8 /* bit_dept */,
223b71206888 Initial import
thib
parents:
diff changeset
184 PNG_COLOR_TYPE_RGB_ALPHA,
223b71206888 Initial import
thib
parents:
diff changeset
185 PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
223b71206888 Initial import
thib
parents:
diff changeset
186 /* create text information */
223b71206888 Initial import
thib
parents:
diff changeset
187 png_text info_text[3];
223b71206888 Initial import
thib
parents:
diff changeset
188 info_text[0].key = "Title";
223b71206888 Initial import
thib
parents:
diff changeset
189 info_text[0].text= path;
223b71206888 Initial import
thib
parents:
diff changeset
190 info_text[0].compression = PNG_TEXT_COMPRESSION_NONE;
223b71206888 Initial import
thib
parents:
diff changeset
191 info_text[1].key = "Author";
223b71206888 Initial import
thib
parents:
diff changeset
192 info_text[1].text= CMDNAME " version " VERSION;
223b71206888 Initial import
thib
parents:
diff changeset
193 info_text[1].compression = PNG_TEXT_COMPRESSION_NONE;
223b71206888 Initial import
thib
parents:
diff changeset
194 info_text[2].key = "Description";
223b71206888 Initial import
thib
parents:
diff changeset
195 info_text[2].text= desc;
223b71206888 Initial import
thib
parents:
diff changeset
196 info_text[2].compression = PNG_TEXT_COMPRESSION_NONE;
223b71206888 Initial import
thib
parents:
diff changeset
197 png_set_text(png_ptr, info_ptr, info_text, 3);
223b71206888 Initial import
thib
parents:
diff changeset
198
223b71206888 Initial import
thib
parents:
diff changeset
199 /* write information */
223b71206888 Initial import
thib
parents:
diff changeset
200 png_write_info(png_ptr, info_ptr);
223b71206888 Initial import
thib
parents:
diff changeset
201
223b71206888 Initial import
thib
parents:
diff changeset
202 /* write body */
223b71206888 Initial import
thib
parents:
diff changeset
203 /* rgba image ; input/output is 32bpp.*/
223b71206888 Initial import
thib
parents:
diff changeset
204 char* row = new char[width*4];
223b71206888 Initial import
thib
parents:
diff changeset
205 int i; for (i=0; i<height; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
206 char* row_ptr = row;
223b71206888 Initial import
thib
parents:
diff changeset
207 int j; for (j=0; j<width; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
208 row_ptr[0] = data[2];
223b71206888 Initial import
thib
parents:
diff changeset
209 row_ptr[1] = data[1];
223b71206888 Initial import
thib
parents:
diff changeset
210 row_ptr[2] = data[0];
223b71206888 Initial import
thib
parents:
diff changeset
211 row_ptr[3] = data[3];
223b71206888 Initial import
thib
parents:
diff changeset
212 row_ptr += 4; data += 4;
223b71206888 Initial import
thib
parents:
diff changeset
213 }
223b71206888 Initial import
thib
parents:
diff changeset
214 png_write_rows(png_ptr, (png_byte**)&row, 1);
223b71206888 Initial import
thib
parents:
diff changeset
215 }
223b71206888 Initial import
thib
parents:
diff changeset
216 png_write_end(png_ptr, info_ptr);
223b71206888 Initial import
thib
parents:
diff changeset
217 png_destroy_write_struct(&png_ptr, &info_ptr);
223b71206888 Initial import
thib
parents:
diff changeset
218 return;
223b71206888 Initial import
thib
parents:
diff changeset
219 }
223b71206888 Initial import
thib
parents:
diff changeset
220
223b71206888 Initial import
thib
parents:
diff changeset
221 void ExtractPngRgbaGraphic(char* path,char* outpath = 0) {
223b71206888 Initial import
thib
parents:
diff changeset
222 char buf[1024]; char* fname = buf;
223b71206888 Initial import
thib
parents:
diff changeset
223 int len;
223b71206888 Initial import
thib
parents:
diff changeset
224 char* dat = ReadFile(path, &len);
223b71206888 Initial import
thib
parents:
diff changeset
225 if (dat == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
226 fprintf(stderr, "Cannot open PDT file : %s\n",path);
223b71206888 Initial import
thib
parents:
diff changeset
227 return;
223b71206888 Initial import
thib
parents:
diff changeset
228 }
223b71206888 Initial import
thib
parents:
diff changeset
229 GRPCONV* conv = GRPCONV::AssignConverter(dat, len, path);
223b71206888 Initial import
thib
parents:
diff changeset
230 if (conv == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
231 fprintf(stderr, "Invalid format\n");
223b71206888 Initial import
thib
parents:
diff changeset
232 return;
223b71206888 Initial import
thib
parents:
diff changeset
233 }
223b71206888 Initial import
thib
parents:
diff changeset
234 bool masked = conv->IsMask();
223b71206888 Initial import
thib
parents:
diff changeset
235 char* data = new char[conv->Width() * conv->Height() * 4 + 1024];
223b71206888 Initial import
thib
parents:
diff changeset
236 if (! conv->Read(data)) {
223b71206888 Initial import
thib
parents:
diff changeset
237 fprintf(stderr, "Insufficient memory\n");
223b71206888 Initial import
thib
parents:
diff changeset
238 delete conv;
223b71206888 Initial import
thib
parents:
diff changeset
239 return;
223b71206888 Initial import
thib
parents:
diff changeset
240 }
223b71206888 Initial import
thib
parents:
diff changeset
241 if (! masked) {
223b71206888 Initial import
thib
parents:
diff changeset
242 for (int i = 0; i < conv->Width() * conv->Height(); i++) {
223b71206888 Initial import
thib
parents:
diff changeset
243 data[4*i+3] = 0xff; // 不透明度を最大にする
223b71206888 Initial import
thib
parents:
diff changeset
244 }
223b71206888 Initial import
thib
parents:
diff changeset
245 }
223b71206888 Initial import
thib
parents:
diff changeset
246 if (outpath == 0) ChangeExt(path,".png", buf); // path をつくる
223b71206888 Initial import
thib
parents:
diff changeset
247 else fname = outpath;
223b71206888 Initial import
thib
parents:
diff changeset
248 FILE* out = fopen(fname, "wb"); // ファイルを開く
223b71206888 Initial import
thib
parents:
diff changeset
249 if (out == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
250 fprintf(stderr, "Cannot open raw file : %s\n",buf);
223b71206888 Initial import
thib
parents:
diff changeset
251 delete conv;
223b71206888 Initial import
thib
parents:
diff changeset
252 return;
223b71206888 Initial import
thib
parents:
diff changeset
253 }
223b71206888 Initial import
thib
parents:
diff changeset
254 create_png(out, path, "", conv->Width(), conv->Height(), data);
223b71206888 Initial import
thib
parents:
diff changeset
255 fclose(out);
223b71206888 Initial import
thib
parents:
diff changeset
256
223b71206888 Initial import
thib
parents:
diff changeset
257 delete conv;
223b71206888 Initial import
thib
parents:
diff changeset
258 }
223b71206888 Initial import
thib
parents:
diff changeset
259 #endif /* HAVE_LIBPNG */
223b71206888 Initial import
thib
parents:
diff changeset
260
223b71206888 Initial import
thib
parents:
diff changeset
261 int main(int argc, char* argv[]) {
223b71206888 Initial import
thib
parents:
diff changeset
262 int i;
223b71206888 Initial import
thib
parents:
diff changeset
263 fprintf(stderr, "%s version %s\n", CMDNAME, VERSION);
223b71206888 Initial import
thib
parents:
diff changeset
264 if (argc < 3) {
223b71206888 Initial import
thib
parents:
diff changeset
265 usage(); return -1;
223b71206888 Initial import
thib
parents:
diff changeset
266 }
223b71206888 Initial import
thib
parents:
diff changeset
267 if (strlen(argv[1]) != 1) {
223b71206888 Initial import
thib
parents:
diff changeset
268 usage(); return -1;
223b71206888 Initial import
thib
parents:
diff changeset
269 }
223b71206888 Initial import
thib
parents:
diff changeset
270 for (i=2; i<argc; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
271 /* option を削る */
223b71206888 Initial import
thib
parents:
diff changeset
272 argc--;
223b71206888 Initial import
thib
parents:
diff changeset
273 int j; for (j=i; j<argc; j++) argv[j] = argv[j+1];
223b71206888 Initial import
thib
parents:
diff changeset
274 }
223b71206888 Initial import
thib
parents:
diff changeset
275 switch(argv[1][0]) {
223b71206888 Initial import
thib
parents:
diff changeset
276 case 'x': case 'X':
223b71206888 Initial import
thib
parents:
diff changeset
277 if (argc < 4) Extract(argv[2], 0, -1);
223b71206888 Initial import
thib
parents:
diff changeset
278 else Extract(argv[2], argv+3, argc-3);
223b71206888 Initial import
thib
parents:
diff changeset
279 break;
223b71206888 Initial import
thib
parents:
diff changeset
280 case 'l': case 'L':
223b71206888 Initial import
thib
parents:
diff changeset
281 List(argv[2]);
223b71206888 Initial import
thib
parents:
diff changeset
282 break;
223b71206888 Initial import
thib
parents:
diff changeset
283 #ifdef HAVE_LIBPNG
223b71206888 Initial import
thib
parents:
diff changeset
284 case 'p': case 'P':
223b71206888 Initial import
thib
parents:
diff changeset
285 case 'a': case 'A':
223b71206888 Initial import
thib
parents:
diff changeset
286 if (argc < 4)
223b71206888 Initial import
thib
parents:
diff changeset
287 ExtractPngRgbaGraphic(argv[2]);
223b71206888 Initial import
thib
parents:
diff changeset
288 else
223b71206888 Initial import
thib
parents:
diff changeset
289 ExtractPngRgbaGraphic(argv[2],argv[3]);
223b71206888 Initial import
thib
parents:
diff changeset
290 break;
223b71206888 Initial import
thib
parents:
diff changeset
291 #endif /* HAVE_LIBPNG */
223b71206888 Initial import
thib
parents:
diff changeset
292 default:
223b71206888 Initial import
thib
parents:
diff changeset
293 usage(); return -1;
223b71206888 Initial import
thib
parents:
diff changeset
294 }
223b71206888 Initial import
thib
parents:
diff changeset
295 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
296 }