formatting
This commit is contained in:
parent
a504b27767
commit
630dbdbb58
66
src/sys.h
66
src/sys.h
@ -335,19 +335,29 @@ struct sys_file_time {
|
||||
};
|
||||
|
||||
struct string sys_get_write_path(struct arena *arena);
|
||||
|
||||
b32 sys_is_file(struct string path);
|
||||
|
||||
b32 sys_is_dir(struct string path);
|
||||
|
||||
void sys_mkdir(struct string path);
|
||||
|
||||
struct sys_file sys_file_open_read(struct string path);
|
||||
|
||||
struct sys_file sys_file_open_read_wait(struct string path); /* Waits until file is not being used by another program */
|
||||
|
||||
struct sys_file sys_file_open_write(struct string path);
|
||||
|
||||
struct sys_file sys_file_open_append(struct string path);
|
||||
|
||||
void sys_file_close(struct sys_file file);
|
||||
|
||||
struct string sys_file_read_all(struct arena *arena, struct sys_file file);
|
||||
|
||||
void sys_file_write(struct sys_file file, struct string data);
|
||||
|
||||
u64 sys_file_get_size(struct sys_file file);
|
||||
|
||||
struct sys_file_time sys_file_get_time(struct sys_file file);
|
||||
|
||||
/* ========================== *
|
||||
@ -361,7 +371,9 @@ struct sys_file_map {
|
||||
};
|
||||
|
||||
struct sys_file_map sys_file_map_open_read(struct sys_file file);
|
||||
|
||||
void sys_file_map_close(struct sys_file_map map);
|
||||
|
||||
struct string sys_file_map_data(struct sys_file_map map);
|
||||
|
||||
/* ========================== *
|
||||
@ -380,7 +392,9 @@ struct sys_file_filter {
|
||||
|
||||
/* Iterate all files in a directory */
|
||||
struct sys_file_filter sys_file_filter_begin(struct arena *arena, struct string pattern);
|
||||
|
||||
b32 sys_file_filter_next(struct arena *arena, struct sys_file_filter *iter);
|
||||
|
||||
void sys_file_filter_end(struct sys_file_filter *iter);
|
||||
|
||||
/* ========================== *
|
||||
@ -411,9 +425,13 @@ struct sys_watch_info_list {
|
||||
};
|
||||
|
||||
struct sys_watch *sys_watch_alloc(struct string path);
|
||||
|
||||
void sys_watch_release(struct sys_watch *dw);
|
||||
|
||||
struct sys_watch_info_list sys_watch_wait(struct arena *arena, struct sys_watch *dw);
|
||||
|
||||
void sys_watch_wake(struct sys_watch *dw);
|
||||
|
||||
struct sys_watch_info_list sys_watch_info_copy(struct arena *arena, struct sys_watch_info_list src);
|
||||
|
||||
/* ========================== *
|
||||
@ -457,25 +475,32 @@ struct sys_window_settings {
|
||||
};
|
||||
|
||||
struct sys_window *sys_window_alloc(void);
|
||||
|
||||
void sys_window_release(struct sys_window *sys_window);
|
||||
|
||||
struct sys_event_array sys_window_pop_events(struct arena *arena, struct sys_window *sys_window);
|
||||
|
||||
void sys_window_update_settings(struct sys_window *sys_window, struct sys_window_settings *settings);
|
||||
|
||||
struct sys_window_settings sys_window_get_settings(struct sys_window *sys_window);
|
||||
|
||||
void sys_window_show(struct sys_window *sys_window);
|
||||
|
||||
struct v2 sys_window_get_size(struct sys_window *sys_window);
|
||||
|
||||
struct v2 sys_window_get_monitor_size(struct sys_window *sys_window);
|
||||
|
||||
/* Returns a platform specific representation of the window. E.g. `hwnd` on win32. */
|
||||
u64 sys_window_get_internal_handle(struct sys_window *sys_window);
|
||||
|
||||
void sys_window_cursor_set_pos(struct sys_window *sys_window, struct v2 pos);
|
||||
|
||||
void sys_window_cursor_show(struct sys_window *sys_window);
|
||||
|
||||
void sys_window_cursor_hide(struct sys_window *sys_window);
|
||||
|
||||
void sys_window_cursor_enable_clip(struct sys_window *sys_window, struct rect bounds);
|
||||
|
||||
void sys_window_cursor_disable_clip(struct sys_window *sys_window);
|
||||
|
||||
/* ========================== *
|
||||
@ -494,7 +519,9 @@ struct sys_thread *sys_thread_alloc(
|
||||
);
|
||||
|
||||
void sys_thread_wait_release(struct sys_thread *thread);
|
||||
|
||||
b32 sys_thread_try_release(struct sys_thread *thread, f32 timeout_seconds); /* Returns 0 if the thread could not release in specified timeout (e.g. because it is still running) */
|
||||
|
||||
void sys_thread_force_release(struct sys_thread *thread);
|
||||
|
||||
/* Gets the current executing thread's ID */
|
||||
@ -507,26 +534,6 @@ void sys_thread_assert(u32 tid);
|
||||
# define sys_thread_assert(tid)
|
||||
#endif
|
||||
|
||||
/* ========================== *
|
||||
* Message box
|
||||
* ========================== */
|
||||
|
||||
enum sys_message_box_kind {
|
||||
SYS_MESSAGE_BOX_KIND_OK,
|
||||
SYS_MESSAGE_BOX_KIND_WARNING,
|
||||
SYS_MESSAGE_BOX_KIND_ERROR,
|
||||
SYS_MESSAGE_BOX_KIND_FATAL
|
||||
};
|
||||
|
||||
void sys_message_box(enum sys_message_box_kind kind, struct string message);
|
||||
|
||||
/* ========================== *
|
||||
* Clipboard
|
||||
* ========================== */
|
||||
|
||||
void sys_set_clipboard_text(struct string str);
|
||||
struct string sys_get_clipboard_text(struct arena *arena);
|
||||
|
||||
/* ========================== *
|
||||
* Address
|
||||
* ========================== */
|
||||
@ -545,8 +552,11 @@ struct sys_address {
|
||||
};
|
||||
|
||||
struct sys_address sys_address_from_string(struct string str);
|
||||
|
||||
struct sys_address sys_address_from_port(u16 port);
|
||||
|
||||
struct string sys_string_from_address(struct arena *arena, struct sys_address address);
|
||||
|
||||
b32 sys_address_eq(struct sys_address a, struct sys_address b);
|
||||
|
||||
/* ========================== *
|
||||
@ -560,16 +570,32 @@ struct sys_sock_read_result {
|
||||
};
|
||||
|
||||
struct sys_sock *sys_sock_alloc(u16 listen_port, u64 sndbuf_size, u64 rcvbuf_size);
|
||||
|
||||
void sys_sock_release(struct sys_sock *sock);
|
||||
|
||||
struct sys_sock_read_result sys_sock_read(struct arena *arena, struct sys_sock *sock);
|
||||
|
||||
void sys_sock_write(struct sys_sock *sock, struct sys_address address, struct string data);
|
||||
|
||||
/* ========================== *
|
||||
* Util
|
||||
* ========================== */
|
||||
|
||||
enum sys_message_box_kind {
|
||||
SYS_MESSAGE_BOX_KIND_OK,
|
||||
SYS_MESSAGE_BOX_KIND_WARNING,
|
||||
SYS_MESSAGE_BOX_KIND_ERROR,
|
||||
SYS_MESSAGE_BOX_KIND_FATAL
|
||||
};
|
||||
|
||||
void sys_message_box(enum sys_message_box_kind kind, struct string message);
|
||||
|
||||
void sys_set_clipboard_text(struct string str);
|
||||
|
||||
struct string sys_get_clipboard_text(struct arena *arena);
|
||||
|
||||
void sys_true_rand(struct string b);
|
||||
|
||||
u32 sys_num_logical_processors(void);
|
||||
|
||||
#endif
|
||||
|
||||
180
src/sys_win32.c
180
src/sys_win32.c
@ -3065,98 +3065,6 @@ void sys_thread_assert(u32 tid)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ========================== *
|
||||
* Message box
|
||||
* ========================== */
|
||||
|
||||
void sys_message_box(enum sys_message_box_kind kind, struct string message)
|
||||
{
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
wchar_t *message_wstr = wstr_from_string(scratch.arena, message);
|
||||
const wchar_t *title = L"";
|
||||
UINT mbox_type = MB_SETFOREGROUND;
|
||||
|
||||
switch (kind) {
|
||||
case SYS_MESSAGE_BOX_KIND_OK: {
|
||||
mbox_type |= MB_ICONINFORMATION;
|
||||
} break;
|
||||
|
||||
case SYS_MESSAGE_BOX_KIND_WARNING: {
|
||||
title = L"Warning";
|
||||
mbox_type |= MB_ICONWARNING;
|
||||
} break;
|
||||
|
||||
case SYS_MESSAGE_BOX_KIND_ERROR: {
|
||||
title = L"Error";
|
||||
mbox_type |= MB_ICONERROR;
|
||||
} break;
|
||||
|
||||
case SYS_MESSAGE_BOX_KIND_FATAL: {
|
||||
title = L"Fatal error";
|
||||
mbox_type |= MB_ICONSTOP;
|
||||
} break;
|
||||
}
|
||||
|
||||
logf_info("Showing message box kind %F with text \"%F\"", FMT_SINT(kind), FMT_STR(message));
|
||||
MessageBoxExW(0, message_wstr, title, mbox_type, 0);
|
||||
|
||||
scratch_end(scratch);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Clipboard
|
||||
* ========================== */
|
||||
|
||||
void sys_set_clipboard_text(struct string str)
|
||||
{
|
||||
if (OpenClipboard(0)) {
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
struct string16 str16 = string16_from_string(scratch.arena, str);
|
||||
u64 str16_size_bytes = str16.len * 2;
|
||||
EmptyClipboard();
|
||||
HANDLE handle = GlobalAlloc(GMEM_MOVEABLE, str16_size_bytes + 1);
|
||||
if (handle) {
|
||||
u16 *dest_wstr = (u16 *)GlobalLock(handle);
|
||||
MEMCPY(dest_wstr, str16.text, str16_size_bytes);
|
||||
dest_wstr[str16.len] = 0;
|
||||
GlobalUnlock(handle);
|
||||
SetClipboardData(CF_UNICODETEXT, handle);
|
||||
}
|
||||
CloseClipboard();
|
||||
scratch_end(scratch);
|
||||
}
|
||||
}
|
||||
|
||||
struct string sys_get_clipboard_text(struct arena *arena)
|
||||
{
|
||||
struct string res = ZI;
|
||||
if (IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(0)) {
|
||||
HANDLE handle = GetClipboardData(CF_UNICODETEXT);
|
||||
if (handle) {
|
||||
u16 *src_wstr = (u16 *)GlobalLock(handle);
|
||||
res = string_from_string16(arena, string16_from_wstr_no_limit(src_wstr));
|
||||
GlobalUnlock(handle);
|
||||
}
|
||||
CloseClipboard();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Util
|
||||
* ========================== */
|
||||
|
||||
void sys_true_rand(struct string b)
|
||||
{
|
||||
BCryptGenRandom(BCRYPT_RNG_ALG_HANDLE, (PUCHAR)b.text, b.len, 0);
|
||||
}
|
||||
|
||||
u32 sys_num_logical_processors(void)
|
||||
{
|
||||
return GetActiveProcessorCount(ALL_PROCESSOR_GROUPS);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Address
|
||||
* ========================== */
|
||||
@ -3498,6 +3406,94 @@ void sys_sock_write(struct sys_sock *sock, struct sys_address address, struct st
|
||||
#endif
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Util
|
||||
* ========================== */
|
||||
|
||||
void sys_message_box(enum sys_message_box_kind kind, struct string message)
|
||||
{
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
wchar_t *message_wstr = wstr_from_string(scratch.arena, message);
|
||||
const wchar_t *title = L"";
|
||||
UINT mbox_type = MB_SETFOREGROUND;
|
||||
|
||||
switch (kind) {
|
||||
case SYS_MESSAGE_BOX_KIND_OK:
|
||||
{
|
||||
mbox_type |= MB_ICONINFORMATION;
|
||||
} break;
|
||||
|
||||
case SYS_MESSAGE_BOX_KIND_WARNING:
|
||||
{
|
||||
title = L"Warning";
|
||||
mbox_type |= MB_ICONWARNING;
|
||||
} break;
|
||||
|
||||
case SYS_MESSAGE_BOX_KIND_ERROR:
|
||||
{
|
||||
title = L"Error";
|
||||
mbox_type |= MB_ICONERROR;
|
||||
} break;
|
||||
|
||||
case SYS_MESSAGE_BOX_KIND_FATAL:
|
||||
{
|
||||
title = L"Fatal error";
|
||||
mbox_type |= MB_ICONSTOP;
|
||||
} break;
|
||||
}
|
||||
|
||||
logf_info("Showing message box kind %F with text \"%F\"", FMT_SINT(kind), FMT_STR(message));
|
||||
MessageBoxExW(0, message_wstr, title, mbox_type, 0);
|
||||
|
||||
scratch_end(scratch);
|
||||
}
|
||||
|
||||
void sys_set_clipboard_text(struct string str)
|
||||
{
|
||||
if (OpenClipboard(0)) {
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
struct string16 str16 = string16_from_string(scratch.arena, str);
|
||||
u64 str16_size_bytes = str16.len * 2;
|
||||
EmptyClipboard();
|
||||
HANDLE handle = GlobalAlloc(GMEM_MOVEABLE, str16_size_bytes + 1);
|
||||
if (handle) {
|
||||
u16 *dest_wstr = (u16 *)GlobalLock(handle);
|
||||
MEMCPY(dest_wstr, str16.text, str16_size_bytes);
|
||||
dest_wstr[str16.len] = 0;
|
||||
GlobalUnlock(handle);
|
||||
SetClipboardData(CF_UNICODETEXT, handle);
|
||||
}
|
||||
CloseClipboard();
|
||||
scratch_end(scratch);
|
||||
}
|
||||
}
|
||||
|
||||
struct string sys_get_clipboard_text(struct arena *arena)
|
||||
{
|
||||
struct string res = ZI;
|
||||
if (IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(0)) {
|
||||
HANDLE handle = GetClipboardData(CF_UNICODETEXT);
|
||||
if (handle) {
|
||||
u16 *src_wstr = (u16 *)GlobalLock(handle);
|
||||
res = string_from_string16(arena, string16_from_wstr_no_limit(src_wstr));
|
||||
GlobalUnlock(handle);
|
||||
}
|
||||
CloseClipboard();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void sys_true_rand(struct string b)
|
||||
{
|
||||
BCryptGenRandom(BCRYPT_RNG_ALG_HANDLE, (PUCHAR)b.text, b.len, 0);
|
||||
}
|
||||
|
||||
u32 sys_num_logical_processors(void)
|
||||
{
|
||||
return GetActiveProcessorCount(ALL_PROCESSOR_GROUPS);
|
||||
}
|
||||
|
||||
/* ========================== *
|
||||
* Entry point
|
||||
* ========================== */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user