From 212f1cc9109aa0deb9e5d990bb2dba2b167618fb Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Thu, 15 Oct 2026 12:31:21 +0300 Subject: Keep installed headers from shadowing or polluting host names The pkg-config file put include/term on the host's include path, so ncurses' term.h could be picked up in place of ours. Hosts now write and the package adds only its include directory. The installed Unicode API had unprefixed names that collide with host symbols and macros. Rename them: term_ for functions, types, and static tables, TERM_ for macros and include guards. unicode_data.inc and tools/generate_unicode.py are renamed to match. The generator's inputs here are Unicode 15.1 and the checked-in table is 18.0.0, so the table data was not regenerated. Only the declarations were checked against the generator. utf8.h casts the malloc result so it compiles as C++. header_test.sh now includes with only include/ on the path. It also checks that a host which defines unicode_width, UTF8_ACCEPT, GRAPHEME_MAX_LEN, in_ranges, and similar names compiles with the Unicode headers as C11 and C++, in both declaration orders. Co-Authored-By: Claude Haiku 5.5 --- src/text.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'src/text.c') diff --git a/src/text.c b/src/text.c index 43c3ef5..e41a2e5 100644 --- a/src/text.c +++ b/src/text.c @@ -50,15 +50,15 @@ static inline void emit_decoded(struct term *t, uint32_t cp, uint16_t flags) * sequence prints U+FFFD (Unicode 3.9, maximal subparts). */ void term_text_utf8_interrupt(struct term *t) { - if (TERM_EXPECT(t->utf8_state == UTF8_ACCEPT, 1)) + if (TERM_EXPECT(t->utf8_state == TERM_UTF8_ACCEPT, 1)) return; - t->utf8_state = UTF8_ACCEPT; + t->utf8_state = TERM_UTF8_ACCEPT; emit_decoded(t, 0xFFFD, term_current_flags(t)); } void term_text_ground(struct term *t, unsigned char ch) { - if (ch >= 0x20 && ch < 0x7f && t->utf8_state == UTF8_ACCEPT) { + if (ch >= 0x20 && ch < 0x7f && t->utf8_state == TERM_UTF8_ACCEPT) { emit_codepoint(t, ch, 1, term_current_flags(t)); return; } @@ -92,14 +92,14 @@ void term_text_ground(struct term *t, unsigned char ch) t->graphics = t->charsets[0] == '0'; } else if (ch >= 0x20 && ch != 0x7f) { uint32_t before = t->utf8_state; - uint32_t st = utf8_decode(&t->utf8_state, &t->utf8_codep, ch); - if (st == UTF8_ACCEPT) { + uint32_t st = term_utf8_decode(&t->utf8_state, &t->utf8_codep, ch); + if (st == TERM_UTF8_ACCEPT) { emit_decoded(t, t->utf8_codep, term_current_flags(t)); - } else if (st == UTF8_REJECT) { - t->utf8_state = UTF8_ACCEPT; + } else if (st == TERM_UTF8_REJECT) { + t->utf8_state = TERM_UTF8_ACCEPT; emit_decoded(t, 0xFFFD, term_current_flags(t)); /* The byte that ended an unfinished sequence starts anew. */ - if (before != UTF8_ACCEPT) + if (before != TERM_UTF8_ACCEPT) term_text_ground(t, ch); } } @@ -109,7 +109,7 @@ static inline bool can_stream_bottom(const struct term *t) { return t->state == ST_GROUND && !t->graphics && !t->insert_mode && t->autowrap && !t->lr_margin_mode && - t->utf8_state == UTF8_ACCEPT && !t->inverse && + t->utf8_state == TERM_UTF8_ACCEPT && !t->inverse && t->scroll_top == 0 && t->scroll_bottom == t->rows - 1 && t->cursor_y == t->rows - 1 && !t->alternate && t->sb_capacity > 0 && @@ -123,14 +123,14 @@ static inline bool try_text_run(struct term *t, const char *buf, size_t len, if (t->pending_wrap || i + 4 > len || ((unsigned char)buf[i] >= 0x80 && ((unsigned char)buf[i] < 0xc2 || (unsigned char)buf[i] > 0xf4)) || - t->last_char == 0x200D || grapheme_is_handle(t->last_char)) + t->last_char == 0x200D || term_grapheme_is_handle(t->last_char)) return false; if (t->cursor_x != 0 && t->cursor_x != term_row(t, t->cursor_y)->len) return false; if ((unsigned char)buf[i] >= 0x80) { uint32_t cp; - int bytes = utf8_decode_one(buf + i, len - i, &cp); + int bytes = term_utf8_decode_one(buf + i, len - i, &cp); if (!bytes || term_text_class(cp) <= 0) return false; } @@ -181,7 +181,7 @@ static inline bool try_text_run(struct term *t, const char *buf, size_t len, newline = true; } if (!newline || i + 4 > len || t->pending_wrap || - t->last_char == 0x200D || grapheme_is_handle(t->last_char) || + t->last_char == 0x200D || term_grapheme_is_handle(t->last_char) || (t->cursor_x != 0 && t->cursor_x != term_row(t, t->cursor_y)->len)) break; @@ -212,7 +212,7 @@ static void term_feed_inner(struct term *t, const char *buf, size_t len, unsigne unsigned char ch = (unsigned char)buf[i]; if (TERM_EXPECT(ch >= 0x20 && ch < 0x7f && !t->insert_mode && !t->lr_margin_mode && t->state == ST_GROUND && !t->graphics && - t->utf8_state == UTF8_ACCEPT, 1)) { + t->utf8_state == TERM_UTF8_ACCEPT, 1)) { int avail = t->pending_wrap ? t->cols : t->cols - t->cursor_x; int rem = (int)(len - i); if (rem > avail) rem = avail; @@ -239,7 +239,7 @@ static void term_feed_inner(struct term *t, const char *buf, size_t len, unsigne (unsigned char)buf[i + 1] <= 0xf4 && (i + 2 == len || ((unsigned char)buf[i + 2] & 0xc0) == 0x80)) { uint32_t next_cp; - if (utf8_decode_one(buf + i + 1, len - i - 1, &next_cp) && + if (term_utf8_decode_one(buf + i + 1, len - i - 1, &next_cp) && term_text_class(next_cp) > 0 && try_text_run(t, buf, len, &i)) continue; @@ -249,7 +249,7 @@ static void term_feed_inner(struct term *t, const char *buf, size_t len, unsigne } if (i + (size_t)run < len && (unsigned char)buf[i + run] >= 0x80) { uint32_t next_cp; - if (utf8_decode_one(buf + i + run, len - i - (size_t)run, &next_cp) && + if (term_utf8_decode_one(buf + i + run, len - i - (size_t)run, &next_cp) && term_text_class(next_cp) > 0 && try_text_run(t, buf, len, &i)) continue; @@ -274,21 +274,21 @@ static void term_feed_inner(struct term *t, const char *buf, size_t len, unsigne if (TERM_EXPECT(ch >= 0x80, 1)) { if (TERM_EXPECT(t->state == ST_GROUND && - t->utf8_state == UTF8_ACCEPT && !t->graphics, 1)) { + t->utf8_state == TERM_UTF8_ACCEPT && !t->graphics, 1)) { if (ch >= 0xc2 && ch <= 0xf4 && (i + 1 == len || ((unsigned char)buf[i + 1] & 0xc0) == 0x80)) { if (!t->insert_mode && !t->lr_margin_mode && try_text_run(t, buf, len, &i)) continue; } else { - if (TERM_EXPECT(t->last_char != 0x200D && !grapheme_is_handle(t->last_char), 1)) + if (TERM_EXPECT(t->last_char != 0x200D && !term_grapheme_is_handle(t->last_char), 1)) sc_print_cell(t, 0xFFFD, 1, cur_flags); else emit_decoded(t, 0xFFFD, cur_flags); continue; } uint32_t cp; - int cp_len = utf8_decode_ground(&t->utf8_state, &t->utf8_codep, buf + i, len - i, &cp); + int cp_len = term_utf8_decode_ground(&t->utf8_state, &t->utf8_codep, buf + i, len - i, &cp); if (cp) emit_decoded(t, cp, cur_flags); i += (size_t)(cp_len - 1); @@ -328,7 +328,7 @@ static void term_feed_inner(struct term *t, const char *buf, size_t len, unsigne } continue; case 0x1b: - if (t->utf8_state == UTF8_ACCEPT && i + 1 < len && + if (t->utf8_state == TERM_UTF8_ACCEPT && i + 1 < len && buf[i + 1] == '[' && !t->insert_mode && !t->lr_margin_mode && !t->graphics) { int fast = term_try_fast_csi(t, buf + i + 2, len - i - 2); -- cgit v1.2.3