2019-10-03 02:58:05 +00:00
|
|
|
/*
|
|
|
|
* Mr. 4th Dimention - Allen Webster
|
|
|
|
*
|
|
|
|
* 01.10.2019
|
|
|
|
*
|
|
|
|
* Search list helper.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
|
|
|
function void
|
|
|
|
search_list_add_path__inner(Arena *arena, Path_Search_List *list, String_Const_u8 path){
|
|
|
|
string_list_push(arena, &list->list, path);
|
|
|
|
list->max_member_length = max(list->max_member_length, path.size);
|
|
|
|
}
|
|
|
|
|
|
|
|
function void
|
|
|
|
search_list_add_path(Arena *arena, Path_Search_List *list, String_Const_u8 path){
|
|
|
|
search_list_add_path__inner(arena, list, push_string_copy(arena, path));
|
|
|
|
}
|
|
|
|
|
|
|
|
function void
|
2019-10-03 17:57:44 +00:00
|
|
|
search_list_add_system_path(Arena *arena, Path_Search_List *list, System_Path_Code path){
|
|
|
|
search_list_add_path__inner(arena, list, system_get_path(arena, path));
|
2019-10-03 02:58:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function String_Const_u8
|
2019-10-03 17:57:44 +00:00
|
|
|
get_full_path(Arena *arena, Path_Search_List *search_list, String_Const_u8 relative){
|
2019-10-03 02:58:05 +00:00
|
|
|
String_Const_u8 result = {};
|
|
|
|
Temp_Memory restore_point = begin_temp(arena);
|
|
|
|
umem buffer_cap = search_list->max_member_length + relative.size + 1;
|
|
|
|
u8 *buffer = push_array(arena, u8, buffer_cap);
|
|
|
|
u8 *opl = buffer + buffer_cap;
|
|
|
|
u8 *relative_base = opl - 1 - relative.size;
|
|
|
|
block_copy(relative_base, relative.str, relative.size);
|
|
|
|
relative_base[relative.size] = 0;
|
|
|
|
for (Node_String_Const_u8 *node = search_list->list.first;
|
|
|
|
node != 0;
|
|
|
|
node = node->next){
|
|
|
|
umem node_size = node->string.size;
|
|
|
|
u8 *path_base = relative_base - node_size;
|
|
|
|
block_copy(path_base, node->string.str, node_size);
|
|
|
|
String_Const_u8 name = SCu8(path_base, opl);
|
2019-10-03 17:57:44 +00:00
|
|
|
File_Attributes attribs = system_quick_file_attributes(arena, name);
|
2019-10-03 02:58:05 +00:00
|
|
|
if (attribs.size > 0){
|
|
|
|
result = name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result.size == 0){
|
|
|
|
end_temp(restore_point);
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|