trimmed down custom api
This commit is contained in:
parent
ce27493fb3
commit
9ac0727d08
|
@ -11,12 +11,8 @@
|
||||||
#define GET_BUFFER_FIRST_SIG(n) Buffer_Summary n(Application_Links *app)
|
#define GET_BUFFER_FIRST_SIG(n) Buffer_Summary n(Application_Links *app)
|
||||||
#define GET_BUFFER_NEXT_SIG(n) void n(Application_Links *app, Buffer_Summary *buffer)
|
#define GET_BUFFER_NEXT_SIG(n) void n(Application_Links *app, Buffer_Summary *buffer)
|
||||||
#define GET_BUFFER_SIG(n) Buffer_Summary n(Application_Links *app, int index)
|
#define GET_BUFFER_SIG(n) Buffer_Summary n(Application_Links *app, int index)
|
||||||
#define GET_ACTIVE_BUFFER_SIG(n) Buffer_Summary n(Application_Links *app)
|
|
||||||
#define GET_PARAMETER_BUFFER_SIG(n) Buffer_Summary n(Application_Links *app, int param_index)
|
#define GET_PARAMETER_BUFFER_SIG(n) Buffer_Summary n(Application_Links *app, int param_index)
|
||||||
#define GET_BUFFER_BY_NAME_SIG(n) Buffer_Summary n(Application_Links *app, char *filename, int len)
|
#define GET_BUFFER_BY_NAME_SIG(n) Buffer_Summary n(Application_Links *app, char *filename, int len)
|
||||||
#define BUFFER_SEEK_DELIMITER_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int start, char delim, int seek_forward, int *out)
|
|
||||||
#define BUFFER_SEEK_STRING_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int start, char *str, int len, int seek_forward, int *out)
|
|
||||||
#define BUFFER_SEEK_STRING_INSENSITIVE_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int start, char *str, int len, int seek_forward, int *out)
|
|
||||||
#define REFRESH_BUFFER_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer)
|
#define REFRESH_BUFFER_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer)
|
||||||
#define BUFFER_READ_RANGE_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *out)
|
#define BUFFER_READ_RANGE_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *out)
|
||||||
#define BUFFER_REPLACE_RANGE_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *str, int len)
|
#define BUFFER_REPLACE_RANGE_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *str, int len)
|
||||||
|
@ -56,12 +52,8 @@ extern "C"{
|
||||||
typedef GET_BUFFER_FIRST_SIG(Get_Buffer_First_Function);
|
typedef GET_BUFFER_FIRST_SIG(Get_Buffer_First_Function);
|
||||||
typedef GET_BUFFER_NEXT_SIG(Get_Buffer_Next_Function);
|
typedef GET_BUFFER_NEXT_SIG(Get_Buffer_Next_Function);
|
||||||
typedef GET_BUFFER_SIG(Get_Buffer_Function);
|
typedef GET_BUFFER_SIG(Get_Buffer_Function);
|
||||||
typedef GET_ACTIVE_BUFFER_SIG(Get_Active_Buffer_Function);
|
|
||||||
typedef GET_PARAMETER_BUFFER_SIG(Get_Parameter_Buffer_Function);
|
typedef GET_PARAMETER_BUFFER_SIG(Get_Parameter_Buffer_Function);
|
||||||
typedef GET_BUFFER_BY_NAME_SIG(Get_Buffer_By_Name_Function);
|
typedef GET_BUFFER_BY_NAME_SIG(Get_Buffer_By_Name_Function);
|
||||||
typedef BUFFER_SEEK_DELIMITER_SIG(Buffer_Seek_Delimiter_Function);
|
|
||||||
typedef BUFFER_SEEK_STRING_SIG(Buffer_Seek_String_Function);
|
|
||||||
typedef BUFFER_SEEK_STRING_INSENSITIVE_SIG(Buffer_Seek_String_Insensitive_Function);
|
|
||||||
typedef REFRESH_BUFFER_SIG(Refresh_Buffer_Function);
|
typedef REFRESH_BUFFER_SIG(Refresh_Buffer_Function);
|
||||||
typedef BUFFER_READ_RANGE_SIG(Buffer_Read_Range_Function);
|
typedef BUFFER_READ_RANGE_SIG(Buffer_Read_Range_Function);
|
||||||
typedef BUFFER_REPLACE_RANGE_SIG(Buffer_Replace_Range_Function);
|
typedef BUFFER_REPLACE_RANGE_SIG(Buffer_Replace_Range_Function);
|
||||||
|
@ -104,12 +96,8 @@ struct Application_Links{
|
||||||
Get_Buffer_First_Function *get_buffer_first;
|
Get_Buffer_First_Function *get_buffer_first;
|
||||||
Get_Buffer_Next_Function *get_buffer_next;
|
Get_Buffer_Next_Function *get_buffer_next;
|
||||||
Get_Buffer_Function *get_buffer;
|
Get_Buffer_Function *get_buffer;
|
||||||
Get_Active_Buffer_Function *get_active_buffer;
|
|
||||||
Get_Parameter_Buffer_Function *get_parameter_buffer;
|
Get_Parameter_Buffer_Function *get_parameter_buffer;
|
||||||
Get_Buffer_By_Name_Function *get_buffer_by_name;
|
Get_Buffer_By_Name_Function *get_buffer_by_name;
|
||||||
Buffer_Seek_Delimiter_Function *buffer_seek_delimiter;
|
|
||||||
Buffer_Seek_String_Function *buffer_seek_string;
|
|
||||||
Buffer_Seek_String_Insensitive_Function *buffer_seek_string_insensitive;
|
|
||||||
Refresh_Buffer_Function *refresh_buffer;
|
Refresh_Buffer_Function *refresh_buffer;
|
||||||
Buffer_Read_Range_Function *buffer_read_range;
|
Buffer_Read_Range_Function *buffer_read_range;
|
||||||
Buffer_Replace_Range_Function *buffer_replace_range;
|
Buffer_Replace_Range_Function *buffer_replace_range;
|
||||||
|
|
|
@ -4,14 +4,13 @@
|
||||||
#define FCPP_STRING_IMPLEMENTATION
|
#define FCPP_STRING_IMPLEMENTATION
|
||||||
#include "4coder_string.h"
|
#include "4coder_string.h"
|
||||||
|
|
||||||
#define UseInterfacesThatArePhasingOut 0
|
|
||||||
#include "4coder_helper.h"
|
#include "4coder_helper.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
static void
|
static void
|
||||||
write_string(Application_Links *app, String string){
|
write_string(Application_Links *app, String string){
|
||||||
Buffer_Summary buffer = app->get_active_buffer(app);
|
Buffer_Summary buffer = get_active_buffer(app);
|
||||||
app->buffer_replace_range(app, &buffer, buffer.buffer_cursor_pos, buffer.buffer_cursor_pos, string.str, string.size);
|
app->buffer_replace_range(app, &buffer, buffer.buffer_cursor_pos, buffer.buffer_cursor_pos, string.str, string.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +91,7 @@ CUSTOM_COMMAND_SIG(if0_off){
|
||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
view = app->get_active_view(app);
|
view = app->get_active_view(app);
|
||||||
buffer = app->get_active_buffer(app);
|
buffer = app->get_buffer(app, view.buffer_id);
|
||||||
|
|
||||||
range = get_range(&view);
|
range = get_range(&view);
|
||||||
pos = range.min;
|
pos = range.min;
|
||||||
|
@ -161,8 +160,8 @@ CUSTOM_COMMAND_SIG(open_file_in_quotes){
|
||||||
view = app->get_active_view(app);
|
view = app->get_active_view(app);
|
||||||
buffer = app->get_buffer(app, view.buffer_id);
|
buffer = app->get_buffer(app, view.buffer_id);
|
||||||
pos = view.cursor.pos;
|
pos = view.cursor.pos;
|
||||||
app->buffer_seek_delimiter(app, &buffer, pos, '"', 1, &end);
|
buffer_seek_delimiter_forward(app, &buffer, pos, '"', &end);
|
||||||
app->buffer_seek_delimiter(app, &buffer, pos, '"', 0, &start);
|
buffer_seek_delimiter_backward(app, &buffer, pos, '"', &start);
|
||||||
|
|
||||||
++start;
|
++start;
|
||||||
size = end - start;
|
size = end - start;
|
||||||
|
@ -265,9 +264,9 @@ isearch(Application_Links *app, int start_reversed){
|
||||||
int step_backward = 0;
|
int step_backward = 0;
|
||||||
|
|
||||||
if (CommandEqual(in.command, search) ||
|
if (CommandEqual(in.command, search) ||
|
||||||
in.key.keycode == key_page_down || in.key.keycode == key_down) step_forward = 1;
|
in.key.keycode == key_page_down || in.key.keycode == key_down) step_forward = 1;
|
||||||
if (CommandEqual(in.command, reverse_search) ||
|
if (CommandEqual(in.command, reverse_search) ||
|
||||||
in.key.keycode == key_page_up || in.key.keycode == key_up) step_backward = 1;
|
in.key.keycode == key_page_up || in.key.keycode == key_up) step_backward = 1;
|
||||||
|
|
||||||
int start_pos = pos;
|
int start_pos = pos;
|
||||||
if (step_forward && reverse){
|
if (step_forward && reverse){
|
||||||
|
@ -286,13 +285,14 @@ isearch(Application_Links *app, int start_reversed){
|
||||||
if (in.key.keycode != key_back){
|
if (in.key.keycode != key_back){
|
||||||
int new_pos;
|
int new_pos;
|
||||||
if (reverse){
|
if (reverse){
|
||||||
// TODO(allen): Need a good way to allow users to implement seeks for themselves.
|
buffer_seek_string_insensitive_backward(app, &buffer, start_pos - 1,
|
||||||
app->buffer_seek_string_insensitive(app, &buffer, start_pos - 1, bar.string.str, bar.string.size, 0, &new_pos);
|
bar.string.str, bar.string.size, &new_pos);
|
||||||
if (new_pos >= 0){
|
if (new_pos >= 0){
|
||||||
if (step_backward){
|
if (step_backward){
|
||||||
pos = new_pos;
|
pos = new_pos;
|
||||||
start_pos = new_pos;
|
start_pos = new_pos;
|
||||||
app->buffer_seek_string_insensitive(app, &buffer, start_pos - 1, bar.string.str, bar.string.size, 0, &new_pos);
|
buffer_seek_string_insensitive_backward(app, &buffer, start_pos - 1,
|
||||||
|
bar.string.str, bar.string.size, &new_pos);
|
||||||
if (new_pos < 0) new_pos = start_pos;
|
if (new_pos < 0) new_pos = start_pos;
|
||||||
}
|
}
|
||||||
match.start = new_pos;
|
match.start = new_pos;
|
||||||
|
@ -300,12 +300,14 @@ isearch(Application_Links *app, int start_reversed){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
app->buffer_seek_string_insensitive(app, &buffer, start_pos + 1, bar.string.str, bar.string.size, 1, &new_pos);
|
buffer_seek_string_insensitive_forward(app, &buffer, start_pos + 1,
|
||||||
|
bar.string.str, bar.string.size, &new_pos);
|
||||||
if (new_pos < buffer.size){
|
if (new_pos < buffer.size){
|
||||||
if (step_forward){
|
if (step_forward){
|
||||||
pos = new_pos;
|
pos = new_pos;
|
||||||
start_pos = new_pos;
|
start_pos = new_pos;
|
||||||
app->buffer_seek_string_insensitive(app, &buffer, start_pos + 1, bar.string.str, bar.string.size, 1, &new_pos);
|
buffer_seek_string_insensitive_forward(app, &buffer, start_pos + 1,
|
||||||
|
bar.string.str, bar.string.size, &new_pos);
|
||||||
if (new_pos >= buffer.size) new_pos = start_pos;
|
if (new_pos >= buffer.size) new_pos = start_pos;
|
||||||
}
|
}
|
||||||
match.start = new_pos;
|
match.start = new_pos;
|
||||||
|
@ -365,14 +367,14 @@ CUSTOM_COMMAND_SIG(replace_in_range){
|
||||||
|
|
||||||
int pos, new_pos;
|
int pos, new_pos;
|
||||||
pos = range.min;
|
pos = range.min;
|
||||||
app->buffer_seek_string(app, &buffer, pos, r.str, r.size, 1, &new_pos);
|
buffer_seek_string_forward(app, &buffer, pos, r.str, r.size, &new_pos);
|
||||||
|
|
||||||
while (new_pos + r.size <= range.end){
|
while (new_pos + r.size <= range.end){
|
||||||
app->buffer_replace_range(app, &buffer, new_pos, new_pos + r.size, w.str, w.size);
|
app->buffer_replace_range(app, &buffer, new_pos, new_pos + r.size, w.str, w.size);
|
||||||
app->refresh_view(app, &view);
|
app->refresh_view(app, &view);
|
||||||
range = get_range(&view);
|
range = get_range(&view);
|
||||||
pos = new_pos + w.size;
|
pos = new_pos + w.size;
|
||||||
app->buffer_seek_string(app, &buffer, pos, r.str, r.size, 1, &new_pos);
|
buffer_seek_string_forward(app, &buffer, pos, r.str, r.size, &new_pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,7 +412,7 @@ CUSTOM_COMMAND_SIG(query_replace){
|
||||||
buffer = app->get_buffer(app, view.buffer_id);
|
buffer = app->get_buffer(app, view.buffer_id);
|
||||||
|
|
||||||
pos = view.cursor.pos;
|
pos = view.cursor.pos;
|
||||||
app->buffer_seek_string(app, &buffer, pos, r.str, r.size, 1, &new_pos);
|
buffer_seek_string_forward(app, &buffer, pos, r.str, r.size, &new_pos);
|
||||||
|
|
||||||
User_Input in = {0};
|
User_Input in = {0};
|
||||||
while (new_pos < buffer.size){
|
while (new_pos < buffer.size){
|
||||||
|
@ -428,7 +430,7 @@ CUSTOM_COMMAND_SIG(query_replace){
|
||||||
pos = match.max;
|
pos = match.max;
|
||||||
}
|
}
|
||||||
|
|
||||||
app->buffer_seek_string(app, &buffer, pos, r.str, r.size, 1, &new_pos);
|
buffer_seek_string_forward(app, &buffer, pos, r.str, r.size, &new_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
app->view_set_highlight(app, &view, 0, 0, 0);
|
app->view_set_highlight(app, &view, 0, 0, 0);
|
||||||
|
@ -663,7 +665,7 @@ CUSTOM_COMMAND_SIG(auto_tab_line_at_cursor){
|
||||||
}
|
}
|
||||||
|
|
||||||
CUSTOM_COMMAND_SIG(auto_tab_whole_file){
|
CUSTOM_COMMAND_SIG(auto_tab_whole_file){
|
||||||
Buffer_Summary buffer = app->get_active_buffer(app);
|
Buffer_Summary buffer = get_active_buffer(app);
|
||||||
push_parameter(app, par_range_start, 0);
|
push_parameter(app, par_range_start, 0);
|
||||||
push_parameter(app, par_range_end, buffer.size);
|
push_parameter(app, par_range_end, buffer.size);
|
||||||
exec_command(app, cmdid_auto_tab_range);
|
exec_command(app, cmdid_auto_tab_range);
|
||||||
|
|
358
4coder_helper.h
358
4coder_helper.h
|
@ -386,3 +386,361 @@ query_user_number(Application_Links *app, Query_Bar *bar){
|
||||||
}
|
}
|
||||||
|
|
||||||
inline String empty_string() {String Result = {}; return(Result);}
|
inline String empty_string() {String Result = {}; return(Result);}
|
||||||
|
|
||||||
|
inline Buffer_Summary
|
||||||
|
get_active_buffer(Application_Links *app){
|
||||||
|
View_Summary view = app->get_active_view(app);
|
||||||
|
Buffer_Summary buffer = app->get_buffer(app, view.buffer_id);
|
||||||
|
return(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct Stream_Chunk{
|
||||||
|
Application_Links *app;
|
||||||
|
Buffer_Summary *buffer;
|
||||||
|
|
||||||
|
char *base_data;
|
||||||
|
int start, end;
|
||||||
|
int data_size;
|
||||||
|
|
||||||
|
char *data;
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
round_down(int x, int b){
|
||||||
|
int r = 0;
|
||||||
|
if (x >= 0){
|
||||||
|
r = x - (x % b);
|
||||||
|
}
|
||||||
|
return(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
round_up(int x, int b){
|
||||||
|
int r = 0;
|
||||||
|
if (x >= 0){
|
||||||
|
r = x - (x % b) + b;
|
||||||
|
}
|
||||||
|
return(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
init_stream_chunk(Stream_Chunk *chunk,
|
||||||
|
Application_Links *app, Buffer_Summary *buffer,
|
||||||
|
int pos, char *data, int size){
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
app->refresh_buffer(app, buffer);
|
||||||
|
if (pos >= 0 && pos < buffer->size && size > 0){
|
||||||
|
result = 1;
|
||||||
|
chunk->app = app;
|
||||||
|
chunk->buffer = buffer;
|
||||||
|
chunk->base_data = data;
|
||||||
|
chunk->data_size = size;
|
||||||
|
chunk->start = round_down(pos, size);
|
||||||
|
chunk->end = round_up(pos, size);
|
||||||
|
if (chunk->end > buffer->size){
|
||||||
|
chunk->end = buffer->size;
|
||||||
|
}
|
||||||
|
app->buffer_read_range(app, buffer, chunk->start, chunk->end, chunk->base_data);
|
||||||
|
chunk->data = chunk->base_data - chunk->start;
|
||||||
|
}
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
forward_stream_chunk(Stream_Chunk *chunk){
|
||||||
|
Application_Links *app = chunk->app;
|
||||||
|
Buffer_Summary *buffer = chunk->buffer;
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
app->refresh_buffer(app, buffer);
|
||||||
|
if (chunk->end < buffer->size){
|
||||||
|
result = 1;
|
||||||
|
chunk->start = chunk->end;
|
||||||
|
chunk->end += chunk->data_size;
|
||||||
|
if (chunk->end > buffer->size){
|
||||||
|
chunk->end = buffer->size;
|
||||||
|
}
|
||||||
|
app->buffer_read_range(app, buffer, chunk->start, chunk->end, chunk->base_data);
|
||||||
|
chunk->data = chunk->base_data - chunk->start;
|
||||||
|
}
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
backward_stream_chunk(Stream_Chunk *chunk){
|
||||||
|
Application_Links *app = chunk->app;
|
||||||
|
Buffer_Summary *buffer = chunk->buffer;
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
app->refresh_buffer(app, buffer);
|
||||||
|
if (chunk->start > 0){
|
||||||
|
result = 1;
|
||||||
|
chunk->end = chunk->start;
|
||||||
|
chunk->start -= chunk->data_size;
|
||||||
|
if (chunk->start < 0){
|
||||||
|
chunk->start = 0;
|
||||||
|
}
|
||||||
|
app->buffer_read_range(app, buffer, chunk->start, chunk->end, chunk->base_data);
|
||||||
|
chunk->data = chunk->base_data - chunk->start;
|
||||||
|
}
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
buffer_seek_delimiter_forward(Application_Links *app, Buffer_Summary *buffer,
|
||||||
|
int pos, char delim, int *result){
|
||||||
|
if (buffer->exists){
|
||||||
|
char chunk[1024];
|
||||||
|
int size = sizeof(chunk);
|
||||||
|
Stream_Chunk stream = {0};
|
||||||
|
|
||||||
|
if (init_stream_chunk(&stream, app, buffer, pos, chunk, size)){
|
||||||
|
int still_looping = 1;
|
||||||
|
do{
|
||||||
|
for(; pos < stream.end; ++pos){
|
||||||
|
char at_pos = stream.data[pos];
|
||||||
|
if (at_pos == delim){
|
||||||
|
*result = pos;
|
||||||
|
goto finished;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
still_looping = forward_stream_chunk(&stream);
|
||||||
|
}while (still_looping);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*result = buffer->size;
|
||||||
|
|
||||||
|
finished:;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
buffer_seek_delimiter_backward(Application_Links *app, Buffer_Summary *buffer,
|
||||||
|
int pos, char delim, int *result){
|
||||||
|
if (buffer->exists){
|
||||||
|
char chunk[1024];
|
||||||
|
int size = sizeof(chunk);
|
||||||
|
Stream_Chunk stream = {0};
|
||||||
|
|
||||||
|
if (init_stream_chunk(&stream, app, buffer, pos, chunk, size)){
|
||||||
|
int still_looping = 1;
|
||||||
|
do{
|
||||||
|
for(; pos >= stream.start; --pos){
|
||||||
|
char at_pos = stream.data[pos];
|
||||||
|
if (at_pos == delim){
|
||||||
|
*result = pos;
|
||||||
|
goto finished;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
still_looping = backward_stream_chunk(&stream);
|
||||||
|
}while (still_looping);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*result = 0;
|
||||||
|
|
||||||
|
finished:;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(allen): This duplication is driving me crazy... I've gotta
|
||||||
|
// upgrade the meta programming system another level.
|
||||||
|
|
||||||
|
// NOTE(allen): This is limitted to a string size of 512.
|
||||||
|
// You can push it up or do something more clever by just
|
||||||
|
// replacing char read_buffer[512]; with more memory.
|
||||||
|
void
|
||||||
|
buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer,
|
||||||
|
int pos, char *str, int size, int *result){
|
||||||
|
char read_buffer[512];
|
||||||
|
char chunk[1024];
|
||||||
|
int chunk_size = sizeof(chunk);
|
||||||
|
Stream_Chunk stream = {0};
|
||||||
|
|
||||||
|
if (size <= 0){
|
||||||
|
*result = pos;
|
||||||
|
}
|
||||||
|
else if (size > sizeof(read_buffer)){
|
||||||
|
*result = pos;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if (buffer->exists){
|
||||||
|
String read_str = make_fixed_width_string(read_buffer);
|
||||||
|
String needle_str = make_string(str, size);
|
||||||
|
char first_char = str[0];
|
||||||
|
|
||||||
|
read_str.size = size;
|
||||||
|
|
||||||
|
if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){
|
||||||
|
int still_looping = 1;
|
||||||
|
do{
|
||||||
|
for(; pos < stream.end; ++pos){
|
||||||
|
char at_pos = stream.data[pos];
|
||||||
|
if (at_pos == first_char){
|
||||||
|
app->buffer_read_range(app, buffer, pos, pos+size, read_buffer);
|
||||||
|
if (match(needle_str, read_str)){
|
||||||
|
*result = pos;
|
||||||
|
goto finished;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
still_looping = forward_stream_chunk(&stream);
|
||||||
|
}while (still_looping);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*result = buffer->size;
|
||||||
|
|
||||||
|
finished:;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE(allen): This is limitted to a string size of 512.
|
||||||
|
// You can push it up or do something more clever by just
|
||||||
|
// replacing char read_buffer[512]; with more memory.
|
||||||
|
void
|
||||||
|
buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer,
|
||||||
|
int pos, char *str, int size, int *result){
|
||||||
|
char read_buffer[512];
|
||||||
|
char chunk[1024];
|
||||||
|
int chunk_size = sizeof(chunk);
|
||||||
|
Stream_Chunk stream = {0};
|
||||||
|
|
||||||
|
if (size <= 0){
|
||||||
|
*result = 0;
|
||||||
|
}
|
||||||
|
else if (size > sizeof(read_buffer)){
|
||||||
|
*result = 0;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if (buffer->exists){
|
||||||
|
String read_str = make_fixed_width_string(read_buffer);
|
||||||
|
String needle_str = make_string(str, size);
|
||||||
|
char first_char = str[0];
|
||||||
|
|
||||||
|
read_str.size = size;
|
||||||
|
|
||||||
|
if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){
|
||||||
|
int still_looping = 1;
|
||||||
|
do{
|
||||||
|
for(; pos >= stream.start; --pos){
|
||||||
|
char at_pos = stream.data[pos];
|
||||||
|
if (at_pos == first_char){
|
||||||
|
app->buffer_read_range(app, buffer, pos, pos+size, read_buffer);
|
||||||
|
if (match(needle_str, read_str)){
|
||||||
|
*result = pos;
|
||||||
|
goto finished;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
still_looping = backward_stream_chunk(&stream);
|
||||||
|
}while (still_looping);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*result = 0;
|
||||||
|
|
||||||
|
finished:;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE(allen): This is limitted to a string size of 512.
|
||||||
|
// You can push it up or do something more clever by just
|
||||||
|
// replacing char read_buffer[512]; with more memory.
|
||||||
|
void
|
||||||
|
buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *buffer,
|
||||||
|
int pos, char *str, int size, int *result){
|
||||||
|
char read_buffer[512];
|
||||||
|
char chunk[1024];
|
||||||
|
int chunk_size = sizeof(chunk);
|
||||||
|
Stream_Chunk stream = {0};
|
||||||
|
|
||||||
|
if (size <= 0){
|
||||||
|
*result = pos;
|
||||||
|
}
|
||||||
|
else if (size > sizeof(read_buffer)){
|
||||||
|
*result = pos;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if (buffer->exists){
|
||||||
|
String read_str = make_fixed_width_string(read_buffer);
|
||||||
|
String needle_str = make_string(str, size);
|
||||||
|
char first_char = char_to_upper(str[0]);
|
||||||
|
|
||||||
|
read_str.size = size;
|
||||||
|
|
||||||
|
if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){
|
||||||
|
int still_looping = 1;
|
||||||
|
do{
|
||||||
|
for(; pos < stream.end; ++pos){
|
||||||
|
char at_pos = char_to_upper(stream.data[pos]);
|
||||||
|
if (at_pos == first_char){
|
||||||
|
app->buffer_read_range(app, buffer, pos, pos+size, read_buffer);
|
||||||
|
if (match_insensitive(needle_str, read_str)){
|
||||||
|
*result = pos;
|
||||||
|
goto finished;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
still_looping = forward_stream_chunk(&stream);
|
||||||
|
}while (still_looping);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*result = buffer->size;
|
||||||
|
|
||||||
|
finished:;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE(allen): This is limitted to a string size of 512.
|
||||||
|
// You can push it up or do something more clever by just
|
||||||
|
// replacing char read_buffer[512]; with more memory.
|
||||||
|
void
|
||||||
|
buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary *buffer,
|
||||||
|
int pos, char *str, int size, int *result){
|
||||||
|
char read_buffer[512];
|
||||||
|
char chunk[1024];
|
||||||
|
int chunk_size = sizeof(chunk);
|
||||||
|
Stream_Chunk stream = {0};
|
||||||
|
|
||||||
|
if (size <= 0){
|
||||||
|
*result = -1;
|
||||||
|
}
|
||||||
|
else if (size > sizeof(read_buffer)){
|
||||||
|
*result = -1;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if (buffer->exists){
|
||||||
|
String read_str = make_fixed_width_string(read_buffer);
|
||||||
|
String needle_str = make_string(str, size);
|
||||||
|
char first_char = char_to_upper(str[0]);
|
||||||
|
|
||||||
|
read_str.size = size;
|
||||||
|
|
||||||
|
if (init_stream_chunk(&stream, app, buffer, pos, chunk, chunk_size)){
|
||||||
|
int still_looping = 1;
|
||||||
|
do{
|
||||||
|
for(; pos >= stream.start; --pos){
|
||||||
|
char at_pos = char_to_upper(stream.data[pos]);
|
||||||
|
if (at_pos == first_char){
|
||||||
|
app->buffer_read_range(app, buffer, pos, pos+size, read_buffer);
|
||||||
|
if (match_insensitive(needle_str, read_str)){
|
||||||
|
*result = pos;
|
||||||
|
goto finished;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
still_looping = backward_stream_chunk(&stream);
|
||||||
|
}while (still_looping);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*result = -1;
|
||||||
|
|
||||||
|
finished:;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -102,17 +102,17 @@ FSTRING_INLINE bool match_part(String a, char *b) { int x; return match_part
|
||||||
FSTRING_LINK bool match_part(char *a, String b);
|
FSTRING_LINK bool match_part(char *a, String b);
|
||||||
FSTRING_LINK bool match_part(String a, String b);
|
FSTRING_LINK bool match_part(String a, String b);
|
||||||
|
|
||||||
FSTRING_LINK bool match_unsensitive(char *a, char *b);
|
FSTRING_LINK bool match_insensitive(char *a, char *b);
|
||||||
FSTRING_LINK bool match_unsensitive(String a, char *b);
|
FSTRING_LINK bool match_insensitive(String a, char *b);
|
||||||
FSTRING_INLINE bool match_unsensitive(char *a, String b) { return match_unsensitive(b,a); }
|
FSTRING_INLINE bool match_insensitive(char *a, String b) { return match_insensitive(b,a); }
|
||||||
FSTRING_LINK bool match_unsensitive(String a, String b);
|
FSTRING_LINK bool match_insensitive(String a, String b);
|
||||||
|
|
||||||
FSTRING_LINK bool match_part_unsensitive(char *a, char *b, int *len);
|
FSTRING_LINK bool match_part_insensitive(char *a, char *b, int *len);
|
||||||
FSTRING_LINK bool match_part_unsensitive(String a, char *b, int *len);
|
FSTRING_LINK bool match_part_insensitive(String a, char *b, int *len);
|
||||||
FSTRING_INLINE bool match_part_unsensitive(char *a, char *b) { int x; return match_part(a,b,&x); }
|
FSTRING_INLINE bool match_part_insensitive(char *a, char *b) { int x; return match_part(a,b,&x); }
|
||||||
FSTRING_INLINE bool match_part_unsensitive(String a, char *b) { int x; return match_part(a,b,&x); }
|
FSTRING_INLINE bool match_part_insensitive(String a, char *b) { int x; return match_part(a,b,&x); }
|
||||||
FSTRING_LINK bool match_part_unsensitive(char *a, String b);
|
FSTRING_LINK bool match_part_insensitive(char *a, String b);
|
||||||
FSTRING_LINK bool match_part_unsensitive(String a, String b);
|
FSTRING_LINK bool match_part_insensitive(String a, String b);
|
||||||
|
|
||||||
FSTRING_LINK int find(char *s, int start, char c);
|
FSTRING_LINK int find(char *s, int start, char c);
|
||||||
FSTRING_LINK int find(String s, int start, char c);
|
FSTRING_LINK int find(String s, int start, char c);
|
||||||
|
@ -123,14 +123,14 @@ FSTRING_LINK int find_substr(char *s, int start, String seek);
|
||||||
FSTRING_LINK int find_substr(String s, int start, String seek);
|
FSTRING_LINK int find_substr(String s, int start, String seek);
|
||||||
FSTRING_LINK int rfind_substr(String s, int start, String seek);
|
FSTRING_LINK int rfind_substr(String s, int start, String seek);
|
||||||
|
|
||||||
FSTRING_LINK int find_substr_unsensitive(char *s, int start, String seek);
|
FSTRING_LINK int find_substr_insensitive(char *s, int start, String seek);
|
||||||
FSTRING_LINK int find_substr_unsensitive(String s, int start, String seek);
|
FSTRING_LINK int find_substr_insensitive(String s, int start, String seek);
|
||||||
|
|
||||||
FSTRING_INLINE bool has_substr(char *s, String seek) { return (s[find_substr(s, 0, seek)] != 0); }
|
FSTRING_INLINE bool has_substr(char *s, String seek) { return (s[find_substr(s, 0, seek)] != 0); }
|
||||||
FSTRING_INLINE bool has_substr(String s, String seek) { return (find_substr(s, 0, seek) < s.size); }
|
FSTRING_INLINE bool has_substr(String s, String seek) { return (find_substr(s, 0, seek) < s.size); }
|
||||||
|
|
||||||
FSTRING_INLINE bool has_substr_unsensitive(char *s, String seek) { return (s[find_substr_unsensitive(s, 0, seek)] != 0); }
|
FSTRING_INLINE bool has_substr_insensitive(char *s, String seek) { return (s[find_substr_insensitive(s, 0, seek)] != 0); }
|
||||||
FSTRING_INLINE bool has_substr_unsensitive(String s, String seek) { return (find_substr_unsensitive(s, 0, seek) < s.size); }
|
FSTRING_INLINE bool has_substr_insensitive(String s, String seek) { return (find_substr_insensitive(s, 0, seek) < s.size); }
|
||||||
|
|
||||||
FSTRING_LINK int int_to_str_size(int x);
|
FSTRING_LINK int int_to_str_size(int x);
|
||||||
FSTRING_LINK int int_to_str(int x, char *s_out);
|
FSTRING_LINK int int_to_str(int x, char *s_out);
|
||||||
|
@ -391,7 +391,7 @@ match_part(String a, String b){
|
||||||
}
|
}
|
||||||
|
|
||||||
FSTRING_LINK bool
|
FSTRING_LINK bool
|
||||||
match_unsensitive(char *a, char *b){
|
match_insensitive(char *a, char *b){
|
||||||
for (int i = 0;; ++i){
|
for (int i = 0;; ++i){
|
||||||
if (char_to_upper(a[i]) !=
|
if (char_to_upper(a[i]) !=
|
||||||
char_to_upper(b[i])){
|
char_to_upper(b[i])){
|
||||||
|
@ -404,7 +404,7 @@ match_unsensitive(char *a, char *b){
|
||||||
}
|
}
|
||||||
|
|
||||||
FSTRING_LINK bool
|
FSTRING_LINK bool
|
||||||
match_unsensitive(String a, char *b){
|
match_insensitive(String a, char *b){
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (; i < a.size; ++i){
|
for (; i < a.size; ++i){
|
||||||
if (char_to_upper(a.str[i]) !=
|
if (char_to_upper(a.str[i]) !=
|
||||||
|
@ -419,7 +419,7 @@ match_unsensitive(String a, char *b){
|
||||||
}
|
}
|
||||||
|
|
||||||
FSTRING_LINK bool
|
FSTRING_LINK bool
|
||||||
match_unsensitive(String a, String b){
|
match_insensitive(String a, String b){
|
||||||
if (a.size != b.size){
|
if (a.size != b.size){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -433,7 +433,7 @@ match_unsensitive(String a, String b){
|
||||||
}
|
}
|
||||||
|
|
||||||
FSTRING_LINK bool
|
FSTRING_LINK bool
|
||||||
match_part_unsensitive(char *a, char *b, int *len){
|
match_part_insensitive(char *a, char *b, int *len){
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; b[i] != 0; ++i){
|
for (i = 0; b[i] != 0; ++i){
|
||||||
if (char_to_upper(a[i]) != char_to_upper(b[i])){
|
if (char_to_upper(a[i]) != char_to_upper(b[i])){
|
||||||
|
@ -445,7 +445,7 @@ match_part_unsensitive(char *a, char *b, int *len){
|
||||||
}
|
}
|
||||||
|
|
||||||
FSTRING_LINK bool
|
FSTRING_LINK bool
|
||||||
match_part_unsensitive(String a, char *b, int *len){
|
match_part_insensitive(String a, char *b, int *len){
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; b[i] != 0; ++i){
|
for (i = 0; b[i] != 0; ++i){
|
||||||
if (char_to_upper(a.str[i]) != char_to_upper(b[i]) ||
|
if (char_to_upper(a.str[i]) != char_to_upper(b[i]) ||
|
||||||
|
@ -458,7 +458,7 @@ match_part_unsensitive(String a, char *b, int *len){
|
||||||
}
|
}
|
||||||
|
|
||||||
FSTRING_LINK bool
|
FSTRING_LINK bool
|
||||||
match_part_unsensitive(char *a, String b){
|
match_part_insensitive(char *a, String b){
|
||||||
for (int i = 0; i != b.size; ++i){
|
for (int i = 0; i != b.size; ++i){
|
||||||
if (char_to_upper(a[i]) != char_to_upper(b.str[i])){
|
if (char_to_upper(a[i]) != char_to_upper(b.str[i])){
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -468,7 +468,7 @@ match_part_unsensitive(char *a, String b){
|
||||||
}
|
}
|
||||||
|
|
||||||
FSTRING_LINK bool
|
FSTRING_LINK bool
|
||||||
match_part_unsensitive(String a, String b){
|
match_part_insensitive(String a, String b){
|
||||||
if (a.size < b.size){
|
if (a.size < b.size){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -602,7 +602,7 @@ rfind_substr(String str, int start, String seek){
|
||||||
}
|
}
|
||||||
|
|
||||||
FSTRING_LINK int
|
FSTRING_LINK int
|
||||||
find_substr_unsensitive(char *str, int start, String seek){
|
find_substr_insensitive(char *str, int start, String seek){
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
bool hit;
|
bool hit;
|
||||||
char a_upper, b_upper;
|
char a_upper, b_upper;
|
||||||
|
@ -630,7 +630,7 @@ find_substr_unsensitive(char *str, int start, String seek){
|
||||||
}
|
}
|
||||||
|
|
||||||
FSTRING_LINK int
|
FSTRING_LINK int
|
||||||
find_substr_unsensitive(String str, int start, String seek){
|
find_substr_insensitive(String str, int start, String seek){
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
int stop_at;
|
int stop_at;
|
||||||
bool hit;
|
bool hit;
|
||||||
|
@ -1217,8 +1217,8 @@ wildcard_match(Absolutes *absolutes, char *x, int case_sensitive){
|
||||||
match_part_func = match_part;
|
match_part_func = match_part;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
match_func = match_unsensitive;
|
match_func = match_insensitive;
|
||||||
match_part_func = match_part_unsensitive;
|
match_part_func = match_part_insensitive;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (absolutes->count == 1){
|
if (absolutes->count == 1){
|
||||||
|
|
24
4ed.cpp
24
4ed.cpp
|
@ -1917,22 +1917,6 @@ extern "C"{
|
||||||
return(buffer);
|
return(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
GET_ACTIVE_BUFFER_SIG(external_get_active_buffer){
|
|
||||||
Command_Data *cmd = (Command_Data*)app->cmd_context;
|
|
||||||
Buffer_Summary buffer = {};
|
|
||||||
View *view = cmd->view;
|
|
||||||
Editing_File *file;
|
|
||||||
|
|
||||||
if (view_lock_level(view) <= LockLevel_Open){
|
|
||||||
file = view->file_data.file;
|
|
||||||
if (file){
|
|
||||||
fill_buffer_summary(&buffer, file, &cmd->models->working_set);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
GET_PARAMETER_BUFFER_SIG(external_get_parameter_buffer){
|
GET_PARAMETER_BUFFER_SIG(external_get_parameter_buffer){
|
||||||
Command_Data *cmd = (Command_Data*)app->cmd_context;
|
Command_Data *cmd = (Command_Data*)app->cmd_context;
|
||||||
Models *models = cmd->models;
|
Models *models = cmd->models;
|
||||||
|
@ -1959,6 +1943,7 @@ extern "C"{
|
||||||
return(buffer);
|
return(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
BUFFER_SEEK_DELIMITER_SIG(external_buffer_seek_delimiter){
|
BUFFER_SEEK_DELIMITER_SIG(external_buffer_seek_delimiter){
|
||||||
Command_Data *cmd = (Command_Data*)app->cmd_context;
|
Command_Data *cmd = (Command_Data*)app->cmd_context;
|
||||||
Editing_File *file;
|
Editing_File *file;
|
||||||
|
@ -2071,6 +2056,7 @@ extern "C"{
|
||||||
|
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
REFRESH_BUFFER_SIG(external_refresh_buffer){
|
REFRESH_BUFFER_SIG(external_refresh_buffer){
|
||||||
int result;
|
int result;
|
||||||
|
@ -2522,7 +2508,6 @@ internal void
|
||||||
view_caller(Coroutine *coroutine){
|
view_caller(Coroutine *coroutine){
|
||||||
View *view = (View*)coroutine->in;
|
View *view = (View*)coroutine->in;
|
||||||
View_Persistent *persistent = &view->persistent;
|
View_Persistent *persistent = &view->persistent;
|
||||||
|
|
||||||
persistent->view_routine(&persistent->models->app_links, persistent->id);
|
persistent->view_routine(&persistent->models->app_links, persistent->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2547,14 +2532,17 @@ app_links_init(System_Functions *system, Application_Links *app_links, void *dat
|
||||||
app_links->get_buffer_next = external_get_buffer_next;
|
app_links->get_buffer_next = external_get_buffer_next;
|
||||||
|
|
||||||
app_links->get_buffer = external_get_buffer;
|
app_links->get_buffer = external_get_buffer;
|
||||||
app_links->get_active_buffer = external_get_active_buffer;
|
|
||||||
app_links->get_parameter_buffer = external_get_parameter_buffer;
|
app_links->get_parameter_buffer = external_get_parameter_buffer;
|
||||||
app_links->get_buffer_by_name = external_get_buffer_by_name;
|
app_links->get_buffer_by_name = external_get_buffer_by_name;
|
||||||
|
|
||||||
app_links->refresh_buffer = external_refresh_buffer;
|
app_links->refresh_buffer = external_refresh_buffer;
|
||||||
|
|
||||||
|
#if 0
|
||||||
app_links->buffer_seek_delimiter = external_buffer_seek_delimiter;
|
app_links->buffer_seek_delimiter = external_buffer_seek_delimiter;
|
||||||
app_links->buffer_seek_string = external_buffer_seek_string;
|
app_links->buffer_seek_string = external_buffer_seek_string;
|
||||||
app_links->buffer_seek_string_insensitive = external_buffer_seek_string_insensitive;
|
app_links->buffer_seek_string_insensitive = external_buffer_seek_string_insensitive;
|
||||||
|
#endif
|
||||||
|
|
||||||
app_links->buffer_read_range = external_buffer_read_range;
|
app_links->buffer_read_range = external_buffer_read_range;
|
||||||
app_links->buffer_replace_range = external_buffer_replace_range;
|
app_links->buffer_replace_range = external_buffer_replace_range;
|
||||||
|
|
||||||
|
|
|
@ -582,6 +582,7 @@ filename_match(String query, Absolutes *absolutes, String filename, b32 case_sen
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
internal Hot_Directory_Match
|
internal Hot_Directory_Match
|
||||||
hot_directory_first_match(Hot_Directory *hot_directory,
|
hot_directory_first_match(Hot_Directory *hot_directory,
|
||||||
String str,
|
String str,
|
||||||
|
@ -605,7 +606,7 @@ hot_directory_first_match(Hot_Directory *hot_directory,
|
||||||
if (match(filename, str)) is_match = 1;
|
if (match(filename, str)) is_match = 1;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if (match_unsensitive(filename, str)) is_match = 1;
|
if (match_insensitive(filename, str)) is_match = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
@ -621,6 +622,7 @@ hot_directory_first_match(Hot_Directory *hot_directory,
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
inline File_Sync_State
|
inline File_Sync_State
|
||||||
buffer_get_sync(Editing_File *file){
|
buffer_get_sync(Editing_File *file){
|
||||||
|
|
|
@ -476,6 +476,24 @@ generate_custom_headers(){
|
||||||
);
|
);
|
||||||
fprintf(file, "};\n");
|
fprintf(file, "};\n");
|
||||||
|
|
||||||
|
// TODO(allen): Generate app->function(app, ...) to function(app, ...) wrappers.
|
||||||
|
// Need to parse parameter names to do this.
|
||||||
|
#if 0
|
||||||
|
for (int i = 0; i < sig_count; ++i){
|
||||||
|
Function_Signature *sig = sigs + i;
|
||||||
|
|
||||||
|
copy_fast_unsafe(name_buffer, sig->name);
|
||||||
|
name_buffer[sig->name.size] = 0;
|
||||||
|
to_lower(name_buffer, name_buffer);
|
||||||
|
|
||||||
|
fprintf(file,
|
||||||
|
"inline %.*s\n"
|
||||||
|
"%s%.*s{ app->%s(",
|
||||||
|
sig->name.size, sig->name.str,
|
||||||
|
name_buffer);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
return(filename);
|
return(filename);
|
||||||
|
|
|
@ -88,12 +88,13 @@ table_add(Table *table, void *item, void *arg, Hash_Function *hash_func, Compare
|
||||||
internal b32
|
internal b32
|
||||||
table_find_pos(Table *table, void *search_key, void *arg, i32 *pos, i32 *index, Hash_Function *hash_func, Compare_Function *comp_func){
|
table_find_pos(Table *table, void *search_key, void *arg, i32 *pos, i32 *index, Hash_Function *hash_func, Compare_Function *comp_func){
|
||||||
u32 hash, *inspect;
|
u32 hash, *inspect;
|
||||||
i32 i;
|
i32 i, start;
|
||||||
|
|
||||||
Assert((table->count - 1) * 8 < table->max * 7);
|
Assert((table->count - 1) * 8 < table->max * 7);
|
||||||
|
|
||||||
hash = (hash_func(search_key, arg) | TableHashMin);
|
hash = (hash_func(search_key, arg) | TableHashMin);
|
||||||
i = hash % table->max;
|
i = hash % table->max;
|
||||||
|
start = i;
|
||||||
inspect = table->hash_array + i;
|
inspect = table->hash_array + i;
|
||||||
|
|
||||||
while (*inspect != TableHashEmpty){
|
while (*inspect != TableHashEmpty){
|
||||||
|
|
4
TODO.txt
4
TODO.txt
|
@ -66,12 +66,12 @@
|
||||||
; [X] sometimes the main cursor is not the same width as the mark cursor in the same spot
|
; [X] sometimes the main cursor is not the same width as the mark cursor in the same spot
|
||||||
; [X] tab character wrong width
|
; [X] tab character wrong width
|
||||||
; [X] miblo's off screen cursor thing
|
; [X] miblo's off screen cursor thing
|
||||||
; [X] paste snaps the cursor back into view!
|
|
||||||
; [X] new file is messed up for code files, it never finishes parsing!
|
; [X] new file is messed up for code files, it never finishes parsing!
|
||||||
|
; [X] key presses that should be consumed in the GUI are now passed to the file!
|
||||||
; [] indication on failure to save
|
; [] indication on failure to save
|
||||||
; [] clean whitespace doesn't appear to be cleaning trailing whitespace anymore???
|
; [] clean whitespace doesn't appear to be cleaning trailing whitespace anymore???
|
||||||
;
|
;
|
||||||
; [] key presses that should be consumed in the GUI are now passed to the file!
|
; [] paste snaps the cursor back into view!
|
||||||
;
|
;
|
||||||
|
|
||||||
; TODOS
|
; TODOS
|
||||||
|
|
|
@ -18,14 +18,12 @@ Buffer_Summary Get_Buffer_First(Application_Links *app)
|
||||||
void Get_Buffer_Next(Application_Links *app, Buffer_Summary *buffer)
|
void Get_Buffer_Next(Application_Links *app, Buffer_Summary *buffer)
|
||||||
|
|
||||||
Buffer_Summary Get_Buffer(Application_Links *app, int index)
|
Buffer_Summary Get_Buffer(Application_Links *app, int index)
|
||||||
Buffer_Summary Get_Active_Buffer(Application_Links *app)
|
|
||||||
Buffer_Summary Get_Parameter_Buffer(Application_Links *app, int param_index)
|
Buffer_Summary Get_Parameter_Buffer(Application_Links *app, int param_index)
|
||||||
Buffer_Summary Get_Buffer_By_Name(Application_Links *app, char *filename, int len)
|
Buffer_Summary Get_Buffer_By_Name(Application_Links *app, char *filename, int len)
|
||||||
|
|
||||||
// TODO(allen): Need more flexible seek system somehow. Regex? Just expose the text stream to the user?
|
//int Buffer_Seek_Delimiter(Application_Links *app, Buffer_Summary *buffer, int start, char delim, int seek_forward, int *out)
|
||||||
int Buffer_Seek_Delimiter(Application_Links *app, Buffer_Summary *buffer, int start, char delim, int seek_forward, int *out)
|
//int Buffer_Seek_String(Application_Links *app, Buffer_Summary *buffer, int start, char *str, int len, int seek_forward, int *out)
|
||||||
int Buffer_Seek_String(Application_Links *app, Buffer_Summary *buffer, int start, char *str, int len, int seek_forward, int *out)
|
//int Buffer_Seek_String_Insensitive(Application_Links *app, Buffer_Summary *buffer, int start, char *str, int len, int seek_forward, int *out)
|
||||||
int Buffer_Seek_String_Insensitive(Application_Links *app, Buffer_Summary *buffer, int start, char *str, int len, int seek_forward, int *out)
|
|
||||||
|
|
||||||
int Refresh_Buffer(Application_Links *app, Buffer_Summary *buffer)
|
int Refresh_Buffer(Application_Links *app, Buffer_Summary *buffer)
|
||||||
int Buffer_Read_Range(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *out)
|
int Buffer_Read_Range(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *out)
|
||||||
|
|
|
@ -27,102 +27,6 @@ CUSTOM_COMMAND_SIG(kill_rect){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE(allen): This stream stuff will be moved to helper if it looks
|
|
||||||
// like it will be helpful. So if you want to use it to build your own
|
|
||||||
// commands I suggest you move it there first.
|
|
||||||
struct Stream_Chunk{
|
|
||||||
Application_Links *app;
|
|
||||||
Buffer_Summary *buffer;
|
|
||||||
|
|
||||||
char *base_data;
|
|
||||||
int start, end;
|
|
||||||
int data_size;
|
|
||||||
|
|
||||||
char *data;
|
|
||||||
};
|
|
||||||
|
|
||||||
int
|
|
||||||
round_down(int x, int b){
|
|
||||||
int r = 0;
|
|
||||||
if (x >= 0){
|
|
||||||
r = x - (x % b);
|
|
||||||
}
|
|
||||||
return(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
round_up(int x, int b){
|
|
||||||
int r = 0;
|
|
||||||
if (x >= 0){
|
|
||||||
r = x - (x % b) + b;
|
|
||||||
}
|
|
||||||
return(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
init_stream_chunk(Stream_Chunk *chunk,
|
|
||||||
Application_Links *app, Buffer_Summary *buffer,
|
|
||||||
int pos, char *data, int size){
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
app->refresh_buffer(app, buffer);
|
|
||||||
if (pos >= 0 && pos < buffer->size && size > 0){
|
|
||||||
result = 1;
|
|
||||||
chunk->app = app;
|
|
||||||
chunk->buffer = buffer;
|
|
||||||
chunk->base_data = data;
|
|
||||||
chunk->data_size = size;
|
|
||||||
chunk->start = round_down(pos, size);
|
|
||||||
chunk->end = round_up(pos, size);
|
|
||||||
if (chunk->end > buffer->size){
|
|
||||||
chunk->end = buffer->size;
|
|
||||||
}
|
|
||||||
app->buffer_read_range(app, buffer, chunk->start, chunk->end, chunk->base_data);
|
|
||||||
chunk->data = chunk->base_data - chunk->start;
|
|
||||||
}
|
|
||||||
return(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
forward_stream_chunk(Stream_Chunk *chunk){
|
|
||||||
Application_Links *app = chunk->app;
|
|
||||||
Buffer_Summary *buffer = chunk->buffer;
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
app->refresh_buffer(app, buffer);
|
|
||||||
if (chunk->end < buffer->size){
|
|
||||||
result = 1;
|
|
||||||
chunk->start = chunk->end;
|
|
||||||
chunk->end += chunk->data_size;
|
|
||||||
if (chunk->end > buffer->size){
|
|
||||||
chunk->end = buffer->size;
|
|
||||||
}
|
|
||||||
app->buffer_read_range(app, buffer, chunk->start, chunk->end, chunk->base_data);
|
|
||||||
chunk->data = chunk->base_data - chunk->start;
|
|
||||||
}
|
|
||||||
return(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
backward_stream_chunk(Stream_Chunk *chunk){
|
|
||||||
Application_Links *app = chunk->app;
|
|
||||||
Buffer_Summary *buffer = chunk->buffer;
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
app->refresh_buffer(app, buffer);
|
|
||||||
if (chunk->start > 0){
|
|
||||||
result = 1;
|
|
||||||
chunk->end = chunk->start;
|
|
||||||
chunk->start -= chunk->data_size;
|
|
||||||
if (chunk->start < 0){
|
|
||||||
chunk->start = 0;
|
|
||||||
}
|
|
||||||
app->buffer_read_range(app, buffer, chunk->start, chunk->end, chunk->base_data);
|
|
||||||
chunk->data = chunk->base_data - chunk->start;
|
|
||||||
}
|
|
||||||
return(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(allen): Both of these brace related commands would work better
|
// TODO(allen): Both of these brace related commands would work better
|
||||||
// if the API exposed access to the tokens in a code file.
|
// if the API exposed access to the tokens in a code file.
|
||||||
CUSTOM_COMMAND_SIG(mark_matching_brace){
|
CUSTOM_COMMAND_SIG(mark_matching_brace){
|
||||||
|
@ -146,7 +50,8 @@ CUSTOM_COMMAND_SIG(mark_matching_brace){
|
||||||
int nesting_counter = 0;
|
int nesting_counter = 0;
|
||||||
char at_cursor = 0;
|
char at_cursor = 0;
|
||||||
|
|
||||||
if (init_stream_chunk(&chunk, app, &buffer, i, chunk_space, sizeof(chunk_space))){
|
if (init_stream_chunk(&chunk, app, &buffer, i,
|
||||||
|
chunk_space, sizeof(chunk_space))){
|
||||||
|
|
||||||
// NOTE(allen): This is important! The data array is a pointer that is adjusted
|
// NOTE(allen): This is important! The data array is a pointer that is adjusted
|
||||||
// so that indexing it with "i" will put it with the chunk that is actually loaded.
|
// so that indexing it with "i" will put it with the chunk that is actually loaded.
|
||||||
|
|
Loading…
Reference in New Issue