Changeset 333 for cpp/frams/param/param.cpp
- Timestamp:
- 03/01/15 01:19:56 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/param/param.cpp
r326 r333 37 37 static const char *strchrlimit(const char *t, int ch, const char *limit) 38 38 { 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); 41 41 } 42 42 … … 392 392 } 393 393 394 int ParamInterface::load(VirtFILE* f, bool warn_unknown_fields, bool *abortable )394 int ParamInterface::load(VirtFILE* f, bool warn_unknown_fields, bool *abortable, int *linenum) 395 395 { 396 396 SString buf; … … 402 402 while (((!abortable) || (!*abortable)) && loadSStringLine(f, buf)) 403 403 { 404 if (linenum) (*linenum)++; 404 405 const char* t = (const char*)buf; 405 406 p0 = t; while ((*p0 == ' ') || (*p0 == '\t')) p0++; … … 417 418 SString s; 418 419 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 } 419 427 removeCR(s); 420 428 int ch; while ((ch = fgetc(f)) != EOF) if (ch == '\n') break; 421 429 unquoteTilde(s); 430 if (linenum && (flags(i)&PARAM_LINECOMMENT)) 431 s = SString::sprintf("@line %d\n", *linenum + 1) + s; 422 432 set(i, (const char*)s); 433 if (linenum) 434 (*linenum) += lfcount; 423 435 } 424 436 else … … 440 452 SString s; 441 453 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 } 442 465 int ch; while ((ch = fgetc(f)) != EOF) if (ch == '\n') break; 443 466 } … … 453 476 switch (*(t=type(i))) 454 477 { 455 456 457 458 459 460 461 462 463 464 465 466 467 468 478 case 'd': 479 { 480 for (i=atol(get(i));i>=0;i--) if (t) t=strchr(t+1,'~'); 481 if (t) 482 { 483 t++; 484 char *t2=strchr(t,'~'); 485 if (!t2) t2=t+strlen(t); 486 SString str; 487 strncpy(str.directWrite(t2-t),t,t2-t); 488 str.endWrite(t2-t); 489 return str; 490 } 491 } 469 492 } 470 493 return get(i); … … 502 525 { 503 526 paInt value; 504 if (!ExtValue::parseInt(str, value,false,true))527 if (!ExtValue::parseInt(str, value, false, true)) 505 528 { 506 529 paInt mn, mx, def; … … 517 540 { 518 541 double value; 519 if (!ExtValue::parseDouble(str, value,true))542 if (!ExtValue::parseDouble(str, value, true)) 520 543 { 521 544 double mn, mx, def; … … 538 561 { 539 562 if (v.type == TObj) 563 { 540 564 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()); 542 569 } 543 570 case 'f': … … 546 573 { 547 574 if (v.type == TObj) 575 { 548 576 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()); 550 581 } 551 582 case 's': { SString t = v.getString(); return setString(i, t); } … … 995 1026 996 1027 field_end = strchrlimit(t, ',', end); if (!field_end) field_end = end; 997 next_field =field_end;1028 next_field = field_end; 998 1029 while ((field_end>t) && isblank(field_end[-1])) field_end--; 999 1030 quote = strchrlimit(t, '\"', field_end);
Note: See TracChangeset
for help on using the changeset viewer.