Commit: 25ca9d949d615106cd04d6e3d9851f67a6132976
Parent: 47c5162ea8bc27fd7e810a8b7cc02146c59783ac
Author: Randy Palamar
Date: Sun, 16 Feb 2025 20:31:49 -0700
cleanup Wextra warnings
Diffstat:
9 files changed, 77 insertions(+), 76 deletions(-)
diff --git a/build.sh b/build.sh
@@ -18,7 +18,7 @@ done
version="$(git describe --dirty --always)-${build}"
-cflags="-march=native -Wall -DVERSION=\"${version}\""
+cflags="-march=native -Wall -Wextra -Wno-unused-parameter -DVERSION=\"${version}\""
#cflags="${cflags} -fproc-stat-report"
#cflags="${cflags} -Rpass-missed=.*"
#cflags="${cflags} -fsanitize=address,undefined"
diff --git a/font.c b/font.c
@@ -253,7 +253,7 @@ render_glyph(Arena *a, FontAtlas *fa, u32 cp, u32 font_id, enum face_style style
uv2 tile_coord = unpack_gpu_tile_coord(cg->gpu_tile_index);
u32 tile_index = tile_coord.y * gc->tiles_in_x + tile_coord.x;
- if (tile_index != 0 && (tile_coord.x + cg->tile_count < gc->tiles_in_x)) {
+ if (tile_index != 0 && ((i32)tile_coord.x + cg->tile_count < gc->tiles_in_x)) {
/* NOTE: try to use the old tile directly */
if (gc->occupied_tiles[tile_index] ||
(cg->tile_count == 2 && gc->occupied_tiles[tile_index + 1]))
@@ -263,7 +263,7 @@ render_glyph(Arena *a, FontAtlas *fa, u32 cp, u32 font_id, enum face_style style
if (!tile_index) {
/* NOTE: there may be a fancier way to do this but we will see if this causes
* any performance issue in practice */
- u32 x = 1, y = 1;
+ i32 x = 1, y = 1;
u8 *occupied = gc->occupied_tiles;
for (y = 0; !tile_index && y < gc->tiles_in_y; y++) {
for (x = 0; !tile_index && x < gc->tiles_in_x; x++) {
diff --git a/platform_linux_aarch64.c b/platform_linux_aarch64.c
@@ -44,11 +44,11 @@
/* TODO: check that this is equivalent */
typedef u64 sys_fd_set[16];
-static FORCE_INLINE i64
+static FORCE_INLINE u64
syscall0(i64 n)
{
register i64 x8 asm("x8") = n;
- register i64 x0 asm("x0");
+ register u64 x0 asm("x0");
asm volatile ("svc 0"
: "=x"(x0)
: "x"(x8)
@@ -57,11 +57,11 @@ syscall0(i64 n)
return x0;
}
-static FORCE_INLINE i64
+static FORCE_INLINE u64
syscall1(i64 n, i64 a1)
{
register i64 x8 asm("x8") = n;
- register i64 x0 asm("x0") = a1;
+ register u64 x0 asm("x0") = a1;
asm volatile ("svc 0"
: "+x"(x0)
: "x"(x8)
@@ -70,11 +70,11 @@ syscall1(i64 n, i64 a1)
return x0;
}
-static FORCE_INLINE i64
+static FORCE_INLINE u64
syscall2(i64 n, i64 a1, i64 a2)
{
register i64 x8 asm("x8") = n;
- register i64 x0 asm("x0") = a1;
+ register u64 x0 asm("x0") = a1;
register i64 x1 asm("x1") = a2;
asm volatile ("svc 0"
: "+x"(x0)
@@ -84,11 +84,11 @@ syscall2(i64 n, i64 a1, i64 a2)
return x0;
}
-static FORCE_INLINE i64
+static FORCE_INLINE u64
syscall3(i64 n, i64 a1, i64 a2, i64 a3)
{
register i64 x8 asm("x8") = n;
- register i64 x0 asm("x0") = a1;
+ register u64 x0 asm("x0") = a1;
register i64 x1 asm("x1") = a2;
register i64 x2 asm("x2") = a3;
asm volatile ("svc 0"
@@ -99,11 +99,11 @@ syscall3(i64 n, i64 a1, i64 a2, i64 a3)
return x0;
}
-static FORCE_INLINE i64
+static FORCE_INLINE u64
syscall4(i64 n, i64 a1, i64 a2, i64 a3, i64 a4)
{
register i64 x8 asm("x8") = n;
- register i64 x0 asm("x0") = a1;
+ register u64 x0 asm("x0") = a1;
register i64 x1 asm("x1") = a2;
register i64 x2 asm("x2") = a3;
register i64 x3 asm("x3") = a4;
@@ -115,11 +115,11 @@ syscall4(i64 n, i64 a1, i64 a2, i64 a3, i64 a4)
return x0;
}
-static FORCE_INLINE i64
+static FORCE_INLINE u64
syscall5(i64 n, i64 a1, i64 a2, i64 a3, i64 a4, i64 a5)
{
register i64 x8 asm("x8") = n;
- register i64 x0 asm("x0") = a1;
+ register u64 x0 asm("x0") = a1;
register i64 x1 asm("x1") = a2;
register i64 x2 asm("x2") = a3;
register i64 x3 asm("x3") = a4;
@@ -132,11 +132,11 @@ syscall5(i64 n, i64 a1, i64 a2, i64 a3, i64 a4, i64 a5)
return x0;
}
-static FORCE_INLINE i64
+static FORCE_INLINE u64
syscall6(i64 n, i64 a1, i64 a2, i64 a3, i64 a4, i64 a5, i64 a6)
{
register i64 x8 asm("x8") = n;
- register i64 x0 asm("x0") = a1;
+ register u64 x0 asm("x0") = a1;
register i64 x1 asm("x1") = a2;
register i64 x2 asm("x2") = a3;
register i64 x3 asm("x3") = a4;
diff --git a/platform_linux_amd64.c b/platform_linux_amd64.c
@@ -46,10 +46,10 @@ typedef u64 sys_fd_set[16];
#define DIRENT_TYPE_OFF 18
#define DIRENT_NAME_OFF 19
-static FORCE_INLINE i64
+static FORCE_INLINE u64
syscall1(i64 n, i64 a1)
{
- i64 result;
+ u64 result;
asm volatile ("syscall"
: "=a"(result)
: "a"(n), "D"(a1)
@@ -58,7 +58,7 @@ syscall1(i64 n, i64 a1)
return result;
}
-static FORCE_INLINE i64
+static FORCE_INLINE u64
syscall2(i64 n, i64 a1, i64 a2)
{
i64 result;
@@ -70,10 +70,10 @@ syscall2(i64 n, i64 a1, i64 a2)
return result;
}
-static FORCE_INLINE i64
+static FORCE_INLINE u64
syscall3(i64 n, i64 a1, i64 a2, i64 a3)
{
- i64 result;
+ u64 result;
asm volatile ("syscall"
: "=a"(result)
: "a"(n), "D"(a1), "S"(a2), "d"(a3)
@@ -82,10 +82,10 @@ syscall3(i64 n, i64 a1, i64 a2, i64 a3)
return result;
}
-static FORCE_INLINE i64
+static FORCE_INLINE u64
syscall4(i64 n, i64 a1, i64 a2, i64 a3, i64 a4)
{
- i64 result;
+ u64 result;
register i64 r10 asm("r10") = a4;
asm volatile ("syscall"
: "=a"(result)
@@ -96,10 +96,10 @@ syscall4(i64 n, i64 a1, i64 a2, i64 a3, i64 a4)
}
-static FORCE_INLINE i64
+static FORCE_INLINE u64
syscall5(i64 n, i64 a1, i64 a2, i64 a3, i64 a4, i64 a5)
{
- i64 result;
+ u64 result;
register i64 r10 asm("r10") = a4;
register i64 r8 asm("r8") = a5;
asm volatile ("syscall"
@@ -110,7 +110,7 @@ syscall5(i64 n, i64 a1, i64 a2, i64 a3, i64 a4, i64 a5)
return result;
}
-static FORCE_INLINE i64
+static FORCE_INLINE u64
syscall6(i64 n, i64 a1, i64 a2, i64 a3, i64 a4, i64 a5, i64 a6)
{
i64 result;
diff --git a/platform_linux_common.c b/platform_linux_common.c
@@ -162,7 +162,7 @@ os_file_attribute_to_mode(u32 attr)
static iptr
os_open(u8 *name, u32 attr)
{
- iptr result = syscall4(SYS_openat, AT_FDCWD, (iptr)name, os_file_attribute_to_mode(attr), 0660);
+ u64 result = syscall4(SYS_openat, AT_FDCWD, (iptr)name, os_file_attribute_to_mode(attr), 0660);
if (result > -4096UL)
result = INVALID_FILE;
return result;
@@ -189,7 +189,7 @@ os_close(iptr file)
static PLATFORM_READ_FN(os_read)
{
- size r = 0, remaining = buffer.len, total_bytes_read = 0;
+ u64 r = 0, remaining = buffer.len, total_bytes_read = 0;
do {
remaining -= r;
@@ -205,8 +205,8 @@ static PLATFORM_READ_FILE_FN(os_read_file)
s8 result = {0};
statx_buffer sb;
- i32 fd = syscall4(SYS_openat, AT_FDCWD, (iptr)path, O_RDONLY, 0);
- i64 status = syscall5(SYS_statx, fd, 0, AT_EMPTY_PATH, STATX_SIZE, (iptr)sb);
+ u64 fd = syscall4(SYS_openat, AT_FDCWD, (iptr)path, O_RDONLY, 0);
+ u64 status = syscall5(SYS_statx, fd, 0, AT_EMPTY_PATH, STATX_SIZE, (iptr)sb);
if (fd <= -4096UL && status == 0) {
result = s8alloc(a, STATX_FILE_SIZE(sb));
@@ -229,7 +229,7 @@ os_block_alloc(size requested_size)
if (alloc_size % PAGE_SIZE != 0)
alloc_size += PAGE_SIZE - alloc_size % PAGE_SIZE;
- i64 memory = syscall6(SYS_mmap, 0, alloc_size, PROT_RW, MAP_ANON|MAP_PRIVATE, -1, 0);
+ u64 memory = syscall6(SYS_mmap, 0, alloc_size, PROT_RW, MAP_ANON|MAP_PRIVATE, -1, 0);
if (memory <= -4096UL) {
result.memory = (void *)memory;
result.size = alloc_size;
@@ -273,11 +273,11 @@ os_map_file(char *path, i32 mode, i32 perm)
}
statx_buffer sb;
- i32 fd = syscall4(SYS_openat, AT_FDCWD, (iptr)path, open_mode, 0);
- i64 status = syscall5(SYS_statx, fd, 0, AT_EMPTY_PATH, STATX_SIZE, (iptr)sb);
+ u64 fd = syscall4(SYS_openat, AT_FDCWD, (iptr)path, open_mode, 0);
+ u64 status = syscall5(SYS_statx, fd, 0, AT_EMPTY_PATH, STATX_SIZE, (iptr)sb);
if (fd <= -4096UL && status == 0) {
- i64 memory = syscall6(SYS_mmap, 0, STATX_FILE_SIZE(sb), mode, perm, fd, 0);
+ u64 memory = syscall6(SYS_mmap, 0, STATX_FILE_SIZE(sb), mode, perm, fd, 0);
if (memory <= -4096UL) {
result.data = (u8 *)memory;
result.len = STATX_FILE_SIZE(sb);
@@ -295,7 +295,7 @@ static PLATFORM_ALLOCATE_RING_BUFFER_FN(os_allocate_ring_buffer)
capacity += PAGE_SIZE - capacity % PAGE_SIZE;
ASSERT(capacity % PAGE_SIZE == 0);
- i32 fd = syscall2(SYS_memfd_create, (iptr)"vtgl:rb", MFD_CLOEXEC);
+ u64 fd = syscall2(SYS_memfd_create, (iptr)"vtgl:rb", MFD_CLOEXEC);
if (fd > -4096UL) os_fatal(s8("os_alloc_ring_buffer: failed to open mem_fd\n"));
syscall2(SYS_ftruncate, fd, capacity);
@@ -303,12 +303,12 @@ static PLATFORM_ALLOCATE_RING_BUFFER_FN(os_allocate_ring_buffer)
rb->filled = 0;
rb->cap = capacity;
rb->buf = (u8 *)syscall6(SYS_mmap, 0, (iptr)(3 * rb->cap), 0, MAP_ANON|MAP_PRIVATE, -1, 0);
- if ((iptr)rb->buf > -4096UL)
+ if ((u64)rb->buf > -4096UL)
os_fatal(s8("os_alloc_ring_buffer: initial mmap failed\n"));
syscall3(SYS_madvise, (iptr)rb->buf, 3 * rb->cap, MADV_HUGEPAGE);
for (i32 i = 0; i < 3; i++) {
- i64 memory = syscall6(SYS_mmap, (iptr)(rb->buf + i * rb->cap), rb->cap, PROT_RW,
+ u64 memory = syscall6(SYS_mmap, (iptr)(rb->buf + i * rb->cap), rb->cap, PROT_RW,
MAP_FIXED|MAP_SHARED, fd, 0);
if (memory > -4096UL) {
u8 buf[256];
@@ -340,7 +340,7 @@ os_fork_child(s8 cmd, c8 **envp)
/* NOTE: we open in non-blocking mode so that we can try and fully drain the pipe
* before processing. Otherwise a single read will be limited to the page size */
- i64 m = syscall4(SYS_openat, AT_FDCWD, (iptr)"/dev/ptmx", O_RDWR|O_NOCTTY|O_NONBLOCK|O_CLOEXEC, 0);
+ u64 m = syscall4(SYS_openat, AT_FDCWD, (iptr)"/dev/ptmx", O_RDWR|O_NOCTTY|O_NONBLOCK|O_CLOEXEC, 0);
if (m > -4096UL) os_fatal(s8("os_fork_child: failed to open master terminal\n"));
/* NOTE: first unlock the tty, then get a valid pty number */
if (syscall3(SYS_ioctl, m, TIOCSPTLCK, (iptr)&n) || syscall3(SYS_ioctl, m, TIOCGPTN, (iptr)&n))
@@ -351,10 +351,10 @@ os_fork_child(s8 cmd, c8 **envp)
stream_push_i64(&sbuf, n);
stream_push_byte(&sbuf, 0);
- i64 s = syscall4(SYS_openat, AT_FDCWD, (iptr)sbuf.buf, O_RDWR|O_NOCTTY, 0);
+ u64 s = syscall4(SYS_openat, AT_FDCWD, (iptr)sbuf.buf, O_RDWR|O_NOCTTY, 0);
if (s > -4096UL) os_fatal(s8("os_fork_child: failed to open slave terminal\n"));
- i64 pid = syscall2(SYS_clone, SIGCHLD, 0);
+ u64 pid = syscall2(SYS_clone, SIGCHLD, 0);
if (pid > -4096UL) os_fatal(s8("os_fork_child: failed to fork a child\n"));
if (pid == 0) {
@@ -388,7 +388,7 @@ static PLATFORM_SET_TERMINAL_SIZE_FN(os_set_terminal_size)
static PLATFORM_ADD_FILE_WATCH_FN(linux_add_file_watch)
{
- i32 wd = syscall3(SYS_inotify_add_watch, linux_ctx.inotify_fd, (iptr)path, LINUX_INOTIFY_MASK);
+ u64 wd = syscall3(SYS_inotify_add_watch, linux_ctx.inotify_fd, (iptr)path, LINUX_INOTIFY_MASK);
if (wd <= -4096UL) {
statx_buffer sb;
syscall5(SYS_statx, AT_FDCWD, (iptr)path, 0, STATX_INO, (iptr)sb);
@@ -417,7 +417,7 @@ try_deferred_file_loads(PlatformCtx *ctx)
LINUX_INOTIFY_MASK);
fw->inode = STATX_INODE(sb);
- if (fw->handle <= -4096UL) {
+ if ((u64)fw->handle <= -4096UL) {
fw->fn(fw->path, fw->user_ctx);
file->last->next = file->next;
file->next = ctx->file_reload_free_list;
@@ -446,7 +446,7 @@ defer_file_reload(PlatformCtx *ctx, i32 file_watch_index, statx_buffer *sb)
fw->inode = STATX_INODE(*sb);
fw->handle = syscall3(SYS_inotify_add_watch, ctx->inotify_fd, (iptr)fw->path, LINUX_INOTIFY_MASK);
- if (fw->handle > -4096UL) {
+ if ((u64)fw->handle > -4096UL) {
result = 0;
linux_deferred_file_reload_queue *new = ctx->file_reload_free_list;
@@ -490,7 +490,7 @@ dispatch_file_watch_events(PlatformCtx *ctx)
* completely and thus the inode will change; here we
* detect that and restart the watch */
statx_buffer sb;
- i64 status = syscall5(SYS_statx, AT_FDCWD, (iptr)fw->path, 0, STATX_INO, (iptr)sb);
+ u64 status = syscall5(SYS_statx, AT_FDCWD, (iptr)fw->path, 0, STATX_INO, (iptr)sb);
if (status > -4096UL || fw->inode != STATX_INODE(sb)) {
syscall2(SYS_inotify_rm_watch, ctx->inotify_fd, fw->handle);
@@ -507,7 +507,7 @@ dispatch_file_watch_events(PlatformCtx *ctx)
static struct stack_base *
new_stack(size capacity)
{
- i64 p = syscall6(SYS_mmap, 0, capacity, PROT_RW, MAP_ANON|MAP_PRIVATE, -1, 0);
+ u64 p = syscall6(SYS_mmap, 0, capacity, PROT_RW, MAP_ANON|MAP_PRIVATE, -1, 0);
if (p > -4096UL)
os_fatal(s8("new_stack: mmap failed\n"));
i64 count = capacity / sizeof(struct stack_base);
diff --git a/terminal.c b/terminal.c
@@ -164,7 +164,7 @@ selection_clear(Selection *s)
}
static void
-selection_scroll(Term *t, u32 origin, i32 n)
+selection_scroll(Term *t, i32 origin, i32 n)
{
Selection *s = &t->selection;
if (!is_valid_range(s->range))
@@ -196,7 +196,7 @@ is_selected(Selection *s, i32 x, i32 y)
}
static b32
-selection_intersects_region(Selection *s, uv2 tl, uv2 br)
+selection_intersects_region(Selection *s, iv2 tl, iv2 br)
{
/* TODO: maybe this can be further simplified (eg. with a k-map) */
Range r = s->range;
@@ -211,7 +211,7 @@ selection_intersects_region(Selection *s, uv2 tl, uv2 br)
}
static void
-fb_clear_region(Term *t, u32 r1, u32 r2, u32 c1, u32 c2)
+fb_clear_region(Term *t, i32 r1, i32 r2, i32 c1, i32 c2)
{
BEGIN_TIMED_BLOCK();
u32 tmp;
@@ -230,8 +230,8 @@ fb_clear_region(Term *t, u32 r1, u32 r2, u32 c1, u32 c2)
CLAMP(r1, 0, t->size.h - 1);
CLAMP(r2, 0, t->size.h - 1);
- uv2 top_left = {.x = c1, .y = r1};
- uv2 bottom_right = {.x = c2, .y = r2};
+ iv2 top_left = {.x = c1, .y = r1};
+ iv2 bottom_right = {.x = c2, .y = r2};
if (selection_intersects_region(&t->selection, top_left, bottom_right))
selection_clear(&t->selection);
@@ -239,8 +239,8 @@ fb_clear_region(Term *t, u32 r1, u32 r2, u32 c1, u32 c2)
CellStyle cursor_style = t->cursor.style;
u32 fg = SHADER_PACK_FG(cursor_style.fg.rgba, cursor_style.attr);
u32 bg = SHADER_PACK_BG(cursor_style.bg.rgba, cursor_style.attr);
- for (u32 r = top_left.y; r <= bottom_right.y; r++) {
- for (u32 c = top_left.x; c <= bottom_right.x; c++) {
+ for (i32 r = top_left.y; r <= bottom_right.y; r++) {
+ for (i32 c = top_left.x; c <= bottom_right.x; c++) {
rows[r][c].fg = fg;
rows[r][c].bg = bg;
rows[r][c].cp = ' ';
@@ -251,7 +251,7 @@ fb_clear_region(Term *t, u32 r1, u32 r2, u32 c1, u32 c2)
}
static void
-fb_scroll_down(Term *t, u32 top, u32 n)
+fb_scroll_down(Term *t, i32 top, i32 n)
{
BEGIN_TIMED_BLOCK();
if (!BETWEEN(top, t->top, t->bot))
@@ -261,7 +261,7 @@ fb_scroll_down(Term *t, u32 top, u32 n)
CLAMP(n, 0, t->bot - top);
fb_clear_region(t, t->bot - n + 1, t->bot, 0, t->size.w);
- for (u32 i = t->bot; i >= top + n; i--) {
+ for (i32 i = t->bot; i >= top + n; i--) {
Row tmp = tv->fb.rows[i];
tv->fb.rows[i] = tv->fb.rows[i - n];
tv->fb.rows[i - n] = tmp;
@@ -272,7 +272,7 @@ end:
}
static void
-fb_scroll_up(Term *t, u32 top, u32 n)
+fb_scroll_up(Term *t, i32 top, i32 n)
{
BEGIN_TIMED_BLOCK();
if (!BETWEEN(top, t->top, t->bot))
@@ -288,7 +288,7 @@ fb_scroll_up(Term *t, u32 top, u32 n)
fb_clear_region(t, t->bot - n + 1, t->bot, 0, t->size.w);
#else
fb_clear_region(t, top, top + n - 1, 0, t->size.w);
- for (u32 i = top; i <= t->bot - n; i++) {
+ for (i32 i = top; i <= t->bot - n; i++) {
Row tmp = tv->fb.rows[i];
tv->fb.rows[i] = tv->fb.rows[i + n];
tv->fb.rows[i + n] = tmp;
@@ -400,7 +400,7 @@ next_tab_position(Term *t, b32 backwards)
u32 bit = col % ARRAY_COUNT(t->tabs);
u32 mask = safe_left_shift(1, bit - backwards) - 1;
- u32 result = 32 * idx;
+ i32 result = 32 * idx;
if (backwards) {
u32 zeroes = clz_u32(t->tabs[idx--] & mask);
while (idx < ARRAY_COUNT(t->tabs) && zeroes == 32)
@@ -419,11 +419,11 @@ next_tab_position(Term *t, b32 backwards)
}
static void
-term_tab_col(Term *t, u32 col, b32 set)
+term_tab_col(Term *t, i32 col, b32 set)
{
ASSERT(col < t->size.w);
- u32 idx = col ? ((col - 1) / ARRAY_COUNT(t->tabs)) : 0;
- u32 bit = col ? ((col - 1) % ARRAY_COUNT(t->tabs)) : 0;
+ u32 idx = (col > 0) ? ((col - 1) / ARRAY_COUNT(t->tabs)) : 0;
+ u32 bit = (col > 0) ? ((col - 1) % ARRAY_COUNT(t->tabs)) : 0;
u32 mask = 1u;
if (bit) mask = safe_left_shift(1, bit);
if (set) t->tabs[idx] |= mask;
@@ -433,9 +433,9 @@ term_tab_col(Term *t, u32 col, b32 set)
static void
reset_tabs(Term *t, u32 column_step)
{
- for (u32 i = 0; i < ARRAY_COUNT(t->tabs); i++)
+ for (i32 i = 0; i < ARRAY_COUNT(t->tabs); i++)
t->tabs[i] = 0;
- for (u32 i = column_step; i < t->size.w; i += column_step)
+ for (i32 i = column_step; i < t->size.w; i += column_step)
term_tab_col(t, i, 1);
}
@@ -660,6 +660,7 @@ set_mode(Term *t, CSI *csi, b32 set, ModeState src, ModeState *dest)
break;
case PRIV(1049): /* xterm: swap cursor then swap screen */
cursor_alt(t, set);
+ /* FALLTHROUGH */
case PRIV(47): /* xterm: swap screen buffer */
case PRIV(1047): /* xterm: swap screen buffer */
if (alt) fb_clear_region(t, 0, t->size.h, 0, t->size.w);
@@ -1256,7 +1257,7 @@ push_normal_cp(Term *t, TermView *tv, u32 cp)
if (t->cursor.charsets[t->cursor.charset_index] == CS_GRAPHIC0 && BETWEEN(cp, 0x60, 0x7e))
cp = graphic_0[cp - 0x60];
- u32 width = 1;
+ i32 width = 1;
if (cp > 0x7F) {
width = wcwidth(cp);
ASSERT(width != -1);
@@ -1403,7 +1404,7 @@ handle_input(Term *t, Arena a, s8 raw)
t->csi.raw.len++;
if (BETWEEN(cp, '@', '~')) {
i32 old_curs_y = t->cursor.pos.y;
- i32 mode = t->mode.term & TM_ALTSCREEN;
+ u32 mode = t->mode.term & TM_ALTSCREEN;
handle_csi(t, &t->csi);
t->escape &= ~EM_CSI;
if ((t->mode.term & TM_ALTSCREEN) != mode) {
diff --git a/util.h b/util.h
@@ -300,7 +300,7 @@ typedef struct {
iv2 cursor;
iv2 next;
iv2 end;
- u32 term_width;
+ i32 term_width;
} SelectionIterator;
enum face_style {
@@ -357,8 +357,8 @@ typedef struct {
u8 *occupied_tiles;
u32 cache_len;
GlyphCacheStats stats;
- u32 tiles_in_x;
- u32 tiles_in_y;
+ i32 tiles_in_x;
+ i32 tiles_in_y;
} GlyphCache;
typedef struct {
@@ -477,7 +477,7 @@ typedef struct Term {
iv2 size;
/* NOTE: scrolling region */
- u32 top, bot;
+ i32 top, bot;
CSI csi;
diff --git a/vtgl.c b/vtgl.c
@@ -497,8 +497,8 @@ render_framebuffer(Term *t, RenderCell *render_buf, TerminalInput *input, Arena
TermView *tv = t->views + t->view_idx;
iv2 term_size = t->size;
/* NOTE: draw whole framebuffer */
- for (u32 row = 0; row < term_size.h; row++) {
- for (u32 col = 0; col < term_size.w; col++) {
+ for (i32 row = 0; row < term_size.h; row++) {
+ for (i32 col = 0; col < term_size.w; col++) {
Cell c = tv->fb.rows[row][col];
RenderCell *rc = render_buf + (row * term_size.w + col);
@@ -619,7 +619,7 @@ static void
begin_selection(Term *t, u32 click_count, v2 mouse)
{
Selection *sel = &t->selection;
- sel->state = CLAMP(click_count, SS_NONE, SS_WORDS);
+ sel->state = MIN(click_count, SS_WORDS);
sel->range.end = INVALID_RANGE_END;
iv2 cell = mouse_to_cell_space(t, mouse);
diff --git a/vtgl.h b/vtgl.h
@@ -27,7 +27,7 @@
#define KB(a) ((a) << 10ULL)
#define MB(a) ((a) << 20ULL)
-#define ARRAY_COUNT(a) (sizeof(a) / sizeof(*a))
+#define ARRAY_COUNT(a) (size)(sizeof(a) / sizeof(*a))
#define ABS(a) ((a) < 0 ? (-a) : (a))
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define CLAMP(x, a, b) ((x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x))
@@ -37,7 +37,7 @@
#define SAFE_RATIO_1(a, b) ((b) ? (a) / (b) : (a))
-#define ISCONTROLC0(c) (BETWEEN((c), 0, 0x1F) || (c) == 0x7F)
+#define ISCONTROLC0(c) ((c) <= 0x1F || (c) == 0x7F)
#define ISCONTROLC1(c) (BETWEEN((c), 0x80, 0x9F))
#define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c))
#define ISSPACE(c) ((c) == ' ' || (c) == '\n' || (c) == '\t')
@@ -337,8 +337,8 @@ enum modifiers {
typedef struct {
/* TODO: is this even supported or does GLFW only call you once per poll? */
- i16 transitions;
- i16 ended_down;
+ u16 transitions;
+ u16 ended_down;
} ButtonState;
typedef struct TerminalInput {