From 01e5352c611599a1b27e44ed48dd5223ce0e4ecb Mon Sep 17 00:00:00 2001 From: heck Date: Wed, 14 Dec 2022 00:48:34 +0100 Subject: [PATCH] refactor: move functions used in tui and ged into base.h --- src/base.h | 33 +++++++++++++++++++++++++++++++++ src/tui_main.c | 21 --------------------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/base.h b/src/base.h index 6c3a55b..49245ce 100644 --- a/src/base.h +++ b/src/base.h @@ -1,4 +1,5 @@ #pragma once +#include #include #include #include @@ -76,6 +77,11 @@ typedef ssize_t Isz; typedef char Glyph; typedef U8 Mark; +enum +{ + Hud_height = 2 +}; + ORCA_FORCEINLINE static Usz orca_round_up_power2(Usz x) { assert(x <= SIZE_MAX / 2 + 1); @@ -114,3 +120,30 @@ static bool orca_is_valid_glyph(Glyph c) } return false; } + +static ORCA_FORCEINLINE double ms_to_sec(double ms) +{ + return ms / 1000.0; +} + + +// Reads something like '5x3' or '5'. Writes the same value to both outputs if +// only one is specified. Returns false on error. +staticni bool read_nxn_or_n(char const *str, int *out_a, int *out_b) +{ + int a, b; + int res = sscanf(str, "%dx%d", &a, &b); + if (res == EOF) + return false; + if (res == 1) { + *out_a = a; + *out_b = a; + return true; + } + if (res == 2) { + *out_a = a; + *out_b = b; + return true; + } + return false; +} diff --git a/src/tui_main.c b/src/tui_main.c index 8ed8027..1354ec5 100644 --- a/src/tui_main.c +++ b/src/tui_main.c @@ -2703,27 +2703,6 @@ staticni bool read_int(char const *str, int *out) return true; } -// Reads something like '5x3' or '5'. Writes the same value to both outputs if -// only one is specified. Returns false on error. -staticni bool read_nxn_or_n(char const *str, int *out_a, int *out_b) -{ - int a, b; - int res = sscanf(str, "%dx%d", &a, &b); - if (res == EOF) - return false; - if (res == 1) { - *out_a = a; - *out_b = a; - return true; - } - if (res == 2) { - *out_a = a; - *out_b = b; - return true; - } - return false; -} - typedef enum { Brackpaste_seq_none = 0,