Mercurial > otakunoraifu
annotate system/file.h @ 48:ed6c21dde840
* use correct format (%p) for pointers
author | thib |
---|---|
date | Wed, 15 Apr 2009 20:28:19 +0000 |
parents | 5f548e5957a8 |
children | 15a18fbe6f21 |
rev | line source |
---|---|
0 | 1 /* file.h : KANON ¤Î°µ½Ì¥Õ¥¡¥¤¥ë¡¦PDT ¥Õ¥¡¥¤¥ë¡Ê²èÁü¥Õ¥¡¥¤¥ë¡Ë¤ÎŸ³«¤Î |
2 * ¤¿¤á¤Î¥¯¥é¥¹ | |
3 * class FILESEARCH : ¥Õ¥¡¥¤¥ë¤Î´ÉÍý¤ò¹Ô¤¦ | |
4 * class ARCINFO : ½ñ¸Ë¥Õ¥¡¥¤¥ë¤ÎÃæ¤Î£±¤Ä¤Î¥Õ¥¡¥¤¥ë¤ò°·¤¦¥¯¥é¥¹ | |
5 * class PDTCONV : PDT ¥Õ¥¡¥¤¥ë¤ÎŸ³«¤ò¹Ô¤¦¡£ | |
6 */ | |
7 | |
8 /* | |
9 * | |
10 * Copyright (C) 2000- Kazunori Ueno(JAGARL) <jagarl@creator.club.ne.jp> | |
11 * | |
12 * This program is free software; you can redistribute it and/or modify | |
13 * it under the terms of the GNU General Public License as published by | |
14 * the Free Software Foundation; either version 2 of the License, or | |
15 * (at your option) any later version. | |
16 * | |
17 * This program is distributed in the hope that it will be useful, | |
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 * GNU General Public License for more details. | |
21 * | |
27 | 22 * You should have received a copy of the GNU General Public License along |
23 * with this program; if not, write to the Free Software Foundation, Inc., | |
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
0 | 25 * |
26 */ | |
27 | |
28 #ifndef __KANON_FILE_H__ | |
29 #define __KANON_FILE_H__ | |
30 | |
31 #ifndef DIR_SPLIT | |
32 #define DIR_SPLIT '/' /* UNIX */ | |
33 #endif | |
34 | |
35 // read 'KANON' compressed file | |
36 | |
37 #include<stdio.h> | |
38 #include<stdlib.h> | |
39 #include<string.h> | |
40 #include<sys/types.h> | |
41 | |
42 #ifdef HAVE_CONFIG_H | |
43 # include "config.h" | |
44 #endif | |
45 | |
46 #if defined(__sparc) || defined(sparc) | |
47 # if !defined(WORDS_BIGENDIAN) | |
48 # define WORDS_BIGENDIAN 1 | |
49 # endif | |
50 #endif | |
51 | |
52 #define INT_SIZE 4 | |
53 | |
54 static int read_little_endian_int(const char* buf) { | |
55 const unsigned char *p = (const unsigned char *) buf; | |
56 return (p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]; | |
57 } | |
58 | |
59 static int read_little_endian_short(const char* buf) { | |
60 const unsigned char *p = (const unsigned char *) buf; | |
61 return (p[1] << 8) | p[0]; | |
62 } | |
63 | |
64 static int write_little_endian_int(char* buf, int number) { | |
65 int c = read_little_endian_int(buf); | |
66 unsigned char *p = (unsigned char *) buf; | |
67 unsigned int unum = (unsigned int) number; | |
68 p[0] = unum & 255; | |
69 unum >>= 8; | |
70 p[1] = unum & 255; | |
71 unum >>= 8; | |
72 p[2] = unum & 255; | |
73 unum >>= 8; | |
74 p[3] = unum & 255; | |
75 return c; | |
76 } | |
77 | |
78 static int write_little_endian_short(char* buf, int number) { | |
79 int c = read_little_endian_short(buf); | |
80 unsigned char *p = (unsigned char *) buf; | |
81 unsigned int unum = (unsigned int) number; | |
82 p[0] = unum & 255; | |
83 unum >>= 8; | |
84 p[1] = unum & 255; | |
85 return c; | |
86 } | |
87 | |
88 | |
89 /********************************************* | |
90 ** FILESEARCH: | |
91 ** ½ñ¸Ë¥Õ¥¡¥¤¥ë¡¿¥Ç¥£¥ì¥¯¥È¥ê¤ò´Þ¤á¡¢ | |
92 ** Á´¥Õ¥¡¥¤¥ë¤Î´ÉÍý¤ò¹Ô¤¦¡£ | |
93 ** | |
94 ** ºÇ½é¤Ë¡¢ÀßÄê¥Õ¥¡¥¤¥ë¤«¤é¥Õ¥¡¥¤¥ë¤Î¼ïÎऴ¤È¤Ë | |
95 ** ¼ÂºÝ¤ËÆþ¤Ã¤Æ¤¤¤ë¥Ç¥£¥ì¥¯¥È¥ê¡¢½ñ¸Ë¤òÀßÄꤹ¤ë | |
96 ** | |
97 ** °Ê¹ß¤ÏFind() ¥á¥½¥Ã¥É¤Ç¼ÂºÝ¤Î¥Õ¥¡¥¤¥ë¤ÎÆâÍƤòÆÀ¤ë | |
98 ** | |
99 */ | |
100 | |
101 /* ARCFILE ¤È DIRFILE ¤Ï¥Õ¥¡¥¤¥ë¼ïÎऴ¤È¤Î¾ðÊó */ | |
102 class ARCFILE; | |
103 class DIRFILE; | |
104 class SCN2kFILE; | |
105 /* ARCINFO ¤Ï¥Õ¥¡¥¤¥ë¤òÆɤ߹þ¤à¤¿¤á¤ËɬÍ× */ | |
106 class ARCINFO; | |
107 class ARCFILE_ATOM; | |
35 | 108 |
109 class KEYHOLDER { | |
110 public: | |
111 void SetKey(char[16]); | |
112 void SetKey2(char[33]); | |
113 void GuessKey(char*); | |
114 const char* GetKey(void); | |
115 private: | |
116 char key[16]; | |
117 }; | |
118 | |
0 | 119 class FILESEARCH { |
120 public: | |
121 #define TYPEMAX 14 | |
122 enum FILETYPE { | |
123 /* °ì±þ¡¢0 - 15 ¤Þ¤Ç reserved */ | |
124 ALL = 1, /* dat/ °Ê²¼¤Î¥Õ¥¡¥¤¥ë(¥Ç¥Õ¥©¥ë¥È¤Î¸¡º÷Àè) */ | |
125 ROOT= 2, /* ¥²¡¼¥à¤Î¥¤¥ó¥¹¥È¡¼¥ë¥Ç¥£¥ì¥¯¥È¥ê */ | |
126 PDT = 3, /* default: PDT/ */ | |
127 SCN = 4, /* default: DAT/SEEN.TXT */ | |
128 ANM = 5, /* default: DAT/ALLANM.ANL */ | |
129 ARD = 6, /* default: DAT/ALLARD.ARD */ | |
130 CUR = 7, /* default: DAT/ALLCUR.CUR */ | |
131 MID = 8, /* default: ALL */ | |
132 WAV = 9, /* default: ALL */ | |
133 KOE = 10, /* default: KOE/ */ | |
134 BGM = 11, /* default: BGM */ | |
135 MOV = 12, /* default : MOV */ | |
136 GAN = 13 /* default : MOV */ | |
137 }; | |
138 enum ARCTYPE {ATYPE_DIR, ATYPE_ARC, ATYPE_SCN2k}; | |
139 private: | |
140 /* InitRoot() ¤Î»þÅÀ¤Ç½é´ü²½¤µ¤ì¤ëÊÑ¿ô */ | |
141 DIRFILE* root_dir; | |
142 DIRFILE* dat_dir; | |
143 ARCFILE* searcher[TYPEMAX]; | |
144 /* ¥Õ¥¡¥¤¥ë¤Î¸ºß°ÌÃ֤Πinformation */ | |
145 ARCTYPE is_archived[TYPEMAX]; | |
47
5f548e5957a8
* get rid of the "deprecated conversion from string constant to ‘char*’" warnings
thib
parents:
35
diff
changeset
|
146 const char* filenames[TYPEMAX]; |
0 | 147 /* ¥Ç¥Õ¥©¥ë¥È¤Î information */ |
148 static ARCTYPE default_is_archived[TYPEMAX]; | |
47
5f548e5957a8
* get rid of the "deprecated conversion from string constant to ‘char*’" warnings
thib
parents:
35
diff
changeset
|
149 static const char* default_dirnames[TYPEMAX]; |
0 | 150 public: |
151 FILESEARCH(void); | |
152 ~FILESEARCH(); | |
153 /* ½é¤á¤Ë¥²¡¼¥à¤Î¥Ç¡¼¥¿¤¬¤¢¤ë¥Ç¥£¥ì¥¯¥È¥ê¤òÀßÄꤹ¤ëɬÍפ¬¤¢¤ë */ | |
154 int InitRoot(char* root); | |
155 /* ¥Õ¥¡¥¤¥ë¤Î·¿¤´¤È¤Î¾ðÊó¤ò¥»¥Ã¥È¤¹¤ë */ | |
156 void SetFileInformation(FILETYPE type, ARCTYPE is_arc, | |
157 char* filename); | |
158 /* Ê£¿ô¤Î¥Õ¥¡¥¤¥ë¤ò°ì¤Ä¤Î·¿¤Ë´ØÏ¢¤Å¤±¤ë */ | |
159 void AppendFileInformation(FILETYPE type, ARCTYPE is_arc, | |
160 char* filename); | |
47
5f548e5957a8
* get rid of the "deprecated conversion from string constant to ‘char*’" warnings
thib
parents:
35
diff
changeset
|
161 ARCFILE* MakeARCFILE(ARCTYPE tp, const char* filename); |
0 | 162 /* fname ¤Ç»ØÄꤵ¤ì¤¿Ì¾Á°¤Î¥Õ¥¡¥¤¥ë¤ò¸¡º÷ */ |
163 class ARCINFO* Find(FILETYPE type, const char* fname, const char* ext=0); | |
164 /* ¤¢¤ë¼ïÎà¤Î¥Õ¥¡¥¤¥ë¤ò¤¹¤Ù¤Æ¥ê¥¹¥È¥¢¥Ã¥× | |
165 ** ËöÈø¤Ï NULL pointer | |
166 */ | |
167 char** ListAll(FILETYPE type); | |
168 }; | |
169 | |
170 class ARCINFO { | |
171 protected: | |
172 /* ¥Õ¥¡¥¤¥ë¤½¤Î¤â¤Î¤Î¾ðÊó */ | |
173 ARCFILE_ATOM& info; | |
174 char* arcfile; | |
175 /* mmap ¤·¤Æ¤¤¤ë¾ì¹ç¡¢¤½¤Î¾ðÊó */ | |
176 bool use_mmap; | |
177 char* mmapped_memory; | |
178 int fd; | |
179 /* ¥Õ¥¡¥¤¥ëÆâÍƤÎÆþ¤Ã¤Æ¤¤¤ë¥Ð¥Ã¥Õ¥¡ */ | |
180 const char* data; | |
181 | |
182 protected: | |
183 ARCINFO(const char* arcfile, ARCFILE_ATOM& from); // only from ARCFILE | |
184 friend class ARCFILE; | |
185 friend class DIRFILE; | |
186 | |
187 virtual bool ExecExtract(void); | |
188 public: | |
189 /* dest ¤Ï256byte ÄøÅÙ¤Î;͵¤¬¤¢¤ë¤³¤È */ | |
190 static void Extract(char*& dest, char*& src, char* destend, char* srcend); | |
191 static void Extract2k(char*& dest, char*& src, char* destend, char* srcend); | |
192 virtual ~ARCINFO(); | |
193 /* ɬÍפʤé Read Á°¤Ë¸Æ¤Ö¤³¤È¤Ç½èÍý¤òʬ³ä¤Ç¤¤ë */ | |
194 int Size(void) const; | |
195 char* CopyRead(void); /* Read() ¤·¤ÆÆâÍƤΥ³¥Ô¡¼¤òÊÖ¤¹ */ | |
196 const char* Read(void); | |
197 /* ¥Õ¥¡¥¤¥ë¤¬ regular file ¤Î¾ì¹ç¡¢¥Õ¥¡¥¤¥ë̾¤òµ¢¤¹ */ | |
198 /* ¤½¤¦¤Ç¤Ê¤¤¤Ê¤é 0 ¤òµ¢¤¹ */ | |
199 const char* Path(void) const; | |
200 FILE* OpenFile(int* length=0) const; /* ¸ß´¹À¤Î¤¿¤á¡§raw file ¤Î¾ì¹ç¡¢¥Õ¥¡¥¤¥ë¤ò³«¤¯ */ | |
201 }; | |
202 | |
203 class GRPCONV { | |
204 public: | |
205 int width; | |
206 int height; | |
207 bool is_mask; | |
208 | |
209 const char* filename; | |
210 const char* data; | |
211 int datalen; | |
212 | |
213 int Width(void) { return width;} | |
214 int Height(void) { return height;} | |
215 bool IsMask(void) { return is_mask;} | |
216 | |
217 GRPCONV(void); | |
218 virtual ~GRPCONV(); | |
219 void Init(const char* fname, const char* data, int dlen, int width, int height, bool is_mask); | |
220 | |
221 virtual bool Read(char* image) = 0; | |
222 static GRPCONV* AssignConverter(const char* inbuf, int inlen, const char* fname); | |
223 static GRPCONV* AssignConverter(ARCINFO* info) { | |
224 const char* dat = info->Read(); | |
225 if (dat == 0) return 0; | |
226 return AssignConverter(dat, info->Size(), "???"); | |
227 } | |
228 void CopyRGBA(char* image, const char* from); | |
229 void CopyRGB(char* image, const char* from); | |
230 void CopyRGBA_rev(char* image, const char* from); | |
231 void CopyRGB_rev(char* image, const char* from); | |
232 }; | |
233 | |
234 extern FILESEARCH file_searcher; | |
35 | 235 extern KEYHOLDER key_holder; |
0 | 236 |
237 #endif // !defined(__KANON_FILE_H__) |