Setup for loading config from the user directory

master
Allen Webster 2021-01-16 15:41:41 -08:00
parent 8da55068a5
commit f1b0bd0522
8 changed files with 27 additions and 53 deletions

View File

@ -14,9 +14,7 @@ def_search_normal_load_list(Arena *arena, List_String_Const_u8 *list){
if (prj_dir.size > 0){ if (prj_dir.size > 0){
string_list_push(arena, list, prj_dir); string_list_push(arena, list, prj_dir);
} }
def_search_list_add_system_path(arena, list, SystemPath_UserDirectory);
// TODO(allen): User directory
def_search_list_add_system_path(arena, list, SystemPath_Binary); def_search_list_add_system_path(arena, list, SystemPath_Binary);
} }
@ -1377,30 +1375,6 @@ change_mode(Application_Links *app, String_Const_u8 mode){
// TODO(allen): cleanup this mess some more // TODO(allen): cleanup this mess some more
function Config*
config_parse__file_handle(Application_Links *app, Arena *arena, String_Const_u8 file_name, FILE *file){
Config *parsed = 0;
String_Const_u8 data = dump_file_handle(arena, file);
if (data.str != 0){
parsed = def_config_from_text(app, arena, file_name, data);
}
return(parsed);
}
function Config*
config_parse__file_name(Application_Links *app, Arena *arena, char *file_name){
Config *parsed = 0;
FILE *file = open_file_try_current_path_then_binary_path(app, file_name);
if (file != 0){
String_Const_u8 data = dump_file_handle(arena, file);
fclose(file);
if (data.str != 0){
parsed = def_config_from_text(app, arena, SCu8(file_name), data);
}
}
return(parsed);
}
function Config* function Config*
theme_parse__data(Application_Links *app, Arena *arena, String_Const_u8 file_name, String_Const_u8 data, Arena *color_arena, Color_Table *color_table){ theme_parse__data(Application_Links *app, Arena *arena, String_Const_u8 file_name, String_Const_u8 data, Arena *color_arena, Color_Table *color_table){
Config *parsed = def_config_from_text(app, arena, file_name, data); Config *parsed = def_config_from_text(app, arena, file_name, data);
@ -1472,7 +1446,10 @@ theme_parse__file_handle(Application_Links *app, Arena *arena, String_Const_u8 f
function Config* function Config*
theme_parse__file_name(Application_Links *app, Arena *arena, char *file_name, Arena *color_arena, Color_Table *color_table){ theme_parse__file_name(Application_Links *app, Arena *arena, char *file_name, Arena *color_arena, Color_Table *color_table){
Config *parsed = 0; Config *parsed = 0;
FILE *file = open_file_try_current_path_then_binary_path(app, file_name); FILE* file = fopen(file_name, "rb");
if (file == 0){
file = def_search_normal_fopen(arena, file_name, "rb");
}
if (file != 0){ if (file != 0){
String_Const_u8 data = dump_file_handle(arena, file); String_Const_u8 data = dump_file_handle(arena, file);
fclose(file); fclose(file);
@ -1494,7 +1471,16 @@ load_config_and_apply(Application_Links *app, Arena *out_arena, i32 override_fon
Scratch_Block scratch(app, out_arena); Scratch_Block scratch(app, out_arena);
linalloc_clear(out_arena); linalloc_clear(out_arena);
Config *parsed = config_parse__file_name(app, out_arena, "config.4coder");
Config *parsed = 0;
FILE *file = def_search_normal_fopen(scratch, "config.4coder", "rb");
if (file != 0){
String_Const_u8 data = dump_file_handle(scratch, file);
fclose(file);
if (data.str != 0){
parsed = def_config_from_text(app, scratch, str8_lit("config.4coder"), data);
}
}
if (parsed != 0){ if (parsed != 0){
// Errors // Errors

View File

@ -177,7 +177,6 @@ struct Config_Get_Result_List{
function void def_search_normal_load_list(Arena *arena, List_String_Const_u8 *list); function void def_search_normal_load_list(Arena *arena, List_String_Const_u8 *list);
function String_Const_u8 def_search_get_full_path(Arena *arena, List_String_Const_u8 *list, String_Const_u8 file_name);
function FILE *def_search_normal_fopen(Arena *arena, char *file_name, char *opt); function FILE *def_search_normal_fopen(Arena *arena, char *file_name, char *opt);
//////////////////////////////// ////////////////////////////////

View File

@ -24,7 +24,7 @@ dynamic_binding_load_from_file(Application_Links *app, Mapping *mapping, String_
Scratch_Block scratch(app); Scratch_Block scratch(app);
String_Const_u8 filename_copied = push_string_copy(scratch, filename); String_Const_u8 filename_copied = push_string_copy(scratch, filename);
FILE *file = open_file_try_current_path_then_binary_path(app, (char*)filename_copied.str); FILE *file = def_search_normal_fopen(scratch, (char*)filename_copied.str, "rb");
if (file != 0){ if (file != 0){
String_Const_u8 data = dump_file_handle(scratch, file); String_Const_u8 data = dump_file_handle(scratch, file);
Config *parsed = def_config_from_text(app, scratch, filename, data); Config *parsed = def_config_from_text(app, scratch, filename, data);

View File

@ -2049,20 +2049,6 @@ push_file_search_up_path(Application_Links *app, Arena *arena, String_Const_u8 s
return(result); return(result);
} }
function FILE*
open_file_try_current_path_then_binary_path(Application_Links *app, char *file_name){
FILE *file = fopen(file_name, "rb");
if (file == 0){
Scratch_Block scratch(app);
List_String_Const_u8 list = {};
string_list_push(scratch, &list, system_get_path(scratch, SystemPath_Binary));
string_list_push_overlap(scratch, &list, '/', SCu8(file_name));
String_Const_u8 str = string_list_flatten(scratch, list, StringFill_NullTerminate);
file = fopen((char*)str.str, "rb");
}
return(file);
}
function FILE* function FILE*
open_file(Arena *scratch, String_Const_u8 name){ open_file(Arena *scratch, String_Const_u8 name){
Temp_Memory temp = begin_temp(scratch); Temp_Memory temp = begin_temp(scratch);

View File

@ -21,6 +21,7 @@ function void def_search_list_add_system_path(Arena *arena, List_String_Const_u8
//////////////////////////////// ////////////////////////////////
// NOTE(allen): Search List Functions // NOTE(allen): Search List Functions
function String_Const_u8 def_search_get_full_path(Arena *arena, List_String_Const_u8 *list, String_Const_u8 file_name);
function FILE *def_search_fopen(Arena *arena, List_String_Const_u8 *list, char *file_name, char *opt); function FILE *def_search_fopen(Arena *arena, List_String_Const_u8 *list, char *file_name, char *opt);
#endif #endif

View File

@ -326,9 +326,9 @@ static Command_Metadata fcoder_metacmd_table[252] = {
{ PROC_LINKS(execute_any_cli, 0), false, "execute_any_cli", 15, "Queries for an output buffer name and system command, runs the system command as a CLI and prints the output to the specified buffer.", 133, "W:\\4ed\\code\\custom\\4coder_cli_command.cpp", 41, 22 }, { PROC_LINKS(execute_any_cli, 0), false, "execute_any_cli", 15, "Queries for an output buffer name and system command, runs the system command as a CLI and prints the output to the specified buffer.", 133, "W:\\4ed\\code\\custom\\4coder_cli_command.cpp", 41, 22 },
{ PROC_LINKS(execute_previous_cli, 0), false, "execute_previous_cli", 20, "If the command execute_any_cli has already been used, this will execute a CLI reusing the most recent buffer name and command.", 126, "W:\\4ed\\code\\custom\\4coder_cli_command.cpp", 41, 7 }, { PROC_LINKS(execute_previous_cli, 0), false, "execute_previous_cli", 20, "If the command execute_any_cli has already been used, this will execute a CLI reusing the most recent buffer name and command.", 126, "W:\\4ed\\code\\custom\\4coder_cli_command.cpp", 41, 7 },
{ PROC_LINKS(exit_4coder, 0), false, "exit_4coder", 11, "Attempts to close 4coder.", 25, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 846 }, { PROC_LINKS(exit_4coder, 0), false, "exit_4coder", 11, "Attempts to close 4coder.", 25, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 846 },
{ PROC_LINKS(go_to_user_directory, 0), false, "go_to_user_directory", 20, "Go to the 4coder user directory", 31, "W:\\4ed\\code\\custom\\4coder_config.cpp", 36, 1653 }, { PROC_LINKS(go_to_user_directory, 0), false, "go_to_user_directory", 20, "Go to the 4coder user directory", 31, "W:\\4ed\\code\\custom\\4coder_config.cpp", 36, 1639 },
{ PROC_LINKS(goto_beginning_of_file, 0), false, "goto_beginning_of_file", 22, "Sets the cursor to the beginning of the file.", 45, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2261 }, { PROC_LINKS(goto_beginning_of_file, 0), false, "goto_beginning_of_file", 22, "Sets the cursor to the beginning of the file.", 45, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2247 },
{ PROC_LINKS(goto_end_of_file, 0), false, "goto_end_of_file", 16, "Sets the cursor to the end of the file.", 39, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2269 }, { PROC_LINKS(goto_end_of_file, 0), false, "goto_end_of_file", 16, "Sets the cursor to the end of the file.", 39, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2255 },
{ PROC_LINKS(goto_first_jump, 0), false, "goto_first_jump", 15, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer.", 95, "W:\\4ed\\code\\custom\\4coder_jump_sticky.cpp", 41, 525 }, { PROC_LINKS(goto_first_jump, 0), false, "goto_first_jump", 15, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer.", 95, "W:\\4ed\\code\\custom\\4coder_jump_sticky.cpp", 41, 525 },
{ PROC_LINKS(goto_first_jump_same_panel_sticky, 0), false, "goto_first_jump_same_panel_sticky", 33, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer and views the buffer in the panel where the jump list was.", 153, "W:\\4ed\\code\\custom\\4coder_jump_sticky.cpp", 41, 542 }, { PROC_LINKS(goto_first_jump_same_panel_sticky, 0), false, "goto_first_jump_same_panel_sticky", 33, "If a buffer containing jump locations has been locked in, goes to the first jump in the buffer and views the buffer in the panel where the jump list was.", 153, "W:\\4ed\\code\\custom\\4coder_jump_sticky.cpp", 41, 542 },
{ PROC_LINKS(goto_jump_at_cursor, 0), false, "goto_jump_at_cursor", 19, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in another view and changes the active panel to the view containing the jump.", 187, "W:\\4ed\\code\\custom\\4coder_jump_sticky.cpp", 41, 348 }, { PROC_LINKS(goto_jump_at_cursor, 0), false, "goto_jump_at_cursor", 19, "If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in another view and changes the active panel to the view containing the jump.", 187, "W:\\4ed\\code\\custom\\4coder_jump_sticky.cpp", 41, 348 },
@ -375,7 +375,7 @@ static Command_Metadata fcoder_metacmd_table[252] = {
{ PROC_LINKS(list_all_substring_locations, 0), false, "list_all_substring_locations", 28, "Queries the user for a string and lists all case-sensitive substring matches found in all open buffers.", 103, "W:\\4ed\\code\\custom\\4coder_search.cpp", 36, 174 }, { PROC_LINKS(list_all_substring_locations, 0), false, "list_all_substring_locations", 28, "Queries the user for a string and lists all case-sensitive substring matches found in all open buffers.", 103, "W:\\4ed\\code\\custom\\4coder_search.cpp", 36, 174 },
{ PROC_LINKS(list_all_substring_locations_case_insensitive, 0), false, "list_all_substring_locations_case_insensitive", 45, "Queries the user for a string and lists all case-insensitive substring matches found in all open buffers.", 105, "W:\\4ed\\code\\custom\\4coder_search.cpp", 36, 186 }, { PROC_LINKS(list_all_substring_locations_case_insensitive, 0), false, "list_all_substring_locations_case_insensitive", 45, "Queries the user for a string and lists all case-insensitive substring matches found in all open buffers.", 105, "W:\\4ed\\code\\custom\\4coder_search.cpp", 36, 186 },
{ PROC_LINKS(load_project, 0), false, "load_project", 12, "Looks for a project.4coder file in the current directory and tries to load it. Looks in parent directories until a project file is found or there are no more parents.", 167, "W:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 823 }, { PROC_LINKS(load_project, 0), false, "load_project", 12, "Looks for a project.4coder file in the current directory and tries to load it. Looks in parent directories until a project file is found or there are no more parents.", 167, "W:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 823 },
{ PROC_LINKS(load_theme_current_buffer, 0), false, "load_theme_current_buffer", 25, "Parse the current buffer as a theme file and add the theme to the theme list. If the buffer has a .4coder postfix in it's name, it is removed when the name is saved.", 165, "W:\\4ed\\code\\custom\\4coder_config.cpp", 36, 1609 }, { PROC_LINKS(load_theme_current_buffer, 0), false, "load_theme_current_buffer", 25, "Parse the current buffer as a theme file and add the theme to the theme list. If the buffer has a .4coder postfix in it's name, it is removed when the name is saved.", 165, "W:\\4ed\\code\\custom\\4coder_config.cpp", 36, 1595 },
{ PROC_LINKS(load_themes_default_folder, 0), false, "load_themes_default_folder", 26, "Loads all the theme files in the default theme folder.", 54, "W:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 535 }, { PROC_LINKS(load_themes_default_folder, 0), false, "load_themes_default_folder", 26, "Loads all the theme files in the default theme folder.", 54, "W:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 535 },
{ PROC_LINKS(load_themes_hot_directory, 0), false, "load_themes_hot_directory", 25, "Loads all the theme files in the current hot directory.", 55, "W:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 547 }, { PROC_LINKS(load_themes_hot_directory, 0), false, "load_themes_hot_directory", 25, "Loads all the theme files in the current hot directory.", 55, "W:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 547 },
{ PROC_LINKS(make_directory_query, 0), false, "make_directory_query", 20, "Queries the user for a name and creates a new directory with the given name.", 76, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1495 }, { PROC_LINKS(make_directory_query, 0), false, "make_directory_query", 20, "Queries the user for a name and creates a new directory with the given name.", 76, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1495 },
@ -461,10 +461,10 @@ static Command_Metadata fcoder_metacmd_table[252] = {
{ PROC_LINKS(save_to_query, 0), false, "save_to_query", 13, "Queries the user for a file name and saves the contents of the current buffer, altering the buffer's name too.", 110, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1427 }, { PROC_LINKS(save_to_query, 0), false, "save_to_query", 13, "Queries the user for a file name and saves the contents of the current buffer, altering the buffer's name too.", 110, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1427 },
{ PROC_LINKS(search, 0), false, "search", 6, "Begins an incremental search down through the current buffer for a user specified string.", 89, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1109 }, { PROC_LINKS(search, 0), false, "search", 6, "Begins an incremental search down through the current buffer for a user specified string.", 89, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1109 },
{ PROC_LINKS(search_identifier, 0), false, "search_identifier", 17, "Begins an incremental search down through the current buffer for the word or token under the cursor.", 100, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1121 }, { PROC_LINKS(search_identifier, 0), false, "search_identifier", 17, "Begins an incremental search down through the current buffer for the word or token under the cursor.", 100, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1121 },
{ PROC_LINKS(seek_beginning_of_line, 0), false, "seek_beginning_of_line", 22, "Seeks the cursor to the beginning of the visual line.", 53, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2249 }, { PROC_LINKS(seek_beginning_of_line, 0), false, "seek_beginning_of_line", 22, "Seeks the cursor to the beginning of the visual line.", 53, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2235 },
{ PROC_LINKS(seek_beginning_of_textual_line, 0), false, "seek_beginning_of_textual_line", 30, "Seeks the cursor to the beginning of the line across all text.", 62, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2237 }, { PROC_LINKS(seek_beginning_of_textual_line, 0), false, "seek_beginning_of_textual_line", 30, "Seeks the cursor to the beginning of the line across all text.", 62, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2223 },
{ PROC_LINKS(seek_end_of_line, 0), false, "seek_end_of_line", 16, "Seeks the cursor to the end of the visual line.", 47, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2255 }, { PROC_LINKS(seek_end_of_line, 0), false, "seek_end_of_line", 16, "Seeks the cursor to the end of the visual line.", 47, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2241 },
{ PROC_LINKS(seek_end_of_textual_line, 0), false, "seek_end_of_textual_line", 24, "Seeks the cursor to the end of the line across all text.", 56, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2243 }, { PROC_LINKS(seek_end_of_textual_line, 0), false, "seek_end_of_textual_line", 24, "Seeks the cursor to the end of the line across all text.", 56, "W:\\4ed\\code\\custom\\4coder_helper.cpp", 36, 2229 },
{ PROC_LINKS(select_all, 0), false, "select_all", 10, "Puts the cursor at the top of the file, and the mark at the bottom of the file.", 79, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 541 }, { PROC_LINKS(select_all, 0), false, "select_all", 10, "Puts the cursor at the top of the file, and the mark at the bottom of the file.", 79, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 541 },
{ PROC_LINKS(select_next_scope_absolute, 0), false, "select_next_scope_absolute", 26, "Finds the first scope started by '{' after the cursor and puts the cursor and mark on the '{' and '}'.", 102, "W:\\4ed\\code\\custom\\4coder_scope_commands.cpp", 44, 57 }, { PROC_LINKS(select_next_scope_absolute, 0), false, "select_next_scope_absolute", 26, "Finds the first scope started by '{' after the cursor and puts the cursor and mark on the '{' and '}'.", 102, "W:\\4ed\\code\\custom\\4coder_scope_commands.cpp", 44, 57 },
{ PROC_LINKS(select_next_scope_after_current, 0), false, "select_next_scope_after_current", 31, "If a scope is selected, find first scope that starts after the selected scope. Otherwise find the first scope that starts after the cursor.", 139, "W:\\4ed\\code\\custom\\4coder_scope_commands.cpp", 44, 66 }, { PROC_LINKS(select_next_scope_after_current, 0), false, "select_next_scope_after_current", 31, "If a scope is selected, find first scope that starts after the selected scope. Otherwise find the first scope that starts after the cursor.", 139, "W:\\4ed\\code\\custom\\4coder_scope_commands.cpp", 44, 66 },

View File

@ -1848,6 +1848,7 @@ main(int argc, char **argv){
String_Const_u8 default_file_name = string_u8_litexpr("custom_4coder.so"); String_Const_u8 default_file_name = string_u8_litexpr("custom_4coder.so");
List_String_Const_u8 search_list = {}; List_String_Const_u8 search_list = {};
def_search_list_add_system_path(scratch, &search_list, SystemPath_CurrentDirectory); def_search_list_add_system_path(scratch, &search_list, SystemPath_CurrentDirectory);
def_search_list_add_system_path(scratch, &search_list, SystemPath_UserDirectory);
def_search_list_add_system_path(scratch, &search_list, SystemPath_Binary); def_search_list_add_system_path(scratch, &search_list, SystemPath_Binary);
String_Const_u8 custom_file_names[2] = {}; String_Const_u8 custom_file_names[2] = {};
i32 custom_file_count = 1; i32 custom_file_count = 1;

View File

@ -1752,6 +1752,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS
String_Const_u8 default_file_name = string_u8_litexpr("custom_4coder.dll"); String_Const_u8 default_file_name = string_u8_litexpr("custom_4coder.dll");
List_String_Const_u8 search_list = {}; List_String_Const_u8 search_list = {};
def_search_list_add_system_path(scratch, &search_list, SystemPath_CurrentDirectory); def_search_list_add_system_path(scratch, &search_list, SystemPath_CurrentDirectory);
def_search_list_add_system_path(scratch, &search_list, SystemPath_UserDirectory);
def_search_list_add_system_path(scratch, &search_list, SystemPath_Binary); def_search_list_add_system_path(scratch, &search_list, SystemPath_Binary);
String_Const_u8 custom_file_names[2] = {}; String_Const_u8 custom_file_names[2] = {};