From a6467d7cfacf8cf71bf61ba0609f8029e8cf59d1 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Wed, 30 Dec 2020 23:53:21 -0800 Subject: [PATCH] Consolidate project parsing, up converting, and dumping --- custom/4coder_project_commands.cpp | 37 ++++++++++++++++------------- custom/generated/command_metadata.h | 14 +++++------ 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/custom/4coder_project_commands.cpp b/custom/4coder_project_commands.cpp index db349501..c076d0e2 100644 --- a/custom/4coder_project_commands.cpp +++ b/custom/4coder_project_commands.cpp @@ -808,6 +808,8 @@ CUSTOM_DOC("Looks for a project.4coder file in the current directory and tries t // NOTE(allen): Parse config data out of project file Project_Parse_Result project_parse = {}; + Variable_Handle proj_var = vars_get_nil(); + if (dump.data.str != 0){ Token_Array array = token_array_from_text(app, scratch, dump.data); if (array.tokens != 0){ @@ -818,15 +820,32 @@ CUSTOM_DOC("Looks for a project.4coder file in the current directory and tries t version = *project_parse.parsed->version; } switch (version){ + case 0: + { + proj_var = prj_version_1_to_version_2(app, project_parse.parsed, project_parse.project); + }break; + case 1: { project_parse.project = parse_project__config_data__version_1(app, scratch, project_root, project_parse.parsed); + proj_var = prj_version_1_to_version_2(app, project_parse.parsed, project_parse.project); + }break; + + default: + { + proj_var = def_fill_var_from_config(app, vars_get_root(), vars_save_string_lit("prj_config"), project_parse.parsed); }break; } } } } + // NOTE(allen): Dump project + if (!vars_is_nil(proj_var)){ + vars_print(app, proj_var); + print_message(app, string_u8_litexpr("\n")); + } + // NOTE(allen): Set current project if (project_parse.parsed != 0 && project_parse.project != 0){ @@ -872,8 +891,7 @@ CUSTOM_DOC("Looks for a project.4coder file in the current directory and tries t // Set window title if (project_parse.project->name.size > 0){ Temp_Memory temp = begin_temp(scratch); - String_Const_u8 builder = push_u8_stringf(scratch, "4coder project: %.*s", - string_expand(project_parse.project->name)); + String_Const_u8 builder = push_u8_stringf(scratch, "4coder project: %.*s", string_expand(project_parse.project->name)); set_window_title(app, builder); end_temp(temp); } @@ -885,21 +903,6 @@ CUSTOM_DOC("Looks for a project.4coder file in the current directory and tries t } } - if (project_parse.project != 0){ - Variable_Handle proj_var = {}; - - if (project_parse.parsed->version == 0 || *project_parse.parsed->version < 2){ - print_message(app, string_u8_litexpr("Project variables converted from version 1 to version 2\n")); - proj_var = prj_version_1_to_version_2(app, project_parse.parsed, project_parse.project); - } - else{ - proj_var = def_fill_var_from_config(app, vars_get_root(), vars_save_string_lit("prj_config"), project_parse.parsed); - } - - vars_print(app, proj_var); - print_message(app, string_u8_litexpr("\n")); - } - // NOTE(allen): errors if (project_parse.parsed != 0){ if (project_parse.project == 0){ diff --git a/custom/generated/command_metadata.h b/custom/generated/command_metadata.h index ec7b5133..2880bb4e 100644 --- a/custom/generated/command_metadata.h +++ b/custom/generated/command_metadata.h @@ -436,9 +436,9 @@ static Command_Metadata fcoder_metacmd_table[250] = { { PROC_LINKS(profile_disable, 0), false, "profile_disable", 15, "Prevent 4coder's self profiler from gathering new profiling information.", 72, "W:\\4ed\\code\\custom\\4coder_profile.cpp", 37, 219 }, { PROC_LINKS(profile_enable, 0), false, "profile_enable", 14, "Allow 4coder's self profiler to gather new profiling information.", 65, "W:\\4ed\\code\\custom\\4coder_profile.cpp", 37, 212 }, { PROC_LINKS(profile_inspect, 0), true, "profile_inspect", 15, "Inspect all currently collected profiling information in 4coder's self profiler.", 80, "W:\\4ed\\code\\custom\\4coder_profile_inspect.cpp", 45, 886 }, -{ PROC_LINKS(project_command_lister, 0), false, "project_command_lister", 22, "Open a lister of all commands in the currently loaded project.", 62, "W:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 1334 }, -{ PROC_LINKS(project_fkey_command, 0), false, "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, "W:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 918 }, -{ PROC_LINKS(project_go_to_root_directory, 0), false, "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, "W:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 944 }, +{ PROC_LINKS(project_command_lister, 0), false, "project_command_lister", 22, "Open a lister of all commands in the currently loaded project.", 62, "W:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 1337 }, +{ PROC_LINKS(project_fkey_command, 0), false, "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, "W:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 921 }, +{ PROC_LINKS(project_go_to_root_directory, 0), false, "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, "W:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 947 }, { PROC_LINKS(query_replace, 0), false, "query_replace", 13, "Queries the user for two strings, and incrementally replaces every occurence of the first string with the second string.", 120, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1282 }, { PROC_LINKS(query_replace_identifier, 0), false, "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, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1303 }, { PROC_LINKS(query_replace_selection, 0), false, "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, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 1319 }, @@ -477,10 +477,10 @@ static Command_Metadata fcoder_metacmd_table[250] = { { PROC_LINKS(set_mark, 0), false, "set_mark", 8, "Sets the mark to the current position of the cursor.", 52, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 115 }, { PROC_LINKS(set_mode_to_notepad_like, 0), false, "set_mode_to_notepad_like", 24, "Sets the edit mode to Notepad like.", 35, "W:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 499 }, { PROC_LINKS(set_mode_to_original, 0), false, "set_mode_to_original", 20, "Sets the edit mode to 4coder original.", 38, "W:\\4ed\\code\\custom\\4coder_default_framework.cpp", 47, 493 }, -{ PROC_LINKS(setup_build_bat, 0), false, "setup_build_bat", 15, "Queries the user for several configuration options and initializes a new build batch script.", 92, "W:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 1286 }, -{ PROC_LINKS(setup_build_bat_and_sh, 0), false, "setup_build_bat_and_sh", 22, "Queries the user for several configuration options and initializes a new build batch script.", 92, "W:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 1298 }, -{ PROC_LINKS(setup_build_sh, 0), false, "setup_build_sh", 14, "Queries the user for several configuration options and initializes a new build shell script.", 92, "W:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 1292 }, -{ PROC_LINKS(setup_new_project, 0), false, "setup_new_project", 17, "Queries the user for several configuration options and initializes a new 4coder project with build scripts for every OS.", 120, "W:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 1279 }, +{ PROC_LINKS(setup_build_bat, 0), false, "setup_build_bat", 15, "Queries the user for several configuration options and initializes a new build batch script.", 92, "W:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 1289 }, +{ PROC_LINKS(setup_build_bat_and_sh, 0), false, "setup_build_bat_and_sh", 22, "Queries the user for several configuration options and initializes a new build batch script.", 92, "W:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 1301 }, +{ PROC_LINKS(setup_build_sh, 0), false, "setup_build_sh", 14, "Queries the user for several configuration options and initializes a new build shell script.", 92, "W:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 1295 }, +{ PROC_LINKS(setup_new_project, 0), false, "setup_new_project", 17, "Queries the user for several configuration options and initializes a new 4coder project with build scripts for every OS.", 120, "W:\\4ed\\code\\custom\\4coder_project_commands.cpp", 46, 1282 }, { PROC_LINKS(show_filebar, 0), false, "show_filebar", 12, "Sets the current view to show it's filebar.", 43, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 697 }, { PROC_LINKS(show_scrollbar, 0), false, "show_scrollbar", 14, "Sets the current view to show it's scrollbar.", 45, "W:\\4ed\\code\\custom\\4coder_base_commands.cpp", 43, 683 }, { PROC_LINKS(show_the_log_graph, 0), true, "show_the_log_graph", 18, "Parses *log* and displays the 'log graph' UI", 44, "W:\\4ed\\code\\custom\\4coder_log_parser.cpp", 40, 991 },