| 465 |
@@ -465,64 +465,41 @@ |
| 465 |
}
|
| 466 |
|
| 467 |
//! @brief Parses from = to end of " pair.
|
| 468 |
bool
|
| 469 |
void
|
| 470 |
CfgParser::parse_value(CfgParserSource *source, std::string &value)
|
| 471 |
{
|
| 472 |
// Init parse buffer and reserve memory.
|
| 473 |
string buf;
|
| 474 |
buf.reserve(PARSE_BUF_SIZE);
|
| 475 |
|
| 476 |
// We expect to get a " after the =, however to do proper error reporting
|
| 477 |
// we store the what we get between so we can show the output if it includes
|
| 478 |
// anything else than spaces.
|
| 479 |
int c, next;
|
| 480 |
bool garbage = false;
|
| 481 |
while ((c = source->getc()) != EOF) {
|
| 482 |
if (c == '"') {
|
| 483 |
break;
|
| 484 |
}
|
| 485 |
|
| 486 |
buf += c;
|
| 487 |
|
| 488 |
if (! isspace(c)) {
|
| 489 |
garbage = true;
|
| 490 |
}
|
| 491 |
}
|
| 492 |
// We expect to get a " after the =, however we ignore anything else.
|
| 493 |
int c;
|
| 494 |
while ((c = source->getc()) != EOF && c != '"')
|
| 495 |
;
|
| 496 |
|
| 497 |
// Check if we got to a " or found EOF first.
|
| 498 |
if (c == EOF) {
|
| 499 |
cerr << "Reached EOF before opening \" in value." << endl;
|
| 500 |
return false;
|
| 501 |
}
|
| 502 |
|
| 503 |
// Check if there was garbage between = and ".
|
| 504 |
if (garbage) {
|
| 505 |
// pass, do nothing
|
| 506 |
return;
|
| 507 |
}
|
| 508 |
|
| 509 |
// Parse until next ", and escape characters after \.
|
| 510 |
buf.clear();
|
| 511 |
while ((c = source->getc()) != EOF) {
|
| 512 |
while ((c = source->getc()) != EOF && c != '"') {
|
| 513 |
// Escape character after \, if newline drop it.
|
| 514 |
if (c == '\\') {
|
| 515 |
next = source->getc();
|
| 516 |
if (next != '\n') {
|
| 517 |
buf += next;
|
| 518 |
c = source->getc();
|
| 519 |
if (c == '\n' || c == EOF) {
|
| 520 |
continue;
|
| 521 |
}
|
| 522 |
} else if (c == '"') {
|
| 523 |
break;
|
| 524 |
} else {
|
| 525 |
buf += c;
|
| 526 |
}
|
| 527 |
value += c;
|
| 528 |
}
|
| 529 |
|
| 530 |
if (c == EOF) {
|
| 531 |
cerr << "Reached EOF before closing \" in value." << endl;
|
| 532 |
}
|
| 533 |
|
| 534 |
value = buf;
|
| 535 |
|
| 536 |
return false;
|
| 537 |
// If the value is empty, parse_entry_finish() might later just skip
|
| 538 |
// the complete entry. To allow empty config options we add a dummy space.
|
| 539 |
if (!value.size()) {
|
| 540 |
value = " ";
|
| 541 |
}
|
| 542 |
}
|
| 543 |
|
| 544 |
//! @brief Parses entry (name + value) and executes command accordingly.
|
| ... |
|
| 612 |
@@ -635,8 +612,12 @@ |
| 612 |
{
|
| 613 |
int c;
|
| 614 |
while ((c = source->getc()) != EOF) {
|
| 638 |
if ((c == '*') && (source->getc() == '/')) {
|
| 639 |
break;
|
| 617 |
if (c == '*') {
|
| 618 |
if ((c = source->getc()) == '/') {
|
| 619 |
break;
|
| 620 |
} else if (c != EOF) {
|
| 621 |
source->ungetc(c);
|
| 622 |
}
|
| 623 |
}
|
| 624 |
}
|
| 625 |
|
| ... |
|
| 628 |
@@ -647,7 +628,7 @@ |
| 628 |
|
| 629 |
//! @brief Parses Source until next non whitespace char is found.
|
| 630 |
char
|
| 650 |
CfgParser::parse_skip_blank (CfgParserSource *source)
|
| 632 |
CfgParser::parse_skip_blank(CfgParserSource *source)
|
| 633 |
{
|
| 634 |
int c;
|
| 635 |
while (((c = source->getc()) != EOF) && isspace(c))
|
| ... |
|