annotate system/system_config.cc @ 31:5ae5533b3a9a

* Added some license headers
author thib
date Sat, 07 Mar 2009 21:36:46 +0000
parents 3a6aaeab7b4e
children 651237260724
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
223b71206888 Initial import
thib
parents:
diff changeset
1 /* system_config.cc
223b71206888 Initial import
thib
parents:
diff changeset
2 * gameexe.ini ファイルの読み込み
223b71206888 Initial import
thib
parents:
diff changeset
3 */
223b71206888 Initial import
thib
parents:
diff changeset
4
223b71206888 Initial import
thib
parents:
diff changeset
5 /*
223b71206888 Initial import
thib
parents:
diff changeset
6 *
223b71206888 Initial import
thib
parents:
diff changeset
7 * Copyright (C) 2000- Kazunori Ueno(JAGARL) <jagarl@creator.club.ne.jp>
223b71206888 Initial import
thib
parents:
diff changeset
8 *
223b71206888 Initial import
thib
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
223b71206888 Initial import
thib
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
223b71206888 Initial import
thib
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
223b71206888 Initial import
thib
parents:
diff changeset
12 * (at your option) any later version.
223b71206888 Initial import
thib
parents:
diff changeset
13 *
223b71206888 Initial import
thib
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
223b71206888 Initial import
thib
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
223b71206888 Initial import
thib
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
223b71206888 Initial import
thib
parents:
diff changeset
17 * GNU General Public License for more details.
223b71206888 Initial import
thib
parents:
diff changeset
18 *
27
3a6aaeab7b4e * Fixed a typo in Jagarl's name
thib
parents: 26
diff changeset
19 * You should have received a copy of the GNU General Public License along
3a6aaeab7b4e * Fixed a typo in Jagarl's name
thib
parents: 26
diff changeset
20 * with this program; if not, write to the Free Software Foundation, Inc.,
3a6aaeab7b4e * Fixed a typo in Jagarl's name
thib
parents: 26
diff changeset
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0
223b71206888 Initial import
thib
parents:
diff changeset
22 *
223b71206888 Initial import
thib
parents:
diff changeset
23 */
223b71206888 Initial import
thib
parents:
diff changeset
24
223b71206888 Initial import
thib
parents:
diff changeset
25 #include <stdio.h>
223b71206888 Initial import
thib
parents:
diff changeset
26 #include <string.h>
223b71206888 Initial import
thib
parents:
diff changeset
27 #include <stdlib.h>
223b71206888 Initial import
thib
parents:
diff changeset
28 #include <stdarg.h>
223b71206888 Initial import
thib
parents:
diff changeset
29 #include <ctype.h>
223b71206888 Initial import
thib
parents:
diff changeset
30 #include <map>
223b71206888 Initial import
thib
parents:
diff changeset
31 #include <string>
223b71206888 Initial import
thib
parents:
diff changeset
32 #include "system_config.h"
223b71206888 Initial import
thib
parents:
diff changeset
33 #include "../system/file.h"
223b71206888 Initial import
thib
parents:
diff changeset
34
223b71206888 Initial import
thib
parents:
diff changeset
35 using namespace std;
223b71206888 Initial import
thib
parents:
diff changeset
36
223b71206888 Initial import
thib
parents:
diff changeset
37 // #define DEBUG_CONFIG
223b71206888 Initial import
thib
parents:
diff changeset
38 #ifdef DEBUG_CONFIG
223b71206888 Initial import
thib
parents:
diff changeset
39 # define dprintf(X) printf X
223b71206888 Initial import
thib
parents:
diff changeset
40 #else
223b71206888 Initial import
thib
parents:
diff changeset
41 # define dprintf(X)
223b71206888 Initial import
thib
parents:
diff changeset
42 #endif /* DEBUG_CONFIG */
223b71206888 Initial import
thib
parents:
diff changeset
43
223b71206888 Initial import
thib
parents:
diff changeset
44 #define MAXTOKEN 10 /* = で区切られた領域の最大数 */
223b71206888 Initial import
thib
parents:
diff changeset
45 #define MAXVARS 32 /* , で区切られた数値の最大数 */
223b71206888 Initial import
thib
parents:
diff changeset
46
223b71206888 Initial import
thib
parents:
diff changeset
47 // 初期化ファイルの読み込み
223b71206888 Initial import
thib
parents:
diff changeset
48 /* config は 文字列、数列、その複合など、いろいろな形式がありうる */
223b71206888 Initial import
thib
parents:
diff changeset
49 /* 文字列と数列は一般に AyuSys_Config クラスに含める */
223b71206888 Initial import
thib
parents:
diff changeset
50
223b71206888 Initial import
thib
parents:
diff changeset
51
223b71206888 Initial import
thib
parents:
diff changeset
52 /**********************************************************/
223b71206888 Initial import
thib
parents:
diff changeset
53 /* とりあえずハッシュ比較付き文字列 */
223b71206888 Initial import
thib
parents:
diff changeset
54 class HashStr {
223b71206888 Initial import
thib
parents:
diff changeset
55 const char* str;
223b71206888 Initial import
thib
parents:
diff changeset
56 unsigned int hash;
223b71206888 Initial import
thib
parents:
diff changeset
57 public:
223b71206888 Initial import
thib
parents:
diff changeset
58 HashStr(const char*);
223b71206888 Initial import
thib
parents:
diff changeset
59 HashStr(const HashStr& orig);
223b71206888 Initial import
thib
parents:
diff changeset
60 ~HashStr() {
223b71206888 Initial import
thib
parents:
diff changeset
61 if (str) delete[] str;
223b71206888 Initial import
thib
parents:
diff changeset
62 }
223b71206888 Initial import
thib
parents:
diff changeset
63 const char* c_str(void) const { return str; }
223b71206888 Initial import
thib
parents:
diff changeset
64 friend inline int operator<(const HashStr& a, const HashStr& b) {
223b71206888 Initial import
thib
parents:
diff changeset
65 if (a.hash == b.hash) {
223b71206888 Initial import
thib
parents:
diff changeset
66 if (a.str == 0) return 1;
223b71206888 Initial import
thib
parents:
diff changeset
67 else if (b.str == 0) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
68 else return strcmp(a.str, b.str);
223b71206888 Initial import
thib
parents:
diff changeset
69 }
223b71206888 Initial import
thib
parents:
diff changeset
70 else return a.hash < b.hash;
223b71206888 Initial import
thib
parents:
diff changeset
71 }
223b71206888 Initial import
thib
parents:
diff changeset
72 };
223b71206888 Initial import
thib
parents:
diff changeset
73 HashStr::HashStr(const char* s ) {
223b71206888 Initial import
thib
parents:
diff changeset
74 if (s == 0 || s[0] == '\0') {
223b71206888 Initial import
thib
parents:
diff changeset
75 str = 0; hash = 0; return; /* invalid string */
223b71206888 Initial import
thib
parents:
diff changeset
76 }
223b71206888 Initial import
thib
parents:
diff changeset
77 char* new_str = new char[strlen(s)+1];
223b71206888 Initial import
thib
parents:
diff changeset
78 strcpy(new_str, s);
223b71206888 Initial import
thib
parents:
diff changeset
79 str = new_str;
223b71206888 Initial import
thib
parents:
diff changeset
80 /* calc hash... 適当 */
223b71206888 Initial import
thib
parents:
diff changeset
81 int h = strlen(s);
223b71206888 Initial import
thib
parents:
diff changeset
82 while(*s != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
83 h = *s + ((h * (0x9449+*s))>>7);
223b71206888 Initial import
thib
parents:
diff changeset
84 s++;
223b71206888 Initial import
thib
parents:
diff changeset
85 }
223b71206888 Initial import
thib
parents:
diff changeset
86 hash = (unsigned int)h;
223b71206888 Initial import
thib
parents:
diff changeset
87 }
223b71206888 Initial import
thib
parents:
diff changeset
88 HashStr::HashStr(const HashStr& orig) {
223b71206888 Initial import
thib
parents:
diff changeset
89 if (orig.str == 0 || orig.str[0] == '\0') {
223b71206888 Initial import
thib
parents:
diff changeset
90 str = 0; hash = 0; return; /* invalid */
223b71206888 Initial import
thib
parents:
diff changeset
91 }
223b71206888 Initial import
thib
parents:
diff changeset
92 char* new_str = new char[strlen(orig.str)+1];
223b71206888 Initial import
thib
parents:
diff changeset
93 strcpy(new_str, orig.str);
223b71206888 Initial import
thib
parents:
diff changeset
94 str = new_str;
223b71206888 Initial import
thib
parents:
diff changeset
95 hash = orig.hash;
223b71206888 Initial import
thib
parents:
diff changeset
96 }
223b71206888 Initial import
thib
parents:
diff changeset
97
223b71206888 Initial import
thib
parents:
diff changeset
98 /**********************************************************
223b71206888 Initial import
thib
parents:
diff changeset
99 **AyuSys_Config_[String | Intlist] :
223b71206888 Initial import
thib
parents:
diff changeset
100 ** 設定の本体
223b71206888 Initial import
thib
parents:
diff changeset
101 ** original : 元設定
223b71206888 Initial import
thib
parents:
diff changeset
102 ** old_data : 前回 ClearDiff() したときの設定
223b71206888 Initial import
thib
parents:
diff changeset
103 ** new_data : ClearDiff() 以降に設定した内容を保存
223b71206888 Initial import
thib
parents:
diff changeset
104 ** データ設定:
223b71206888 Initial import
thib
parents:
diff changeset
105 ** Init() : 元設定を作成
223b71206888 Initial import
thib
parents:
diff changeset
106 ** Set() : 設定を変更
223b71206888 Initial import
thib
parents:
diff changeset
107 ** Get() : 最も新しい設定を得る
223b71206888 Initial import
thib
parents:
diff changeset
108 **
223b71206888 Initial import
thib
parents:
diff changeset
109 ** 変更の記録:
223b71206888 Initial import
thib
parents:
diff changeset
110 ** Diff() : 前回のClearDiff() から変更した内容を得る
223b71206888 Initial import
thib
parents:
diff changeset
111 ** DiffLen() : Diff() で必要な文字列長を得る
223b71206888 Initial import
thib
parents:
diff changeset
112 ** ClearDiff() : 変更記録を消す
223b71206888 Initial import
thib
parents:
diff changeset
113 ** PatchOld() : Diff() で得た記録に基づき、変更前の状態に戻す
223b71206888 Initial import
thib
parents:
diff changeset
114 ** PatchNew() : Diff() で得た記録に基づき、変更後の状態に戻す
223b71206888 Initial import
thib
parents:
diff changeset
115 **
223b71206888 Initial import
thib
parents:
diff changeset
116 ** 元設定からの変更の記録:
223b71206888 Initial import
thib
parents:
diff changeset
117 ** SetOriginal() : 元設定に戻す
223b71206888 Initial import
thib
parents:
diff changeset
118 ** DiffOriginal() : 元設定から現在の設定の変更を得る
223b71206888 Initial import
thib
parents:
diff changeset
119 ** DiffOriginalLen() : DiffOriginal() で必要な文字列長を得る
223b71206888 Initial import
thib
parents:
diff changeset
120 ** PatchOriginal() : DiffOriginal() で得た記録に基づき、設定を復旧する
223b71206888 Initial import
thib
parents:
diff changeset
121 */
223b71206888 Initial import
thib
parents:
diff changeset
122
223b71206888 Initial import
thib
parents:
diff changeset
123 /************************************************
223b71206888 Initial import
thib
parents:
diff changeset
124 ** AyuSysConfigStringItem
223b71206888 Initial import
thib
parents:
diff changeset
125 ** 文字列をデータとしてもつ設定項目
223b71206888 Initial import
thib
parents:
diff changeset
126 */
223b71206888 Initial import
thib
parents:
diff changeset
127 class AyuSysConfigStringItem {
223b71206888 Initial import
thib
parents:
diff changeset
128 char* original_data;
223b71206888 Initial import
thib
parents:
diff changeset
129 char* old_data;
223b71206888 Initial import
thib
parents:
diff changeset
130 char* new_data;
223b71206888 Initial import
thib
parents:
diff changeset
131 public:
223b71206888 Initial import
thib
parents:
diff changeset
132 AyuSysConfigStringItem(void) {
223b71206888 Initial import
thib
parents:
diff changeset
133 original_data = 0;
223b71206888 Initial import
thib
parents:
diff changeset
134 old_data = 0;
223b71206888 Initial import
thib
parents:
diff changeset
135 new_data = 0;
223b71206888 Initial import
thib
parents:
diff changeset
136 }
223b71206888 Initial import
thib
parents:
diff changeset
137 AyuSysConfigStringItem(const AyuSysConfigStringItem& o) {
223b71206888 Initial import
thib
parents:
diff changeset
138 original_data = 0; old_data = 0; new_data = 0;
223b71206888 Initial import
thib
parents:
diff changeset
139 if (o.original_data) {
223b71206888 Initial import
thib
parents:
diff changeset
140 original_data = new char[strlen(o.original_data)+1];
223b71206888 Initial import
thib
parents:
diff changeset
141 strcpy(original_data, o.original_data);
223b71206888 Initial import
thib
parents:
diff changeset
142 }
223b71206888 Initial import
thib
parents:
diff changeset
143 if (o.old_data) {
223b71206888 Initial import
thib
parents:
diff changeset
144 old_data = new char[strlen(o.old_data)+1];
223b71206888 Initial import
thib
parents:
diff changeset
145 strcpy(old_data, o.old_data);
223b71206888 Initial import
thib
parents:
diff changeset
146 }
223b71206888 Initial import
thib
parents:
diff changeset
147 if (o.new_data) {
223b71206888 Initial import
thib
parents:
diff changeset
148 new_data = new char[strlen(o.new_data)+1];
223b71206888 Initial import
thib
parents:
diff changeset
149 strcpy(new_data, o.new_data);
223b71206888 Initial import
thib
parents:
diff changeset
150 }
223b71206888 Initial import
thib
parents:
diff changeset
151 }
223b71206888 Initial import
thib
parents:
diff changeset
152 /* 設定:Init で初期化、Set で変更、Get で変更を優先して取り出す */
223b71206888 Initial import
thib
parents:
diff changeset
153 void Init(int deal, const char* str) { /* deal は無視 */
223b71206888 Initial import
thib
parents:
diff changeset
154 if (original_data) delete[] original_data;
223b71206888 Initial import
thib
parents:
diff changeset
155 int len = strlen(str);
223b71206888 Initial import
thib
parents:
diff changeset
156 original_data = new char[len+1];
223b71206888 Initial import
thib
parents:
diff changeset
157 strcpy(original_data, str);
223b71206888 Initial import
thib
parents:
diff changeset
158 original_data[len] = '\0';
223b71206888 Initial import
thib
parents:
diff changeset
159 }
223b71206888 Initial import
thib
parents:
diff changeset
160 void Set(int deal, const char* str) { /* deal は無視 */
223b71206888 Initial import
thib
parents:
diff changeset
161 if (new_data) delete[] new_data;
223b71206888 Initial import
thib
parents:
diff changeset
162 int len = strlen(str);
223b71206888 Initial import
thib
parents:
diff changeset
163 new_data = new char[len+1];
223b71206888 Initial import
thib
parents:
diff changeset
164 strcpy(new_data, str);
223b71206888 Initial import
thib
parents:
diff changeset
165 new_data[len] = '\0';
223b71206888 Initial import
thib
parents:
diff changeset
166 }
223b71206888 Initial import
thib
parents:
diff changeset
167 const char* Get(int deal) const {/* deal は無視 */
223b71206888 Initial import
thib
parents:
diff changeset
168 if (new_data) return new_data;
223b71206888 Initial import
thib
parents:
diff changeset
169 else if (old_data) return old_data;
223b71206888 Initial import
thib
parents:
diff changeset
170 return original_data;
223b71206888 Initial import
thib
parents:
diff changeset
171 }
223b71206888 Initial import
thib
parents:
diff changeset
172 const char* GetOriginal(int deal) const {
223b71206888 Initial import
thib
parents:
diff changeset
173 return original_data;
223b71206888 Initial import
thib
parents:
diff changeset
174 }
223b71206888 Initial import
thib
parents:
diff changeset
175 int Deal(void) const {
223b71206888 Initial import
thib
parents:
diff changeset
176 return 1;
223b71206888 Initial import
thib
parents:
diff changeset
177 }
223b71206888 Initial import
thib
parents:
diff changeset
178 /* オリジナルからの変化の調査 :
223b71206888 Initial import
thib
parents:
diff changeset
179 ** DiffOriginal で変化を文字列で取り出し、PatchOriginal で
223b71206888 Initial import
thib
parents:
diff changeset
180 ** 変化を反映
223b71206888 Initial import
thib
parents:
diff changeset
181 */
223b71206888 Initial import
thib
parents:
diff changeset
182 int DiffOriginalLen(void) {
223b71206888 Initial import
thib
parents:
diff changeset
183 if (new_data == 0) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
184 return strlen(new_data)+1;
223b71206888 Initial import
thib
parents:
diff changeset
185 }
223b71206888 Initial import
thib
parents:
diff changeset
186 void DiffOriginal(string& data) {
223b71206888 Initial import
thib
parents:
diff changeset
187 if (new_data == 0) { /* あり得ない */
223b71206888 Initial import
thib
parents:
diff changeset
188 fprintf(stderr,"AyuSysConfigStringItem::DiffOriginal : this method must not called if not required!\n");
223b71206888 Initial import
thib
parents:
diff changeset
189 return;
223b71206888 Initial import
thib
parents:
diff changeset
190 }
223b71206888 Initial import
thib
parents:
diff changeset
191 char* out_data = new char[strlen(new_data)*2+1];
223b71206888 Initial import
thib
parents:
diff changeset
192 char* buf = out_data;
223b71206888 Initial import
thib
parents:
diff changeset
193 int i;
223b71206888 Initial import
thib
parents:
diff changeset
194 for (i=0; new_data[i]!=0; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
195 switch(new_data[i]) {
223b71206888 Initial import
thib
parents:
diff changeset
196 case '?': *buf++ = '?'; *buf++ = '0'; break;
223b71206888 Initial import
thib
parents:
diff changeset
197 case '"': *buf++ = '?'; *buf++ = '1'; break;
223b71206888 Initial import
thib
parents:
diff changeset
198 case '\'': *buf++ = '?'; *buf++ = '2'; break;
223b71206888 Initial import
thib
parents:
diff changeset
199 case ',': *buf++ = '?'; *buf++ = '3'; break;
223b71206888 Initial import
thib
parents:
diff changeset
200 case '.': *buf++ = '?'; *buf++ = '4'; break;
223b71206888 Initial import
thib
parents:
diff changeset
201 case ':': *buf++ = '?'; *buf++ = '5'; break;
223b71206888 Initial import
thib
parents:
diff changeset
202 case ';': *buf++ = '?'; *buf++ = '6'; break;
223b71206888 Initial import
thib
parents:
diff changeset
203 case '=': *buf++ = '?'; *buf++ = '7'; break;
223b71206888 Initial import
thib
parents:
diff changeset
204 case '<': *buf++ = '?'; *buf++ = '8'; break;
223b71206888 Initial import
thib
parents:
diff changeset
205 case '>': *buf++ = '?'; *buf++ = '9'; break;
223b71206888 Initial import
thib
parents:
diff changeset
206 default: *buf++ = new_data[i]; break;
223b71206888 Initial import
thib
parents:
diff changeset
207 }
223b71206888 Initial import
thib
parents:
diff changeset
208 }
223b71206888 Initial import
thib
parents:
diff changeset
209 *buf++ = 0;
223b71206888 Initial import
thib
parents:
diff changeset
210 data += out_data;
223b71206888 Initial import
thib
parents:
diff changeset
211 delete[] out_data;
223b71206888 Initial import
thib
parents:
diff changeset
212 return;
223b71206888 Initial import
thib
parents:
diff changeset
213 }
223b71206888 Initial import
thib
parents:
diff changeset
214 const char* PatchOriginal(const char* data) {
223b71206888 Initial import
thib
parents:
diff changeset
215 static char* table = "?\"',.:;=<>";
223b71206888 Initial import
thib
parents:
diff changeset
216 if (new_data) delete[] new_data;
223b71206888 Initial import
thib
parents:
diff changeset
217 if (old_data) delete[] old_data;
223b71206888 Initial import
thib
parents:
diff changeset
218 new_data = 0; old_data = 0;
223b71206888 Initial import
thib
parents:
diff changeset
219 new_data = new char[1024];
223b71206888 Initial import
thib
parents:
diff changeset
220 int i,j = 0;
223b71206888 Initial import
thib
parents:
diff changeset
221 for (i=0; i<1020; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
222 switch(data[j]) {
223b71206888 Initial import
thib
parents:
diff changeset
223 case '?':
223b71206888 Initial import
thib
parents:
diff changeset
224 if (data[j+1] >= '0' && data[j+1] <= '9') {
223b71206888 Initial import
thib
parents:
diff changeset
225 new_data[i] = table[ data[j+1] - '0'];
223b71206888 Initial import
thib
parents:
diff changeset
226 j += 2;
223b71206888 Initial import
thib
parents:
diff changeset
227 break;
223b71206888 Initial import
thib
parents:
diff changeset
228 }
223b71206888 Initial import
thib
parents:
diff changeset
229 case '"': case '\'': case ',': case '.': case ':':
223b71206888 Initial import
thib
parents:
diff changeset
230 case ';': case '=': case '<': case '>':
223b71206888 Initial import
thib
parents:
diff changeset
231 goto for_end;
223b71206888 Initial import
thib
parents:
diff changeset
232 default: new_data[i] = data[j++]; break;
223b71206888 Initial import
thib
parents:
diff changeset
233 }
223b71206888 Initial import
thib
parents:
diff changeset
234 }
223b71206888 Initial import
thib
parents:
diff changeset
235 for_end:
223b71206888 Initial import
thib
parents:
diff changeset
236 new_data[i] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
237 return data;
223b71206888 Initial import
thib
parents:
diff changeset
238 }
223b71206888 Initial import
thib
parents:
diff changeset
239 void SetOriginal(void) {
223b71206888 Initial import
thib
parents:
diff changeset
240 if (new_data) delete[] new_data;
223b71206888 Initial import
thib
parents:
diff changeset
241 if (old_data) delete[] old_data;
223b71206888 Initial import
thib
parents:
diff changeset
242 new_data = 0; old_data = 0;
223b71206888 Initial import
thib
parents:
diff changeset
243 }
223b71206888 Initial import
thib
parents:
diff changeset
244 void Dump(FILE* f) const {
223b71206888 Initial import
thib
parents:
diff changeset
245 if (original_data) fprintf(f, "original %s ",original_data);
223b71206888 Initial import
thib
parents:
diff changeset
246 if (old_data) fprintf(f, "old_data %s ",old_data);
223b71206888 Initial import
thib
parents:
diff changeset
247 if (new_data) fprintf(f, "new_data %s ",new_data);
223b71206888 Initial import
thib
parents:
diff changeset
248 fprintf(f, "\n");
223b71206888 Initial import
thib
parents:
diff changeset
249 }
223b71206888 Initial import
thib
parents:
diff changeset
250 };
223b71206888 Initial import
thib
parents:
diff changeset
251
223b71206888 Initial import
thib
parents:
diff changeset
252 /************************************************
223b71206888 Initial import
thib
parents:
diff changeset
253 ** AyuSysConfigIntlistItem
223b71206888 Initial import
thib
parents:
diff changeset
254 ** 数値列をデータとしてもつ設定項目
223b71206888 Initial import
thib
parents:
diff changeset
255 */
223b71206888 Initial import
thib
parents:
diff changeset
256 class AyuSysConfigIntlistItem {
223b71206888 Initial import
thib
parents:
diff changeset
257 int item_deal;
223b71206888 Initial import
thib
parents:
diff changeset
258 int* original_data;
223b71206888 Initial import
thib
parents:
diff changeset
259 int* old_data;
223b71206888 Initial import
thib
parents:
diff changeset
260 int* new_data;
223b71206888 Initial import
thib
parents:
diff changeset
261 public:
223b71206888 Initial import
thib
parents:
diff changeset
262 AyuSysConfigIntlistItem(void) {
223b71206888 Initial import
thib
parents:
diff changeset
263 item_deal = 0;
223b71206888 Initial import
thib
parents:
diff changeset
264 original_data = 0;
223b71206888 Initial import
thib
parents:
diff changeset
265 old_data = 0;
223b71206888 Initial import
thib
parents:
diff changeset
266 new_data = 0;
223b71206888 Initial import
thib
parents:
diff changeset
267 }
223b71206888 Initial import
thib
parents:
diff changeset
268 AyuSysConfigIntlistItem(const AyuSysConfigIntlistItem& o) {
223b71206888 Initial import
thib
parents:
diff changeset
269 item_deal = o.item_deal;
223b71206888 Initial import
thib
parents:
diff changeset
270 original_data = 0; old_data = 0; new_data = 0;
223b71206888 Initial import
thib
parents:
diff changeset
271 if (o.original_data) {
223b71206888 Initial import
thib
parents:
diff changeset
272 original_data = new int[item_deal];
223b71206888 Initial import
thib
parents:
diff changeset
273 memcpy(original_data, o.original_data, sizeof(int)*item_deal);
223b71206888 Initial import
thib
parents:
diff changeset
274 }
223b71206888 Initial import
thib
parents:
diff changeset
275 if (o.old_data) {
223b71206888 Initial import
thib
parents:
diff changeset
276 old_data = new int[item_deal];
223b71206888 Initial import
thib
parents:
diff changeset
277 memcpy(old_data, o.old_data, sizeof(int)*item_deal);
223b71206888 Initial import
thib
parents:
diff changeset
278 }
223b71206888 Initial import
thib
parents:
diff changeset
279 if (o.new_data) {
223b71206888 Initial import
thib
parents:
diff changeset
280 new_data = new int[item_deal];
223b71206888 Initial import
thib
parents:
diff changeset
281 memcpy(new_data, o.new_data, sizeof(int)*item_deal);
223b71206888 Initial import
thib
parents:
diff changeset
282 }
223b71206888 Initial import
thib
parents:
diff changeset
283 }
223b71206888 Initial import
thib
parents:
diff changeset
284 /* 設定:Init で初期化、Set で変更、Get で変更を優先して取り出す */
223b71206888 Initial import
thib
parents:
diff changeset
285 void Init(int deal, const int* list) { /* deal は無視 */
223b71206888 Initial import
thib
parents:
diff changeset
286 if (original_data) delete[] original_data;
223b71206888 Initial import
thib
parents:
diff changeset
287 original_data = 0;
223b71206888 Initial import
thib
parents:
diff changeset
288 if (deal <= 0) {
223b71206888 Initial import
thib
parents:
diff changeset
289 item_deal = 0; return;
223b71206888 Initial import
thib
parents:
diff changeset
290 }
223b71206888 Initial import
thib
parents:
diff changeset
291 item_deal = deal;
223b71206888 Initial import
thib
parents:
diff changeset
292 original_data = new int[item_deal];
223b71206888 Initial import
thib
parents:
diff changeset
293 memcpy(original_data, list, sizeof(int)*deal);
223b71206888 Initial import
thib
parents:
diff changeset
294 }
223b71206888 Initial import
thib
parents:
diff changeset
295 void Set(int deal, const int* list) { /* deal は無視 */
223b71206888 Initial import
thib
parents:
diff changeset
296 item_deal = deal;
223b71206888 Initial import
thib
parents:
diff changeset
297 if (new_data) delete[] new_data;
223b71206888 Initial import
thib
parents:
diff changeset
298 new_data = new int[item_deal];
223b71206888 Initial import
thib
parents:
diff changeset
299 memcpy(new_data, list, sizeof(int)*item_deal);
223b71206888 Initial import
thib
parents:
diff changeset
300 }
223b71206888 Initial import
thib
parents:
diff changeset
301 const int* Get(int deal) const {/* deal は無視 */
223b71206888 Initial import
thib
parents:
diff changeset
302 if (item_deal == 0) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
303 if (deal > item_deal) {
223b71206888 Initial import
thib
parents:
diff changeset
304 fprintf(stderr,"AyuSysConfigIntlistItem::Get : invalid items deal %d (correct: %d)\n",deal,item_deal);
223b71206888 Initial import
thib
parents:
diff changeset
305 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
306 }
223b71206888 Initial import
thib
parents:
diff changeset
307 if (new_data) return new_data;
223b71206888 Initial import
thib
parents:
diff changeset
308 else if (old_data) return old_data;
223b71206888 Initial import
thib
parents:
diff changeset
309 return original_data;
223b71206888 Initial import
thib
parents:
diff changeset
310 }
223b71206888 Initial import
thib
parents:
diff changeset
311 const int* GetOriginal(int deal) const {/* deal は無視 */
223b71206888 Initial import
thib
parents:
diff changeset
312 if (item_deal == 0) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
313 if (deal > item_deal) {
223b71206888 Initial import
thib
parents:
diff changeset
314 fprintf(stderr,"AyuSysConfigIntlistItem::Get : invalid items deal %d (correct: %d)\n",deal,item_deal);
223b71206888 Initial import
thib
parents:
diff changeset
315 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
316 }
223b71206888 Initial import
thib
parents:
diff changeset
317 return original_data;
223b71206888 Initial import
thib
parents:
diff changeset
318 }
223b71206888 Initial import
thib
parents:
diff changeset
319 int Deal(void) const {
223b71206888 Initial import
thib
parents:
diff changeset
320 return item_deal;
223b71206888 Initial import
thib
parents:
diff changeset
321 }
223b71206888 Initial import
thib
parents:
diff changeset
322 /* オリジナルからの変化の調査 :
223b71206888 Initial import
thib
parents:
diff changeset
323 ** DiffOriginal で変化を文字列で取り出し、PatchOriginal で
223b71206888 Initial import
thib
parents:
diff changeset
324 ** 変化を反映
223b71206888 Initial import
thib
parents:
diff changeset
325 */
223b71206888 Initial import
thib
parents:
diff changeset
326 int DiffOriginalLen(void) {
223b71206888 Initial import
thib
parents:
diff changeset
327 if (new_data == 0) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
328 return 12 * item_deal + 1;
223b71206888 Initial import
thib
parents:
diff changeset
329 }
223b71206888 Initial import
thib
parents:
diff changeset
330 void DiffOriginal(string& data) {
223b71206888 Initial import
thib
parents:
diff changeset
331 if (new_data == 0) { /* あり得ない */
223b71206888 Initial import
thib
parents:
diff changeset
332 fprintf(stderr,"AyuSysConfigStringItem::DiffOriginal : this method must not called if not required!\n");
223b71206888 Initial import
thib
parents:
diff changeset
333 return;
223b71206888 Initial import
thib
parents:
diff changeset
334 }
223b71206888 Initial import
thib
parents:
diff changeset
335 int i; char buf[1024];
223b71206888 Initial import
thib
parents:
diff changeset
336 for (i=0; i<item_deal; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
337 sprintf(buf, "%d,",new_data[i]);
223b71206888 Initial import
thib
parents:
diff changeset
338 data += buf;
223b71206888 Initial import
thib
parents:
diff changeset
339 }
223b71206888 Initial import
thib
parents:
diff changeset
340 return;
223b71206888 Initial import
thib
parents:
diff changeset
341 }
223b71206888 Initial import
thib
parents:
diff changeset
342 const char* PatchOriginal(const char* data) {
223b71206888 Initial import
thib
parents:
diff changeset
343 if (old_data) delete[] old_data;
223b71206888 Initial import
thib
parents:
diff changeset
344 if (new_data) delete[] new_data;
223b71206888 Initial import
thib
parents:
diff changeset
345 old_data = 0; new_data = 0;
223b71206888 Initial import
thib
parents:
diff changeset
346 new_data = new int[item_deal];
223b71206888 Initial import
thib
parents:
diff changeset
347 int i;
223b71206888 Initial import
thib
parents:
diff changeset
348 for (i=0; i<item_deal; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
349 new_data[i] = atoi(data);
223b71206888 Initial import
thib
parents:
diff changeset
350 if (strchr(data, ',') == 0) break;
223b71206888 Initial import
thib
parents:
diff changeset
351 data = strchr(data, ',') + 1;
223b71206888 Initial import
thib
parents:
diff changeset
352 }
223b71206888 Initial import
thib
parents:
diff changeset
353 return data;
223b71206888 Initial import
thib
parents:
diff changeset
354 }
223b71206888 Initial import
thib
parents:
diff changeset
355 void SetOriginal(void) {
223b71206888 Initial import
thib
parents:
diff changeset
356 if (new_data) delete[] new_data;
223b71206888 Initial import
thib
parents:
diff changeset
357 if (old_data) delete[] old_data;
223b71206888 Initial import
thib
parents:
diff changeset
358 new_data = 0; old_data = 0;
223b71206888 Initial import
thib
parents:
diff changeset
359 }
223b71206888 Initial import
thib
parents:
diff changeset
360 void Dump(FILE* f) const {
223b71206888 Initial import
thib
parents:
diff changeset
361 fprintf(f, "item deal %d, ",item_deal);
223b71206888 Initial import
thib
parents:
diff changeset
362 if (original_data) {
223b71206888 Initial import
thib
parents:
diff changeset
363 fprintf(f, "(%d", original_data[0]);
223b71206888 Initial import
thib
parents:
diff changeset
364 int i;for (i=1; i<item_deal; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
365 fprintf(f, ",%d",original_data[i]);
223b71206888 Initial import
thib
parents:
diff changeset
366 }
223b71206888 Initial import
thib
parents:
diff changeset
367 fprintf(f, ") ");
223b71206888 Initial import
thib
parents:
diff changeset
368 }
223b71206888 Initial import
thib
parents:
diff changeset
369 if (old_data) {
223b71206888 Initial import
thib
parents:
diff changeset
370 fprintf(f, "old %08x(%d", (unsigned int)(old_data), old_data[0]);
223b71206888 Initial import
thib
parents:
diff changeset
371 int i;for (i=1; i<item_deal; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
372 fprintf(f, ",%d",old_data[i]);
223b71206888 Initial import
thib
parents:
diff changeset
373 }
223b71206888 Initial import
thib
parents:
diff changeset
374 fprintf(f, ") ");
223b71206888 Initial import
thib
parents:
diff changeset
375 }
223b71206888 Initial import
thib
parents:
diff changeset
376 if (new_data) {
223b71206888 Initial import
thib
parents:
diff changeset
377 fprintf(f, "new %08x(%d", (unsigned int)(new_data), new_data[0]);
223b71206888 Initial import
thib
parents:
diff changeset
378 int i;for (i=1; i<item_deal; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
379 fprintf(f, ",%d",new_data[i]);
223b71206888 Initial import
thib
parents:
diff changeset
380 }
223b71206888 Initial import
thib
parents:
diff changeset
381 fprintf(f, ") ");
223b71206888 Initial import
thib
parents:
diff changeset
382 }
223b71206888 Initial import
thib
parents:
diff changeset
383 fprintf(f, "\n");
223b71206888 Initial import
thib
parents:
diff changeset
384 }
223b71206888 Initial import
thib
parents:
diff changeset
385 };
223b71206888 Initial import
thib
parents:
diff changeset
386
223b71206888 Initial import
thib
parents:
diff changeset
387 // template map<HashStr, AyuSysConfigStringItem>;
223b71206888 Initial import
thib
parents:
diff changeset
388 // template map<HashStr, AyuSysConfigIntlistItem>;
223b71206888 Initial import
thib
parents:
diff changeset
389
223b71206888 Initial import
thib
parents:
diff changeset
390 /************************************************
223b71206888 Initial import
thib
parents:
diff changeset
391 ** AyuSysConfigItem
223b71206888 Initial import
thib
parents:
diff changeset
392 ** データ名 -> データ本体の map と、map 全体に
223b71206888 Initial import
thib
parents:
diff changeset
393 ** 様々な操作を行うためのメソッド
223b71206888 Initial import
thib
parents:
diff changeset
394 */
223b71206888 Initial import
thib
parents:
diff changeset
395
223b71206888 Initial import
thib
parents:
diff changeset
396 template<class ItemType, class DataType> class AyuSysConfigItem {
223b71206888 Initial import
thib
parents:
diff changeset
397 typedef map<HashStr,ItemType> maptype;
223b71206888 Initial import
thib
parents:
diff changeset
398 typedef typename maptype::iterator mapiterator;
223b71206888 Initial import
thib
parents:
diff changeset
399 typedef typename maptype::const_iterator const_mapiterator;
223b71206888 Initial import
thib
parents:
diff changeset
400 maptype data;
223b71206888 Initial import
thib
parents:
diff changeset
401 public:
223b71206888 Initial import
thib
parents:
diff changeset
402 void SetOrig(HashStr& name, int deal, const DataType* str) {
223b71206888 Initial import
thib
parents:
diff changeset
403 if (str == 0) return; /* 無効 */
223b71206888 Initial import
thib
parents:
diff changeset
404 data[name].Init(deal, str);
223b71206888 Initial import
thib
parents:
diff changeset
405 }
223b71206888 Initial import
thib
parents:
diff changeset
406 void Set(HashStr& name, int deal, const DataType* new_data) {
223b71206888 Initial import
thib
parents:
diff changeset
407 if (new_data == 0) return; /* 無効 */
223b71206888 Initial import
thib
parents:
diff changeset
408 /* 設定を検索 */
223b71206888 Initial import
thib
parents:
diff changeset
409 mapiterator it = data.find(name);
223b71206888 Initial import
thib
parents:
diff changeset
410 /* 設定が元設定に見つからないなら失敗 */
223b71206888 Initial import
thib
parents:
diff changeset
411 if (it == data.end()) {
223b71206888 Initial import
thib
parents:
diff changeset
412 fprintf(stderr,"AyuSysConfigItem::Set : there is no '%s' parameter\n",name.c_str());
223b71206888 Initial import
thib
parents:
diff changeset
413 return;
223b71206888 Initial import
thib
parents:
diff changeset
414 }
223b71206888 Initial import
thib
parents:
diff changeset
415 /* 設定を変更 */
223b71206888 Initial import
thib
parents:
diff changeset
416 it->second.Set(deal, new_data);
223b71206888 Initial import
thib
parents:
diff changeset
417 }
223b71206888 Initial import
thib
parents:
diff changeset
418 /* 新しい設定を優先して返す */
223b71206888 Initial import
thib
parents:
diff changeset
419 const DataType* Get(int deal, HashStr& name) const {
223b71206888 Initial import
thib
parents:
diff changeset
420 const_mapiterator it = data.find(name);
223b71206888 Initial import
thib
parents:
diff changeset
421 if (it == data.end()) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
422 return it->second.Get(deal);
223b71206888 Initial import
thib
parents:
diff changeset
423 }
223b71206888 Initial import
thib
parents:
diff changeset
424 const DataType* GetOriginal(int deal, HashStr& name) const {
223b71206888 Initial import
thib
parents:
diff changeset
425 const_mapiterator it = data.find(name);
223b71206888 Initial import
thib
parents:
diff changeset
426 if (it == data.end()) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
427 return it->second.GetOriginal(deal);
223b71206888 Initial import
thib
parents:
diff changeset
428 }
223b71206888 Initial import
thib
parents:
diff changeset
429 int Deal(HashStr& name) const {
223b71206888 Initial import
thib
parents:
diff changeset
430 const_mapiterator it = data.find(name);
223b71206888 Initial import
thib
parents:
diff changeset
431 if (it == data.end()) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
432 return it->second.Deal();
223b71206888 Initial import
thib
parents:
diff changeset
433 }
223b71206888 Initial import
thib
parents:
diff changeset
434 /* オリジナルからの変化の調査 :
223b71206888 Initial import
thib
parents:
diff changeset
435 ** DiffOriginal で変化を文字列で取り出し、PatchOriginal で
223b71206888 Initial import
thib
parents:
diff changeset
436 ** 変化を反映
223b71206888 Initial import
thib
parents:
diff changeset
437 */
223b71206888 Initial import
thib
parents:
diff changeset
438 void DiffOriginal(string& ret_str) {
223b71206888 Initial import
thib
parents:
diff changeset
439 mapiterator it = data.begin();
223b71206888 Initial import
thib
parents:
diff changeset
440 for (; it != data.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
441 int len = it->second.DiffOriginalLen();
223b71206888 Initial import
thib
parents:
diff changeset
442 if (len) {
223b71206888 Initial import
thib
parents:
diff changeset
443 ret_str += it->first.c_str();
223b71206888 Initial import
thib
parents:
diff changeset
444 ret_str += "=";
223b71206888 Initial import
thib
parents:
diff changeset
445 it->second.DiffOriginal(ret_str);
223b71206888 Initial import
thib
parents:
diff changeset
446 ret_str += ";";
223b71206888 Initial import
thib
parents:
diff changeset
447 }
223b71206888 Initial import
thib
parents:
diff changeset
448 }
223b71206888 Initial import
thib
parents:
diff changeset
449 ret_str += ";";
223b71206888 Initial import
thib
parents:
diff changeset
450 return;
223b71206888 Initial import
thib
parents:
diff changeset
451 }
223b71206888 Initial import
thib
parents:
diff changeset
452 const char* PatchOriginal(const char* diff_data) {
223b71206888 Initial import
thib
parents:
diff changeset
453 while(*diff_data != ';') {
223b71206888 Initial import
thib
parents:
diff changeset
454 char name[1024];
223b71206888 Initial import
thib
parents:
diff changeset
455 const char* data_start = strchr(diff_data, '=');
223b71206888 Initial import
thib
parents:
diff changeset
456 if (data_start == 0) break;
223b71206888 Initial import
thib
parents:
diff changeset
457 strncpy(name, diff_data, data_start-diff_data);
223b71206888 Initial import
thib
parents:
diff changeset
458 name[data_start-diff_data] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
459 data_start++;
223b71206888 Initial import
thib
parents:
diff changeset
460 mapiterator it = data.find(name);
223b71206888 Initial import
thib
parents:
diff changeset
461 if (it != data.end()) {
223b71206888 Initial import
thib
parents:
diff changeset
462 diff_data = data_start;
223b71206888 Initial import
thib
parents:
diff changeset
463 it->second.PatchOriginal(diff_data);
223b71206888 Initial import
thib
parents:
diff changeset
464 }
223b71206888 Initial import
thib
parents:
diff changeset
465 diff_data = strchr(diff_data, ';');
223b71206888 Initial import
thib
parents:
diff changeset
466 if (diff_data) diff_data++;
223b71206888 Initial import
thib
parents:
diff changeset
467 }
223b71206888 Initial import
thib
parents:
diff changeset
468 if (*diff_data == ';') {
223b71206888 Initial import
thib
parents:
diff changeset
469 diff_data++;
223b71206888 Initial import
thib
parents:
diff changeset
470 } else {
223b71206888 Initial import
thib
parents:
diff changeset
471 fprintf(stderr,"AyusysConfigItem::PatchOriginal: invalid data %s\n",diff_data);
223b71206888 Initial import
thib
parents:
diff changeset
472 }
223b71206888 Initial import
thib
parents:
diff changeset
473 return diff_data;
223b71206888 Initial import
thib
parents:
diff changeset
474 }
223b71206888 Initial import
thib
parents:
diff changeset
475 void SetOriginal(void) {
223b71206888 Initial import
thib
parents:
diff changeset
476 mapiterator it = data.begin();
223b71206888 Initial import
thib
parents:
diff changeset
477 for (; it != data.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
478 it->second.SetOriginal();
223b71206888 Initial import
thib
parents:
diff changeset
479 }
223b71206888 Initial import
thib
parents:
diff changeset
480 }
223b71206888 Initial import
thib
parents:
diff changeset
481 void Dump(FILE* f) const {
223b71206888 Initial import
thib
parents:
diff changeset
482 const_mapiterator it = data.begin();
223b71206888 Initial import
thib
parents:
diff changeset
483 for (; it != data.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
484 fprintf(f, "name %s: ",it->first.c_str());
223b71206888 Initial import
thib
parents:
diff changeset
485 it->second.Dump(f);
223b71206888 Initial import
thib
parents:
diff changeset
486 }
223b71206888 Initial import
thib
parents:
diff changeset
487 }
223b71206888 Initial import
thib
parents:
diff changeset
488 };
223b71206888 Initial import
thib
parents:
diff changeset
489 // template AyuSysConfigItem<AyuSysConfigStringItem, char>;
223b71206888 Initial import
thib
parents:
diff changeset
490 // template AyuSysConfigItem<AyuSysConfigIntlistItem, int>;
223b71206888 Initial import
thib
parents:
diff changeset
491
223b71206888 Initial import
thib
parents:
diff changeset
492 /************************************************/
223b71206888 Initial import
thib
parents:
diff changeset
493 /* ラッパ */
223b71206888 Initial import
thib
parents:
diff changeset
494 struct AyuSysConfigString {
223b71206888 Initial import
thib
parents:
diff changeset
495 AyuSysConfigItem<AyuSysConfigStringItem,char> orig;
223b71206888 Initial import
thib
parents:
diff changeset
496 void Dump(FILE* f) const {
223b71206888 Initial import
thib
parents:
diff changeset
497 fprintf(f, "string config:\n");
223b71206888 Initial import
thib
parents:
diff changeset
498 orig.Dump(f);
223b71206888 Initial import
thib
parents:
diff changeset
499 }
223b71206888 Initial import
thib
parents:
diff changeset
500 };
223b71206888 Initial import
thib
parents:
diff changeset
501 struct AyuSysConfigIntlist {
223b71206888 Initial import
thib
parents:
diff changeset
502 AyuSysConfigItem<AyuSysConfigIntlistItem, int> orig;
223b71206888 Initial import
thib
parents:
diff changeset
503 void Dump(FILE* f) const {
223b71206888 Initial import
thib
parents:
diff changeset
504 fprintf(f, "integer array config:\n");
223b71206888 Initial import
thib
parents:
diff changeset
505 orig.Dump(f);
223b71206888 Initial import
thib
parents:
diff changeset
506 }
223b71206888 Initial import
thib
parents:
diff changeset
507 };
223b71206888 Initial import
thib
parents:
diff changeset
508
223b71206888 Initial import
thib
parents:
diff changeset
509 /************************************************/
223b71206888 Initial import
thib
parents:
diff changeset
510 /* AyuSysConfig クラス */
223b71206888 Initial import
thib
parents:
diff changeset
511 int AyuSysConfig::SearchParam(const char* name) const{
223b71206888 Initial import
thib
parents:
diff changeset
512 HashStr str(name);
223b71206888 Initial import
thib
parents:
diff changeset
513 if (str_config->orig.Get(1, str)) return 1; /* char* のパラメータ */
223b71206888 Initial import
thib
parents:
diff changeset
514 else if (int_config->orig.Get(1, str)) return 2; /* int のパラメータ */
223b71206888 Initial import
thib
parents:
diff changeset
515 /* XXX.015.XXX の類のキー名を XXX.000.XXX の形に規格化して再検索 */
223b71206888 Initial import
thib
parents:
diff changeset
516 char name_copy[1024];
223b71206888 Initial import
thib
parents:
diff changeset
517 strncpy(name_copy, name, 1000);
223b71206888 Initial import
thib
parents:
diff changeset
518 name_copy[1000] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
519 char* s;
223b71206888 Initial import
thib
parents:
diff changeset
520 for (s=name_copy; s != 0; s = strchr(s,'.')) {
223b71206888 Initial import
thib
parents:
diff changeset
521 if (isdigit(s[1]) && isdigit(s[2]) && isdigit(s[3])) {
223b71206888 Initial import
thib
parents:
diff changeset
522 s[1] = '0'; s[2] = '0'; s[3] = '0';
223b71206888 Initial import
thib
parents:
diff changeset
523 }
223b71206888 Initial import
thib
parents:
diff changeset
524 s++;
223b71206888 Initial import
thib
parents:
diff changeset
525 }
223b71206888 Initial import
thib
parents:
diff changeset
526 HashStr str2(name_copy);
223b71206888 Initial import
thib
parents:
diff changeset
527 if (str_config->orig.Get(1, str2)) return 1; /* char* のパラメータ */
223b71206888 Initial import
thib
parents:
diff changeset
528 else if (int_config->orig.Get(1, str2)) return 2; /* int のパラメータ */
223b71206888 Initial import
thib
parents:
diff changeset
529 else return 0;
223b71206888 Initial import
thib
parents:
diff changeset
530 }
223b71206888 Initial import
thib
parents:
diff changeset
531 const char* AyuSysConfig::GetParaStr(const char* name) const{
223b71206888 Initial import
thib
parents:
diff changeset
532 HashStr str(name);
223b71206888 Initial import
thib
parents:
diff changeset
533 const char* ret = str_config->orig.Get(1,str);
223b71206888 Initial import
thib
parents:
diff changeset
534 if (ret == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
535 // fprintf(stderr,"Cannot find config name '%s'\n",name);
223b71206888 Initial import
thib
parents:
diff changeset
536 }
223b71206888 Initial import
thib
parents:
diff changeset
537 return ret;
223b71206888 Initial import
thib
parents:
diff changeset
538 }
223b71206888 Initial import
thib
parents:
diff changeset
539 int AyuSysConfig::GetParam(const char* name, int deal, ...) const{
223b71206888 Initial import
thib
parents:
diff changeset
540 HashStr str(name);
223b71206888 Initial import
thib
parents:
diff changeset
541 va_list va; int i;
223b71206888 Initial import
thib
parents:
diff changeset
542 const int* vars = int_config->orig.Get(deal, str);
223b71206888 Initial import
thib
parents:
diff changeset
543 if (vars == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
544 // fprintf(stderr,"Cannot find config name '%s'\n",name);
223b71206888 Initial import
thib
parents:
diff changeset
545 va_start(va, deal);
223b71206888 Initial import
thib
parents:
diff changeset
546 for (i=0; i<deal; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
547 int* var = va_arg(va, int*);
223b71206888 Initial import
thib
parents:
diff changeset
548 if (var) *var = 0;
223b71206888 Initial import
thib
parents:
diff changeset
549 }
223b71206888 Initial import
thib
parents:
diff changeset
550 return -1;
223b71206888 Initial import
thib
parents:
diff changeset
551 } else {
223b71206888 Initial import
thib
parents:
diff changeset
552 va_start(va, deal);
223b71206888 Initial import
thib
parents:
diff changeset
553 for (i=0; i<deal; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
554 int* var = va_arg(va, int*);
223b71206888 Initial import
thib
parents:
diff changeset
555 if (var) *var = vars[i];
223b71206888 Initial import
thib
parents:
diff changeset
556 }
223b71206888 Initial import
thib
parents:
diff changeset
557 }
223b71206888 Initial import
thib
parents:
diff changeset
558 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
559 }
223b71206888 Initial import
thib
parents:
diff changeset
560 int AyuSysConfig::GetOriginalParam(const char* name, int deal, ...) const{
223b71206888 Initial import
thib
parents:
diff changeset
561 HashStr str(name);
223b71206888 Initial import
thib
parents:
diff changeset
562 va_list va; int i;
223b71206888 Initial import
thib
parents:
diff changeset
563 const int* vars = int_config->orig.GetOriginal(deal, str);
223b71206888 Initial import
thib
parents:
diff changeset
564 if (vars == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
565 // fprintf(stderr,"Cannot find config name '%s'\n",name);
223b71206888 Initial import
thib
parents:
diff changeset
566 va_start(va, deal);
223b71206888 Initial import
thib
parents:
diff changeset
567 for (i=0; i<deal; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
568 int* var = va_arg(va, int*);
223b71206888 Initial import
thib
parents:
diff changeset
569 if (var) *var = 0;
223b71206888 Initial import
thib
parents:
diff changeset
570 }
223b71206888 Initial import
thib
parents:
diff changeset
571 return -1;
223b71206888 Initial import
thib
parents:
diff changeset
572 } else {
223b71206888 Initial import
thib
parents:
diff changeset
573 va_start(va, deal);
223b71206888 Initial import
thib
parents:
diff changeset
574 for (i=0; i<deal; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
575 int* var = va_arg(va, int*);
223b71206888 Initial import
thib
parents:
diff changeset
576 if (var) *var = vars[i];
223b71206888 Initial import
thib
parents:
diff changeset
577 }
223b71206888 Initial import
thib
parents:
diff changeset
578 }
223b71206888 Initial import
thib
parents:
diff changeset
579 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
580 }
223b71206888 Initial import
thib
parents:
diff changeset
581 const int* AyuSysConfig::GetParamArray(const char* name, int& deal) const{
223b71206888 Initial import
thib
parents:
diff changeset
582 HashStr str(name);
223b71206888 Initial import
thib
parents:
diff changeset
583 if (int_config->orig.Deal(str) == 0) { deal = 0; return 0; }
223b71206888 Initial import
thib
parents:
diff changeset
584 deal = int_config->orig.Deal(str);
223b71206888 Initial import
thib
parents:
diff changeset
585 const int* vars = int_config->orig.Get(deal, str);
223b71206888 Initial import
thib
parents:
diff changeset
586 if (vars == 0) { deal = 0; return 0; }
223b71206888 Initial import
thib
parents:
diff changeset
587 return vars;
223b71206888 Initial import
thib
parents:
diff changeset
588 }
223b71206888 Initial import
thib
parents:
diff changeset
589 void AyuSysConfig::SetParaStr(const char* name, const char* var) {
223b71206888 Initial import
thib
parents:
diff changeset
590 HashStr str(name);
223b71206888 Initial import
thib
parents:
diff changeset
591 dirty_flag = 1; change_flag = 1;
223b71206888 Initial import
thib
parents:
diff changeset
592 str_config->orig.Set(str, 1, var);
223b71206888 Initial import
thib
parents:
diff changeset
593 }
223b71206888 Initial import
thib
parents:
diff changeset
594 void AyuSysConfig::SetParam(const char* name, int deal, ...) {
223b71206888 Initial import
thib
parents:
diff changeset
595 if (deal >= MAXVARS) return ;
223b71206888 Initial import
thib
parents:
diff changeset
596 HashStr str(name);
223b71206888 Initial import
thib
parents:
diff changeset
597 int vars[MAXVARS]; va_list va; int i;
223b71206888 Initial import
thib
parents:
diff changeset
598 va_start(va, deal);
223b71206888 Initial import
thib
parents:
diff changeset
599 for (i=0; i<deal; i++) vars[i] = va_arg(va, int);
223b71206888 Initial import
thib
parents:
diff changeset
600 int_config->orig.Set(str, deal, vars);
223b71206888 Initial import
thib
parents:
diff changeset
601 dirty_flag = 1; change_flag = 1;
223b71206888 Initial import
thib
parents:
diff changeset
602 return;
223b71206888 Initial import
thib
parents:
diff changeset
603 }
223b71206888 Initial import
thib
parents:
diff changeset
604 void AyuSysConfig::SetOrigParaStr(const char* name, const char* var) {
223b71206888 Initial import
thib
parents:
diff changeset
605 HashStr str(name);
223b71206888 Initial import
thib
parents:
diff changeset
606 str_config->orig.SetOrig(str, 1, var);
223b71206888 Initial import
thib
parents:
diff changeset
607 change_flag = 1;
223b71206888 Initial import
thib
parents:
diff changeset
608 }
223b71206888 Initial import
thib
parents:
diff changeset
609 void AyuSysConfig::SetOrigParam(const char* name, int deal, ...) {
223b71206888 Initial import
thib
parents:
diff changeset
610 if (deal >= MAXVARS) return;
223b71206888 Initial import
thib
parents:
diff changeset
611 HashStr str(name);
223b71206888 Initial import
thib
parents:
diff changeset
612 int vars[MAXVARS]; va_list va; int i;
223b71206888 Initial import
thib
parents:
diff changeset
613 va_start(va, deal);
223b71206888 Initial import
thib
parents:
diff changeset
614 for(i=0; i<deal; i++) vars[i] = va_arg(va, int);
223b71206888 Initial import
thib
parents:
diff changeset
615 int_config->orig.SetOrig(str, deal, vars);
223b71206888 Initial import
thib
parents:
diff changeset
616 change_flag = 1;
223b71206888 Initial import
thib
parents:
diff changeset
617 }
223b71206888 Initial import
thib
parents:
diff changeset
618 void AyuSysConfig::SetOrigParamArray(const char* name, int deal, int* array) {
223b71206888 Initial import
thib
parents:
diff changeset
619 HashStr str(name);
223b71206888 Initial import
thib
parents:
diff changeset
620 int_config->orig.SetOrig(str, deal, array);
223b71206888 Initial import
thib
parents:
diff changeset
621 }
223b71206888 Initial import
thib
parents:
diff changeset
622 void AyuSysConfig::SetOriginal(void) {
223b71206888 Initial import
thib
parents:
diff changeset
623 /* 全ての設定を元に戻す */
223b71206888 Initial import
thib
parents:
diff changeset
624 str_config->orig.SetOriginal();
223b71206888 Initial import
thib
parents:
diff changeset
625 int_config->orig.SetOriginal();
223b71206888 Initial import
thib
parents:
diff changeset
626 change_flag = 1;
223b71206888 Initial import
thib
parents:
diff changeset
627 }
223b71206888 Initial import
thib
parents:
diff changeset
628 void AyuSysConfig::DiffOriginal(string& data) {
223b71206888 Initial import
thib
parents:
diff changeset
629 str_config->orig.DiffOriginal(data);
223b71206888 Initial import
thib
parents:
diff changeset
630 int_config->orig.DiffOriginal(data);
223b71206888 Initial import
thib
parents:
diff changeset
631 return;
223b71206888 Initial import
thib
parents:
diff changeset
632 }
223b71206888 Initial import
thib
parents:
diff changeset
633 const char* AyuSysConfig::PatchOriginal(const char* data) {
223b71206888 Initial import
thib
parents:
diff changeset
634 data = str_config->orig.PatchOriginal(data);
223b71206888 Initial import
thib
parents:
diff changeset
635 data = int_config->orig.PatchOriginal(data);
223b71206888 Initial import
thib
parents:
diff changeset
636 return data;
223b71206888 Initial import
thib
parents:
diff changeset
637 }
223b71206888 Initial import
thib
parents:
diff changeset
638
223b71206888 Initial import
thib
parents:
diff changeset
639 void AyuSysConfig::Dump(FILE* f) const {
223b71206888 Initial import
thib
parents:
diff changeset
640 str_config->Dump(f);
223b71206888 Initial import
thib
parents:
diff changeset
641 int_config->Dump(f);
223b71206888 Initial import
thib
parents:
diff changeset
642 }
223b71206888 Initial import
thib
parents:
diff changeset
643
223b71206888 Initial import
thib
parents:
diff changeset
644 /************************************************
223b71206888 Initial import
thib
parents:
diff changeset
645 ** AyuSysConfig のコンストラクタ:
223b71206888 Initial import
thib
parents:
diff changeset
646 ** 全ての config 項目を初期化する
223b71206888 Initial import
thib
parents:
diff changeset
647 */
223b71206888 Initial import
thib
parents:
diff changeset
648 AyuSysConfig::AyuSysConfig(void) {
223b71206888 Initial import
thib
parents:
diff changeset
649 int i;
223b71206888 Initial import
thib
parents:
diff changeset
650
223b71206888 Initial import
thib
parents:
diff changeset
651 change_flag = 1; dirty_flag = 0;
223b71206888 Initial import
thib
parents:
diff changeset
652 str_config = new AyuSysConfigString;
223b71206888 Initial import
thib
parents:
diff changeset
653 int_config = new AyuSysConfigIntlist;
223b71206888 Initial import
thib
parents:
diff changeset
654
223b71206888 Initial import
thib
parents:
diff changeset
655 /****** 文字列 *******/
223b71206888 Initial import
thib
parents:
diff changeset
656 SetOrigParaStr("#WAKUPDT", "GRDAT"); /* 枠、マウスカーソルなどの画像ファイル */
223b71206888 Initial import
thib
parents:
diff changeset
657 SetOrigParaStr("#REGNAME", "xclannad"); /* レジストリ名。セーブファイルの作成に使う */
223b71206888 Initial import
thib
parents:
diff changeset
658 SetOrigParaStr("#CAPTION", "xclannad"); /* ウィンドウのタイトル */
223b71206888 Initial import
thib
parents:
diff changeset
659 SetOrigParaStr("#SAVENAME","SAVE.INI"); /* セーブファイルの名前 */
223b71206888 Initial import
thib
parents:
diff changeset
660 SetOrigParaStr("#SAVETITLE", "This is save file"); /* セーブファイルの先頭の文字列 */
223b71206888 Initial import
thib
parents:
diff changeset
661 SetOrigParaStr("#SAVENOTITLE", "-----------------"); /* 使われてないセーブデータの名前 */
223b71206888 Initial import
thib
parents:
diff changeset
662 SetOrigParaStr("#CGM_FILE", "MODE.CGM");/* CG mode の設定が保存されたファイル名 */
223b71206888 Initial import
thib
parents:
diff changeset
663 SetOrigParaStr("#CGTABLE_FILE", "MODE.CGM");/* CG mode の設定が保存されたファイル名 */
223b71206888 Initial import
thib
parents:
diff changeset
664
223b71206888 Initial import
thib
parents:
diff changeset
665 SetOrigParaStr("#WAKU.000.000.NAME", ""); // テキストウィンドウの窓飾り画像名
223b71206888 Initial import
thib
parents:
diff changeset
666 SetOrigParaStr("#WAKU.000.000.BACK", ""); // テキストウィンドウのテキスト背景画像名
223b71206888 Initial import
thib
parents:
diff changeset
667 SetOrigParaStr("#WAKU.000.000.BTN", ""); // テキストウィンドウのボタン画像名
223b71206888 Initial import
thib
parents:
diff changeset
668
223b71206888 Initial import
thib
parents:
diff changeset
669 SetOrigParaStr("#MOUSE_CURSOR.000.NAME", ""); // マウスカーソルのファイル名
223b71206888 Initial import
thib
parents:
diff changeset
670 SetOrigParaStr("#CURSOR.000.NAME", ""); // リターンカーソルのファイル名
223b71206888 Initial import
thib
parents:
diff changeset
671 SetOrigParaStr("#SELBTN.000.NAME", ""); // 選択肢背景
223b71206888 Initial import
thib
parents:
diff changeset
672 SetOrigParaStr("#SELBTN.000.BACK", ""); // 選択肢背景
223b71206888 Initial import
thib
parents:
diff changeset
673
223b71206888 Initial import
thib
parents:
diff changeset
674 char name_str[8] = "#NAME.A";
223b71206888 Initial import
thib
parents:
diff changeset
675 for (i='A'; i<='Z'; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
676 name_str[6] = i;
223b71206888 Initial import
thib
parents:
diff changeset
677 SetOrigParaStr(name_str, "");
223b71206888 Initial import
thib
parents:
diff changeset
678 }
223b71206888 Initial import
thib
parents:
diff changeset
679
223b71206888 Initial import
thib
parents:
diff changeset
680 /****** 数値列 *******/
223b71206888 Initial import
thib
parents:
diff changeset
681 SetOrigParam("#CANCELCALL", 2, 0,0); /* キャンセルボタン(右クリック)したときに呼び出されるサブルーチン番号(メニュー) */
223b71206888 Initial import
thib
parents:
diff changeset
682 SetOrigParam("#COM2_TITLE", 1, 1); /* ? */
223b71206888 Initial import
thib
parents:
diff changeset
683 SetOrigParam("#COM2_TITLE_COLOR", 1, 2); /* 選択肢タイトルの色 */
223b71206888 Initial import
thib
parents:
diff changeset
684 SetOrigParam("#COM2_TITLE_INDENT", 1, 2); /* ? */
223b71206888 Initial import
thib
parents:
diff changeset
685 SetOrigParam("#SAVEFILETIME", 1, 24); /* セーブする場所の数 */
223b71206888 Initial import
thib
parents:
diff changeset
686 SetOrigParam("#SEEN_START", 1, 0); /* ゲームを開始するシナリオ番号 */
223b71206888 Initial import
thib
parents:
diff changeset
687 SetOrigParam("#SEEN_SRT", 1, 0); /* ゲームを開始するシナリオ番号(好き好き大好き) */
223b71206888 Initial import
thib
parents:
diff changeset
688 SetOrigParam("#SEEN_MENU", 1, 0); /* メニューのシナリオ番号 */
223b71206888 Initial import
thib
parents:
diff changeset
689 SetOrigParam("#SEEN_TEXT_CURRENT", 1, 0); /* seen.txt を root directory に置くか */
223b71206888 Initial import
thib
parents:
diff changeset
690 SetOrigParam("#FADE_TIME", 1, 40); /* 画面のフェード・アウトの速度 */
223b71206888 Initial import
thib
parents:
diff changeset
691 SetOrigParam("#NVL_SYSTEM",1, 0); /* テキストウィンドウが全画面か否か */
223b71206888 Initial import
thib
parents:
diff changeset
692 SetOrigParam("#WINDOW_ATTR", 5, -1, 128,128, 190, 0); /* テキストウィンドウの色 */
223b71206888 Initial import
thib
parents:
diff changeset
693 SetOrigParam("#WINDOW_ATTR_AREA", 4, 4,4,4,4); /* テキストウィンドウの範囲 */
223b71206888 Initial import
thib
parents:
diff changeset
694 SetOrigParam("#WINDOW_ATTR_TYPE", 1, 0); /* テキストウィンドウを半透明にするか */
223b71206888 Initial import
thib
parents:
diff changeset
695 SetOrigParam("#WINDOW_MSG_POS", 2, 22, 350); /* テキストウィンドウの位置 */
223b71206888 Initial import
thib
parents:
diff changeset
696 SetOrigParam("#WINDOW_COM_POS", 2,450, 250); /* 選択ウィンドウの位置 */
223b71206888 Initial import
thib
parents:
diff changeset
697 SetOrigParam("#WINDOW_GRP_POS", 2, 16, 100); /* なにかのウィンドウの位置 */
223b71206888 Initial import
thib
parents:
diff changeset
698 SetOrigParam("#WINDOW_SUB_POS", 2, 48, 100); /* なにかのウィンドウの位置 */
223b71206888 Initial import
thib
parents:
diff changeset
699 SetOrigParam("#WINDOW_SYS_POS", 2, 32, 100); /* なにかのウィンドウの位置 */
223b71206888 Initial import
thib
parents:
diff changeset
700 SetOrigParam("#WINDOW_WAKU_TYPE", 1, 0); /* テキストウィンドウの枠の種類。xkanon 独自設定 */
223b71206888 Initial import
thib
parents:
diff changeset
701 SetOrigParam("#RETN_CONT", 1, 16); /* リターンカーソルの数 */
223b71206888 Initial import
thib
parents:
diff changeset
702 SetOrigParam("#RETN_SPEED",1,100); /* リターンカーソルの動く速度 */
223b71206888 Initial import
thib
parents:
diff changeset
703 SetOrigParam("#RETN_XSIZE", 1, 16); /* リターンカーソルの大きさ */
223b71206888 Initial import
thib
parents:
diff changeset
704 SetOrigParam("#RETN_YSIZE", 1, 16); /* リターンカーソルの大きさ */
223b71206888 Initial import
thib
parents:
diff changeset
705 SetOrigParam("#FONT_SIZE", 1, 26); /* フォントの大きさ */
223b71206888 Initial import
thib
parents:
diff changeset
706 SetOrigParam("#FONT_WEIGHT", 1, 100); /* フォントの weight */
223b71206888 Initial import
thib
parents:
diff changeset
707 SetOrigParam("#MSG_MOJI_SIZE", 2, 12, 29); /* 文字の大きさ(半角) */
223b71206888 Initial import
thib
parents:
diff changeset
708 SetOrigParam("#MESSAGE_SIZE", 2, 23, 3); /* メッセージウィンドウの文字数 */
223b71206888 Initial import
thib
parents:
diff changeset
709 SetOrigParam("#COM_MESSAGE_SIZE", 2, 23, 3); /* メッセージウィンドウの文字数 */
223b71206888 Initial import
thib
parents:
diff changeset
710 SetOrigParam("#INIT_MESSAGE_SPEED", 1, 30); /* テキスト表示速度 */
223b71206888 Initial import
thib
parents:
diff changeset
711 SetOrigParam("#INIT_MESSAGE_SPEED_MOD", 1, 0); /* テキスト表示 no wait */
223b71206888 Initial import
thib
parents:
diff changeset
712 SetOrigParam("#MESSAGE_KEY_WAIT_USE", 1, 0); /* テキスト進行オートモード */
223b71206888 Initial import
thib
parents:
diff changeset
713 SetOrigParam("#MESSAGE_KEY_WAIT_TIME", 1, 1500); /* オートモードでのキー待ち時間 */
223b71206888 Initial import
thib
parents:
diff changeset
714
223b71206888 Initial import
thib
parents:
diff changeset
715 SetOrigParam("#GRP_DC_TIMES", 1, 4); /* 裏画面の数 */
223b71206888 Initial import
thib
parents:
diff changeset
716 SetOrigParam("#MUSIC_LINEAR_PAC",1,0); /* PCM データの 8bit -> 16bit 変換を行うか */
223b71206888 Initial import
thib
parents:
diff changeset
717 SetOrigParam("#MUSIC_TYPE",1,0); /* PCM データの種類 */
223b71206888 Initial import
thib
parents:
diff changeset
718 SetOrigParam("#WINDOW_MSGBK_BOX",1,0); /* バックログ用のボタン */
223b71206888 Initial import
thib
parents:
diff changeset
719 SetOrigParam("#WINDOW_MSGBK_LBOX_POS",4,15,7,8,0); /* バックログ用のボタン(左)の位置 */
223b71206888 Initial import
thib
parents:
diff changeset
720 SetOrigParam("#WINDOW_MSGBK_RBOX_POS",4,7,7,0,0); /* バックログ用のボタン(左)の位置 */
223b71206888 Initial import
thib
parents:
diff changeset
721 SetOrigParam("#MSGBK_MOD",1,0); /* バックログ用のボタンを使用するか */
223b71206888 Initial import
thib
parents:
diff changeset
722
223b71206888 Initial import
thib
parents:
diff changeset
723 SetOrigParam("#WAKU.000.000.TYPE", 1, 5);
223b71206888 Initial import
thib
parents:
diff changeset
724 SetOrigParam("#WAKU.000.000.MOVE_BOX", 5, 0, 0, 0, 0, 0); // テキストウィンドウの移動用ボタン位置
223b71206888 Initial import
thib
parents:
diff changeset
725 SetOrigParam("#WAKU.000.000.CLEAR_BOX", 5, 0, 0, 0, 0, 0); // 一時消去用ボタン位置
223b71206888 Initial import
thib
parents:
diff changeset
726 SetOrigParam("#WAKU.000.000.READJUMP_BOX", 5, 0, 0, 0, 0, 0); // スキップ用ボタン位置
223b71206888 Initial import
thib
parents:
diff changeset
727 SetOrigParam("#WAKU.000.000.AUTOMODE_BOX", 5, 0, 0, 0, 0, 0); // オート用ボタン位置
223b71206888 Initial import
thib
parents:
diff changeset
728 SetOrigParam("#WAKU.000.000.MSGBK_BOX", 5, 0, 0, 0, 0, 0); // バックログボタン位置
223b71206888 Initial import
thib
parents:
diff changeset
729 SetOrigParam("#WAKU.000.000.MSGBKLEFT_BOX", 5, 0, 0, 0, 0, 0); // バックログ(進める)ボタン位置
223b71206888 Initial import
thib
parents:
diff changeset
730 SetOrigParam("#WAKU.000.000.MSGBKRIGHT_BOX", 5, 0, 0, 0, 0, 0); // バックログ(戻る)ボタン位置
223b71206888 Initial import
thib
parents:
diff changeset
731 SetOrigParam("#WAKU.000.000.EXBTN_000_BOX", 5, 0, 0, 0, 0, 0); // その他ボタン0位置
223b71206888 Initial import
thib
parents:
diff changeset
732 SetOrigParam("#WAKU.000.000.EXBTN_001_BOX", 5, 0, 0, 0, 0, 0); // その他ボタン1位置
223b71206888 Initial import
thib
parents:
diff changeset
733 SetOrigParam("#WAKU.000.000.EXBTN_002_BOX", 5, 0, 0, 0, 0, 0); // その他ボタン2位置
223b71206888 Initial import
thib
parents:
diff changeset
734
223b71206888 Initial import
thib
parents:
diff changeset
735 SetOrigParam("#WINDOW.000.MOJI_SIZE", 1, 21); // 文字サイズ
223b71206888 Initial import
thib
parents:
diff changeset
736 SetOrigParam("#WINDOW.000.MOJI_REP", 2, -1, 2); // 文字の余裕
223b71206888 Initial import
thib
parents:
diff changeset
737 SetOrigParam("#WINDOW.000.MOJI_CNT", 2, 20, 3); // ウィンドウ内の文字数
223b71206888 Initial import
thib
parents:
diff changeset
738 SetOrigParam("#WINDOW.000.MOJI_POS", 4, 100, 0, 180, 40); // テキスト位置。3つ目がx で1つ目がyらしい
223b71206888 Initial import
thib
parents:
diff changeset
739 SetOrigParam("#WINDOW.000.MOJI_SHADOW", 1, 0); // 文字に影を付けるか
223b71206888 Initial import
thib
parents:
diff changeset
740 SetOrigParam("#WINDOW.000.LUBY_SIZE", 1, 8); // ルビの文字サイズ
223b71206888 Initial import
thib
parents:
diff changeset
741 SetOrigParam("#WINDOW.000.MOJI_MIN", 2, 8, 1); // 文字同士の隙間?
223b71206888 Initial import
thib
parents:
diff changeset
742 SetOrigParam("#WINDOW.000.SELCOM_USE", 1, 0); // 選択肢の実装方法
223b71206888 Initial import
thib
parents:
diff changeset
743 SetOrigParam("#WINDOW.000.POS", 4, 100, 0, 0, 260); // ウィンドウ位置
223b71206888 Initial import
thib
parents:
diff changeset
744 SetOrigParam("#WINDOW.000.ATTR_MOD", 1, 0); // ウィンドウ色
223b71206888 Initial import
thib
parents:
diff changeset
745 SetOrigParam("#WINDOW.000.ATTR", 5, -1, -1, -1, -1, -1); // ウィンドウ色
223b71206888 Initial import
thib
parents:
diff changeset
746 /* SELCOM はよくわからんので無視 */
223b71206888 Initial import
thib
parents:
diff changeset
747 SetOrigParam("#WINDOW.000.OPEN_ANM_MOD", 1, 0); // ウィンドウを開くときの効果らしい
223b71206888 Initial import
thib
parents:
diff changeset
748 SetOrigParam("#WINDOW.000.OPEN_ANM_TIME", 1, 500);
223b71206888 Initial import
thib
parents:
diff changeset
749 SetOrigParam("#WINDOW.000.CLOSE_ANM_MOD", 1, 0); // ウィンドウを閉じるときの効果らしい
223b71206888 Initial import
thib
parents:
diff changeset
750 SetOrigParam("#WINDOW.000.CLOSE_ANM_TIME", 1, 500);
223b71206888 Initial import
thib
parents:
diff changeset
751 SetOrigParam("#WINDOW.000.WAKU_SETNO", 1, 0); // 枠の種類
223b71206888 Initial import
thib
parents:
diff changeset
752 SetOrigParam("#WINDOW.000.MOVE_USE", 1, 0); // ウィンドウ枠移動ボタン使用の可否
223b71206888 Initial import
thib
parents:
diff changeset
753 SetOrigParam("#WINDOW.000.CLEAR_USE", 1, 0); // ウィンドウ枠消去ボタン使用の可否
223b71206888 Initial import
thib
parents:
diff changeset
754 SetOrigParam("#WINDOW.000.READJUMP_USE", 1, 0); // スキップボタン使用の可否
223b71206888 Initial import
thib
parents:
diff changeset
755 SetOrigParam("#WINDOW.000.AUTOMODE_USE", 1, 0); // スキップボタン使用の可否
223b71206888 Initial import
thib
parents:
diff changeset
756 SetOrigParam("#WINDOW.000.MSGBK_USE", 1, 0); // バックログボタン使用の可否
223b71206888 Initial import
thib
parents:
diff changeset
757 SetOrigParam("#WINDOW.000.MSGBKLEFT_USE", 1, 0); // バックログ(進む)ボタン使用の可否
223b71206888 Initial import
thib
parents:
diff changeset
758 SetOrigParam("#WINDOW.000.MSGBKRIGHT_USE", 1, 0); // バックログ(戻る)ボタン使用の可否
223b71206888 Initial import
thib
parents:
diff changeset
759 SetOrigParam("#WINDOW.000.EXBTN_000_USE", 1, 0); // その他ボタン0使用の可否
223b71206888 Initial import
thib
parents:
diff changeset
760 SetOrigParam("#WINDOW.000.EXBTN_001_USE", 1, 0); // その他ボタン1使用の可否
223b71206888 Initial import
thib
parents:
diff changeset
761 SetOrigParam("#WINDOW.000.EXBTN_002_USE", 1, 0); // その他ボタン2使用の可否
223b71206888 Initial import
thib
parents:
diff changeset
762 SetOrigParam("#WINDOW.000.NAME_MOD", 1, 0); // 名前ウィンドウを別途使用するか
223b71206888 Initial import
thib
parents:
diff changeset
763 SetOrigParam("#WINDOW.000.NAME_MOJI_SIZE", 1, 20); // 名前フォントのサイズ
223b71206888 Initial import
thib
parents:
diff changeset
764 SetOrigParam("#WINDOW.000.NAME_MOJI_POS", 2, 0, 0); // 名前ウィンドウの文字の位置
223b71206888 Initial import
thib
parents:
diff changeset
765 SetOrigParam("#WINDOW.000.NAME_MOJI_MIN", 1, 0); // 名前ウィンドウの幅
223b71206888 Initial import
thib
parents:
diff changeset
766 SetOrigParam("#WINDOW.000.NAME_CENTERING", 1, 1); // 名前のセンタリングの有無
223b71206888 Initial import
thib
parents:
diff changeset
767 SetOrigParam("#WINDOW.000.NAME_POS", 2, 159, 78); // 名前ウィンドウ位置(左下位置らしい)
223b71206888 Initial import
thib
parents:
diff changeset
768 SetOrigParam("#WINDOW.000.NAME_WAKU_SETNO", 1, -1); // 名前ウィンドウ位置(左下位置らしい)
223b71206888 Initial import
thib
parents:
diff changeset
769 SetOrigParam("#WINDOW.000.FACE.000", 5, 0, 0, 1, 1, 1); // 顔ウィンドウ位置(始め2つがx,y、MOJI_POSからの相対位置なのに注意)
223b71206888 Initial import
thib
parents:
diff changeset
770 SetOrigParam("#WINDOW.000.KEYCUR_MOD", 3, 0, 0, 0); // リターンカーソルの位置
223b71206888 Initial import
thib
parents:
diff changeset
771
223b71206888 Initial import
thib
parents:
diff changeset
772
223b71206888 Initial import
thib
parents:
diff changeset
773 SetOrigParam("#CURSOR.000.SIZE", 2, 0, 0); // リターンカーソルの大きさ
223b71206888 Initial import
thib
parents:
diff changeset
774 SetOrigParam("#CURSOR.000.CONT", 1, 50); // リターンカーソルの繰り返し数
223b71206888 Initial import
thib
parents:
diff changeset
775 SetOrigParam("#CURSOR.000.SPEED", 1, 1000); // ブリンクする速さ
223b71206888 Initial import
thib
parents:
diff changeset
776
223b71206888 Initial import
thib
parents:
diff changeset
777 SetOrigParam("#SELBTN.000.BASEPOS", 2, 0, 0); // 選択肢ウィンドウの位置
223b71206888 Initial import
thib
parents:
diff changeset
778 SetOrigParam("#SELBTN.000.REPPOS", 2, 0, 50); // 選択肢ウィンドウの次の位置(相対)
223b71206888 Initial import
thib
parents:
diff changeset
779 SetOrigParam("#SELBTN.000.MOJISIZE", 4, 26, 0,0,0); // 文字の大きさ
223b71206888 Initial import
thib
parents:
diff changeset
780 SetOrigParam("#SELBTN.000.MOJIDEFAULTCOL", 1, 0); // 非選択時の文字色
223b71206888 Initial import
thib
parents:
diff changeset
781 SetOrigParam("#SELBTN.000.MOJISELECTCOL", 1, 0); // 選択時の文字色
223b71206888 Initial import
thib
parents:
diff changeset
782
223b71206888 Initial import
thib
parents:
diff changeset
783 SetOrigParam("#COLOR_TABLE.000", 3, 255,255,255);
223b71206888 Initial import
thib
parents:
diff changeset
784 SetOrigParam("#SHAKE.000", 3, 0,0,0);
223b71206888 Initial import
thib
parents:
diff changeset
785
223b71206888 Initial import
thib
parents:
diff changeset
786 SetOrigParam("#SELR.000",16,0,0,640,480,0,0,500,50,0,0,0,0,0,0,255,0);
223b71206888 Initial import
thib
parents:
diff changeset
787 SetOrigParam("#SEL.000", 15,0,0,639,479,0,0, 32, 4,0,0,0,0,0,0,0);
223b71206888 Initial import
thib
parents:
diff changeset
788
223b71206888 Initial import
thib
parents:
diff changeset
789 SetOrigParam("#SCREENSIZE_MOD", 1, 0); /* 0 = 640x480; 1 = 800x600 */
16
92765a5661f7 added "new" label on last savegame and corrected StatSaveFile
thib
parents: 9
diff changeset
790
92765a5661f7 added "new" label on last savegame and corrected StatSaveFile
thib
parents: 9
diff changeset
791 SetOrigParam("#LASTSAVE", 1, 0);
26
f45da03ca631 * Corrected --disable-vorbis in configure.ac
thib
parents: 16
diff changeset
792
f45da03ca631 * Corrected --disable-vorbis in configure.ac
thib
parents: 16
diff changeset
793 SetOrigParam("#VOLMOD", 4, 128, 128, 128, 128);
0
223b71206888 Initial import
thib
parents:
diff changeset
794 }
9
b6d6c0ffb423 Fixed some memory leaks
thib
parents: 0
diff changeset
795 AyuSysConfig::~AyuSysConfig(void) {
b6d6c0ffb423 Fixed some memory leaks
thib
parents: 0
diff changeset
796 delete str_config;
b6d6c0ffb423 Fixed some memory leaks
thib
parents: 0
diff changeset
797 delete int_config;
b6d6c0ffb423 Fixed some memory leaks
thib
parents: 0
diff changeset
798 }
0
223b71206888 Initial import
thib
parents:
diff changeset
799
223b71206888 Initial import
thib
parents:
diff changeset
800 static int SplitVar(const char* str, int* ret_var, int ret_size) {
223b71206888 Initial import
thib
parents:
diff changeset
801 /* , あるいは ),:( をセパレータとして、-?[0-9]+ の
223b71206888 Initial import
thib
parents:
diff changeset
802 ** フォーマットの数値列を読み込む。先頭に (、末尾に ) が付きうる。
223b71206888 Initial import
thib
parents:
diff changeset
803 ** (),-[0-9] 以外の文字があったらそこで終了
223b71206888 Initial import
thib
parents:
diff changeset
804 ** 得られたデータ数を返す
223b71206888 Initial import
thib
parents:
diff changeset
805 */
223b71206888 Initial import
thib
parents:
diff changeset
806 if (*str == '(') str++;
223b71206888 Initial import
thib
parents:
diff changeset
807 int i; for (i=0; i<ret_size; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
808 int c; int is_positive = 1;
223b71206888 Initial import
thib
parents:
diff changeset
809 /* セパレータの読み飛ばし */
223b71206888 Initial import
thib
parents:
diff changeset
810 c = *str;
223b71206888 Initial import
thib
parents:
diff changeset
811 if (c == ',' || c == ':') {
223b71206888 Initial import
thib
parents:
diff changeset
812 str++;
223b71206888 Initial import
thib
parents:
diff changeset
813 } else if (c == ')' && str[1] == '(') {
223b71206888 Initial import
thib
parents:
diff changeset
814 str += 2;
223b71206888 Initial import
thib
parents:
diff changeset
815 }
223b71206888 Initial import
thib
parents:
diff changeset
816 /* - を parse */
223b71206888 Initial import
thib
parents:
diff changeset
817 c = *str;
223b71206888 Initial import
thib
parents:
diff changeset
818 if (c == '-' && isdigit(str[1])) {
223b71206888 Initial import
thib
parents:
diff changeset
819 is_positive = -1; str++;
223b71206888 Initial import
thib
parents:
diff changeset
820 } else if (! isdigit(c)) {
223b71206888 Initial import
thib
parents:
diff changeset
821 return i; /* 異常な文字を見つけた:終了 */
223b71206888 Initial import
thib
parents:
diff changeset
822 }
223b71206888 Initial import
thib
parents:
diff changeset
823 int number = 0;
223b71206888 Initial import
thib
parents:
diff changeset
824 /* 数字読み込み */
223b71206888 Initial import
thib
parents:
diff changeset
825 while(isdigit( (c=*str) )) {
223b71206888 Initial import
thib
parents:
diff changeset
826 number *= 10;
223b71206888 Initial import
thib
parents:
diff changeset
827 number += c-'0';
223b71206888 Initial import
thib
parents:
diff changeset
828 str++;
223b71206888 Initial import
thib
parents:
diff changeset
829 }
223b71206888 Initial import
thib
parents:
diff changeset
830 ret_var[i] = is_positive * number;
223b71206888 Initial import
thib
parents:
diff changeset
831 }
223b71206888 Initial import
thib
parents:
diff changeset
832 return i;
223b71206888 Initial import
thib
parents:
diff changeset
833 }
223b71206888 Initial import
thib
parents:
diff changeset
834 /* 決められた数の引数を得る。-1 ならエラーが生じた */
223b71206888 Initial import
thib
parents:
diff changeset
835 static inline int SplitVar(const char* str, int& var1) {
223b71206888 Initial import
thib
parents:
diff changeset
836 if (SplitVar(str, &var1, 1) != 1) return -1;
223b71206888 Initial import
thib
parents:
diff changeset
837 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
838 }
223b71206888 Initial import
thib
parents:
diff changeset
839 static inline int SplitVar(const char* str, int& var1, int& var2) {
223b71206888 Initial import
thib
parents:
diff changeset
840 int vars[2];
223b71206888 Initial import
thib
parents:
diff changeset
841 if (SplitVar(str, vars, 2) != 2) return -1;
223b71206888 Initial import
thib
parents:
diff changeset
842 var1 = vars[0]; var2 = vars[1];
223b71206888 Initial import
thib
parents:
diff changeset
843 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
844 }
223b71206888 Initial import
thib
parents:
diff changeset
845 static inline int SplitVar(const char* str, int& var1, int& var2, int& var3) {
223b71206888 Initial import
thib
parents:
diff changeset
846 int vars[3];
223b71206888 Initial import
thib
parents:
diff changeset
847 if (SplitVar(str, vars, 3) != 3) return -1;
223b71206888 Initial import
thib
parents:
diff changeset
848 var1 = vars[0]; var2 = vars[1]; var3 = vars[2];
223b71206888 Initial import
thib
parents:
diff changeset
849 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
850 }
223b71206888 Initial import
thib
parents:
diff changeset
851 static inline int SplitVar(const char* str, int& var1, int& var2, int& var3, int& var4) {
223b71206888 Initial import
thib
parents:
diff changeset
852 int vars[4];
223b71206888 Initial import
thib
parents:
diff changeset
853 if (SplitVar(str, vars, 4) != 4) return -1;
223b71206888 Initial import
thib
parents:
diff changeset
854 var1 = vars[0]; var2 = vars[1]; var3 = vars[2]; var4 = vars[3];
223b71206888 Initial import
thib
parents:
diff changeset
855 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
856 }
223b71206888 Initial import
thib
parents:
diff changeset
857
223b71206888 Initial import
thib
parents:
diff changeset
858 bool AyuSysConfig::LoadInitFile(void)
223b71206888 Initial import
thib
parents:
diff changeset
859 {
223b71206888 Initial import
thib
parents:
diff changeset
860 char buf[1024]; int i;
223b71206888 Initial import
thib
parents:
diff changeset
861 char* tokens[MAXTOKEN]; int token_deal; int buf_ptr;
223b71206888 Initial import
thib
parents:
diff changeset
862 int numbers[MAXVARS];
223b71206888 Initial import
thib
parents:
diff changeset
863
223b71206888 Initial import
thib
parents:
diff changeset
864 ARCINFO* info = file_searcher.Find(FILESEARCH::ROOT, "gameexe.ini");
223b71206888 Initial import
thib
parents:
diff changeset
865 if (info == NULL) return false;
223b71206888 Initial import
thib
parents:
diff changeset
866 int size = info->Size();
223b71206888 Initial import
thib
parents:
diff changeset
867 unsigned char* buf_orig = (unsigned char*)info->Read();
223b71206888 Initial import
thib
parents:
diff changeset
868 if (size <= 0 || buf_orig == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
869 delete info; return false;
223b71206888 Initial import
thib
parents:
diff changeset
870 }
223b71206888 Initial import
thib
parents:
diff changeset
871 unsigned char* buf_end = buf_orig + size;
223b71206888 Initial import
thib
parents:
diff changeset
872 int line_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
873 while(buf_orig < buf_end) {
223b71206888 Initial import
thib
parents:
diff changeset
874 /* buf_orig から一行読み込む */
223b71206888 Initial import
thib
parents:
diff changeset
875 /* その際に、
223b71206888 Initial import
thib
parents:
diff changeset
876 ** ・頭が # 以外なら次の行までとばす
223b71206888 Initial import
thib
parents:
diff changeset
877 ** ・"" 外のスペース、TABを初めとする制御文字 (0x20 以下のASCIIコード)を削除
223b71206888 Initial import
thib
parents:
diff changeset
878 ** ・= で区切る。区切りは最大で10個で、tokens に代入される
223b71206888 Initial import
thib
parents:
diff changeset
879 ** などの操作を行う
223b71206888 Initial import
thib
parents:
diff changeset
880 */
223b71206888 Initial import
thib
parents:
diff changeset
881
223b71206888 Initial import
thib
parents:
diff changeset
882 /* # チェック */
223b71206888 Initial import
thib
parents:
diff changeset
883 if (*buf_orig != '#') {
223b71206888 Initial import
thib
parents:
diff changeset
884 /* 次の '\n' まで読み飛ばし */
223b71206888 Initial import
thib
parents:
diff changeset
885 while(buf_orig < buf_end &&
223b71206888 Initial import
thib
parents:
diff changeset
886 *buf_orig != '\n' && *buf_orig != '\r') buf_orig++;
223b71206888 Initial import
thib
parents:
diff changeset
887 if (buf_orig < buf_end-1 && *buf_orig == '\r' && buf_orig[1] == '\n') buf_orig += 2;
223b71206888 Initial import
thib
parents:
diff changeset
888 else if (*buf_orig == '\r' || *buf_orig == '\n') buf_orig++;
223b71206888 Initial import
thib
parents:
diff changeset
889 line_count++;
223b71206888 Initial import
thib
parents:
diff changeset
890 continue;
223b71206888 Initial import
thib
parents:
diff changeset
891 }
223b71206888 Initial import
thib
parents:
diff changeset
892 /* 初期化 */
223b71206888 Initial import
thib
parents:
diff changeset
893 token_deal = 1; tokens[0] = buf; buf_ptr = 0;
223b71206888 Initial import
thib
parents:
diff changeset
894 int in_quote = 0;
223b71206888 Initial import
thib
parents:
diff changeset
895
223b71206888 Initial import
thib
parents:
diff changeset
896 while(buf_orig < buf_end && buf_ptr < 1023) {
223b71206888 Initial import
thib
parents:
diff changeset
897 if (in_quote) {
223b71206888 Initial import
thib
parents:
diff changeset
898 /* "" の中 */
223b71206888 Initial import
thib
parents:
diff changeset
899 int c = *buf_orig;
223b71206888 Initial import
thib
parents:
diff changeset
900 if (c == '\n' || c == '\r') {
223b71206888 Initial import
thib
parents:
diff changeset
901 break;
223b71206888 Initial import
thib
parents:
diff changeset
902 } else if (c == '\"') {
223b71206888 Initial import
thib
parents:
diff changeset
903 in_quote = 0;
223b71206888 Initial import
thib
parents:
diff changeset
904 } else {
223b71206888 Initial import
thib
parents:
diff changeset
905 buf[buf_ptr++] = c;
223b71206888 Initial import
thib
parents:
diff changeset
906 }
223b71206888 Initial import
thib
parents:
diff changeset
907 buf_orig++;
223b71206888 Initial import
thib
parents:
diff changeset
908 } else { /* quote されてない */
223b71206888 Initial import
thib
parents:
diff changeset
909 /* 制御文字を読み飛ばす */
223b71206888 Initial import
thib
parents:
diff changeset
910 while(*buf_orig <= 0x20 && buf_orig < buf_end &&
223b71206888 Initial import
thib
parents:
diff changeset
911 *buf_orig != '\n' && *buf_orig != '\r') buf_orig++;
223b71206888 Initial import
thib
parents:
diff changeset
912 int c = *buf_orig;
223b71206888 Initial import
thib
parents:
diff changeset
913 if (c == '\n' || c == '\r') break;
223b71206888 Initial import
thib
parents:
diff changeset
914 /* = なら次の token */
223b71206888 Initial import
thib
parents:
diff changeset
915 if (c == '=') {
223b71206888 Initial import
thib
parents:
diff changeset
916 c = 0; tokens[token_deal++] = buf+buf_ptr+1;
223b71206888 Initial import
thib
parents:
diff changeset
917 if (token_deal >= MAXTOKEN) break;
223b71206888 Initial import
thib
parents:
diff changeset
918 } else if (c == '\"') {
223b71206888 Initial import
thib
parents:
diff changeset
919 in_quote = 1; buf_orig++; continue;
223b71206888 Initial import
thib
parents:
diff changeset
920 }
223b71206888 Initial import
thib
parents:
diff changeset
921 buf[buf_ptr++] = c;
223b71206888 Initial import
thib
parents:
diff changeset
922 buf_orig++;
223b71206888 Initial import
thib
parents:
diff changeset
923 }
223b71206888 Initial import
thib
parents:
diff changeset
924 }
223b71206888 Initial import
thib
parents:
diff changeset
925 buf[buf_ptr] = '\0';
223b71206888 Initial import
thib
parents:
diff changeset
926 /* 末尾の \r\n を消去 */
223b71206888 Initial import
thib
parents:
diff changeset
927 if (buf_orig < buf_end-1 && buf_orig[0] == '\r' && buf_orig[1] == '\n') buf_orig += 2;
223b71206888 Initial import
thib
parents:
diff changeset
928 else if (buf_orig < buf_end && (buf_orig[0] == '\r' || buf_orig[0] == '\n')) buf_orig++;
223b71206888 Initial import
thib
parents:
diff changeset
929 /* 必要なら parse 内容を出力 */
223b71206888 Initial import
thib
parents:
diff changeset
930 dprintf(("line %3d ",line_count));
223b71206888 Initial import
thib
parents:
diff changeset
931 for (i=0; i<token_deal; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
932 dprintf(("%d:\"%s\", ",i,tokens[i]));
223b71206888 Initial import
thib
parents:
diff changeset
933 }
223b71206888 Initial import
thib
parents:
diff changeset
934 dprintf(("\n"));
223b71206888 Initial import
thib
parents:
diff changeset
935 if (in_quote) {
223b71206888 Initial import
thib
parents:
diff changeset
936 fprintf(stderr, "Warning : open quote is found while parsing gameexe.ini, line %d\n",line_count);
223b71206888 Initial import
thib
parents:
diff changeset
937 }
223b71206888 Initial import
thib
parents:
diff changeset
938
223b71206888 Initial import
thib
parents:
diff changeset
939
223b71206888 Initial import
thib
parents:
diff changeset
940 /* 得られた内容を parse */
223b71206888 Initial import
thib
parents:
diff changeset
941
223b71206888 Initial import
thib
parents:
diff changeset
942 /* #NAME=<文字列> */
223b71206888 Initial import
thib
parents:
diff changeset
943 int type = SearchParam(tokens[0]);
223b71206888 Initial import
thib
parents:
diff changeset
944 if (type == 1) { /* #NAME=<文字列> */
223b71206888 Initial import
thib
parents:
diff changeset
945 if (token_deal != 2) {
223b71206888 Initial import
thib
parents:
diff changeset
946 dprintf(("Parse error, line %d, %s\n",line_count, tokens[0]));
223b71206888 Initial import
thib
parents:
diff changeset
947 goto parse_error;
223b71206888 Initial import
thib
parents:
diff changeset
948 }
223b71206888 Initial import
thib
parents:
diff changeset
949 SetOrigParaStr(tokens[0], tokens[1]);
223b71206888 Initial import
thib
parents:
diff changeset
950 goto parse_end;
223b71206888 Initial import
thib
parents:
diff changeset
951 } else if (type == 2) { /* #NAME=<数値列> */
223b71206888 Initial import
thib
parents:
diff changeset
952 if (token_deal != 2) {
223b71206888 Initial import
thib
parents:
diff changeset
953 dprintf(("Parse error, line %d, %s\n",line_count, tokens[0]));
223b71206888 Initial import
thib
parents:
diff changeset
954 goto parse_error;
223b71206888 Initial import
thib
parents:
diff changeset
955 }
223b71206888 Initial import
thib
parents:
diff changeset
956 int number_deal = SplitVar(tokens[1], numbers, MAXVARS);
223b71206888 Initial import
thib
parents:
diff changeset
957 SetOrigParamArray(tokens[0], number_deal, numbers);
223b71206888 Initial import
thib
parents:
diff changeset
958 goto parse_end;
223b71206888 Initial import
thib
parents:
diff changeset
959 }
223b71206888 Initial import
thib
parents:
diff changeset
960 /* 一般的な設定以外 : cdrom track など */
223b71206888 Initial import
thib
parents:
diff changeset
961 if (strncmp(tokens[0],"#NAME.", 6) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
962 if (token_deal != 2) goto parse_error;
223b71206888 Initial import
thib
parents:
diff changeset
963 SetOrigParaStr(tokens[0], tokens[1]);
223b71206888 Initial import
thib
parents:
diff changeset
964 goto parse_end;
223b71206888 Initial import
thib
parents:
diff changeset
965 } else if (strncmp(tokens[0],"#DIRC.",6) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
966 if (token_deal != 3) goto parse_error;
223b71206888 Initial import
thib
parents:
diff changeset
967 /* ファイル形式の指定 */
223b71206888 Initial import
thib
parents:
diff changeset
968 FILESEARCH::FILETYPE type;
223b71206888 Initial import
thib
parents:
diff changeset
969 char* name = tokens[0]+6;
223b71206888 Initial import
thib
parents:
diff changeset
970 if (strcmp(name, "PDT") == 0) type = FILESEARCH::PDT;
223b71206888 Initial import
thib
parents:
diff changeset
971 else if (strcmp(name, "G00") == 0) type = FILESEARCH::PDT;
223b71206888 Initial import
thib
parents:
diff changeset
972 else if (strcmp(name, "GRP") == 0) type = FILESEARCH::PDT;
223b71206888 Initial import
thib
parents:
diff changeset
973 else if (strcmp(name, "TXT") == 0) type = FILESEARCH::SCN;
223b71206888 Initial import
thib
parents:
diff changeset
974 else if (strcmp(name, "ANM") == 0) type = FILESEARCH::ANM;
223b71206888 Initial import
thib
parents:
diff changeset
975 else if (strcmp(name, "ARD") == 0) type = FILESEARCH::ARD;
223b71206888 Initial import
thib
parents:
diff changeset
976 else if (strcmp(name, "CUR") == 0) type = FILESEARCH::CUR;
223b71206888 Initial import
thib
parents:
diff changeset
977 else if (strcmp(name, "WAV") == 0) type = FILESEARCH::WAV;
223b71206888 Initial import
thib
parents:
diff changeset
978 else if (strcmp(name, "KOE") == 0) type = FILESEARCH::KOE;
223b71206888 Initial import
thib
parents:
diff changeset
979 else if (strcmp(name, "GAN") == 0) type = FILESEARCH::GAN;
223b71206888 Initial import
thib
parents:
diff changeset
980 else goto parse_error; /* 他に ALL,ROOT,MID,KOE,BGM。たぶん、存在しない */
223b71206888 Initial import
thib
parents:
diff changeset
981 if (tokens[2][0] == 'N') { /* directory */
223b71206888 Initial import
thib
parents:
diff changeset
982 file_searcher.SetFileInformation(type, FILESEARCH::ATYPE_DIR, tokens[1]);
223b71206888 Initial import
thib
parents:
diff changeset
983 dprintf(("set file directory; type %s, directory %s\n",name,tokens[1]));
223b71206888 Initial import
thib
parents:
diff changeset
984 } else if (tokens[2][0] == 'P' && tokens[2][1] == ':') { /* アーカイブ */
223b71206888 Initial import
thib
parents:
diff changeset
985 file_searcher.SetFileInformation(type, FILESEARCH::ATYPE_ARC, tokens[2]+2);
223b71206888 Initial import
thib
parents:
diff changeset
986 dprintf(("set file archive; type %s, file %s\n",name,tokens[2]+2));
223b71206888 Initial import
thib
parents:
diff changeset
987 } else goto parse_error;
223b71206888 Initial import
thib
parents:
diff changeset
988 goto parse_end;
223b71206888 Initial import
thib
parents:
diff changeset
989 }
223b71206888 Initial import
thib
parents:
diff changeset
990 if (strncmp(tokens[0],"#ADRC.",6) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
991 if (token_deal != 3) goto parse_error;
223b71206888 Initial import
thib
parents:
diff changeset
992 /* ファイル形式の指定 */
223b71206888 Initial import
thib
parents:
diff changeset
993 FILESEARCH::FILETYPE type;
223b71206888 Initial import
thib
parents:
diff changeset
994 char* name = tokens[0]+6;
223b71206888 Initial import
thib
parents:
diff changeset
995 if (strcmp(name, "PDT") == 0) type = FILESEARCH::PDT;
223b71206888 Initial import
thib
parents:
diff changeset
996 else if (strcmp(name, "G00") == 0) type = FILESEARCH::PDT;
223b71206888 Initial import
thib
parents:
diff changeset
997 else if (strcmp(name, "GRP") == 0) type = FILESEARCH::PDT;
223b71206888 Initial import
thib
parents:
diff changeset
998 else if (strcmp(name, "TXT") == 0) type = FILESEARCH::SCN;
223b71206888 Initial import
thib
parents:
diff changeset
999 else if (strcmp(name, "ANM") == 0) type = FILESEARCH::ANM;
223b71206888 Initial import
thib
parents:
diff changeset
1000 else if (strcmp(name, "ARD") == 0) type = FILESEARCH::ARD;
223b71206888 Initial import
thib
parents:
diff changeset
1001 else if (strcmp(name, "CUR") == 0) type = FILESEARCH::CUR;
223b71206888 Initial import
thib
parents:
diff changeset
1002 else if (strcmp(name, "WAV") == 0) type = FILESEARCH::WAV;
223b71206888 Initial import
thib
parents:
diff changeset
1003 else if (strcmp(name, "KOE") == 0) type = FILESEARCH::KOE;
223b71206888 Initial import
thib
parents:
diff changeset
1004 else if (strcmp(name, "GAN") == 0) type = FILESEARCH::GAN;
223b71206888 Initial import
thib
parents:
diff changeset
1005 else goto parse_error; /* 他に ALL,ROOT,MID,KOE,BGM。たぶん、存在しない */
223b71206888 Initial import
thib
parents:
diff changeset
1006 if (tokens[2][0] == 'N') { /* directory */
223b71206888 Initial import
thib
parents:
diff changeset
1007 file_searcher.AppendFileInformation(type, FILESEARCH::ATYPE_DIR, tokens[1]);
223b71206888 Initial import
thib
parents:
diff changeset
1008 dprintf(("set file directory; type %s, directory %s\n",name,tokens[1]));
223b71206888 Initial import
thib
parents:
diff changeset
1009 } else if (tokens[2][0] == 'P' && tokens[2][1] == ':') { /* アーカイブ */
223b71206888 Initial import
thib
parents:
diff changeset
1010 file_searcher.AppendFileInformation(type, FILESEARCH::ATYPE_ARC, tokens[2]+2);
223b71206888 Initial import
thib
parents:
diff changeset
1011 dprintf(("set file archive; type %s, file %s\n",name,tokens[2]+2));
223b71206888 Initial import
thib
parents:
diff changeset
1012 } else if (tokens[2][0] == 'R' && tokens[2][1] == ':') { /* それ散るアーカイブ */
223b71206888 Initial import
thib
parents:
diff changeset
1013 file_searcher.AppendFileInformation(type, FILESEARCH::ATYPE_ARC, tokens[2]+2);
223b71206888 Initial import
thib
parents:
diff changeset
1014 dprintf(("set file archive; type %s, file %s\n",name,tokens[2]+2));
223b71206888 Initial import
thib
parents:
diff changeset
1015 } else goto parse_error;
223b71206888 Initial import
thib
parents:
diff changeset
1016 goto parse_end;
223b71206888 Initial import
thib
parents:
diff changeset
1017 }
223b71206888 Initial import
thib
parents:
diff changeset
1018 if (strncmp(tokens[0],"#FOLDNAME.",10) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1019 if (token_deal != 3) goto parse_error;
223b71206888 Initial import
thib
parents:
diff changeset
1020 /* ファイル形式の指定 */
223b71206888 Initial import
thib
parents:
diff changeset
1021 FILESEARCH::FILETYPE type;
223b71206888 Initial import
thib
parents:
diff changeset
1022 char* name = tokens[0]+10;
223b71206888 Initial import
thib
parents:
diff changeset
1023 if (strcmp(name, "PDT") == 0) type = FILESEARCH::PDT;
223b71206888 Initial import
thib
parents:
diff changeset
1024 else if (strcmp(name, "G00") == 0) type = FILESEARCH::PDT;
223b71206888 Initial import
thib
parents:
diff changeset
1025 else if (strcmp(name, "GRP") == 0) type = FILESEARCH::PDT;
223b71206888 Initial import
thib
parents:
diff changeset
1026 else if (strcmp(name, "TXT") == 0) type = FILESEARCH::SCN;
223b71206888 Initial import
thib
parents:
diff changeset
1027 else if (strcmp(name, "ANM") == 0) type = FILESEARCH::ANM;
223b71206888 Initial import
thib
parents:
diff changeset
1028 else if (strcmp(name, "ARD") == 0) type = FILESEARCH::ARD;
223b71206888 Initial import
thib
parents:
diff changeset
1029 else if (strcmp(name, "CUR") == 0) type = FILESEARCH::CUR;
223b71206888 Initial import
thib
parents:
diff changeset
1030 else if (strcmp(name, "WAV") == 0) type = FILESEARCH::WAV;
223b71206888 Initial import
thib
parents:
diff changeset
1031 else if (strcmp(name, "BGM") == 0) type = FILESEARCH::BGM;
223b71206888 Initial import
thib
parents:
diff changeset
1032 else if (strcmp(name, "GAN") == 0) type = FILESEARCH::GAN;
223b71206888 Initial import
thib
parents:
diff changeset
1033 else goto parse_error; /* 他に ALL,ROOT,MID,KOE,BGM。たぶん、存在しない */
223b71206888 Initial import
thib
parents:
diff changeset
1034 if (tokens[2][0] == '0') { /* directory */
223b71206888 Initial import
thib
parents:
diff changeset
1035 file_searcher.AppendFileInformation(type, FILESEARCH::ATYPE_DIR, tokens[1]);
223b71206888 Initial import
thib
parents:
diff changeset
1036 dprintf(("set file directory; type %s, directory %s\n",name,tokens[1]));
223b71206888 Initial import
thib
parents:
diff changeset
1037 } else if (tokens[2][0] == '1' && tokens[2][1] == ':') { /* アーカイブ */
223b71206888 Initial import
thib
parents:
diff changeset
1038 file_searcher.AppendFileInformation(type, FILESEARCH::ATYPE_SCN2k, tokens[2]+2);
223b71206888 Initial import
thib
parents:
diff changeset
1039 dprintf(("set file archive; type %s, file %s\n",name,tokens[2]+2));
223b71206888 Initial import
thib
parents:
diff changeset
1040 } else goto parse_error;
223b71206888 Initial import
thib
parents:
diff changeset
1041 goto parse_end;
223b71206888 Initial import
thib
parents:
diff changeset
1042 }
223b71206888 Initial import
thib
parents:
diff changeset
1043 if (strcmp(tokens[0], "#CDTRACK") == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1044 if (token_deal != 3) goto parse_error;
223b71206888 Initial import
thib
parents:
diff changeset
1045 track_name.AddCDROM(tokens[2], atoi(tokens[1]));
223b71206888 Initial import
thib
parents:
diff changeset
1046 dprintf(("Set CDTRACK, name %s, track %d\n",tokens[2], atoi(tokens[1])));
223b71206888 Initial import
thib
parents:
diff changeset
1047 goto parse_end;
223b71206888 Initial import
thib
parents:
diff changeset
1048 }
223b71206888 Initial import
thib
parents:
diff changeset
1049 if (strcmp(tokens[0], "#DSTRACK") == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1050 /* #DSTRACK=00000000-99999000-00782556="filename" ="name" */
223b71206888 Initial import
thib
parents:
diff changeset
1051 /* #DSTRACK=00000000-99999000-00782556="name" */
223b71206888 Initial import
thib
parents:
diff changeset
1052 /* 第二トークンの3つめのパラメータを得る(繰り返しの時の再生開始位置) */
223b71206888 Initial import
thib
parents:
diff changeset
1053 int start_pt = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1054 const char* tk1 = strchr(tokens[1], '-');
223b71206888 Initial import
thib
parents:
diff changeset
1055 const char* tk2 = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1056 if (tk1 && *tk1) tk2 = strchr(tk1+1, '-');
223b71206888 Initial import
thib
parents:
diff changeset
1057 if (tk2 && *tk2) start_pt = atoi(tk2+1);
223b71206888 Initial import
thib
parents:
diff changeset
1058 if (token_deal == 3) {
223b71206888 Initial import
thib
parents:
diff changeset
1059 track_name.AddWave(tokens[2], tokens[2], start_pt);
223b71206888 Initial import
thib
parents:
diff changeset
1060 dprintf(("Set Wave track, name %s\n",tokens[2]));
223b71206888 Initial import
thib
parents:
diff changeset
1061 } else if (token_deal == 4) {
223b71206888 Initial import
thib
parents:
diff changeset
1062 track_name.AddWave(tokens[3], tokens[2], start_pt);
223b71206888 Initial import
thib
parents:
diff changeset
1063 dprintf(("Set Wave track, name %s, file %s\n",tokens[3], tokens[2]));
223b71206888 Initial import
thib
parents:
diff changeset
1064 } else goto parse_error;
223b71206888 Initial import
thib
parents:
diff changeset
1065 goto parse_end;
223b71206888 Initial import
thib
parents:
diff changeset
1066 }
223b71206888 Initial import
thib
parents:
diff changeset
1067 if (strncmp(tokens[0], "#SE.", 4) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1068 /* SE.XXX="XXX"=X */
223b71206888 Initial import
thib
parents:
diff changeset
1069 if (token_deal == 2) {
223b71206888 Initial import
thib
parents:
diff changeset
1070 track_name.AddSE(atoi(tokens[0]+4), tokens[1]);
223b71206888 Initial import
thib
parents:
diff changeset
1071 } else if (token_deal == 3) {
223b71206888 Initial import
thib
parents:
diff changeset
1072 if (atoi(tokens[2]) != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1073 track_name.AddSE(atoi(tokens[0]+4), tokens[1]);
223b71206888 Initial import
thib
parents:
diff changeset
1074 }
223b71206888 Initial import
thib
parents:
diff changeset
1075 }
223b71206888 Initial import
thib
parents:
diff changeset
1076 dprintf(("Set SE %d, name %s\n",atoi(tokens[0]+4), tokens[1]));
223b71206888 Initial import
thib
parents:
diff changeset
1077 goto parse_end;
223b71206888 Initial import
thib
parents:
diff changeset
1078 }
223b71206888 Initial import
thib
parents:
diff changeset
1079 /* 設定項目が見つからなかった */
223b71206888 Initial import
thib
parents:
diff changeset
1080 dprintf(("Cannot find configuration name: %s\n",tokens[0]));
223b71206888 Initial import
thib
parents:
diff changeset
1081 parse_error:
223b71206888 Initial import
thib
parents:
diff changeset
1082 parse_end:
223b71206888 Initial import
thib
parents:
diff changeset
1083 line_count++;
223b71206888 Initial import
thib
parents:
diff changeset
1084 }
223b71206888 Initial import
thib
parents:
diff changeset
1085 delete info;
223b71206888 Initial import
thib
parents:
diff changeset
1086 /* デフォルトのオプションを指定する */
223b71206888 Initial import
thib
parents:
diff changeset
1087 // set_game(GetParaStr("#REGNAME"), *this);
223b71206888 Initial import
thib
parents:
diff changeset
1088 return true;
223b71206888 Initial import
thib
parents:
diff changeset
1089 }
223b71206888 Initial import
thib
parents:
diff changeset
1090
223b71206888 Initial import
thib
parents:
diff changeset
1091 TrackName::TrackName(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1092 deal = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1093 track = new char*[deal];
223b71206888 Initial import
thib
parents:
diff changeset
1094 track_wave = new char*[deal];
223b71206888 Initial import
thib
parents:
diff changeset
1095 track_num = new int[deal];
223b71206888 Initial import
thib
parents:
diff changeset
1096 track_start = new int[deal];
223b71206888 Initial import
thib
parents:
diff changeset
1097 int i; for (i=0; i<deal; i++) track[i] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1098 for (i=0; i<deal; i++) track_wave[i] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1099 se_deal = 10;
223b71206888 Initial import
thib
parents:
diff changeset
1100 se_track = new char*[se_deal];
223b71206888 Initial import
thib
parents:
diff changeset
1101 for (i=0; i<se_deal; i++) se_track[i] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1102 }
223b71206888 Initial import
thib
parents:
diff changeset
1103
223b71206888 Initial import
thib
parents:
diff changeset
1104 TrackName::~TrackName() {
223b71206888 Initial import
thib
parents:
diff changeset
1105 int i; for (i=0; i<deal; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1106 if (track[i] != 0) delete[] track[i];
223b71206888 Initial import
thib
parents:
diff changeset
1107 if (track_wave[i] != 0) delete[] track_wave[i];
223b71206888 Initial import
thib
parents:
diff changeset
1108 }
223b71206888 Initial import
thib
parents:
diff changeset
1109 for (i=0; i<se_deal; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1110 if (se_track[i]) delete[] se_track[i];
223b71206888 Initial import
thib
parents:
diff changeset
1111 }
223b71206888 Initial import
thib
parents:
diff changeset
1112 delete[] track;
223b71206888 Initial import
thib
parents:
diff changeset
1113 delete[] track_wave;
223b71206888 Initial import
thib
parents:
diff changeset
1114 delete[] track_num;
223b71206888 Initial import
thib
parents:
diff changeset
1115 delete[] track_start;
223b71206888 Initial import
thib
parents:
diff changeset
1116 delete[] se_track;
223b71206888 Initial import
thib
parents:
diff changeset
1117 }
223b71206888 Initial import
thib
parents:
diff changeset
1118 void TrackName::Expand(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1119 int new_deal = deal * 2;
223b71206888 Initial import
thib
parents:
diff changeset
1120 int* new_track_num = new int[new_deal];
223b71206888 Initial import
thib
parents:
diff changeset
1121 int* new_track_start = new int[new_deal];
223b71206888 Initial import
thib
parents:
diff changeset
1122 char** new_track = new char*[new_deal];
223b71206888 Initial import
thib
parents:
diff changeset
1123 char** new_track_wave = new char*[new_deal];
223b71206888 Initial import
thib
parents:
diff changeset
1124 int i; for (i=0; i<deal; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1125 new_track_num[i] = track_num[i];
223b71206888 Initial import
thib
parents:
diff changeset
1126 new_track_start[i] = track_start[i];
223b71206888 Initial import
thib
parents:
diff changeset
1127 new_track[i] = track[i];
223b71206888 Initial import
thib
parents:
diff changeset
1128 new_track_wave[i] = track_wave[i];
223b71206888 Initial import
thib
parents:
diff changeset
1129 }
223b71206888 Initial import
thib
parents:
diff changeset
1130 for (; i<new_deal; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1131 new_track_num[i] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1132 new_track_start[i] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1133 new_track[i] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1134 new_track_wave[i] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1135 }
223b71206888 Initial import
thib
parents:
diff changeset
1136 deal = new_deal;
223b71206888 Initial import
thib
parents:
diff changeset
1137 delete[] track; track = new_track;
223b71206888 Initial import
thib
parents:
diff changeset
1138 delete[] track_num; track_num= new_track_num;
223b71206888 Initial import
thib
parents:
diff changeset
1139 delete[] track_start; track_start= new_track_start;
223b71206888 Initial import
thib
parents:
diff changeset
1140 delete[] track_wave; track_wave = new_track_wave;
223b71206888 Initial import
thib
parents:
diff changeset
1141 }
223b71206888 Initial import
thib
parents:
diff changeset
1142 void TrackName::ExpandSE(int n) {
223b71206888 Initial import
thib
parents:
diff changeset
1143 if (n < 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
1144 n += 10;
223b71206888 Initial import
thib
parents:
diff changeset
1145 if (se_deal >= n) return;
223b71206888 Initial import
thib
parents:
diff changeset
1146 char** new_se = new char*[n];
223b71206888 Initial import
thib
parents:
diff changeset
1147 int i; for (i=0; i<se_deal; i++) new_se[i] = se_track[i];
223b71206888 Initial import
thib
parents:
diff changeset
1148 for (; i<n; i++) new_se[i] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1149 delete[] se_track;
223b71206888 Initial import
thib
parents:
diff changeset
1150 se_deal = n; se_track = new_se;
223b71206888 Initial import
thib
parents:
diff changeset
1151 }
223b71206888 Initial import
thib
parents:
diff changeset
1152 void TrackName::AddCDROM(char* name, int tk) {
223b71206888 Initial import
thib
parents:
diff changeset
1153 if (CDTrack(name) != -1) return;
223b71206888 Initial import
thib
parents:
diff changeset
1154 int i; for (i=0; i<deal; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1155 if (track[i] == 0) break;
223b71206888 Initial import
thib
parents:
diff changeset
1156 }
223b71206888 Initial import
thib
parents:
diff changeset
1157 int num = i;
223b71206888 Initial import
thib
parents:
diff changeset
1158 if (i == deal) Expand();
223b71206888 Initial import
thib
parents:
diff changeset
1159 track[num] = new char[strlen(name)+1];
223b71206888 Initial import
thib
parents:
diff changeset
1160 for (i=0; name[i] != 0; i++) track[num][i] = tolower(name[i]);
223b71206888 Initial import
thib
parents:
diff changeset
1161 track[num][i] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1162 track_num[num] = tk;
223b71206888 Initial import
thib
parents:
diff changeset
1163 }
223b71206888 Initial import
thib
parents:
diff changeset
1164 void TrackName::AddWave(char* name, char* file, int pt) {
223b71206888 Initial import
thib
parents:
diff changeset
1165 if (CDTrack(name) != -1) return;
223b71206888 Initial import
thib
parents:
diff changeset
1166 int i; for (i=0; i<deal; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1167 if (track[i] == 0) break;
223b71206888 Initial import
thib
parents:
diff changeset
1168 }
223b71206888 Initial import
thib
parents:
diff changeset
1169 int num = i;
223b71206888 Initial import
thib
parents:
diff changeset
1170 if (i == deal) Expand();
223b71206888 Initial import
thib
parents:
diff changeset
1171 track_num[num] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1172 track_start[num] = pt;
223b71206888 Initial import
thib
parents:
diff changeset
1173 track[num] = new char[strlen(name)+1];
223b71206888 Initial import
thib
parents:
diff changeset
1174 for (i=0; name[i] != 0; i++) track[num][i] = tolower(name[i]);
223b71206888 Initial import
thib
parents:
diff changeset
1175 track[num][i] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1176 track_wave[num] = new char[strlen(file)+1]; strcpy(track_wave[num], file);
223b71206888 Initial import
thib
parents:
diff changeset
1177 }
223b71206888 Initial import
thib
parents:
diff changeset
1178 int TrackName::CDTrack(char* name) {
223b71206888 Initial import
thib
parents:
diff changeset
1179 char buf[1024];
223b71206888 Initial import
thib
parents:
diff changeset
1180 int i;
223b71206888 Initial import
thib
parents:
diff changeset
1181 for (i=0; name[i]!=0; i++) buf[i]=tolower(name[i]);
223b71206888 Initial import
thib
parents:
diff changeset
1182 buf[i]=0;
223b71206888 Initial import
thib
parents:
diff changeset
1183 for (i=0; i<deal; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1184 if (track[i] == 0) return -1;
223b71206888 Initial import
thib
parents:
diff changeset
1185 if (strcmp(track[i], buf) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1186 return track_num[i];
223b71206888 Initial import
thib
parents:
diff changeset
1187 }
223b71206888 Initial import
thib
parents:
diff changeset
1188 }
223b71206888 Initial import
thib
parents:
diff changeset
1189 return -1;
223b71206888 Initial import
thib
parents:
diff changeset
1190 }
223b71206888 Initial import
thib
parents:
diff changeset
1191 int TrackName::TrackStart(char* name) {
223b71206888 Initial import
thib
parents:
diff changeset
1192 char buf[1024];
223b71206888 Initial import
thib
parents:
diff changeset
1193 int i;
223b71206888 Initial import
thib
parents:
diff changeset
1194 for (i=0; name[i]!=0; i++) buf[i]=tolower(name[i]);
223b71206888 Initial import
thib
parents:
diff changeset
1195 buf[i]=0;
223b71206888 Initial import
thib
parents:
diff changeset
1196 for (i=0; i<deal; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1197 if (track[i] == 0) return -1;
223b71206888 Initial import
thib
parents:
diff changeset
1198 if (strcmp(track[i], buf) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1199 return track_start[i];
223b71206888 Initial import
thib
parents:
diff changeset
1200 }
223b71206888 Initial import
thib
parents:
diff changeset
1201 }
223b71206888 Initial import
thib
parents:
diff changeset
1202 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
1203 }
223b71206888 Initial import
thib
parents:
diff changeset
1204 const char* TrackName::WaveTrack(char* name) {
223b71206888 Initial import
thib
parents:
diff changeset
1205 char buf[1024];
223b71206888 Initial import
thib
parents:
diff changeset
1206 int i;
223b71206888 Initial import
thib
parents:
diff changeset
1207 for (i=0; name[i]!=0; i++) buf[i]=tolower(name[i]);
223b71206888 Initial import
thib
parents:
diff changeset
1208 buf[i]=0;
223b71206888 Initial import
thib
parents:
diff changeset
1209 for (i=0; i<deal; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1210 if (track[i] == 0) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
1211 if (strcmp(track[i], buf) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1212 return track_wave[i];
223b71206888 Initial import
thib
parents:
diff changeset
1213 }
223b71206888 Initial import
thib
parents:
diff changeset
1214 }
223b71206888 Initial import
thib
parents:
diff changeset
1215 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
1216 }
223b71206888 Initial import
thib
parents:
diff changeset
1217 const char* TrackName::SETrack(int n) {
223b71206888 Initial import
thib
parents:
diff changeset
1218 if (n < 0 || n >= se_deal) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
1219 return se_track[n];
223b71206888 Initial import
thib
parents:
diff changeset
1220 }
223b71206888 Initial import
thib
parents:
diff changeset
1221 void TrackName::AddSE(int n, char* file) {
223b71206888 Initial import
thib
parents:
diff changeset
1222 if (se_deal <= n) ExpandSE(n);
223b71206888 Initial import
thib
parents:
diff changeset
1223 if (se_track[n]) delete[] se_track[n];
223b71206888 Initial import
thib
parents:
diff changeset
1224 se_track[n] = new char[strlen(file)+1];
223b71206888 Initial import
thib
parents:
diff changeset
1225 strcpy(se_track[n], file);
223b71206888 Initial import
thib
parents:
diff changeset
1226 }
223b71206888 Initial import
thib
parents:
diff changeset
1227