buffer seek delimiter api
This commit is contained in:
parent
c1b0521e81
commit
b86407bdb9
|
@ -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{
|
||||
|
|
25
4ed.cpp
25
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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue