egl/glx work; eliminate unneeded path normalization paths; do not assume os current path when normalizing paths; gl synchronous debug strings

This commit is contained in:
Ryan Fleury
2025-05-12 16:03:36 -07:00
parent fe3cac7ac3
commit a5b227a1c6
20 changed files with 230 additions and 205 deletions
+45 -64
View File
@@ -1,6 +1,9 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//~ rjf: Relative <-> Absolute Path
internal String8
path_relative_dst_from_absolute_dst_src(Arena *arena, String8 dst, String8 src)
{
@@ -8,7 +11,7 @@ path_relative_dst_from_absolute_dst_src(Arena *arena, String8 dst, String8 src)
// rjf: gather path parts
String8 dst_name = str8_skip_last_slash(dst);
String8 src_folder = str8_chop_last_slash(src);
String8 src_folder = src;
String8 dst_folder = str8_chop_last_slash(dst);
String8List src_folders = str8_split_path(scratch.arena, src_folder);
String8List dst_folders = str8_split_path(scratch.arena, dst_folder);
@@ -35,7 +38,7 @@ path_relative_dst_from_absolute_dst_src(Arena *arena, String8 dst, String8 src)
String8 dst_path = {0};
if(num_backtracks >= src_folders.node_count)
{
dst_path = path_normalized_from_string(arena, dst);
dst_path = dst;
}
else
{
@@ -90,54 +93,43 @@ path_absolute_dst_from_relative_dst_src(Arena *arena, String8 dst, String8 src)
if(dst_style == PathStyle_Relative)
{
Temp scratch = scratch_begin(&arena, 1);
String8 dst_from_src_absolute = push_str8f(scratch.arena, "%S/%S", str8_chop_last_slash(src), dst);
String8 dst_from_src_absolute_normalized = path_normalized_from_string(arena, dst_from_src_absolute);
result = dst_from_src_absolute_normalized;
String8 dst_from_src_absolute = push_str8f(scratch.arena, "%S/%S", src, dst);
String8List dst_from_src_absolute_parts = str8_split_path(scratch.arena, dst_from_src_absolute);
PathStyle dst_from_src_absolute_style = path_style_from_str8(src);
str8_path_list_resolve_dots_in_place(&dst_from_src_absolute_parts, dst_from_src_absolute_style);
result = str8_path_list_join_by_style(arena, &dst_from_src_absolute_parts, dst_from_src_absolute_style);
scratch_end(scratch);
}
return result;
}
////////////////////////////////
//~ rjf: Path Normalization
internal String8List
path_normalized_list_from_string(Arena *arena, String8 path_string, PathStyle *style_out)
{
// analyze path
// rjf: analyze path
PathStyle path_style = path_style_from_str8(path_string);
String8List path = str8_split_path(arena, path_string);
// prepend current path to convert relative -> absolute
PathStyle path_style_full = path_style;
if(path.node_count != 0 && path_style == PathStyle_Relative)
{
String8 current_path_string = os_get_current_path(arena);
PathStyle current_path_style = path_style_from_str8(current_path_string);
Assert(current_path_style != PathStyle_Relative);
String8List current_path = str8_split_path(arena, current_path_string);
str8_list_concat_in_place(&current_path, &path);
path = current_path;
path_style_full = current_path_style;
}
// rjf: resolve dots
str8_path_list_resolve_dots_in_place(&path, path_style);
// resolve dots
str8_path_list_resolve_dots_in_place(&path, path_style_full);
// return
// rjf: return
if(style_out != 0)
{
*style_out = path_style_full;
*style_out = path_style;
}
return path;
}
internal String8
path_normalized_from_string(Arena *arena, String8 path_string){
path_normalized_from_string(Arena *arena, String8 path_string)
{
Temp scratch = scratch_begin(&arena, 1);
PathStyle style = PathStyle_Relative;
String8List path = path_normalized_list_from_string(scratch.arena, path_string, &style);
String8 result = str8_path_list_join_by_style(arena, &path, style);
scratch_end(scratch);
return result;
@@ -154,8 +146,31 @@ path_match_normalized(String8 left, String8 right)
return result;
}
////////////////////////////////
//~ rjf: Basic Helpers
internal PathStyle
path_style_from_string(String8 string)
{
for (U64 i = 0; i < ArrayCount(g_path_style_map); ++i)
{
if(str8_match(g_path_style_map[i].string, string, StringMatchFlag_CaseInsensitive))
{
return g_path_style_map[i].path_style;
}
}
return PathStyle_Null;
}
internal String8
path_char_from_style(PathStyle style)
string_from_path_style(PathStyle style)
{
Assert(style < ArrayCount(g_path_style_map));
return g_path_style_map[style].string;
}
internal String8
path_separator_string_from_style(PathStyle style)
{
String8 result = str8_zero();
switch (style)
@@ -194,7 +209,7 @@ path_convert_slashes(Arena *arena, String8 path, PathStyle path_style)
Temp scratch = scratch_begin(&arena, 1);
String8List list = str8_split_path(scratch.arena, path);
StringJoin join = {0};
join.sep = path_char_from_style(path_style);
join.sep = path_separator_string_from_style(path_style);
String8 result = str8_list_join(arena, &list, &join);
scratch_end(scratch);
return result;
@@ -207,37 +222,3 @@ path_replace_file_extension(Arena *arena, String8 file_name, String8 ext)
String8 result = push_str8f(arena, "%S.%S", file_name_no_ext, ext);
return result;
}
global read_only struct
{
String8 string;
PathStyle path_style;
} g_path_style_map[] =
{
{ str8_lit_comp(""), PathStyle_Null },
{ str8_lit_comp("relative"), PathStyle_Relative },
{ str8_lit_comp("windows"), PathStyle_WindowsAbsolute },
{ str8_lit_comp("unix"), PathStyle_UnixAbsolute },
{ str8_lit_comp("system"), PathStyle_SystemAbsolute },
};
internal PathStyle
path_style_from_string(String8 string)
{
for (U64 i = 0; i < ArrayCount(g_path_style_map); ++i)
{
if(str8_match(g_path_style_map[i].string, string, StringMatchFlag_CaseInsensitive))
{
return g_path_style_map[i].path_style;
}
}
return PathStyle_Null;
}
internal String8
path_string_from_style(PathStyle style)
{
Assert(style < ArrayCount(g_path_style_map));
return g_path_style_map[style].string;
}