diff options
Diffstat (limited to 'src/snapshot.c')
| -rw-r--r-- | src/snapshot.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/snapshot.c b/src/snapshot.c index 82a2805..8726265 100644 --- a/src/snapshot.c +++ b/src/snapshot.c @@ -78,8 +78,8 @@ static bool reserve(struct term_snapshot *s, int cols, int rows) /* Append a cluster record. The caller reserved room for it. */ static uint32_t arena_add(struct term_snapshot *s, const struct gstore *g, uint32_t handle) { - uint32_t cps[GRAPHEME_MAX_LEN]; - int n = term_gstore_expand(g, handle, cps, GRAPHEME_MAX_LEN); + uint32_t cps[TERM_GRAPHEME_MAX_LEN]; + int n = term_gstore_expand(g, handle, cps, TERM_GRAPHEME_MAX_LEN); if (n <= 0) return ' '; uint32_t off = s->arena_len; @@ -92,13 +92,13 @@ static uint32_t arena_add(struct term_snapshot *s, const struct gstore *g, uint3 /* Arena words that converting src adds. Counts what arena_add() writes. */ static uint64_t row_words(const struct gstore *g, const struct cell *src, int cols) { - uint32_t cps[GRAPHEME_MAX_LEN]; + uint32_t cps[TERM_GRAPHEME_MAX_LEN]; uint64_t words = 0; for (int x = 0; x < cols; x++) { uint32_t text = src[x].c; - if (!grapheme_is_handle(text)) + if (!term_grapheme_is_handle(text)) continue; - int n = term_gstore_expand(g, text, cps, GRAPHEME_MAX_LEN); + int n = term_gstore_expand(g, text, cps, TERM_GRAPHEME_MAX_LEN); if (n > 0) words += (uint64_t)n + 1; } @@ -117,7 +117,7 @@ static uint32_t convert_row(struct term_snapshot *s, const struct gstore *g, uint32_t text = c->c; if (TERM_EXPECT(text < 0x20, 0)) text = text ? ' ' : 0; - else if (TERM_EXPECT(grapheme_is_handle(text), 0)) + else if (TERM_EXPECT(term_grapheme_is_handle(text), 0)) text = arena_add(s, g, text); dst[x] = (struct term_cell){ .text = text, @@ -341,34 +341,36 @@ bool term_snapshot_update(struct term_snapshot *s, struct term *t) const struct term_view *term_snapshot_view(const struct term_snapshot *s) { - return &s->view; + return s ? &s->view : NULL; } const struct term_cell *term_snapshot_row(const struct term_snapshot *s, int y) { - if (y < 0 || y >= s->view.size.y) + if (!s || y < 0 || y >= s->view.size.y) return NULL; return s->cells + (size_t)y * s->view.size.x; } uint64_t term_snapshot_row_key(const struct term_snapshot *s, int y) { - if (y < 0 || y >= s->view.size.y) + if (!s || y < 0 || y >= s->view.size.y) return 0; return s->keys[y]; } struct term_span term_snapshot_row_selection(const struct term_snapshot *s, int y) { - if (y < 0 || y >= s->view.size.y) + if (!s || y < 0 || y >= s->view.size.y) return (struct term_span){ 0 }; return s->selection[y]; } int term_snapshot_cluster(const struct term_snapshot *s, uint32_t text, uint32_t *cps, int cap) { + if (!s) + return 0; if (!(text & TERM_TEXT_CLUSTER)) { - if (cap > 0) + if (cps && cap > 0) cps[0] = text; return 1; } @@ -377,7 +379,7 @@ int term_snapshot_cluster(const struct term_snapshot *s, uint32_t text, uint32_t return 0; int n = (int)s->arena[off]; int copy = n < cap ? n : cap; - if (copy > 0) + if (cps && copy > 0) memcpy(cps, &s->arena[off + 1], (size_t)copy * sizeof(*cps)); return n; } |
