mirror of
https://github.com/Ed94/metadesk.git
synced 2026-06-13 07:52:22 -07:00
updating base with stuff missing from metagens's base (was in the regular base of raddbg)
This commit is contained in:
Vendored
+3
-1
@@ -37,7 +37,9 @@
|
||||
"stb_sprintf.h": "c",
|
||||
"base_types.h": "c",
|
||||
"platform.h": "c",
|
||||
"macros.h": "c"
|
||||
"macros.h": "c",
|
||||
"linkage.h": "c",
|
||||
"context_cracking.h": "c"
|
||||
},
|
||||
"workbench.colorCustomizations": {
|
||||
"activityBar.activeBackground": "#713fb8",
|
||||
|
||||
@@ -94,3 +94,280 @@ typedef S16 B16;
|
||||
typedef S32 B32;
|
||||
|
||||
typedef void VoidProc(void);
|
||||
|
||||
////////////////////////////////
|
||||
//~ NOTE(allen): Constants
|
||||
|
||||
#define SIGN32 0x80000000;
|
||||
#define EXPONENT32 0x7F800000;
|
||||
#define MANTISSA32 0x007FFFFF;
|
||||
|
||||
#define BIG_GOLDEN32 1.61803398875f;
|
||||
#define SMALL_GOLDEN32 0.61803398875f;
|
||||
|
||||
#define PI32 3.1415926535897f;
|
||||
|
||||
#define MACHINE_EPSILON64 4.94065645841247e-324;
|
||||
|
||||
#define MIN_U8 0u
|
||||
#define MAX_U8 0xffu
|
||||
#define MIN_S8 ( -0x7f - 1 )
|
||||
#define MAX_S8 0x7f
|
||||
|
||||
#define MIN_U16 0u
|
||||
#define MAX_U16 0xffffu
|
||||
#define MIN_S16 ( -0x7fff - 1 )
|
||||
#define MAX_S16 0x7fff
|
||||
|
||||
#define MIN_U32 0u
|
||||
#define MAX_U32 0xffffffffu
|
||||
#define MIN_S32 ( -0x7fffffff - 1 )
|
||||
#define MAX_S32 0x7fffffff
|
||||
|
||||
#define MIN_U64 0ull
|
||||
#define MAX_U64 0xffffffffffffffffull
|
||||
#define MIN_S64 ( -0x7fffffffffffffffll - 1 )
|
||||
#define MAX_S64 0x7fffffffffffffffll
|
||||
|
||||
#if ARCH_32BIT
|
||||
# define MIN_USIZE U32_MIN
|
||||
# define MAX_USIZE U32_MAX
|
||||
# define MIN_ISIZE S32_MIN
|
||||
# define MAX_ISIZE S32_MAX
|
||||
#elif ARCH_64BIT
|
||||
# define MIN_USIZE U64_MIN
|
||||
# define MAX_USIZE U64_MAX
|
||||
# define MIN_ISIZE S64_MIN
|
||||
# define MAX_ISIZE S64_MAX
|
||||
#else
|
||||
# error Unknown architecture size. This library only supports 32 bit and 64 bit architectures.
|
||||
#endif
|
||||
|
||||
#define MIN_F32 1.17549435e-38f
|
||||
#define MAX_F32 3.40282347e+38f
|
||||
#define MIN_F64 2.2250738585072014e-308
|
||||
#define MAX_F64 1.7976931348623157e+308
|
||||
|
||||
#define BITMASK1 0x00000001
|
||||
#define BITMASK2 0x00000003
|
||||
#define BITMASK3 0x00000007
|
||||
#define BITMASK4 0x0000000f
|
||||
#define BITMASK5 0x0000001f
|
||||
#define BITMASK6 0x0000003f
|
||||
#define BITMASK7 0x0000007f
|
||||
#define BITMASK8 0x000000ff
|
||||
#define BITMASK9 0x000001ff
|
||||
#define BITMASK10 0x000003ff
|
||||
#define BITMASK11 0x000007ff
|
||||
#define BITMASK12 0x00000fff
|
||||
#define BITMASK13 0x00001fff
|
||||
#define BITMASK14 0x00003fff
|
||||
#define BITMASK15 0x00007fff
|
||||
#define BITMASK16 0x0000ffff
|
||||
#define BITMASK17 0x0001ffff
|
||||
#define BITMASK18 0x0003ffff
|
||||
#define BITMASK19 0x0007ffff
|
||||
#define BITMASK20 0x000fffff
|
||||
#define BITMASK21 0x001fffff
|
||||
#define BITMASK22 0x003fffff
|
||||
#define BITMASK23 0x007fffff
|
||||
#define BITMASK24 0x00ffffff
|
||||
#define BITMASK25 0x01ffffff
|
||||
#define BITMASK26 0x03ffffff
|
||||
#define BITMASK27 0x07ffffff
|
||||
#define BITMASK28 0x0fffffff
|
||||
#define BITMASK29 0x1fffffff
|
||||
#define BITMASK30 0x3fffffff
|
||||
#define BITMASK31 0x7fffffff
|
||||
#define BITMASK32 0xffffffff
|
||||
|
||||
#define BITMASK33 0x00000001ffffffffull
|
||||
#define BITMASK34 0x00000003ffffffffull
|
||||
#define BITMASK35 0x00000007ffffffffull
|
||||
#define BITMASK36 0x0000000fffffffffull
|
||||
#define BITMASK37 0x0000001fffffffffull
|
||||
#define BITMASK38 0x0000003fffffffffull
|
||||
#define BITMASK39 0x0000007fffffffffull
|
||||
#define BITMASK40 0x000000ffffffffffull
|
||||
#define BITMASK41 0x000001ffffffffffull
|
||||
#define BITMASK42 0x000003ffffffffffull
|
||||
#define BITMASK43 0x000007ffffffffffull
|
||||
#define BITMASK44 0x00000fffffffffffull
|
||||
#define BITMASK45 0x00001fffffffffffull
|
||||
#define BITMASK46 0x00003fffffffffffull
|
||||
#define BITMASK47 0x00007fffffffffffull
|
||||
#define BITMASK48 0x0000ffffffffffffull
|
||||
#define BITMASK49 0x0001ffffffffffffull
|
||||
#define BITMASK50 0x0003ffffffffffffull
|
||||
#define BITMASK51 0x0007ffffffffffffull
|
||||
#define BITMASK52 0x000fffffffffffffull
|
||||
#define BITMASK53 0x001fffffffffffffull
|
||||
#define BITMASK54 0x003fffffffffffffull
|
||||
#define BITMASK55 0x007fffffffffffffull
|
||||
#define BITMASK56 0x00ffffffffffffffull
|
||||
#define BITMASK57 0x01ffffffffffffffull
|
||||
#define BITMASK58 0x03ffffffffffffffull
|
||||
#define BITMASK59 0x07ffffffffffffffull
|
||||
#define BITMASK60 0x0fffffffffffffffull
|
||||
#define BITMASK61 0x1fffffffffffffffull
|
||||
#define BITMASK62 0x3fffffffffffffffull
|
||||
#define BITMASK63 0x7fffffffffffffffull
|
||||
#define BITMASK64 0xffffffffffffffffull
|
||||
|
||||
#define BIT1 (1 << 0)
|
||||
#define BIT2 (1 << 1)
|
||||
#define BIT3 (1 << 2)
|
||||
#define BIT4 (1 << 3)
|
||||
#define BIT5 (1 << 4)
|
||||
#define BIT6 (1 << 5)
|
||||
#define BIT7 (1 << 6)
|
||||
#define BIT8 (1 << 7)
|
||||
#define BIT9 (1 << 8)
|
||||
#define BIT10 (1 << 9)
|
||||
#define BIT11 (1 << 10)
|
||||
#define BIT12 (1 << 11)
|
||||
#define BIT13 (1 << 12)
|
||||
#define BIT14 (1 << 13)
|
||||
#define BIT15 (1 << 14)
|
||||
#define BIT16 (1 << 15)
|
||||
#define BIT17 (1 << 16)
|
||||
#define BIT18 (1 << 17)
|
||||
#define BIT19 (1 << 18)
|
||||
#define BIT20 (1 << 19)
|
||||
#define BIT21 (1 << 20)
|
||||
#define BIT22 (1 << 21)
|
||||
#define BIT23 (1 << 22)
|
||||
#define BIT24 (1 << 23)
|
||||
#define BIT25 (1 << 24)
|
||||
#define BIT26 (1 << 25)
|
||||
#define BIT27 (1 << 26)
|
||||
#define BIT28 (1 << 27)
|
||||
#define BIT29 (1 << 28)
|
||||
#define BIT30 (1 << 29)
|
||||
#define BIT31 (1 << 30)
|
||||
#define BIT32 (1 << 31)
|
||||
|
||||
#define BIT33 (1ull << 32)
|
||||
#define BIT34 (1ull << 33)
|
||||
#define BIT35 (1ull << 34)
|
||||
#define BIT36 (1ull << 35)
|
||||
#define BIT37 (1ull << 36)
|
||||
#define BIT38 (1ull << 37)
|
||||
#define BIT39 (1ull << 38)
|
||||
#define BIT40 (1ull << 39)
|
||||
#define BIT41 (1ull << 40)
|
||||
#define BIT42 (1ull << 41)
|
||||
#define BIT43 (1ull << 42)
|
||||
#define BIT44 (1ull << 43)
|
||||
#define BIT45 (1ull << 44)
|
||||
#define BIT46 (1ull << 45)
|
||||
#define BIT47 (1ull << 46)
|
||||
#define BIT48 (1ull << 47)
|
||||
#define BIT49 (1ull << 48)
|
||||
#define BIT50 (1ull << 49)
|
||||
#define BIT51 (1ull << 50)
|
||||
#define BIT52 (1ull << 51)
|
||||
#define BIT53 (1ull << 52)
|
||||
#define BIT54 (1ull << 53)
|
||||
#define BIT55 (1ull << 54)
|
||||
#define BIT56 (1ull << 55)
|
||||
#define BIT57 (1ull << 56)
|
||||
#define BIT58 (1ull << 57)
|
||||
#define BIT59 (1ull << 58)
|
||||
#define BIT60 (1ull << 59)
|
||||
#define BIT61 (1ull << 60)
|
||||
#define BIT62 (1ull << 61)
|
||||
#define BIT63 (1ull << 62)
|
||||
#define BIT64 (1ull << 63)
|
||||
|
||||
////////////////////////////////
|
||||
//~ Globally Unique Ids
|
||||
|
||||
typedef union Guid Guid;
|
||||
union Guid
|
||||
{
|
||||
struct
|
||||
{
|
||||
U32 data1;
|
||||
U16 data2;
|
||||
U16 data3;
|
||||
U8 data4[8];
|
||||
};
|
||||
U8 v[16];
|
||||
};
|
||||
static_assert(size_of(Guid) == 16, "Guid is not 16 bytes");
|
||||
|
||||
////////////////////////////////
|
||||
//~ Arrays
|
||||
|
||||
typedef struct U16Array U16Array;
|
||||
struct U16Array
|
||||
{
|
||||
U64 count;
|
||||
U16* v;
|
||||
};
|
||||
typedef struct U32Array U32Array;
|
||||
struct U32Array
|
||||
{
|
||||
U64 count;
|
||||
U32* v;
|
||||
};
|
||||
typedef struct U64Array U64Array;
|
||||
struct U64Array
|
||||
{
|
||||
U64 count;
|
||||
U64* v;
|
||||
};
|
||||
typedef struct U128Array U128Array;
|
||||
struct U128Array
|
||||
{
|
||||
U64 count;
|
||||
U128* v;
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Safe Casts
|
||||
|
||||
internal U16 safe_cast_u16(U32 x);
|
||||
internal U32 safe_cast_u32(U64 x);
|
||||
internal S32 safe_cast_s32(S64 x);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Large Base Type Functions
|
||||
|
||||
internal U128 u128_zero(void);
|
||||
internal U128 u128_make(U64 v0, U64 v1);
|
||||
internal B32 u128_match(U128 a, U128 b);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Bit Patterns
|
||||
|
||||
internal U32 u32_from_u64_saturate(U64 x);
|
||||
internal U64 u64_up_to_pow2(U64 x);
|
||||
internal S32 extend_sign32(U32 x, U32 size);
|
||||
internal S64 extend_sign64(U64 x, U64 size);
|
||||
|
||||
internal F32 inf32(void);
|
||||
internal F32 neg_inf32(void);
|
||||
|
||||
internal U16 bswap_u16(U16 x);
|
||||
internal U32 bswap_u32(U32 x);
|
||||
internal U64 bswap_u64(U64 x);
|
||||
|
||||
#if ARCH_LITTLE_ENDIAN
|
||||
# define from_be_u16(x) bswap_u16(x)
|
||||
# define from_be_u32(x) bswap_u32(x)
|
||||
# define from_be_u64(x) bswap_u64(x)
|
||||
#else
|
||||
# define from_be_u16(x) (x)
|
||||
# define from_be_u32(x) (x)
|
||||
# define from_be_u64(x) (x)
|
||||
#endif
|
||||
|
||||
internal U64 count_bits_set32(U32 val);
|
||||
internal U64 count_bits_set64(U64 val);
|
||||
|
||||
internal U64 ctz32(U32 val);
|
||||
internal U64 ctz64(U64 val);
|
||||
internal U64 clz32(U32 val);
|
||||
internal U64 clz64(U64 val);
|
||||
|
||||
@@ -1,192 +0,0 @@
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "context_cracking.h"
|
||||
# include "linkage.h"
|
||||
# include "macros.h"
|
||||
# include "base_types.h"
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
//~ NOTE(allen): Constants
|
||||
|
||||
#define SIGN32 0x80000000;
|
||||
#define EXPONENT32 0x7F800000;
|
||||
#define MANTISSA32 0x007FFFFF;
|
||||
|
||||
#define BIG_GOLDEN32 1.61803398875f;
|
||||
#define SMALL_GOLDEN32 0.61803398875f;
|
||||
|
||||
#define PI32 3.1415926535897f;
|
||||
|
||||
#define MACHINE_EPSILON64 4.94065645841247e-324;
|
||||
|
||||
#define MIN_U8 0u
|
||||
#define MAX_U8 0xffu
|
||||
#define MIN_S8 ( -0x7f - 1 )
|
||||
#define MAX_S8 0x7f
|
||||
|
||||
#define MIN_U16 0u
|
||||
#define MAX_U16 0xffffu
|
||||
#define MIN_S16 ( -0x7fff - 1 )
|
||||
#define MAX_S16 0x7fff
|
||||
|
||||
#define MIN_U32 0u
|
||||
#define MAX_U32 0xffffffffu
|
||||
#define MIN_S32 ( -0x7fffffff - 1 )
|
||||
#define MAX_S32 0x7fffffff
|
||||
|
||||
#define MIN_U64 0ull
|
||||
#define MAX_U64 0xffffffffffffffffull
|
||||
#define MIN_S64 ( -0x7fffffffffffffffll - 1 )
|
||||
#define MAX_S64 0x7fffffffffffffffll
|
||||
|
||||
#if ARCH_32BIT
|
||||
# define MIN_USIZE U32_MIN
|
||||
# define MAX_USIZE U32_MAX
|
||||
# define MIN_ISIZE S32_MIN
|
||||
# define MAX_ISIZE S32_MAX
|
||||
#elif ARCH_64BIT
|
||||
# define MIN_USIZE U64_MIN
|
||||
# define MAX_USIZE U64_MAX
|
||||
# define MIN_ISIZE S64_MIN
|
||||
# define MAX_ISIZE S64_MAX
|
||||
#else
|
||||
# error Unknown architecture size. This library only supports 32 bit and 64 bit architectures.
|
||||
#endif
|
||||
|
||||
#define MIN_F32 1.17549435e-38f
|
||||
#define MAX_F32 3.40282347e+38f
|
||||
#define MIN_F64 2.2250738585072014e-308
|
||||
#define MAX_F64 1.7976931348623157e+308
|
||||
|
||||
#define BITMASK1 0x00000001
|
||||
#define BITMASK2 0x00000003
|
||||
#define BITMASK3 0x00000007
|
||||
#define BITMASK4 0x0000000f
|
||||
#define BITMASK5 0x0000001f
|
||||
#define BITMASK6 0x0000003f
|
||||
#define BITMASK7 0x0000007f
|
||||
#define BITMASK8 0x000000ff
|
||||
#define BITMASK9 0x000001ff
|
||||
#define BITMASK10 0x000003ff
|
||||
#define BITMASK11 0x000007ff
|
||||
#define BITMASK12 0x00000fff
|
||||
#define BITMASK13 0x00001fff
|
||||
#define BITMASK14 0x00003fff
|
||||
#define BITMASK15 0x00007fff
|
||||
#define BITMASK16 0x0000ffff
|
||||
#define BITMASK17 0x0001ffff
|
||||
#define BITMASK18 0x0003ffff
|
||||
#define BITMASK19 0x0007ffff
|
||||
#define BITMASK20 0x000fffff
|
||||
#define BITMASK21 0x001fffff
|
||||
#define BITMASK22 0x003fffff
|
||||
#define BITMASK23 0x007fffff
|
||||
#define BITMASK24 0x00ffffff
|
||||
#define BITMASK25 0x01ffffff
|
||||
#define BITMASK26 0x03ffffff
|
||||
#define BITMASK27 0x07ffffff
|
||||
#define BITMASK28 0x0fffffff
|
||||
#define BITMASK29 0x1fffffff
|
||||
#define BITMASK30 0x3fffffff
|
||||
#define BITMASK31 0x7fffffff
|
||||
#define BITMASK32 0xffffffff
|
||||
|
||||
#define BITMASK33 0x00000001ffffffffull
|
||||
#define BITMASK34 0x00000003ffffffffull
|
||||
#define BITMASK35 0x00000007ffffffffull
|
||||
#define BITMASK36 0x0000000fffffffffull
|
||||
#define BITMASK37 0x0000001fffffffffull
|
||||
#define BITMASK38 0x0000003fffffffffull
|
||||
#define BITMASK39 0x0000007fffffffffull
|
||||
#define BITMASK40 0x000000ffffffffffull
|
||||
#define BITMASK41 0x000001ffffffffffull
|
||||
#define BITMASK42 0x000003ffffffffffull
|
||||
#define BITMASK43 0x000007ffffffffffull
|
||||
#define BITMASK44 0x00000fffffffffffull
|
||||
#define BITMASK45 0x00001fffffffffffull
|
||||
#define BITMASK46 0x00003fffffffffffull
|
||||
#define BITMASK47 0x00007fffffffffffull
|
||||
#define BITMASK48 0x0000ffffffffffffull
|
||||
#define BITMASK49 0x0001ffffffffffffull
|
||||
#define BITMASK50 0x0003ffffffffffffull
|
||||
#define BITMASK51 0x0007ffffffffffffull
|
||||
#define BITMASK52 0x000fffffffffffffull
|
||||
#define BITMASK53 0x001fffffffffffffull
|
||||
#define BITMASK54 0x003fffffffffffffull
|
||||
#define BITMASK55 0x007fffffffffffffull
|
||||
#define BITMASK56 0x00ffffffffffffffull
|
||||
#define BITMASK57 0x01ffffffffffffffull
|
||||
#define BITMASK58 0x03ffffffffffffffull
|
||||
#define BITMASK59 0x07ffffffffffffffull
|
||||
#define BITMASK60 0x0fffffffffffffffull
|
||||
#define BITMASK61 0x1fffffffffffffffull
|
||||
#define BITMASK62 0x3fffffffffffffffull
|
||||
#define BITMASK63 0x7fffffffffffffffull
|
||||
#define BITMASK64 0xffffffffffffffffull
|
||||
|
||||
#define BIT1 (1 << 0)
|
||||
#define BIT2 (1 << 1)
|
||||
#define BIT3 (1 << 2)
|
||||
#define BIT4 (1 << 3)
|
||||
#define BIT5 (1 << 4)
|
||||
#define BIT6 (1 << 5)
|
||||
#define BIT7 (1 << 6)
|
||||
#define BIT8 (1 << 7)
|
||||
#define BIT9 (1 << 8)
|
||||
#define BIT10 (1 << 9)
|
||||
#define BIT11 (1 << 10)
|
||||
#define BIT12 (1 << 11)
|
||||
#define BIT13 (1 << 12)
|
||||
#define BIT14 (1 << 13)
|
||||
#define BIT15 (1 << 14)
|
||||
#define BIT16 (1 << 15)
|
||||
#define BIT17 (1 << 16)
|
||||
#define BIT18 (1 << 17)
|
||||
#define BIT19 (1 << 18)
|
||||
#define BIT20 (1 << 19)
|
||||
#define BIT21 (1 << 20)
|
||||
#define BIT22 (1 << 21)
|
||||
#define BIT23 (1 << 22)
|
||||
#define BIT24 (1 << 23)
|
||||
#define BIT25 (1 << 24)
|
||||
#define BIT26 (1 << 25)
|
||||
#define BIT27 (1 << 26)
|
||||
#define BIT28 (1 << 27)
|
||||
#define BIT29 (1 << 28)
|
||||
#define BIT30 (1 << 29)
|
||||
#define BIT31 (1 << 30)
|
||||
#define BIT32 (1 << 31)
|
||||
|
||||
#define BIT33 (1ull << 32)
|
||||
#define BIT34 (1ull << 33)
|
||||
#define BIT35 (1ull << 34)
|
||||
#define BIT36 (1ull << 35)
|
||||
#define BIT37 (1ull << 36)
|
||||
#define BIT38 (1ull << 37)
|
||||
#define BIT39 (1ull << 38)
|
||||
#define BIT40 (1ull << 39)
|
||||
#define BIT41 (1ull << 40)
|
||||
#define BIT42 (1ull << 41)
|
||||
#define BIT43 (1ull << 42)
|
||||
#define BIT44 (1ull << 43)
|
||||
#define BIT45 (1ull << 44)
|
||||
#define BIT46 (1ull << 45)
|
||||
#define BIT47 (1ull << 46)
|
||||
#define BIT48 (1ull << 47)
|
||||
#define BIT49 (1ull << 48)
|
||||
#define BIT50 (1ull << 49)
|
||||
#define BIT51 (1ull << 50)
|
||||
#define BIT52 (1ull << 51)
|
||||
#define BIT53 (1ull << 52)
|
||||
#define BIT54 (1ull << 53)
|
||||
#define BIT55 (1ull << 54)
|
||||
#define BIT56 (1ull << 55)
|
||||
#define BIT57 (1ull << 56)
|
||||
#define BIT58 (1ull << 57)
|
||||
#define BIT59 (1ull << 58)
|
||||
#define BIT60 (1ull << 59)
|
||||
#define BIT61 (1ull << 60)
|
||||
#define BIT62 (1ull << 61)
|
||||
#define BIT63 (1ull << 62)
|
||||
#define BIT64 (1ull << 63)
|
||||
+1
-1
@@ -1,8 +1,8 @@
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "context_cracking.h"
|
||||
# include "base_types.h"
|
||||
# include "macros.h"
|
||||
# include "base_types.h"
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
@@ -143,6 +143,45 @@
|
||||
#define memory_consume(T, p, e) ( ((p) + sizeof(T) <= (e)) ? ((p) += sizeof(T), *(T*)((p) - sizeof(T))) : ((p) = (e),0) )
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Memory Functions
|
||||
|
||||
inline B32
|
||||
memory_is_zero(void *ptr, U64 size){
|
||||
B32 result = 1;
|
||||
|
||||
// break down size
|
||||
U64 extra = (size&0x7);
|
||||
U64 count8 = (size >> 3);
|
||||
|
||||
// check with 8-byte stride
|
||||
U64 *p64 = (U64*)ptr;
|
||||
if(result)
|
||||
{
|
||||
for (U64 i = 0; i < count8; i += 1, p64 += 1){
|
||||
if (*p64 != 0){
|
||||
result = 0;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check extra
|
||||
if(result)
|
||||
{
|
||||
U8 *p8 = (U8*)p64;
|
||||
for (U64 i = 0; i < extra; i += 1, p8 += 1){
|
||||
if (*p8 != 0){
|
||||
result = 0;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
done:;
|
||||
return(result);
|
||||
}
|
||||
|
||||
inline
|
||||
void* mem_move( void* destination, void const* source, SSIZE byte_count )
|
||||
{
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "base_types.h"
|
||||
#endif
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Non-Fancy Ring Buffer Reads/Writes
|
||||
|
||||
internal U64 ring_write(U8 *ring_base, U64 ring_size, U64 ring_pos, void *src_data, U64 src_data_size);
|
||||
internal U64 ring_read(U8 *ring_base, U64 ring_size, U64 ring_pos, void *dst_data, U64 read_size);
|
||||
#define ring_write_struct(ring_base, ring_size, ring_pos, ptr) ring_write((ring_base), (ring_size), (ring_pos), (ptr), sizeof(*(ptr)))
|
||||
#define ring_read_struct(ring_base, ring_size, ring_pos, ptr) ring_read((ring_base), (ring_size), (ring_pos), (ptr), sizeof(*(ptr)))
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Sorts
|
||||
|
||||
#define quick_sort(ptr, count, element_size, cmp_function) qsort((ptr), (count), (element_size), (int (*)(const void *, const void *))(cmp_function))
|
||||
|
||||
@@ -58,3 +58,16 @@ Dir2;
|
||||
|
||||
#define axis2_from_dir2(d) (((d) & 1) ? Axis2_Y : Axis2_X)
|
||||
#define side_from_dir2(d) (((d) < Dir2_Right) ? Side_Min : Side_Max)
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Enum -> Sign
|
||||
|
||||
internal S32
|
||||
sign_from_side_S32(Side side){
|
||||
return((side == Side_Min)?-1:1);
|
||||
}
|
||||
|
||||
internal F32
|
||||
sign_from_side_F32(Side side){
|
||||
return((side == Side_Min)?-1.f:1.f);
|
||||
}
|
||||
|
||||
+266
-193
@@ -1099,131 +1099,122 @@ read_only global U8 utf8_class[32] = {
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,2,2,2,2,3,3,4,5,
|
||||
};
|
||||
|
||||
internal UnicodeDecode
|
||||
utf8_decode(U8 *str, U64 max){
|
||||
UnicodeDecode result = {1, MAX_U32};
|
||||
U8 byte = str[0];
|
||||
U8 byte_class = utf8_class[byte >> 3];
|
||||
switch (byte_class)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
result.codepoint = byte;
|
||||
}break;
|
||||
case 2:
|
||||
{
|
||||
if (2 < max)
|
||||
{
|
||||
U8 cont_byte = str[1];
|
||||
if (utf8_class[cont_byte >> 3] == 0)
|
||||
{
|
||||
result.codepoint = (byte & BITMASK5) << 6;
|
||||
result.codepoint |= (cont_byte & BITMASK6);
|
||||
result.inc = 2;
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 3:
|
||||
{
|
||||
if (2 < max)
|
||||
{
|
||||
U8 cont_byte[2] = {str[1], str[2]};
|
||||
if (utf8_class[cont_byte[0] >> 3] == 0 &&
|
||||
utf8_class[cont_byte[1] >> 3] == 0)
|
||||
{
|
||||
result.codepoint = (byte & BITMASK4) << 12;
|
||||
result.codepoint |= ((cont_byte[0] & BITMASK6) << 6);
|
||||
result.codepoint |= (cont_byte[1] & BITMASK6);
|
||||
result.inc = 3;
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 4:
|
||||
{
|
||||
if (3 < max)
|
||||
{
|
||||
U8 cont_byte[3] = {str[1], str[2], str[3]};
|
||||
if (utf8_class[cont_byte[0] >> 3] == 0 &&
|
||||
utf8_class[cont_byte[1] >> 3] == 0 &&
|
||||
utf8_class[cont_byte[2] >> 3] == 0)
|
||||
{
|
||||
result.codepoint = (byte & BITMASK3) << 18;
|
||||
result.codepoint |= ((cont_byte[0] & BITMASK6) << 12);
|
||||
result.codepoint |= ((cont_byte[1] & BITMASK6) << 6);
|
||||
result.codepoint |= (cont_byte[2] & BITMASK6);
|
||||
result.inc = 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return(result);
|
||||
UnicodeDecode
|
||||
utf8_decode(U8* str, U64 max)
|
||||
{
|
||||
UnicodeDecode result = {1, MAX_U32};
|
||||
U8 byte = str[0];
|
||||
U8 byte_class = utf8_class[byte >> 3];
|
||||
switch (byte_class)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
result.codepoint = byte;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
{
|
||||
if (2 < max)
|
||||
{
|
||||
U8 cont_byte = str[1];
|
||||
if (utf8_class[cont_byte >> 3] == 0)
|
||||
{
|
||||
result.codepoint = (byte & BITMASK5) << 6;
|
||||
result.codepoint |= (cont_byte & BITMASK6);
|
||||
result.inc = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
{
|
||||
if (2 < max)
|
||||
{
|
||||
U8 cont_byte[2] = {str[1], str[2]};
|
||||
if (utf8_class[cont_byte[0] >> 3] == 0 &&
|
||||
utf8_class[cont_byte[1] >> 3] == 0)
|
||||
{
|
||||
result.codepoint = (byte & BITMASK4) << 12;
|
||||
result.codepoint |= ((cont_byte[0] & BITMASK6) << 6);
|
||||
result.codepoint |= (cont_byte[1] & BITMASK6);
|
||||
result.inc = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:
|
||||
{
|
||||
if (3 < max)
|
||||
{
|
||||
U8 cont_byte[3] = {str[1], str[2], str[3]};
|
||||
if (utf8_class[cont_byte[0] >> 3] == 0 &&
|
||||
utf8_class[cont_byte[1] >> 3] == 0 &&
|
||||
utf8_class[cont_byte[2] >> 3] == 0)
|
||||
{
|
||||
result.codepoint = (byte & BITMASK3) << 18;
|
||||
result.codepoint |= ((cont_byte[0] & BITMASK6) << 12);
|
||||
result.codepoint |= ((cont_byte[1] & BITMASK6) << 6);
|
||||
result.codepoint |= (cont_byte[2] & BITMASK6);
|
||||
result.inc = 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal UnicodeDecode
|
||||
utf16_decode(U16 *str, U64 max){
|
||||
UnicodeDecode result = {1, max_U32};
|
||||
result.codepoint = str[0];
|
||||
result.inc = 1;
|
||||
if (max > 1 && 0xD800 <= str[0] && str[0] < 0xDC00 && 0xDC00 <= str[1] && str[1] < 0xE000){
|
||||
result.codepoint = ((str[0] - 0xD800) << 10) | ((str[1] - 0xDC00) + 0x10000);
|
||||
result.inc = 2;
|
||||
}
|
||||
return(result);
|
||||
U32
|
||||
utf8_encode(U8* str, U32 codepoint)
|
||||
{
|
||||
U32 inc = 0;
|
||||
if (codepoint <= 0x7F){
|
||||
str[0] = (U8)codepoint;
|
||||
inc = 1;
|
||||
}
|
||||
else if (codepoint <= 0x7FF){
|
||||
str[0] = (BITMASK2 << 6) | ((codepoint >> 6) & BITMASK5);
|
||||
str[1] = BIT8 | (codepoint & BITMASK6);
|
||||
inc = 2;
|
||||
}
|
||||
else if (codepoint <= 0xFFFF){
|
||||
str[0] = (BITMASK3 << 5) | ((codepoint >> 12) & BITMASK4);
|
||||
str[1] = BIT8 | ((codepoint >> 6) & BITMASK6);
|
||||
str[2] = BIT8 | ( codepoint & BITMASK6);
|
||||
inc = 3;
|
||||
}
|
||||
else if (codepoint <= 0x10FFFF){
|
||||
str[0] = (BITMASK4 << 4) | ((codepoint >> 18) & BITMASK3);
|
||||
str[1] = BIT8 | ((codepoint >> 12) & BITMASK6);
|
||||
str[2] = BIT8 | ((codepoint >> 6) & BITMASK6);
|
||||
str[3] = BIT8 | ( codepoint & BITMASK6);
|
||||
inc = 4;
|
||||
}
|
||||
else{
|
||||
str[0] = '?';
|
||||
inc = 1;
|
||||
}
|
||||
return(inc);
|
||||
}
|
||||
|
||||
internal U32
|
||||
utf8_encode(U8 *str, U32 codepoint){
|
||||
U32 inc = 0;
|
||||
if (codepoint <= 0x7F){
|
||||
str[0] = (U8)codepoint;
|
||||
inc = 1;
|
||||
}
|
||||
else if (codepoint <= 0x7FF){
|
||||
str[0] = (bitmask2 << 6) | ((codepoint >> 6) & bitmask5);
|
||||
str[1] = bit8 | (codepoint & bitmask6);
|
||||
inc = 2;
|
||||
}
|
||||
else if (codepoint <= 0xFFFF){
|
||||
str[0] = (bitmask3 << 5) | ((codepoint >> 12) & bitmask4);
|
||||
str[1] = bit8 | ((codepoint >> 6) & bitmask6);
|
||||
str[2] = bit8 | ( codepoint & bitmask6);
|
||||
inc = 3;
|
||||
}
|
||||
else if (codepoint <= 0x10FFFF){
|
||||
str[0] = (bitmask4 << 4) | ((codepoint >> 18) & bitmask3);
|
||||
str[1] = bit8 | ((codepoint >> 12) & bitmask6);
|
||||
str[2] = bit8 | ((codepoint >> 6) & bitmask6);
|
||||
str[3] = bit8 | ( codepoint & bitmask6);
|
||||
inc = 4;
|
||||
}
|
||||
else{
|
||||
str[0] = '?';
|
||||
inc = 1;
|
||||
}
|
||||
return(inc);
|
||||
}
|
||||
|
||||
internal U32
|
||||
utf16_encode(U16 *str, U32 codepoint){
|
||||
U32 inc = 1;
|
||||
if (codepoint == max_U32){
|
||||
str[0] = (U16)'?';
|
||||
}
|
||||
else if (codepoint < 0x10000){
|
||||
str[0] = (U16)codepoint;
|
||||
}
|
||||
else{
|
||||
U32 v = codepoint - 0x10000;
|
||||
str[0] = safe_cast_u16(0xD800 + (v >> 10));
|
||||
str[1] = safe_cast_u16(0xDC00 + (v & bitmask10));
|
||||
inc = 2;
|
||||
}
|
||||
return(inc);
|
||||
}
|
||||
|
||||
internal U32
|
||||
utf8_from_utf32_single(U8 *buffer, U32 character){
|
||||
return(utf8_encode(buffer, character));
|
||||
U32
|
||||
utf16_encode(U16 *str, U32 codepoint) {
|
||||
U32 inc = 1;
|
||||
if (codepoint == MAX_U32) {
|
||||
str[0] = (U16)'?';
|
||||
}
|
||||
else if (codepoint < 0x10000) {
|
||||
str[0] = (U16)codepoint;
|
||||
}
|
||||
else {
|
||||
U32 v = codepoint - 0x10000;
|
||||
str[0] = safe_cast_u16(0xD800 + (v >> 10));
|
||||
str[1] = safe_cast_u16(0xDC00 + (v & BITMASK10));
|
||||
inc = 2;
|
||||
}
|
||||
return(inc);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
@@ -1428,25 +1419,98 @@ push_file_name_date_time_string(Arena *arena, DateTime *date_time){
|
||||
return(result);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Text Escaping
|
||||
|
||||
internal String8
|
||||
string_from_elapsed_time(Arena *arena, DateTime dt){
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
String8List list = {0};
|
||||
if (dt.year){
|
||||
str8_list_pushf(scratch.arena, &list, "%dy", dt.year);
|
||||
str8_list_pushf(scratch.arena, &list, "%um", dt.mon);
|
||||
str8_list_pushf(scratch.arena, &list, "%ud", dt.day);
|
||||
} else if (dt.mon){
|
||||
str8_list_pushf(scratch.arena, &list, "%um", dt.mon);
|
||||
str8_list_pushf(scratch.arena, &list, "%ud", dt.day);
|
||||
} else if (dt.day){
|
||||
str8_list_pushf(scratch.arena, &list, "%ud", dt.day);
|
||||
escaped_from_raw_str8(Arena *arena, String8 string)
|
||||
{
|
||||
TempArena scratch = scratch_begin(&arena, 1);
|
||||
String8List parts = {0};
|
||||
U64 start_split_idx = 0;
|
||||
for(U64 idx = 0; idx <= string.size; idx += 1)
|
||||
{
|
||||
U8 byte = (idx < string.size) ? string.str[idx] : 0;
|
||||
B32 split = 1;
|
||||
String8 separator_replace = {0};
|
||||
switch(byte)
|
||||
{
|
||||
default:{split = 0;}break;
|
||||
case 0: {}break;
|
||||
case '\a': {separator_replace = str8_lit("\\a");}break;
|
||||
case '\b': {separator_replace = str8_lit("\\b");}break;
|
||||
case '\f': {separator_replace = str8_lit("\\f");}break;
|
||||
case '\n': {separator_replace = str8_lit("\\n");}break;
|
||||
case '\r': {separator_replace = str8_lit("\\r");}break;
|
||||
case '\t': {separator_replace = str8_lit("\\t");}break;
|
||||
case '\v': {separator_replace = str8_lit("\\v");}break;
|
||||
case '\\': {separator_replace = str8_lit("\\\\");}break;
|
||||
case '"': {separator_replace = str8_lit("\\\"");}break;
|
||||
case '?': {separator_replace = str8_lit("\\?");}break;
|
||||
}
|
||||
if(split)
|
||||
{
|
||||
String8 substr = str8_substr(string, r1u64(start_split_idx, idx));
|
||||
start_split_idx = idx+1;
|
||||
str8_list_push(scratch.arena, &parts, substr);
|
||||
if(separator_replace.size != 0)
|
||||
{
|
||||
str8_list_push(scratch.arena, &parts, separator_replace);
|
||||
}
|
||||
}
|
||||
}
|
||||
str8_list_pushf(scratch.arena, &list, "%u:%u:%u:%u ms", dt.hour, dt.min, dt.sec, dt.msec);
|
||||
StringJoin join = { str8_lit_comp(""), str8_lit_comp(" "), str8_lit_comp("") };
|
||||
String8 result = str8_list_join(arena, &list, &join);
|
||||
StringJoin join = {0};
|
||||
String8 result = str8_list_join(arena, &parts, &join);
|
||||
scratch_end(scratch);
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
raw_from_escaped_str8(Arena *arena, String8 string)
|
||||
{
|
||||
TempArena scratch = scratch_begin(&arena, 1);
|
||||
String8List strs = {0};
|
||||
U64 start = 0;
|
||||
for(U64 idx = 0; idx <= string.size; idx += 1)
|
||||
{
|
||||
if(idx == string.size || string.str[idx] == '\\' || string.str[idx] == '\r')
|
||||
{
|
||||
String8 str = str8_substr(string, r1u64(start, idx));
|
||||
if(str.size != 0)
|
||||
{
|
||||
str8_list_push(scratch.arena, &strs, str);
|
||||
}
|
||||
start = idx+1;
|
||||
}
|
||||
if(idx < string.size && string.str[idx] == '\\')
|
||||
{
|
||||
U8 next_char = string.str[idx+1];
|
||||
U8 replace_byte = 0;
|
||||
switch(next_char)
|
||||
{
|
||||
default:{}break;
|
||||
case 'a': replace_byte = 0x07; break;
|
||||
case 'b': replace_byte = 0x08; break;
|
||||
case 'e': replace_byte = 0x1b; break;
|
||||
case 'f': replace_byte = 0x0c; break;
|
||||
case 'n': replace_byte = 0x0a; break;
|
||||
case 'r': replace_byte = 0x0d; break;
|
||||
case 't': replace_byte = 0x09; break;
|
||||
case 'v': replace_byte = 0x0b; break;
|
||||
case '\\':replace_byte = '\\'; break;
|
||||
case '\'':replace_byte = '\''; break;
|
||||
case '"': replace_byte = '"'; break;
|
||||
case '?': replace_byte = '?'; break;
|
||||
}
|
||||
String8 replace_string = push_str8_copy(scratch.arena, str8(&replace_byte, 1));
|
||||
str8_list_push(scratch.arena, &strs, replace_string);
|
||||
idx += 1;
|
||||
start += 1;
|
||||
}
|
||||
}
|
||||
String8 result = str8_list_join(arena, &strs, 0);
|
||||
scratch_end(scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
@@ -1455,7 +1519,7 @@ string_from_elapsed_time(Arena *arena, DateTime dt){
|
||||
internal String8
|
||||
indented_from_string(Arena *arena, String8 string)
|
||||
{
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
TempArena scratch = scratch_begin(&arena, 1);
|
||||
read_only local_persist U8 indentation_bytes[] = " ";
|
||||
String8List indented_strings = {0};
|
||||
S64 depth = 0;
|
||||
@@ -1467,8 +1531,8 @@ indented_from_string(Arena *arena, String8 string)
|
||||
switch(byte)
|
||||
{
|
||||
default:{}break;
|
||||
case '{':case '[':case '(':{next_depth += 1; next_depth = Max(0, next_depth);}break;
|
||||
case '}':case ']':case ')':{next_depth -= 1; next_depth = Max(0, next_depth); depth = next_depth;}break;
|
||||
case '{':case '[':case '(':{next_depth += 1; next_depth = max(0, next_depth);}break;
|
||||
case '}':case ']':case ')':{next_depth -= 1; next_depth = max(0, next_depth); depth = next_depth;}break;
|
||||
case '\n':
|
||||
case 0:
|
||||
{
|
||||
@@ -1491,58 +1555,68 @@ indented_from_string(Arena *arena, String8 string)
|
||||
//~ rjf: Text Wrapping
|
||||
|
||||
internal String8List
|
||||
wrapped_lines_from_string(Arena *arena, String8 string, U64 first_line_max_width, U64 max_width, U64 wrap_indent)
|
||||
wrapped_lines_from_string(Arena* arena, String8 string, U64 first_line_max_width, U64 max_width, U64 wrap_indent)
|
||||
{
|
||||
String8List list = {0};
|
||||
Rng1U64 line_range = r1u64(0, 0);
|
||||
U64 wrapped_indent_level = 0;
|
||||
static char *spaces = " ";
|
||||
for (U64 idx = 0; idx <= string.size; idx += 1){
|
||||
U8 chr = idx < string.size ? string.str[idx] : 0;
|
||||
if (chr == '\n'){
|
||||
Rng1U64 candidate_line_range = line_range;
|
||||
candidate_line_range.max = idx;
|
||||
// NOTE(nick): when wrapping is interrupted with \n we emit a string without including \n
|
||||
// because later tool_fprint_list inserts separator after each node
|
||||
// except for last node, so don't strip last \n.
|
||||
if (idx + 1 == string.size){
|
||||
candidate_line_range.max += 1;
|
||||
}
|
||||
String8 substr = str8_substr(string, candidate_line_range);
|
||||
str8_list_push(arena, &list, substr);
|
||||
line_range = r1u64(idx+1,idx+1);
|
||||
}
|
||||
else
|
||||
if (char_is_space(chr) || chr == 0){
|
||||
Rng1U64 candidate_line_range = line_range;
|
||||
candidate_line_range.max = idx;
|
||||
String8 substr = str8_substr(string, candidate_line_range);
|
||||
U64 width_this_line = max_width-wrapped_indent_level;
|
||||
if (list.node_count == 0){
|
||||
width_this_line = first_line_max_width;
|
||||
}
|
||||
if (substr.size > width_this_line){
|
||||
String8 line = str8_substr(string, line_range);
|
||||
if (wrapped_indent_level > 0){
|
||||
line = push_str8f(arena, "%.*s%S", wrapped_indent_level, spaces, line);
|
||||
}
|
||||
str8_list_push(arena, &list, line);
|
||||
line_range = r1u64(line_range.max+1, candidate_line_range.max);
|
||||
wrapped_indent_level = ClampTop(64, wrap_indent);
|
||||
}
|
||||
else{
|
||||
line_range = candidate_line_range;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (line_range.min < string.size && line_range.max > line_range.min){
|
||||
String8 line = str8_substr(string, line_range);
|
||||
if (wrapped_indent_level > 0){
|
||||
line = push_str8f(arena, "%.*s%S", wrapped_indent_level, spaces, line);
|
||||
}
|
||||
str8_list_push(arena, &list, line);
|
||||
}
|
||||
return list;
|
||||
String8List list = {0};
|
||||
Rng1U64 line_range = r1u64(0, 0);
|
||||
|
||||
U64 wrapped_indent_level = 0;
|
||||
static char* spaces = " ";
|
||||
|
||||
for (U64 idx = 0; idx <= string.size; idx += 1)
|
||||
{
|
||||
U8 chr = idx < string.size ? string.str[idx] : 0;
|
||||
if (chr == '\n')
|
||||
{
|
||||
Rng1U64
|
||||
candidate_line_range = line_range;
|
||||
candidate_line_range.max = idx;
|
||||
// NOTE(nick): when wrapping is interrupted with \n we emit a string without including \n
|
||||
// because later tool_fprint_list inserts separator after each node
|
||||
// except for last node, so don't strip last \n.
|
||||
if (idx + 1 == string.size){
|
||||
candidate_line_range.max += 1;
|
||||
}
|
||||
String8 substr = str8_substr(string, candidate_line_range);
|
||||
str8_list_push(arena, &list, substr);
|
||||
line_range = r1u64(idx + 1,idx + 1);
|
||||
}
|
||||
else
|
||||
if (char_is_space(chr) || chr == 0)
|
||||
{
|
||||
Rng1U64
|
||||
candidate_line_range = line_range;
|
||||
candidate_line_range.max = idx;
|
||||
|
||||
String8 substr = str8_substr(string, candidate_line_range);
|
||||
U64 width_this_line = max_width-wrapped_indent_level;
|
||||
|
||||
if (list.node_count == 0) {
|
||||
width_this_line = first_line_max_width;
|
||||
}
|
||||
if (substr.size > width_this_line)
|
||||
{
|
||||
String8 line = str8_substr(string, line_range);
|
||||
if (wrapped_indent_level > 0){
|
||||
line = push_str8f(arena, "%.*s%S", wrapped_indent_level, spaces, line);
|
||||
}
|
||||
str8_list_push(arena, &list, line);
|
||||
line_range = r1u64(line_range.max + 1, candidate_line_range.max);
|
||||
wrapped_indent_level = clamp_top(64, wrap_indent);
|
||||
}
|
||||
else{
|
||||
line_range = candidate_line_range;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (line_range.min < string.size && line_range.max > line_range.min) {
|
||||
String8 line = str8_substr(string, line_range);
|
||||
if (wrapped_indent_level > 0) {
|
||||
line = push_str8f(arena, "%.*s%S", wrapped_indent_level, spaces, line);
|
||||
}
|
||||
str8_list_push(arena, &list, line);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
@@ -1584,7 +1658,7 @@ internal FuzzyMatchRangeList
|
||||
fuzzy_match_find(Arena *arena, String8 needle, String8 haystack)
|
||||
{
|
||||
FuzzyMatchRangeList result = {0};
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
TempArena scratch = scratch_begin(&arena, 1);
|
||||
String8List needles = str8_split(scratch.arena, needle, (U8*)" ", 1, 0);
|
||||
result.needle_part_count = needles.node_count;
|
||||
for(String8Node *needle_n = needles.first; needle_n != 0; needle_n = needle_n->next)
|
||||
@@ -1857,4 +1931,3 @@ str8_deserial_read_block(String8 string, U64 off, U64 size, String8 *block_out)
|
||||
*block_out = str8_substr(string, range);
|
||||
return block_out->size;
|
||||
}
|
||||
|
||||
|
||||
+75
-17
@@ -6,7 +6,6 @@
|
||||
# include "macros.h"
|
||||
# include "generic_macros.h"
|
||||
# include "base_types.h"
|
||||
# include "constants.h"
|
||||
# include "arena.h"
|
||||
# include "space.h"
|
||||
# include "math.h"
|
||||
@@ -196,6 +195,10 @@ inline String8 str8_cstring (char* c) { String8 result
|
||||
inline String16 str16_cstring(U16* c) { String16 result = {(U16*)c, cstring16_length((U16*)c)}; return(result); }
|
||||
inline String32 str32_cstring(U32* c) { String32 result = {(U32*)c, cstring32_length((U32*)c)}; return(result); }
|
||||
|
||||
// TODO(Ed): review these
|
||||
internal String16 str16_cstring_capped(void *cstr, void *cap);
|
||||
internal String8 str8_cstring_capped_reverse(void *raw_start, void *raw_cap);
|
||||
|
||||
inline String8
|
||||
str8_cstring_capped(void *cstr, void *cap) {
|
||||
char *ptr = (char*)cstr;
|
||||
@@ -206,13 +209,30 @@ str8_cstring_capped(void *cstr, void *cap) {
|
||||
return(result);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: String Stylization
|
||||
|
||||
inline String8 upper_from_str8 (Arena* arena, String8 string) { string = push_str8_copy(arena, string); for(U64 idx = 0; idx < string.size; idx += 1) { string.str[idx] = char_to_upper(string.str[idx]); } return string; }
|
||||
inline String8 lower_from_str8 (Arena* arena, String8 string) { string = push_str8_copy(arena, string); for(U64 idx = 0; idx < string.size; idx += 1) { string.str[idx] = char_to_lower(string.str[idx]); } return string; }
|
||||
inline String8 backslashed_from_str8(Arena *arena, String8 string) { string = push_str8_copy(arena, string); for(U64 idx = 0; idx < string.size; idx += 1) { string.str[idx] = char_is_slash(string.str[idx]) ? '\\' : string.str[idx]; } return string; }
|
||||
|
||||
inline String8 upper_from_str8_alloc (AllocatorInfo ainfo, String8 string) { string = str8_copy(ainfo, string); for(U64 idx = 0; idx < string.size; idx += 1) { string.str[idx] = char_to_upper(string.str[idx]); } return string; }
|
||||
inline String8 lower_from_str8_alloc (AllocatorInfo ainfo, String8 string) { string = str8_copy(ainfo, string); for(U64 idx = 0; idx < string.size; idx += 1) { string.str[idx] = char_to_lower(string.str[idx]); } return string; }
|
||||
inline String8 backslashed_from_str8_alloc(AllocatorInfo ainfo, String8 string) { string = str8_copy(ainfo, string); for(U64 idx = 0; idx < string.size; idx += 1) { string.str[idx] = char_is_slash(string.str[idx]) ? '\\' : string.str[idx]; } return string; }
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: String Matching
|
||||
|
||||
#define str8_match_lit(a_lit, b, flags) str8_match(str8_lit(a_lit), (b), (flags))
|
||||
#define str8_match_cstr(a_cstr, b, flags) str8_match(str8_cstring(a_cstr), (b), (flags))
|
||||
#define str8_ends_with_lit(string, end_lit, flags) str8_ends_with((string), str8_lit(end_lit), (flags))
|
||||
|
||||
MD_API B32 str8_match (String8 a, String8 b, StringMatchFlags flags);
|
||||
MD_API U64 str8_find_needle(String8 string, U64 start_pos, String8 needle, StringMatchFlags flags);
|
||||
B32 str8_ends_with (String8 string, String8 end, StringMatchFlags flags);
|
||||
|
||||
internal U64 str8_find_needle_reverse(String8 string, U64 start_pos, String8 needle, StringMatchFlags flags);
|
||||
|
||||
inline B32
|
||||
str8_ends_with(String8 string, String8 end, StringMatchFlags flags) {
|
||||
String8 postfix = str8_postfix(string, end.size);
|
||||
@@ -300,17 +320,6 @@ str8f(AllocatorInfo ainfo, char *fmt, ...){
|
||||
return(result);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: String Stylization
|
||||
|
||||
inline String8 upper_from_str8 (Arena* arena, String8 string) { string = push_str8_copy(arena, string); for(U64 idx = 0; idx < string.size; idx += 1) { string.str[idx] = char_to_upper(string.str[idx]); } return string; }
|
||||
inline String8 lower_from_str8 (Arena* arena, String8 string) { string = push_str8_copy(arena, string); for(U64 idx = 0; idx < string.size; idx += 1) { string.str[idx] = char_to_lower(string.str[idx]); } return string; }
|
||||
inline String8 backslashed_from_str8(Arena *arena, String8 string) { string = push_str8_copy(arena, string); for(U64 idx = 0; idx < string.size; idx += 1) { string.str[idx] = char_is_slash(string.str[idx]) ? '\\' : string.str[idx]; } return string; }
|
||||
|
||||
inline String8 upper_from_str8_alloc (AllocatorInfo ainfo, String8 string) { string = str8_copy(ainfo, string); for(U64 idx = 0; idx < string.size; idx += 1) { string.str[idx] = char_to_upper(string.str[idx]); } return string; }
|
||||
inline String8 lower_from_str8_alloc (AllocatorInfo ainfo, String8 string) { string = str8_copy(ainfo, string); for(U64 idx = 0; idx < string.size; idx += 1) { string.str[idx] = char_to_lower(string.str[idx]); } return string; }
|
||||
inline String8 backslashed_from_str8_alloc(AllocatorInfo ainfo, String8 string) { string = str8_copy(ainfo, string); for(U64 idx = 0; idx < string.size; idx += 1) { string.str[idx] = char_is_slash(string.str[idx]) ? '\\' : string.str[idx]; } return string; }
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: String <=> Integer Conversions
|
||||
|
||||
@@ -319,6 +328,11 @@ MD_API S64 sign_from_str8 (String8 string, String8* string_tail);
|
||||
MD_API B32 str8_is_integer (String8 string, U32 radix);
|
||||
MD_API U64 u64_from_str8 (String8 string, U32 radix);
|
||||
S64 s64_from_str8 (String8 string, U32 radix);
|
||||
|
||||
// TODO(Ed): review these
|
||||
internal U32 u32_from_str8(String8 string, U32 radix);
|
||||
internal S32 s32_from_str8(String8 string, U32 radix);
|
||||
|
||||
MD_API B32 try_u64_from_str8_c_rules(String8 string, U64* x);
|
||||
B32 try_s64_from_str8_c_rules(String8 string, S64* x);
|
||||
|
||||
@@ -327,6 +341,10 @@ MD_API String8 str8_from_memory_size(Arena* arena, U64 z);
|
||||
MD_API String8 str8_from_u64 (Arena* arena, U64 u64, U32 radix, U8 min_digits, U8 digit_group_separator);
|
||||
MD_API String8 str8_from_s64 (Arena* arena, S64 s64, U32 radix, U8 min_digits, U8 digit_group_separator);
|
||||
|
||||
// TODO(Ed): review these
|
||||
internal String8 str8_from_bits_u32(Arena *arena, U32 x);
|
||||
internal String8 str8_from_bits_u64(Arena *arena, U64 x);
|
||||
|
||||
MD_API String8 str8_from_allocator_size(AllocatorInfo ainfo, U64 z);
|
||||
MD_API String8 str8_from_allocator_u64 (AllocatorInfo ainfo, U64 u64, U32 radix, U8 min_digits, U8 digit_group_separator);
|
||||
MD_API String8 str8_from_alloctor_s64 (AllocatorInfo ainfo, S64 u64, U32 radix, U8 min_digits, U8 digit_group_separator);
|
||||
@@ -652,11 +670,26 @@ MD_API String8 str8_path_list_join_by_style_alloc (AllocatorInfo ainfo, Str
|
||||
////////////////////////////////
|
||||
//~ rjf: UTF-8 & UTF-16 Decoding/Encoding
|
||||
|
||||
UnicodeDecode utf8_decode (U8* str, U64 max);
|
||||
UnicodeDecode utf16_decode (U16* str, U64 max);
|
||||
U32 utf8_encode (U8* str, U32 codepoint);
|
||||
U32 utf16_encode (U16* str, U32 codepoint);
|
||||
U32 utf8_from_utf32_single(U8* buffer, U32 character);
|
||||
MD_API UnicodeDecode utf8_decode (U8* str, U64 max);
|
||||
UnicodeDecode utf16_decode (U16* str, U64 max);
|
||||
MD_API U32 utf8_encode (U8* str, U32 codepoint);
|
||||
MD_API U32 utf16_encode (U16* str, U32 codepoint);
|
||||
U32 utf8_from_utf32_single(U8* buffer, U32 character);
|
||||
|
||||
inline UnicodeDecode
|
||||
utf16_decode(U16* str, U64 max) {
|
||||
UnicodeDecode result = {1, MAX_U32};
|
||||
result.codepoint = str[0];
|
||||
result.inc = 1;
|
||||
if (max > 1 && 0xD800 <= str[0] && str[0] < 0xDC00 && 0xDC00 <= str[1] && str[1] < 0xE000) {
|
||||
result.codepoint = ((str[0] - 0xD800) << 10) |
|
||||
((str[1] - 0xDC00) + 0x10000);
|
||||
result.inc = 2;
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
inline U32 utf8_from_utf32_single(U8* buffer, U32 character){ return(utf8_encode(buffer, character)); }
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Unicode String Conversions
|
||||
@@ -666,6 +699,11 @@ internal String16 str16_from_8(Arena* arena, String8 in);
|
||||
internal String8 str8_from_32(Arena* arena, String32 in);
|
||||
internal String32 str32_from_8(Arena* arena, String8 in);
|
||||
|
||||
////////////////////////////////
|
||||
//~ String -> Enum Conversions
|
||||
|
||||
internal OperatingSystem operating_system_from_string(String8 string);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Basic Types & Space Enum -> String Conversions
|
||||
|
||||
@@ -683,11 +721,29 @@ internal String8 push_date_time_string (Arena* arena, DateTime* date_ti
|
||||
internal String8 push_file_name_date_time_string(Arena* arena, DateTime* date_time);
|
||||
internal String8 string_from_elapsed_time (Arena* arena, DateTime dt);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Globally Unique Ids
|
||||
|
||||
internal String8 string_from_guid(Arena *arena, Guid guid);
|
||||
internal B32 try_guid_from_string(String8 string, Guid *guid_out);
|
||||
internal Guid guid_from_string(String8 string);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Basic Text Indentation
|
||||
|
||||
internal String8 indented_from_string(Arena *arena, String8 string);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Text Escaping
|
||||
|
||||
internal String8 escaped_from_raw_str8(Arena *arena, String8 string);
|
||||
internal String8 raw_from_escaped_str8(Arena *arena, String8 string);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Text Wrapping
|
||||
|
||||
String8List wrapped_lines_from_string(Arena *arena, String8 string, U64 first_line_max_width, U64 max_width, U64 wrap_indent);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: String <-> Color
|
||||
|
||||
@@ -729,6 +785,8 @@ internal void* str8_deserial_get_raw_ptr (String8 string, U64 off
|
||||
internal U64 str8_deserial_read_cstr (String8 string, U64 off, String8* cstr_out);
|
||||
internal U64 str8_deserial_read_windows_utf16_string16(String8 string, U64 off, String16* str_out);
|
||||
internal U64 str8_deserial_read_block (String8 string, U64 off, U64 size, String8* block_out);
|
||||
internal U64 str8_deserial_read_uleb128(String8 string, U64 off, U64 *value_out);
|
||||
internal U64 str8_deserial_read_sleb128(String8 string, U64 off, S64 *value_out);
|
||||
|
||||
#define str8_deserial_read_array(string, off, ptr, count) str8_deserial_read((string), (off), (ptr), sizeof(*(ptr)) * (count), sizeof( *(ptr)))
|
||||
#define str8_deserial_read_struct(string, off, ptr) str8_deserial_read((string), (off), (ptr), sizeof(*(ptr)), sizeof( *(ptr)))
|
||||
|
||||
@@ -48,7 +48,3 @@ TxtRng txt_rng_intersect(TxtRng a, TxtRng b);
|
||||
TxtRng txt_rng_union(TxtRng a, TxtRng b);
|
||||
B32 txt_rng_contains(TxtRng r, TxtPt pt);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Text Wrapping
|
||||
|
||||
String8List wrapped_lines_from_string(Arena *arena, String8 string, U64 first_line_max_width, U64 max_width, U64 wrap_indent);
|
||||
|
||||
@@ -60,3 +60,11 @@ struct DateTime
|
||||
};
|
||||
|
||||
typedef U64 DenseTime;
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Time Functions
|
||||
|
||||
internal DenseTime dense_time_from_date_time(DateTime date_time);
|
||||
internal DateTime date_time_from_dense_time(DenseTime time);
|
||||
internal DateTime date_time_from_micro_seconds(U64 time);
|
||||
internal DateTime date_time_from_unix_time(U64 unix_time);
|
||||
|
||||
@@ -15,6 +15,15 @@ typedef enum OperatingSystem
|
||||
}
|
||||
OperatingSystem;
|
||||
|
||||
typedef enum ImageType
|
||||
{
|
||||
Image_Null,
|
||||
Image_CoffPe,
|
||||
Image_Elf32,
|
||||
Image_Elf64,
|
||||
Image_Macho
|
||||
} ImageType;
|
||||
|
||||
typedef enum Architecture
|
||||
{
|
||||
Architecture_Null,
|
||||
@@ -35,3 +44,13 @@ typedef enum Compiler
|
||||
Compiler_COUNT,
|
||||
}
|
||||
Compiler;
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Toolchain/Environment Enum Functions
|
||||
|
||||
internal U64 bit_size_from_arch(Arch arch);
|
||||
internal U64 max_instruction_size_from_arch(Arch arch);
|
||||
|
||||
internal OperatingSystem operating_system_from_context(void);
|
||||
internal Arch arch_from_context(void);
|
||||
internal Compiler compiler_from_context(void);
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
MD_NS_BEGIN
|
||||
|
||||
#include "base/base_types.h"
|
||||
#include "base/constants.h"
|
||||
#include "base/debug.h"
|
||||
#include "base/memory.h"
|
||||
#include "base/memory_substrate.h"
|
||||
@@ -27,7 +26,6 @@ MD_NS_BEGIN
|
||||
#include "base/toolchain.h"
|
||||
#include "base/strings.h"
|
||||
|
||||
|
||||
MD_NS_END
|
||||
|
||||
// mdesk
|
||||
|
||||
Reference in New Issue
Block a user