From a9ab90bd2488783c3523fa30315f9754937fd52e Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sat, 23 Feb 2019 22:17:27 +0000 Subject: Make `static` an attribute rather than a keyword prefix --- core/strings/builder.odin | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core/strings') diff --git a/core/strings/builder.odin b/core/strings/builder.odin index e86d748cc..547c456ba 100644 --- a/core/strings/builder.odin +++ b/core/strings/builder.odin @@ -61,8 +61,8 @@ write_bytes :: proc(b: ^Builder, x: []byte) { append(&b.buf, ..x); } -@(private) -static DIGITS_LOWER := "0123456789abcdefx"; +@(private, static) +DIGITS_LOWER := "0123456789abcdefx"; write_quoted_string :: proc(b: ^Builder, s: string, quote: byte = '"') { write_byte(b, quote); -- cgit v1.2.3 From d852b0c9485267f247210f3a2f8021e8e2c96232 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Sat, 9 Mar 2019 11:08:50 +0100 Subject: Add win32.get_cwd to return the current working directory --- core/strings/strings.odin | 17 +++++++++++++++++ core/sys/win32/crt.odin | 14 ++++++++++++++ core/sys/win32/general.odin | 3 +++ 3 files changed, 34 insertions(+) create mode 100644 core/sys/win32/crt.odin (limited to 'core/strings') diff --git a/core/strings/strings.odin b/core/strings/strings.odin index c8c8e560c..edf288c16 100644 --- a/core/strings/strings.odin +++ b/core/strings/strings.odin @@ -329,6 +329,10 @@ is_space :: proc(r: rune) -> bool { return false; } +is_null :: proc(r: rune) -> bool { + return r == 0x0000; +} + index_proc :: proc(s: string, p: proc(rune) -> bool, truth := true) -> int { for r, i in s { if p(r) == truth { @@ -476,3 +480,16 @@ trim_right_space :: proc(s: string) -> string { trim_space :: proc(s: string) -> string { return trim_right_space(trim_left_space(s)); } + +trim_left_null :: proc(s: string) -> string { + return trim_left_proc(s, is_null); +} + +trim_right_null :: proc(s: string) -> string { + return trim_right_proc(s, is_null); +} + +trim_null :: proc(s: string) -> string { + return trim_right_null(trim_left_null(s)); +} + diff --git a/core/sys/win32/crt.odin b/core/sys/win32/crt.odin new file mode 100644 index 000000000..46fba6fe8 --- /dev/null +++ b/core/sys/win32/crt.odin @@ -0,0 +1,14 @@ +package win32 + +import "core:strings"; + +foreign { + @(link_name="_wgetcwd") _get_cwd_wide :: proc(buffer: Wstring, buf_len: int) -> ^Wstring --- +} + +get_cwd :: proc(allocator := context.temp_allocator) -> string { + buffer := make([]u16, MAX_PATH_WIDE, allocator); + _get_cwd_wide(Wstring(&buffer[0]), MAX_PATH_WIDE); + file := ucs2_to_utf8(buffer[:], allocator); + return strings.trim_right_null(file); +} \ No newline at end of file diff --git a/core/sys/win32/general.odin b/core/sys/win32/general.odin index c34294b51..f4f3de380 100644 --- a/core/sys/win32/general.odin +++ b/core/sys/win32/general.odin @@ -108,6 +108,8 @@ File_Attribute_Data :: struct { file_size_low: u32, } +// NOTE(Jeroen): The widechar version might want at least the 32k MAX_PATH_WIDE +// https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-findfirstfilew#parameters Find_Data_W :: struct{ file_attributes: u32, creation_time: Filetime, @@ -798,6 +800,7 @@ is_key_down :: inline proc(key: Key_Code) -> bool { return get_async_key_state(i MAX_PATH :: 0x00000104; +MAX_PATH_WIDE :: 0x8000; HANDLE_FLAG_INHERIT :: 1; HANDLE_FLAG_PROTECT_FROM_CLOSE :: 2; -- cgit v1.2.3