From 3c2a71d7c3244a648a639db01413c86486251e14 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sat, 26 May 2018 00:49:37 -0700 Subject: [PATCH] Fully upgraded project system, still needs a few rounds of revision though --- 4coder_config.cpp | 439 +++++++++----- 4coder_config.h | 27 +- 4coder_generated/command_metadata.h | 14 +- 4coder_helper.cpp | 36 +- 4coder_project_commands.cpp | 852 ++++++++++++++++++++++------ 4coder_project_commands.h | 68 ++- 4coder_search.cpp | 20 +- my_bindings.cpp | 28 + project.4coder | 86 ++- 9 files changed, 1178 insertions(+), 392 deletions(-) create mode 100644 my_bindings.cpp diff --git a/4coder_config.cpp b/4coder_config.cpp index 5b0a8cd1..3d45f8b3 100644 --- a/4coder_config.cpp +++ b/4coder_config.cpp @@ -531,7 +531,10 @@ config_evaluate_rvalue(Config *config, Config_Assignment *assignment, Config_RVa Config_RValue_Type type, void *out){ bool32 success = false; if (r != 0 && !assignment->visited){ - if (r->type == ConfigRValueType_LValue){ + if (type == ConfigRValueType_NoType){ + success = true; + } + else if (r->type == ConfigRValueType_LValue){ assignment->visited = true; Config_LValue *l = r->lvalue; success = config_var(config, l->identifier, l->index, type, out); @@ -539,31 +542,33 @@ config_evaluate_rvalue(Config *config, Config_Assignment *assignment, Config_RVa } else if (r->type == type){ success = true; - switch (type){ - case ConfigRValueType_Boolean: - { - *(bool32*)out = r->boolean; - }break; - - case ConfigRValueType_Integer: - { - *(int32_t*)out = r->integer; - }break; - - case ConfigRValueType_String: - { - *(String*)out = r->string; - }break; - - case ConfigRValueType_Character: - { - *(char*)out = r->character; - }break; - - case ConfigRValueType_Compound: - { - *(Config_Compound**)out = r->compound; - }break; + if (out != 0){ + switch (type){ + case ConfigRValueType_Boolean: + { + *(bool32*)out = r->boolean; + }break; + + case ConfigRValueType_Integer: + { + *(int32_t*)out = r->integer; + }break; + + case ConfigRValueType_String: + { + *(String*)out = r->string; + }break; + + case ConfigRValueType_Character: + { + *(char*)out = r->character; + }break; + + case ConfigRValueType_Compound: + { + *(Config_Compound**)out = r->compound; + }break; + } } } } @@ -580,87 +585,6 @@ config_var(Config *config, String var_name, int32_t subscript, Config_RValue_Typ return(success); } -static bool32 -config_bool_var(Config *config, String var_name, int32_t subscript, bool32 *var_out){ - return(config_var(config, var_name, subscript, ConfigRValueType_Boolean, var_out)); -} - -static bool32 -config_bool_var(Config *config, char *var_name, int32_t subscript, bool32 *var_out){ - return(config_var(config, make_string_slowly(var_name), subscript, ConfigRValueType_Boolean, var_out)); -} - -static bool32 -config_int_var(Config *config, String var_name, int32_t subscript, int32_t *var_out){ - return(config_var(config, var_name, subscript, ConfigRValueType_Integer, var_out)); -} - -static bool32 -config_int_var(Config *config, char *var_name, int32_t subscript, int32_t *var_out){ - return(config_var(config, make_string_slowly(var_name), subscript, ConfigRValueType_Integer, var_out)); -} - -static bool32 -config_uint_var(Config *config, String var_name, int32_t subscript, uint32_t *var_out){ - return(config_var(config, var_name, subscript, ConfigRValueType_Integer, var_out)); -} - -static bool32 -config_uint_var(Config *config, char *var_name, int32_t subscript, uint32_t *var_out){ - return(config_var(config, make_string_slowly(var_name), subscript, ConfigRValueType_Integer, var_out)); -} - -static bool32 -config_string_var(Config *config, String var_name, int32_t subscript, String *var_out){ - return(config_var(config, var_name, subscript, ConfigRValueType_String, var_out)); -} - -static bool32 -config_string_var(Config *config, char *var_name, int32_t subscript, String *var_out){ - return(config_var(config, make_string_slowly(var_name), subscript, ConfigRValueType_String, var_out)); -} - -static bool32 -config_placed_string_var(Config *config, String var_name, int32_t subscript, - String *var_out, char *space, int32_t space_size){ - *var_out = make_string_cap(space, 0, space_size); - String str = {0}; - bool32 result = config_string_var(config, var_name, subscript, &str); - if (result){ - copy(var_out, str); - } - return(result); -} - -static bool32 -config_placed_string_var(Config *config, char *var_name, int32_t subscript, - String *var_out, char *space, int32_t space_size){ - return(config_placed_string_var(config, make_string_slowly(var_name), subscript, - var_out, space, space_size)); -} - -#define config_fixed_string_var(c,v,s,o,a) config_placed_string_var((c),(v),(s),(o),(a),sizeof(a)) - -static bool32 -config_char_var(Config *config, String var_name, int32_t subscript, char *var_out){ - return(config_var(config, var_name, subscript, ConfigRValueType_Character, var_out)); -} - -static bool32 -config_char_var(Config *config, char *var_name, int32_t subscript, char *var_out){ - return(config_var(config, make_string_slowly(var_name), subscript, ConfigRValueType_Character, var_out)); -} - -static bool32 -config_compound_var(Config *config, String var_name, int32_t subscript, Config_Compound **var_out){ - return(config_var(config, var_name, subscript, ConfigRValueType_Compound, var_out)); -} - -static bool32 -config_compound_var(Config *config, char *var_name, int32_t subscript, Config_Compound **var_out){ - return(config_var(config, make_string_slowly(var_name), subscript, ConfigRValueType_Compound, var_out)); -} - static bool32 config_compound_member(Config *config, Config_Compound *compound, String var_name, int32_t index, Config_RValue_Type type, void *var_out){ @@ -698,81 +622,314 @@ config_compound_member(Config *config, Config_Compound *compound, String var_nam if (element_matches_query){ Config_Assignment dummy_assignment = {0}; success = config_evaluate_rvalue(config, &dummy_assignment, element->r, type, var_out); + break; } } return(success); } +static Iteration_Step_Result +typed_array_iteration_step(Config *parsed, Config_Compound *compound, Config_RValue_Type type, + int32_t index, void *var_out); + +static int32_t +typed_array_get_count(Config *parsed, Config_Compound *compound, Config_RValue_Type type); + +#define config_fixed_string_var(c,v,s,o,a) config_placed_string_var((c),(v),(s),(o),(a),sizeof(a)) + +//////////////////////////////// + static bool32 -config_compound_bool_member(Config *config, Config_Compound *compound, - String var_name, int32_t index, bool32 *var_out){ - return(config_compound_member(config, compound, var_name, index, ConfigRValueType_Boolean, var_out)); +config_has_var(Config *config, String var_name, int32_t subscript){ + bool32 result = config_var(config, var_name, subscript, ConfigRValueType_NoType, 0); + return(result); +} + +static bool32 +config_has_var(Config *config, char *var_name, int32_t subscript){ + String var_name_str = make_string_slowly(var_name); + bool32 result = config_var(config, var_name_str, subscript, ConfigRValueType_NoType, 0); + return(result); +} + +static bool32 +config_bool_var(Config *config, String var_name, int32_t subscript, bool32* var_out){ + bool32 result = config_var(config, var_name, subscript, ConfigRValueType_Boolean, var_out); + return(result); +} + +static bool32 +config_bool_var(Config *config, char *var_name, int32_t subscript, bool32* var_out){ + String var_name_str = make_string_slowly(var_name); + bool32 result = config_var(config, var_name_str, subscript, ConfigRValueType_Boolean, var_out); + return(result); +} + +static bool32 +config_int_var(Config *config, String var_name, int32_t subscript, int32_t* var_out){ + bool32 result = config_var(config, var_name, subscript, ConfigRValueType_Integer, var_out); + return(result); +} + +static bool32 +config_int_var(Config *config, char *var_name, int32_t subscript, int32_t* var_out){ + String var_name_str = make_string_slowly(var_name); + bool32 result = config_var(config, var_name_str, subscript, ConfigRValueType_Integer, var_out); + return(result); +} + +static bool32 +config_uint_var(Config *config, String var_name, int32_t subscript, uint32_t* var_out){ + bool32 result = config_var(config, var_name, subscript, ConfigRValueType_Integer, var_out); + return(result); +} + +static bool32 +config_uint_var(Config *config, char *var_name, int32_t subscript, uint32_t* var_out){ + String var_name_str = make_string_slowly(var_name); + bool32 result = config_var(config, var_name_str, subscript, ConfigRValueType_Integer, var_out); + return(result); +} + +static bool32 +config_string_var(Config *config, String var_name, int32_t subscript, String* var_out){ + bool32 result = config_var(config, var_name, subscript, ConfigRValueType_String, var_out); + return(result); +} + +static bool32 +config_string_var(Config *config, char *var_name, int32_t subscript, String* var_out){ + String var_name_str = make_string_slowly(var_name); + bool32 result = config_var(config, var_name_str, subscript, ConfigRValueType_String, var_out); + return(result); +} + +static bool32 +config_placed_string_var(Config *config, String var_name, int32_t subscript, String* var_out, char *space, int32_t space_size){ + bool32 result = config_var(config, var_name, subscript, ConfigRValueType_String, var_out); + if (result){ + String str = *var_out; + *var_out = make_string_cap(space, 0, space_size); + copy(var_out, str); + } + return(result); +} + +static bool32 +config_placed_string_var(Config *config, char *var_name, int32_t subscript, String* var_out, char *space, int32_t space_size){ + String var_name_str = make_string_slowly(var_name); + bool32 result = config_var(config, var_name_str, subscript, ConfigRValueType_String, var_out); + if (result){ + String str = *var_out; + *var_out = make_string_cap(space, 0, space_size); + copy(var_out, str); + } + return(result); +} + +static bool32 +config_char_var(Config *config, String var_name, int32_t subscript, char* var_out){ + bool32 result = config_var(config, var_name, subscript, ConfigRValueType_Character, var_out); + return(result); +} + +static bool32 +config_char_var(Config *config, char *var_name, int32_t subscript, char* var_out){ + String var_name_str = make_string_slowly(var_name); + bool32 result = config_var(config, var_name_str, subscript, ConfigRValueType_Character, var_out); + return(result); +} + +static bool32 +config_compound_var(Config *config, String var_name, int32_t subscript, Config_Compound** var_out){ + bool32 result = config_var(config, var_name, subscript, ConfigRValueType_Compound, var_out); + return(result); +} + +static bool32 +config_compound_var(Config *config, char *var_name, int32_t subscript, Config_Compound** var_out){ + String var_name_str = make_string_slowly(var_name); + bool32 result = config_var(config, var_name_str, subscript, ConfigRValueType_Compound, var_out); + return(result); +} + +static bool32 +config_compound_has_member(Config *config, Config_Compound *compound, + String var_name, int32_t index){ + bool32 result = config_compound_member(config, compound, var_name, index, + ConfigRValueType_NoType, 0); + return(result); +} + +static bool32 +config_compound_has_member(Config *config, Config_Compound *compound, + char *var_name, int32_t index){ + String var_name_str = make_string_slowly(var_name); + bool32 result = config_compound_member(config, compound, var_name_str, index, + ConfigRValueType_NoType, 0); + return(result); } static bool32 config_compound_bool_member(Config *config, Config_Compound *compound, - char *var_name, int32_t index, bool32 *var_out){ - return(config_compound_member(config, compound, make_string_slowly(var_name), index, ConfigRValueType_Boolean, var_out)); + String var_name, int32_t index, bool32* var_out){ + bool32 result = config_compound_member(config, compound, var_name, index, + ConfigRValueType_Boolean, var_out); + return(result); +} + +static bool32 +config_compound_bool_member(Config *config, Config_Compound *compound, + char *var_name, int32_t index, bool32* var_out){ + String var_name_str = make_string_slowly(var_name); + bool32 result = config_compound_member(config, compound, var_name_str, index, + ConfigRValueType_Boolean, var_out); + return(result); } static bool32 config_compound_int_member(Config *config, Config_Compound *compound, - String var_name, int32_t index, int32_t *var_out){ - return(config_compound_member(config, compound, var_name, index, ConfigRValueType_Integer, var_out)); + String var_name, int32_t index, int32_t* var_out){ + bool32 result = config_compound_member(config, compound, var_name, index, + ConfigRValueType_Integer, var_out); + return(result); } static bool32 config_compound_int_member(Config *config, Config_Compound *compound, - char *var_name, int32_t index, int32_t *var_out){ - return(config_compound_member(config, compound, make_string_slowly(var_name), index, ConfigRValueType_Integer, var_out)); + char *var_name, int32_t index, int32_t* var_out){ + String var_name_str = make_string_slowly(var_name); + bool32 result = config_compound_member(config, compound, var_name_str, index, + ConfigRValueType_Integer, var_out); + return(result); } static bool32 config_compound_uint_member(Config *config, Config_Compound *compound, - String var_name, int32_t index, uint32_t *var_out){ - return(config_compound_member(config, compound, var_name, index, ConfigRValueType_Integer, var_out)); + String var_name, int32_t index, uint32_t* var_out){ + bool32 result = config_compound_member(config, compound, var_name, index, + ConfigRValueType_Integer, var_out); + return(result); } static bool32 config_compound_uint_member(Config *config, Config_Compound *compound, - char *var_name, int32_t index, uint32_t *var_out){ - return(config_compound_member(config, compound, make_string_slowly(var_name), index, ConfigRValueType_Integer, var_out)); + char *var_name, int32_t index, uint32_t* var_out){ + String var_name_str = make_string_slowly(var_name); + bool32 result = config_compound_member(config, compound, var_name_str, index, + ConfigRValueType_Integer, var_out); + return(result); } static bool32 config_compound_string_member(Config *config, Config_Compound *compound, - String var_name, int32_t index, String *var_out){ - return(config_compound_member(config, compound, var_name, index, ConfigRValueType_String, var_out)); + String var_name, int32_t index, String* var_out){ + bool32 result = config_compound_member(config, compound, var_name, index, + ConfigRValueType_String, var_out); + return(result); } static bool32 config_compound_string_member(Config *config, Config_Compound *compound, - char *var_name, int32_t index, String *var_out){ - return(config_compound_member(config, compound, make_string_slowly(var_name), index, ConfigRValueType_String, var_out)); + char *var_name, int32_t index, String* var_out){ + String var_name_str = make_string_slowly(var_name); + bool32 result = config_compound_member(config, compound, var_name_str, index, + ConfigRValueType_String, var_out); + return(result); +} + +static bool32 +config_compound_placed_string_member(Config *config, Config_Compound *compound, + String var_name, int32_t index, String* var_out, char *space, int32_t space_size){ + bool32 result = config_compound_member(config, compound, var_name, index, + ConfigRValueType_String, var_out); + if (result){ + String str = *var_out; + *var_out = make_string_cap(space, 0, space_size); + copy(var_out, str); + } + return(result); +} + +static bool32 +config_compound_placed_string_member(Config *config, Config_Compound *compound, + char *var_name, int32_t index, String* var_out, char *space, int32_t space_size){ + String var_name_str = make_string_slowly(var_name); + bool32 result = config_compound_member(config, compound, var_name_str, index, + ConfigRValueType_String, var_out); + if (result){ + String str = *var_out; + *var_out = make_string_cap(space, 0, space_size); + copy(var_out, str); + } + return(result); } static bool32 config_compound_char_member(Config *config, Config_Compound *compound, - String var_name, int32_t index, char *var_out){ - return(config_compound_member(config, compound, var_name, index, ConfigRValueType_Character, var_out)); + String var_name, int32_t index, char* var_out){ + bool32 result = config_compound_member(config, compound, var_name, index, + ConfigRValueType_Character, var_out); + return(result); } static bool32 config_compound_char_member(Config *config, Config_Compound *compound, - char *var_name, int32_t index, char *var_out){ - return(config_compound_member(config, compound, make_string_slowly(var_name), index, ConfigRValueType_Character, var_out)); + char *var_name, int32_t index, char* var_out){ + String var_name_str = make_string_slowly(var_name); + bool32 result = config_compound_member(config, compound, var_name_str, index, + ConfigRValueType_Character, var_out); + return(result); } static bool32 config_compound_compound_member(Config *config, Config_Compound *compound, - String var_name, int32_t index, Config_Compound **var_out){ - return(config_compound_member(config, compound, var_name, index, ConfigRValueType_Compound, var_out)); + String var_name, int32_t index, Config_Compound** var_out){ + bool32 result = config_compound_member(config, compound, var_name, index, + ConfigRValueType_Compound, var_out); + return(result); } static bool32 config_compound_compound_member(Config *config, Config_Compound *compound, - char *var_name, int32_t index, Config_Compound **var_out){ - return(config_compound_member(config, compound, make_string_slowly(var_name), index, ConfigRValueType_Compound, var_out)); + char *var_name, int32_t index, Config_Compound** var_out){ + String var_name_str = make_string_slowly(var_name); + bool32 result = config_compound_member(config, compound, var_name_str, index, + ConfigRValueType_Compound, var_out); + return(result); +} + +//////////////////////////////// + +static Iteration_Step_Result +typed_array_iteration_step(Config *parsed, Config_Compound *compound, Config_RValue_Type type, + int32_t index, void *var_out){ + Iteration_Step_Result result = Iteration_Good; + if (!config_compound_member(parsed, compound, make_lit_string("~"), index, type, var_out)){ + if (config_compound_has_member(parsed, compound, "~", index)){ + result = Iteration_Skip; + } + else{ + result = Iteration_Quit; + } + } + return(result); +} + +static int32_t +typed_array_get_count(Config *parsed, Config_Compound *compound, Config_RValue_Type type){ + int32_t count = 0; + for (int32_t i = 0;; ++i){ + Iteration_Step_Result step_result = typed_array_iteration_step(parsed, compound, type, i, 0); + if (step_result == Iteration_Skip){ + continue; + } + else if (step_result == Iteration_Quit){ + break; + } + count += 1; + } + return(count); } //////////////////////////////// @@ -894,23 +1051,23 @@ config_parse__data(Partition *arena, String file_name, String data, Config_Data config_int_var(parsed, "default_min_base_width", 0, &config->default_min_base_width); config_fixed_string_var(parsed, "default_theme_name", 0, - &config->default_theme_name, config->default_theme_name_space); + &config->default_theme_name, config->default_theme_name_space); config_fixed_string_var(parsed, "default_font_name", 0, - &config->default_font_name, config->default_font_name_space); + &config->default_font_name, config->default_font_name_space); config_fixed_string_var(parsed, "user_name", 0, - &config->user_name, config->user_name_space); + &config->user_name, config->user_name_space); config_fixed_string_var(parsed, "default_compiler_bat", 0, - &config->default_compiler_bat, config->default_compiler_bat_space); + &config->default_compiler_bat, config->default_compiler_bat_space); config_fixed_string_var(parsed, "default_flags_bat", 0, - &config->default_flags_bat, config->default_flags_bat_space); + &config->default_flags_bat, config->default_flags_bat_space); config_fixed_string_var(parsed, "default_compiler_sh", 0, - &config->default_compiler_sh, config->default_compiler_sh_space); + &config->default_compiler_sh, config->default_compiler_sh_space); config_fixed_string_var(parsed, "default_flags_sh", 0, - &config->default_flags_sh, config->default_flags_sh_space); + &config->default_flags_sh, config->default_flags_sh_space); config_fixed_string_var(parsed, "mapping", 0, - &config->current_mapping, config->current_mapping_space); + &config->current_mapping, config->current_mapping_space); String str; if (config_string_var(parsed, "treat_as_code", 0, &str)){ @@ -997,7 +1154,7 @@ theme_parse__file_handle(Partition *arena, String file_name, FILE *file, Theme_D String data = dump_file_handle(arena, file); Config *parsed = 0; if (data.str != 0){ - parsed = theme_parse__data(arena, file_name, data, theme); + parsed = theme_parse__data(arena, file_name, data, theme); } return(parsed); } diff --git a/4coder_config.h b/4coder_config.h index 11293310..ed2dfd1b 100644 --- a/4coder_config.h +++ b/4coder_config.h @@ -27,9 +27,9 @@ struct Config_Error{ struct Config_Parser{ Cpp_Token *start; Cpp_Token *token; -Cpp_Token *end; + Cpp_Token *end; - String file_name; + String file_name; String data; Partition *arena; @@ -37,7 +37,7 @@ Cpp_Token *end; Config_Error *first_error; Config_Error *last_error; int32_t count_error; - }; +}; struct Config_LValue{ String identifier; @@ -53,7 +53,10 @@ enum{ ConfigRValueType_String = 4, ConfigRValueType_Character = 5, ConfigRValueType_Compound = 6, - ConfigRValueType_COUNT = 7, + ConfigRValueType_NoType = 7, +}; +enum{ + ConfigRValueType_COUNT = ConfigRValueType_NoType, }; struct Config_Compound{ @@ -148,19 +151,19 @@ struct Config_Data{ bool32 enable_code_wrapping; bool32 automatically_adjust_wrapping; - bool32 automatically_indent_text_on_save; + bool32 automatically_indent_text_on_save; bool32 automatically_save_changes_on_build; bool32 automatically_load_project; bool32 lalt_lctrl_is_altgr; - char default_theme_name_space[256]; - String default_theme_name; + char default_theme_name_space[256]; + String default_theme_name; - char default_font_name_space[256]; - String default_font_name; + char default_font_name_space[256]; + String default_font_name; - char user_name_space[256]; - String user_name; + char user_name_space[256]; + String user_name; char default_compiler_bat_space[256]; String default_compiler_bat; @@ -178,7 +181,7 @@ struct Config_Data{ String current_mapping; Extension_List code_exts; - }; +}; struct Theme_Data{ char space[128]; diff --git a/4coder_generated/command_metadata.h b/4coder_generated/command_metadata.h index f6357e7e..951d40f1 100644 --- a/4coder_generated/command_metadata.h +++ b/4coder_generated/command_metadata.h @@ -229,7 +229,7 @@ static Command_Metadata fcoder_metacmd_table[193] = { { PROC_LINKS(clean_all_lines, 0), "clean_all_lines", 15, "Removes trailing whitespace from all lines in the current buffer.", 65, "C:\\work\\4ed\\code\\4coder_base_commands.cpp", 45, 368 }, { PROC_LINKS(click_set_cursor, 0), "click_set_cursor", 16, "Sets the cursor position to the mouse position.", 47, "C:\\work\\4ed\\code\\4coder_base_commands.cpp", 45, 174 }, { PROC_LINKS(click_set_mark, 0), "click_set_mark", 14, "Sets the mark position to the mouse position.", 45, "C:\\work\\4ed\\code\\4coder_base_commands.cpp", 45, 187 }, -{ PROC_LINKS(close_all_code, 0), "close_all_code", 14, "Closes any buffer with a filename ending with an extension configured to be recognized as a code file type.", 107, "C:\\work\\4ed\\code\\4coder_project_commands.cpp", 48, 380 }, +{ PROC_LINKS(close_all_code, 0), "close_all_code", 14, "Closes any buffer with a filename ending with an extension configured to be recognized as a code file type.", 107, "C:\\work\\4ed\\code\\4coder_project_commands.cpp", 48, 879 }, { PROC_LINKS(close_build_panel, 0), "close_build_panel", 17, "If the special build panel is open, closes it.", 46, "C:\\work\\4ed\\code\\4coder_build_commands.cpp", 46, 205 }, { PROC_LINKS(close_panel, 0), "close_panel", 11, "Closes the currently active panel if it is not the only panel open.", 67, "C:\\work\\4ed\\code\\4coder_base_commands.cpp", 45, 441 }, { PROC_LINKS(copy, 0), "copy", 4, "Copy the text in the range from the cursor to the mark onto the clipboard.", 74, "C:\\work\\4ed\\code\\4coder_clipboard.cpp", 41, 26 }, @@ -295,7 +295,7 @@ static Command_Metadata fcoder_metacmd_table[193] = { { PROC_LINKS(list_all_locations_of_type_definition_of_identifier, 0), "list_all_locations_of_type_definition_of_identifier", 51, "Reads a token or word under the cursor and lists all locations of strings that appear to define a type whose name matches it.", 125, "C:\\work\\4ed\\code\\4coder_search.cpp", 38, 800 }, { PROC_LINKS(list_all_substring_locations, 0), "list_all_substring_locations", 28, "Queries the user for a string and lists all case-sensitive substring matches found in all open buffers.", 103, "C:\\work\\4ed\\code\\4coder_search.cpp", 38, 747 }, { PROC_LINKS(list_all_substring_locations_case_insensitive, 0), "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, "C:\\work\\4ed\\code\\4coder_search.cpp", 38, 759 }, -{ PROC_LINKS(load_project, 0), "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, "C:\\work\\4ed\\code\\4coder_project_commands.cpp", 48, 403 }, +{ PROC_LINKS(load_project, 0), "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, "C:\\work\\4ed\\code\\4coder_project_commands.cpp", 48, 902 }, { PROC_LINKS(make_directory_query, 0), "make_directory_query", 20, "Queries the user for a name and creates a new directory with the given name.", 76, "C:\\work\\4ed\\code\\4coder_base_commands.cpp", 45, 1101 }, { PROC_LINKS(miblo_decrement_basic, 0), "miblo_decrement_basic", 21, "Decrement an integer under the cursor by one.", 45, "C:\\work\\4ed\\code\\4coder_miblo_numbers.cpp", 45, 110 }, { PROC_LINKS(miblo_decrement_time_stamp, 0), "miblo_decrement_time_stamp", 26, "Decrement a time stamp under the cursor by one second. (format [m]m:ss or h:mm:ss", 81, "C:\\work\\4ed\\code\\4coder_miblo_numbers.cpp", 45, 383 }, @@ -317,8 +317,8 @@ static Command_Metadata fcoder_metacmd_table[193] = { { PROC_LINKS(newline_or_goto_position_same_panel_direct, 0), "newline_or_goto_position_same_panel_direct", 42, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor_same_panel.", 117, "C:\\work\\4ed\\code\\4coder_jump_direct.cpp", 43, 116 }, { PROC_LINKS(newline_or_goto_position_same_panel_sticky, 0), "newline_or_goto_position_same_panel_sticky", 42, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor_same_panel.", 117, "C:\\work\\4ed\\code\\4coder_jump_sticky.cpp", 43, 571 }, { PROC_LINKS(newline_or_goto_position_sticky, 0), "newline_or_goto_position_sticky", 31, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor.", 106, "C:\\work\\4ed\\code\\4coder_jump_sticky.cpp", 43, 556 }, -{ PROC_LINKS(open_all_code, 0), "open_all_code", 13, "Open all code in the current directory. File types are determined by extensions. An extension is considered code based on the extensions specified in 4coder.config.", 164, "C:\\work\\4ed\\code\\4coder_project_commands.cpp", 48, 387 }, -{ PROC_LINKS(open_all_code_recursive, 0), "open_all_code_recursive", 23, "Works as open_all_code but also runs in all subdirectories.", 59, "C:\\work\\4ed\\code\\4coder_project_commands.cpp", 48, 394 }, +{ PROC_LINKS(open_all_code, 0), "open_all_code", 13, "Open all code in the current directory. File types are determined by extensions. An extension is considered code based on the extensions specified in 4coder.config.", 164, "C:\\work\\4ed\\code\\4coder_project_commands.cpp", 48, 886 }, +{ PROC_LINKS(open_all_code_recursive, 0), "open_all_code_recursive", 23, "Works as open_all_code but also runs in all subdirectories.", 59, "C:\\work\\4ed\\code\\4coder_project_commands.cpp", 48, 893 }, { PROC_LINKS(open_color_tweaker, 0), "open_color_tweaker", 18, "Opens the 4coder colors and fonts selector menu.", 48, "C:\\work\\4ed\\code\\4coder_base_commands.cpp", 45, 1457 }, { PROC_LINKS(open_file_in_quotes, 0), "open_file_in_quotes", 19, "Reads a filename from surrounding '\"' characters and attempts to open the corresponding file.", 94, "C:\\work\\4ed\\code\\4coder_base_commands.cpp", 45, 1320 }, { PROC_LINKS(open_in_other, 0), "open_in_other", 13, "Switches to the next active panel and begins an open file dialogue.", 67, "C:\\work\\4ed\\code\\4coder_base_commands.cpp", 45, 1465 }, @@ -335,8 +335,8 @@ static Command_Metadata fcoder_metacmd_table[193] = { { PROC_LINKS(paste_next, 0), "paste_next", 10, "If the previous command was paste or paste_next, replaces the paste range with the next text down on the clipboard, otherwise operates as the paste command.", 156, "C:\\work\\4ed\\code\\4coder_clipboard.cpp", 41, 84 }, { PROC_LINKS(paste_next_and_indent, 0), "paste_next_and_indent", 21, "Paste the next item on the clipboard and run auto-indent on the newly pasted text.", 82, "C:\\work\\4ed\\code\\4coder_clipboard.cpp", 41, 135 }, { PROC_LINKS(place_in_scope, 0), "place_in_scope", 14, "Wraps the code contained in the range between cursor and mark with a new curly brace scope.", 91, "C:\\work\\4ed\\code\\4coder_scope_commands.cpp", 46, 481 }, -{ PROC_LINKS(project_fkey_command, 0), "project_fkey_command", 20, "Run an 'fkey command' configured in a project.4coder file. Determines the index of the 'fkey command' by which function key or numeric key was pressed to trigger the command.", 175, "C:\\work\\4ed\\code\\4coder_project_commands.cpp", 48, 410 }, -{ PROC_LINKS(project_go_to_root_directory, 0), "project_go_to_root_directory", 28, "Changes 4coder's hot directory to the root directory of the currently loaded project. With no loaded project nothing hapepns.", 125, "C:\\work\\4ed\\code\\4coder_project_commands.cpp", 48, 435 }, +{ PROC_LINKS(project_fkey_command, 0), "project_fkey_command", 20, "Run an 'fkey command' configured in a project.4coder file. Determines the index of the 'fkey command' by which function key or numeric key was pressed to trigger the command.", 175, "C:\\work\\4ed\\code\\4coder_project_commands.cpp", 48, 909 }, +{ PROC_LINKS(project_go_to_root_directory, 0), "project_go_to_root_directory", 28, "Changes 4coder's hot directory to the root directory of the currently loaded project. With no loaded project nothing hapepns.", 125, "C:\\work\\4ed\\code\\4coder_project_commands.cpp", 48, 934 }, { PROC_LINKS(query_replace, 0), "query_replace", 13, "Queries the user for two strings, and incrementally replaces every occurence of the first string with the second string.", 120, "C:\\work\\4ed\\code\\4coder_base_commands.cpp", 45, 893 }, { PROC_LINKS(query_replace_identifier, 0), "query_replace_identifier", 24, "Queries the user for a string, and incrementally replace every occurence of the word or token found at the cursor with the specified string.", 140, "C:\\work\\4ed\\code\\4coder_base_commands.cpp", 45, 913 }, { PROC_LINKS(query_replace_selection, 0), "query_replace_selection", 23, "Queries the user for a string, and incrementally replace every occurence of the string found in the selected range with the specified string.", 141, "C:\\work\\4ed\\code\\4coder_base_commands.cpp", 45, 931 }, @@ -378,7 +378,7 @@ static Command_Metadata fcoder_metacmd_table[193] = { { PROC_LINKS(set_bindings_default, 0), "set_bindings_default", 20, "Remap keybindings using the 'default' mapping rule.", 51, "C:\\work\\4ed\\code\\4coder_remapping_commands.cpp", 50, 61 }, { PROC_LINKS(set_bindings_mac_default, 0), "set_bindings_mac_default", 24, "Remap keybindings using the 'mac-default' mapping rule.", 55, "C:\\work\\4ed\\code\\4coder_remapping_commands.cpp", 50, 75 }, { PROC_LINKS(set_mark, 0), "set_mark", 8, "Sets the mark to the current position of the cursor.", 52, "C:\\work\\4ed\\code\\4coder_base_commands.cpp", 45, 86 }, -{ PROC_LINKS(setup_new_project, 0), "setup_new_project", 17, "Queries the user for several configuration options and initializes a new 4coder project with build scripts for every OS.", 120, "C:\\work\\4ed\\code\\4coder_project_commands.cpp", 48, 482 }, +{ PROC_LINKS(setup_new_project, 0), "setup_new_project", 17, "Queries the user for several configuration options and initializes a new 4coder project with build scripts for every OS.", 120, "C:\\work\\4ed\\code\\4coder_project_commands.cpp", 48, 982 }, { PROC_LINKS(show_filebar, 0), "show_filebar", 12, "Sets the current view to show it's filebar.", 43, "C:\\work\\4ed\\code\\4coder_base_commands.cpp", 45, 464 }, { PROC_LINKS(show_scrollbar, 0), "show_scrollbar", 14, "Sets the current view to show it's scrollbar.", 45, "C:\\work\\4ed\\code\\4coder_base_commands.cpp", 45, 450 }, { PROC_LINKS(snipe_token_or_word, 0), "snipe_token_or_word", 19, "Delete a single, whole token on or to the left of the cursor and post it to the clipboard.", 90, "C:\\work\\4ed\\code\\4coder_seek.cpp", 36, 1259 }, diff --git a/4coder_helper.cpp b/4coder_helper.cpp index 7f122a1f..7dc505c9 100644 --- a/4coder_helper.cpp +++ b/4coder_helper.cpp @@ -1121,10 +1121,10 @@ lexer_keywords_default_init(Partition *arena, Cpp_Keyword_Table *kw_out, Cpp_Key void *kw_mem = push_array(arena, char, (i32_4tech)kw_size); void *pp_mem = push_array(arena, char, (i32_4tech)pp_size); if (kw_mem != 0 && pp_mem != 0){ - *kw_out = cpp_make_table_default(CPP_TABLE_KEYWORDS, kw_mem, kw_size); -*pp_out = cpp_make_table_default(CPP_TABLE_PREPROCESSOR_DIRECTIVES, pp_mem, pp_size); + *kw_out = cpp_make_table_default(CPP_TABLE_KEYWORDS, kw_mem, kw_size); + *pp_out = cpp_make_table_default(CPP_TABLE_PREPROCESSOR_DIRECTIVES, pp_mem, pp_size); success = true; -} + } return(success); } @@ -1191,8 +1191,8 @@ open_file_try_current_path_then_binary_path(Application_Links *app, char *file_n append(&str, "/"); append(&str, file_name); if (terminate_with_null(&str)){ - file = fopen(str.str, "rb"); -} + file = fopen(str.str, "rb"); + } } return(file); } @@ -1232,7 +1232,7 @@ dump_file(Partition *arena, String file_name){ FILE *file = open_file(arena, file_name); if (file != 0){ result.file_name = file_name; - result.data = dump_file_handle(arena, file); + result.data = dump_file_handle(arena, file); fclose(file); } return(result); @@ -1251,5 +1251,29 @@ dump_file_search_up_path(Partition *arena, String path, String file_name){ return(result); } +static String +push_string(Partition *arena, int32_t cap){ + char *mem = push_array(arena, char, cap); + String result = {0}; + if (mem != 0){ + result = make_string_cap(mem, 0, cap); + } + return(result); +} + +static String +push_string_copy(Partition *arena, String str){ + String result = {0}; + if (str.str != 0){ + result = push_string(arena, str.size + 1); + push_align(arena, 8); + if (result.str != 0){ + copy(&result, str); + terminate_with_null(&result); + } + } + return(result); +} + // BOTTOM diff --git a/4coder_project_commands.cpp b/4coder_project_commands.cpp index 67773872..163eac47 100644 --- a/4coder_project_commands.cpp +++ b/4coder_project_commands.cpp @@ -5,21 +5,35 @@ // TOP static Project current_project = {0}; +static Partition current_project_arena = {0}; /////////////////////////////// -static CString_Array -project_get_extensions(Project *project){ - CString_Array array = {0}; - array.strings = default_extensions; - array.count = ArrayCount(default_extensions); - if (project->loaded){ - array.strings = project->extension_list.exts; - array.count = project->extension_list.count; +static Project_File_Pattern_Array +get_pattern_array_from_cstring_array(Partition *arena, CString_Array list){ + Project_File_Pattern_Array array = {0}; + int32_t count = list.count; + array.patterns = push_array(arena, Project_File_Pattern, count); + array.count = count; + for (int32_t i = 0; i < count; ++i){ + String base_str = make_string_slowly(list.strings[i]); + String str = push_string(arena, base_str.size + 3); + append(&str, "*."); + append(&str, base_str); + terminate_with_null(&str); + get_absolutes(str, &array.patterns[i].absolutes, false, false); } return(array); } +static Project_File_Pattern_Array +get_pattern_array_from_extension_list(Partition *arena, Extension_List extension_list){ + CString_Array list = {0}; + list.strings = extension_list.exts; + list.count = extension_list.count; + return(get_pattern_array_from_cstring_array(arena, list)); +} + /////////////////////////////// static void @@ -73,190 +87,499 @@ close_all_files_with_extension(Application_Links *app, Partition *scratch_part, end_temp_memory(temp); } +static bool32 +match_in_pattern_array(char *str, Project_File_Pattern_Array array){ + bool32 found_match = false; + Project_File_Pattern *pattern = array.patterns; + for (int32_t i = 0; i < array.count; ++i, ++pattern){ + if (wildcard_match_c(&pattern->absolutes, str, true)){ + found_match = true; + break; + } + } + return(found_match); +} + static void -open_all_files_in_directory_with_extension__inner(Application_Links *app, String space, - CString_Array extension_array, - uint32_t flags){ +open_all_files_in_directory_pattern_match__inner(Application_Links *app, String space, + Project_File_Pattern_Array whitelist, + Project_File_Pattern_Array blacklist, + uint32_t flags){ File_List list = get_file_list(app, space.str, space.size); int32_t dir_size = space.size; - for (uint32_t i = 0; i < list.count; ++i){ - File_Info *info = list.infos + i; - if (info->folder && - ((flags & OpenAllFilesFlag_Recursive) != 0) && - info->filename[0] != '.'){ - space.size = dir_size; - append(&space, info->filename); - append(&space, "/"); - open_all_files_in_directory_with_extension__inner(app, space, extension_array, flags); - } - else{ - bool32 is_match = true; - if (extension_array.count > 0){ - is_match = false; - String ext = make_string_cap(info->filename, info->filename_len, info->filename_len + 1); - ext = file_extension(ext); - for (int32_t j = 0; j < extension_array.count; ++j){ - if (match(ext, extension_array.strings[j])){ - is_match = true; - break; - } - } + File_Info *info = list.infos; + for (uint32_t i = 0; i < list.count; ++i, ++info){ + if (info->folder){ + if ((flags & OpenAllFilesFlag_Recursive) == 0){ + continue; + } + if (match_in_pattern_array(info->filename, blacklist)){ + continue; } - if (is_match){ - space.size = dir_size; - append(&space, info->filename); - create_buffer(app, space.str, space.size, 0); + space.size = dir_size; + String str = make_string(info->filename, info->filename_len); + append(&space, str); + append(&space, "/"); + open_all_files_in_directory_pattern_match__inner(app, space, whitelist, blacklist, flags); + } + else{ + if (!match_in_pattern_array(info->filename, whitelist)){ + continue; } + if (match_in_pattern_array(info->filename, blacklist)){ + continue; + } + + space.size = dir_size; + String str = make_string(info->filename, info->filename_len); + append(&space, str); + create_buffer(app, space.str, space.size, 0); } } free_file_list(app, list); } +static Project_File_Pattern_Array +get_standard_blacklist(Partition *arena){ + static char *dot_str = ".*"; + CString_Array black_array = {0}; + black_array.strings = &dot_str; + black_array.count = 1; + return(get_pattern_array_from_cstring_array(arena, black_array)); +} + static void -open_all_files_in_directory_with_extension(Application_Links *app, Partition *scratch, - String dir, - CString_Array extension_array, - uint32_t flags){ +open_all_files_in_directory_pattern_match(Application_Links *app, Partition *scratch, + String dir, + Project_File_Pattern_Array whitelist, + Project_File_Pattern_Array blacklist, + uint32_t flags){ Temp_Memory temp = begin_temp_memory(scratch); int32_t size = 32 << 10; char *mem = push_array(scratch, char, size); String space = make_string_cap(mem, 0, size); append(&space, dir); - open_all_files_in_directory_with_extension__inner(app, space, extension_array, flags); + open_all_files_in_directory_pattern_match__inner(app, space, whitelist, blacklist, flags); + end_temp_memory(temp); +} + +static void +open_all_files_in_directory_with_extension(Application_Links *app, Partition *scratch, + String dir, CString_Array array, + uint32_t flags){ + Temp_Memory temp = begin_temp_memory(scratch); + Project_File_Pattern_Array whitelist = get_pattern_array_from_cstring_array(scratch, array); + Project_File_Pattern_Array blacklist = get_standard_blacklist(scratch); + open_all_files_in_directory_pattern_match(app, scratch, dir, whitelist, blacklist, flags); end_temp_memory(temp); } static void open_all_files_in_hot_with_extension(Application_Links *app, Partition *scratch, - CString_Array extensions_array, + CString_Array array, uint32_t flags){ Temp_Memory temp = begin_temp_memory(scratch); int32_t size = 32 << 10; char *mem = push_array(scratch, char, size); String space = make_string_cap(mem, 0, size); space.size = directory_get_hot(app, space.str, space.memory_size); - open_all_files_in_directory_with_extension__inner(app, space, extensions_array, flags); + Project_File_Pattern_Array whitelist = get_pattern_array_from_cstring_array(scratch, array); + Project_File_Pattern_Array blacklist = get_standard_blacklist(scratch); + open_all_files_in_directory_pattern_match__inner(app, space, whitelist, blacklist, flags); end_temp_memory(temp); } /////////////////////////////// -static Config* -parse_project__data(Partition *scratch, String file_name, String data, String file_dir, - Project *project){ - Config *parsed = 0; - - Cpp_Token_Array array = text_data_to_token_array(scratch, data); - if (array.tokens != 0){ - parsed = text_data_and_token_array_to_parse_data(scratch, file_name, data, array); - if (parsed != 0){ - memset(project, 0, sizeof(*project)); - project->loaded = true; - - // Set new project directory - { - project->dir = project->dir_space; - String str = make_fixed_width_string(project->dir_space); - copy(&str, file_dir); - terminate_with_null(&str); - project->dir_len = str.size; - } - - // Read the settings from project.4coder - String str = {0}; - if (config_string_var(parsed, "extensions", 0, &str)){ - parse_extension_line_to_extension_list(str, &project->extension_list); - } - - bool32 open_recursively = false; - if (config_bool_var(parsed, "open_recursively", 0, &open_recursively)){ - project->open_recursively = open_recursively; - } - #if defined(IS_WINDOWS) -# define FKEY_COMMAND "fkey_command_win" +#define PlatformName "win" #elif defined(IS_LINUX) -# define FKEY_COMMAND "fkey_command_linux" +#define PlatformName "linux" #elif defined(IS_MAC) -# define FKEY_COMMAND "fkey_command_mac" +#define PlatformName "mac" #else # error no project configuration names for this platform #endif + +static Project* +parse_project__config_data__version_0(Partition *arena, String file_dir, Config *parsed){ + Project *project = push_array(arena, Project, 1); + memset(project, 0, sizeof(*project)); + + // Set new project directory + { + int32_t cap = file_dir.size + 1; + char *mem = push_array(arena, char, cap); + project->dir = make_string(mem, 0, cap); + copy(&project->dir, file_dir); + terminate_with_null(&project->dir); + + project->load_path_array.paths = push_array(arena, Project_File_Load_Path, 1); + project->load_path_array.count = 1; + + project->load_path_array.paths[0].path = project->dir; + project->load_path_array.paths[0].recursive = false; + project->load_path_array.paths[0].relative = false; + + project->name = project->dir; + } + + // Read the settings from project.4coder + String str = {0}; + if (config_string_var(parsed, "extensions", 0, &str)){ + Extension_List extension_list; + parse_extension_line_to_extension_list(str, &extension_list); + project->pattern_array = get_pattern_array_from_extension_list(arena, extension_list); + project->blacklist_pattern_array = get_standard_blacklist(arena); + } + + bool32 open_recursively = false; + if (config_bool_var(parsed, "open_recursively", 0, &open_recursively)){ + project->load_path_array.paths[0].recursive = open_recursively; + } + + char fkey_command_name[] = "fkey_command_" PlatformName; + + project->command_array.commands = push_array(arena, Project_Command, 16); + project->command_array.count = 16; + + Project_Command *command = project->command_array.commands; + for (int32_t j = 1; j <= 16; ++j, ++command){ + project->fkey_commands[j - 1] = j - 1; + memset(command, 0, sizeof(*command)); + + Config_Compound *compound = 0; + if (config_compound_var(parsed, fkey_command_name, j, &compound)){ + command->name = push_string(arena, 4); + append_int_to_str(&command->name, j); + terminate_with_null(&command->name); - for (int32_t i = 1; i <= 16; ++i){ - Config_Compound *compound = 0; - if (config_compound_var(parsed, FKEY_COMMAND, i, &compound)){ - Fkey_Command *command = &project->fkey_commands[i - 1]; - command->command[0] = 0; - command->out[0] = 0; - command->use_build_panel = false; - command->save_dirty_buffers = false; + String cmd = {0}; + if (config_compound_string_member(parsed, compound, "cmd", 0, &cmd)){ + command->cmd = push_string_copy(arena, cmd); + } + + String out = {0}; + if (config_compound_string_member(parsed, compound, "out", 1, &out)){ + command->out = push_string_copy(arena, out); + } + + bool32 footer_panel = false; + if (config_compound_bool_member(parsed, compound, "footer_panel", 2, &footer_panel)){ + command->footer_panel = footer_panel; + } + + bool32 save_dirty_files = false; + if (config_compound_bool_member(parsed, compound, "save_dirty_files", 3, &save_dirty_files)){ + command->save_dirty_files = save_dirty_files; + } + } + else{ + command->name = push_string(arena, 4); + append_int_to_str(&command->name, j); + terminate_with_null(&command->name); + } + } + + project->loaded = true; + return(project); +} + +static void +parse_project__extract_pattern_array(Partition *arena, Config *parsed, + char *root_variable_name, + Project_File_Pattern_Array *array_out){ + Config_Compound *compound = 0; + if (config_compound_var(parsed, root_variable_name, 0, &compound)){ + int32_t count = typed_array_get_count(parsed, compound, ConfigRValueType_String); + + array_out->patterns = push_array(arena, Project_File_Pattern, count); + array_out->count = count; + + for (int32_t i = 0, c = 0; c < count; ++i){ + String str = {0}; + if (config_compound_string_member(parsed, compound, "~", i, &str)){ + str = push_string_copy(arena, str); + get_absolutes(str, &array_out->patterns[c].absolutes, false, false); + ++c; + } + } + } +} + +static Project* +parse_project__config_data__version_1(Partition *arena, String root_dir, Config *parsed){ + Project *project = push_array(arena, Project, 1); + memset(project, 0, sizeof(*project)); + + // Set new project directory + { + int32_t cap = root_dir.size + 1; + project->dir = push_string(arena, cap); + copy(&project->dir, root_dir); + terminate_with_null(&project->dir); + } + + // project_name + { + String str = {0}; + if (config_string_var(parsed, "project_name", 0, &str)){ + project->name = push_string_copy(arena, str); + } + } + + // patterns + parse_project__extract_pattern_array(arena, parsed, "patterns", &project->pattern_array); + + // blacklist_patterns + parse_project__extract_pattern_array(arena, parsed, "blacklist_patterns", &project->blacklist_pattern_array); + + // load_paths + { + Config_Compound *compound = 0; + if (config_compound_var(parsed, "load_paths", 0, &compound)){ + for (int32_t i = 0;; ++i){ + Config_Compound *paths_option = 0; + Iteration_Step_Result step_result = typed_array_iteration_step(parsed, compound, ConfigRValueType_Compound, i, &paths_option); + if (step_result == Iteration_Skip){ + continue; + } + else if (step_result == Iteration_Quit){ + break; + } + + bool32 use_this_option = false; + + Config_Compound *paths = 0; + if (config_compound_compound_member(parsed, paths_option, "paths", 0, &paths)){ + String str = {0}; + if (config_compound_string_member(parsed, paths_option, "os", 1, &str)){ + if (match(str, make_lit_string(PlatformName))){ + use_this_option = true; + } + } + } + + if (use_this_option){ + int32_t count = typed_array_get_count(parsed, paths, ConfigRValueType_Compound); - String cmd = {0}; - if (config_compound_string_member(parsed, compound, "cmd", 0, &cmd)){ - String dst = make_fixed_width_string(command->command); - append(&dst, cmd); - terminate_with_null(&dst); + project->load_path_array.paths = push_array(arena, Project_File_Load_Path, count); + project->load_path_array.count = count; + + Project_File_Load_Path *dst = project->load_path_array.paths; + for (int32_t j = 0, c = 0; c < count; ++j){ + Config_Compound *src = 0; + if (config_compound_compound_member(parsed, paths, "~", j, &src)){ + memset(dst, 0, sizeof(*dst)); + dst->recursive = true; + dst->relative = true; + + String str = {0}; + if (config_compound_string_member(parsed, src, "path", 0, &str)){ + dst->path = push_string_copy(arena, str); + } + + config_compound_bool_member(parsed, src, "recursive", 1, &dst->recursive); + config_compound_bool_member(parsed, src, "relative", 1, &dst->relative); + + ++c; + ++dst; + } } - String out = {0}; - if (config_compound_string_member(parsed, compound, "out", 1, &out)){ - String dst = make_fixed_width_string(command->out); - append(&dst, out); - terminate_with_null(&out); - } - - bool32 footer_panel = false; - if (config_compound_bool_member(parsed, compound, "footer_panel", 2, &footer_panel)){ - command->use_build_panel = footer_panel; - } - - bool32 save_dirty_buffers = false; - if (config_compound_bool_member(parsed, compound, "save_dirty_files", 3, &save_dirty_buffers)){ - command->save_dirty_buffers = save_dirty_buffers; - } + break; } } } } - return(parsed); + // command_list + { + Config_Compound *compound = 0; + if (config_compound_var(parsed, "command_list", 0, &compound)){ + int32_t count = typed_array_get_count(parsed, compound, ConfigRValueType_Compound); + + project->command_array.commands = push_array(arena, Project_Command, count); + project->command_array.count = count; + + Project_Command *dst = project->command_array.commands; + for (int32_t i = 0, c = 0; c < count; ++i){ + + Config_Compound *src = 0; + if (config_compound_compound_member(parsed, compound, "~", i, &src)){ + memset(dst, 0, sizeof(*dst)); + + bool32 can_emit_command = true; + + String name = {0}; + Config_Compound *cmd_set = 0; + String out = {0}; + bool32 footer_panel = false; + bool32 save_dirty_files = true; + String cmd_str = {0}; + + if (!config_compound_string_member(parsed, src, "name", 0, &name)){ + can_emit_command = false; + goto finish_command; + } + + if (!config_compound_compound_member(parsed, src, "cmd", 1, &cmd_set)){ + can_emit_command = false; + goto finish_command; + } + + can_emit_command = false; + for (int32_t j = 0;; ++j){ + Config_Compound *cmd_option = 0; + Iteration_Step_Result step_result = typed_array_iteration_step(parsed, cmd_set, ConfigRValueType_Compound, j, &cmd_option); + if (step_result == Iteration_Skip){ + continue; + } + else if (step_result == Iteration_Quit){ + break; + } + + bool32 use_this_option = false; + + String cmd = {0}; + if (config_compound_string_member(parsed, cmd_option, "cmd", 0, &cmd)){ + String str = {0}; + if (config_compound_string_member(parsed, cmd_option, "os", 1, &str)){ + if (match(str, make_lit_string(PlatformName))){ + use_this_option = true; + } + } + } + + if (use_this_option){ + can_emit_command = true; + cmd_str = cmd; + break; + } + } + + if (can_emit_command){ + config_compound_string_member(parsed, src, "out", 2, &out); + config_compound_bool_member(parsed, src, "footer_panel", 3, &footer_panel); + config_compound_bool_member(parsed, src, "save_dirty_files", 4, + &save_dirty_files); + + dst->name = push_string_copy(arena, name); + dst->cmd = push_string_copy(arena, cmd_str); + dst->out = push_string_copy(arena, out); + dst->footer_panel = footer_panel; + dst->save_dirty_files = save_dirty_files; + } + + finish_command:; + ++dst; + ++c; + } + } + } + } + + // fkey_command + { + for (int32_t i = 1; i <= 16; ++i){ + String name = {0}; + int32_t index = -1; + if (config_string_var(parsed, "fkey_command", i, &name)){ + int32_t count = project->command_array.count; + Project_Command *command_ptr = project->command_array.commands; + for (int32_t j = 0; j < count; ++j, ++command_ptr){ + if (match(command_ptr->name, name)){ + index = j; + break; + } + } + } + project->fkey_commands[i - 1] = index; + } + } + + project->loaded = true; + return(project); } -static Config* -parse_project__nearest_file(Application_Links *app, Partition *scratch, Project *project){ - Config *parsed = 0; +static Project* +parse_project__config_data(Partition *arena, String file_dir, Config *parsed){ + int32_t version = 0; + if (parsed->version != 0){ + version = *parsed->version; + } + switch (version){ + case 0: + { + return(parse_project__config_data__version_0(arena, file_dir, parsed)); + }break; + + case 1: + { + return(parse_project__config_data__version_1(arena, file_dir, parsed)); + }break; + + default: + { + return(0); + }break; + } +} + +static Project_Parse_Result +parse_project__data(Partition *arena, String file_name, String data, String file_dir){ + Project_Parse_Result result = {0}; + Cpp_Token_Array array = text_data_to_token_array(arena, data); + if (array.tokens != 0){ + result.parsed = text_data_and_token_array_to_parse_data(arena, file_name, data, array); + if (result.parsed != 0){ + result.project = parse_project__config_data(arena, file_dir, result.parsed); + } + } + return(result); +} + +static Project_Parse_Result +parse_project__nearest_file(Application_Links *app, Partition *arena){ + Project_Parse_Result result = {0}; + + Temp_Memory restore_point = begin_temp_memory(arena); String project_path = {0}; - Temp_Memory temp = begin_temp_memory(scratch); int32_t size = 32 << 10; - char *space = push_array(scratch, char, size); + char *space = push_array(arena, char, size); if (space != 0){ project_path = make_string_cap(space, 0, size); project_path.size = directory_get_hot(app, project_path.str, project_path.memory_size); - end_temp_memory(temp); - push_array(scratch, char, project_path.size); + end_temp_memory(restore_point); + push_array(arena, char, project_path.size); project_path.memory_size = project_path.size; if (project_path.size == 0){ print_message(app, literal("The hot directory is empty, cannot search for a project.\n")); } else{ - File_Name_Path_Data dump = dump_file_search_up_path(scratch, project_path, make_lit_string("project.4coder")); + File_Name_Path_Data dump = dump_file_search_up_path(arena, project_path, make_lit_string("project.4coder")); if (dump.data.str != 0){ String project_root = dump.path; remove_last_folder(&project_root); - parsed = parse_project__data(scratch, dump.file_name, dump.data, project_root, project); + result = parse_project__data(arena, dump.file_name, dump.data, project_root); } else{ char message_space[512]; String message = make_fixed_width_string(message_space); append(&message, "Did not find project.4coder. "); - if (current_project.dir != 0){ - append(&message, "Continuing with: "); - append(&message, current_project.dir); + if (current_project.loaded){ + if (current_project.name.size > 0){ + append(&message, "Continuing with: "); + append(&message, current_project.name); + } + else{ + append(&message, "Continuing with: "); + append(&message, current_project.dir); + } } else{ append(&message, "Continuing without a project"); @@ -266,92 +589,266 @@ parse_project__nearest_file(Application_Links *app, Partition *scratch, Project } } } - end_temp_memory(temp); - return(parsed); + return(result); +} + +static bool32 +project_deep_copy__pattern_array(Partition *arena, Project_File_Pattern_Array *src_array, + Project_File_Pattern_Array *dst_array){ + int32_t pattern_count = src_array->count; + dst_array->patterns = push_array(arena, Project_File_Pattern, pattern_count); + if (dst_array->patterns == 0){ + return(false); + } + dst_array->count = pattern_count; + + Project_File_Pattern *dst = dst_array->patterns; + Project_File_Pattern *src = src_array->patterns; + for (int32_t i = 0; i < pattern_count; ++i, ++dst, ++src){ + int32_t abs_count = src->absolutes.count; + dst->absolutes.count = abs_count; + for (int32_t j = 0; j < abs_count; ++j){ + dst->absolutes.a[j] = push_string_copy(arena, src->absolutes.a[j]); + if (dst->absolutes.a[j].str == 0){ + return(false); + } + } + } + + return(true); +} + +static Project +project_deep_copy__inner(Partition *arena, Project *project){ + Project result = {0}; + + result.dir = push_string_copy(arena, project->dir); + if (result.dir.str == 0){ + return(result); + } + + result.name = push_string_copy(arena, project->name); + if (result.name.str == 0){ + return(result); + } + + if (!project_deep_copy__pattern_array(arena, &project->pattern_array, &result.pattern_array)){ + return(result); + } + if (!project_deep_copy__pattern_array(arena, &project->blacklist_pattern_array, &result.blacklist_pattern_array)){ + return(result); + } + + { + int32_t path_count = project->load_path_array.count; + result.load_path_array.paths = push_array(arena, Project_File_Load_Path, path_count); + if (result.load_path_array.paths == 0){ + return(result); + } + result.load_path_array.count = path_count; + + Project_File_Load_Path *dst = result.load_path_array.paths; + Project_File_Load_Path *src = project->load_path_array.paths; + for (int32_t i = 0; i < path_count; ++i, ++dst, ++src){ + dst->path = push_string_copy(arena, src->path); + if (dst->path.str == 0){ + return(result); + } + dst->recursive = src->recursive; + dst->relative = src->relative; + } + } + + { + int32_t command_count = project->command_array.count; + result.command_array.commands = push_array(arena, Project_Command, command_count); + if (result.command_array.commands == 0){ + return(result); + } + result.command_array.count = command_count; + + Project_Command *dst = result.command_array.commands; + Project_Command *src = project->command_array.commands; + for (int32_t i = 0; i < command_count; ++i, ++dst, ++src){ + memset(dst, 0, sizeof(*dst)); + if (src->name.str != 0){ + dst->name = push_string_copy(arena, src->name); + if (dst->name.str == 0){ + return(result); + } + } + if (src->cmd.str != 0){ + dst->cmd = push_string_copy(arena, src->cmd); + if (dst->cmd.str == 0){ + return(result); + } + } + if (src->out.str != 0){ + dst->out = push_string_copy(arena, src->out); + if (dst->out.str == 0){ + return(result); + } + } + dst->footer_panel = src->footer_panel; + dst->save_dirty_files = src->save_dirty_files; + } + } + + { + memcpy(result.fkey_commands, project->fkey_commands, sizeof(result.fkey_commands)); + } + + result.loaded = true; + return(result); +} + +static Project +project_deep_copy(Partition *arena, Project *project){ + Temp_Memory temp = begin_temp_memory(arena); + Project result = project_deep_copy__inner(arena, project); + if (!result.loaded){ + end_temp_memory(temp); + memset(&result, 0, sizeof(result)); + } + return(result); } static void set_current_project(Application_Links *app, Partition *scratch, Project *project, Config *parsed){ - memcpy(¤t_project, project, sizeof(current_project)); - current_project.dir = current_project.dir_space; + bool32 print_errors = false; - String file_dir = make_string(current_project.dir_space, current_project.dir_len); - - // Open all project files - uint32_t flags = 0; - if (current_project.open_recursively){ - flags |= OpenAllFilesFlag_Recursive; + if (parsed != 0 && project != 0){ + if (current_project_arena.base == 0){ + int32_t project_mem_size = (1 << 20); + void *project_mem = memory_allocate(app, project_mem_size); + current_project_arena = make_part(project_mem, project_mem_size); + } + + // Copy project to current_project + current_project_arena.pos = 0; + Project new_project = project_deep_copy(¤t_project_arena, project); + if (new_project.loaded){ + current_project = new_project; + + print_errors = true; + + // Open all project files + for (int32_t i = 0; i < current_project.load_path_array.count; ++i){ + Project_File_Load_Path *load_path = ¤t_project.load_path_array.paths[i]; + uint32_t flags = 0; + if (load_path->recursive){ + flags |= OpenAllFilesFlag_Recursive; + } + + Temp_Memory temp = begin_temp_memory(scratch); + String path_str = load_path->path; + String file_dir = path_str; + if (load_path->relative){ + String project_dir = current_project.dir; + int32_t cap = path_str.size + project_dir.size + 2; + char *mem = push_array(scratch, char, cap); + push_align(scratch, 8); + if (mem != 0){ + file_dir = make_string_cap(mem, 0, cap); + append(&file_dir, project_dir); + if (file_dir.size == 0 || file_dir.str[file_dir.size - 1] != '/'){ + append(&file_dir, "/"); + } + append(&file_dir, path_str); + if (file_dir.size == 0 || file_dir.str[file_dir.size - 1] != '/'){ + append(&file_dir, "/"); + } + terminate_with_null(&file_dir); + } + } + + Project_File_Pattern_Array whitelist = current_project.pattern_array; + Project_File_Pattern_Array blacklist = current_project.blacklist_pattern_array; + open_all_files_in_directory_pattern_match(app, scratch, file_dir, + whitelist, blacklist, + flags); + + end_temp_memory(temp); + } + + // Set window title + if (project->name.size > 0){ + char space[1024]; + String builder = make_fixed_width_string(space); + append(&builder, "4coder project: "); + append(&builder, project->name); + terminate_with_null(&builder); + set_window_title(app, builder.str); + } + } + else{ +#define M "Failed to initialize new project; need more memory dedicated to the project system.\n" + print_message(app, literal(M)); +#undef M + } + } + else if (parsed != 0){ + print_errors = true; } - CString_Array array = project_get_extensions(¤t_project); - open_all_files_in_directory_with_extension(app, scratch, file_dir, array, flags); - // Set window title - char space[1024]; - String builder = make_fixed_width_string(space); - append(&builder, "4coder: "); - append(&builder, file_dir); - terminate_with_null(&builder); - set_window_title(app, builder.str); - - Temp_Memory temp = begin_temp_memory(scratch); - String error_text = config_stringize_errors(scratch, parsed); - print_message(app, error_text.str, error_text.size); - end_temp_memory(temp); + if (print_errors){ + Temp_Memory temp = begin_temp_memory(scratch); + String error_text = config_stringize_errors(scratch, parsed); + print_message(app, error_text.str, error_text.size); + end_temp_memory(temp); + } } static void set_current_project_from_data(Application_Links *app, Partition *scratch, String file_name, String data, String file_dir){ Temp_Memory temp = begin_temp_memory(scratch); - Project project = {0}; - Config *parsed = parse_project__data(scratch, file_name, data, file_dir, &project); - if (parsed != 0){ - set_current_project(app, scratch, &project, parsed); - } + Project_Parse_Result project_parse = parse_project__data(scratch, file_name, data, file_dir); + set_current_project(app, scratch, project_parse.project, project_parse.parsed); end_temp_memory(temp); } static void set_current_project_from_nearest_project_file(Application_Links *app, Partition *scratch){ Temp_Memory temp = begin_temp_memory(scratch); - Project project = {0}; - Config *parsed = parse_project__nearest_file(app, scratch, &project); - if (parsed != 0){ - set_current_project(app, scratch, &project, parsed); - } + Project_Parse_Result project_parse = parse_project__nearest_file(app, scratch); + set_current_project(app, scratch, project_parse.project, project_parse.parsed); end_temp_memory(temp); } static void -exec_project_fkey_command(Application_Links *app, int32_t command_ind){ - Fkey_Command *fkey = ¤t_project.fkey_commands[command_ind]; - char *command = fkey->command; +exec_project_fkey_command(Application_Links *app, int32_t fkey_index){ + if (!current_project.loaded){ + return; + } - if (command[0] != 0){ - char *out = fkey->out; - bool32 use_build_panel = fkey->use_build_panel; - bool32 save_dirty_buffers = fkey->save_dirty_buffers; + int32_t command_index = current_project.fkey_commands[fkey_index]; + if (command_index < 0 || command_index >= current_project.command_array.count){ + return; + } + + Project_Command *fkey = ¤t_project.command_array.commands[command_index]; + if (fkey->cmd.size > 0){ + bool32 footer_panel = fkey->footer_panel; + bool32 save_dirty_files = fkey->save_dirty_files; - if (save_dirty_buffers){ + if (save_dirty_files){ save_all_dirty_buffers(app); } - int32_t command_len = str_size(command); - View_Summary view = {0}; View_Summary *view_ptr = 0; Buffer_Identifier buffer_id = {0}; uint32_t flags = CLI_OverlapWithConflict; bool32 set_fancy_font = false; - if (out[0] != 0){ - int32_t out_len = str_size(out); - buffer_id = buffer_identifier(out, out_len); + if (fkey->out.size > 0){ + buffer_id = buffer_identifier(fkey->out.str, fkey->out.size); - if (use_build_panel){ + if (footer_panel){ view = get_or_open_build_panel(app); - if (match(out, "*compilation*")){ + if (match(fkey->out, "*compilation*")){ set_fancy_font = true; } } @@ -361,14 +858,16 @@ exec_project_fkey_command(Application_Links *app, int32_t command_ind){ view_ptr = &view; memset(&prev_location, 0, sizeof(prev_location)); - lock_jump_buffer(out, out_len); + lock_jump_buffer(fkey->out.str, fkey->out.size); } else{ // TODO(allen): fix the exec_system_command call so it can take a null buffer_id. buffer_id = buffer_identifier(literal("*dump*")); } - exec_system_command(app, view_ptr, buffer_id, current_project.dir, current_project.dir_len, command, command_len, flags); + String dir = current_project.dir; + String cmd = fkey->cmd; + exec_system_command(app, view_ptr, buffer_id, dir.str, dir.size, cmd.str, cmd.size, flags); if (set_fancy_font){ set_fancy_compilation_buffer_font(app); } @@ -380,21 +879,21 @@ exec_project_fkey_command(Application_Links *app, int32_t command_ind){ CUSTOM_COMMAND_SIG(close_all_code) CUSTOM_DOC("Closes any buffer with a filename ending with an extension configured to be recognized as a code file type.") { - CString_Array extensions = project_get_extensions(¤t_project); + CString_Array extensions = get_code_extensions(&global_config.code_exts); close_all_files_with_extension(app, &global_part, extensions); } CUSTOM_COMMAND_SIG(open_all_code) CUSTOM_DOC("Open all code in the current directory. File types are determined by extensions. An extension is considered code based on the extensions specified in 4coder.config.") { - CString_Array extensions = project_get_extensions(¤t_project); + CString_Array extensions = get_code_extensions(&global_config.code_exts); open_all_files_in_hot_with_extension(app, &global_part, extensions, 0); } CUSTOM_COMMAND_SIG(open_all_code_recursive) CUSTOM_DOC("Works as open_all_code but also runs in all subdirectories.") { - CString_Array extensions = project_get_extensions(¤t_project); + CString_Array extensions = get_code_extensions(&global_config.code_exts); open_all_files_in_hot_with_extension(app, &global_part, extensions, OpenAllFilesFlag_Recursive); } @@ -436,7 +935,8 @@ CUSTOM_COMMAND_SIG(project_go_to_root_directory) CUSTOM_DOC("Changes 4coder's hot directory to the root directory of the currently loaded project. With no loaded project nothing hapepns.") { if (current_project.loaded){ - directory_set_hot(app, current_project.dir, current_project.dir_len); + String dir = current_project.dir; + directory_set_hot(app, dir.str, dir.size); } } diff --git a/4coder_project_commands.h b/4coder_project_commands.h index 31300316..3d737939 100644 --- a/4coder_project_commands.h +++ b/4coder_project_commands.h @@ -15,23 +15,65 @@ enum{ /////////////////////////////// -struct Fkey_Command{ - char command[128]; - char out[128]; - bool32 use_build_panel; - bool32 save_dirty_buffers; +typedef int32_t Iteration_Step_Result; +enum{ + Iteration_Good = 0, + Iteration_Skip = 1, + Iteration_Quit = 2, +}; + +/////////////////////////////// + +struct Project_Command{ + String name; + String cmd; + String out; + bool32 footer_panel; + bool32 save_dirty_files; +}; + +struct Project_Command_Array{ + Project_Command *commands; + int32_t count; +}; + +struct Project_File_Load_Path{ + String path; + bool32 recursive; + bool32 relative; +}; + +struct Project_File_Load_Path_Array{ + Project_File_Load_Path *paths; + int32_t count; +}; + +struct Project_File_Pattern{ + Absolutes absolutes; +}; + +struct Project_File_Pattern_Array{ + Project_File_Pattern *patterns; + int32_t count; }; struct Project{ - char dir_space[256]; - char *dir; - int32_t dir_len; - - Extension_List extension_list; - Fkey_Command fkey_commands[16]; - - bool32 open_recursively; bool32 loaded; + + String dir; + String name; + + Project_File_Pattern_Array pattern_array; + Project_File_Pattern_Array blacklist_pattern_array; + Project_File_Load_Path_Array load_path_array; + Project_Command_Array command_array; + + int32_t fkey_commands[16]; +}; + +struct Project_Parse_Result{ + Config *parsed; + Project *project; }; /////////////////////////////// diff --git a/4coder_search.cpp b/4coder_search.cpp index c718b62e..01015023 100644 --- a/4coder_search.cpp +++ b/4coder_search.cpp @@ -614,7 +614,7 @@ buffered_print_match_jump_line(Application_Links *app, Partition *part, Temp_Mem static void list__parameters(Application_Links *app, General_Memory *general, Partition *scratch, - String *strings, int32_t count, Search_Range_Flag match_flags){ + String *strings, int32_t count, Search_Range_Flag match_flags){ // Open the search buffer String search_name = make_lit_string("*search*"); Buffer_Summary search_buffer = get_buffer_by_name(app, search_name.str, search_name.size, AccessAll); @@ -674,7 +674,7 @@ list_single__parameters(Application_Links *app, General_Memory *general, Partiti static void list_query__parameters(Application_Links *app, General_Memory *general, Partition *scratch, - bool32 substrings, bool32 case_insensitive){ + bool32 substrings, bool32 case_insensitive){ char space[1024]; String str = get_query_string(app, "List Locations For: ", space, sizeof(space)); if (str.str != 0){ @@ -685,7 +685,7 @@ list_query__parameters(Application_Links *app, General_Memory *general, Partitio static void list_identifier__parameters(Application_Links *app, General_Memory *general, Partition *scratch, - bool32 substrings, bool32 case_insensitive){ + bool32 substrings, bool32 case_insensitive){ View_Summary view = get_active_view(app, AccessProtected); Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessProtected); if (!buffer.exists) return; @@ -699,7 +699,7 @@ list_identifier__parameters(Application_Links *app, General_Memory *general, Par static void list_selected_range__parameters(Application_Links *app, General_Memory *general, Partition *scratch, - bool32 substrings, bool32 case_insensitive){ + bool32 substrings, bool32 case_insensitive){ View_Summary view = get_active_view(app, AccessProtected); Temp_Memory temp = begin_temp_memory(scratch); String str = get_string_in_view_range(app, scratch, &view); @@ -724,10 +724,10 @@ list_type_definition__parameters(Application_Links *app, General_Memory *general match_strings[5] = build_string(scratch, "enum " , str, "\n{"); list__parameters(app, general, scratch, - match_strings, ArrayCount(match_strings), 0); + match_strings, ArrayCount(match_strings), 0); end_temp_memory(temp); - + #if 0 Buffer_Summary buffer = get_buffer_by_name(app, literal("*search*"), AccessAll); if (buffer.line_count == 2){ @@ -748,13 +748,13 @@ CUSTOM_COMMAND_SIG(list_all_substring_locations) CUSTOM_DOC("Queries the user for a string and lists all case-sensitive substring matches found in all open buffers.") { list_query__parameters(app, &global_general, &global_part, true, false); - } +} CUSTOM_COMMAND_SIG(list_all_locations_case_insensitive) CUSTOM_DOC("Queries the user for a string and lists all exact case-insensitive matches found in all open buffers.") { list_query__parameters(app, &global_general, &global_part, false, true); - } +} CUSTOM_COMMAND_SIG(list_all_substring_locations_case_insensitive) CUSTOM_DOC("Queries the user for a string and lists all case-insensitive substring matches found in all open buffers.") @@ -793,8 +793,8 @@ CUSTOM_DOC("Queries user for string, lists all locations of strings that appear String str = get_query_string(app, "List Definitions For: ", space, sizeof(space)); if (str.str != 0){ change_active_panel(app); -list_type_definition__parameters(app, &global_general, &global_part, str); -} + list_type_definition__parameters(app, &global_general, &global_part, str); + } } CUSTOM_COMMAND_SIG(list_all_locations_of_type_definition_of_identifier) diff --git a/my_bindings.cpp b/my_bindings.cpp new file mode 100644 index 00000000..0d45e20f --- /dev/null +++ b/my_bindings.cpp @@ -0,0 +1,28 @@ +/* +New File +*/ + +#include "4coder_default_include.cpp" + +extern "C" int32_t +get_bindings(void *data, int32_t size){ + Bind_Helper context_ = begin_bind_helper(data, size); + Bind_Helper *context = &context_; + + set_all_default_hooks(context); + + default_keys(context); + begin_map(context, mapid_global); + bind(context, 'M', MDFR_ALT, goto_prev_jump_no_skips_sticky); + bind(context, 'N', MDFR_ALT, goto_first_jump_sticky); + end_map(context); + begin_map(context, mapid_file); + end_map(context); + begin_map(context, default_code_map); + end_map(context); + + + int32_t result = end_bind_helper(context); + return(result); +} + diff --git a/project.4coder b/project.4coder index d20d8866..5595f920 100644 --- a/project.4coder +++ b/project.4coder @@ -1,34 +1,66 @@ -extensions = ".c.cpp.h.m.bat.sh.4coder.txt"; -open_recursively = true; +version(1); +project_name = "4coder"; +patterns = { +"*.c", +"*.cpp", +"*.h", +"*.m", +"*.bat", +"*.sh", +"*.4coder", +"*.txt", +}; +blacklist_patterns = { +".*", +}; +load_paths_only = { {"."}, }; +load_paths = { + {load_paths_only, .os = "win"}, + {load_paths_only, .os = "linux"}, + {load_paths_only, .os = "mac"}, +}; build_x86_win32 = "echo build: x86 & build.bat /DDEV_BUILD_X86"; build_x86_linux = "echo build: x86 & ./build.sh -DDEV_BUILD_X86"; build_x86_mac = "echo build: x86 & ./build.sh -DDEV_BUILD_X86"; -fkey_command_win[1] = {"echo build: x64 & build.bat", "*compilation*" , .footer_panel = true , .save_dirty_files = true }; -fkey_command_win[2] = {"build_site.bat" , "*site*" , .footer_panel = false, .save_dirty_files = true }; -fkey_command_win[3] = {"build_string.bat" , "*compilation*" , .footer_panel = true , .save_dirty_files = true }; -fkey_command_win[4] = {build_x86_win32 , "*compilation*" , .footer_panel = true, .save_dirty_files = true }; -fkey_command_win[5] = {"build_metadata.bat" , "*compilation*" , .footer_panel = true , .save_dirty_files = true }; -fkey_command_win[6] = {"run_regression_tests.bat" , "*test*" , .footer_panel = false, .save_dirty_files = true }; -fkey_command_win[7] = {"build_tests.bat" , "*compilation*" , .footer_panel = true , .save_dirty_files = true }; -fkey_command_win[8] = {"generate_tests.bat" , "*compilation*" , .footer_panel = true , .save_dirty_files = true }; -fkey_command_win[12] = {"package.bat" , "*package*" , .footer_panel = false, .save_dirty_files = true }; +command_list = { + { .name = "build x64", + .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, + .cmd = { {"echo build: x64 & build.bat" , .os = "win" }, + {"echo build: x64 & ./build.sh", .os = "linux"}, + {"echo build: x64 & ./build.sh", .os = "mac" }, }, }, + { .name = "build site", + .out = "*site*", .footer_panel = false, .save_dirty_files = true, + .cmd = { {"build_site.bat", .os = "win" }, + {"build_site.sh" , .os = "linux"}, + {"build_site.sh" , .os = "mac" }, }, }, + { .name = "build string", + .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, + .cmd = { {"build_string.bat", .os = "win" }, + {"build_string.sh" , .os = "linux"}, + {"build_string.sh" , .os = "mac" }, }, }, + { .name = "build x86", + .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, + .cmd = { {build_x86_win32, .os = "win" }, + {build_x86_linux, .os = "linux"}, + {build_x86_mac , .os = "mac" }, }, }, + { .name = "build metadata", + .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, + .cmd = { {"build_metadata.bat", .os = "win" }, + {"build_metadata.sh" , .os = "linux"}, + {"build_metadata.sh" , .os = "mac" }, }, }, + { .name = "package", + .out = "*package*", .footer_panel = false, .save_dirty_files = true, + .cmd = { {"package.bat", .os = "win" }, + {"package.sh" , .os = "linux"}, + {"package.sh" , .os = "mac" }, }, }, +}; -fkey_command_win[1] = {"build_tests.bat" , "*compilation*" , .footer_panel = true , .save_dirty_files = true }; -fkey_command_win[2] = {"generate_tests.bat" , "*compilation*" , .footer_panel = true , .save_dirty_files = true }; -fkey_command_win[3] = {"run_regression_tests.bat" , "*test*" , .footer_panel = false, .save_dirty_files = true }; - -fkey_command_linux[1] = {"echo build: x64 & ./build.sh", "*compilation*" , .footer_panel = true , .save_dirty_files = true }; -fkey_command_linux[2] = {"build_site.sh" , "*site*" , .footer_panel = false, .save_dirty_files = true }; -fkey_command_linux[3] = {"build_string.sh" , "*compilation*" , .footer_panel = true , .save_dirty_files = true }; -fkey_command_linux[4] = {build_x86_linux , "*compilation*" , .footer_panel = true , .save_dirty_files = true }; -fkey_command_linux[5] = {"./build_metadata.sh" , "*compilation*" , .footer_panel = true , .save_dirty_files = true }; -fkey_command_linux[12] = {"./package.sh" , "*package*" , .footer_panel = false, .save_dirty_files = true }; - -fkey_command_mac[1] = {"echo build: x64 & ./build.sh", "*compilation*" , .footer_panel = true , .save_dirty_files = true }; -fkey_command_mac[2] = {"build_site.sh" , "*site*" , .footer_panel = false, .save_dirty_files = true }; -fkey_command_mac[3] = {"build_string.sh" , "*compilation*" , .footer_panel = true , .save_dirty_files = true }; -fkey_command_mac[4] = {build_x86_mac , "*compilation*" , .footer_panel = true , .save_dirty_files = true }; -fkey_command_mac[10] = {"./package.sh" , "*package*" , .footer_panel = false, .save_dirty_files = true }; +fkey_command[1] = "build x64"; +fkey_command[2] = "build site"; +fkey_command[3] = "build string"; +fkey_command[4] = "build x86"; +fkey_command[5] = "build metadata"; +fkey_command[12] = "package";