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

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

Fixed clang's compiler forward declaration problem - not using ExtValue? in param.h (template moved to param.cpp)

  • Property svn:eol-style set to native
File size: 33.4 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
[805]424template<typename T> void messageOnExceedRange(SimpleAbstractParam *pi, int i, int setflags, T valuetoset) ///< prints a warning when setflags indicates that allowed param range has been exceeded during set
[796]425{
426        if (setflags & (PSET_HITMIN | PSET_HITMAX))
427        {
[805]428                ExtValue v(valuetoset);
429                pi->messageOnExceedRange(i, setflags, v);
430        }
431}
432
433void SimpleAbstractParam::messageOnExceedRange(int i, int setflags, ExtValue& valuetoset) ///< prints a warning when setflags indicates that allowed param range has been exceeded during set
434{
435        if (setflags & (PSET_HITMIN | PSET_HITMAX))
436        {
[796]437                SString svaluetoset = valuetoset.getString(); //converts any type to SString
438                SString actual = get(i);
439                bool s_type = type(i)[0] == 's';
440                bool show_length = valuetoset.getType() == TString;
441                const char* quote = (valuetoset.getType() == TString) ? "\"" : "'";
442                logPrintf("Param", "set", LOG_WARN, "Setting %s.%s = %s exceeded allowed range (too %s). %s to %s.",
443                        getName(), id(i),
444                        ::sstringDelimitAndShorten(svaluetoset, 30, show_length, quote, quote).c_str(),
445                        (setflags&PSET_HITMAX) ? (s_type ? "long" : "big") : "small", s_type ? "Truncated" : "Adjusted",
446                        ::sstringDelimitAndShorten(actual, 30, show_length, quote, quote).c_str()
447                        );
448        }
449}
450
[720]451int ParamInterface::load(FileFormat format, VirtFILE* f, LoadOptions *options)
[109]452{
[720]453        LoadOptions default_options;
454        if (options == NULL)
455                options = &default_options;
456        switch (format)
457        {
458        case FormatMultiLine:
459                return loadMultiLine(f, *options);
460
461        case FormatSingleLine:
462        {
463                StringFILE *sf = dynamic_cast<StringFILE*>(f);
464                SString s;
465                if (sf)
466                {
467                        s = sf->getString().c_str();
468                        options->offset += sf->Vtell();
469                }
470                else
471                {
472                        if (!loadSStringLine(f, s))
473                                return -1;
474                }
475                return loadSingleLine(s, *options);
476        }
477        }
478        return -1;
479}
480
481int ParamInterface::load(FileFormat format, const SString &s, LoadOptions *options)
482{
483        LoadOptions default_options;
484        if (options == NULL)
485                options = &default_options;
486        switch (format)
487        {
488        case FormatMultiLine:
489        {
490                string std_string(s.c_str());
491                StringFILE f(std_string);
492                return loadMultiLine(&f, *options);
493        }
494
495        case FormatSingleLine:
496                return loadSingleLine(s, *options);
497        }
498        return -1;
499}
500
501int ParamInterface::loadMultiLine(VirtFILE* f, LoadOptions &options)
502{
[154]503        SString buf;
504        int i;
505        const char *p, *p0;
506        int p_len;
507        bool loaded;
508        int fields_loaded = 0;
[413]509        int unexpected_line = 0;
[426]510        vector<bool> seen;
511        seen.resize(getPropCount());
[650]512        if ((i = findId("beforeLoad")) >= 0)
513                call(i, NULL, NULL);
[720]514        while (((!options.abortable) || (!*options.abortable)) && loadSStringLine(f, buf))
[109]515        {
[720]516                if (options.linenum) (*options.linenum)++;
[348]517                const char* t = buf.c_str();
[413]518                p0 = t; while (isblank(*p0)) p0++;
[154]519                if (!*p0) break;
[413]520                if (p0[0] == '#') { unexpected_line = 0; continue; }
521                p = strchr(p0, ':');
522                if (!p)
[650]523                {
524                        switch (unexpected_line)
[413]525                        {
[650]526                        case 0:
527                                logPrintf("ParamInterface", "load", LOG_WARN, "Ignored unexpected line %s while reading object '%s'",
[720]528                                        options.linenum ?
529                                        SString::sprintf("%d", *options.linenum).c_str()
[413]530                                        : SString::sprintf("'%s'", p0).c_str(),
[650]531                                        getName());
532                                break;
533                        case 1:
534                                logPrintf("ParamInterface", "load", LOG_WARN, "The following line(s) were also unexpected and were ignored");
535                                break;
536                        }
[413]537                        unexpected_line++;
538                        continue;
[650]539                }
[413]540                unexpected_line = 0;
[247]541                p_len = (int)(p - p0);
[154]542                loaded = false;
[268]543                if (p_len && ((i = findIdn(p0, p_len)) >= 0))
[109]544                {
[426]545                        if (seen[i])
[650]546                        {
547                                SString fileinfo;
548                                const char* fname = f->VgetPath();
549                                if (fname != NULL)
[426]550                                {
[650]551                                        fileinfo = SString::sprintf(" while reading from '%s'", fname);
[720]552                                        if (options.linenum)
553                                                fileinfo += SString::sprintf(" (line %d)", *options.linenum);
[426]554                                }
[796]555                                logPrintf("ParamInterface", "load", LOG_WARN, "Multiple '%s.%s' properties found%s", getName(), id(i), fileinfo.c_str());
[650]556                        }
[426]557                        else
[650]558                                seen[i] = true;
[312]559                        if (!(flags(i)&PARAM_DONTLOAD))
[109]560                        {
[312]561                                if (p0[p_len + 1] == '~')
562                                {
563                                        SString s;
[650]564                                        if (!readUntilTilde(f, s))
565                                                closingTildeError(this, f, i);
[333]566                                        int lfcount = 1;
[348]567                                        const char* tmp = s.c_str();
[333]568                                        while (tmp)
569                                                if ((tmp = strchr(tmp, '\n')))
570                                                {
571                                                lfcount++; tmp++;
572                                                }
[312]573                                        removeCR(s);
[523]574                                        int ch; while ((ch = f->Vgetc()) != EOF) if (ch == '\n') break;
[312]575                                        unquoteTilde(s);
[720]576                                        if (options.linenum && (flags(i)&PARAM_LINECOMMENT))
577                                                s = SString::sprintf("@file %s\n@line %d\n", f->VgetPath(), *options.linenum + 1) + s;
[743]578                                        setFromString(i, s.c_str(), false);
[720]579                                        if (options.linenum)
580                                                (*options.linenum) += lfcount;
[312]581                                }
582                                else
583                                {
[743]584                                        setFromString(i, p0 + p_len + 1, false);
[312]585                                }
586                                fields_loaded++;
587                                loaded = true;
[109]588                        }
589                }
[720]590                else if (options.warn_unknown_fields)
[312]591                {
592                        SString name(p0, p_len);
[796]593                        logPrintf("ParamInterface", "load", LOG_WARN, "Ignored unknown property '%s.%s'", getName(), name.c_str());
[312]594                }
[268]595
[154]596                if ((!loaded) && (p0[p_len + 1] == '~'))
[109]597                { // eat unrecognized multiline field
[154]598                        SString s;
[650]599                        if (!readUntilTilde(f, s))
600                                closingTildeError(this, f, -1);
[720]601                        if (options.linenum)
[333]602                        {
[348]603                                const char* tmp = s.c_str();
[333]604                                int lfcount = 1;
605                                while (tmp)
606                                        if ((tmp = strchr(tmp, '\n')))
607                                        {
608                                        lfcount++; tmp++;
609                                        }
[720]610                                (*options.linenum) += lfcount;
[333]611                        }
[523]612                        int ch; while ((ch = f->Vgetc()) != EOF) if (ch == '\n') break;
[109]613                }
614        }
[650]615        if ((i = findId("afterLoad")) >= 0)
616                call(i, NULL, NULL);
[154]617        return fields_loaded;
[109]618}
619
620
621/*
622SString SimpleAbstractParam::getString(int i)
623{
624char *t;
625switch (*(t=type(i)))
[312]626{
[333]627case 'd':
628{
629for (i=atol(get(i));i>=0;i--) if (t) t=strchr(t+1,'~');
630if (t)
631{
632t++;
633char *t2=strchr(t,'~');
634if (!t2) t2=t+strlen(t);
635SString str;
636strncpy(str.directWrite(t2-t),t,t2-t);
637str.endWrite(t2-t);
638return str;
[312]639}
[333]640}
641}
[109]642return get(i);
643}
644*/
645
646int ParamInterface::findId(const char* n)
647{
[154]648        int i; const char *p;
649        for (i = 0; p = id(i); i++) if (!strcmp(n, p)) return i;
650        return -1;
[109]651}
652
[154]653int ParamInterface::findIdn(const char* naz, int n)
[109]654{
[154]655        int i; const char *p;
656        for (i = 0; p = id(i); i++) if ((!strncmp(naz, p, n)) && (!p[n])) return i;
657        return -1;
[109]658}
659
[154]660void ParamInterface::get(int i, ExtValue &ret)
[109]661{
[154]662        switch (type(i)[0])
[109]663        {
664        case 'd':       ret.setInt(getInt(i)); break;
665        case 'f':       ret.setDouble(getDouble(i)); break;
666        case 's':       ret.setString(getString(i)); break;
667        case 'o':       ret.setObject(getObject(i)); break;
[154]668        case 'x':       ret = getExtValue(i); break;
[796]669        default: logPrintf("ParamInterface", "get", LOG_ERROR, "'%s.%s' is not a property", getName(), id(i));
[109]670        }
671}
672
[743]673int ParamInterface::setIntFromString(int i, const char* str, bool strict)
[109]674{
[326]675        paInt value;
[645]676        if (!ExtValue::parseInt(str, value, strict, true))
[109]677        {
[314]678                paInt mn, mx, def;
[743]679                if (getMinMaxInt(i, mn, mx, def) >= 3)
[393]680                        return setInt(i, def) | PSET_PARSEFAILED;
[154]681                else
[393]682                        return setInt(i, (paInt)0) | PSET_PARSEFAILED;
[154]683        }
[109]684        else
[326]685                return setInt(i, value);
[109]686}
687
[743]688int ParamInterface::setDoubleFromString(int i, const char* str)
[109]689{
[326]690        double value;
[333]691        if (!ExtValue::parseDouble(str, value, true))
[109]692        {
[314]693                double mn, mx, def;
[743]694                if (getMinMaxDouble(i, mn, mx, def) >= 3)
[393]695                        return setDouble(i, def) | PSET_PARSEFAILED;
[154]696                else
[393]697                        return setDouble(i, (double)0) | PSET_PARSEFAILED;
[154]698        }
[109]699        else
[326]700                return setDouble(i, value);
[109]701}
702
[154]703int ParamInterface::set(int i, const ExtValue &v)
[109]704{
[154]705        switch (type(i)[0])
[109]706        {
[144]707        case 'd':
[154]708                if ((v.type == TInt) || (v.type == TDouble)) return setInt(i, v.getInt());
[144]709                else
[154]710                {
711                        if (v.type == TObj)
[333]712                        {
[478]713                                logPrintf("ParamInterface", "set", LOG_ERROR, "Setting int '%s.%s' from object reference (%s)", getName(), id(i), v.getString().c_str());
[333]714                                return 0;
715                        }
716                        else
[743]717                                return setIntFromString(i, v.getString().c_str(), false);
[154]718                }
[144]719        case 'f':
[154]720                if ((v.type == TInt) || (v.type == TDouble)) return setDouble(i, v.getDouble());
[144]721                else
[154]722                {
723                        if (v.type == TObj)
[333]724                        {
[478]725                                logPrintf("ParamInterface", "set", LOG_ERROR, "Setting float '%s.%s' from object reference (%s)", getName(), id(i), v.getString().c_str());
[333]726                                return 0;
727                        }
728                        else
[743]729                                return setDoubleFromString(i, v.getString().c_str());
[154]730                }
731        case 's': { SString t = v.getString(); return setString(i, t); }
[478]732        case 'o':
[650]733                if ((v.type != TUnknown) && (v.type != TObj))
[478]734                        logPrintf("ParamInterface", "set", LOG_ERROR, "Setting object '%s.%s' from %s", getName(), id(i), v.typeAndValue().c_str());
735                else
736                        return setObject(i, v.getObject());
737                break;
[154]738        case 'x': return setExtValue(i, v);
[796]739        default: logPrintf("ParamInterface", "set", LOG_ERROR, "'%s.%s' is not a property", getName(), id(i));
[109]740        }
[154]741        return 0;
[109]742}
743
[743]744int ParamInterface::setFromString(int i, const char *v, bool strict)
[109]745{
[312]746        char typ = type(i)[0];
[273]747        switch (typ)
[109]748        {
[743]749        case 'd': return setIntFromString(i, v, strict);
750        case 'f': return setDoubleFromString(i, v);
[154]751        case 's': { SString t(v); return setString(i, t); }
[273]752        case 'x': case 'o':
[109]753        {
[154]754                ExtValue e;
755                const char* after;
756                if (!strncmp(v, SERIALIZATION_PREFIX, strlen(SERIALIZATION_PREFIX)))
[109]757                {
[154]758                        after = e.deserialize(v + strlen(SERIALIZATION_PREFIX));
759                        if ((after == NULL) || (*after))
[343]760                        {
[478]761                                logPrintf("ParamInterface", "set", LOG_ERROR, "serialization format mismatch in %s.%s", (getName() ? getName() : "<Unknown>"), id(i));
[334]762                                e.setEmpty();
[343]763                        }
[109]764                }
[154]765                else if ((after = e.parseNumber(v)) && (*after == 0)) //consumed the whole string
[109]766                {
[154]767                        //OK!
[109]768                }
[154]769                else
[109]770                {
[154]771                        e.setString(SString(v));
[109]772                }
[312]773                if (typ == 'x')
[273]774                        return setExtValue(i, e);
775                else
776                        return setObject(i, e.getObject());
[109]777        }
778        }
[154]779        return 0;
[109]780}
781
[704]782SString ParamInterface::getText(int i) //find the current enum text or call get(i) if not enum
[109]783{
[154]784        const char *t;
[720]785        if (((*(t = type(i))) == 'd') && (strchr(t, '~') != NULL)) //type is int and contains enum labels
[109]786        {
[314]787                paInt mn, mx, def;
[312]788                int value = getInt(i);
[743]789                if (getMinMaxIntFromTypeDef(t, mn, mx, def) >= 2)
[312]790                {
[314]791                        if (value > mx)
[704]792                                return get(i);//unexpected value of out bounds (should never happen) -> fallback
[314]793                        value -= mn;
[312]794                }
[704]795                if (value < 0) return get(i); //unexpected value of out bounds (should never happen) -> fallback
796                // now value is 0-based index of ~text
797                for (; value >= 0; value--) if (t) t = strchr(t + 1, '~'); else break;
798                if (t) // found n-th ~text in type description (else: not enough ~texts in type description)
[109]799                {
[154]800                        t++;
801                        const char *t2 = strchr(t, '~');
802                        if (!t2) t2 = t + strlen(t);
[247]803                        return SString(t, (int)(t2 - t));
[109]804                }
805        }
[704]806        return get(i); //fallback - return int value as string
[109]807}
808
809SString ParamInterface::get(int i)
810{
[154]811        switch (type(i)[0])
[109]812        {
813        case 'd': return SString::valueOf(getInt(i));
814        case 'f': return SString::valueOf(getDouble(i));
815        case 's': return getString(i);
816        }
[154]817        ExtValue v;
818        get(i, v);
819        return v.getString();
[109]820}
821
[535]822bool ParamInterface::isValidTypeDescription(const char* t)
823{
[650]824        if (t == NULL) return false;
825        if (*t == 0) return false;
826        if (strchr("dfsoxp", *t) == NULL) return false;
827        switch (*t)
[574]828        {
829        case 'd':
[754]830        {
831                paInt a, b, c;
832                int have = getMinMaxIntFromTypeDef(t, a, b, c);
833                if (have == 1) return false;
834                if ((have >= 2) && (b < a) && (a != 0) && (b != -1)) return false; // max<min meaning 'undefined' is only allowed as "d 0 -1"
835        }
[574]836                break;
837        case 'f':
[754]838        {
839                double a, b, c;
840                int have = getMinMaxDoubleFromTypeDef(t, a, b, c);
841                if (have == 1) return false;
842                if ((have >= 2) && (b < a) && (a != 0) && (b != -1)) return false; // max<min meaning 'undefined' is only allowed as "f 0 -1"
843        }
[574]844                break;
[754]845        case 's':
846        {
847                int a, b; SString c;
848                int have = getMinMaxStringFromTypeDef(t, a, b, c);
849                //if (have == 1) return false; //not sure?
850                if ((have >= 1) && (!((a == 0) || (a == 1)))) return false; // 'min' for string (single/multi) can be only 0 or 1
851                if ((have >= 2) && (b < 0)) return false; // max=0 means unlimited, max<0 is not allowed
[574]852        }
[754]853                break;
854        }
[650]855        return true;
[535]856}
[109]857
[743]858SString ParamInterface::friendlyTypeDescrFromTypeDef(const char* type)
[640]859{
[650]860        SString t;
861        switch (type[0])
[640]862        {
[650]863        case 'd': t += "integer";
[743]864        {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]865                break;
866        case 'f': t += "float";
[743]867        {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]868                break;
869        case 's': t += "string";
[743]870        {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]871                break;
872        case 'x': t += "untyped value"; break;
873        case 'p': t += "function"; break;
874        case 'o': t += "object"; if (type[1]) { t += " of class "; t += type + 1; } break;
[640]875        default: return "unknown type";
876        }
[650]877        return t;
[640]878}
879
[109]880//////////////////////////////// PARAM ////////////////////////////////////
881
[483]882#ifdef _DEBUG
[230]883void SimpleAbstractParam::sanityCheck(int i)
884{
[650]885        ParamEntry *pe = entry(i);
[230]886
[650]887        const char* t = pe->type;
888        const char* err = NULL;
[230]889
[535]890        if (!isValidTypeDescription(t))
[650]891                err = "invalid type description";
892        if (*t == 'p')
[230]893        {
[650]894                if (pe->fun1 == NULL)
895                        err = "no procedure defined";
[654]896                if (pe->flags & PARAM_READONLY)
897                        err = "function can't be PARAM_READONLY";
[230]898        }
[312]899        else
[230]900        {
[732]901                if ((t[0] == 'o') && (t[1] == ' '))
902                {
903                        err = "space after 'o'";
904                }
[659]905                if (!(pe->flags & (PARAM_READONLY | PARAM_DONTSAVE | PARAM_USERREADONLY | PARAM_CONST | PARAM_DONTLOAD | PARAM_LINECOMMENT | PARAM_OBJECTSET)))
[230]906                { //write access
[650]907                        if ((pe->fun2 == NULL) && (pe->offset == PARAM_ILLEGAL_OFFSET))
908                                err = "no field defined (GETONLY without PARAM_READONLY?)";
[230]909                }
910        }
[650]911        if (err != NULL)
912                logPrintf("SimpleAbstractParam", "sanityCheck", LOG_ERROR,
[312]913                "Invalid ParamEntry for %s.%s (%s)", getName(), pe->id, err);
[650]914}
[230]915#endif
916
[109]917void *SimpleAbstractParam::getTarget(int i)
918{
[154]919        return (void*)(((char*)object) + entry(i)->offset);
920        //return &(object->*(entry(i)->fldptr));
[109]921}
922
923///////// get
924
[483]925#ifdef _DEBUG
[230]926#define SANITY_CHECK(i) sanityCheck(i)
927#else
928#define SANITY_CHECK(i)
929#endif
930
[247]931paInt SimpleAbstractParam::getInt(int i)
[109]932{
[230]933        SANITY_CHECK(i);
[154]934        ExtValue v;
935        ParamEntry *pe = entry(i);
936        if (pe->fun1)
[109]937        {
[154]938                (*(void(*)(void*, ExtValue*))pe->fun1)(object, &v);
939                return v.getInt();
[109]940        }
[154]941        else
[109]942        {
[154]943                void *target = getTarget(i);
[247]944                return *((paInt*)target);
[109]945        }
946}
947
948double SimpleAbstractParam::getDouble(int i)
949{
[230]950        SANITY_CHECK(i);
[154]951        ExtValue v;
952        ParamEntry *pe = entry(i);
953        if (pe->fun1)
[109]954        {
[154]955                (*(void(*)(void*, ExtValue*))pe->fun1)(object, &v);
956                return v.getDouble();
[109]957        }
[154]958        else
[109]959        {
[154]960                void *target = getTarget(i);
961                return *((double*)target);
[109]962        }
963}
964
965SString SimpleAbstractParam::getString(int i)
966{
[230]967        SANITY_CHECK(i);
[154]968        ExtValue v;
969        ParamEntry *pe = entry(i);
970        if (pe->fun1)
[109]971        {
[154]972                (*(void(*)(void*, ExtValue*))pe->fun1)(object, &v);
973                return v.getString();
[109]974        }
[154]975        else
[109]976        {
[154]977                void *target = getTarget(i);
978                return *((SString*)target);
[109]979        }
980}
981
982ExtObject SimpleAbstractParam::getObject(int i)
983{
[230]984        SANITY_CHECK(i);
[154]985        ExtValue v;
986        ParamEntry *pe = entry(i);
987        if (pe->fun1)
[109]988        {
[154]989                (*(void(*)(void*, ExtValue*))pe->fun1)(object, &v);
990                return v.getObject();
[109]991        }
[154]992        else
[109]993        {
[154]994                void *target = getTarget(i);
995                return *((ExtObject*)target);
[109]996        }
997}
998
999ExtValue SimpleAbstractParam::getExtValue(int i)
1000{
[230]1001        SANITY_CHECK(i);
[154]1002        ExtValue v;
1003        ParamEntry *pe = entry(i);
1004        if (pe->fun1)
[109]1005        {
[154]1006                (*(void(*)(void*, ExtValue*))pe->fun1)(object, &v);
1007                return v;
[109]1008        }
[154]1009        else
[109]1010        {
[154]1011                void *target = getTarget(i);
1012                return *((ExtValue*)target);
[109]1013        }
1014}
1015
1016
1017//////// set
1018
[247]1019int SimpleAbstractParam::setInt(int i, paInt x)
[109]1020{
[230]1021        SANITY_CHECK(i);
[154]1022        ExtValue v;
1023        ParamEntry *pe = entry(i);
1024        if (pe->flags&PARAM_READONLY) return PSET_RONLY;
[247]1025        paInt xcopy = x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below
[574]1026        paInt mn = 0, mx = 0, de = 0;
[154]1027        int result = 0;
[743]1028        if (getMinMaxIntFromTypeDef(pe->type, mn, mx, de) >= 2)
[316]1029                if (mn <= mx) // else if mn>mx then the min/max constraint makes no sense and there is no checking
[109]1030                {
[314]1031                if (x < mn) { x = mn; result = PSET_HITMIN; }
1032                else if (x > mx) { x = mx; result = PSET_HITMAX; }
[109]1033                }
1034
[154]1035        if (pe->fun2)
[109]1036        {
[154]1037                v.setInt(x);
1038                result |= (*(int(*)(void*, const ExtValue*))pe->fun2)(object, &v);
[109]1039        }
[154]1040        else
[109]1041        {
[154]1042                void *target = getTarget(i);
[247]1043                if (dontcheckchanges || (*((paInt*)target) != x))
[154]1044                {
[109]1045                        result |= PSET_CHANGED;
[247]1046                        *((paInt*)target) = x;
[154]1047                }
[109]1048        }
[805]1049        ::messageOnExceedRange(this, i, result, xcopy);
[109]1050        return result;
1051}
1052
[154]1053int SimpleAbstractParam::setDouble(int i, double x)
[109]1054{
[230]1055        SANITY_CHECK(i);
[154]1056        ExtValue v;
1057        ParamEntry *pe = entry(i);
1058        if (pe->flags&PARAM_READONLY) return PSET_RONLY;
1059        double xcopy = x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below
[574]1060        double mn = 0, mx = 0, de = 0;
[154]1061        int result = 0;
[743]1062        if (getMinMaxDoubleFromTypeDef(pe->type, mn, mx, de) >= 2)
[316]1063                if (mn <= mx) // else if mn>mx then the min/max constraint makes no sense and there is no checking
[109]1064                {
[314]1065                if (x < mn) { x = mn; result = PSET_HITMIN; }
1066                else if (x > mx) { x = mx; result = PSET_HITMAX; }
[109]1067                }
1068
[154]1069        if (pe->fun2)
[109]1070        {
[154]1071                v.setDouble(x);
1072                result |= (*(int(*)(void*, const ExtValue*))pe->fun2)(object, &v);
[109]1073        }
[154]1074        else
[109]1075        {
[154]1076                void *target = getTarget(i);
1077                if (dontcheckchanges || (*((double*)target) != x))
[109]1078                {
[154]1079                        result |= PSET_CHANGED;
1080                        *((double*)target) = x;
[109]1081                }
1082        }
[805]1083        ::messageOnExceedRange(this, i, result, xcopy);
[109]1084        return result;
1085}
1086
[154]1087int SimpleAbstractParam::setString(int i, const SString& x)
[109]1088{
[230]1089        SANITY_CHECK(i);
[154]1090        ExtValue v;
1091        SString vs;
1092        const SString *xx = &x;
1093        ParamEntry *pe = entry(i);
1094        if (pe->flags&PARAM_READONLY) return PSET_RONLY;
1095        SString xcopy = x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below
1096        const char* t = pe->type + 1;
1097        while (*t) if (*t == ' ') break; else t++;
[314]1098        int mn = 0, mx = 0;
[154]1099        int result = 0;
[314]1100        if (sscanf(t, "%d %d", &mn, &mx) == 2) //using getMinMax would also get default value, which is not needed here
[109]1101        {
[314]1102                if ((x.len() > mx) && (mx > 0))
[109]1103                {
[314]1104                        vs = x.substr(0, mx);
[154]1105                        xx = &vs;
1106                        result |= PSET_HITMAX;
[109]1107                }
1108        }
1109
[154]1110        if (pe->fun2)
[109]1111        {
[154]1112                v.setString(*xx);
1113                result |= (*(int(*)(void*, const ExtValue*))pe->fun2)(object, &v);
[109]1114        }
[154]1115        else
[109]1116        {
[154]1117                void *target = getTarget(i);
1118                if (dontcheckchanges || (!(*((SString*)target) == *xx)))
[109]1119                {
[154]1120                        result |= PSET_CHANGED;
[306]1121                        *((SString*)target) = *xx;
[109]1122                }
1123        }
[805]1124        ::messageOnExceedRange(this, i, result, xcopy);
[109]1125        return result;
1126}
1127
[154]1128int SimpleAbstractParam::setObject(int i, const ExtObject& x)
[109]1129{
[230]1130        SANITY_CHECK(i);
[154]1131        ExtValue v;
1132        ParamEntry *pe = entry(i);
1133        if (pe->flags&PARAM_READONLY) return PSET_RONLY;
[478]1134        if (pe->flags&PARAM_OBJECTSET)
[650]1135        {
1136                ExtObject o = getObject(i);
[478]1137                Param tmp;
[650]1138                ParamInterface* oif = o.getParamInterface(tmp);
[478]1139                int ass;
[650]1140                if (oif && ((ass = oif->findId("assign")) >= 0))
1141                {
1142                        ExtValue arg = x;
1143                        oif->call(ass, &arg, &v);
1144                }
[478]1145                else
1146                        logPrintf("SimpleAbstractParam", "setObject", LOG_ERROR,
[650]1147                        "'%s.%s' is PARAM_OBJECTSET but no 'assign()' in %s", getName(), pe->id, o.interfaceName());
[478]1148                return PSET_CHANGED;
[650]1149        }
[154]1150        ExtObject xcopy = x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below
1151        if (pe->fun2)
[109]1152        {
[154]1153                v.setObject(x);
1154                int result = (*(int(*)(void*, const ExtValue*))pe->fun2)(object, &v);
[805]1155                ::messageOnExceedRange(this, i, result, xcopy);
[154]1156                return result;
[109]1157        }
[154]1158        else
[109]1159        {
[154]1160                void *target = getTarget(i);
1161                *((ExtObject*)target) = x;
1162                return PSET_CHANGED;
[109]1163        }
1164}
1165
[154]1166int SimpleAbstractParam::setExtValue(int i, const ExtValue& x)
[109]1167{
[230]1168        SANITY_CHECK(i);
[154]1169        ParamEntry *pe = entry(i);
1170        if (pe->flags&PARAM_READONLY) return PSET_RONLY;
1171        ExtValue xcopy = x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below
1172        if (pe->fun2)
[109]1173        {
[154]1174                int result = (*(int(*)(void*, const ExtValue*))pe->fun2)(object, &x);
[805]1175                ::messageOnExceedRange(this, i, result, xcopy);
[154]1176                return result;
[109]1177        }
[154]1178        else
[109]1179        {
[154]1180                void *target = getTarget(i);
1181                *((ExtValue*)target) = x;
1182                return PSET_CHANGED;
[109]1183        }
1184}
1185
[154]1186void SimpleAbstractParam::call(int i, ExtValue *args, ExtValue *ret)
[109]1187{
[230]1188        SANITY_CHECK(i);
[154]1189        ParamEntry *pe = entry(i);
1190        if (!pe) return;
1191        if (pe->fun1 && (pe->type[0] == 'p'))
1192                (*(void(*)(void*, ExtValue*, ExtValue*))pe->fun1)(object, args, ret);
1193        else
[109]1194        {
[375]1195                logPrintf("SimpleAbstractParam", "call", LOG_ERROR,
[154]1196                        (*pe->type != 'p') ? "'%s.%s' is not a function" : "Internal error - undefined function pointer for '%s.%s'", getName(), pe->id);
[290]1197                ret->setInvalid();
[109]1198        }
1199}
1200
[278]1201void SimpleAbstractParam::setDefault()
[109]1202{
[154]1203        bool save = dontcheckchanges;
1204        dontcheckchanges = 1;
[278]1205        ParamInterface::setDefault();
[154]1206        dontcheckchanges = save;
[109]1207}
1208
[278]1209void SimpleAbstractParam::setDefault(int i)
[109]1210{
[154]1211        bool save = dontcheckchanges;
1212        dontcheckchanges = 1;
[278]1213        ParamInterface::setDefault(i);
[154]1214        dontcheckchanges = save;
[109]1215}
1216
[154]1217// Returns the address of the beginning of the line.
1218// len = line length (without \n).
1219// 0 may mean the line with length=0 or the end of the SString.
1220// poz is advanced to the beginning of the next line.
1221// A typical loop: for(poz=0;poz<s.d;) {line=getline(s,poz,len);...
1222static const char *getline(const SString &s, int &poz, int &len)
[109]1223{
[348]1224        const char *beg = s.c_str() + poz;
1225        if (poz >= s.len()) { poz = s.len(); len = 0; return s.c_str() + s.len(); }
[154]1226        const char *lf = strchr(beg, '\n');
[348]1227        if (!lf) { lf = s.c_str() + s.len() - 1; poz = s.len(); }
1228        else { poz = (int)(lf - s.c_str()) + 1; if (poz > s.len()) poz = s.len(); }
[154]1229        while (lf >= beg) if ((*lf == '\n') || (*lf == '\r')) lf--; else break;
[247]1230        len = (int)(lf - beg) + 1;
[154]1231        return beg;
[109]1232}
1233
[720]1234int ParamInterface::loadSingleLine(const SString &s, LoadOptions &options)
[109]1235{
[154]1236        int i; // the index number of the parameter
1237        int tmpi;
1238        int len;
1239        int ret;
1240        int fields_loaded = 0;
1241        const char *t, *lin, *end;
[320]1242        const char *equals_sign, *field_end, *next_field;
[154]1243        char remember;
1244        const char *quote, *quote2;
1245        const char *value, *valstop;
1246        SString tmpvalue;
[650]1247        bool parse_failed = false;
[720]1248        if (options.offset >= s.len()) return fields_loaded;
1249        t = s.c_str() + options.offset;
[109]1250
[720]1251        lin = getline(s, options.offset, len); // all fields must be encoded in a single line
[154]1252        if (!len) return fields_loaded; // empty line = end
1253        i = 0;
1254        end = lin + len;
1255        while (t < end)
1256        {
1257                // processing a single field
[320]1258                // "p:name=field_value,  field_name=field_value  , name=value..."
1259                //                     ^ ^-t (after)           ^ ^_next_field
1260                //                     \_t (before)            \_field_end
[325]1261                while (isspace(*t)) if (t < end) t++; else return fields_loaded;
[109]1262
[320]1263                field_end = strchrlimit(t, ',', end); if (!field_end) field_end = end;
[333]1264                next_field = field_end;
[325]1265                while ((field_end>t) && isblank(field_end[-1])) field_end--;
[320]1266                quote = strchrlimit(t, '\"', field_end);
[154]1267                if (quote)
[109]1268                {
[154]1269                        quote2 = skipQuoteString(quote + 1, end);
[320]1270                        if (quote2 > field_end)
[154]1271                        {
[320]1272                                field_end = strchrlimit(quote2 + 1, ',', end);
[393]1273                                if (!field_end) field_end = end;
1274                                next_field = field_end;
[154]1275                        }
1276                        equals_sign = strchrlimit(t, '=', quote);
[109]1277                }
[154]1278                else
1279                {
[320]1280                        equals_sign = strchrlimit(t, '=', field_end);
[154]1281                        quote2 = 0;
1282                }
1283                if (equals_sign == t) { t++; equals_sign = 0; }
[320]1284                if (field_end == t)     // skip empty value
[154]1285                {
1286                        t++; i++;
1287                        continue;
1288                }
1289                if (equals_sign) // have parameter name
1290                {
[247]1291                        tmpi = findIdn(t, (int)(equals_sign - t));
[154]1292                        i = tmpi;
1293                        if (tmpi < 0)
[312]1294                        {
1295                                SString name(t, (int)(equals_sign - t));
[796]1296                                logPrintf("Param", "loadSingleLine", LOG_WARN, "Unknown property '%s.%s' (ignored)", getName(), name.c_str());
[312]1297                        }
[154]1298                        t = equals_sign + 1; // t=value
1299                }
[109]1300#ifdef WARN_MISSING_NAME
[154]1301                else
[109]1302#ifdef SAVE_SELECTED_NAMES
[650]1303                        if ((i >= getPropCount()) || !(flags(i)&PARAM_CANOMITNAME))
[109]1304#endif
[154]1305                        {
[533]1306                        if (id(i))
[796]1307                                logPrintf("Param", "loadSingleLine", LOG_WARN, "Missing property name in '%s' (assuming '%s')", getName(), id(i));
[533]1308                        else
[796]1309                                logPrintf("Param", "loadSingleLine", LOG_WARN, "Value after the last property of '%s'", getName());
[154]1310                        }
[109]1311#endif
[154]1312                if ((i >= 0) && id(i))
[109]1313                {
[154]1314                        value = t;
1315                        if (quote)
1316                        {
[247]1317                                tmpvalue.copyFrom(quote + 1, (int)(quote2 - quote) - 1);
[154]1318                                sstringUnquote(tmpvalue);
[348]1319                                value = tmpvalue.c_str();
[154]1320                                valstop = quote2;
1321                        }
1322                        else
[320]1323                                if (field_end < end) valstop = field_end; else valstop = end;
[154]1324
1325                        remember = *valstop;
1326                        *(char*)valstop = 0;
[743]1327                        ret = setFromString(i, value, true);
[154]1328                        fields_loaded++;
[393]1329                        if (ret&PSET_PARSEFAILED)
[650]1330                                parse_failed = true;
[154]1331                        *(char*)valstop = remember;
[109]1332                }
1333
[154]1334                if (i >= 0) i++;
[109]1335#ifdef __CODEGUARD__
[732]1336                if (next_field < end - 1) t = next_field + 1; else return fields_loaded;
[109]1337#else
[320]1338                t = next_field + 1;
[109]1339#endif
[154]1340        }
[720]1341        if (parse_failed) options.parse_failed = true;
1342        return fields_loaded;
[109]1343}
1344
[154]1345int Param::grmember(int g, int a)
[109]1346{
[154]1347        if ((getGroupCount() < 2) && (!g))
1348                return (a < getPropCount()) ? a : -9999;
[109]1349
[154]1350        ParamEntry *e = entry(0);
1351        int x = 0, i = 0;
1352        for (; e->id; i++, e++)
[109]1353        {
[154]1354                if (e->group == g)
1355                        if (a == x) return i; else x++;
[109]1356        }
[154]1357        return -9999;
[109]1358}
Note: See TracBrowser for help on using the repository browser.