2017-01-03 20:05:35 +00:00
|
|
|
/*
|
|
|
|
* Mr. 4th Dimention - Allen Webster
|
|
|
|
*
|
|
|
|
* 03.01.2017
|
|
|
|
*
|
|
|
|
* Hot_Directory data structure for 4coder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
|
|
|
struct Hot_Directory{
|
2017-02-12 06:01:01 +00:00
|
|
|
char string_space[256];
|
|
|
|
char canon_dir_space[256];
|
2017-01-03 20:05:35 +00:00
|
|
|
String string;
|
2017-02-12 06:01:01 +00:00
|
|
|
String canon_dir;
|
2017-01-03 20:05:35 +00:00
|
|
|
File_List file_list;
|
|
|
|
};
|
|
|
|
|
|
|
|
internal void
|
|
|
|
hot_directory_clean_end(Hot_Directory *hot_directory){
|
|
|
|
String *str = &hot_directory->string;
|
|
|
|
if (str->size != 0 && str->str[str->size-1] != '/'){
|
|
|
|
str->size = reverse_seek_slash(*str) + 1;
|
|
|
|
str->str[str->size] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal i32
|
|
|
|
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){
|
|
|
|
i32 comp = 0;
|
|
|
|
comp = p->folder - a->folder;
|
|
|
|
if (comp == 0){
|
2017-03-23 19:15:05 +00:00
|
|
|
comp = compare_cc(a->filename, p->filename);
|
2017-01-03 20:05:35 +00:00
|
|
|
}
|
|
|
|
if (comp < 0){
|
|
|
|
Swap(File_Info, *a, infos[start]);
|
|
|
|
++start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Swap(File_Info, *p, infos[start]);
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
hot_directory_set(System_Functions *system, Hot_Directory *hot_directory, String str){
|
2017-02-10 18:02:17 +00:00
|
|
|
copy_checked_ss(&hot_directory->string, str);
|
|
|
|
b32 success = terminate_with_null(&hot_directory->string);
|
2017-01-03 20:05:35 +00:00
|
|
|
if (success){
|
|
|
|
if (str.size > 0){
|
2017-02-12 06:01:01 +00:00
|
|
|
u32 canon_max = hot_directory->canon_dir.memory_size;
|
|
|
|
u32 canon_length = 0;
|
|
|
|
char *canon_str = hot_directory->canon_dir.str;
|
|
|
|
system->set_file_list(&hot_directory->file_list, hot_directory->string.str, canon_str, &canon_length, canon_max);
|
|
|
|
if (canon_length > 0){
|
|
|
|
hot_directory->canon_dir.size = canon_length;
|
|
|
|
if (!char_is_slash(hot_directory->canon_dir.str[canon_length-1])){
|
|
|
|
append_s_char(&hot_directory->canon_dir, '/');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
hot_directory->canon_dir.size = 0;
|
|
|
|
}
|
2017-01-03 20:05:35 +00:00
|
|
|
}
|
|
|
|
else{
|
2017-02-12 06:01:01 +00:00
|
|
|
system->set_file_list(&hot_directory->file_list, 0, 0, 0, 0);
|
|
|
|
hot_directory->canon_dir.size = 0;
|
2017-01-03 20:05:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
hot_directory_fixup(hot_directory);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
hot_directory_reload(System_Functions *system, Hot_Directory *hot_directory){
|
2017-02-10 18:02:17 +00:00
|
|
|
hot_directory_set(system, hot_directory, hot_directory->string);
|
2017-01-03 20:05:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal void
|
2017-02-12 06:01:01 +00:00
|
|
|
hot_directory_init(Hot_Directory *hot_directory, String dir){
|
|
|
|
hot_directory->string = make_fixed_width_string(hot_directory->string_space);
|
|
|
|
hot_directory->canon_dir = make_fixed_width_string(hot_directory->canon_dir_space);
|
|
|
|
|
2017-01-03 20:05:35 +00:00
|
|
|
hot_directory->string.str[255] = 0;
|
|
|
|
hot_directory->string.size = 0;
|
|
|
|
copy_ss(&hot_directory->string, dir);
|
|
|
|
if (hot_directory->string.str[hot_directory->string.size-1] != '/'){
|
|
|
|
append_s_char(&hot_directory->string, '/');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|