From b86407bdb93f0a5e4146ac991ed86c2f29674154 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Tue, 23 Feb 2016 15:06:22 -0500 Subject: [PATCH] buffer seek delimiter api --- 4coder_custom.h | 19 ++++++++++++++++++- 4ed.cpp | 25 +++++++++++++++++++++++++ buffer/4coder_buffer_abstract.cpp | 20 ++++++++++++++++++++ vc120.pdb | Bin 102400 -> 102400 bytes 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/4coder_custom.h b/4coder_custom.h index c5c5cc0b..683c4839 100644 --- a/4coder_custom.h +++ b/4coder_custom.h @@ -219,7 +219,7 @@ struct Extra_Font{ 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. + // but that causes a lot problems for C++ reasons. int exists; int ready; int file_id; @@ -257,32 +257,46 @@ extern "C"{ typedef HOOK_SIG(Hook_Function); } +// Command exectuion #define PUSH_PARAMETER_SIG(name) void name(void *cmd_context, Dynamic param, Dynamic value) #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) + +// File system navigation #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) +// Buffer manipulation #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) +#define BUFFER_SEEK_DELIMITER_SIG(name) int name(void *cmd_context, Buffer_Summary *buffer, int start, char delim, int *out) +#define BUFFER_READ_RANGE_SIG(name) int name(void *cmd_context, Buffer_Summary *buffer, int start, int end, char *out) + extern "C"{ + // Command exectuion 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); + + // File system navigation typedef DIRECTORY_GET_HOT_SIG(Directory_Get_Hot); typedef DIRECTORY_HAS_FILE_SIG(Directory_Has_File); typedef DIRECTORY_CD_SIG(Directory_CD); + // Buffer manipulation 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); + + typedef BUFFER_SEEK_DELIMITER_SIG(Buffer_Seek_Delimiter_Function); + typedef BUFFER_READ_RANGE_SIG(Buffer_Read_Range_Function); } struct Application_Links{ @@ -302,6 +316,9 @@ struct Application_Links{ Get_Buffer_Function *get_buffer; Get_Active_Buffer_Function *get_active_buffer; Get_Buffer_By_Name_Function *get_buffer_by_name; + + Buffer_Seek_Delimiter_Function *buffer_seek_delimiter; + Buffer_Read_Range_Function *buffer_read_range; }; struct Custom_API{ diff --git a/4ed.cpp b/4ed.cpp index e3b66cc5..4e1a0a32 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -2138,6 +2138,31 @@ extern "C"{ return(buffer); } + BUFFER_SEEK_DELIMITER_SIG(external_buffer_seek_delimiter){ + Command_Data *cmd = (Command_Data*)cmd_context; + Editing_File *file; + Working_Set *working_set; + int result = 0; + int size; + + if (buffer->exists){ + working_set = cmd->working_set; + file = working_set->files + buffer->file_id; + if (!file->state.is_dummy && file_is_ready(file)){ + size = buffer_size(&file->state.buffer); + result = 1; + if (start < size){ + *out = buffer_seek_delimiter(&file->state.buffer, start, delim); + if (*out < 0) *out = 0; + if (*out > size) *out = size; + } + fill_buffer_summary(buffer, file, working_set); + } + } + + return(result); + } + DIRECTORY_GET_HOT_SIG(external_directory_get_hot){ Command_Data *cmd = (Command_Data*)cmd_context; Hot_Directory *hot = &cmd->vars->hot_directory; diff --git a/buffer/4coder_buffer_abstract.cpp b/buffer/4coder_buffer_abstract.cpp index 7fa8153e..ceebf940 100644 --- a/buffer/4coder_buffer_abstract.cpp +++ b/buffer/4coder_buffer_abstract.cpp @@ -89,6 +89,26 @@ buffer_count_newlines(Buffer_Type *buffer, int start, int end){ return(count); } +internal_4tech int +buffer_seek_delimiter(Buffer_Type *buffer, int pos, char delim){ + Buffer_Stringify_Type loop; + char *data; + int end, size; + + size = buffer_size(buffer); + for(loop = buffer_stringify_loop(buffer, pos, size); + buffer_stringify_good(&loop); + buffer_stringify_next(&loop)){ + end = loop.size + loop.absolute_pos; + data = loop.data - loop.absolute_pos; + for (; pos < end; ++pos){ + if (data[pos] == delim) goto double_break; + } + } + double_break: + return(pos); +} + internal_4tech int buffer_seek_whitespace_down(Buffer_Type *buffer, int pos){ Buffer_Stringify_Type loop; diff --git a/vc120.pdb b/vc120.pdb index 042e4c9a11572b9a07aa6b526051c72dc81d9b85..d124b484ce857dcb3bbc728b9c69efbb3e343f5b 100644 GIT binary patch delta 870 zcmcJN!D|yi6vn^Fbhk;mNj8>*S``+oXbCk5=ut@pAxe>oAOX?cq?x2aEg?ox33SD) zr*5Hw9&+kI6q<~+y$C({FQ}lRVlP4u^`ze7+cFUm?9B&{H^2Gj%{;zcx2?NvedXBD z;SaBXpU4M5(XWo;eub5nmxh)H0tHjX&Fz?HnNbdR>o+W9f-EIN8EzhUe$l@P_&Nd{ zp}MXCE(emd=1b!aOUpuTY-~P^fcew}3^0s>?V)4fI$+0vCavp~P2wnmrq6%|hcv&h zNcCTRJH3DP&8WVz>buLhl+FouK9b-l(Pjaqo0W=a*f)f@YL~^e+VxsfG~nxkbf>R3 zM6ql)igQ(glh6_oAW$K_AG6-Xy;SGaRH$2Toj&;bCC9TX9A6%CEPm%O-f?`I;IOti z-c%XxJb{-Md*$M4KD@AD9Gaz@T4bM&UT=V|?DfbuiZ*%UCpn6BncWy1nU6wG7Rf!G z@+|XR(vvmCmlfYq>?m$2E-AjRxUBer;+o>eif0tJ70)rGcOI=lFjz=1FlYejDXa_(AT7DYJgUNFwjPZDVq%suuE)oKEb}}fe-WMipL#169aTMeW+n2*`%$8jMBm| z6SgTZ@(8eA764i?UC@A0nAZnrHwbe8MMAb48Zh4G$0O~)c%7e7ZaZfHBc31v`AKxL Rri1?WkO0ON{L2a$6#)6QS|0!a