1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
2 | // Copyright (C) 1999-2015 Maciej Komosinski and Szymon Ulatowski. |
---|
3 | // See LICENSE.txt for details. |
---|
4 | |
---|
5 | #include <stdio.h> |
---|
6 | #include <ctype.h> |
---|
7 | |
---|
8 | #include "param.h" |
---|
9 | #include <frams/util/extvalue.h> |
---|
10 | #include "common/log.h" |
---|
11 | #include <frams/util/sstringutils.h> |
---|
12 | |
---|
13 | //#define SAVE_ALL_NAMES |
---|
14 | #define SAVE_SELECTED_NAMES |
---|
15 | #define WARN_MISSING_NAME |
---|
16 | |
---|
17 | char MakeCodeGuardHappy; |
---|
18 | |
---|
19 | ParamEntry empty_paramtab[] = |
---|
20 | { { "Empty", 1, 0, "Empty", }, { 0, 0, 0, }, }; |
---|
21 | |
---|
22 | static void czytdotyldy(VirtFILE *f, SString &s) |
---|
23 | { |
---|
24 | SString temp; |
---|
25 | int z; |
---|
26 | char last_char = 0; |
---|
27 | while ((z = fgetc(f)) != EOF) |
---|
28 | { |
---|
29 | if (z == '~') |
---|
30 | if (last_char != '\\') break; |
---|
31 | last_char = (char)z; |
---|
32 | temp += last_char; |
---|
33 | } |
---|
34 | s = temp; |
---|
35 | } |
---|
36 | |
---|
37 | static const char *strchrlimit(const char *t, int ch, const char *limit) |
---|
38 | { |
---|
39 | if (limit < t) return NULL; |
---|
40 | return (const char*)memchr((const void*)t, ch, limit - t); |
---|
41 | } |
---|
42 | |
---|
43 | void ParamInterface::copyFrom(ParamInterface *src) |
---|
44 | { |
---|
45 | int n = getPropCount(); |
---|
46 | ExtValue v; |
---|
47 | int j; |
---|
48 | for (int i = 0; i < n; i++) |
---|
49 | if ((!(flags(i)&PARAM_READONLY)) |
---|
50 | && (*type(i) != 'p')) |
---|
51 | { |
---|
52 | j = src->findId(id(i)); |
---|
53 | if (j < 0) continue; |
---|
54 | src->get(j, v); |
---|
55 | set(i, v); |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | void ParamInterface::quickCopyFrom(ParamInterface *src) |
---|
60 | { |
---|
61 | int n = getPropCount(); |
---|
62 | ExtValue v; |
---|
63 | for (int i = 0; i < n; i++) |
---|
64 | if ((!(flags(i)&PARAM_READONLY)) |
---|
65 | && (*type(i) != 'p')) |
---|
66 | { |
---|
67 | src->get(i, v); |
---|
68 | set(i, v); |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | int ParamInterface::getMinMax(int prop, paInt& minumum, paInt& maximum, paInt &def) |
---|
73 | { |
---|
74 | const char* t = type(prop) + 1; |
---|
75 | while (*t) if (*t == ' ') break; else t++; |
---|
76 | return sscanf(t, PA_INT_SCANF " " PA_INT_SCANF " " PA_INT_SCANF, &minumum, &maximum, &def); |
---|
77 | } |
---|
78 | |
---|
79 | int ParamInterface::getMinMax(int prop, double& minumum, double& maximum, double& def) |
---|
80 | { |
---|
81 | const char* t = type(prop) + 1; |
---|
82 | while (*t) if (*t == ' ') break; else t++; |
---|
83 | return sscanf(t, "%lg %lg %lg", &minumum, &maximum, &def); |
---|
84 | } |
---|
85 | |
---|
86 | int ParamInterface::getMinMax(int prop, int& minumum, int& maximum, SString& def) |
---|
87 | { |
---|
88 | const char* t = type(prop) + 1; |
---|
89 | while (*t) if (*t == ' ') break; else t++; |
---|
90 | int ret = sscanf(t, "%d %d", &minumum, &maximum); |
---|
91 | def = SString::empty(); |
---|
92 | if (ret == 2) |
---|
93 | { |
---|
94 | while (*t == ' ') t++; |
---|
95 | for (int skip_fields = 2; skip_fields > 0; skip_fields--) |
---|
96 | { |
---|
97 | while (*t) if (*t == ' ') break; else t++; |
---|
98 | while (*t == ' ') t++; |
---|
99 | } |
---|
100 | if (*t) |
---|
101 | { |
---|
102 | const char* end = strchr(t, '~'); |
---|
103 | if (!end) |
---|
104 | end = t + strlen(t); |
---|
105 | while ((end > t) && (end[-1] == ' ')) end--; |
---|
106 | def = SString(t, end - t); |
---|
107 | } |
---|
108 | return 3; |
---|
109 | } |
---|
110 | else |
---|
111 | return ret; |
---|
112 | } |
---|
113 | |
---|
114 | void ParamInterface::setDefault() |
---|
115 | { |
---|
116 | for (int i = 0; i < getPropCount(); i++) |
---|
117 | setDefault(i); |
---|
118 | } |
---|
119 | |
---|
120 | void ParamInterface::setMin() |
---|
121 | { |
---|
122 | for (int i = 0; i < getPropCount(); i++) |
---|
123 | setMin(i); |
---|
124 | } |
---|
125 | |
---|
126 | void ParamInterface::setMax() |
---|
127 | { |
---|
128 | for (int i = 0; i < getPropCount(); i++) |
---|
129 | setMax(i); |
---|
130 | } |
---|
131 | |
---|
132 | void ParamInterface::setDefault(int i) |
---|
133 | { |
---|
134 | const char *t = type(i); |
---|
135 | switch (*t) |
---|
136 | { |
---|
137 | case 'f': |
---|
138 | { |
---|
139 | double mn = 0, mx = 0, def = 0; |
---|
140 | if (getMinMax(i, mn, mx, def) < 3) def = mn; |
---|
141 | setDouble(i, def); |
---|
142 | } |
---|
143 | break; |
---|
144 | case 'd': |
---|
145 | { |
---|
146 | paInt mn = 0, mx = 0, def = 0; |
---|
147 | if (getMinMax(i, mn, mx, def) < 3) def = mn; |
---|
148 | setInt(i, def); |
---|
149 | } |
---|
150 | break; |
---|
151 | case 's': case 'x': |
---|
152 | { |
---|
153 | int mn, mx; SString def; |
---|
154 | getMinMax(i, mn, mx, def); |
---|
155 | if (*t == 's') |
---|
156 | setString(i, def); |
---|
157 | else |
---|
158 | { |
---|
159 | if (def.len() > 0) setExtValue(i, ExtValue(def)); else setExtValue(i, ExtValue::empty()); |
---|
160 | } |
---|
161 | } |
---|
162 | break; |
---|
163 | case 'o': |
---|
164 | setObject(i, ExtObject::empty()); |
---|
165 | break; |
---|
166 | } |
---|
167 | } |
---|
168 | |
---|
169 | void ParamInterface::setMin(int i) |
---|
170 | { |
---|
171 | const char *t = type(i); |
---|
172 | switch (*t) |
---|
173 | { |
---|
174 | case 'f': |
---|
175 | { |
---|
176 | double mn = 0, mx = 0, def = 0; |
---|
177 | getMinMax(i, mn, mx, def); |
---|
178 | setDouble(i, mn); |
---|
179 | } |
---|
180 | break; |
---|
181 | case 'd': |
---|
182 | { |
---|
183 | paInt mn = 0, mx = 0, def = 0; |
---|
184 | getMinMax(i, mn, mx, def); |
---|
185 | setInt(i, mn); |
---|
186 | } |
---|
187 | break; |
---|
188 | default: set(i, ""); |
---|
189 | } |
---|
190 | } |
---|
191 | |
---|
192 | void ParamInterface::setMax(int i) |
---|
193 | { |
---|
194 | const char *t = type(i); |
---|
195 | switch (*t) |
---|
196 | { |
---|
197 | case 'f': |
---|
198 | { |
---|
199 | double mn = 0, mx = 0, def = 0; |
---|
200 | getMinMax(i, mn, mx, def); |
---|
201 | setDouble(i, mx); |
---|
202 | } |
---|
203 | break; |
---|
204 | case 'd': |
---|
205 | { |
---|
206 | paInt mn = 0, mx = 0, def = 0; |
---|
207 | getMinMax(i, mn, mx, def); |
---|
208 | setInt(i, mx); |
---|
209 | } |
---|
210 | break; |
---|
211 | default: set(i, ""); |
---|
212 | } |
---|
213 | } |
---|
214 | |
---|
215 | SString ParamInterface::getStringById(const char*prop) |
---|
216 | { |
---|
217 | int i = findId(prop); if (i >= 0) return getString(i); else return SString(); |
---|
218 | } |
---|
219 | paInt ParamInterface::getIntById(const char*prop) |
---|
220 | { |
---|
221 | int i = findId(prop); if (i >= 0) return getInt(i); else return 0; |
---|
222 | } |
---|
223 | double ParamInterface::getDoubleById(const char*prop) |
---|
224 | { |
---|
225 | int i = findId(prop); if (i >= 0) return getDouble(i); else return 0; |
---|
226 | } |
---|
227 | ExtObject ParamInterface::getObjectById(const char*prop) |
---|
228 | { |
---|
229 | int i = findId(prop); if (i >= 0) return getObject(i); else return ExtObject(); |
---|
230 | } |
---|
231 | ExtValue ParamInterface::getExtValueById(const char*prop) |
---|
232 | { |
---|
233 | int i = findId(prop); if (i >= 0) return getExtValue(i); else return ExtValue(); |
---|
234 | } |
---|
235 | |
---|
236 | int ParamInterface::setIntById(const char* prop, paInt v) |
---|
237 | { |
---|
238 | int i = findId(prop); if (i >= 0) return setInt(i, v); else return PSET_NOPROPERTY; |
---|
239 | } |
---|
240 | int ParamInterface::setDoubleById(const char* prop, double v) |
---|
241 | { |
---|
242 | int i = findId(prop); if (i >= 0) return setDouble(i, v); else return PSET_NOPROPERTY; |
---|
243 | } |
---|
244 | int ParamInterface::setStringById(const char* prop, const SString &v) |
---|
245 | { |
---|
246 | int i = findId(prop); if (i >= 0) return setString(i, v); else return PSET_NOPROPERTY; |
---|
247 | } |
---|
248 | int ParamInterface::setObjectById(const char* prop, const ExtObject &v) |
---|
249 | { |
---|
250 | int i = findId(prop); if (i >= 0) return setObject(i, v); else return PSET_NOPROPERTY; |
---|
251 | } |
---|
252 | int ParamInterface::setExtValueById(const char* prop, const ExtValue &v) |
---|
253 | { |
---|
254 | int i = findId(prop); if (i >= 0) return setExtValue(i, v); else return PSET_NOPROPERTY; |
---|
255 | } |
---|
256 | int ParamInterface::setById(const char* prop, const ExtValue &v) |
---|
257 | { |
---|
258 | int i = findId(prop); if (i >= 0) return set(i, v); else return PSET_NOPROPERTY; |
---|
259 | } |
---|
260 | |
---|
261 | int ParamInterface::save(VirtFILE* f, const char* altname, bool force) |
---|
262 | { |
---|
263 | const char *p; |
---|
264 | SString ws; |
---|
265 | int err = 0, i; |
---|
266 | bool withname = false; |
---|
267 | if ((altname == NULL) || (altname[0] != 0)) |
---|
268 | { |
---|
269 | err |= (fputs(altname ? altname : getName(), f) == EOF); |
---|
270 | err |= (fputs(":\n", f) == EOF); |
---|
271 | withname = true; |
---|
272 | } |
---|
273 | for (i = 0; p = id(i); i++) |
---|
274 | err |= saveprop(f, i, p, force); |
---|
275 | if (withname) |
---|
276 | err |= (fputs("\n", f) == EOF); |
---|
277 | return err; |
---|
278 | } |
---|
279 | |
---|
280 | const char* ParamInterface::SERIALIZATION_PREFIX = "@Serialized:"; |
---|
281 | |
---|
282 | int ParamInterface::saveprop(VirtFILE* f, int i, const char* p, bool force) |
---|
283 | { |
---|
284 | if ((flags(i)&PARAM_DONTSAVE) && (!force)) return 0; |
---|
285 | const char *typ = type(i); |
---|
286 | if (*typ == 'p') return 0; |
---|
287 | |
---|
288 | const char *t, *w; |
---|
289 | SString ws; |
---|
290 | int err = 0, cr; |
---|
291 | |
---|
292 | err |= (fputs(p, f) == EOF); fputc(':', f); |
---|
293 | cr = 0; |
---|
294 | if ((*typ == 'x') || (*typ == 'o')) |
---|
295 | { |
---|
296 | ExtValue ex; |
---|
297 | get(i, ex); |
---|
298 | ws = SString(SERIALIZATION_PREFIX) + ex.serialize(); |
---|
299 | } |
---|
300 | else |
---|
301 | ws = get(i); |
---|
302 | quoteTilde(ws); |
---|
303 | w = ws.c_str(); |
---|
304 | if (ws.len() > 50) cr = 1; |
---|
305 | else for (t = w; *t; t++) if ((*t == 10) || (*t == 13)) { cr = 1; break; } |
---|
306 | if (cr) fputs("~\n", f); |
---|
307 | err |= (fputs(w, f) == EOF); |
---|
308 | err |= (fputs(cr ? "~\n" : "\n", f) == EOF); |
---|
309 | return err; |
---|
310 | } |
---|
311 | |
---|
312 | |
---|
313 | int SimpleAbstractParam::isequal(int i, void* defdata) |
---|
314 | { // defdata->member == object->member ? |
---|
315 | void *backup = object; |
---|
316 | switch (type(i)[0]) |
---|
317 | { |
---|
318 | case 'd': |
---|
319 | { |
---|
320 | select(defdata); |
---|
321 | paInt x = getInt(i); |
---|
322 | select(backup); |
---|
323 | return x == getInt(i); |
---|
324 | } |
---|
325 | case 'f': |
---|
326 | { |
---|
327 | select(defdata); |
---|
328 | double x = getDouble(i); |
---|
329 | select(backup); |
---|
330 | return x == getDouble(i); |
---|
331 | } |
---|
332 | case 's': |
---|
333 | { |
---|
334 | select(defdata); |
---|
335 | SString x = getString(i); |
---|
336 | select(backup); |
---|
337 | return x == getString(i); |
---|
338 | } |
---|
339 | } |
---|
340 | return 1; |
---|
341 | } |
---|
342 | |
---|
343 | void SimpleAbstractParam::save2(SString& f, void *defdata, bool addcr, bool all_names) |
---|
344 | { // defdata!=NULL -> does not save default values |
---|
345 | const char *p; |
---|
346 | int i; |
---|
347 | int needlabel = 0; |
---|
348 | int first = 1; |
---|
349 | SString val; |
---|
350 | SString t; |
---|
351 | int fl; |
---|
352 | // t+=SString(getName()); t+=':'; |
---|
353 | for (i = 0; p = id(i); i++) |
---|
354 | if (!((fl = flags(i))&PARAM_DONTSAVE)) |
---|
355 | { |
---|
356 | if (defdata && isequal(i, defdata)) |
---|
357 | needlabel = 1; |
---|
358 | else |
---|
359 | { |
---|
360 | if (!first) t += ", "; |
---|
361 | #ifndef SAVE_ALL_NAMES |
---|
362 | #ifdef SAVE_SELECTED_NAMES |
---|
363 | if (needlabel || all_names || !(fl & PARAM_CANOMITNAME)) |
---|
364 | #else |
---|
365 | if (needlabel) |
---|
366 | #endif |
---|
367 | #endif |
---|
368 | { |
---|
369 | t += p; t += "="; needlabel = 0; |
---|
370 | } |
---|
371 | if (type(i)[0] == 's') |
---|
372 | { // string - special case |
---|
373 | SString str = getString(i); |
---|
374 | if (strContainsOneOf(str.c_str(), ", \\\n\r\t\"")) |
---|
375 | { |
---|
376 | t += "\""; |
---|
377 | sstringQuote(str); |
---|
378 | t += str; |
---|
379 | t += "\""; |
---|
380 | } |
---|
381 | else |
---|
382 | t += str; |
---|
383 | } |
---|
384 | else |
---|
385 | t += get(i); |
---|
386 | first = 0; |
---|
387 | } |
---|
388 | } |
---|
389 | if (addcr) |
---|
390 | t += "\n"; |
---|
391 | f += t; |
---|
392 | } |
---|
393 | |
---|
394 | int ParamInterface::load(VirtFILE* f, bool warn_unknown_fields, bool *abortable, int *linenum) |
---|
395 | { |
---|
396 | SString buf; |
---|
397 | int i; |
---|
398 | const char *p, *p0; |
---|
399 | int p_len; |
---|
400 | bool loaded; |
---|
401 | int fields_loaded = 0; |
---|
402 | int unexpected_line = 0; |
---|
403 | if ((i=findId("beforeLoad"))>=0) |
---|
404 | call(i,NULL,NULL); |
---|
405 | while (((!abortable) || (!*abortable)) && loadSStringLine(f, buf)) |
---|
406 | { |
---|
407 | if (linenum) (*linenum)++; |
---|
408 | const char* t = buf.c_str(); |
---|
409 | p0 = t; while (isblank(*p0)) p0++; |
---|
410 | if (!*p0) break; |
---|
411 | if (p0[0] == '#') { unexpected_line = 0; continue; } |
---|
412 | p = strchr(p0, ':'); |
---|
413 | if (!p) |
---|
414 | { |
---|
415 | switch(unexpected_line) |
---|
416 | { |
---|
417 | case 0: |
---|
418 | logPrintf("ParamInterface", "load", LOG_WARN, "Ignored unexpected line %s while reading object '%s'", |
---|
419 | linenum ? |
---|
420 | SString::sprintf("%d",*linenum).c_str() |
---|
421 | : SString::sprintf("'%s'", p0).c_str(), |
---|
422 | getName()); |
---|
423 | break; |
---|
424 | case 1: |
---|
425 | logPrintf("ParamInterface", "load", LOG_WARN, "The following line(s) were also unexpected and were ignored"); |
---|
426 | break; |
---|
427 | } |
---|
428 | unexpected_line++; |
---|
429 | continue; |
---|
430 | } |
---|
431 | unexpected_line = 0; |
---|
432 | p_len = (int)(p - p0); |
---|
433 | loaded = false; |
---|
434 | if (p_len && ((i = findIdn(p0, p_len)) >= 0)) |
---|
435 | { |
---|
436 | if (!(flags(i)&PARAM_DONTLOAD)) |
---|
437 | { |
---|
438 | if (p0[p_len + 1] == '~') |
---|
439 | { |
---|
440 | SString s; |
---|
441 | czytdotyldy(f, s); |
---|
442 | int lfcount = 1; |
---|
443 | const char* tmp = s.c_str(); |
---|
444 | while (tmp) |
---|
445 | if ((tmp = strchr(tmp, '\n'))) |
---|
446 | { |
---|
447 | lfcount++; tmp++; |
---|
448 | } |
---|
449 | removeCR(s); |
---|
450 | int ch; while ((ch = fgetc(f)) != EOF) if (ch == '\n') break; |
---|
451 | unquoteTilde(s); |
---|
452 | if (linenum && (flags(i)&PARAM_LINECOMMENT)) |
---|
453 | s = SString::sprintf("@file %s\n@line %d\n", f->VgetPath(), *linenum + 1) + s; |
---|
454 | set(i, s.c_str()); |
---|
455 | if (linenum) |
---|
456 | (*linenum) += lfcount; |
---|
457 | } |
---|
458 | else |
---|
459 | { |
---|
460 | set(i, p0 + p_len + 1); |
---|
461 | } |
---|
462 | fields_loaded++; |
---|
463 | loaded = true; |
---|
464 | } |
---|
465 | } |
---|
466 | else if (warn_unknown_fields) |
---|
467 | { |
---|
468 | SString name(p0, p_len); |
---|
469 | logPrintf("ParamInterface", "load", LOG_WARN, "Ignored unknown property '%s' while reading object '%s'", name.c_str(), getName()); |
---|
470 | } |
---|
471 | |
---|
472 | if ((!loaded) && (p0[p_len + 1] == '~')) |
---|
473 | { // eat unrecognized multiline field |
---|
474 | SString s; |
---|
475 | czytdotyldy(f, s); |
---|
476 | if (linenum) |
---|
477 | { |
---|
478 | const char* tmp = s.c_str(); |
---|
479 | int lfcount = 1; |
---|
480 | while (tmp) |
---|
481 | if ((tmp = strchr(tmp, '\n'))) |
---|
482 | { |
---|
483 | lfcount++; tmp++; |
---|
484 | } |
---|
485 | (*linenum) += lfcount; |
---|
486 | } |
---|
487 | int ch; while ((ch = fgetc(f)) != EOF) if (ch == '\n') break; |
---|
488 | } |
---|
489 | } |
---|
490 | if ((i=findId("afterLoad"))>=0) |
---|
491 | call(i,NULL,NULL); |
---|
492 | return fields_loaded; |
---|
493 | } |
---|
494 | |
---|
495 | |
---|
496 | /* |
---|
497 | SString SimpleAbstractParam::getString(int i) |
---|
498 | { |
---|
499 | char *t; |
---|
500 | switch (*(t=type(i))) |
---|
501 | { |
---|
502 | case 'd': |
---|
503 | { |
---|
504 | for (i=atol(get(i));i>=0;i--) if (t) t=strchr(t+1,'~'); |
---|
505 | if (t) |
---|
506 | { |
---|
507 | t++; |
---|
508 | char *t2=strchr(t,'~'); |
---|
509 | if (!t2) t2=t+strlen(t); |
---|
510 | SString str; |
---|
511 | strncpy(str.directWrite(t2-t),t,t2-t); |
---|
512 | str.endWrite(t2-t); |
---|
513 | return str; |
---|
514 | } |
---|
515 | } |
---|
516 | } |
---|
517 | return get(i); |
---|
518 | } |
---|
519 | */ |
---|
520 | |
---|
521 | int ParamInterface::findId(const char* n) |
---|
522 | { |
---|
523 | int i; const char *p; |
---|
524 | for (i = 0; p = id(i); i++) if (!strcmp(n, p)) return i; |
---|
525 | return -1; |
---|
526 | } |
---|
527 | |
---|
528 | int ParamInterface::findIdn(const char* naz, int n) |
---|
529 | { |
---|
530 | int i; const char *p; |
---|
531 | for (i = 0; p = id(i); i++) if ((!strncmp(naz, p, n)) && (!p[n])) return i; |
---|
532 | return -1; |
---|
533 | } |
---|
534 | |
---|
535 | void ParamInterface::get(int i, ExtValue &ret) |
---|
536 | { |
---|
537 | switch (type(i)[0]) |
---|
538 | { |
---|
539 | case 'd': ret.setInt(getInt(i)); break; |
---|
540 | case 'f': ret.setDouble(getDouble(i)); break; |
---|
541 | case 's': ret.setString(getString(i)); break; |
---|
542 | case 'o': ret.setObject(getObject(i)); break; |
---|
543 | case 'x': ret = getExtValue(i); break; |
---|
544 | default: logPrintf("ParamInterface", "get", LOG_ERROR, "'%s.%s' is not a field", getName(), id(i)); |
---|
545 | } |
---|
546 | } |
---|
547 | |
---|
548 | int ParamInterface::setInt(int i, const char* str) |
---|
549 | { |
---|
550 | paInt value; |
---|
551 | if (!ExtValue::parseInt(str, value, false, true)) |
---|
552 | { |
---|
553 | paInt mn, mx, def; |
---|
554 | if (getMinMax(i, mn, mx, def) >= 3) |
---|
555 | return setInt(i, def) | PSET_PARSEFAILED; |
---|
556 | else |
---|
557 | return setInt(i, (paInt)0) | PSET_PARSEFAILED; |
---|
558 | } |
---|
559 | else |
---|
560 | return setInt(i, value); |
---|
561 | } |
---|
562 | |
---|
563 | int ParamInterface::setDouble(int i, const char* str) |
---|
564 | { |
---|
565 | double value; |
---|
566 | if (!ExtValue::parseDouble(str, value, true)) |
---|
567 | { |
---|
568 | double mn, mx, def; |
---|
569 | if (getMinMax(i, mn, mx, def) >= 3) |
---|
570 | return setDouble(i, def) | PSET_PARSEFAILED; |
---|
571 | else |
---|
572 | return setDouble(i, (double)0) | PSET_PARSEFAILED; |
---|
573 | } |
---|
574 | else |
---|
575 | return setDouble(i, value); |
---|
576 | } |
---|
577 | |
---|
578 | int ParamInterface::set(int i, const ExtValue &v) |
---|
579 | { |
---|
580 | switch (type(i)[0]) |
---|
581 | { |
---|
582 | case 'd': |
---|
583 | if ((v.type == TInt) || (v.type == TDouble)) return setInt(i, v.getInt()); |
---|
584 | else |
---|
585 | { |
---|
586 | if (v.type == TObj) |
---|
587 | { |
---|
588 | logPrintf("ParamInterface", "set", LOG_WARN, "Getting integer value from object reference (%s)", v.getString().c_str()); |
---|
589 | return 0; |
---|
590 | } |
---|
591 | else |
---|
592 | return setInt(i, v.getString().c_str()); |
---|
593 | } |
---|
594 | case 'f': |
---|
595 | if ((v.type == TInt) || (v.type == TDouble)) return setDouble(i, v.getDouble()); |
---|
596 | else |
---|
597 | { |
---|
598 | if (v.type == TObj) |
---|
599 | { |
---|
600 | logPrintf("ParamInterface", "set", LOG_WARN, "Getting floating point value from object reference (%s)", v.getString().c_str()); |
---|
601 | return 0; |
---|
602 | } |
---|
603 | else |
---|
604 | return setDouble(i, v.getString().c_str()); |
---|
605 | } |
---|
606 | case 's': { SString t = v.getString(); return setString(i, t); } |
---|
607 | case 'o': return setObject(i, v.getObject()); |
---|
608 | case 'x': return setExtValue(i, v); |
---|
609 | default: logPrintf("ParamInterface", "set", LOG_ERROR, "'%s.%s' is not a field", getName(), id(i)); |
---|
610 | } |
---|
611 | return 0; |
---|
612 | } |
---|
613 | |
---|
614 | int ParamInterface::set(int i, const char *v) |
---|
615 | { |
---|
616 | char typ = type(i)[0]; |
---|
617 | switch (typ) |
---|
618 | { |
---|
619 | case 'd': return setInt(i, v); |
---|
620 | case 'f': return setDouble(i, v); |
---|
621 | case 's': { SString t(v); return setString(i, t); } |
---|
622 | case 'x': case 'o': |
---|
623 | { |
---|
624 | ExtValue e; |
---|
625 | const char* after; |
---|
626 | if (!strncmp(v, SERIALIZATION_PREFIX, strlen(SERIALIZATION_PREFIX))) |
---|
627 | { |
---|
628 | after = e.deserialize(v + strlen(SERIALIZATION_PREFIX)); |
---|
629 | if ((after == NULL) || (*after)) |
---|
630 | { |
---|
631 | logPrintf("ParamInterface", "set", LOG_WARN, "serialization format mismatch in %s.%s", (getName() ? getName() : "<Unknown>"), id(i)); |
---|
632 | e.setEmpty(); |
---|
633 | } |
---|
634 | } |
---|
635 | else if ((after = e.parseNumber(v)) && (*after == 0)) //consumed the whole string |
---|
636 | { |
---|
637 | //OK! |
---|
638 | } |
---|
639 | else |
---|
640 | { |
---|
641 | e.setString(SString(v)); |
---|
642 | } |
---|
643 | if (typ == 'x') |
---|
644 | return setExtValue(i, e); |
---|
645 | else |
---|
646 | return setObject(i, e.getObject()); |
---|
647 | } |
---|
648 | } |
---|
649 | return 0; |
---|
650 | } |
---|
651 | |
---|
652 | SString ParamInterface::getText(int i) |
---|
653 | { |
---|
654 | const char *t; |
---|
655 | if ((*(t = type(i))) == 'd') |
---|
656 | { |
---|
657 | paInt mn, mx, def; |
---|
658 | int value = getInt(i); |
---|
659 | if (getMinMax(i, mn, mx, def) >= 2) |
---|
660 | { |
---|
661 | if (value > mx) |
---|
662 | return get(i); |
---|
663 | value -= mn; |
---|
664 | } |
---|
665 | if (value < 0) return get(i); |
---|
666 | for (; value >= 0; value--) if (t) t = strchr(t + 1, '~'); |
---|
667 | if (t) |
---|
668 | { |
---|
669 | t++; |
---|
670 | const char *t2 = strchr(t, '~'); |
---|
671 | if (!t2) t2 = t + strlen(t); |
---|
672 | return SString(t, (int)(t2 - t)); |
---|
673 | } |
---|
674 | } |
---|
675 | return get(i); |
---|
676 | } |
---|
677 | |
---|
678 | SString ParamInterface::get(int i) |
---|
679 | { |
---|
680 | switch (type(i)[0]) |
---|
681 | { |
---|
682 | case 'd': return SString::valueOf(getInt(i)); |
---|
683 | case 'f': return SString::valueOf(getDouble(i)); |
---|
684 | case 's': return getString(i); |
---|
685 | } |
---|
686 | ExtValue v; |
---|
687 | get(i, v); |
---|
688 | return v.getString(); |
---|
689 | } |
---|
690 | |
---|
691 | |
---|
692 | //////////////////////////////// PARAM //////////////////////////////////// |
---|
693 | |
---|
694 | #ifdef DEBUG |
---|
695 | void SimpleAbstractParam::sanityCheck(int i) |
---|
696 | { |
---|
697 | ParamEntry *pe=entry(i); |
---|
698 | |
---|
699 | const char* t=pe->type; |
---|
700 | const char* err=NULL; |
---|
701 | |
---|
702 | if (*t=='p') |
---|
703 | { |
---|
704 | if (pe->fun1==NULL) |
---|
705 | err="no procedure defined"; |
---|
706 | } |
---|
707 | else |
---|
708 | { |
---|
709 | if (!(pe->flags & PARAM_READONLY)) |
---|
710 | { //write access |
---|
711 | if ((pe->fun2==NULL)&&(pe->offset==PARAM_ILLEGAL_OFFSET)) |
---|
712 | err="no field defined (GETONLY without PARAM_READONLY?)"; |
---|
713 | } |
---|
714 | } |
---|
715 | if (err!=NULL) |
---|
716 | logPrintf("SimpleAbstractParam","sanityCheck", LOG_ERROR, |
---|
717 | "Invalid ParamEntry for %s.%s (%s)", getName(), pe->id, err); |
---|
718 | } |
---|
719 | #endif |
---|
720 | |
---|
721 | void *SimpleAbstractParam::getTarget(int i) |
---|
722 | { |
---|
723 | return (void*)(((char*)object) + entry(i)->offset); |
---|
724 | //return &(object->*(entry(i)->fldptr)); |
---|
725 | } |
---|
726 | |
---|
727 | ///////// get |
---|
728 | |
---|
729 | #ifdef DEBUG |
---|
730 | #define SANITY_CHECK(i) sanityCheck(i) |
---|
731 | #else |
---|
732 | #define SANITY_CHECK(i) |
---|
733 | #endif |
---|
734 | |
---|
735 | paInt SimpleAbstractParam::getInt(int i) |
---|
736 | { |
---|
737 | SANITY_CHECK(i); |
---|
738 | ExtValue v; |
---|
739 | ParamEntry *pe = entry(i); |
---|
740 | if (pe->fun1) |
---|
741 | { |
---|
742 | (*(void(*)(void*, ExtValue*))pe->fun1)(object, &v); |
---|
743 | return v.getInt(); |
---|
744 | } |
---|
745 | else |
---|
746 | { |
---|
747 | void *target = getTarget(i); |
---|
748 | return *((paInt*)target); |
---|
749 | } |
---|
750 | } |
---|
751 | |
---|
752 | double SimpleAbstractParam::getDouble(int i) |
---|
753 | { |
---|
754 | SANITY_CHECK(i); |
---|
755 | ExtValue v; |
---|
756 | ParamEntry *pe = entry(i); |
---|
757 | if (pe->fun1) |
---|
758 | { |
---|
759 | (*(void(*)(void*, ExtValue*))pe->fun1)(object, &v); |
---|
760 | return v.getDouble(); |
---|
761 | } |
---|
762 | else |
---|
763 | { |
---|
764 | void *target = getTarget(i); |
---|
765 | return *((double*)target); |
---|
766 | } |
---|
767 | } |
---|
768 | |
---|
769 | SString SimpleAbstractParam::getString(int i) |
---|
770 | { |
---|
771 | SANITY_CHECK(i); |
---|
772 | ExtValue v; |
---|
773 | ParamEntry *pe = entry(i); |
---|
774 | if (pe->fun1) |
---|
775 | { |
---|
776 | (*(void(*)(void*, ExtValue*))pe->fun1)(object, &v); |
---|
777 | return v.getString(); |
---|
778 | } |
---|
779 | else |
---|
780 | { |
---|
781 | void *target = getTarget(i); |
---|
782 | return *((SString*)target); |
---|
783 | } |
---|
784 | } |
---|
785 | |
---|
786 | ExtObject SimpleAbstractParam::getObject(int i) |
---|
787 | { |
---|
788 | SANITY_CHECK(i); |
---|
789 | ExtValue v; |
---|
790 | ParamEntry *pe = entry(i); |
---|
791 | if (pe->fun1) |
---|
792 | { |
---|
793 | (*(void(*)(void*, ExtValue*))pe->fun1)(object, &v); |
---|
794 | return v.getObject(); |
---|
795 | } |
---|
796 | else |
---|
797 | { |
---|
798 | void *target = getTarget(i); |
---|
799 | return *((ExtObject*)target); |
---|
800 | } |
---|
801 | } |
---|
802 | |
---|
803 | ExtValue SimpleAbstractParam::getExtValue(int i) |
---|
804 | { |
---|
805 | SANITY_CHECK(i); |
---|
806 | ExtValue v; |
---|
807 | ParamEntry *pe = entry(i); |
---|
808 | if (pe->fun1) |
---|
809 | { |
---|
810 | (*(void(*)(void*, ExtValue*))pe->fun1)(object, &v); |
---|
811 | return v; |
---|
812 | } |
---|
813 | else |
---|
814 | { |
---|
815 | void *target = getTarget(i); |
---|
816 | return *((ExtValue*)target); |
---|
817 | } |
---|
818 | } |
---|
819 | |
---|
820 | |
---|
821 | //////// set |
---|
822 | |
---|
823 | int SimpleAbstractParam::setInt(int i, paInt x) |
---|
824 | { |
---|
825 | SANITY_CHECK(i); |
---|
826 | ExtValue v; |
---|
827 | ParamEntry *pe = entry(i); |
---|
828 | if (pe->flags&PARAM_READONLY) return PSET_RONLY; |
---|
829 | paInt xcopy = x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below |
---|
830 | paInt mn = 0, mx = 0; |
---|
831 | int result = 0; |
---|
832 | const char* t = pe->type + 1; |
---|
833 | while (*t) if (*t == ' ') break; else t++; |
---|
834 | if (sscanf(t, PA_INT_SCANF " " PA_INT_SCANF, &mn, &mx) == 2) |
---|
835 | if (mn <= mx) // else if mn>mx then the min/max constraint makes no sense and there is no checking |
---|
836 | { |
---|
837 | if (x < mn) { x = mn; result = PSET_HITMIN; } |
---|
838 | else if (x > mx) { x = mx; result = PSET_HITMAX; } |
---|
839 | } |
---|
840 | |
---|
841 | if (pe->fun2) |
---|
842 | { |
---|
843 | v.setInt(x); |
---|
844 | result |= (*(int(*)(void*, const ExtValue*))pe->fun2)(object, &v); |
---|
845 | } |
---|
846 | else |
---|
847 | { |
---|
848 | void *target = getTarget(i); |
---|
849 | if (dontcheckchanges || (*((paInt*)target) != x)) |
---|
850 | { |
---|
851 | result |= PSET_CHANGED; |
---|
852 | *((paInt*)target) = x; |
---|
853 | } |
---|
854 | } |
---|
855 | messageOnExceedRange(i, result, xcopy); |
---|
856 | return result; |
---|
857 | } |
---|
858 | |
---|
859 | int SimpleAbstractParam::setDouble(int i, double x) |
---|
860 | { |
---|
861 | SANITY_CHECK(i); |
---|
862 | ExtValue v; |
---|
863 | ParamEntry *pe = entry(i); |
---|
864 | if (pe->flags&PARAM_READONLY) return PSET_RONLY; |
---|
865 | double xcopy = x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below |
---|
866 | double mn = 0, mx = 0; |
---|
867 | int result = 0; |
---|
868 | const char* t = pe->type + 1; |
---|
869 | while (*t) if (*t == ' ') break; else t++; |
---|
870 | if (sscanf(t, "%lg %lg", &mn, &mx) == 2) |
---|
871 | if (mn <= mx) // else if mn>mx then the min/max constraint makes no sense and there is no checking |
---|
872 | { |
---|
873 | if (x < mn) { x = mn; result = PSET_HITMIN; } |
---|
874 | else if (x > mx) { x = mx; result = PSET_HITMAX; } |
---|
875 | } |
---|
876 | |
---|
877 | if (pe->fun2) |
---|
878 | { |
---|
879 | v.setDouble(x); |
---|
880 | result |= (*(int(*)(void*, const ExtValue*))pe->fun2)(object, &v); |
---|
881 | } |
---|
882 | else |
---|
883 | { |
---|
884 | void *target = getTarget(i); |
---|
885 | if (dontcheckchanges || (*((double*)target) != x)) |
---|
886 | { |
---|
887 | result |= PSET_CHANGED; |
---|
888 | *((double*)target) = x; |
---|
889 | } |
---|
890 | } |
---|
891 | messageOnExceedRange(i, result, xcopy); |
---|
892 | return result; |
---|
893 | } |
---|
894 | |
---|
895 | int SimpleAbstractParam::setString(int i, const SString& x) |
---|
896 | { |
---|
897 | SANITY_CHECK(i); |
---|
898 | ExtValue v; |
---|
899 | SString vs; |
---|
900 | const SString *xx = &x; |
---|
901 | ParamEntry *pe = entry(i); |
---|
902 | if (pe->flags&PARAM_READONLY) return PSET_RONLY; |
---|
903 | SString xcopy = x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below |
---|
904 | const char* t = pe->type + 1; |
---|
905 | while (*t) if (*t == ' ') break; else t++; |
---|
906 | int mn = 0, mx = 0; |
---|
907 | int result = 0; |
---|
908 | if (sscanf(t, "%d %d", &mn, &mx) == 2) //using getMinMax would also get default value, which is not needed here |
---|
909 | { |
---|
910 | if ((x.len() > mx) && (mx > 0)) |
---|
911 | { |
---|
912 | vs = x.substr(0, mx); |
---|
913 | xx = &vs; |
---|
914 | result |= PSET_HITMAX; |
---|
915 | } |
---|
916 | } |
---|
917 | |
---|
918 | if (pe->fun2) |
---|
919 | { |
---|
920 | v.setString(*xx); |
---|
921 | result |= (*(int(*)(void*, const ExtValue*))pe->fun2)(object, &v); |
---|
922 | } |
---|
923 | else |
---|
924 | { |
---|
925 | void *target = getTarget(i); |
---|
926 | if (dontcheckchanges || (!(*((SString*)target) == *xx))) |
---|
927 | { |
---|
928 | result |= PSET_CHANGED; |
---|
929 | *((SString*)target) = *xx; |
---|
930 | } |
---|
931 | } |
---|
932 | messageOnExceedRange(i, result, xcopy); |
---|
933 | return result; |
---|
934 | } |
---|
935 | |
---|
936 | int SimpleAbstractParam::setObject(int i, const ExtObject& x) |
---|
937 | { |
---|
938 | SANITY_CHECK(i); |
---|
939 | ExtValue v; |
---|
940 | ParamEntry *pe = entry(i); |
---|
941 | if (pe->flags&PARAM_READONLY) return PSET_RONLY; |
---|
942 | ExtObject xcopy = x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below |
---|
943 | if (pe->fun2) |
---|
944 | { |
---|
945 | v.setObject(x); |
---|
946 | int result = (*(int(*)(void*, const ExtValue*))pe->fun2)(object, &v); |
---|
947 | messageOnExceedRange(i, result, xcopy); |
---|
948 | return result; |
---|
949 | } |
---|
950 | else |
---|
951 | { |
---|
952 | void *target = getTarget(i); |
---|
953 | *((ExtObject*)target) = x; |
---|
954 | return PSET_CHANGED; |
---|
955 | } |
---|
956 | } |
---|
957 | |
---|
958 | int SimpleAbstractParam::setExtValue(int i, const ExtValue& x) |
---|
959 | { |
---|
960 | SANITY_CHECK(i); |
---|
961 | ParamEntry *pe = entry(i); |
---|
962 | if (pe->flags&PARAM_READONLY) return PSET_RONLY; |
---|
963 | ExtValue xcopy = x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below |
---|
964 | if (pe->fun2) |
---|
965 | { |
---|
966 | int result = (*(int(*)(void*, const ExtValue*))pe->fun2)(object, &x); |
---|
967 | messageOnExceedRange(i, result, xcopy); |
---|
968 | return result; |
---|
969 | } |
---|
970 | else |
---|
971 | { |
---|
972 | void *target = getTarget(i); |
---|
973 | *((ExtValue*)target) = x; |
---|
974 | return PSET_CHANGED; |
---|
975 | } |
---|
976 | } |
---|
977 | |
---|
978 | void SimpleAbstractParam::call(int i, ExtValue *args, ExtValue *ret) |
---|
979 | { |
---|
980 | SANITY_CHECK(i); |
---|
981 | ParamEntry *pe = entry(i); |
---|
982 | if (!pe) return; |
---|
983 | if (pe->fun1 && (pe->type[0] == 'p')) |
---|
984 | (*(void(*)(void*, ExtValue*, ExtValue*))pe->fun1)(object, args, ret); |
---|
985 | else |
---|
986 | { |
---|
987 | logPrintf("SimpleAbstractParam", "call", LOG_ERROR, |
---|
988 | (*pe->type != 'p') ? "'%s.%s' is not a function" : "Internal error - undefined function pointer for '%s.%s'", getName(), pe->id); |
---|
989 | ret->setInvalid(); |
---|
990 | } |
---|
991 | } |
---|
992 | |
---|
993 | void SimpleAbstractParam::setDefault() |
---|
994 | { |
---|
995 | bool save = dontcheckchanges; |
---|
996 | dontcheckchanges = 1; |
---|
997 | ParamInterface::setDefault(); |
---|
998 | dontcheckchanges = save; |
---|
999 | } |
---|
1000 | |
---|
1001 | void SimpleAbstractParam::setDefault(int i) |
---|
1002 | { |
---|
1003 | bool save = dontcheckchanges; |
---|
1004 | dontcheckchanges = 1; |
---|
1005 | ParamInterface::setDefault(i); |
---|
1006 | dontcheckchanges = save; |
---|
1007 | } |
---|
1008 | |
---|
1009 | // Returns the address of the beginning of the line. |
---|
1010 | // len = line length (without \n). |
---|
1011 | // 0 may mean the line with length=0 or the end of the SString. |
---|
1012 | // poz is advanced to the beginning of the next line. |
---|
1013 | // A typical loop: for(poz=0;poz<s.d;) {line=getline(s,poz,len);... |
---|
1014 | static const char *getline(const SString &s, int &poz, int &len) |
---|
1015 | { |
---|
1016 | const char *beg = s.c_str() + poz; |
---|
1017 | if (poz >= s.len()) { poz = s.len(); len = 0; return s.c_str() + s.len(); } |
---|
1018 | const char *lf = strchr(beg, '\n'); |
---|
1019 | if (!lf) { lf = s.c_str() + s.len() - 1; poz = s.len(); } |
---|
1020 | else { poz = (int)(lf - s.c_str()) + 1; if (poz > s.len()) poz = s.len(); } |
---|
1021 | while (lf >= beg) if ((*lf == '\n') || (*lf == '\r')) lf--; else break; |
---|
1022 | len = (int)(lf - beg) + 1; |
---|
1023 | return beg; |
---|
1024 | } |
---|
1025 | |
---|
1026 | int ParamInterface::load2(const SString &s, int &poz) |
---|
1027 | { |
---|
1028 | int i; // the index number of the parameter |
---|
1029 | int tmpi; |
---|
1030 | int len; |
---|
1031 | int ret; |
---|
1032 | int fields_loaded = 0; |
---|
1033 | const char *t, *lin, *end; |
---|
1034 | const char *equals_sign, *field_end, *next_field; |
---|
1035 | char remember; |
---|
1036 | const char *quote, *quote2; |
---|
1037 | const char *value, *valstop; |
---|
1038 | SString tmpvalue; |
---|
1039 | bool parse_failed=false; |
---|
1040 | if (poz >= s.len()) return fields_loaded; |
---|
1041 | t = s.c_str() + poz; |
---|
1042 | |
---|
1043 | lin = getline(s, poz, len); // all fields must be encoded in a single line |
---|
1044 | if (!len) return fields_loaded; // empty line = end |
---|
1045 | i = 0; |
---|
1046 | end = lin + len; |
---|
1047 | while (t < end) |
---|
1048 | { |
---|
1049 | // processing a single field |
---|
1050 | // "p:name=field_value, field_name=field_value , name=value..." |
---|
1051 | // ^ ^-t (after) ^ ^_next_field |
---|
1052 | // \_t (before) \_field_end |
---|
1053 | while (isspace(*t)) if (t < end) t++; else return fields_loaded; |
---|
1054 | |
---|
1055 | field_end = strchrlimit(t, ',', end); if (!field_end) field_end = end; |
---|
1056 | next_field = field_end; |
---|
1057 | while ((field_end>t) && isblank(field_end[-1])) field_end--; |
---|
1058 | quote = strchrlimit(t, '\"', field_end); |
---|
1059 | if (quote) |
---|
1060 | { |
---|
1061 | quote2 = skipQuoteString(quote + 1, end); |
---|
1062 | if (quote2 > field_end) |
---|
1063 | { |
---|
1064 | field_end = strchrlimit(quote2 + 1, ',', end); |
---|
1065 | if (!field_end) field_end = end; |
---|
1066 | next_field = field_end; |
---|
1067 | } |
---|
1068 | equals_sign = strchrlimit(t, '=', quote); |
---|
1069 | } |
---|
1070 | else |
---|
1071 | { |
---|
1072 | equals_sign = strchrlimit(t, '=', field_end); |
---|
1073 | quote2 = 0; |
---|
1074 | } |
---|
1075 | if (equals_sign == t) { t++; equals_sign = 0; } |
---|
1076 | if (field_end == t) // skip empty value |
---|
1077 | { |
---|
1078 | t++; i++; |
---|
1079 | continue; |
---|
1080 | } |
---|
1081 | if (equals_sign) // have parameter name |
---|
1082 | { |
---|
1083 | tmpi = findIdn(t, (int)(equals_sign - t)); |
---|
1084 | i = tmpi; |
---|
1085 | if (tmpi < 0) |
---|
1086 | { |
---|
1087 | SString name(t, (int)(equals_sign - t)); |
---|
1088 | logPrintf("Param", "load2", LOG_WARN, "Unknown property '%s' while reading object '%s' (ignored)", name.c_str(), getName()); |
---|
1089 | } |
---|
1090 | t = equals_sign + 1; // t=value |
---|
1091 | } |
---|
1092 | #ifdef WARN_MISSING_NAME |
---|
1093 | else |
---|
1094 | #ifdef SAVE_SELECTED_NAMES |
---|
1095 | if (!(flags(i)&PARAM_CANOMITNAME)) |
---|
1096 | #endif |
---|
1097 | { |
---|
1098 | logPrintf("Param", "load2", LOG_WARN, "Missing property name in '%s' (assuming '%s')", |
---|
1099 | getName(), id(i) ? id(i) : "unknown property?"); |
---|
1100 | } |
---|
1101 | #endif |
---|
1102 | if ((i >= 0) && id(i)) |
---|
1103 | { |
---|
1104 | value = t; |
---|
1105 | if (quote) |
---|
1106 | { |
---|
1107 | tmpvalue.copyFrom(quote + 1, (int)(quote2 - quote) - 1); |
---|
1108 | sstringUnquote(tmpvalue); |
---|
1109 | value = tmpvalue.c_str(); |
---|
1110 | valstop = quote2; |
---|
1111 | } |
---|
1112 | else |
---|
1113 | if (field_end < end) valstop = field_end; else valstop = end; |
---|
1114 | |
---|
1115 | remember = *valstop; |
---|
1116 | *(char*)valstop = 0; |
---|
1117 | ret = set(i, value); |
---|
1118 | fields_loaded++; |
---|
1119 | if (ret&(PSET_HITMAX | PSET_HITMIN)) |
---|
1120 | logPrintf("Param", "load2", LOG_WARN, "Adjusted '%s' in '%s' (was too %s)", |
---|
1121 | id(i), getName(), (ret&PSET_HITMAX) ? "big" : "small"); |
---|
1122 | if (ret&PSET_PARSEFAILED) |
---|
1123 | parse_failed=true; |
---|
1124 | *(char*)valstop = remember; |
---|
1125 | } |
---|
1126 | |
---|
1127 | if (i >= 0) i++; |
---|
1128 | #ifdef __CODEGUARD__ |
---|
1129 | if (next_field<end-1) t=next_field+1; else return fields_loaded; |
---|
1130 | #else |
---|
1131 | t = next_field + 1; |
---|
1132 | #endif |
---|
1133 | } |
---|
1134 | return fields_loaded | (parse_failed ? LOAD2_PARSE_FAILED : 0); |
---|
1135 | } |
---|
1136 | |
---|
1137 | int Param::grmember(int g, int a) |
---|
1138 | { |
---|
1139 | if ((getGroupCount() < 2) && (!g)) |
---|
1140 | return (a < getPropCount()) ? a : -9999; |
---|
1141 | |
---|
1142 | ParamEntry *e = entry(0); |
---|
1143 | int x = 0, i = 0; |
---|
1144 | for (; e->id; i++, e++) |
---|
1145 | { |
---|
1146 | if (e->group == g) |
---|
1147 | if (a == x) return i; else x++; |
---|
1148 | } |
---|
1149 | return -9999; |
---|
1150 | } |
---|