char* parseConfigLine(char* line, matcher_line* p_line, const matcher_tags* tags) Parse out a config file line suitable for passing to a ControlMatcher object If successful, nullptr is returned. If unsuccessful, a static error string is returned
| 425 | // a static error string is returned |
| 426 | // |
| 427 | const char * |
| 428 | parseConfigLine(char *line, matcher_line *p_line, const matcher_tags *tags) |
| 429 | { |
| 430 | enum pState { |
| 431 | FIND_LABEL, |
| 432 | PARSE_LABEL, |
| 433 | PARSE_VAL, |
| 434 | START_PARSE_VAL, |
| 435 | CONSUME, |
| 436 | }; |
| 437 | |
| 438 | pState state = FIND_LABEL; |
| 439 | bool inQuote = false; |
| 440 | char *copyForward = nullptr; |
| 441 | char *copyFrom = nullptr; |
| 442 | char *s = line; |
| 443 | char *label = nullptr; |
| 444 | char *val = nullptr; |
| 445 | int num_el = 0; |
| 446 | matcher_type type = MATCH_NONE; |
| 447 | |
| 448 | // Zero out the parsed line structure |
| 449 | memset(p_line, 0, sizeof(matcher_line)); |
| 450 | |
| 451 | if (*s == '\0') { |
| 452 | return nullptr; |
| 453 | } |
| 454 | |
| 455 | do { |
| 456 | switch (state) { |
| 457 | case FIND_LABEL: |
| 458 | if (!isspace(*s)) { |
| 459 | state = PARSE_LABEL; |
| 460 | label = s; |
| 461 | } |
| 462 | s++; |
| 463 | break; |
| 464 | case PARSE_LABEL: |
| 465 | if (*s == '=') { |
| 466 | *s = '\0'; |
| 467 | state = START_PARSE_VAL; |
| 468 | } |
| 469 | s++; |
| 470 | break; |
| 471 | case START_PARSE_VAL: |
| 472 | // Init state needed for parsing values |
| 473 | copyForward = nullptr; |
| 474 | copyFrom = nullptr; |
| 475 | |
| 476 | if (*s == '"') { |
| 477 | inQuote = true; |
| 478 | val = s + 1; |
| 479 | } else if (*s == '\\') { |
| 480 | inQuote = false; |
| 481 | val = s + 1; |
| 482 | } else { |
| 483 | inQuote = false; |
| 484 | val = s; |
no test coverage detected