Ignore:
Timestamp:
03/01/15 01:19:56 (9 years ago)
Author:
Maciej Komosinski
Message:
  • use source/code mapping for line number and file information in vm error messages
  • enum ExtValue::CompareResult? instead of int
File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/param/param.cpp

    r326 r333  
    3737static const char *strchrlimit(const char *t, int ch, const char *limit)
    3838{
    39         if (limit<t) return NULL;
    40         return (const char*)memchr((const void*)t,ch,limit-t);
     39        if (limit < t) return NULL;
     40        return (const char*)memchr((const void*)t, ch, limit - t);
    4141}
    4242
     
    392392}
    393393
    394 int ParamInterface::load(VirtFILE* f, bool warn_unknown_fields, bool *abortable)
     394int ParamInterface::load(VirtFILE* f, bool warn_unknown_fields, bool *abortable, int *linenum)
    395395{
    396396        SString buf;
     
    402402        while (((!abortable) || (!*abortable)) && loadSStringLine(f, buf))
    403403        {
     404                if (linenum) (*linenum)++;
    404405                const char* t = (const char*)buf;
    405406                p0 = t; while ((*p0 == ' ') || (*p0 == '\t')) p0++;
     
    417418                                        SString s;
    418419                                        czytdotyldy(f, s);
     420                                        int lfcount = 1;
     421                                        const char* tmp = s;
     422                                        while (tmp)
     423                                                if ((tmp = strchr(tmp, '\n')))
     424                                                {
     425                                                lfcount++; tmp++;
     426                                                }
    419427                                        removeCR(s);
    420428                                        int ch; while ((ch = fgetc(f)) != EOF) if (ch == '\n') break;
    421429                                        unquoteTilde(s);
     430                                        if (linenum && (flags(i)&PARAM_LINECOMMENT))
     431                                                s = SString::sprintf("@line %d\n", *linenum + 1) + s;
    422432                                        set(i, (const char*)s);
     433                                        if (linenum)
     434                                                (*linenum) += lfcount;
    423435                                }
    424436                                else
     
    440452                        SString s;
    441453                        czytdotyldy(f, s);
     454                        if (linenum)
     455                        {
     456                                const char* tmp = s;
     457                                int lfcount = 1;
     458                                while (tmp)
     459                                        if ((tmp = strchr(tmp, '\n')))
     460                                        {
     461                                        lfcount++; tmp++;
     462                                        }
     463                                (*linenum) += lfcount;
     464                        }
    442465                        int ch; while ((ch = fgetc(f)) != EOF) if (ch == '\n') break;
    443466                }
     
    453476switch (*(t=type(i)))
    454477{
    455         case 'd':
    456         {
    457                 for (i=atol(get(i));i>=0;i--) if (t) t=strchr(t+1,'~');
    458                 if (t)
    459                 {
    460                         t++;
    461                         char *t2=strchr(t,'~');
    462                         if (!t2) t2=t+strlen(t);
    463                         SString str;
    464                         strncpy(str.directWrite(t2-t),t,t2-t);
    465                         str.endWrite(t2-t);
    466                         return str;
    467                 }
    468         }
     478case 'd':
     479{
     480for (i=atol(get(i));i>=0;i--) if (t) t=strchr(t+1,'~');
     481if (t)
     482{
     483t++;
     484char *t2=strchr(t,'~');
     485if (!t2) t2=t+strlen(t);
     486SString str;
     487strncpy(str.directWrite(t2-t),t,t2-t);
     488str.endWrite(t2-t);
     489return str;
     490}
     491}
    469492}
    470493return get(i);
     
    502525{
    503526        paInt value;
    504         if (!ExtValue::parseInt(str,value,false,true))
     527        if (!ExtValue::parseInt(str, value, false, true))
    505528        {
    506529                paInt mn, mx, def;
     
    517540{
    518541        double value;
    519         if (!ExtValue::parseDouble(str,value,true))
     542        if (!ExtValue::parseDouble(str, value, true))
    520543        {
    521544                double mn, mx, def;
     
    538561                {
    539562                        if (v.type == TObj)
     563                        {
    540564                                FMprintf("ParamInterface", "set", FMLV_WARN, "Getting integer value from object reference (%s)", (const char*)v.getString());
    541                         return setInt(i, (const char*)v.getString());
     565                                return 0;
     566                        }
     567                        else
     568                                return setInt(i, (const char*)v.getString());
    542569                }
    543570        case 'f':
     
    546573                {
    547574                        if (v.type == TObj)
     575                        {
    548576                                FMprintf("ParamInterface", "set", FMLV_WARN, "Getting floating point value from object reference (%s)", (const char*)v.getString());
    549                         return setDouble(i, (const char*)v.getString());
     577                                return 0;
     578                        }
     579                        else
     580                                return setDouble(i, (const char*)v.getString());
    550581                }
    551582        case 's': { SString t = v.getString(); return setString(i, t); }
     
    9951026
    9961027                field_end = strchrlimit(t, ',', end); if (!field_end) field_end = end;
    997                 next_field=field_end;
     1028                next_field = field_end;
    9981029                while ((field_end>t) && isblank(field_end[-1])) field_end--;
    9991030                quote = strchrlimit(t, '\"', field_end);
Note: See TracChangeset for help on using the changeset viewer.