source: cpp/frams/param/param.cpp @ 796

Last change on this file since 796 was 796, checked in by Maciej Komosinski, 6 years ago

Unified error messages and error handling for loadSingleLine and loadMultiLine

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