annotate scn2k/scn2k_cmd.cc @ 65:4416cfac86ae

Convert EUC-JP files to UTF8
author Thibaut Girka <thib@sitedethib.com>
date Fri, 26 Nov 2010 10:53:15 +0100
parents 4b9ffe15a87d
children e4a12dd9a51b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
223b71206888 Initial import
thib
parents:
diff changeset
1 /*
223b71206888 Initial import
thib
parents:
diff changeset
2 * Copyright (c) 2004-2006 Kazunori "jagarl" Ueno
223b71206888 Initial import
thib
parents:
diff changeset
3 * All rights reserved.
223b71206888 Initial import
thib
parents:
diff changeset
4 *
223b71206888 Initial import
thib
parents:
diff changeset
5 * Redistribution and use in source and binary forms, with or without
223b71206888 Initial import
thib
parents:
diff changeset
6 * modification, are permitted provided that the following conditions
223b71206888 Initial import
thib
parents:
diff changeset
7 * are met:
223b71206888 Initial import
thib
parents:
diff changeset
8 * 1. Redistributions of source code must retain the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
9 * notice, this list of conditions and the following disclaimer.
223b71206888 Initial import
thib
parents:
diff changeset
10 * 2. Redistributions in binary form must reproduce the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer in the
223b71206888 Initial import
thib
parents:
diff changeset
12 * documentation and/or other materials provided with the distribution.
223b71206888 Initial import
thib
parents:
diff changeset
13 * 3. The name of the author may not be used to endorse or promote products
223b71206888 Initial import
thib
parents:
diff changeset
14 * derived from this software without specific prior written permission.
223b71206888 Initial import
thib
parents:
diff changeset
15 *
223b71206888 Initial import
thib
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
223b71206888 Initial import
thib
parents:
diff changeset
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
223b71206888 Initial import
thib
parents:
diff changeset
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
223b71206888 Initial import
thib
parents:
diff changeset
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
223b71206888 Initial import
thib
parents:
diff changeset
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
223b71206888 Initial import
thib
parents:
diff changeset
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
223b71206888 Initial import
thib
parents:
diff changeset
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
223b71206888 Initial import
thib
parents:
diff changeset
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
223b71206888 Initial import
thib
parents:
diff changeset
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
223b71206888 Initial import
thib
parents:
diff changeset
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
223b71206888 Initial import
thib
parents:
diff changeset
26 */
223b71206888 Initial import
thib
parents:
diff changeset
27
223b71206888 Initial import
thib
parents:
diff changeset
28
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
29 #include "scn2k.h"
0
223b71206888 Initial import
thib
parents:
diff changeset
30
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
31 #include <stdlib.h>
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
32 #include <stdarg.h>
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
33 #include <stdio.h>
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
34 #include <string.h>
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
35 #include <string>
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
36 #include "system/file.h"
0
223b71206888 Initial import
thib
parents:
diff changeset
37
223b71206888 Initial import
thib
parents:
diff changeset
38 using namespace std;
223b71206888 Initial import
thib
parents:
diff changeset
39
223b71206888 Initial import
thib
parents:
diff changeset
40
223b71206888 Initial import
thib
parents:
diff changeset
41 // #define SCN_DUMP
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
42 /* 注意点: @@@ で表記 */
0
223b71206888 Initial import
thib
parents:
diff changeset
43
223b71206888 Initial import
thib
parents:
diff changeset
44
223b71206888 Initial import
thib
parents:
diff changeset
45
223b71206888 Initial import
thib
parents:
diff changeset
46 //bool debug_flag = true;
223b71206888 Initial import
thib
parents:
diff changeset
47 bool debug_flag = false;
223b71206888 Initial import
thib
parents:
diff changeset
48 void dprintf(const char* fmt, ...) {
223b71206888 Initial import
thib
parents:
diff changeset
49 if (debug_flag) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
50 va_list ap;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
51 va_start(ap, fmt);
0
223b71206888 Initial import
thib
parents:
diff changeset
52 vprintf(fmt, ap);
223b71206888 Initial import
thib
parents:
diff changeset
53 va_end(ap);
223b71206888 Initial import
thib
parents:
diff changeset
54 }
223b71206888 Initial import
thib
parents:
diff changeset
55 }
223b71206888 Initial import
thib
parents:
diff changeset
56
223b71206888 Initial import
thib
parents:
diff changeset
57
223b71206888 Initial import
thib
parents:
diff changeset
58 void eprintf(const char* fmt, ...) {
223b71206888 Initial import
thib
parents:
diff changeset
59 va_list ap; va_start(ap, fmt);
223b71206888 Initial import
thib
parents:
diff changeset
60 // vprintf(fmt, ap);
223b71206888 Initial import
thib
parents:
diff changeset
61 va_end(ap);
223b71206888 Initial import
thib
parents:
diff changeset
62 }
223b71206888 Initial import
thib
parents:
diff changeset
63
223b71206888 Initial import
thib
parents:
diff changeset
64 /**************************************************************
223b71206888 Initial import
thib
parents:
diff changeset
65 ** Flag
223b71206888 Initial import
thib
parents:
diff changeset
66 */
223b71206888 Initial import
thib
parents:
diff changeset
67
223b71206888 Initial import
thib
parents:
diff changeset
68 Flags::Flags(void) {
223b71206888 Initial import
thib
parents:
diff changeset
69 int i,j;
223b71206888 Initial import
thib
parents:
diff changeset
70 for (i=0; i<=TYPE_VARMAX; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
71 for (j=0; j<2000; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
72 var[i][j] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
73 }
223b71206888 Initial import
thib
parents:
diff changeset
74 }
223b71206888 Initial import
thib
parents:
diff changeset
75 sys = 0;
223b71206888 Initial import
thib
parents:
diff changeset
76 }
223b71206888 Initial import
thib
parents:
diff changeset
77
223b71206888 Initial import
thib
parents:
diff changeset
78 bool Flags::IsInt(int type) const {
223b71206888 Initial import
thib
parents:
diff changeset
79 int v = type % 26;
43
01aa5ddf7dc8 A lot of very minor improvements (deleted some unused variables, and other things like that...)
thib
parents: 29
diff changeset
80 return (v >= 0 && v < 7) || v == 25;
0
223b71206888 Initial import
thib
parents:
diff changeset
81 }
223b71206888 Initial import
thib
parents:
diff changeset
82
223b71206888 Initial import
thib
parents:
diff changeset
83 int Flags::MaxIndex(int type) const {
223b71206888 Initial import
thib
parents:
diff changeset
84 switch (type / 26) {
223b71206888 Initial import
thib
parents:
diff changeset
85 case 1:
223b71206888 Initial import
thib
parents:
diff changeset
86 return 63999;
223b71206888 Initial import
thib
parents:
diff changeset
87 case 2:
223b71206888 Initial import
thib
parents:
diff changeset
88 return 31999;
223b71206888 Initial import
thib
parents:
diff changeset
89 case 3:
223b71206888 Initial import
thib
parents:
diff changeset
90 return 15999;
223b71206888 Initial import
thib
parents:
diff changeset
91 case 4:
223b71206888 Initial import
thib
parents:
diff changeset
92 return 7999;
223b71206888 Initial import
thib
parents:
diff changeset
93 default:
223b71206888 Initial import
thib
parents:
diff changeset
94 return 1999;
223b71206888 Initial import
thib
parents:
diff changeset
95 }
223b71206888 Initial import
thib
parents:
diff changeset
96 }
223b71206888 Initial import
thib
parents:
diff changeset
97
223b71206888 Initial import
thib
parents:
diff changeset
98 int Flags::operator()() const {
223b71206888 Initial import
thib
parents:
diff changeset
99 return sys; // rand() % 10000;
223b71206888 Initial import
thib
parents:
diff changeset
100 }
223b71206888 Initial import
thib
parents:
diff changeset
101
223b71206888 Initial import
thib
parents:
diff changeset
102 int Flags::operator() (VarInfo info) const {
223b71206888 Initial import
thib
parents:
diff changeset
103 return Get(info.type, info.number);
223b71206888 Initial import
thib
parents:
diff changeset
104 }
223b71206888 Initial import
thib
parents:
diff changeset
105
223b71206888 Initial import
thib
parents:
diff changeset
106 int Flags::Get(int type, int number) const {
223b71206888 Initial import
thib
parents:
diff changeset
107 int index = type % 26;
223b71206888 Initial import
thib
parents:
diff changeset
108 type /= 26;
223b71206888 Initial import
thib
parents:
diff changeset
109 if (index == 25) {
223b71206888 Initial import
thib
parents:
diff changeset
110 if (var[7][number] != 0) return var[7][number];
223b71206888 Initial import
thib
parents:
diff changeset
111 if (cgm_data.find(number) == cgm_data.end()) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
112 else return 1;
223b71206888 Initial import
thib
parents:
diff changeset
113 }
223b71206888 Initial import
thib
parents:
diff changeset
114 if (index == 10) index = 8;
223b71206888 Initial import
thib
parents:
diff changeset
115 if (index == 11) index = 9;
223b71206888 Initial import
thib
parents:
diff changeset
116 if (index > TYPE_VARMAX || uint(type) > 4) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
117 if (type == 0) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
118 // A[]..G[], Z[] を直に読む
0
223b71206888 Initial import
thib
parents:
diff changeset
119 if (uint(number) >= 2000) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
120 return var[index][number];
223b71206888 Initial import
thib
parents:
diff changeset
121 } else {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
122 // Ab[]..G4b[], Z8b[] などを読む
0
223b71206888 Initial import
thib
parents:
diff changeset
123 int factor = 1 << (type - 1);
223b71206888 Initial import
thib
parents:
diff changeset
124 int eltsize = 32 / factor;
223b71206888 Initial import
thib
parents:
diff changeset
125 if (uint(number) >= (64000 / factor)) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
126 return (var[index][number / eltsize] >> ((number % eltsize) * factor)) & ((1 << factor) - 1);
223b71206888 Initial import
thib
parents:
diff changeset
127 }
223b71206888 Initial import
thib
parents:
diff changeset
128 }
223b71206888 Initial import
thib
parents:
diff changeset
129
223b71206888 Initial import
thib
parents:
diff changeset
130 void Flags::Set(VarInfo info, int value) {
223b71206888 Initial import
thib
parents:
diff changeset
131 int type = info.type / 26;
223b71206888 Initial import
thib
parents:
diff changeset
132 int index = info.type % 26;
223b71206888 Initial import
thib
parents:
diff changeset
133 if (index == 25) {
223b71206888 Initial import
thib
parents:
diff changeset
134 if (uint(info.number) >= 2000) return;
223b71206888 Initial import
thib
parents:
diff changeset
135 if (value == 0)
223b71206888 Initial import
thib
parents:
diff changeset
136 cgm_data.erase(info.number);
223b71206888 Initial import
thib
parents:
diff changeset
137 else
223b71206888 Initial import
thib
parents:
diff changeset
138 cgm_data.insert(info.number);
223b71206888 Initial import
thib
parents:
diff changeset
139 index = 7;
223b71206888 Initial import
thib
parents:
diff changeset
140 }
223b71206888 Initial import
thib
parents:
diff changeset
141 if (index == 10) index = 8;
223b71206888 Initial import
thib
parents:
diff changeset
142 if (index == 11) index = 9;
223b71206888 Initial import
thib
parents:
diff changeset
143 if (index < 0 || index > TYPE_VARMAX) {
223b71206888 Initial import
thib
parents:
diff changeset
144 fprintf(stderr,"Error: invalid access to Var<%d>[%d]\n",info.type,info.number);
223b71206888 Initial import
thib
parents:
diff changeset
145 }
223b71206888 Initial import
thib
parents:
diff changeset
146 if (type == 0) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
147 // A[]..G[], Z[] を直に書く
0
223b71206888 Initial import
thib
parents:
diff changeset
148 if (uint(info.number) >= 2000) return;
223b71206888 Initial import
thib
parents:
diff changeset
149 var[index][info.number] = value;
223b71206888 Initial import
thib
parents:
diff changeset
150 } else {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
151 // Ab[]..G4b[], Z8b[] などを書く
0
223b71206888 Initial import
thib
parents:
diff changeset
152 int factor = 1 << (type - 1);
223b71206888 Initial import
thib
parents:
diff changeset
153 int eltsize = 32 / factor;
223b71206888 Initial import
thib
parents:
diff changeset
154 int eltmask = (1 << factor) - 1;
223b71206888 Initial import
thib
parents:
diff changeset
155 int shift = (info.number % eltsize) * factor;
223b71206888 Initial import
thib
parents:
diff changeset
156 if (uint(info.number) >= (64000 / factor)) return;
223b71206888 Initial import
thib
parents:
diff changeset
157 var[index][info.number / eltsize] =
223b71206888 Initial import
thib
parents:
diff changeset
158 (var[index][info.number / eltsize] & ~(eltmask << shift))
223b71206888 Initial import
thib
parents:
diff changeset
159 | (value & eltmask) << shift;
223b71206888 Initial import
thib
parents:
diff changeset
160 }
223b71206888 Initial import
thib
parents:
diff changeset
161 }
223b71206888 Initial import
thib
parents:
diff changeset
162
223b71206888 Initial import
thib
parents:
diff changeset
163 void Flags::SetSys(int value) {
223b71206888 Initial import
thib
parents:
diff changeset
164 sys = value;
223b71206888 Initial import
thib
parents:
diff changeset
165 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
166
0
223b71206888 Initial import
thib
parents:
diff changeset
167 void Flags::SetStr(VarInfo info, string val) {
223b71206888 Initial import
thib
parents:
diff changeset
168 switch(info.type) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
169 case TYPE_VARLOCSTR:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
170 if (info.number >= 3) return;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
171 loc_str[info.number] = val;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
172 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
173 case TYPE_VARSYSSTR:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
174 if (info.number >= 2000) return;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
175 sys_str[info.number] = val;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
176 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
177 case TYPE_VARSTR:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
178 if (info.number >= 2000) return;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
179 str[info.number] = val;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
180 break;
0
223b71206888 Initial import
thib
parents:
diff changeset
181 }
223b71206888 Initial import
thib
parents:
diff changeset
182 return;
223b71206888 Initial import
thib
parents:
diff changeset
183 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
184
0
223b71206888 Initial import
thib
parents:
diff changeset
185 void Flags::Str(int type, unsigned int number, char* buf, int sz) const {
223b71206888 Initial import
thib
parents:
diff changeset
186 if (sz <= 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
187 buf[0] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
188 const string* sptr;
223b71206888 Initial import
thib
parents:
diff changeset
189 switch(type) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
190 case TYPE_VARLOCSTR:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
191 if (number >= 3) return;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
192 sptr = &loc_str[number];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
193 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
194 case TYPE_VARSYSSTR:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
195 if (number >= 2000) return;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
196 sptr = &sys_str[number];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
197 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
198 case TYPE_VARSTR:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
199 if (number >= 2000) return;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
200 sptr = &str[number];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
201 break;
0
223b71206888 Initial import
thib
parents:
diff changeset
202 }
223b71206888 Initial import
thib
parents:
diff changeset
203
223b71206888 Initial import
thib
parents:
diff changeset
204 int len = sptr->length();
223b71206888 Initial import
thib
parents:
diff changeset
205 if (sz-1 > len) sz = len;
223b71206888 Initial import
thib
parents:
diff changeset
206 sptr->copy(buf, sz, 0);
223b71206888 Initial import
thib
parents:
diff changeset
207 buf[sz] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
208 return;
223b71206888 Initial import
thib
parents:
diff changeset
209 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
210
0
223b71206888 Initial import
thib
parents:
diff changeset
211 string Flags::Str(int type, unsigned int number) const {
223b71206888 Initial import
thib
parents:
diff changeset
212 switch(type) {
223b71206888 Initial import
thib
parents:
diff changeset
213 case TYPE_VARLOCSTR:
223b71206888 Initial import
thib
parents:
diff changeset
214 if (number >= 3) return "";
223b71206888 Initial import
thib
parents:
diff changeset
215 return loc_str[number];
223b71206888 Initial import
thib
parents:
diff changeset
216 case TYPE_VARSYSSTR:
223b71206888 Initial import
thib
parents:
diff changeset
217 if (number >= 2000) return "";
223b71206888 Initial import
thib
parents:
diff changeset
218 return sys_str[number];
223b71206888 Initial import
thib
parents:
diff changeset
219 case TYPE_VARSTR:
223b71206888 Initial import
thib
parents:
diff changeset
220 if (number >= 2000) return "";
223b71206888 Initial import
thib
parents:
diff changeset
221 return str[number];
223b71206888 Initial import
thib
parents:
diff changeset
222 }
223b71206888 Initial import
thib
parents:
diff changeset
223 return "";
223b71206888 Initial import
thib
parents:
diff changeset
224 }
223b71206888 Initial import
thib
parents:
diff changeset
225
63
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
226 void Flags::Load(const char* save) {
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
227 Load(save, false);
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
228 }
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
229
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
230 void Flags::LoadSys(const char* save) {
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
231 Load(save, true);
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
232 }
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
233
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
234 void Flags::Load(const char* save, bool sys) {
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
235 int i, j;
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
236 int start, end;
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
237 std::string *var_str;
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
238 char string_field[] = "V<?>[%04d]=";
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
239
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
240 start = (sys) ? (TYPE_NONSYSVARMAX + 1) : 0;
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
241 end = (sys) ? (TYPE_NONSYSVARMAX + 2) : TYPE_NONSYSVARMAX;
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
242
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
243 var_str = (sys) ? sys_str : str;
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
244 string_field[2] = (sys) ? 'M' : 'C';
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
245
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
246 for (i=start; i <= end; i++) {
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
247 for (j=0; j < 2000; j++) {
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
248 var[i][j] = 0;
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
249 }
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
250 }
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
251 for (j=0; j<2000; j++) {
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
252 var_str[j] = "";
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
253 }
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
254 sys = 0;
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
255
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
256 save = strstr(save, "\n[Flags]\n");
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
257
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
258 if (save) {
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
259 save += strlen("\n[Flags]\n");
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
260 do {
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
261 if (save[0] == '[') break; // next section
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
262 if (strncmp(save, string_field, 2) == 0) {
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
263 if (strncmp(save, string_field, 5) == 0) { // string
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
264 char buf[1024];
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
265 int n;
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
266 if (sscanf(save, string_field, &n) == 1) {
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
267 const char* s = strchr(save, '=');
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
268 s++;
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
269 const char* send = strchr(s, '\n');
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
270 int slen = send - s;
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
271 strncpy(buf, s, slen);
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
272 buf[slen] = 0;
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
273 if (n >= 0 && n < 2000)
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
274 var_str[n] = buf;
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
275 }
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
276 } else if (save[2] >= '0' && save[2] <= '9') {
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
277 int c, n, v;
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
278 if (sscanf(save, "V<%d>[%04d]=%d\n",&c,&n,&v) == 3) {
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
279 if (n >= 0 && n < 2000)
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
280 {
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
281 if (!sys && c >= 0 && c <= TYPE_NONSYSVARMAX)
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
282 var[c][n] = v;
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
283 else if (sys && c == TYPE_NONSYSVARMAX + 1)
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
284 var[TYPE_NONSYSVARMAX + 1][n] = v;
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
285 else if (sys && c == 25)
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
286 var[7][n] = v;
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
287 }
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
288 }
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
289 }
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
290 }
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
291 save = strchr(save, '\n');
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
292 if (save)
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
293 save++;
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
294 } while (save);
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
295 }
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
296 }
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
297
0
223b71206888 Initial import
thib
parents:
diff changeset
298 void Flags::Save(string& save) {
223b71206888 Initial import
thib
parents:
diff changeset
299 char buf[1024];
223b71206888 Initial import
thib
parents:
diff changeset
300 save = "\n[Flags]\n";
63
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
301 int i, j;
0
223b71206888 Initial import
thib
parents:
diff changeset
302 for (i=0; i<=TYPE_NONSYSVARMAX; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
303 for (j=0; j<2000; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
304 if (var[i][j] != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
305 sprintf(buf, "V<%d>[%04d]=%d\n",i,j,var[i][j]);
223b71206888 Initial import
thib
parents:
diff changeset
306 save += buf;
223b71206888 Initial import
thib
parents:
diff changeset
307 }
223b71206888 Initial import
thib
parents:
diff changeset
308 }
223b71206888 Initial import
thib
parents:
diff changeset
309 }
223b71206888 Initial import
thib
parents:
diff changeset
310 for (j=0; j<2000; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
311 if (str[j].length() != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
312 sprintf(buf, "V<C>[%04d]=%s\n", j, str[j].c_str());
223b71206888 Initial import
thib
parents:
diff changeset
313 save += buf;
223b71206888 Initial import
thib
parents:
diff changeset
314 }
223b71206888 Initial import
thib
parents:
diff changeset
315 }
223b71206888 Initial import
thib
parents:
diff changeset
316 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
317
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
318 void Flags::SaveSys(string& save) { //FIXME: see how to factorize with Save
0
223b71206888 Initial import
thib
parents:
diff changeset
319 char buf[1024];
223b71206888 Initial import
thib
parents:
diff changeset
320 int j;
223b71206888 Initial import
thib
parents:
diff changeset
321 save = "\n[Flags]\n";
63
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
322 for (j=0; j<2000; j++) {
0
223b71206888 Initial import
thib
parents:
diff changeset
323 if (var[6][j] != 0) {
63
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
324 sprintf(buf, "V<6>[%04d]=%d\n", j, var[6][j]);
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
325 save += buf;
0
223b71206888 Initial import
thib
parents:
diff changeset
326 }
63
4b9ffe15a87d Refactor Load/LoadSys
Thibaut GIRKA <thib@sitedethib.com>
parents: 62
diff changeset
327 }
0
223b71206888 Initial import
thib
parents:
diff changeset
328 for (j=0; j<2000; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
329 if (var[7][j] != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
330 sprintf(buf, "V<25>[%04d]=%d\n",j,var[7][j]);
223b71206888 Initial import
thib
parents:
diff changeset
331 save += buf;
223b71206888 Initial import
thib
parents:
diff changeset
332 }
223b71206888 Initial import
thib
parents:
diff changeset
333 }
223b71206888 Initial import
thib
parents:
diff changeset
334 for (j=0; j<2000; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
335 if (sys_str[j].length() != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
336 sprintf(buf, "V<M>[%04d]=%s\n", j, sys_str[j].c_str());
223b71206888 Initial import
thib
parents:
diff changeset
337 save += buf;
223b71206888 Initial import
thib
parents:
diff changeset
338 }
223b71206888 Initial import
thib
parents:
diff changeset
339 }
223b71206888 Initial import
thib
parents:
diff changeset
340 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
341
0
223b71206888 Initial import
thib
parents:
diff changeset
342 bool Flags::Exec(Cmd& cmd) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
343 if (cmd.cmd_type == CMD_FLAGS) { // 代入演算
0
223b71206888 Initial import
thib
parents:
diff changeset
344 if (cmd.args.size() != 2) return false;
223b71206888 Initial import
thib
parents:
diff changeset
345 Set(cmd.args[0], cmd.args[1].value);
223b71206888 Initial import
thib
parents:
diff changeset
346 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
347 return true;
223b71206888 Initial import
thib
parents:
diff changeset
348 }
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
349 if (cmd.cmd1 == 1 && cmd.cmd2 == 0x0a) { // 文字列演算
0
223b71206888 Initial import
thib
parents:
diff changeset
350 VarInfo arg1 = cmd.args[0];
223b71206888 Initial import
thib
parents:
diff changeset
351 switch(cmd.cmd3) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
352 case 0:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
353 if (cmd.cmd4 == 0) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
354 SetStr(arg1, cmd.Str(cmd.args[1]));
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
355 } else if (cmd.cmd4 == 1) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
356 string s = cmd.Str(cmd.args[1]);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
357 const char* sc = s.c_str();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
358 int len = cmd.args[2].value;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
359 int i;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
360 for (i=0; i < sc[i] && len != 0; i++, len--) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
361 if (sc[i]<0 && sc[i+1]!=0) i++;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
362 }
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
363 s.erase(i); // 全角で len 文字まで切り詰める
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
364 SetStr(arg1, s);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
365 // fprintf(stderr,"Set[%d,%d]<-%s\n",arg1.type,arg1.number,s.c_str());
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
366 } else break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
367 cmd.clear();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
368 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
369 case 1:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
370 if (cmd.cmd4 == 0) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
371 SetStr(arg1, "");
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
372 cmd.clear();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
373 } else if (cmd.cmd4 == 1) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
374 // 領域指定で文字列クリア
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
375 VarInfo v1 = cmd.args[0];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
376 VarInfo v2 = cmd.args[1];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
377 eprintf("memclear(str). Var[%d]<%d> - Var[%d]<%d>\n",v1.type, v1.number, v2.type, v2.number);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
378 if (v1.type != v2.type || (v1.type != TYPE_VARSTR && v1.type != TYPE_VARSYSSTR && v1.type != TYPE_VARLOCSTR)) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
379 eprintf(" error: bad args\n");
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
380 } else {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
381 if (v1.number < 0) v1.number = 0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
382 if (v2.number > 2000) v2.number = 2000;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
383 for (; v1.number <= v2.number; v1.number++) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
384 SetStr(v1, "");
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
385 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
386 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
387 cmd.clear();
0
223b71206888 Initial import
thib
parents:
diff changeset
388 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
389 case 2:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
390 SetStr(arg1, Str(arg1.type,arg1.number) + cmd.Str(cmd.args[1]));
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
391 // fprintf(stderr,"Append[%d,%d]<-%s(%d:%d)\n",arg1.type,arg1.number,Str(arg1.type,arg1.number).c_str(),cmd.args[1].type,cmd.args[1].number);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
392 cmd.clear();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
393 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
394 case 3:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
395 SetSys(strlen(cmd.Str(cmd.args[0])));
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
396 cmd.clear();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
397 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
398 case 4:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
399 { int v = strcmp(cmd.Str(cmd.args[0]), cmd.Str(cmd.args[1]));
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
400 // string s1=cmd.Str(cmd.args[0]);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
401 // string s2=cmd.Str(cmd.args[1]);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
402 // fprintf(stderr,"Cmp %s(%d:%d):%s(%d:%d):%d\n",s1.c_str(),cmd.args[0].type,cmd.args[0].number,s2.c_str(),cmd.args[1].type,cmd.args[1].number,v);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
403 if (v < 0) SetSys(-1);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
404 else if (v > 0) SetSys(1);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
405 else SetSys(0);
0
223b71206888 Initial import
thib
parents:
diff changeset
406 cmd.clear();
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
407 break; }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
408 case 5: // substring, index from left
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
409 case 6: // substring, index from right
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
410 // 全角対応らしい
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
411 //FIXME: Make sure it works properly
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
412 { int offset = cmd.args[2].value;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
413 int len = strlen(cmd.Str(cmd.args[1]));
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
414 string str = cmd.Str(cmd.args[1]);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
415 const char* s = str.c_str();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
416 if (cmd.cmd3 == 6) offset = len - offset;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
417 if (offset < 0) offset = 0;
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
418 // 先頭 N 文字を読み飛ばす
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
419 int i;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
420 int offset_top = 0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
421 for (i=0; i<offset && s[offset_top] != 0; i++) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
422 if (s[offset_top] < 0 && s[offset_top+1] != 0) offset_top += 2;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
423 else offset_top += 1;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
424 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
425 if (s[offset_top] == 0) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
426 SetStr(arg1, "");
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
427 } else if (cmd.cmd4 == 0) { // 長さ制限なし
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
428 SetStr(arg1, string(s, offset_top, len-offset_top));
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
429 } else { // cmd.cmd4 == 1
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
430 int slen = cmd.args[3].value;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
431 int offset_end = offset_top;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
432 for (i=0; i<slen && s[offset_end] != 0; i++) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
433 if (s[offset_end] < 0 && s[offset_end]+1 != 0) offset_end += 2;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
434 else offset_end += 1;
0
223b71206888 Initial import
thib
parents:
diff changeset
435 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
436 string result(s, offset_top, offset_end-offset_top);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
437 SetStr(arg1, result);
0
223b71206888 Initial import
thib
parents:
diff changeset
438 }
223b71206888 Initial import
thib
parents:
diff changeset
439 cmd.clear();
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
440 break; }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
441 case 7: {// strlen w/ kanji
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
442 const char* s = cmd.Str(cmd.args[0]); int i;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
443 for (i=0; *s != 0; i++) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
444 if (*s < 0 && s[1] != 0) s += 2;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
445 else s++;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
446 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
447 SetSys(i);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
448 cmd.clear();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
449 break; }
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
450 case 8: // 文字列を切って短くする
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
451 if (cmd.args[1].value <= 0) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
452 SetStr(arg1, "");
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
453 } else if (cmd.args[1].value < strlen(cmd.Str(cmd.args[1]))) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
454 Str(arg1.type,arg1.number).erase(cmd.args[1].value);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
455 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
456 cmd.clear();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
457 break;
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
458 case 0x0e: // 漢字モードでitoa
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
459 {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
460 int arg1 = cmd.args[0].value;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
461 string result;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
462 char wc[3]; wc[2]=0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
463 char buf[20];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
464 if (cmd.cmd4 == 0) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
465 sprintf(buf, "%d", arg1);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
466 } else { // cmd.cmd4 == 1
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
467 char fmt[20];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
468 sprintf(fmt, "%%%dd", cmd.args[2].value);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
469 sprintf(buf, fmt, arg1);
0
223b71206888 Initial import
thib
parents:
diff changeset
470 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
471 int i;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
472 for (i=0; buf[i] != 0; i++) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
473 if (buf[i] == ' ') {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
474 wc[0] = 0x81; // ' ' in SHIFT_JIS
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
475 wc[1] = 0x40;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
476 } else if (buf[i] == '-') {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
477 wc[0] = 0x81; // '-' in SHIFT_JIS
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
478 wc[1] = 0x7c;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
479 } else if (isdigit(buf[i])) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
480 wc[0] = 0x82; // number in SHIFT_JIS
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
481 wc[1] = buf[i] - '0' + 0x4f;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
482 } else {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
483 continue;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
484 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
485 result += wc;
0
223b71206888 Initial import
thib
parents:
diff changeset
486 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
487 SetStr(cmd.args[1], result);
0
223b71206888 Initial import
thib
parents:
diff changeset
488 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
489 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
490 break;
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
491 case 0x0f: case 0x11: // itoa (0x11 の方は zero padding するっぽい)
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
492 if (cmd.cmd4 == 0) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
493 int arg1 = cmd.args[0].value;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
494 char buf[1024]; sprintf(buf, "%d", arg1);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
495 SetStr(cmd.args[1], buf);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
496 cmd.clear();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
497 } else if (cmd.cmd4 == 1) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
498 // 漢字(SJIS) : 82 [4f+N]
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
499 // やはり漢字じゃない?
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
500 int arg1 = cmd.args[0].value;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
501 char buf[1024]; char fmt[1024];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
502 if (cmd.cmd3 == 0x0f) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
503 sprintf(fmt, "%%%dd",cmd.args[2].value); /* 空白でパディング */
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
504 } else {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
505 sprintf(fmt, "%%0%dd",cmd.args[2].value);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
506 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
507 sprintf(buf, fmt, arg1);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
508 SetStr(cmd.args[1], buf);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
509 cmd.clear();
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
510 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
511 break;
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
512 case 0x64: // 文字列の表示 : 引数をテキストウィンドウに表示
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
513 if (cmd.cmd4 == 1) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
514 char buf[256];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
515 snprintf(buf, 255, "%d", Get(cmd.args[0].type, cmd.args[0].number));
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
516 cmd.args[0].type = TYPE_STR;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
517 cmd.args[0].value = cmd.AddStr(buf);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
518 cmd.cmd4 = 0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
519 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
520 cmd.cmd_type = CMD_TEXT;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
521 break;
0
223b71206888 Initial import
thib
parents:
diff changeset
522 }
223b71206888 Initial import
thib
parents:
diff changeset
523 }
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
524 if (cmd.cmd1 == 1 && cmd.cmd2 == 0x0b) { // 数値変数演算
0
223b71206888 Initial import
thib
parents:
diff changeset
525 if (cmd.cmd3 == 0 && cmd.cmd4 == 0) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
526 /* 複数の変数をセット */
0
223b71206888 Initial import
thib
parents:
diff changeset
527 VarInfo v1 = cmd.args[0];
223b71206888 Initial import
thib
parents:
diff changeset
528 eprintf("set multiple-var Var[%d]<%d> <- ",v1.type, v1.number);
223b71206888 Initial import
thib
parents:
diff changeset
529 int i;
223b71206888 Initial import
thib
parents:
diff changeset
530 if (cmd.args.size() < cmd.argc) {
223b71206888 Initial import
thib
parents:
diff changeset
531 eprintf(" error: argsize changed %d -> %d\n",cmd.argc, cmd.args.size());
223b71206888 Initial import
thib
parents:
diff changeset
532 cmd.argc = cmd.args.size();
223b71206888 Initial import
thib
parents:
diff changeset
533 }
223b71206888 Initial import
thib
parents:
diff changeset
534 for (i=0; i<cmd.argc; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
535 eprintf("%d, ",cmd.args[i+1].value);
223b71206888 Initial import
thib
parents:
diff changeset
536 Set(v1, cmd.args[i+1].value);
223b71206888 Initial import
thib
parents:
diff changeset
537 v1.number++;
223b71206888 Initial import
thib
parents:
diff changeset
538 }
223b71206888 Initial import
thib
parents:
diff changeset
539 eprintf("\n");
223b71206888 Initial import
thib
parents:
diff changeset
540 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
541 } else if (cmd.cmd3 == 1 && cmd.cmd4 == 0) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
542 /* 領域指定で変数をクリア */
0
223b71206888 Initial import
thib
parents:
diff changeset
543 VarInfo v1 = cmd.args[0];
223b71206888 Initial import
thib
parents:
diff changeset
544 VarInfo v2 = cmd.args[1];
223b71206888 Initial import
thib
parents:
diff changeset
545 eprintf("memclear. Var[%d]<%d> - Var[%d]<%d>\n",v1.type, v1.number, v2.type, v2.number);
223b71206888 Initial import
thib
parents:
diff changeset
546 if (v1.type != v2.type || !IsInt(v1.type)) eprintf(" error: bad args\n");
223b71206888 Initial import
thib
parents:
diff changeset
547 else {
223b71206888 Initial import
thib
parents:
diff changeset
548 if (v1.number < 0) v1.number = 0;
223b71206888 Initial import
thib
parents:
diff changeset
549 if (v2.number > MaxIndex(v2.type)) v2.number = MaxIndex(v2.type);
223b71206888 Initial import
thib
parents:
diff changeset
550 for (; v1.number <= v2.number; v1.number++)
223b71206888 Initial import
thib
parents:
diff changeset
551 Set(v1, 0);
223b71206888 Initial import
thib
parents:
diff changeset
552 }
223b71206888 Initial import
thib
parents:
diff changeset
553 cmd.clear();
223b71206888 Initial import
thib
parents:
diff changeset
554 } else if (cmd.cmd3 == 1 && cmd.cmd4 == 1) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
555 /* 領域指定で変数をセット */
0
223b71206888 Initial import
thib
parents:
diff changeset
556 VarInfo v1 = cmd.args[0];
223b71206888 Initial import
thib
parents:
diff changeset
557 VarInfo v2 = cmd.args[1];
223b71206888 Initial import
thib
parents:
diff changeset
558 int value = cmd.args[2].value;
223b71206888 Initial import
thib
parents:
diff changeset
559 eprintf("memset. Var[%d]<%d> - Var[%d]<%d> <- %d\n",v1.type, v1.number, v2.type, v2.number, value);
223b71206888 Initial import
thib
parents:
diff changeset
560 if (v1.type != v2.type || !IsInt(v1.type)) eprintf(" error: bad args\n");
223b71206888 Initial import
thib
parents:
diff changeset
561 else {
223b71206888 Initial import
thib
parents:
diff changeset
562 if (v1.number < 0) v1.number = 0;
223b71206888 Initial import
thib
parents:
diff changeset
563 if (v2.number > MaxIndex(v2.type)) v2.number = MaxIndex(v2.type);
223b71206888 Initial import
thib
parents:
diff changeset
564 for (; v1.number <= v2.number; v1.number++)
223b71206888 Initial import
thib
parents:
diff changeset
565 Set(v1, value);
223b71206888 Initial import
thib
parents:
diff changeset
566 }
223b71206888 Initial import
thib
parents:
diff changeset
567 cmd.clear();
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
568 } else if (cmd.cmd3 == 4 && cmd.cmd4 == 1) { // 領域クリア(sysfunc.txt)
0
223b71206888 Initial import
thib
parents:
diff changeset
569 VarInfo v1 = cmd.args[0];
223b71206888 Initial import
thib
parents:
diff changeset
570 int step = cmd.args[1].value;
223b71206888 Initial import
thib
parents:
diff changeset
571 int deal = cmd.args[2].value;
223b71206888 Initial import
thib
parents:
diff changeset
572 int val = cmd.args[3].value;
223b71206888 Initial import
thib
parents:
diff changeset
573 eprintf("memclear. Var[%d]<%d> step %d deal %d <- val %d\n",v1.type, v1.number, step, deal, val);
223b71206888 Initial import
thib
parents:
diff changeset
574 int i; for (i=0; i<deal; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
575 Set(v1, val);
223b71206888 Initial import
thib
parents:
diff changeset
576 v1.number += step;
223b71206888 Initial import
thib
parents:
diff changeset
577 }
223b71206888 Initial import
thib
parents:
diff changeset
578 cmd.clear();
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
579 } else if (cmd.cmd3 == 0x64 && cmd.cmd4 == 0) { //領域で数値を合計する
0
223b71206888 Initial import
thib
parents:
diff changeset
580 VarInfo v1 = cmd.args[0];
223b71206888 Initial import
thib
parents:
diff changeset
581 VarInfo v2 = cmd.args[1];
223b71206888 Initial import
thib
parents:
diff changeset
582 eprintf("sum var. Var[%d]<%d> - Var[%d]<%d>\n",v1.type, v1.number, v2.type, v2.number);
223b71206888 Initial import
thib
parents:
diff changeset
583 int sum = 0;
223b71206888 Initial import
thib
parents:
diff changeset
584 if (v1.type != v2.type || !IsInt(v1.type)) eprintf(" error: bad args\n");
223b71206888 Initial import
thib
parents:
diff changeset
585 else {
223b71206888 Initial import
thib
parents:
diff changeset
586 if (v1.number < 0) v1.number = 0;
223b71206888 Initial import
thib
parents:
diff changeset
587 if (v2.number > MaxIndex(v2.type)) v2.number = MaxIndex(v2.type);
223b71206888 Initial import
thib
parents:
diff changeset
588 for (; v1.number <= v2.number; v1.number++)
223b71206888 Initial import
thib
parents:
diff changeset
589 sum += (*this)(v1);
223b71206888 Initial import
thib
parents:
diff changeset
590 }
223b71206888 Initial import
thib
parents:
diff changeset
591 eprintf(" ret %d\n",sum);
223b71206888 Initial import
thib
parents:
diff changeset
592 cmd.SetSysvar(sum);
223b71206888 Initial import
thib
parents:
diff changeset
593 }
223b71206888 Initial import
thib
parents:
diff changeset
594 }
223b71206888 Initial import
thib
parents:
diff changeset
595 return false;
223b71206888 Initial import
thib
parents:
diff changeset
596 }
223b71206888 Initial import
thib
parents:
diff changeset
597
223b71206888 Initial import
thib
parents:
diff changeset
598 /*********************************************************************
54
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
599 ** SimpleCmd
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
600 */
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
601
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
602 SimpleCmd::SimpleCmd(int a, int b, int c)
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
603 {
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
604 cmd1 = a;
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
605 cmd2 = b;
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
606 cmd3 = c;
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
607 }
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
608
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
609 SimpleCmd::SimpleCmd(void)
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
610 {
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
611 cmd1 = cmd2 = cmd3 = 0;
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
612 }
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
613
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
614 bool SimpleCmd::operator<(const SimpleCmd& cmd) const
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
615 {
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
616 if (cmd1 < cmd.cmd1) return true;
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
617 else if (cmd1 > cmd.cmd1) return false;
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
618
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
619 if (cmd2 < cmd.cmd2) return true;
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
620 else if (cmd2 > cmd.cmd2) return false;
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
621
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
622 if (cmd3 < cmd.cmd3) return true;
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
623 else return false;
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
624 }
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
625
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
626 bool SimpleCmd::operator==(const SimpleCmd& cmd) const
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
627 {
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
628 return (cmd1 == cmd.cmd1 && cmd2 == cmd.cmd2 && cmd3 == cmd.cmd3);
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
629 }
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
630
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
631
d7cde171a1de * scn2k_grp.cc now handles commands in a cleanier way \o/
thib
parents: 52
diff changeset
632 /*********************************************************************
0
223b71206888 Initial import
thib
parents:
diff changeset
633 ** Cmd
223b71206888 Initial import
thib
parents:
diff changeset
634 */
223b71206888 Initial import
thib
parents:
diff changeset
635
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
636 /* 数値 num := 0x24 0xff <int num> */
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
637 /* 変数 var := 0x24 <uchar type> 0x5b <exp> 0x5d */
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
638 /* 項 token := num | var | 0x28 <exp> 0x29 | <plus|minus> token */
0
223b71206888 Initial import
thib
parents:
diff changeset
639
223b71206888 Initial import
thib
parents:
diff changeset
640 int Cmd::GetLeftToken(const char*& d, VarInfo& info) {
223b71206888 Initial import
thib
parents:
diff changeset
641 bool var_flag = true;
223b71206888 Initial import
thib
parents:
diff changeset
642 int minus_flag = 0;
223b71206888 Initial import
thib
parents:
diff changeset
643 int value = 0;
223b71206888 Initial import
thib
parents:
diff changeset
644 if (d[0] == 0x5c && (d[1] == 1 || d[1] == 0) ) {
223b71206888 Initial import
thib
parents:
diff changeset
645 if (d[1] == 1) {dprintf("minus-"); minus_flag ^= 1;}
223b71206888 Initial import
thib
parents:
diff changeset
646 else dprintf("plus-");
223b71206888 Initial import
thib
parents:
diff changeset
647 d += 2;
223b71206888 Initial import
thib
parents:
diff changeset
648 var_flag = false;
223b71206888 Initial import
thib
parents:
diff changeset
649 }
223b71206888 Initial import
thib
parents:
diff changeset
650 if (d[0] == 0x24 && ((unsigned const char*)d)[1] == 0xff) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
651 // if ( (d[0] == 0x30 || d[0] == 0x31) && d[1] == 0x24 && ((unsigned const char*)d)[2] == 0xff) /* @@@ not supported; selection 内で、0x30|0x31 が付随することがある */
0
223b71206888 Initial import
thib
parents:
diff changeset
652 // numerical atom
223b71206888 Initial import
thib
parents:
diff changeset
653 d += 6;
223b71206888 Initial import
thib
parents:
diff changeset
654 value = read_little_endian_int(d-4);
223b71206888 Initial import
thib
parents:
diff changeset
655 dprintf("%d",value);
223b71206888 Initial import
thib
parents:
diff changeset
656 var_flag = false;
223b71206888 Initial import
thib
parents:
diff changeset
657 } else if (d[0] == 0x24 && *(unsigned char*)(d+1) == 0xc8) {
223b71206888 Initial import
thib
parents:
diff changeset
658 dprintf("V<sys>");
223b71206888 Initial import
thib
parents:
diff changeset
659 d += 2;
223b71206888 Initial import
thib
parents:
diff changeset
660 info.type = TYPE_SYS; info.number = 0;
223b71206888 Initial import
thib
parents:
diff changeset
661 value = info.value = flags();
223b71206888 Initial import
thib
parents:
diff changeset
662 } else if (d[0] == 0x24 && d[2] == 0x5b) {
223b71206888 Initial import
thib
parents:
diff changeset
663 // 0x24,<type>,0x5b,<expr>,0x5d-terminated term
223b71206888 Initial import
thib
parents:
diff changeset
664 info.type = *(unsigned char*)(d+1);
223b71206888 Initial import
thib
parents:
diff changeset
665 d += 3;
223b71206888 Initial import
thib
parents:
diff changeset
666 dprintf("V<%d>[",info.type);
223b71206888 Initial import
thib
parents:
diff changeset
667 info.number = GetExpression(d);
223b71206888 Initial import
thib
parents:
diff changeset
668 dprintf("]");
223b71206888 Initial import
thib
parents:
diff changeset
669 if (*d == 0x5d) d++;
223b71206888 Initial import
thib
parents:
diff changeset
670 else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
671 if (info.type == TYPE_VARSTR || info.type == TYPE_VARSYSSTR || info.type == TYPE_VARLOCSTR) {
223b71206888 Initial import
thib
parents:
diff changeset
672 value = 0;
223b71206888 Initial import
thib
parents:
diff changeset
673 info.value = StrVar(info.type, info.number);
223b71206888 Initial import
thib
parents:
diff changeset
674 } else {
223b71206888 Initial import
thib
parents:
diff changeset
675 value = info.value = flags(info);
223b71206888 Initial import
thib
parents:
diff changeset
676 }
223b71206888 Initial import
thib
parents:
diff changeset
677 dprintf("(=%d)",value);
223b71206888 Initial import
thib
parents:
diff changeset
678 } else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
679
223b71206888 Initial import
thib
parents:
diff changeset
680 if (minus_flag) value = -value;
223b71206888 Initial import
thib
parents:
diff changeset
681 if (!var_flag) {
223b71206888 Initial import
thib
parents:
diff changeset
682 info.type = TYPE_VAL;
223b71206888 Initial import
thib
parents:
diff changeset
683 info.value = value;
223b71206888 Initial import
thib
parents:
diff changeset
684 }
223b71206888 Initial import
thib
parents:
diff changeset
685 return value;
223b71206888 Initial import
thib
parents:
diff changeset
686 }
223b71206888 Initial import
thib
parents:
diff changeset
687
47
5f548e5957a8 * get rid of the "deprecated conversion from string constant to ‘char*’" warnings
thib
parents: 44
diff changeset
688 static const char* op_str[70] = {
0
223b71206888 Initial import
thib
parents:
diff changeset
689 // 0 1 2 3 4 5 6 7 8 9
223b71206888 Initial import
thib
parents:
diff changeset
690 "+", "-", "*", "/", "%", "&", "|", "^", "<<", ">>", // +00
223b71206888 Initial import
thib
parents:
diff changeset
691 "err.","err.","err.","err.","err.","err.","err.","err.","err.","err.", // +10
223b71206888 Initial import
thib
parents:
diff changeset
692 "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>=", // +20
223b71206888 Initial import
thib
parents:
diff changeset
693 "=", "err.","err.","err.","err.","err.","err.","err.","err.","err.", // +30
223b71206888 Initial import
thib
parents:
diff changeset
694 "==", "!=", "<=", "<", ">=", ">", "err.","err.","err.","err.", // +40
223b71206888 Initial import
thib
parents:
diff changeset
695 "err.","err.","err.","err.","err.","err.","err.","err.","err.","err.", // +50
223b71206888 Initial import
thib
parents:
diff changeset
696 "&&", "||", "err.","err.","err.","err.","err.","err.","err.","err.", // +60
223b71206888 Initial import
thib
parents:
diff changeset
697 };
223b71206888 Initial import
thib
parents:
diff changeset
698
223b71206888 Initial import
thib
parents:
diff changeset
699 static int op_pri_tbl[12] = {
223b71206888 Initial import
thib
parents:
diff changeset
700 // + - * / % & | ^ << >>
223b71206888 Initial import
thib
parents:
diff changeset
701 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10};
223b71206888 Initial import
thib
parents:
diff changeset
702
223b71206888 Initial import
thib
parents:
diff changeset
703 inline int op_pri(int op) {
223b71206888 Initial import
thib
parents:
diff changeset
704 if (op > 11) return 10;
223b71206888 Initial import
thib
parents:
diff changeset
705 return op_pri_tbl[op];
223b71206888 Initial import
thib
parents:
diff changeset
706 }
223b71206888 Initial import
thib
parents:
diff changeset
707 inline int op_pri_cond(int op) {
223b71206888 Initial import
thib
parents:
diff changeset
708 if (op <= 11) return op_pri_tbl[op];
223b71206888 Initial import
thib
parents:
diff changeset
709 else if (op < 50) return 7;
223b71206888 Initial import
thib
parents:
diff changeset
710 else if (op == 60) return 8;
223b71206888 Initial import
thib
parents:
diff changeset
711 else if (op == 61) return 8;
223b71206888 Initial import
thib
parents:
diff changeset
712 else return 10;
223b71206888 Initial import
thib
parents:
diff changeset
713 }
223b71206888 Initial import
thib
parents:
diff changeset
714
223b71206888 Initial import
thib
parents:
diff changeset
715
223b71206888 Initial import
thib
parents:
diff changeset
716 inline int eval(int v1, int op, int v2) {
223b71206888 Initial import
thib
parents:
diff changeset
717 switch(op) {
223b71206888 Initial import
thib
parents:
diff changeset
718 case 0: return v1+v2;
223b71206888 Initial import
thib
parents:
diff changeset
719 case 1: return v1-v2;
223b71206888 Initial import
thib
parents:
diff changeset
720 case 2: return v1*v2;
223b71206888 Initial import
thib
parents:
diff changeset
721 case 3: return v2!=0 ? v1/v2 : v1;
223b71206888 Initial import
thib
parents:
diff changeset
722 case 4: return v2!=0 ? v1%v2 : v1;
223b71206888 Initial import
thib
parents:
diff changeset
723 case 5: return v1&v2;
223b71206888 Initial import
thib
parents:
diff changeset
724 case 6: return v1|v2;
223b71206888 Initial import
thib
parents:
diff changeset
725 case 7: return v1^v2;
223b71206888 Initial import
thib
parents:
diff changeset
726 case 8: return v1<<v2;
223b71206888 Initial import
thib
parents:
diff changeset
727 case 9: return v1>>v2;
223b71206888 Initial import
thib
parents:
diff changeset
728 case 40: return v1 == v2;
223b71206888 Initial import
thib
parents:
diff changeset
729 case 41: return v1 != v2;
223b71206888 Initial import
thib
parents:
diff changeset
730 case 42: return v1 <= v2;
223b71206888 Initial import
thib
parents:
diff changeset
731 case 43: return v1 < v2;
223b71206888 Initial import
thib
parents:
diff changeset
732 case 44: return v1 >= v2;
223b71206888 Initial import
thib
parents:
diff changeset
733 case 45: return v1 > v2;
223b71206888 Initial import
thib
parents:
diff changeset
734 case 60: return v1 && v2;
223b71206888 Initial import
thib
parents:
diff changeset
735 case 61: return v1 || v2;
223b71206888 Initial import
thib
parents:
diff changeset
736 }
223b71206888 Initial import
thib
parents:
diff changeset
737 return v2;
223b71206888 Initial import
thib
parents:
diff changeset
738 }
223b71206888 Initial import
thib
parents:
diff changeset
739
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
740 Cmd::Cmd(const Flags& f, int _sys_ver) : flags(f), system_version(_sys_ver) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
741 cmd_type = CMD_NOP;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
742 argc = 0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
743 errorflag = false;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
744 cmdstr[0] = 0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
745 strend = 0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
746 pos = -1;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
747 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
748
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
749 /* 演算子 op := 0x5c <uchar op> */
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
750 /* 数式 exp: [op] <token> [op <token> [...]] */
0
223b71206888 Initial import
thib
parents:
diff changeset
751 int Cmd::GetExpression(const char*& d, VarInfo* info_ptr) {
223b71206888 Initial import
thib
parents:
diff changeset
752 #define STACK_DEPTH 1024
223b71206888 Initial import
thib
parents:
diff changeset
753 #define OP_LB 11
223b71206888 Initial import
thib
parents:
diff changeset
754 char op_stack[STACK_DEPTH];
223b71206888 Initial import
thib
parents:
diff changeset
755 int val_stack[STACK_DEPTH];
223b71206888 Initial import
thib
parents:
diff changeset
756 int stack_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
757
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
758 // 第一項の読み込み
0
223b71206888 Initial import
thib
parents:
diff changeset
759 while(*d == 0x28) {
223b71206888 Initial import
thib
parents:
diff changeset
760 d++;
223b71206888 Initial import
thib
parents:
diff changeset
761 dprintf("(");
223b71206888 Initial import
thib
parents:
diff changeset
762 op_stack[stack_count++] = OP_LB;
223b71206888 Initial import
thib
parents:
diff changeset
763 }
223b71206888 Initial import
thib
parents:
diff changeset
764 VarInfo info;
223b71206888 Initial import
thib
parents:
diff changeset
765 int value = GetLeftToken(d, info);
223b71206888 Initial import
thib
parents:
diff changeset
766
223b71206888 Initial import
thib
parents:
diff changeset
767 while(*d == 0x29 && stack_count > 0 && op_stack[stack_count-1] == OP_LB) {
223b71206888 Initial import
thib
parents:
diff changeset
768 d++;
223b71206888 Initial import
thib
parents:
diff changeset
769 dprintf(")");
223b71206888 Initial import
thib
parents:
diff changeset
770 stack_count--;
223b71206888 Initial import
thib
parents:
diff changeset
771 }
223b71206888 Initial import
thib
parents:
diff changeset
772
223b71206888 Initial import
thib
parents:
diff changeset
773 if (*d != 0x5c && stack_count == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
774 if (info_ptr) *info_ptr = info;
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
775 return value; // 単純なleft-termはここで終了。有効なinfo_ptrを帰す(可能性がある)
0
223b71206888 Initial import
thib
parents:
diff changeset
776 }
223b71206888 Initial import
thib
parents:
diff changeset
777
223b71206888 Initial import
thib
parents:
diff changeset
778 while(*d == 0x5c) {
223b71206888 Initial import
thib
parents:
diff changeset
779 int op_type = *(unsigned char*)(d+1);
223b71206888 Initial import
thib
parents:
diff changeset
780 d += 2;
223b71206888 Initial import
thib
parents:
diff changeset
781 if (op_type < 70) dprintf("%s",op_str[op_type]);
223b71206888 Initial import
thib
parents:
diff changeset
782 else dprintf("err.");
223b71206888 Initial import
thib
parents:
diff changeset
783 if (op_type >= 10) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
784 int cur_pri = op_pri(op_type);
223b71206888 Initial import
thib
parents:
diff changeset
785 while(stack_count != 0 && op_pri(op_stack[stack_count-1]) <= cur_pri) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
786 // 優先順位の高い、先行する演算を行う
0
223b71206888 Initial import
thib
parents:
diff changeset
787 value = eval(val_stack[stack_count-1], op_stack[stack_count-1], value);
223b71206888 Initial import
thib
parents:
diff changeset
788 stack_count--;
223b71206888 Initial import
thib
parents:
diff changeset
789 }
223b71206888 Initial import
thib
parents:
diff changeset
790 val_stack[stack_count] = value;
223b71206888 Initial import
thib
parents:
diff changeset
791 op_stack[stack_count++] = op_type;
223b71206888 Initial import
thib
parents:
diff changeset
792 while(*d == 0x28) {
223b71206888 Initial import
thib
parents:
diff changeset
793 d++;
223b71206888 Initial import
thib
parents:
diff changeset
794 dprintf("(");
223b71206888 Initial import
thib
parents:
diff changeset
795 op_stack[stack_count++] = OP_LB;
223b71206888 Initial import
thib
parents:
diff changeset
796 }
223b71206888 Initial import
thib
parents:
diff changeset
797 if (stack_count >= STACK_DEPTH) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
798 value = GetLeftToken(d, info);
223b71206888 Initial import
thib
parents:
diff changeset
799
223b71206888 Initial import
thib
parents:
diff changeset
800 while (*d != 0x5c && stack_count > 0) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
801 // 未実行の演算を終わらせる
0
223b71206888 Initial import
thib
parents:
diff changeset
802 if (op_stack[stack_count-1] != OP_LB) {
223b71206888 Initial import
thib
parents:
diff changeset
803 value = eval(val_stack[stack_count-1], op_stack[stack_count-1], value);
223b71206888 Initial import
thib
parents:
diff changeset
804 stack_count--;
223b71206888 Initial import
thib
parents:
diff changeset
805 } else if (*d == 0x29) { /* op_stack == OP_LB */
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
806 // bracket 終端があれば、閉じておく
0
223b71206888 Initial import
thib
parents:
diff changeset
807 d++;
223b71206888 Initial import
thib
parents:
diff changeset
808 dprintf(")");
223b71206888 Initial import
thib
parents:
diff changeset
809 stack_count--;
223b71206888 Initial import
thib
parents:
diff changeset
810 } else break; // error
223b71206888 Initial import
thib
parents:
diff changeset
811 }
223b71206888 Initial import
thib
parents:
diff changeset
812 }
223b71206888 Initial import
thib
parents:
diff changeset
813 if (stack_count) SetError(); // unbalanced bracket
223b71206888 Initial import
thib
parents:
diff changeset
814 dprintf("(=%d)",value);
223b71206888 Initial import
thib
parents:
diff changeset
815 if (info_ptr) {
223b71206888 Initial import
thib
parents:
diff changeset
816 info_ptr->type = TYPE_VAL;
223b71206888 Initial import
thib
parents:
diff changeset
817 info_ptr->value = value;
223b71206888 Initial import
thib
parents:
diff changeset
818 }
223b71206888 Initial import
thib
parents:
diff changeset
819 return value;
223b71206888 Initial import
thib
parents:
diff changeset
820 }
223b71206888 Initial import
thib
parents:
diff changeset
821
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
822 // 条件分岐専用に、条件演算と算術演算の混合を検知できる専用ルーチン(本来はGetExpressionで差し支えない)
0
223b71206888 Initial import
thib
parents:
diff changeset
823 int Cmd::GetExpressionCond(const char*& d) {
223b71206888 Initial import
thib
parents:
diff changeset
824 char op_stack[STACK_DEPTH];
223b71206888 Initial import
thib
parents:
diff changeset
825 int val_stack[STACK_DEPTH];
223b71206888 Initial import
thib
parents:
diff changeset
826 int valattr_stack[STACK_DEPTH];
223b71206888 Initial import
thib
parents:
diff changeset
827 #define ATTR_VAL 0
223b71206888 Initial import
thib
parents:
diff changeset
828 #define ATTR_FLAG 1
223b71206888 Initial import
thib
parents:
diff changeset
829 int stack_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
830
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
831 // 第一項の読み込み
0
223b71206888 Initial import
thib
parents:
diff changeset
832 while(*d == 0x28) {
223b71206888 Initial import
thib
parents:
diff changeset
833 d++;
223b71206888 Initial import
thib
parents:
diff changeset
834 dprintf("(");
223b71206888 Initial import
thib
parents:
diff changeset
835 op_stack[stack_count++] = OP_LB;
223b71206888 Initial import
thib
parents:
diff changeset
836 }
223b71206888 Initial import
thib
parents:
diff changeset
837 VarInfo info;
223b71206888 Initial import
thib
parents:
diff changeset
838 int value = GetLeftToken(d, info);
223b71206888 Initial import
thib
parents:
diff changeset
839 while(*d == 0x29 && stack_count > 0 && op_stack[stack_count-1] == OP_LB) {
223b71206888 Initial import
thib
parents:
diff changeset
840 d++;
223b71206888 Initial import
thib
parents:
diff changeset
841 dprintf(")");
223b71206888 Initial import
thib
parents:
diff changeset
842 stack_count--;
223b71206888 Initial import
thib
parents:
diff changeset
843 }
223b71206888 Initial import
thib
parents:
diff changeset
844 bool valattr = ATTR_VAL;
223b71206888 Initial import
thib
parents:
diff changeset
845
223b71206888 Initial import
thib
parents:
diff changeset
846 while(*d == 0x5c) {
223b71206888 Initial import
thib
parents:
diff changeset
847 int op_type = *(unsigned char*)(d+1);
223b71206888 Initial import
thib
parents:
diff changeset
848 d += 2;
223b71206888 Initial import
thib
parents:
diff changeset
849 if (op_type < 70) dprintf("%s",op_str[op_type]);
223b71206888 Initial import
thib
parents:
diff changeset
850 else dprintf("err.");
223b71206888 Initial import
thib
parents:
diff changeset
851 int cur_pri = op_pri_cond(op_type);
223b71206888 Initial import
thib
parents:
diff changeset
852 while(stack_count != 0 && op_pri_cond(op_stack[stack_count-1]) <= cur_pri) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
853 // 優先順位の高い、先行する演算を行う
0
223b71206888 Initial import
thib
parents:
diff changeset
854 if (op_stack[stack_count-1] >= 60) {
223b71206888 Initial import
thib
parents:
diff changeset
855 if (valattr_stack[stack_count-1] != ATTR_FLAG || valattr != ATTR_FLAG) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
856 } else {
223b71206888 Initial import
thib
parents:
diff changeset
857 if (valattr_stack[stack_count-1] != ATTR_VAL || valattr != ATTR_VAL) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
858 }
223b71206888 Initial import
thib
parents:
diff changeset
859 value = eval(val_stack[stack_count-1], op_stack[stack_count-1], value);
223b71206888 Initial import
thib
parents:
diff changeset
860 if (op_stack[stack_count-1] >= 40) valattr = ATTR_FLAG;
223b71206888 Initial import
thib
parents:
diff changeset
861 stack_count--;
223b71206888 Initial import
thib
parents:
diff changeset
862 }
223b71206888 Initial import
thib
parents:
diff changeset
863 val_stack[stack_count] = value;
223b71206888 Initial import
thib
parents:
diff changeset
864 valattr_stack[stack_count] = valattr;
223b71206888 Initial import
thib
parents:
diff changeset
865 op_stack[stack_count++] = op_type;
223b71206888 Initial import
thib
parents:
diff changeset
866 while(*d == 0x28) {
223b71206888 Initial import
thib
parents:
diff changeset
867 d++;
223b71206888 Initial import
thib
parents:
diff changeset
868 dprintf("(");
223b71206888 Initial import
thib
parents:
diff changeset
869 op_stack[stack_count++] = OP_LB;
223b71206888 Initial import
thib
parents:
diff changeset
870 }
223b71206888 Initial import
thib
parents:
diff changeset
871 if (stack_count >= STACK_DEPTH) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
872 value = GetLeftToken(d, info);
223b71206888 Initial import
thib
parents:
diff changeset
873 valattr = ATTR_VAL;
223b71206888 Initial import
thib
parents:
diff changeset
874
223b71206888 Initial import
thib
parents:
diff changeset
875 while (*d != 0x5c && stack_count > 0) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
876 // 未実行の演算を終わらせる
0
223b71206888 Initial import
thib
parents:
diff changeset
877 if (op_stack[stack_count-1] != OP_LB) {
223b71206888 Initial import
thib
parents:
diff changeset
878 if (op_stack[stack_count-1] >= 60) {
223b71206888 Initial import
thib
parents:
diff changeset
879 if (valattr_stack[stack_count-1] != ATTR_FLAG || valattr != ATTR_FLAG) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
880 } else {
223b71206888 Initial import
thib
parents:
diff changeset
881 if (valattr_stack[stack_count-1] != ATTR_VAL || valattr != ATTR_VAL) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
882 }
223b71206888 Initial import
thib
parents:
diff changeset
883 value = eval(val_stack[stack_count-1], op_stack[stack_count-1], value);
223b71206888 Initial import
thib
parents:
diff changeset
884 if (op_stack[stack_count-1] >= 40) valattr = ATTR_FLAG;
223b71206888 Initial import
thib
parents:
diff changeset
885 stack_count--;
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
886 // bracket 終端があれば、閉じておく
0
223b71206888 Initial import
thib
parents:
diff changeset
887 } else if (*d == 0x29) { /* op_stack == OP_LB */
223b71206888 Initial import
thib
parents:
diff changeset
888 d++;
223b71206888 Initial import
thib
parents:
diff changeset
889 dprintf(")");
223b71206888 Initial import
thib
parents:
diff changeset
890 stack_count--;
223b71206888 Initial import
thib
parents:
diff changeset
891 } else break; // error
223b71206888 Initial import
thib
parents:
diff changeset
892 }
223b71206888 Initial import
thib
parents:
diff changeset
893 }
223b71206888 Initial import
thib
parents:
diff changeset
894 if (stack_count) SetError(); // unbalanced bracket
223b71206888 Initial import
thib
parents:
diff changeset
895 if (value) dprintf("(=true)");
223b71206888 Initial import
thib
parents:
diff changeset
896 else dprintf("(=false)");
223b71206888 Initial import
thib
parents:
diff changeset
897 return value;
223b71206888 Initial import
thib
parents:
diff changeset
898 }
223b71206888 Initial import
thib
parents:
diff changeset
899
223b71206888 Initial import
thib
parents:
diff changeset
900
223b71206888 Initial import
thib
parents:
diff changeset
901 /*
223b71206888 Initial import
thib
parents:
diff changeset
902 str =
223b71206888 Initial import
thib
parents:
diff changeset
903 arg =
223b71206888 Initial import
thib
parents:
diff changeset
904 args = 0x28 <exp> [[0x2c] <exp> [[0x2c] <exp> [...] ]]
223b71206888 Initial import
thib
parents:
diff changeset
905 */
223b71206888 Initial import
thib
parents:
diff changeset
906
223b71206888 Initial import
thib
parents:
diff changeset
907 int Cmd::GetArgs(const char*& d) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
908 if (*d != 0x28) return 0; /* 引数なし */
0
223b71206888 Initial import
thib
parents:
diff changeset
909 d++;
223b71206888 Initial import
thib
parents:
diff changeset
910 dprintf("args:");
223b71206888 Initial import
thib
parents:
diff changeset
911 VarInfo var;
223b71206888 Initial import
thib
parents:
diff changeset
912 int i; for (i=0; i<100 ; i++) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
913 /* number, variable, string の種別なく値を得る */
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
914 if (*d == 0x61) { // よくわからない(智代アフター)
29
d229cce98f50 * no more (or, at least, less) duplicate code between scn2kdump and the rest
thib
parents: 21
diff changeset
915 dprintf("@%d",d[1]);
0
223b71206888 Initial import
thib
parents:
diff changeset
916 d += 2;
223b71206888 Initial import
thib
parents:
diff changeset
917 if (*d == 0x28) {
223b71206888 Initial import
thib
parents:
diff changeset
918 dprintf("{");
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
919 GetArgs(d); // (A,B,C)節が含まれることがある
0
223b71206888 Initial import
thib
parents:
diff changeset
920 dprintf("}");
223b71206888 Initial import
thib
parents:
diff changeset
921 } else {
223b71206888 Initial import
thib
parents:
diff changeset
922 dprintf("{}");
223b71206888 Initial import
thib
parents:
diff changeset
923 }
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
924 } else if (d[0] == 0x0a || d[0] == 0x40) { // よくわからない (Little Busters!)
0
223b71206888 Initial import
thib
parents:
diff changeset
925 int var;
223b71206888 Initial import
thib
parents:
diff changeset
926 if (system_version == 0) { var = read_little_endian_int(d+1); d += 5;}
223b71206888 Initial import
thib
parents:
diff changeset
927 else { var = read_little_endian_short(d+1); d += 3;}
223b71206888 Initial import
thib
parents:
diff changeset
928 dprintf("line %d; ",var);
223b71206888 Initial import
thib
parents:
diff changeset
929 } else if (*d == 0x24 || (*d == 0x5c && (d[1] == 1 || d[1] == 0)) || *d == 0x28) {
223b71206888 Initial import
thib
parents:
diff changeset
930 GetExpression(d, &var);
223b71206888 Initial import
thib
parents:
diff changeset
931 args.push_back(var);
223b71206888 Initial import
thib
parents:
diff changeset
932 } else if (StrType(d)) {
223b71206888 Initial import
thib
parents:
diff changeset
933 var.type = TYPE_STR;
223b71206888 Initial import
thib
parents:
diff changeset
934 var.value = GetString(d);
223b71206888 Initial import
thib
parents:
diff changeset
935 args.push_back(var);
223b71206888 Initial import
thib
parents:
diff changeset
936 } else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
937 if (*d == 0x29) break;
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
938 if (*d == 0x2c) {d++;} // 次の arg が演算子で始まる、などがなければ存在しない
0
223b71206888 Initial import
thib
parents:
diff changeset
939 dprintf(",");
223b71206888 Initial import
thib
parents:
diff changeset
940 }
223b71206888 Initial import
thib
parents:
diff changeset
941 if (*d == 0x29) d++;
223b71206888 Initial import
thib
parents:
diff changeset
942 else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
943 return i;
223b71206888 Initial import
thib
parents:
diff changeset
944 }
223b71206888 Initial import
thib
parents:
diff changeset
945
223b71206888 Initial import
thib
parents:
diff changeset
946 int Cmd::GetArgsSpecial(int normal_args,const char*& d) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
947 if (*d != 0x28) return 0; /* 引数なし */
0
223b71206888 Initial import
thib
parents:
diff changeset
948 d++;
223b71206888 Initial import
thib
parents:
diff changeset
949 dprintf("args:");
223b71206888 Initial import
thib
parents:
diff changeset
950 int i; for (i=0; i<normal_args; i++) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
951 /* number, variable, string の種別なく値を得る */
0
223b71206888 Initial import
thib
parents:
diff changeset
952 if (*d == 0x24 || (*d == 0x5c && (d[1] == 1 || d[1] == 0)) || *d == 0x28) {
223b71206888 Initial import
thib
parents:
diff changeset
953 GetExpression(d);
223b71206888 Initial import
thib
parents:
diff changeset
954 } else if (StrType(d)) {
223b71206888 Initial import
thib
parents:
diff changeset
955 GetString(d);
223b71206888 Initial import
thib
parents:
diff changeset
956 } else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
957 if (*d == 0x29) break;
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
958 if (*d == 0x2c) {d++;} // 次の arg が演算子で始まる、などがなければ存在しない
0
223b71206888 Initial import
thib
parents:
diff changeset
959 dprintf(",");
223b71206888 Initial import
thib
parents:
diff changeset
960 }
223b71206888 Initial import
thib
parents:
diff changeset
961 for (i=0; i<argc ; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
962 if (*d == 0x28) {
223b71206888 Initial import
thib
parents:
diff changeset
963 /*
223b71206888 Initial import
thib
parents:
diff changeset
964 ** cmd 01-22:0c1c, 01-22:0835
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
965 ** Princess Bride のカードが落ちるアニメの場面
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
966 ** なお、_PBCARDANM* の画像はこのコマンドでのみ使われているので、特殊処理として無視することも可能
0
223b71206888 Initial import
thib
parents:
diff changeset
967 **
223b71206888 Initial import
thib
parents:
diff changeset
968 ** cmd 01-04:0276, 026c, 0270
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
969 ** 複数の enum が args の数だけ続く処理。特殊処理として分離する
0
223b71206888 Initial import
thib
parents:
diff changeset
970 */
223b71206888 Initial import
thib
parents:
diff changeset
971 dprintf("enum.<");
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
972 /* (...) は列挙型 or 構造体の可能性がある */
0
223b71206888 Initial import
thib
parents:
diff changeset
973 const char* d_orig = d;
223b71206888 Initial import
thib
parents:
diff changeset
974 int pt = args.size(); args.push_back(VarInfo(0));
223b71206888 Initial import
thib
parents:
diff changeset
975 int count = GetArgs(d);
223b71206888 Initial import
thib
parents:
diff changeset
976 args[pt] = VarInfo(count);
223b71206888 Initial import
thib
parents:
diff changeset
977 dprintf(">");
223b71206888 Initial import
thib
parents:
diff changeset
978 } else if (*d == 0x61 && (d[1] >= 0x00 && d[1] <= 0x04) && d[2] == 0x28 ) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
979 /* 使われるコマンドは 01-21:004b, 01-28:0064 のいずれか(R,C,PB,LO)
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
980 ** それらのコマンドは
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
981 ** arg1: 画像ファイル名
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
982 ** arg2 : Sel 番号
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
983 ** らしく、arg3 以降が 0x61 <00-04> (a,b,c,...) となる(ダンプ上は enum と表記される)
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
984 ** () 内の引数はさまざまで、a のみ(画像ファイル名)、
0
223b71206888 Initial import
thib
parents:
diff changeset
985 ** a,b b=SEL?
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
986 ** a,b,c (b,c)=座標?
0
223b71206888 Initial import
thib
parents:
diff changeset
987 ** a,(b,c,d,e,f,g) b-g = src / dest?
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
988 ** らしい
0
223b71206888 Initial import
thib
parents:
diff changeset
989 */
223b71206888 Initial import
thib
parents:
diff changeset
990 dprintf("kasane. #%d <",d[1]);
223b71206888 Initial import
thib
parents:
diff changeset
991 d += 2;
223b71206888 Initial import
thib
parents:
diff changeset
992 int pt = args.size(); args.push_back(VarInfo(0));
223b71206888 Initial import
thib
parents:
diff changeset
993 int count = GetArgs(d);
223b71206888 Initial import
thib
parents:
diff changeset
994 args[pt] = VarInfo(count);
223b71206888 Initial import
thib
parents:
diff changeset
995 dprintf(">");
223b71206888 Initial import
thib
parents:
diff changeset
996 } else if (*d == 0x24 || (*d == 0x5c && (d[1] == 1 || d[1] == 0))) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
997 /* cmd 01-15:0028 ; 始めに 0x24 節があり、続いて 0x28 節になる */
0
223b71206888 Initial import
thib
parents:
diff changeset
998 VarInfo var;
223b71206888 Initial import
thib
parents:
diff changeset
999 GetExpression(d, &var);
223b71206888 Initial import
thib
parents:
diff changeset
1000 args.push_back(var);
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1001 i--; // この引数はargc の数には入らない
0
223b71206888 Initial import
thib
parents:
diff changeset
1002 } else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1003 if (d[0] == 0x0a || d[0] == 0x40) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1004 /* cmd 01-15:0028 ; 0x28 節の後に毎回 0x0a 節が来る */
0
223b71206888 Initial import
thib
parents:
diff changeset
1005 int var;
223b71206888 Initial import
thib
parents:
diff changeset
1006 if (system_version == 0) { var = read_little_endian_int(d+1); d += 5;}
223b71206888 Initial import
thib
parents:
diff changeset
1007 else { var = read_little_endian_short(d+1); d += 3;}
223b71206888 Initial import
thib
parents:
diff changeset
1008 dprintf("line %d; ",var);
223b71206888 Initial import
thib
parents:
diff changeset
1009 }
223b71206888 Initial import
thib
parents:
diff changeset
1010 if (*d == 0x29) break;
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1011 if (*d == 0x2c) {d++;} // 次の arg が演算子で始まる、などがなければ存在しない
0
223b71206888 Initial import
thib
parents:
diff changeset
1012 dprintf(",");
223b71206888 Initial import
thib
parents:
diff changeset
1013 }
223b71206888 Initial import
thib
parents:
diff changeset
1014 if (*d == 0x29) d++;
223b71206888 Initial import
thib
parents:
diff changeset
1015 else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1016 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
1017 }
223b71206888 Initial import
thib
parents:
diff changeset
1018
223b71206888 Initial import
thib
parents:
diff changeset
1019 /* switch
223b71206888 Initial import
thib
parents:
diff changeset
1020 <exp>
223b71206888 Initial import
thib
parents:
diff changeset
1021 0x7b
223b71206888 Initial import
thib
parents:
diff changeset
1022 <exp> <int>
223b71206888 Initial import
thib
parents:
diff changeset
1023 ...
223b71206888 Initial import
thib
parents:
diff changeset
1024 0x7d
223b71206888 Initial import
thib
parents:
diff changeset
1025 */
223b71206888 Initial import
thib
parents:
diff changeset
1026
223b71206888 Initial import
thib
parents:
diff changeset
1027 int Cmd::GetSwitch(const char*& d) {
223b71206888 Initial import
thib
parents:
diff changeset
1028 if (*d != 0x28) {SetError(); return -1;}
223b71206888 Initial import
thib
parents:
diff changeset
1029 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1030 dprintf("switch. ");
223b71206888 Initial import
thib
parents:
diff changeset
1031 int var = GetExpression(d);
223b71206888 Initial import
thib
parents:
diff changeset
1032 if (*d != 0x29) {SetError(); return -1;}
223b71206888 Initial import
thib
parents:
diff changeset
1033 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1034 dprintf("->\n");
223b71206888 Initial import
thib
parents:
diff changeset
1035 if (*d == 0x7b) {
223b71206888 Initial import
thib
parents:
diff changeset
1036 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1037 } else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1038
223b71206888 Initial import
thib
parents:
diff changeset
1039 int default_jmp = -1; int jmpto = -1;
223b71206888 Initial import
thib
parents:
diff changeset
1040 int i; for (i=0; i<argc; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1041 dprintf("\t");
223b71206888 Initial import
thib
parents:
diff changeset
1042 if (*d++ != 0x28) {SetError(); return -1;}
223b71206888 Initial import
thib
parents:
diff changeset
1043 if (*d != 0x29) {
223b71206888 Initial import
thib
parents:
diff changeset
1044 int item = GetExpression(d);
223b71206888 Initial import
thib
parents:
diff changeset
1045 if (*d++ != 0x29) {SetError(); return -1;}
223b71206888 Initial import
thib
parents:
diff changeset
1046 int jmp = read_little_endian_int(d);
223b71206888 Initial import
thib
parents:
diff changeset
1047 if (var == item) {
223b71206888 Initial import
thib
parents:
diff changeset
1048 dprintf("(selected)");
223b71206888 Initial import
thib
parents:
diff changeset
1049 jmpto = jmp;
223b71206888 Initial import
thib
parents:
diff changeset
1050 }
223b71206888 Initial import
thib
parents:
diff changeset
1051 dprintf(" -> %d\n", jmp);
223b71206888 Initial import
thib
parents:
diff changeset
1052 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1053 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1054 default_jmp = read_little_endian_int(d);
223b71206888 Initial import
thib
parents:
diff changeset
1055 }
223b71206888 Initial import
thib
parents:
diff changeset
1056 d += 4;
223b71206888 Initial import
thib
parents:
diff changeset
1057 }
223b71206888 Initial import
thib
parents:
diff changeset
1058 if (default_jmp != -1) {
223b71206888 Initial import
thib
parents:
diff changeset
1059 dprintf("default -> %d\n",default_jmp);
223b71206888 Initial import
thib
parents:
diff changeset
1060 if (jmpto == -1) jmpto = default_jmp;
223b71206888 Initial import
thib
parents:
diff changeset
1061 }
223b71206888 Initial import
thib
parents:
diff changeset
1062 if (*d == 0x7d) {
223b71206888 Initial import
thib
parents:
diff changeset
1063 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1064 } else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1065 return jmpto;
223b71206888 Initial import
thib
parents:
diff changeset
1066 }
223b71206888 Initial import
thib
parents:
diff changeset
1067 /* simple switch
223b71206888 Initial import
thib
parents:
diff changeset
1068 <exp>
223b71206888 Initial import
thib
parents:
diff changeset
1069 0x7b
223b71206888 Initial import
thib
parents:
diff changeset
1070 <int>
223b71206888 Initial import
thib
parents:
diff changeset
1071 ...
223b71206888 Initial import
thib
parents:
diff changeset
1072 0x7d
223b71206888 Initial import
thib
parents:
diff changeset
1073 */
223b71206888 Initial import
thib
parents:
diff changeset
1074 int Cmd::GetSimpleSwitch(const char*& d) {
223b71206888 Initial import
thib
parents:
diff changeset
1075 if (*d != 0x28) {SetError(); return -1;}
223b71206888 Initial import
thib
parents:
diff changeset
1076 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1077 dprintf("simple switch. ");
223b71206888 Initial import
thib
parents:
diff changeset
1078 int var = GetExpression(d);
223b71206888 Initial import
thib
parents:
diff changeset
1079 if (*d != 0x29) {SetError(); return -1;}
223b71206888 Initial import
thib
parents:
diff changeset
1080 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1081 dprintf(" ->\n");
223b71206888 Initial import
thib
parents:
diff changeset
1082 int jumpto = -1;
223b71206888 Initial import
thib
parents:
diff changeset
1083 if (*d == 0x7b) {
223b71206888 Initial import
thib
parents:
diff changeset
1084 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1085 } else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1086 int i; for (i=0; i<argc; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1087 int j = read_little_endian_int(d);
223b71206888 Initial import
thib
parents:
diff changeset
1088 d += 4;
223b71206888 Initial import
thib
parents:
diff changeset
1089 dprintf("\t%d -> %d\n", i+1, j);
223b71206888 Initial import
thib
parents:
diff changeset
1090 if (var == i) jumpto = j;
223b71206888 Initial import
thib
parents:
diff changeset
1091 }
223b71206888 Initial import
thib
parents:
diff changeset
1092 if (*d == 0x7d) {
223b71206888 Initial import
thib
parents:
diff changeset
1093 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1094 } else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1095 return jumpto;
223b71206888 Initial import
thib
parents:
diff changeset
1096 }
223b71206888 Initial import
thib
parents:
diff changeset
1097
223b71206888 Initial import
thib
parents:
diff changeset
1098 /*
223b71206888 Initial import
thib
parents:
diff changeset
1099 selection
223b71206888 Initial import
thib
parents:
diff changeset
1100 ? <exp>
223b71206888 Initial import
thib
parents:
diff changeset
1101 0x7b
223b71206888 Initial import
thib
parents:
diff changeset
1102 <0x0a|0x40> <ushort | uint>
223b71206888 Initial import
thib
parents:
diff changeset
1103 */
223b71206888 Initial import
thib
parents:
diff changeset
1104 void Cmd::GetSelection(const char*& d) {
223b71206888 Initial import
thib
parents:
diff changeset
1105 dprintf("selection. ");
223b71206888 Initial import
thib
parents:
diff changeset
1106 if (*d == 0x28) {
223b71206888 Initial import
thib
parents:
diff changeset
1107 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1108 GetExpression(d);
223b71206888 Initial import
thib
parents:
diff changeset
1109 if (*d != 0x29) { SetError(); return;}
223b71206888 Initial import
thib
parents:
diff changeset
1110 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1111 }
223b71206888 Initial import
thib
parents:
diff changeset
1112 if (*d == 0x7b) {
223b71206888 Initial import
thib
parents:
diff changeset
1113 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1114 dprintf("{\n\t");
223b71206888 Initial import
thib
parents:
diff changeset
1115 } else SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1116 int arg_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1117 string text = "";
223b71206888 Initial import
thib
parents:
diff changeset
1118 int cond_result = false;
223b71206888 Initial import
thib
parents:
diff changeset
1119 int sel_no = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1120 while(*d != 0x7d) {
223b71206888 Initial import
thib
parents:
diff changeset
1121 if (d[0] == 0x0a || d[0] == 0x40) {
223b71206888 Initial import
thib
parents:
diff changeset
1122 int var;
223b71206888 Initial import
thib
parents:
diff changeset
1123 if (system_version == 0) { var = read_little_endian_int(d+1); d += 5;}
223b71206888 Initial import
thib
parents:
diff changeset
1124 else { var = read_little_endian_short(d+1); d += 3;}
223b71206888 Initial import
thib
parents:
diff changeset
1125 dprintf("Line %d; ",var);
223b71206888 Initial import
thib
parents:
diff changeset
1126 if (text.length() != 0) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1127 if (cond_result) ; // 条件節が true なら表示しない
0
223b71206888 Initial import
thib
parents:
diff changeset
1128 else {
223b71206888 Initial import
thib
parents:
diff changeset
1129 const char* str = text.c_str();
223b71206888 Initial import
thib
parents:
diff changeset
1130 VarInfo var;
223b71206888 Initial import
thib
parents:
diff changeset
1131 var.type = TYPE_STR;
223b71206888 Initial import
thib
parents:
diff changeset
1132 var.value = CopyString(str);
223b71206888 Initial import
thib
parents:
diff changeset
1133 args.push_back(var);
223b71206888 Initial import
thib
parents:
diff changeset
1134 var.type = TYPE_VAL;
223b71206888 Initial import
thib
parents:
diff changeset
1135 var.value = sel_no;
223b71206888 Initial import
thib
parents:
diff changeset
1136 args.push_back(var);
223b71206888 Initial import
thib
parents:
diff changeset
1137 }
223b71206888 Initial import
thib
parents:
diff changeset
1138 sel_no++;
223b71206888 Initial import
thib
parents:
diff changeset
1139 }
223b71206888 Initial import
thib
parents:
diff changeset
1140 text = "";
223b71206888 Initial import
thib
parents:
diff changeset
1141 cond_result = false;
223b71206888 Initial import
thib
parents:
diff changeset
1142 } else if (d[0] == 0x2c) {
223b71206888 Initial import
thib
parents:
diff changeset
1143 dprintf(":comma:");
223b71206888 Initial import
thib
parents:
diff changeset
1144 } else if (d[0] == 0x28) {
223b71206888 Initial import
thib
parents:
diff changeset
1145 dprintf(":cond:");
223b71206888 Initial import
thib
parents:
diff changeset
1146 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1147 while(d[0] != 0x29) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1148 int result = GetExpressionCond(d); // PRINT- 節でないばあい、条件表示。次は文字節、またはPRINT節のはず
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1149 if (*d == 0x32) { // 0x32 なら、現在の条件節を表示しない
0
223b71206888 Initial import
thib
parents:
diff changeset
1150 d++; dprintf("##");
223b71206888 Initial import
thib
parents:
diff changeset
1151 cond_result = result;
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1152 } else if (*d == 0x31) { // 0x31 なら、現在の条件節を表示する
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1153 // Little Busters! : この条件で正しいかは未検証
0
223b71206888 Initial import
thib
parents:
diff changeset
1154 d++; dprintf("***");
223b71206888 Initial import
thib
parents:
diff changeset
1155 cond_result = !result;
223b71206888 Initial import
thib
parents:
diff changeset
1156 }
223b71206888 Initial import
thib
parents:
diff changeset
1157 dprintf(":");
223b71206888 Initial import
thib
parents:
diff changeset
1158 }
223b71206888 Initial import
thib
parents:
diff changeset
1159 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1160 } else if (StrType(d)) {
223b71206888 Initial import
thib
parents:
diff changeset
1161 int strpt = GetString(d);
223b71206888 Initial import
thib
parents:
diff changeset
1162 text += strheap + strpt;
223b71206888 Initial import
thib
parents:
diff changeset
1163 arg_count++;
223b71206888 Initial import
thib
parents:
diff changeset
1164 dprintf("\n\t");
223b71206888 Initial import
thib
parents:
diff changeset
1165 } else if (*d == 0x23 && strncmp(d,"###PRINT",8) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1166 d += 8;
223b71206888 Initial import
thib
parents:
diff changeset
1167 if (d[0] != 0x28) SetError();
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1168 else { // 文字変数の内容の表示
0
223b71206888 Initial import
thib
parents:
diff changeset
1169 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1170 dprintf("Print.");
223b71206888 Initial import
thib
parents:
diff changeset
1171 VarInfo info;
223b71206888 Initial import
thib
parents:
diff changeset
1172 GetLeftToken(d, info);
223b71206888 Initial import
thib
parents:
diff changeset
1173 if (d[0] != 0x29 || info.type == -1) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1174 d++;
21
d1bb7b365816 Fixed dynamic strings in selections (Fuko Pranks for instance)
thib
parents: 13
diff changeset
1175 dprintf(";");/*
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1176 // 数値を全角文字に変換して登録
0
223b71206888 Initial import
thib
parents:
diff changeset
1177 char str[10], str2[20]; // itoa
223b71206888 Initial import
thib
parents:
diff changeset
1178 sprintf(str, "%d", info.value);
223b71206888 Initial import
thib
parents:
diff changeset
1179 int i; for (i=0; str[i] != 0; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1180 str2[i*2] = 0xa3;
223b71206888 Initial import
thib
parents:
diff changeset
1181 str2[i*2+1] = 0xb0 + str[i]-'0';
223b71206888 Initial import
thib
parents:
diff changeset
1182 }
21
d1bb7b365816 Fixed dynamic strings in selections (Fuko Pranks for instance)
thib
parents: 13
diff changeset
1183 str2[i*2] = 0;*/
d1bb7b365816 Fixed dynamic strings in selections (Fuko Pranks for instance)
thib
parents: 13
diff changeset
1184 text += strheap + info.value;
0
223b71206888 Initial import
thib
parents:
diff changeset
1185 }
223b71206888 Initial import
thib
parents:
diff changeset
1186 } else { SetError(); break;}
223b71206888 Initial import
thib
parents:
diff changeset
1187 }
223b71206888 Initial import
thib
parents:
diff changeset
1188 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1189 /* @@@ */
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1190 /* 一致しない場合があるのでコメントアウト */
0
223b71206888 Initial import
thib
parents:
diff changeset
1191 // if (arg_count != argc) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1192 dprintf("\n}\n");
223b71206888 Initial import
thib
parents:
diff changeset
1193 }
223b71206888 Initial import
thib
parents:
diff changeset
1194
223b71206888 Initial import
thib
parents:
diff changeset
1195 void Cmd::GetCmd(Flags& flags_orig, const char*& d ) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1196 if (d == NULL) { SetError(); return;}
0
223b71206888 Initial import
thib
parents:
diff changeset
1197 if (cmd_type != CMD_NOP) return;
223b71206888 Initial import
thib
parents:
diff changeset
1198
223b71206888 Initial import
thib
parents:
diff changeset
1199 cmdstr[0] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1200 rawdata = d;
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1201 if (*d == 0x23) { /* コマンド */
0
223b71206888 Initial import
thib
parents:
diff changeset
1202 cmd_type = CMD_OTHER;
223b71206888 Initial import
thib
parents:
diff changeset
1203 cmd1 = *(unsigned const char*)(d+1);
223b71206888 Initial import
thib
parents:
diff changeset
1204 cmd2 = *(unsigned const char*)(d+2);
223b71206888 Initial import
thib
parents:
diff changeset
1205 cmd3 = read_little_endian_short(d+3);
223b71206888 Initial import
thib
parents:
diff changeset
1206 argc = read_little_endian_short(d+5);
223b71206888 Initial import
thib
parents:
diff changeset
1207 cmd4 = *(unsigned const char*)(d+7);
223b71206888 Initial import
thib
parents:
diff changeset
1208 d += 8;
223b71206888 Initial import
thib
parents:
diff changeset
1209 /* verbose */
223b71206888 Initial import
thib
parents:
diff changeset
1210 // dprintf(" 0x23 - cmd %02x-%02x:%04x:%02x[%2d] \n",cmd1,cmd2,cmd3,cmd4,argc);
29
d229cce98f50 * no more (or, at least, less) duplicate code between scn2kdump and the rest
thib
parents: 21
diff changeset
1211 sprintf(cmdstr, "%02x-%02x:%04x:%02x : %s",cmd1,cmd2,cmd3,cmd4, CmdDescr(cmd1,cmd2,cmd3,cmd4));
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1212 /* 引数を得る */
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1213 /* 特殊引数のもの */
0
223b71206888 Initial import
thib
parents:
diff changeset
1214 int is_special = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1215 if (cmd1 == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1216 if (cmd2 == 1) {
223b71206888 Initial import
thib
parents:
diff changeset
1217 int jump_arg = -1;
223b71206888 Initial import
thib
parents:
diff changeset
1218 if (cmd3 == 0 || cmd3 == 5) {
223b71206888 Initial import
thib
parents:
diff changeset
1219 /* gosub / goto */
223b71206888 Initial import
thib
parents:
diff changeset
1220 jump_arg =read_little_endian_int(d);
223b71206888 Initial import
thib
parents:
diff changeset
1221 d += 4;
223b71206888 Initial import
thib
parents:
diff changeset
1222 if (cmd3 == 0)
223b71206888 Initial import
thib
parents:
diff changeset
1223 dprintf("\tjmp -> %d\n", jump_arg);
223b71206888 Initial import
thib
parents:
diff changeset
1224 else /* cmd3 == 5 */
223b71206888 Initial import
thib
parents:
diff changeset
1225 dprintf("\tcall -> %d\n", jump_arg);
223b71206888 Initial import
thib
parents:
diff changeset
1226 is_special = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1227 } else if (cmd3 == 1 || cmd3 == 2) {
223b71206888 Initial import
thib
parents:
diff changeset
1228 /* conditional jump (if / unless) */
223b71206888 Initial import
thib
parents:
diff changeset
1229 if (*d++ != 0x28) { SetError(); return;}
223b71206888 Initial import
thib
parents:
diff changeset
1230 dprintf("\t");
223b71206888 Initial import
thib
parents:
diff changeset
1231 int cond = GetExpressionCond(d);
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1232 if (cmd3 == 1) cond = !cond; // 逆になる
0
223b71206888 Initial import
thib
parents:
diff changeset
1233 if (*d++ != 0x29) { SetError(); return; }
223b71206888 Initial import
thib
parents:
diff changeset
1234 int jumpto = read_little_endian_int(d);
223b71206888 Initial import
thib
parents:
diff changeset
1235 d += 4;
223b71206888 Initial import
thib
parents:
diff changeset
1236 dprintf("-> %d\n", jumpto);
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1237 if (! cond) jump_arg = jumpto; /* condition が満たされない場合、ジャンプ */
0
223b71206888 Initial import
thib
parents:
diff changeset
1238 is_special = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1239 } else if (cmd3 == 4) {
223b71206888 Initial import
thib
parents:
diff changeset
1240 /* switch to */
223b71206888 Initial import
thib
parents:
diff changeset
1241 jump_arg = GetSwitch(d);
223b71206888 Initial import
thib
parents:
diff changeset
1242 is_special = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1243 } else if (cmd3 == 8 || cmd3 == 3) {
223b71206888 Initial import
thib
parents:
diff changeset
1244 /* switch to */
223b71206888 Initial import
thib
parents:
diff changeset
1245 jump_arg = GetSimpleSwitch(d);
223b71206888 Initial import
thib
parents:
diff changeset
1246 is_special = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1247 } else if (cmd3 == 16) { // call with parameters
223b71206888 Initial import
thib
parents:
diff changeset
1248 GetArgs(d);
223b71206888 Initial import
thib
parents:
diff changeset
1249 jump_arg = read_little_endian_int(d);
223b71206888 Initial import
thib
parents:
diff changeset
1250 d += 4;
223b71206888 Initial import
thib
parents:
diff changeset
1251 is_special = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1252 } else goto retry;
223b71206888 Initial import
thib
parents:
diff changeset
1253 if (jump_arg == -1) {
223b71206888 Initial import
thib
parents:
diff changeset
1254 cmd_type = CMD_NOP;
223b71206888 Initial import
thib
parents:
diff changeset
1255 }
223b71206888 Initial import
thib
parents:
diff changeset
1256 else {
223b71206888 Initial import
thib
parents:
diff changeset
1257 cmd_type = CMD_JMP;
223b71206888 Initial import
thib
parents:
diff changeset
1258 args.push_back(VarInfo(jump_arg));
223b71206888 Initial import
thib
parents:
diff changeset
1259 }
223b71206888 Initial import
thib
parents:
diff changeset
1260 } else if (cmd2 == 2 && (cmd3 == 0 || cmd3 == 1 || cmd3 == 2 || cmd3 == 3 || cmd3 == 0x0d) ) {
223b71206888 Initial import
thib
parents:
diff changeset
1261 /* selection */
223b71206888 Initial import
thib
parents:
diff changeset
1262 GetSelection(d);
223b71206888 Initial import
thib
parents:
diff changeset
1263 is_special = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1264 }
223b71206888 Initial import
thib
parents:
diff changeset
1265 }
223b71206888 Initial import
thib
parents:
diff changeset
1266 retry:
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1267 /* 一般引数のもの */
0
223b71206888 Initial import
thib
parents:
diff changeset
1268 if (!is_special) {
29
d229cce98f50 * no more (or, at least, less) duplicate code between scn2kdump and the rest
thib
parents: 21
diff changeset
1269 dprintf(" 0x23 - cmd %02x-%02x:%04x:%02x[%2d] : %s\n",cmd1,cmd2,cmd3,cmd4,argc,CmdDescr(cmd1,cmd2,cmd3,cmd4));
0
223b71206888 Initial import
thib
parents:
diff changeset
1270 dprintf("\t");
223b71206888 Initial import
thib
parents:
diff changeset
1271 if (cmd1 == 1 && cmd2 == 0x22 && (cmd3 == 0xc1c || cmd3 == 0x835)) GetArgsSpecial(3, d);
223b71206888 Initial import
thib
parents:
diff changeset
1272 else if (cmd1 == 1 && cmd2 == 0x0b && cmd3 == 0x65) GetArgsSpecial(0, d);
223b71206888 Initial import
thib
parents:
diff changeset
1273 else if (cmd1 == 1 && cmd2 == 0x15 && cmd3 == 0x28) GetArgsSpecial(0, d);
223b71206888 Initial import
thib
parents:
diff changeset
1274 else if (cmd1 == 1 && cmd2 == 4 && (cmd3 == 0x26c || cmd3 == 0x26d || cmd3 == 0x270 || cmd3 == 0x276)) GetArgsSpecial(0, d);
223b71206888 Initial import
thib
parents:
diff changeset
1275 else if (cmd1 == 1 && cmd2 == 4 && cmd3 == 0x586) GetArgsSpecial(1, d);
43
01aa5ddf7dc8 A lot of very minor improvements (deleted some unused variables, and other things like that...)
thib
parents: 29
diff changeset
1276 else if (cmd1 == 1 && ((cmd2 == 0x21 && cmd3 == 0x4b) || (cmd2 == 0x28 && cmd3 == 0x64))) GetArgsSpecial(2,d);
0
223b71206888 Initial import
thib
parents:
diff changeset
1277 else GetArgs(d);
223b71206888 Initial import
thib
parents:
diff changeset
1278 dprintf("\n");
223b71206888 Initial import
thib
parents:
diff changeset
1279
223b71206888 Initial import
thib
parents:
diff changeset
1280 }
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1281 } else if (*d == 0x24) { /* 代入演算 */
0
223b71206888 Initial import
thib
parents:
diff changeset
1282 if (d[1] == 0x12 || d[2] != 0x5b) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1283 dprintf("expr: ");
223b71206888 Initial import
thib
parents:
diff changeset
1284 sprintf(cmdstr, "expr");
223b71206888 Initial import
thib
parents:
diff changeset
1285
223b71206888 Initial import
thib
parents:
diff changeset
1286 VarInfo info;
223b71206888 Initial import
thib
parents:
diff changeset
1287 int value = GetLeftToken(d, info);
223b71206888 Initial import
thib
parents:
diff changeset
1288 if (d[0] != 0x5c) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1289 int type = d[1];
223b71206888 Initial import
thib
parents:
diff changeset
1290 if (type < 20 || type > 30) SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1291 else dprintf("%s",op_str[type]);
223b71206888 Initial import
thib
parents:
diff changeset
1292 d += 2;
223b71206888 Initial import
thib
parents:
diff changeset
1293 int value2 = GetExpression(d);
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1294 // 代入情報を埋め込む
0
223b71206888 Initial import
thib
parents:
diff changeset
1295 if (type != 30) value2 = eval(value, type-20, value2);
223b71206888 Initial import
thib
parents:
diff changeset
1296 cmd_type = CMD_FLAGS;
223b71206888 Initial import
thib
parents:
diff changeset
1297 args.push_back(info);
223b71206888 Initial import
thib
parents:
diff changeset
1298 args.push_back(value2);
223b71206888 Initial import
thib
parents:
diff changeset
1299 dprintf("\n");
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1300 } else if (StrType(d)) { /* 文字出力 */
0
223b71206888 Initial import
thib
parents:
diff changeset
1301 VarInfo info;
223b71206888 Initial import
thib
parents:
diff changeset
1302 info.type = TYPE_STR;
223b71206888 Initial import
thib
parents:
diff changeset
1303 info.value = GetString(d);
223b71206888 Initial import
thib
parents:
diff changeset
1304 args.push_back(info);
223b71206888 Initial import
thib
parents:
diff changeset
1305 cmd_type = CMD_TEXT;
223b71206888 Initial import
thib
parents:
diff changeset
1306 dprintf("\n");
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1307 } else if (*d == 0x0a || *d == 0x40 || *d == 0x21) { /* デバッグ用データと既読フラグ */
0
223b71206888 Initial import
thib
parents:
diff changeset
1308 cmd_type = CMD_NOP;
223b71206888 Initial import
thib
parents:
diff changeset
1309 if (*d == 0x0a) {
223b71206888 Initial import
thib
parents:
diff changeset
1310 dprintf("line ");
223b71206888 Initial import
thib
parents:
diff changeset
1311 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1312 int l;
223b71206888 Initial import
thib
parents:
diff changeset
1313 if (system_version == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1314 l = read_little_endian_int(d);
223b71206888 Initial import
thib
parents:
diff changeset
1315 d += 4;
223b71206888 Initial import
thib
parents:
diff changeset
1316 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1317 l = read_little_endian_short(d);
223b71206888 Initial import
thib
parents:
diff changeset
1318 d += 2;
223b71206888 Initial import
thib
parents:
diff changeset
1319 }
223b71206888 Initial import
thib
parents:
diff changeset
1320 dprintf("%d\n", l);
223b71206888 Initial import
thib
parents:
diff changeset
1321 } else { /* 0x40, 0x21 */
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1322 // 既読マーカーらしい。エントリーポイントとセーブポイントも使われる。
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1323 // RealLive 1.2.5から、0x40はセーブポイント、0x21はエントリーポイント。
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1324 // 1.2.5以前、どちらも0x40が使われる。
0
223b71206888 Initial import
thib
parents:
diff changeset
1325 int kidoku_index;
223b71206888 Initial import
thib
parents:
diff changeset
1326 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1327 if (system_version == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1328 kidoku_index = read_little_endian_int(d);
223b71206888 Initial import
thib
parents:
diff changeset
1329 d += 4;
223b71206888 Initial import
thib
parents:
diff changeset
1330 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1331 kidoku_index = read_little_endian_short(d);
223b71206888 Initial import
thib
parents:
diff changeset
1332 d += 2;
223b71206888 Initial import
thib
parents:
diff changeset
1333 }
223b71206888 Initial import
thib
parents:
diff changeset
1334 dprintf("kidoku marker %d\n", kidoku_index);
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1335 // text_readflagは、このkidoku_indexを使ったら良いかな。
0
223b71206888 Initial import
thib
parents:
diff changeset
1336 }
223b71206888 Initial import
thib
parents:
diff changeset
1337 } else if (*d == 0x2c) { /* ??? */
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1338 dprintf("commd;0x2c\n"); // conditional jump の行き先によくあるらしい(常に、かはわからない)
0
223b71206888 Initial import
thib
parents:
diff changeset
1339 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1340 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1341 SetError();
223b71206888 Initial import
thib
parents:
diff changeset
1342 }
223b71206888 Initial import
thib
parents:
diff changeset
1343 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1344
0
223b71206888 Initial import
thib
parents:
diff changeset
1345 void Cmd::clear(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1346 cmd_type = CMD_NOP;
223b71206888 Initial import
thib
parents:
diff changeset
1347 ResetString();
223b71206888 Initial import
thib
parents:
diff changeset
1348 args.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1349 errorflag = false;
223b71206888 Initial import
thib
parents:
diff changeset
1350 pos = -1;
223b71206888 Initial import
thib
parents:
diff changeset
1351 }
223b71206888 Initial import
thib
parents:
diff changeset
1352
223b71206888 Initial import
thib
parents:
diff changeset
1353 char Cmd::strtype[256] = {
223b71206888 Initial import
thib
parents:
diff changeset
1354 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* +00 */
223b71206888 Initial import
thib
parents:
diff changeset
1355 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* +10 */ // 0123456789ABCDEF
223b71206888 Initial import
thib
parents:
diff changeset
1356 1,0,3,0, 0,0,0,1, 0,0,0,0, 0,1,1,0, /* +20 */ // !"#$%&'()*+,-./
223b71206888 Initial import
thib
parents:
diff changeset
1357 1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,1, /* +30 */ // 0123456789:;<=>?
223b71206888 Initial import
thib
parents:
diff changeset
1358 0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, /* +40 */ // @ABCDEFGHIJKLMNO
223b71206888 Initial import
thib
parents:
diff changeset
1359 1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,1, /* +50 */ // PQRSTUVWXYZ[\]^_
223b71206888 Initial import
thib
parents:
diff changeset
1360 0,0,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, /* +60 */ // `abcdefghijklmno
223b71206888 Initial import
thib
parents:
diff changeset
1361 1,1,1,1, 1,1,1,1, 1,1,1,1, 0,0,0,0, /* +70 */ // pqrstuvwxyz{|}~
223b71206888 Initial import
thib
parents:
diff changeset
1362 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, /* +80 */
223b71206888 Initial import
thib
parents:
diff changeset
1363 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, /* +90 */
223b71206888 Initial import
thib
parents:
diff changeset
1364 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* +A0 */
223b71206888 Initial import
thib
parents:
diff changeset
1365 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* +B0 */
223b71206888 Initial import
thib
parents:
diff changeset
1366 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* +C0 */
223b71206888 Initial import
thib
parents:
diff changeset
1367 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* +D0 */
223b71206888 Initial import
thib
parents:
diff changeset
1368 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,2,2, /* +E0 */
223b71206888 Initial import
thib
parents:
diff changeset
1369 2,2,2,2, 2,2,2,2, 2,2,2,2, 2,2,0,0 /* +F0 */
223b71206888 Initial import
thib
parents:
diff changeset
1370 };
223b71206888 Initial import
thib
parents:
diff changeset
1371
223b71206888 Initial import
thib
parents:
diff changeset
1372 int Cmd::GetString(const char*& d) {
223b71206888 Initial import
thib
parents:
diff changeset
1373 int retnum = -1;
223b71206888 Initial import
thib
parents:
diff changeset
1374 bool quote_flag = false;
223b71206888 Initial import
thib
parents:
diff changeset
1375 int stype;
223b71206888 Initial import
thib
parents:
diff changeset
1376 retnum = strend;
223b71206888 Initial import
thib
parents:
diff changeset
1377 while(1) {
223b71206888 Initial import
thib
parents:
diff changeset
1378 if (*d == '\\') {
223b71206888 Initial import
thib
parents:
diff changeset
1379 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1380 strheap[strend++] = *d++;
223b71206888 Initial import
thib
parents:
diff changeset
1381 } else if (*d == '"') {
223b71206888 Initial import
thib
parents:
diff changeset
1382 if (quote_flag) quote_flag = false;
223b71206888 Initial import
thib
parents:
diff changeset
1383 else quote_flag = true;
223b71206888 Initial import
thib
parents:
diff changeset
1384 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1385 } else if (quote_flag) {
223b71206888 Initial import
thib
parents:
diff changeset
1386 strheap[strend++] = *d++;
43
01aa5ddf7dc8 A lot of very minor improvements (deleted some unused variables, and other things like that...)
thib
parents: 29
diff changeset
1387 } else if ((stype = StrType(d))) {
0
223b71206888 Initial import
thib
parents:
diff changeset
1388 strheap[strend++] = *d++;
223b71206888 Initial import
thib
parents:
diff changeset
1389 if (stype == 2) strheap[strend++] = *d++;
223b71206888 Initial import
thib
parents:
diff changeset
1390 } else break;
223b71206888 Initial import
thib
parents:
diff changeset
1391 }
223b71206888 Initial import
thib
parents:
diff changeset
1392 strheap[strend++] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1393 dprintf("\"%s\"", strheap + retnum);
223b71206888 Initial import
thib
parents:
diff changeset
1394 if (strend >= STRHEAP_SIZE) {
223b71206888 Initial import
thib
parents:
diff changeset
1395 dprintf("Error: string heap overflow\n");
223b71206888 Initial import
thib
parents:
diff changeset
1396 }
223b71206888 Initial import
thib
parents:
diff changeset
1397 return retnum;
223b71206888 Initial import
thib
parents:
diff changeset
1398 }
223b71206888 Initial import
thib
parents:
diff changeset
1399
223b71206888 Initial import
thib
parents:
diff changeset
1400 int Cmd::CopyString(const char* d) {
223b71206888 Initial import
thib
parents:
diff changeset
1401 int retnum = strend;
223b71206888 Initial import
thib
parents:
diff changeset
1402 int len = strlen(d);
223b71206888 Initial import
thib
parents:
diff changeset
1403 memcpy(strheap+strend, d, len+1);
223b71206888 Initial import
thib
parents:
diff changeset
1404 strend += len+1;
223b71206888 Initial import
thib
parents:
diff changeset
1405 d += len+1;
223b71206888 Initial import
thib
parents:
diff changeset
1406 return retnum;
223b71206888 Initial import
thib
parents:
diff changeset
1407 }
223b71206888 Initial import
thib
parents:
diff changeset
1408
223b71206888 Initial import
thib
parents:
diff changeset
1409 int Cmd::StrVar(int type, int var_num) {
223b71206888 Initial import
thib
parents:
diff changeset
1410 int retnum = strend;
223b71206888 Initial import
thib
parents:
diff changeset
1411 flags.Str(type, var_num, strheap+strend, STRHEAP_SIZE-strend);
223b71206888 Initial import
thib
parents:
diff changeset
1412 strend += strlen(strheap+strend)+1;
223b71206888 Initial import
thib
parents:
diff changeset
1413 return retnum;
223b71206888 Initial import
thib
parents:
diff changeset
1414 }
223b71206888 Initial import
thib
parents:
diff changeset
1415
223b71206888 Initial import
thib
parents:
diff changeset
1416 void Cmd::SetSysvar(int n, int val) {
223b71206888 Initial import
thib
parents:
diff changeset
1417 VarInfo info;
223b71206888 Initial import
thib
parents:
diff changeset
1418 if (cmd_type != CMD_SYSVAR) {
223b71206888 Initial import
thib
parents:
diff changeset
1419 args.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1420 }
223b71206888 Initial import
thib
parents:
diff changeset
1421 cmd_type = CMD_SYSVAR;
223b71206888 Initial import
thib
parents:
diff changeset
1422
223b71206888 Initial import
thib
parents:
diff changeset
1423 info.type = TYPE_SYS;
223b71206888 Initial import
thib
parents:
diff changeset
1424 info.number = n;
223b71206888 Initial import
thib
parents:
diff changeset
1425 info.value = val;
223b71206888 Initial import
thib
parents:
diff changeset
1426 args.push_back(info);
223b71206888 Initial import
thib
parents:
diff changeset
1427 }
223b71206888 Initial import
thib
parents:
diff changeset
1428 void Cmd::SetFlagvar(VarInfo info, int val) {
223b71206888 Initial import
thib
parents:
diff changeset
1429 if (cmd_type != CMD_SYSVAR) {
223b71206888 Initial import
thib
parents:
diff changeset
1430 args.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1431 }
223b71206888 Initial import
thib
parents:
diff changeset
1432 cmd_type = CMD_SYSVAR;
223b71206888 Initial import
thib
parents:
diff changeset
1433
223b71206888 Initial import
thib
parents:
diff changeset
1434 info.value = val;
223b71206888 Initial import
thib
parents:
diff changeset
1435 args.push_back(info);
223b71206888 Initial import
thib
parents:
diff changeset
1436 }
223b71206888 Initial import
thib
parents:
diff changeset
1437
223b71206888 Initial import
thib
parents:
diff changeset
1438 void Cmd::SetStrvar(VarInfo info, const string& s) {
223b71206888 Initial import
thib
parents:
diff changeset
1439 if (cmd_type != CMD_SYSVAR) {
223b71206888 Initial import
thib
parents:
diff changeset
1440 args.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1441 }
223b71206888 Initial import
thib
parents:
diff changeset
1442
223b71206888 Initial import
thib
parents:
diff changeset
1443 cmd_type = CMD_SYSVAR;
223b71206888 Initial import
thib
parents:
diff changeset
1444 const char* ss = s.c_str();
223b71206888 Initial import
thib
parents:
diff changeset
1445 info.value = CopyString(ss);
223b71206888 Initial import
thib
parents:
diff changeset
1446 args.push_back(info);
223b71206888 Initial import
thib
parents:
diff changeset
1447 }
223b71206888 Initial import
thib
parents:
diff changeset
1448
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1449
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1450 const char* Cmd::Str(const VarInfo& info) const {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1451 if (info.type != TYPE_STR && info.type != TYPE_VARSTR && info.type != TYPE_VARLOCSTR && info.type != TYPE_VARSYSSTR)
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1452 return "";
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1453 int pt = info.value;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1454 if (pt < 0 || pt >= STRHEAP_SIZE) return "";
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1455 return strheap + pt;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1456 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1457
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1458 int Cmd::AddStr(char* s) {
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1459 // 1-0a-0064 はこういうものが必要らしい
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1460 int start = strend;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1461 while (*s) strheap[strend++] = *s++;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1462 strheap[strend++] = 0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1463 return start;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1464 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1465
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1466
0
223b71206888 Initial import
thib
parents:
diff changeset
1467 void Cmd::read(const CmdSimplified& from) {
223b71206888 Initial import
thib
parents:
diff changeset
1468 errorflag = false;
223b71206888 Initial import
thib
parents:
diff changeset
1469 ResetString();
223b71206888 Initial import
thib
parents:
diff changeset
1470
223b71206888 Initial import
thib
parents:
diff changeset
1471 cmd_type = Cmdtype(from.type);
223b71206888 Initial import
thib
parents:
diff changeset
1472 cmd1 = from.cmd1;
223b71206888 Initial import
thib
parents:
diff changeset
1473 cmd2 = from.cmd2;
223b71206888 Initial import
thib
parents:
diff changeset
1474 cmd3 = from.cmd3;
223b71206888 Initial import
thib
parents:
diff changeset
1475 cmd4 = from.cmd4;
223b71206888 Initial import
thib
parents:
diff changeset
1476 argc = from.argc;
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1477 /* args の読み込み */
0
223b71206888 Initial import
thib
parents:
diff changeset
1478 args.clear();
223b71206888 Initial import
thib
parents:
diff changeset
1479 char* d = from.args;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1480 if (d == NULL) return;
0
223b71206888 Initial import
thib
parents:
diff changeset
1481 while(*d != TYPE_END) {
223b71206888 Initial import
thib
parents:
diff changeset
1482 VarInfo info;
223b71206888 Initial import
thib
parents:
diff changeset
1483 switch(*d) {
223b71206888 Initial import
thib
parents:
diff changeset
1484 case TYPE_VAL:
223b71206888 Initial import
thib
parents:
diff changeset
1485 info.type = TYPE_VAL;
223b71206888 Initial import
thib
parents:
diff changeset
1486 info.number = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1487 info.value = read_little_endian_int(d+1);
223b71206888 Initial import
thib
parents:
diff changeset
1488 d += 5;
223b71206888 Initial import
thib
parents:
diff changeset
1489 args.push_back(info);
223b71206888 Initial import
thib
parents:
diff changeset
1490 break;
223b71206888 Initial import
thib
parents:
diff changeset
1491 case TYPE_STR:
223b71206888 Initial import
thib
parents:
diff changeset
1492 info.type = TYPE_STR;
223b71206888 Initial import
thib
parents:
diff changeset
1493 info.number = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1494 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1495 info.value = CopyString( d);
223b71206888 Initial import
thib
parents:
diff changeset
1496 d += strlen(d)+1;
223b71206888 Initial import
thib
parents:
diff changeset
1497 args.push_back(info);
223b71206888 Initial import
thib
parents:
diff changeset
1498 break;
223b71206888 Initial import
thib
parents:
diff changeset
1499 default:
223b71206888 Initial import
thib
parents:
diff changeset
1500 fprintf(stderr,"Cmd::read: Invalid Load Data\n");
223b71206888 Initial import
thib
parents:
diff changeset
1501 *d = TYPE_END;
223b71206888 Initial import
thib
parents:
diff changeset
1502 }
223b71206888 Initial import
thib
parents:
diff changeset
1503 }
223b71206888 Initial import
thib
parents:
diff changeset
1504 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1505
0
223b71206888 Initial import
thib
parents:
diff changeset
1506 void Cmd::write(CmdSimplified& to, char*& buffer) const {
223b71206888 Initial import
thib
parents:
diff changeset
1507 /*
223b71206888 Initial import
thib
parents:
diff changeset
1508 if (cmd_type != CMD_OTHER) {
223b71206888 Initial import
thib
parents:
diff changeset
1509 fprintf(stderr,"Cmd::write: Invalid Cmd during Saving Data\n");
223b71206888 Initial import
thib
parents:
diff changeset
1510 to.cmd1 = 0; to.cmd2 = 0; to.cmd3 = 0; to.cmd4 = 0; to.argc = 0; to.args = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1511 return;
223b71206888 Initial import
thib
parents:
diff changeset
1512 }
223b71206888 Initial import
thib
parents:
diff changeset
1513 */
223b71206888 Initial import
thib
parents:
diff changeset
1514 to.type = cmd_type;
223b71206888 Initial import
thib
parents:
diff changeset
1515 to.cmd1 = cmd1;
223b71206888 Initial import
thib
parents:
diff changeset
1516 to.cmd2 = cmd2;
223b71206888 Initial import
thib
parents:
diff changeset
1517 to.cmd3 = cmd3;
223b71206888 Initial import
thib
parents:
diff changeset
1518 to.cmd4 = cmd4;
223b71206888 Initial import
thib
parents:
diff changeset
1519 to.argc = argc;
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1520 /* args の書き込み */
0
223b71206888 Initial import
thib
parents:
diff changeset
1521 if (args.empty()) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1522 to.args = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
1523 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1524 to.args = buffer;
223b71206888 Initial import
thib
parents:
diff changeset
1525 char* d = to.args;
223b71206888 Initial import
thib
parents:
diff changeset
1526 vector<VarInfo>::const_iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1527 for (it = args.begin(); it != args.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
1528 int type = it->type;
223b71206888 Initial import
thib
parents:
diff changeset
1529 if ( (type >= 0 && type < 7) || type == TYPE_VAL || type == char(TYPE_SYS)) { // digits
223b71206888 Initial import
thib
parents:
diff changeset
1530 *d++ = TYPE_VAL;
223b71206888 Initial import
thib
parents:
diff changeset
1531 write_little_endian_int(d, it->value);
223b71206888 Initial import
thib
parents:
diff changeset
1532 d += 4;
223b71206888 Initial import
thib
parents:
diff changeset
1533 } else if (type == TYPE_VARSTR || type == TYPE_VARSYSSTR || type == TYPE_VARLOCSTR || type == TYPE_STR) { // string
223b71206888 Initial import
thib
parents:
diff changeset
1534 *d++ = TYPE_STR;
223b71206888 Initial import
thib
parents:
diff changeset
1535 const char* s = Str(*it);
223b71206888 Initial import
thib
parents:
diff changeset
1536 int len = strlen(s);
223b71206888 Initial import
thib
parents:
diff changeset
1537 memcpy(d, s, len+1);
223b71206888 Initial import
thib
parents:
diff changeset
1538 d += len+1;
223b71206888 Initial import
thib
parents:
diff changeset
1539 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1540 fprintf(stderr,"Cmd::write: Invalid Cmd args during Saving Data\n");
223b71206888 Initial import
thib
parents:
diff changeset
1541 }
223b71206888 Initial import
thib
parents:
diff changeset
1542 }
223b71206888 Initial import
thib
parents:
diff changeset
1543 *d++ = TYPE_END;
223b71206888 Initial import
thib
parents:
diff changeset
1544 buffer = d;
223b71206888 Initial import
thib
parents:
diff changeset
1545 }
223b71206888 Initial import
thib
parents:
diff changeset
1546 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1547
0
223b71206888 Initial import
thib
parents:
diff changeset
1548 void CmdSimplified::copy(const CmdSimplified& from, char*& args_buffer) {
223b71206888 Initial import
thib
parents:
diff changeset
1549 *this = from;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1550 if (args == NULL) return;
0
223b71206888 Initial import
thib
parents:
diff changeset
1551 char* args_old = from.args;
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1552 /* args のコピー */
0
223b71206888 Initial import
thib
parents:
diff changeset
1553 while(*args_old != TYPE_END) {
223b71206888 Initial import
thib
parents:
diff changeset
1554 if (*args_old == TYPE_VAL) {
223b71206888 Initial import
thib
parents:
diff changeset
1555 args_old += 5;
223b71206888 Initial import
thib
parents:
diff changeset
1556 } else { /* TYPE_STR */
223b71206888 Initial import
thib
parents:
diff changeset
1557 args_old += strlen(args_old)+1;
223b71206888 Initial import
thib
parents:
diff changeset
1558 }
223b71206888 Initial import
thib
parents:
diff changeset
1559 }
223b71206888 Initial import
thib
parents:
diff changeset
1560 args_old++;
223b71206888 Initial import
thib
parents:
diff changeset
1561 int args_len = args_old - from.args;
223b71206888 Initial import
thib
parents:
diff changeset
1562 memmove(args_buffer, from.args, args_len);
223b71206888 Initial import
thib
parents:
diff changeset
1563 args = args_buffer;
223b71206888 Initial import
thib
parents:
diff changeset
1564 args_buffer += args_len;
223b71206888 Initial import
thib
parents:
diff changeset
1565 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1566
0
223b71206888 Initial import
thib
parents:
diff changeset
1567 void CmdSimplified::Save(string& saveret) {
223b71206888 Initial import
thib
parents:
diff changeset
1568 char buf[1024];
223b71206888 Initial import
thib
parents:
diff changeset
1569 sprintf(buf, "%02x-%02x:%04x:%02x(%02d),", cmd1, cmd2, cmd3, cmd4, argc);
223b71206888 Initial import
thib
parents:
diff changeset
1570 saveret += buf;
223b71206888 Initial import
thib
parents:
diff changeset
1571
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1572 /* args のコピー */
0
223b71206888 Initial import
thib
parents:
diff changeset
1573 char* d = args;
223b71206888 Initial import
thib
parents:
diff changeset
1574 while(d && *d != TYPE_END) {
223b71206888 Initial import
thib
parents:
diff changeset
1575 if (*d == TYPE_VAL) {
223b71206888 Initial import
thib
parents:
diff changeset
1576 d++;
223b71206888 Initial import
thib
parents:
diff changeset
1577 sprintf(buf, "%d,", read_little_endian_int(d));
223b71206888 Initial import
thib
parents:
diff changeset
1578 d += 4;
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1579 } else { /* TYPE_STR と仮定 */
0
223b71206888 Initial import
thib
parents:
diff changeset
1580 d++;
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1581 if (strlen(d) > 1000) d[1000] = 0; // ありえない・・・
0
223b71206888 Initial import
thib
parents:
diff changeset
1582 int i; int cnt = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1583 buf[cnt++] = '"';
223b71206888 Initial import
thib
parents:
diff changeset
1584 for (i=0; d[i] != 0; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1585 if (d[i] == '"') buf[cnt++] = '"';
223b71206888 Initial import
thib
parents:
diff changeset
1586 buf[cnt++] = d[i];
223b71206888 Initial import
thib
parents:
diff changeset
1587 }
223b71206888 Initial import
thib
parents:
diff changeset
1588 buf[cnt++]='"';
223b71206888 Initial import
thib
parents:
diff changeset
1589 buf[cnt++] = ',';
223b71206888 Initial import
thib
parents:
diff changeset
1590 buf[cnt++] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1591 d += strlen(d)+1;
223b71206888 Initial import
thib
parents:
diff changeset
1592 }
223b71206888 Initial import
thib
parents:
diff changeset
1593 saveret += buf;
223b71206888 Initial import
thib
parents:
diff changeset
1594 }
223b71206888 Initial import
thib
parents:
diff changeset
1595 saveret += 'E';
223b71206888 Initial import
thib
parents:
diff changeset
1596 }
223b71206888 Initial import
thib
parents:
diff changeset
1597
223b71206888 Initial import
thib
parents:
diff changeset
1598 void CmdSimplified::Load(const char* save, char*& args_buffer) {
223b71206888 Initial import
thib
parents:
diff changeset
1599 args = args_buffer;
223b71206888 Initial import
thib
parents:
diff changeset
1600
223b71206888 Initial import
thib
parents:
diff changeset
1601 type = CMD_OTHER;
223b71206888 Initial import
thib
parents:
diff changeset
1602 sscanf(save, "%02x-%02x:%04x:%02x(%02d),", &cmd1, &cmd2, &cmd3, &cmd4, &argc);
223b71206888 Initial import
thib
parents:
diff changeset
1603 save = strchr(save, ',');
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1604 if (save == NULL) {
0
223b71206888 Initial import
thib
parents:
diff changeset
1605 *args_buffer++ = TYPE_END;
223b71206888 Initial import
thib
parents:
diff changeset
1606 return;
223b71206888 Initial import
thib
parents:
diff changeset
1607 }
223b71206888 Initial import
thib
parents:
diff changeset
1608 save++;
223b71206888 Initial import
thib
parents:
diff changeset
1609 while(*save != 'E' && *save != '\n' && *save != '\0') {
223b71206888 Initial import
thib
parents:
diff changeset
1610 if (isdigit(*save)) {
223b71206888 Initial import
thib
parents:
diff changeset
1611 int v;
223b71206888 Initial import
thib
parents:
diff changeset
1612 sscanf(save,"%d,",&v);
223b71206888 Initial import
thib
parents:
diff changeset
1613 *args_buffer++ = TYPE_VAL;
223b71206888 Initial import
thib
parents:
diff changeset
1614 write_little_endian_int(args_buffer, v);
223b71206888 Initial import
thib
parents:
diff changeset
1615 args_buffer+= 4;
223b71206888 Initial import
thib
parents:
diff changeset
1616 save = strchr(save, ',');
223b71206888 Initial import
thib
parents:
diff changeset
1617 if (save) save++;
223b71206888 Initial import
thib
parents:
diff changeset
1618 } else { // *save == '"'
223b71206888 Initial import
thib
parents:
diff changeset
1619 save++;
223b71206888 Initial import
thib
parents:
diff changeset
1620 *args_buffer++ = TYPE_STR;
223b71206888 Initial import
thib
parents:
diff changeset
1621 while(1) {
223b71206888 Initial import
thib
parents:
diff changeset
1622 if (*save == 0) break;
223b71206888 Initial import
thib
parents:
diff changeset
1623 if (*save == '"') {
223b71206888 Initial import
thib
parents:
diff changeset
1624 if (save[1] != '"') break;
223b71206888 Initial import
thib
parents:
diff changeset
1625 save++;
223b71206888 Initial import
thib
parents:
diff changeset
1626 }
223b71206888 Initial import
thib
parents:
diff changeset
1627 *args_buffer++ = *save++;
223b71206888 Initial import
thib
parents:
diff changeset
1628 }
223b71206888 Initial import
thib
parents:
diff changeset
1629 save += 2;
223b71206888 Initial import
thib
parents:
diff changeset
1630 *args_buffer++ = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1631 }
223b71206888 Initial import
thib
parents:
diff changeset
1632 }
223b71206888 Initial import
thib
parents:
diff changeset
1633 *args_buffer++ = TYPE_END;
223b71206888 Initial import
thib
parents:
diff changeset
1634 }
223b71206888 Initial import
thib
parents:
diff changeset
1635
223b71206888 Initial import
thib
parents:
diff changeset
1636 #ifdef SCN_DUMP
223b71206888 Initial import
thib
parents:
diff changeset
1637 void usage(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1638 fprintf(stderr,"usage : scn2kdump [inputfile] [outputfile]\n");
223b71206888 Initial import
thib
parents:
diff changeset
1639 fprintf(stderr," inputfile: seen.txt(default)\n");
223b71206888 Initial import
thib
parents:
diff changeset
1640 fprintf(stderr," outputfile: seen.txt_out(default)\n");
223b71206888 Initial import
thib
parents:
diff changeset
1641 exit(-1);
223b71206888 Initial import
thib
parents:
diff changeset
1642 }
223b71206888 Initial import
thib
parents:
diff changeset
1643 int main(int argc, char** argv) {
223b71206888 Initial import
thib
parents:
diff changeset
1644 /* determine file names */
223b71206888 Initial import
thib
parents:
diff changeset
1645 bool verbose = false;
223b71206888 Initial import
thib
parents:
diff changeset
1646 char* inname = "seen.txt";
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1647 char* outname = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
1648 if (argc > 2 && strcmp(argv[1],"-v") == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1649 int i; for (i=1; i<argc; i++) argv[i] = argv[i+1];
223b71206888 Initial import
thib
parents:
diff changeset
1650 argc--;
223b71206888 Initial import
thib
parents:
diff changeset
1651 verbose = true;
223b71206888 Initial import
thib
parents:
diff changeset
1652 }
223b71206888 Initial import
thib
parents:
diff changeset
1653 switch(argc) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1654 case 1: break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1655 case 2:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1656 inname = argv[1];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1657 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1658 case 3:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1659 inname = argv[1];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1660 outname = argv[2];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1661 break;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1662 default: usage();
0
223b71206888 Initial import
thib
parents:
diff changeset
1663 }
223b71206888 Initial import
thib
parents:
diff changeset
1664 /* open output file */
223b71206888 Initial import
thib
parents:
diff changeset
1665 FILE* outstream = stdout;
223b71206888 Initial import
thib
parents:
diff changeset
1666 /* create archive instance */
223b71206888 Initial import
thib
parents:
diff changeset
1667 SCN2kFILE archive(inname);
223b71206888 Initial import
thib
parents:
diff changeset
1668 archive.Init();
223b71206888 Initial import
thib
parents:
diff changeset
1669 if (archive.Deal() == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1670 fprintf(stderr,"Cannot open / Invalid archive file %s\n",inname);
223b71206888 Initial import
thib
parents:
diff changeset
1671 usage();
223b71206888 Initial import
thib
parents:
diff changeset
1672 }
223b71206888 Initial import
thib
parents:
diff changeset
1673 /* dump files */
223b71206888 Initial import
thib
parents:
diff changeset
1674 archive.InitList();
223b71206888 Initial import
thib
parents:
diff changeset
1675 char* fname;
223b71206888 Initial import
thib
parents:
diff changeset
1676 fprintf(stderr,"Dump start\n");
223b71206888 Initial import
thib
parents:
diff changeset
1677 int system_version = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1678 while( (fname = archive.ListItem()) != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1679 ARCINFO* info = archive.Find(fname,"");
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 47
diff changeset
1680 if (info == NULL) continue;
0
223b71206888 Initial import
thib
parents:
diff changeset
1681 char* data = info->CopyRead();
223b71206888 Initial import
thib
parents:
diff changeset
1682 char* d = data;
223b71206888 Initial import
thib
parents:
diff changeset
1683 char* dend = d + info->Size();
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1684 /* version 確認 */
0
223b71206888 Initial import
thib
parents:
diff changeset
1685 if (read_little_endian_int(d) == 0x1cc) {
223b71206888 Initial import
thib
parents:
diff changeset
1686 system_version = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1687 } else if (read_little_endian_int(d) == 0x1d0) {
223b71206888 Initial import
thib
parents:
diff changeset
1688 system_version = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1689 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1690 continue;
223b71206888 Initial import
thib
parents:
diff changeset
1691 }
223b71206888 Initial import
thib
parents:
diff changeset
1692 if (read_little_endian_int(d+4) == 0x1adb2) ; // little busters!
223b71206888 Initial import
thib
parents:
diff changeset
1693 else if (read_little_endian_int(d+4) != 0x2712) continue;
223b71206888 Initial import
thib
parents:
diff changeset
1694 int header_size;
223b71206888 Initial import
thib
parents:
diff changeset
1695 if (system_version == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1696 header_size = 0x1cc + read_little_endian_int(d+0x20) * 4;
223b71206888 Initial import
thib
parents:
diff changeset
1697 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1698 header_size = read_little_endian_int(d+0x20);
223b71206888 Initial import
thib
parents:
diff changeset
1699 }
223b71206888 Initial import
thib
parents:
diff changeset
1700 d += header_size;
223b71206888 Initial import
thib
parents:
diff changeset
1701
223b71206888 Initial import
thib
parents:
diff changeset
1702 const char* dcur = d;
223b71206888 Initial import
thib
parents:
diff changeset
1703 const char* dstart = d;
223b71206888 Initial import
thib
parents:
diff changeset
1704 fprintf(stderr,"Dumping %s\n",fname);
223b71206888 Initial import
thib
parents:
diff changeset
1705 Flags flags;
65
4416cfac86ae Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents: 63
diff changeset
1706 /* 最初から最後までコマンド取得 -> 出力を繰り返す */
0
223b71206888 Initial import
thib
parents:
diff changeset
1707 while(dcur<dend) {
223b71206888 Initial import
thib
parents:
diff changeset
1708 const char* dprev = dcur;
223b71206888 Initial import
thib
parents:
diff changeset
1709 Cmd cmd(flags, system_version); cmd.ClearError();
223b71206888 Initial import
thib
parents:
diff changeset
1710
223b71206888 Initial import
thib
parents:
diff changeset
1711 /* end? */
223b71206888 Initial import
thib
parents:
diff changeset
1712 if (*dcur == -1) {
223b71206888 Initial import
thib
parents:
diff changeset
1713 /* 0xff x 32byte + 0x00 : end sign */
223b71206888 Initial import
thib
parents:
diff changeset
1714 int i; for (i=0; i<0x20; i++)
223b71206888 Initial import
thib
parents:
diff changeset
1715 if (dcur[i] != -1) break;
223b71206888 Initial import
thib
parents:
diff changeset
1716 if (i == 0x20 && dcur[i] == 0) break;
223b71206888 Initial import
thib
parents:
diff changeset
1717 }
223b71206888 Initial import
thib
parents:
diff changeset
1718 dprintf("%d : ",dcur-dstart);
223b71206888 Initial import
thib
parents:
diff changeset
1719 cmd.GetCmd(flags, dcur);
223b71206888 Initial import
thib
parents:
diff changeset
1720 if (cmd.IsError()) {
223b71206888 Initial import
thib
parents:
diff changeset
1721 fprintf(outstream, "Error at %6d\n",dprev-dstart);
223b71206888 Initial import
thib
parents:
diff changeset
1722 while(dcur < dend) {
223b71206888 Initial import
thib
parents:
diff changeset
1723 if (*dcur == 0x29 && dcur[1] == 0x0a) {dcur++;break;}
223b71206888 Initial import
thib
parents:
diff changeset
1724 dcur++;
223b71206888 Initial import
thib
parents:
diff changeset
1725 }
223b71206888 Initial import
thib
parents:
diff changeset
1726 dprev -= 2*16;
223b71206888 Initial import
thib
parents:
diff changeset
1727 int ilen = (dcur-dprev+15)/16;
223b71206888 Initial import
thib
parents:
diff changeset
1728 int i; for (i=0; i<ilen; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1729 fprintf(outstream, "%6d: ",dprev-dstart);
223b71206888 Initial import
thib
parents:
diff changeset
1730 int j; for (j=0; j<16; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
1731 if (dprev >= dend) break;
223b71206888 Initial import
thib
parents:
diff changeset
1732 if (dprev < data) continue;
223b71206888 Initial import
thib
parents:
diff changeset
1733 fprintf(outstream, "%02x ",*(unsigned char*)(dprev));
223b71206888 Initial import
thib
parents:
diff changeset
1734 dprev++;
223b71206888 Initial import
thib
parents:
diff changeset
1735 }
223b71206888 Initial import
thib
parents:
diff changeset
1736 fprintf(outstream, "\n");
223b71206888 Initial import
thib
parents:
diff changeset
1737 }
223b71206888 Initial import
thib
parents:
diff changeset
1738 }
223b71206888 Initial import
thib
parents:
diff changeset
1739 }
223b71206888 Initial import
thib
parents:
diff changeset
1740 delete info;
223b71206888 Initial import
thib
parents:
diff changeset
1741 }
223b71206888 Initial import
thib
parents:
diff changeset
1742 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
1743 }
223b71206888 Initial import
thib
parents:
diff changeset
1744 #endif
223b71206888 Initial import
thib
parents:
diff changeset
1745