annotate scn2k/scn2k_cmd.cc @ 74:f8751d74918b default tip

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