| 34 | /* ── Pattern parsing ─────────────────────────────────────────────── */ |
| 35 | |
| 36 | static void gi_add_pattern(cbm_gitignore_t *gi, const char *line, int len) { |
| 37 | gi_view_t view; |
| 38 | if (!gi_normalize(line, (size_t)len, &view, NULL) || !view.length) { |
| 39 | return; |
| 40 | } |
| 41 | gi_pattern_t p = {.negated = view.negated, .dir_only = view.dir_only, .rooted = view.rooted}; |
| 42 | const char *start = view.text; |
| 43 | len = (int)view.length; |
| 44 | |
| 45 | /* Copy pattern */ |
| 46 | p.pattern = malloc(len + SKIP_ONE); |
| 47 | if (!p.pattern) { |
| 48 | return; |
| 49 | } |
| 50 | memcpy(p.pattern, start, len); |
| 51 | p.pattern[len] = '\0'; |
| 52 | |
| 53 | /* Grow array if needed */ |
| 54 | if (gi->count >= gi->capacity) { |
| 55 | int new_cap = gi->capacity ? gi->capacity * PAIR_LEN : GI_INIT_CAP; |
| 56 | gi_pattern_t *new_patterns = realloc(gi->patterns, new_cap * sizeof(gi_pattern_t)); |
| 57 | if (!new_patterns) { |
| 58 | free(p.pattern); |
| 59 | return; |
| 60 | } |
| 61 | gi->patterns = new_patterns; |
| 62 | gi->capacity = new_cap; |
| 63 | } |
| 64 | |
| 65 | gi->patterns[gi->count++] = p; |
| 66 | } |
| 67 | |
| 68 | /* ── Public API ──────────────────────────────────────────────────── */ |
| 69 |
no test coverage detected