linux
This commit is contained in:
7
build.sh
Normal file
7
build.sh
Normal file
@@ -0,0 +1,7 @@
|
||||
cd "$(dirname "$0")"
|
||||
mkdir build
|
||||
pushd build
|
||||
clang ../src/meta/build_tool.c -ldl -o build_tool.exe -g -fdiagnostics-absolute-paths
|
||||
popd
|
||||
|
||||
./build/build_tool.exe -cc=clang
|
||||
48
build_file.c
48
build_file.c
@@ -17,6 +17,12 @@
|
||||
#include "src/wasm_app/wasm_app.meta.c"
|
||||
#include "src/testing/testing.meta.c"
|
||||
|
||||
#if PLATFORM_WINDOWS
|
||||
#define py "py "
|
||||
#else
|
||||
#define py "python3 "
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
core_init();
|
||||
int ok = 0;
|
||||
@@ -28,7 +34,7 @@ int main(int argc, char **argv) {
|
||||
b32 generate_math = true;
|
||||
if (generate_math && cache_code_modified(s8_lit("../src/core/core_math_gen.py"), s8_null)) {
|
||||
os_set_working_dir("../src/core");
|
||||
os_systemf("py core_math_gen.py");
|
||||
os_systemf(py "core_math_gen.py");
|
||||
os_set_working_dir("../../build");
|
||||
}
|
||||
mt_ui(tcx->temp);
|
||||
@@ -38,10 +44,10 @@ int main(int argc, char **argv) {
|
||||
mt_testing(tcx->temp);
|
||||
|
||||
b32 run_server = false;
|
||||
b32 core_test_target = false;
|
||||
b32 core_test_target = true;
|
||||
b32 win32_target = false;
|
||||
b32 standalone_w32_target = false;
|
||||
b32 wasm_target = true;
|
||||
b32 wasm_target = false;
|
||||
|
||||
if (run_server) {
|
||||
os_systemf("start /D ..\\package ..\\package\\run_server.bat");
|
||||
@@ -80,18 +86,30 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
if (core_test_target && cache_code_modified(s8_lit("../src/testing/testing_main.c"), s8_lit("testing.exe"))) {
|
||||
os_delete_file(s8_lit("testing.pdb"));
|
||||
ok = os_systemf(
|
||||
"cl ../src/testing/testing_main.c -Fe:testing.exe -Fd:testing.pdb"
|
||||
" -I ../src"
|
||||
" /Zi /FC /nologo /Oi"
|
||||
" /WX /W3 /wd4200 /diagnostics:column"
|
||||
" /link /incremental:no /DEBUG:FULL"
|
||||
);
|
||||
if (ok != 0) return ok;
|
||||
if (PLATFORM_WINDOWS) {
|
||||
os_delete_file(s8_lit("testing.pdb"));
|
||||
ok = os_systemf(
|
||||
"cl ../src/testing/testing_main.c -Fe:testing.exe -Fd:testing.pdb"
|
||||
" -I ../src"
|
||||
" /Zi /FC /nologo /Oi"
|
||||
" /WX /W3 /wd4200 /diagnostics:column"
|
||||
" /link /incremental:no /DEBUG:FULL"
|
||||
);
|
||||
if (ok != 0) return ok;
|
||||
|
||||
ok = os_systemf("testing.exe");
|
||||
if (ok != 0) return ok;
|
||||
ok = os_systemf("testing.exe");
|
||||
if (ok != 0) return ok;
|
||||
} else {
|
||||
ok = os_systemf(
|
||||
"clang ../src/testing/testing_main.c -o testing.exe -g -I ../src"
|
||||
" -fdiagnostics-absolute-paths -Wno-unsequenced"
|
||||
" -lm -ldl"
|
||||
);
|
||||
if (ok != 0) return ok;
|
||||
|
||||
ok = os_systemf("./testing.exe");
|
||||
if (ok != 0) return ok;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +121,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
if (wasm_code_modified) {
|
||||
ok = os_systemf(
|
||||
"clang.exe ../src/wasm_app/main.c -o main.wasm"
|
||||
"clang ../src/wasm_app/main.c -o main.wasm"
|
||||
" -Oz -g -I../src"
|
||||
" -Wall -Wno-missing-braces -Wno-single-bit-bitfield-constant-conversion -Wno-unsequenced -Wno-initializer-overrides"
|
||||
" -fdiagnostics-absolute-paths -fdiagnostics-format=msvc"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// automatically generated using: D:\dev\wasm\src/app/app.meta.c
|
||||
// automatically generated using: /home/sev/wasm/src/app/app.meta.c
|
||||
|
||||
type_t type__app_key_t = { type_kind_enum, s8_const_lit("app_key_t"), sizeof(app_key_t),
|
||||
.members = (type_member_t[]){
|
||||
@@ -228,7 +228,7 @@ app_key_t w32_map_wparam_to_app_key(WPARAM wparam) {
|
||||
default: {return app_key_null;} break;
|
||||
}
|
||||
}
|
||||
#endif/*D:\dev\wasm\src/app/app.meta.c(135)*/
|
||||
#endif/*/home/sev/wasm/src/app/app.meta.c(135)*/
|
||||
type_t type__app_mouse_button_t = { type_kind_enum, s8_const_lit("app_mouse_button_t"), sizeof(app_mouse_button_t),
|
||||
.members = (type_member_t[]){
|
||||
{.name = s8_const_lit("app_mouse_button_null"), .value = app_mouse_button_null},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// automatically generated using: D:\dev\wasm\src/app/app.meta.c
|
||||
// automatically generated using: /home/sev/wasm/src/app/app.meta.c
|
||||
typedef enum {
|
||||
app_key_null,
|
||||
app_key_1,
|
||||
@@ -71,7 +71,7 @@ app_key_page_up,
|
||||
app_key_page_down,
|
||||
app_key_count,
|
||||
} app_key_t;
|
||||
/*D:\dev\wasm\src/app/app.meta.c(135)*/
|
||||
/*/home/sev/wasm/src/app/app.meta.c(135)*/
|
||||
typedef enum {
|
||||
app_mouse_button_null,
|
||||
app_mouse_button_left,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
#include "app_win32_opengl.c"
|
||||
|
||||
#pragma comment(linker, "/subsystem:windows")
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
#include "core_platform_wasm.c"
|
||||
#elif PLATFORM_WINDOWS
|
||||
#pragma comment(lib, "user32.lib")
|
||||
#pragma comment(lib, "DbgHelp.lib")
|
||||
#define NOMINMAX
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <TlHelp32.h>
|
||||
#include <DbgHelp.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
@@ -21,11 +24,12 @@
|
||||
#include <time.h>
|
||||
#include <sys/mman.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <execinfo.h>
|
||||
#include <ucontext.h>
|
||||
#include <unistd.h>
|
||||
#include <dlfcn.h>
|
||||
#define B_STACKTRACE_IMPL
|
||||
#include "stacktrace.h"
|
||||
//:unix_debug_break
|
||||
//static void os_unix_sigtrap(int signum) { signal(SIGTRAP, SIG_DFL); }
|
||||
#include "core_platform_unix.c"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -140,13 +140,15 @@ union convert_f32_i32_t { f32 f; i32 i; };
|
||||
#define FILE_AND_LINE __FILE__":"STRINGIFY(__LINE__)
|
||||
#endif
|
||||
|
||||
#if PLATFORM_CL
|
||||
#if PLATFORM_WINDOWS
|
||||
#define debug__break() (IsDebuggerPresent() && (__debugbreak(), 1))
|
||||
#else
|
||||
#define debug__break() __builtin_trap()
|
||||
//:unix_debug_break
|
||||
#elif PLATFORM_UNIX
|
||||
// https://github.com/r-lyeh/tinybits/blob/master/tinyassert.c
|
||||
// #define debug__break() (signal(SIGTRAP, break_handler_), raise(SIGTRAP))
|
||||
#include <signal.h>
|
||||
static void os_unix_sigtrap(int signum) { signal(SIGTRAP, SIG_DFL); }
|
||||
#define debug__break() (signal(SIGTRAP, os_unix_sigtrap), raise(SIGTRAP))
|
||||
#else
|
||||
#define debug__break() __builtin_trap()
|
||||
#endif
|
||||
#define debug_break() (debug__break(), 1)
|
||||
|
||||
|
||||
@@ -28,18 +28,18 @@ fn void memory_zero(void *dst, usize size) {
|
||||
memory_set(dst, 0, size);
|
||||
}
|
||||
|
||||
fn_inline f32 f32_sqrt(f32 x) { return IF_PLATFORM_CLANG_ELSE(__builtin_sqrtf(x), sqrtf(x)); }
|
||||
fn_inline f64 f64_sqrt(f64 x) { return IF_PLATFORM_CLANG_ELSE(__builtin_sqrt(x), sqrt(x)); }
|
||||
fn_inline f32 f32_ceil(f32 x) { return IF_PLATFORM_CLANG_ELSE(__builtin_ceilf(x), ceilf(x)); }
|
||||
fn_inline f64 f64_ceil(f64 x) { return IF_PLATFORM_CLANG_ELSE(__builtin_ceil(x), ceil(x)); }
|
||||
fn_inline f32 f32_floor(f32 x) { return IF_PLATFORM_CLANG_ELSE(__builtin_floorf(x), floorf(x)); }
|
||||
fn_inline f64 f64_floor(f64 x) { return IF_PLATFORM_CLANG_ELSE(__builtin_floor(x), floor(x)); }
|
||||
fn_inline f32 f32_abs(f32 x) { return IF_PLATFORM_CLANG_ELSE(__builtin_fabsf(x), fabsf(x)); }
|
||||
fn_inline f64 f64_abs(f64 x) { return IF_PLATFORM_CLANG_ELSE(__builtin_fabs(x), fabs(x)); }
|
||||
// fn_inline f32 f32_round(f32 x) { return IF_PLATFORM_CLANG_ELSE(__builtin_roundf(x), roundf(x)); }
|
||||
fn_inline f64 f64_round(f64 x) { return IF_PLATFORM_CLANG_ELSE(__builtin_round(x), round(x)); }
|
||||
fn_inline f64 f64_mod(f64 a, f64 b) { return IF_PLATFORM_CLANG_ELSE(__builtin_fmod(a, b), fmod(a, b)); }
|
||||
fn_inline f32 f32_mod(f32 a, f32 b) { return IF_PLATFORM_CLANG_ELSE(__builtin_fmodf(a, b), fmodf(a, b)); }
|
||||
fn f32 f32_sqrt(f32 x) { return IF_PLATFORM_CLANG_ELSE(__builtin_sqrtf(x), sqrtf(x)); }
|
||||
fn f64 f64_sqrt(f64 x) { return IF_PLATFORM_CLANG_ELSE(__builtin_sqrt(x), sqrt(x)); }
|
||||
fn f32 f32_ceil(f32 x) { return IF_PLATFORM_CLANG_ELSE(__builtin_ceilf(x), ceilf(x)); }
|
||||
fn f64 f64_ceil(f64 x) { return IF_PLATFORM_CLANG_ELSE(__builtin_ceil(x), ceil(x)); }
|
||||
fn f32 f32_floor(f32 x) { return IF_PLATFORM_CLANG_ELSE(__builtin_floorf(x), floorf(x)); }
|
||||
fn f64 f64_floor(f64 x) { return IF_PLATFORM_CLANG_ELSE(__builtin_floor(x), floor(x)); }
|
||||
fn f32 f32_abs(f32 x) { return IF_PLATFORM_CLANG_ELSE(__builtin_fabsf(x), fabsf(x)); }
|
||||
fn f64 f64_abs(f64 x) { return IF_PLATFORM_CLANG_ELSE(__builtin_fabs(x), fabs(x)); }
|
||||
// fn f32 f32_round(f32 x) { return IF_PLATFORM_CLANG_ELSE(__builtin_roundf(x), roundf(x)); }
|
||||
fn f64 f64_round(f64 x) { return IF_PLATFORM_CLANG_ELSE(__builtin_round(x), round(x)); }
|
||||
fn f64 f64_mod(f64 a, f64 b) { return IF_PLATFORM_CLANG_ELSE(__builtin_fmod(a, b), fmod(a, b)); }
|
||||
fn f32 f32_mod(f32 a, f32 b) { return IF_PLATFORM_CLANG_ELSE(__builtin_fmodf(a, b), fmodf(a, b)); }
|
||||
|
||||
/* https://gitlab.com/nakst/essence/-/blob/master/shared/math.cpp
|
||||
**
|
||||
|
||||
@@ -35,5 +35,4 @@ fn void log_basef(log_level_t level, s8_t file_and_line, const char *str, ...);
|
||||
#define not_implemented assert(!"not implemented!")
|
||||
#define invalid_codepath assert(!"invalid code path!")
|
||||
#define default_is_invalid default: assert(!"invalid default case")
|
||||
#define else_is_invalid else { assert(!"else was not expected to be executed!"); }
|
||||
|
||||
#define else_is_invalid else { assert(!"else was not expected to be executed!"); }
|
||||
@@ -1,4 +1,4 @@
|
||||
// auto generated using: C:\dev\wasm\src\core\core_math_gen.py
|
||||
// auto generated using: core_math_gen.py
|
||||
fn_inline v2f32_t v2f32(f32 x, f32 y) { return (v2f32_t){ x, y }; }
|
||||
gb_read_only v2f32_t v2f32_null = {0};
|
||||
fn_inline b32 v2f32_is_null(v2f32_t a) { return memory_equal(&a, &v2f32_null, sizeof(a)); }
|
||||
|
||||
@@ -86,4 +86,8 @@
|
||||
#define IF_PLATFORM_WINDOWS(x) x
|
||||
#else
|
||||
#define IF_PLATFORM_WINDOWS(x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if PLATFORM_LINUX && !defined(_GNU_SOURCE)
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
@@ -3,17 +3,17 @@ fn void *os_vmem_reserve(usize size) {
|
||||
return result == MAP_FAILED ? NULL : result;
|
||||
}
|
||||
|
||||
fn b32 os_vmem_commit(void *p, usize size) {
|
||||
mprotect(p, size, PROT_READ|PROT_WRITE);
|
||||
fn b32 os_vmem_commit(void *ptr, usize size) {
|
||||
mprotect(ptr, size, PROT_READ|PROT_WRITE);
|
||||
return true;
|
||||
}
|
||||
|
||||
fn b32 os_vmem_release(void *p) {
|
||||
void *result = munmap(ptr, size);
|
||||
return result == MAP_FAILED ? false : true;
|
||||
fn b32 os_vmem_release(void *ptr) {
|
||||
int result = munmap(ptr, 0);
|
||||
return result == 0 ? true : false;
|
||||
}
|
||||
|
||||
fn b32 os_vmem_decommit(void *p, usize size) {
|
||||
fn b32 os_vmem_decommit(void *ptr, usize size) {
|
||||
madvise(ptr, size, MADV_DONTNEED);
|
||||
mprotect(ptr, size, PROT_NONE);
|
||||
return true;
|
||||
@@ -34,7 +34,7 @@ fn f64 os_parse_float(char *str) {
|
||||
}
|
||||
|
||||
fn void os_unix_crash_handler(int signal, siginfo_t* info, void* context) {
|
||||
context; // unused
|
||||
(void)context; // unused
|
||||
printf("signal: %d", signal);
|
||||
if (signal == SIGSEGV) {
|
||||
printf(" at addr: %p", info->si_addr);
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#if !defined(B_STACKTRACE_INCLUDED)
|
||||
#define B_STACKTRACE_INCLUDED (1)
|
||||
/*
|
||||
b_stacktrace v0.21 -- a cross-platform stack-trace generator
|
||||
SPDX-License-Identifier: MIT
|
||||
@@ -67,14 +65,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#if !defined(B_STACKTRACE_API)
|
||||
#define B_STACKTRACE_API extern
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
A stacktrace handle
|
||||
*/
|
||||
@@ -85,38 +75,22 @@ typedef struct b_stacktrace_tag* b_stacktrace_handle;
|
||||
can be expanded to a string via b_stacktrace_to_string.
|
||||
The handle is allocated with `malloc` and needs to be freed with `free`
|
||||
*/
|
||||
B_STACKTRACE_API b_stacktrace_handle b_stacktrace_get();
|
||||
fn b_stacktrace_handle b_stacktrace_get();
|
||||
|
||||
/*
|
||||
Converts a stack-trace handle to a human-readable string.
|
||||
The string is allocated with `malloc` and needs to be freed with `free`
|
||||
*/
|
||||
B_STACKTRACE_API char* b_stacktrace_to_string(b_stacktrace_handle stacktrace);
|
||||
fn char* b_stacktrace_to_string(b_stacktrace_handle stacktrace);
|
||||
|
||||
/*
|
||||
Returns a human-readable stack-trace string from the point of view of the
|
||||
caller.
|
||||
The string is allocated with `malloc` and needs to be freed with `free`
|
||||
*/
|
||||
B_STACKTRACE_API char* b_stacktrace_get_string(void);
|
||||
fn char* b_stacktrace_get_string(void);
|
||||
|
||||
/* version */
|
||||
#define B_STACKTRACE_VER_MAJOR 0
|
||||
#define B_STACKTRACE_VER_MINOR 20
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(B_STACKTRACE_IMPL)
|
||||
|
||||
#if defined(__linux__) && !defined(_GNU_SOURCE)
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
typedef struct print_buf {
|
||||
char* buf;
|
||||
@@ -160,15 +134,7 @@ char* b_stacktrace_get_string(void) {
|
||||
|
||||
#define B_STACKTRACE_MAX_DEPTH 1024
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
#include <TlHelp32.h>
|
||||
#include <DbgHelp.h>
|
||||
|
||||
#pragma comment(lib, "DbgHelp.lib")
|
||||
|
||||
#if PLATFORM_WINDOWS
|
||||
#define B_STACKTRACE_ERROR_FLAG ((DWORD64)1 << 63)
|
||||
|
||||
typedef struct b_stacktrace_entry {
|
||||
@@ -296,11 +262,7 @@ char* b_stacktrace_to_string(b_stacktrace_handle h) {
|
||||
return out.buf;
|
||||
}
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
#include <execinfo.h>
|
||||
#include <unistd.h>
|
||||
#include <dlfcn.h>
|
||||
#elif PLATFORM_MAC_OS
|
||||
|
||||
typedef struct b_stacktrace {
|
||||
void* trace[B_STACKTRACE_MAX_DEPTH];
|
||||
@@ -327,13 +289,7 @@ char* b_stacktrace_to_string(b_stacktrace_handle h) {
|
||||
return out.buf;
|
||||
}
|
||||
|
||||
#elif defined(__linux__)
|
||||
|
||||
#include <execinfo.h>
|
||||
#include <ucontext.h>
|
||||
#include <unistd.h>
|
||||
#include <dlfcn.h>
|
||||
#include <string.h>
|
||||
#elif PLATFORM_POSIX
|
||||
|
||||
typedef struct b_stacktrace {
|
||||
void* trace[B_STACKTRACE_MAX_DEPTH];
|
||||
@@ -407,6 +363,3 @@ char* b_stacktrace_get_string(void) {
|
||||
}
|
||||
#endif /* platform */
|
||||
|
||||
#endif /* B_STACKTRACE_IMPL */
|
||||
#endif /* B_STACKTRACE_INCLUDED */
|
||||
|
||||
|
||||
@@ -2747,11 +2747,12 @@ OS_API OS_FileIter OS_IterateFiles(MA_Arena *arena, S8_String path) {
|
||||
return it;
|
||||
}
|
||||
|
||||
OS_API int os_systemf(const char *string, ...);
|
||||
OS_API OS_Result os_make_dir(char *path) {
|
||||
IO_Printf("mkdir %s\n", path);
|
||||
MA_Temp scratch = MA_GetScratch();
|
||||
path = S8_Copy(scratch.arena, S8_MakeFromChar(path));
|
||||
int error = mkdir(path.str, 0755);
|
||||
S8_String path8 = S8_Copy(scratch.arena, S8_MakeFromChar(path));
|
||||
int error = mkdir(path8.str, 0755);
|
||||
MA_ReleaseScratch(scratch);
|
||||
return error == 0 ? OS_SUCCESS : OS_FAILURE;
|
||||
}
|
||||
@@ -5155,9 +5156,9 @@ int main(int argument_count, char **arguments) {
|
||||
if (S8_AreEqual(cc, S8_Lit("cl"), false)) {
|
||||
result = os_systemf("cl \"%.*s\" -nologo -Zi -WX -W3 -wd4200 -diagnostics:column /Fe:%.*s /Fd:%.*s.pdb", S8_Expand(build_file), S8_Expand(exe_name), S8_Expand(name_no_ext));
|
||||
} else if (S8_AreEqual(cc, S8_Lit("clang"), false)) {
|
||||
result = os_systemf("clang \"%.*s\" -o %.*s -g -fdiagnostics-absolute-paths -Wno-writable-strings %s", S8_Expand(build_file), S8_Expand(exe_name), IF_LINUX_ELSE("-lm", ""));
|
||||
result = os_systemf("clang \"%.*s\" -o %.*s -ldl -g -fdiagnostics-absolute-paths -Wno-writable-strings %s", S8_Expand(build_file), S8_Expand(exe_name), IF_LINUX_ELSE("-lm", ""));
|
||||
} else {
|
||||
result = os_systemf("g \"%.*s\" -o %.*s -g -Wno-write-strings %s", S8_Expand(build_file), S8_Expand(exe_name), IF_LINUX_ELSE("-lm", ""));
|
||||
result = os_systemf("gcc \"%.*s\" -o %.*s -ldl -g -Wno-write-strings %s", S8_Expand(build_file), S8_Expand(exe_name), IF_LINUX_ELSE("-lm", ""));
|
||||
}
|
||||
|
||||
if (result != 0) {
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#if PLATFORM_WINDOWS
|
||||
#include "os_win32.c"
|
||||
#elif PLATFORM_POSIX
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include "os_unix.c"
|
||||
#endif
|
||||
|
||||
|
||||
128
src/os/os_unix.c
128
src/os/os_unix.c
@@ -1,16 +1,30 @@
|
||||
fn os_date_t os_local_time_now(void) {
|
||||
fn os_date_t os_local_time(void) {
|
||||
os_date_t result = {0};
|
||||
time_t time = time(NULL);
|
||||
struct tm *lt = localtime(&time);
|
||||
time_t t = time(NULL);
|
||||
struct tm *lt = localtime(&t);
|
||||
result.sec = lt->tm_sec;
|
||||
result.min = lt->tm_min;
|
||||
result.hour = lt->tm_hour;
|
||||
result.day = lt->tm_mday;
|
||||
result.month = lt->tm_month;
|
||||
result.month = lt->tm_mon;
|
||||
result.year = lt->tm_year;
|
||||
return result;
|
||||
}
|
||||
|
||||
fn os_date_t os_universal_time(void) {
|
||||
os_date_t result = {0};
|
||||
time_t t = time(NULL);
|
||||
struct tm u = {0};
|
||||
gmtime_r(&t, &u);
|
||||
result.sec = u.tm_sec;
|
||||
result.min = u.tm_min;
|
||||
result.hour = u.tm_hour;
|
||||
result.day = u.tm_mday;
|
||||
result.month = u.tm_mon;
|
||||
result.year = u.tm_year;
|
||||
return result;
|
||||
}
|
||||
|
||||
fn u64 os_get_microseconds(void) {
|
||||
struct timespec t;
|
||||
clock_gettime(CLOCK_MONOTONIC, &t);
|
||||
@@ -22,4 +36,110 @@ fn f64 os_get_milliseconds(void) {
|
||||
u64 micros = os_get_microseconds();
|
||||
f64 result = (f64)micros / 1000.0;
|
||||
return result;
|
||||
}
|
||||
|
||||
fn s8_t os_exe(ma_arena_t *arena) {
|
||||
const i32 buffer_size = 2048;
|
||||
ma_temp_t temp = ma_begin_scratch1(arena);
|
||||
char *buffer = ma_push_array(arena, char, buffer_size);
|
||||
ssize_t size = readlink("/proc/self/exe", buffer, buffer_size);
|
||||
assert(size < buffer_size); // @todo:?
|
||||
assert(size != -1);
|
||||
s8_t string = s8_copy(arena, s8(buffer, size));
|
||||
ma_end_scratch(temp);
|
||||
return string;
|
||||
}
|
||||
|
||||
fn s8_t os_exe_dir(ma_arena_t *arena) {
|
||||
ma_temp_t temp = ma_begin_scratch1(arena);
|
||||
s8_t exe = os_exe(temp.arena);
|
||||
s8_t dir = s8_chop_last_slash(exe);
|
||||
dir.len += 1;
|
||||
s8_t result = s8_copy(arena, dir);
|
||||
ma_end_scratch(temp);
|
||||
assert(result.str[result.len - 1] == '/');
|
||||
return result;
|
||||
}
|
||||
|
||||
fn s8_t os_cwd(ma_arena_t *arena) {
|
||||
const i32 buffer_size = 2048;
|
||||
ma_temp_t temp = ma_begin_scratch1(arena);
|
||||
char *buffer = ma_push_array(arena, char, buffer_size);
|
||||
char *ok = getcwd(buffer, buffer_size);
|
||||
assert(ok);
|
||||
s8_t result = s8_printf(arena, "%s/", buffer);
|
||||
ma_end_scratch(temp);
|
||||
assert(result.str[result.len - 1] == '/');
|
||||
return result;
|
||||
}
|
||||
|
||||
fn b32 os_exists(s8_t path) {
|
||||
ma_temp_t temp = ma_begin_scratch();
|
||||
s8_t copy = s8_copy(temp.arena, path);
|
||||
int ok = access(copy.str, F_OK);
|
||||
ma_end_scratch(temp);
|
||||
return ok == 0 ? true : false;
|
||||
}
|
||||
|
||||
fn b32 os_is_dir(s8_t path) {
|
||||
b32 result = false;
|
||||
ma_temp_t temp = ma_begin_scratch();
|
||||
s8_t copy = s8_copy(temp.arena, path);
|
||||
DIR *dir = opendir(copy.str);
|
||||
if (dir) {
|
||||
result = true;
|
||||
closedir(dir);
|
||||
}
|
||||
ma_end_scratch(temp);
|
||||
return result;
|
||||
}
|
||||
|
||||
fn b32 os_is_file(s8_t path) {
|
||||
ma_temp_t temp = ma_begin_scratch();
|
||||
s8_t copy = s8_copy(temp.arena, path);
|
||||
struct stat path_stat;
|
||||
stat(copy.str, &path_stat);
|
||||
ma_end_scratch(temp);
|
||||
b32 result = S_ISREG(path_stat.st_mode);
|
||||
return result;
|
||||
}
|
||||
|
||||
fn b32 os_is_abs(s8_t path) {
|
||||
b32 result = path.len && path.str[0] == '/';
|
||||
return result;
|
||||
}
|
||||
|
||||
fn s8_t os_read(ma_arena_t *arena, s8_t path) {
|
||||
s8_t result = {0};
|
||||
ma_temp_t temp = ma_begin_scratch1(arena);
|
||||
s8_t copy_path = s8_copy(temp.arena, path);
|
||||
FILE *fd = fopen(copy_path.str, "rb");
|
||||
if (fd) {
|
||||
fseek(fd, 0, SEEK_END);
|
||||
long size = ftell(fd);
|
||||
fseek(fd, 0, SEEK_SET);
|
||||
char *string = malloc(size + 1);
|
||||
fread(string, size, 1, fd);
|
||||
fclose(fd);
|
||||
|
||||
result = s8(string, size);
|
||||
result.str[result.len] = 0;
|
||||
}
|
||||
ma_end_scratch(temp);
|
||||
return result;
|
||||
}
|
||||
|
||||
fn os_write_t os_write(s8_t path, s8_t content) {
|
||||
os_write_t result = os_write_path_not_found;
|
||||
ma_temp_t scratch = ma_begin_scratch();
|
||||
s8_t copy_path = s8_copy(scratch.arena, path);
|
||||
FILE *fd = fopen(copy_path.str, "w");
|
||||
if (fd) {
|
||||
size_t size_written = fwrite(content.str, 1, content.len, fd);
|
||||
assert((int64_t)size_written == content.len);
|
||||
fclose(fd);
|
||||
result = os_write_success;
|
||||
}
|
||||
ma_end_scratch(scratch);
|
||||
return result;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// automatically generated using: D:\dev\wasm\src/render/render.meta.c
|
||||
// automatically generated using: /home/sev/wasm/src/render/render.meta.c
|
||||
gb_read_only u8 main_font_data[] = {
|
||||
0,1,0,0,0,16,1,0,0,4,0,0,71,68,69,70,9,171,18,85,0,0,2,40,0,0,1,242,71,80,79,83,196,118,81,155,0,0,24,140,0,0,22,52,71,83,85,66,112,248,190,150,0,0,222,16,0,0,83,202,79,83,47,50,
|
||||
138,149,152,224,0,0,1,200,0,0,0,96,83,84,65,84,121,145,108,221,0,0,1,96,0,0,0,46,99,109,97,112,147,243,132,151,0,0,75,136,0,0,65,218,103,97,115,112,0,0,0,16,0,0,1,20,0,0,0,8,103,108,121,102,
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
fn void os_test(void) {
|
||||
os_date_t local_time = os_local_time();
|
||||
os_date_t universal_time = os_universal_time();
|
||||
debugf("local_time = %S | universal_time = %S", os_format_date(tcx->temp, local_time), os_format_date(tcx->temp, universal_time));
|
||||
debugf("OS local_time = %S | universal_time = %S", os_format_date(tcx->temp, local_time), os_format_date(tcx->temp, universal_time));
|
||||
|
||||
s8_t exe_dir = os_exe_dir(tcx->temp);
|
||||
assert(exe_dir.str[exe_dir.len - 1] == '/');
|
||||
s8_t exe = os_exe(tcx->temp);
|
||||
s8_t cwd = os_cwd(tcx->temp);
|
||||
assert(exe_dir.str[cwd.len - 1] == '/');
|
||||
assert(cwd.str[cwd.len - 1] == '/');
|
||||
assert(os_is_dir(exe_dir));
|
||||
assert(os_is_file(exe));
|
||||
assert(os_is_dir(cwd));
|
||||
@@ -25,7 +25,11 @@ fn void os_test(void) {
|
||||
assert(os_is_abs(exe));
|
||||
assert(os_is_abs(cwd));
|
||||
assert(!os_is_abs(s8_lit("../path/")));
|
||||
debugf("%S %S %S", exe_dir, exe, cwd);
|
||||
debugf("OS paths %S %S %S", exe_dir, exe, cwd);
|
||||
|
||||
s8_t file = os_read(tcx->temp, s8_lit("../.gitignore"));
|
||||
assert(file.str != 0);
|
||||
assert(file.len != 0);
|
||||
}
|
||||
|
||||
fn void test_s8(void) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// automatically generated using: D:\dev\wasm\src/ui/ui.meta.c
|
||||
// automatically generated using: /home/sev/wasm/src/ui/ui.meta.c
|
||||
|
||||
type_t type__ui_color_t = { type_kind_enum, s8_const_lit("ui_color_t"), sizeof(ui_color_t),
|
||||
.members = (type_member_t[]){
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// automatically generated using: D:\dev\wasm\src/ui/ui.meta.c
|
||||
// automatically generated using: /home/sev/wasm/src/ui/ui.meta.c
|
||||
typedef enum {
|
||||
ui_color_rect,
|
||||
ui_color_rect_hot,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// automatically generated using: D:\dev\wasm\src/wasm_app/wasm_app.meta.c
|
||||
// automatically generated using: /home/sev/wasm/src/wasm_app/wasm_app.meta.c
|
||||
gb f32 font_size = 30;
|
||||
gb f32 _font_size = 30;
|
||||
gb_read_only mt_tweak_t tweak_table[] = {
|
||||
|
||||
Reference in New Issue
Block a user