4coder/4ed_hot_directory.cpp

85 lines
2.8 KiB
C++
Raw Normal View History

/*
* Mr. 4th Dimention - Allen Webster
*
* 03.01.2017
*
* Hot_Directory data structure for 4coder
*
*/
// TOP
internal void
hot_directory_clean_end(Hot_Directory *hot_directory){
2019-08-04 00:49:40 +00:00
String_Const_u8 str = hot_directory->string;
2019-06-01 23:58:28 +00:00
if (!character_is_slash(string_get_character(str, str.size - 1))){
2019-08-04 00:49:40 +00:00
hot_directory->string = string_remove_last_folder(str);
}
}
internal i32
2019-08-04 00:49:40 +00:00
hot_directory_quick_partition(File_Info **infos, i32 start, i32 pivot){
File_Info **p = infos + pivot;
File_Info **a = infos + start;
for (i32 i = start; i < pivot; ++i, ++a){
2019-08-04 00:49:40 +00:00
b32 p_folder = (HasFlag((**p).attributes.flags, FileAttribute_IsDirectory));
b32 a_folder = (HasFlag((**a).attributes.flags, FileAttribute_IsDirectory));
i32 comp = p_folder - a_folder;
if (comp == 0){
2019-08-04 00:49:40 +00:00
comp = string_compare((**a).file_name, (**p).file_name);
}
if (comp < 0){
2019-08-04 00:49:40 +00:00
Swap(File_Info*, *a, infos[start]);
++start;
}
}
2019-08-04 00:49:40 +00:00
Swap(File_Info*, *p, infos[start]);
return(start);
}
internal void
2019-08-04 00:49:40 +00:00
hot_directory_quick_sort(File_Info **infos, i32 start, i32 pivot){
i32 mid = hot_directory_quick_partition(infos, start, pivot);
if (start < mid-1) hot_directory_quick_sort(infos, start, mid-1);
if (mid+1 < pivot) hot_directory_quick_sort(infos, mid+1, pivot);
}
2019-01-31 13:06:42 +00:00
internal void
hot_directory_fixup(Hot_Directory *hot_directory){
File_List *files = &hot_directory->file_list;
if (files->count >= 2){
hot_directory_quick_sort(files->infos, 0, files->count - 1);
}
}
2019-01-31 13:06:42 +00:00
internal void
2019-06-01 23:58:28 +00:00
hot_directory_set(System_Functions *system, Hot_Directory *hot_directory, String_Const_u8 str){
2019-08-04 00:49:40 +00:00
linalloc_clear(&hot_directory->arena);
hot_directory->string = push_string_copy(&hot_directory->arena, str);
hot_directory->canonical = system->get_canonical(&hot_directory->arena, str);
hot_directory->file_list = system->get_file_list(&hot_directory->arena, hot_directory->canonical);
}
2019-01-31 13:06:42 +00:00
internal void
2019-08-04 00:49:40 +00:00
hot_directory_reload(System_Functions *system, Arena *scratch, Hot_Directory *hot_directory){
Temp_Memory temp = begin_temp(scratch);
String_Const_u8 string = push_string_copy(scratch, hot_directory->string);
2019-06-01 23:58:28 +00:00
hot_directory_set(system, hot_directory, string);
2019-08-04 00:49:40 +00:00
end_temp(temp);
}
internal void
2019-08-04 00:49:40 +00:00
hot_directory_init(System_Functions *system, Arena *scratch, Hot_Directory *hot_directory, String_Const_u8 directory){
hot_directory->arena = make_arena_system(system);
Temp_Memory temp = begin_temp(scratch);
String_Const_u8 dir = directory;
if (!character_is_slash(string_get_character(directory, directory.size - 1))){
dir = push_u8_stringf(scratch, "%.*s/", string_expand(directory));
}
2019-08-04 00:49:40 +00:00
hot_directory_set(system, hot_directory, dir);
end_temp(temp);
}
// BOTTOM