diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2021-09-23 13:38:20 -0700 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2021-09-23 13:38:20 -0700 |
| commit | cf99abb852536867169168d2c7fabf158099dfd9 (patch) | |
| tree | bf0f33da9f5ec02d9297e52ba83146edda9d9610 /print.c | |
| parent | 55ff8ec6637d90d50ed83c43f83e25fe4571f6bb (diff) | |
WIP implementation of setjmp/longjmp recovery
Diffstat (limited to 'print.c')
| -rw-r--r-- | print.c | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -56,9 +56,9 @@ static void print_between(FILE *out, printer_t *pr, const char *start, const cha { file_t *f = pr->file; while (start < end) { - size_t line_num = get_line_number(f, start); + size_t line_num = f ? get_line_number(f, start) : 0; print_line_number(out, pr, line_num, color, 0); - const char *eol = get_line(pr->file, line_num + 1); + const char *eol = f ? get_line(f, line_num + 1) : end; if (!eol || eol > end) eol = end; if (color && color != current_color) { fprintf(out, "%s", color); @@ -118,8 +118,8 @@ static void _print_match(FILE *out, printer_t *pr, match_t *m) { pr->pos = m->start; if (m->pat->type == BP_REPLACE) { - size_t line = get_line_number(pr->file, m->start); - size_t line_end = get_line_number(pr->file, m->end); + size_t line = pr->file ? get_line_number(pr->file, m->start) : 0; + size_t line_end = pr->file ? get_line_number(pr->file, m->end) : 0; if (pr->use_color && current_color != color_replace) { fprintf(out, "%s", color_replace); @@ -232,7 +232,7 @@ void print_match(FILE *out, printer_t *pr, match_t *m) current_color = color_normal; bool first = (pr->pos == NULL); if (first) { // First match printed: - pr->pos = pr->file->start; + pr->pos = pr->file ? pr->file->start : m->start; pr->needs_line_number = 1; } if (m) { |
