Browse Source

refactor: move functions used in tui and ged into base.h

master
heck 2 years ago
parent
commit
01e5352c61
  1. 33
      src/base.h
  2. 21
      src/tui_main.c

33
src/base.h

@ -1,4 +1,5 @@
#pragma once
#include <stdio.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
@ -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;
}

21
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,

Loading…
Cancel
Save