| 633 | } |
| 634 | |
| 635 | int cbm_parse_dotenv_source(const char *source, cbm_dotenv_result_t *out) { |
| 636 | if (!source || !out) { |
| 637 | return CBM_NOT_FOUND; |
| 638 | } |
| 639 | memset(out, 0, sizeof(*out)); |
| 640 | |
| 641 | const char *p = source; |
| 642 | char line[CBM_SZ_4K]; |
| 643 | |
| 644 | while (*p) { |
| 645 | const char *eol = strchr(p, '\n'); |
| 646 | size_t line_len = eol ? (size_t)(eol - p) : strlen(p); |
| 647 | if (line_len >= sizeof(line)) { |
| 648 | line_len = sizeof(line) - SKIP_ONE; |
| 649 | } |
| 650 | memcpy(line, p, line_len); |
| 651 | line[line_len] = '\0'; |
| 652 | p = eol ? eol + SKIP_ONE : p + line_len; |
| 653 | |
| 654 | char *trimmed = line; |
| 655 | while (*trimmed == ' ' || *trimmed == '\t') { |
| 656 | trimmed++; |
| 657 | } |
| 658 | rtrim(trimmed); |
| 659 | |
| 660 | if (*trimmed == '\0' || *trimmed == '#') { |
| 661 | continue; |
| 662 | } |
| 663 | |
| 664 | parse_dotenv_line(trimmed, out); |
| 665 | } |
| 666 | |
| 667 | return (out->env_count > 0) ? 0 : IS_NOT_FOUND; |
| 668 | } |
| 669 | |
| 670 | /* ── Shell script parser ────────────────────────────────────────── */ |
| 671 |
no test coverage detected