From 9a59958006010461bc96e6df91931e1bab698726 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Tue, 23 Feb 2016 10:23:45 -0500 Subject: [PATCH] new get buffer api --- 4coder_custom.cpp | 6 +++ 4coder_custom.h | 23 +++++++-- 4coder_helper.h | 3 ++ 4ed.cpp | 129 ++++++++++++++++++++++++++++++++++------------ 4ed_file.cpp | 2 +- vc120.pdb | Bin 102400 -> 102400 bytes 6 files changed, 127 insertions(+), 36 deletions(-) diff --git a/4coder_custom.cpp b/4coder_custom.cpp index 801afd79..9205d4d9 100644 --- a/4coder_custom.cpp +++ b/4coder_custom.cpp @@ -5,6 +5,12 @@ #define FCPP_STRING_IMPLEMENTATION #include "4coder_string.h" +// NOTE(allen): See exec_command and surrounding code in 4coder_helper.h +// to decide whether you want macro translations, without them you will +// have to manipulate the command and parameter stack through +// "app->" which may be more or less clear depending on your use. +#define DisableMacroTranslations 0 + #include "4coder_custom.h" #include "4coder_helper.h" diff --git a/4coder_custom.h b/4coder_custom.h index 01e54696..600ac374 100644 --- a/4coder_custom.h +++ b/4coder_custom.h @@ -220,6 +220,7 @@ struct Buffer_Summary{ // NOTE(allen): None of these members nor any of the data pointed to // by these members should be modified, I would have made them const... // but that actually causes problems for C++ reasons. + int found_buffer; int file_id; int size; @@ -259,31 +260,47 @@ extern "C"{ #define PUSH_MEMORY_SIG(name) char* name(void *cmd_context, int len) #define EXECUTE_COMMAND_SIG(name) void name(void *cmd_context, int command_id) #define CLEAR_PARAMETERS_SIG(name) void name(void *cmd_context) -#define GET_ACTIVE_BUFFER_SIG(name) Buffer_Summary name(void *cmd_context) #define DIRECTORY_GET_HOT_SIG(name) int name(void *cmd_context, char *buffer, int max) #define DIRECTORY_HAS_FILE_SIG(name) int name(String dir, char *filename) #define DIRECTORY_CD_SIG(name) int name(String *dir, char *rel_path) +#define GET_BUFFER_MAX_INDEX_SIG(name) int name(void *cmd_context) +#define GET_BUFFER_SIG(name) Buffer_Summary name(void *cmd_context, int index) +#define GET_ACTIVE_BUFFER_SIG(name) Buffer_Summary name(void *cmd_context) +#define GET_BUFFER_BY_NAME(name) Buffer_Summary name(void *cmd_context, String filename) + extern "C"{ typedef EXECUTE_COMMAND_SIG(Exec_Command_Function); typedef PUSH_PARAMETER_SIG(Push_Parameter_Function); typedef PUSH_MEMORY_SIG(Push_Memory_Function); typedef CLEAR_PARAMETERS_SIG(Clear_Parameters_Function); - typedef GET_ACTIVE_BUFFER_SIG(Get_Active_Buffer_Function); typedef DIRECTORY_GET_HOT_SIG(Directory_Get_Hot); typedef DIRECTORY_HAS_FILE_SIG(Directory_Has_File); typedef DIRECTORY_CD_SIG(Directory_CD); + + typedef GET_BUFFER_MAX_INDEX_SIG(Get_Buffer_Max_Index_Function); + typedef GET_BUFFER_SIG(Get_Buffer_Function); + typedef GET_ACTIVE_BUFFER_SIG(Get_Active_Buffer_Function); + typedef GET_BUFFER_BY_NAME(Get_Buffer_By_Name_Function); } struct Application_Links{ + // Command exectuion Exec_Command_Function *exec_command_keep_stack; Push_Parameter_Function *push_parameter; Push_Memory_Function *push_memory; Clear_Parameters_Function *clear_parameters; - Get_Active_Buffer_Function *get_active_buffer; + + // File system navigation Directory_Get_Hot *directory_get_hot; Directory_Has_File *directory_has_file; Directory_CD *directory_cd; + + // Buffer manipulation + Get_Buffer_Max_Index_Function *get_buffer_max_index; + Get_Buffer_Function *get_buffer; + Get_Active_Buffer_Function *get_active_buffer; + Get_Buffer_By_Name_Function *get_buffer_by_name; }; struct Custom_API{ diff --git a/4coder_helper.h b/4coder_helper.h index db6a9847..9236ec77 100644 --- a/4coder_helper.h +++ b/4coder_helper.h @@ -242,6 +242,8 @@ push_directory(Application_Links *app, void *cmd_context){ #define dir_string(d) ((d).str), ((d).size) +#if DisableMacroTranslations == 0 + inline void exec_command_(Application_Links *app, void *cmd_context, Command_ID id){ app->exec_command_keep_stack(cmd_context, id); @@ -260,4 +262,5 @@ exec_command_(Application_Links *app, void *cmd_context, Custom_Command_Function #define exec_command(cmd_context, cmd) exec_command_(app, cmd_context, cmd) +#endif diff --git a/4ed.cpp b/4ed.cpp index 210c2dc3..8fa55f1a 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -238,18 +238,17 @@ COMMAND_DECL(write_character){ USE_LAYOUT(layout); USE_MEM(mem); - u8 character = (u8)command->key.character; - char str_space[2]; - String string = make_string(str_space, 2); - str_space[0] = character; - string.size = 1; - - i32 pos; - pos = view->cursor.pos; - i32 next_cursor_pos = view->cursor.pos + string.size; - view_replace_range(system, mem, view, layout, pos, pos, string.str, string.size, next_cursor_pos); - view_cursor_move(view, next_cursor_pos); - file->state.cursor_pos = view->cursor.pos; + char character; + i32 pos, next_cursor_pos; + + character = command->key.character; + if (character != 0){ + pos = view->cursor.pos; + next_cursor_pos = view->cursor.pos + 1; + view_replace_range(system, mem, view, layout, pos, pos, &character, 1, next_cursor_pos); + view_cursor_move(view, next_cursor_pos); + file->state.cursor_pos = view->cursor.pos; + } } COMMAND_DECL(seek_whitespace_right){ @@ -1681,7 +1680,7 @@ COMMAND_DECL(cursor_mark_swap){ REQ_FILE_VIEW(view); i32 pos = view->cursor.pos; - view->cursor = view_compute_cursor_from_pos(view, view->mark); + view_cursor_move(view, view->mark); view->mark = pos; } @@ -2010,6 +2009,22 @@ COMPOSE_DECL(compose_write_auto_tab_line){ globalvar Command_Function command_table[cmdid_count]; +internal void +fill_buffer_summary(Buffer_Summary *buffer, Editing_File *file, Working_Set *working_set){ + buffer->found_buffer = 1; + buffer->file_id = (int)(file - working_set->files); + buffer->size = file->state.buffer.size; + buffer->file_cursor_pos = file->state.cursor_pos; + + buffer->file_name_len = file->name.source_path.size; + buffer->buffer_name_len = file->name.live_name.size; + buffer->file_name = file->name.source_path.str; + buffer->buffer_name = file->name.live_name.str; + + buffer->is_lexed = file->settings.tokens_exist; + buffer->map_id = file->settings.base_map_id; +} + extern "C"{ EXECUTE_COMMAND_SIG(external_exec_command_keep_stack){ Command_Data *cmd = (Command_Data*)cmd_context; @@ -2049,34 +2064,79 @@ extern "C"{ cmd->part.pos = 0; } - GET_ACTIVE_BUFFER_SIG(external_get_active_buffer){ + GET_BUFFER_MAX_INDEX_SIG(external_get_buffer_max_index){ Command_Data *cmd = (Command_Data*)cmd_context; + Working_Set *working_set; + int max; + working_set = cmd->working_set; + max = working_set->file_index_count; + return(max); + } + + GET_BUFFER_SIG(external_get_buffer){ + Command_Data *cmd = (Command_Data*)cmd_context; + Editing_File *file; + Working_Set *working_set; + int max; Buffer_Summary buffer = {}; - File_View *view = view_to_file_view(cmd->view); - if (view){ - Editing_File *file = view->file; - if (file && !file->state.is_dummy){ + working_set = cmd->working_set; + max = working_set->file_index_count; + + if (index >= 0 && index < max){ + file = working_set->files + index; + if (!file->state.is_dummy && file_is_ready(file)){ #if BUFFER_EXPERIMENT_SCALPEL <= 0 - Working_Set *working_set = cmd->working_set; - buffer.file_id = (int)(file - working_set->files); - buffer.size = file->state.buffer.size; - buffer.file_cursor_pos = file->state.cursor_pos; - - buffer.file_name_len = file->name.source_path.size; - buffer.buffer_name_len = file->name.live_name.size; - buffer.file_name = file->name.source_path.str; - buffer.buffer_name = file->name.live_name.str; - - buffer.is_lexed = file->settings.tokens_exist; - buffer.map_id = file->settings.base_map_id; + fill_buffer_summary(&buffer, file, working_set); #endif } } return(buffer); } - + + GET_ACTIVE_BUFFER_SIG(external_get_active_buffer){ + Command_Data *cmd = (Command_Data*)cmd_context; + File_View *view; + Editing_File *file; + Working_Set *working_set; + Buffer_Summary buffer = {}; + + view = view_to_file_view(cmd->view); + if (view){ + file = view->file; + working_set = cmd->working_set; + + if (file && !file->state.is_dummy && file_is_ready(file)){ +#if BUFFER_EXPERIMENT_SCALPEL <= 0 + fill_buffer_summary(&buffer, file, working_set); +#endif + } + } + + return(buffer); + } + + GET_BUFFER_BY_NAME(external_get_buffer_by_name){ + Command_Data *cmd = (Command_Data*)cmd_context; + Editing_File *file; + Working_Set *working_set; + i32 index; + Buffer_Summary buffer = {}; + + working_set = cmd->working_set; + if (table_find(&working_set->table, filename, &index)){ + file = working_set->files + index; + if (!file->state.is_dummy && file_is_ready(file)){ +#if BUFFER_EXPERIMENT_SCALPEL <= 0 + fill_buffer_summary(&buffer, file, working_set); +#endif + } + } + + return(buffer); + } + DIRECTORY_GET_HOT_SIG(external_directory_get_hot){ Command_Data *cmd = (Command_Data*)cmd_context; Hot_Directory *hot = &cmd->vars->hot_directory; @@ -2096,10 +2156,15 @@ app_links_init(System_Functions *system){ app_links.push_parameter = external_push_parameter; app_links.push_memory = external_push_memory; app_links.clear_parameters = external_clear_parameters; - app_links.get_active_buffer = external_get_active_buffer; + app_links.directory_get_hot = external_directory_get_hot; app_links.directory_has_file = system->directory_has_file; app_links.directory_cd = system->directory_cd; + + app_links.get_buffer_max_index = external_get_buffer_max_index; + app_links.get_buffer = external_get_buffer; + app_links.get_active_buffer = external_get_active_buffer; + app_links.get_buffer_by_name = external_get_buffer_by_name; } #if FRED_INTERNAL diff --git a/4ed_file.cpp b/4ed_file.cpp index ea0c7014..3b9f083b 100644 --- a/4ed_file.cpp +++ b/4ed_file.cpp @@ -197,7 +197,7 @@ table_add(File_Table *table, String name, i32 id){ return 0; } -internal bool32 +internal b32 table_find_pos(File_Table *table, String name, i32 *index){ File_Table_Entry e; i32 i; diff --git a/vc120.pdb b/vc120.pdb index 57b9390263497adb465e017c1d6bdb6c25273856..8c19adbfc62338fa46c60e1ce6657660a67d8a4f 100644 GIT binary patch delta 1271 zcmcIkUr19?82`?_yUVV#UBxZI#FhOS*kVSD)q_oZP>FP#rk0EAb-R;+Q?nT}vKEp0 zu&1sOLDc$#QA9W|rac5gFG12%^iUAhLoZ30Jrwn@zOx-=1W_+t_&E3X{eI^=zwexL zZz5$(q>R&h3hh%ifbZbr0H4*do8i?FY(7p86y7%Q?oLTBmOh&`o3w$4#K$!tPVTB9 zy-V}$0@20gy@Kv>Er^rEwAtHAD+2_q0CpUc0zfGbfDmv1(`83DshahYX)`g*5s5tG z^hJN7=mC^Do5V*^7Yaxes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