From 9ac0727d08c2eef09fc946a5c6de79387d285908 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Mon, 30 May 2016 21:22:55 -0400 Subject: [PATCH] trimmed down custom api --- 4coder_custom_api.h | 12 -- 4coder_default_include.cpp | 64 ++++--- 4coder_helper.h | 358 +++++++++++++++++++++++++++++++++++ 4coder_string.h | 50 ++--- 4ed.cpp | 28 +-- 4ed_file.cpp | 4 +- 4ed_metagen.cpp | 18 ++ 4tech_table.cpp | 3 +- TODO.txt | 4 +- custom_api_spec.txt | 8 +- power/4coder_experiments.cpp | 99 +--------- 11 files changed, 454 insertions(+), 194 deletions(-) diff --git a/4coder_custom_api.h b/4coder_custom_api.h index 5903c3df..aa9a839c 100644 --- a/4coder_custom_api.h +++ b/4coder_custom_api.h @@ -11,12 +11,8 @@ #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_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_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 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) @@ -56,12 +52,8 @@ extern "C"{ typedef GET_BUFFER_FIRST_SIG(Get_Buffer_First_Function); typedef GET_BUFFER_NEXT_SIG(Get_Buffer_Next_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_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 BUFFER_READ_RANGE_SIG(Buffer_Read_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_Next_Function *get_buffer_next; Get_Buffer_Function *get_buffer; - Get_Active_Buffer_Function *get_active_buffer; Get_Parameter_Buffer_Function *get_parameter_buffer; 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; Buffer_Read_Range_Function *buffer_read_range; Buffer_Replace_Range_Function *buffer_replace_range; diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index 72efbe6c..da08c946 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -4,14 +4,13 @@ #define FCPP_STRING_IMPLEMENTATION #include "4coder_string.h" -#define UseInterfacesThatArePhasingOut 0 #include "4coder_helper.h" #include static void 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); } @@ -92,7 +91,7 @@ CUSTOM_COMMAND_SIG(if0_off){ int pos; view = app->get_active_view(app); - buffer = app->get_active_buffer(app); + buffer = app->get_buffer(app, view.buffer_id); range = get_range(&view); pos = range.min; @@ -161,8 +160,8 @@ CUSTOM_COMMAND_SIG(open_file_in_quotes){ view = app->get_active_view(app); buffer = app->get_buffer(app, view.buffer_id); pos = view.cursor.pos; - app->buffer_seek_delimiter(app, &buffer, pos, '"', 1, &end); - app->buffer_seek_delimiter(app, &buffer, pos, '"', 0, &start); + buffer_seek_delimiter_forward(app, &buffer, pos, '"', &end); + buffer_seek_delimiter_backward(app, &buffer, pos, '"', &start); ++start; size = end - start; @@ -213,39 +212,39 @@ isearch(Application_Links *app, int start_reversed){ Buffer_Summary buffer; User_Input in; Query_Bar bar; - + view = app->get_active_view(app); buffer = app->get_buffer(app, view.locked_buffer_id); if (!buffer.exists) return; if (app->start_query_bar(app, &bar, 0) == 0) return; - + Range match; int reverse = start_reversed; int pos; pos = view.cursor.pos; match = make_range(pos, pos); - + char bar_string_space[256]; bar.string = make_fixed_width_string(bar_string_space); - + String isearch = make_lit_string("I-Search: "); String rsearch = make_lit_string("Reverse-I-Search: "); - + while (1){ // NOTE(allen): Change the bar's prompt to match the current direction. if (reverse) bar.prompt = rsearch; else bar.prompt = isearch; - + in = app->get_user_input(app, EventOnAnyKey, EventOnEsc | EventOnButton); if (in.abort) break; - + // NOTE(allen): If we're getting mouse events here it's a 4coder bug, because we // only asked to intercept key events. assert(in.type == UserInputKey); - + int made_change = 0; if (in.key.keycode == '\n' || in.key.keycode == '\t'){ break; @@ -260,15 +259,15 @@ isearch(Application_Links *app, int start_reversed){ made_change = 1; } } - + int step_forward = 0; int step_backward = 0; - + 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) || - 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; if (step_forward && reverse){ start_pos = match.start + 1; @@ -282,17 +281,18 @@ isearch(Application_Links *app, int start_reversed){ reverse = 1; step_backward = 0; } - + if (in.key.keycode != key_back){ int new_pos; if (reverse){ - // TODO(allen): Need a good way to allow users to implement seeks for themselves. - 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){ if (step_backward){ 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; } match.start = new_pos; @@ -300,12 +300,14 @@ isearch(Application_Links *app, int start_reversed){ } } 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 (step_forward){ 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; } match.start = new_pos; @@ -318,12 +320,12 @@ isearch(Application_Links *app, int start_reversed){ match.end = match.start + bar.string.size; } } - + app->view_set_highlight(app, &view, match.start, match.end, 1); } app->view_set_highlight(app, &view, 0, 0, 0); if (in.abort) return; - + app->view_set_cursor(app, &view, seek_pos(match.min), 1); } @@ -365,14 +367,14 @@ CUSTOM_COMMAND_SIG(replace_in_range){ int pos, new_pos; 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){ app->buffer_replace_range(app, &buffer, new_pos, new_pos + r.size, w.str, w.size); app->refresh_view(app, &view); range = get_range(&view); 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); 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}; while (new_pos < buffer.size){ @@ -428,7 +430,7 @@ CUSTOM_COMMAND_SIG(query_replace){ 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); @@ -663,7 +665,7 @@ CUSTOM_COMMAND_SIG(auto_tab_line_at_cursor){ } 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_end, buffer.size); exec_command(app, cmdid_auto_tab_range); diff --git a/4coder_helper.h b/4coder_helper.h index ce090629..54e7960a 100644 --- a/4coder_helper.h +++ b/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 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:; + } +} + + diff --git a/4coder_string.h b/4coder_string.h index c1958cc0..c51c82bc 100644 --- a/4coder_string.h +++ b/4coder_string.h @@ -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(String a, String b); -FSTRING_LINK bool match_unsensitive(char *a, char *b); -FSTRING_LINK bool match_unsensitive(String a, char *b); -FSTRING_INLINE bool match_unsensitive(char *a, String b) { return match_unsensitive(b,a); } -FSTRING_LINK bool match_unsensitive(String a, String b); +FSTRING_LINK bool match_insensitive(char *a, char *b); +FSTRING_LINK bool match_insensitive(String a, char *b); +FSTRING_INLINE bool match_insensitive(char *a, String b) { return match_insensitive(b,a); } +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_unsensitive(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_unsensitive(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_unsensitive(String a, String b); +FSTRING_LINK bool match_part_insensitive(char *a, char *b, int *len); +FSTRING_LINK bool match_part_insensitive(String a, char *b, int *len); +FSTRING_INLINE bool match_part_insensitive(char *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_insensitive(char *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(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 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_unsensitive(String s, int start, String seek); +FSTRING_LINK int find_substr_insensitive(char *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(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_unsensitive(String s, String seek) { return (find_substr_unsensitive(s, 0, seek) < s.size); } +FSTRING_INLINE bool has_substr_insensitive(char *s, String seek) { return (s[find_substr_insensitive(s, 0, seek)] != 0); } +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(int x, char *s_out); @@ -391,7 +391,7 @@ match_part(String a, String b){ } FSTRING_LINK bool -match_unsensitive(char *a, char *b){ +match_insensitive(char *a, char *b){ for (int i = 0;; ++i){ if (char_to_upper(a[i]) != char_to_upper(b[i])){ @@ -404,7 +404,7 @@ match_unsensitive(char *a, char *b){ } FSTRING_LINK bool -match_unsensitive(String a, char *b){ +match_insensitive(String a, char *b){ int i = 0; for (; i < a.size; ++i){ if (char_to_upper(a.str[i]) != @@ -419,7 +419,7 @@ match_unsensitive(String a, char *b){ } FSTRING_LINK bool -match_unsensitive(String a, String b){ +match_insensitive(String a, String b){ if (a.size != b.size){ return 0; } @@ -433,7 +433,7 @@ match_unsensitive(String a, String b){ } FSTRING_LINK bool -match_part_unsensitive(char *a, char *b, int *len){ +match_part_insensitive(char *a, char *b, int *len){ int i; for (i = 0; b[i] != 0; ++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 -match_part_unsensitive(String a, char *b, int *len){ +match_part_insensitive(String a, char *b, int *len){ int i; for (i = 0; b[i] != 0; ++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 -match_part_unsensitive(char *a, String b){ +match_part_insensitive(char *a, String b){ for (int i = 0; i != b.size; ++i){ if (char_to_upper(a[i]) != char_to_upper(b.str[i])){ return 0; @@ -468,7 +468,7 @@ match_part_unsensitive(char *a, String b){ } FSTRING_LINK bool -match_part_unsensitive(String a, String b){ +match_part_insensitive(String a, String b){ if (a.size < b.size){ return 0; } @@ -602,7 +602,7 @@ rfind_substr(String str, int start, String seek){ } 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; bool hit; char a_upper, b_upper; @@ -630,7 +630,7 @@ find_substr_unsensitive(char *str, int start, String seek){ } 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 stop_at; bool hit; @@ -1217,8 +1217,8 @@ wildcard_match(Absolutes *absolutes, char *x, int case_sensitive){ match_part_func = match_part; } else{ - match_func = match_unsensitive; - match_part_func = match_part_unsensitive; + match_func = match_insensitive; + match_part_func = match_part_insensitive; } if (absolutes->count == 1){ diff --git a/4ed.cpp b/4ed.cpp index ea10980d..2137b137 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -1917,22 +1917,6 @@ extern "C"{ 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){ Command_Data *cmd = (Command_Data*)app->cmd_context; Models *models = cmd->models; @@ -1958,7 +1942,8 @@ extern "C"{ return(buffer); } - + +#if 0 BUFFER_SEEK_DELIMITER_SIG(external_buffer_seek_delimiter){ Command_Data *cmd = (Command_Data*)app->cmd_context; Editing_File *file; @@ -2071,7 +2056,8 @@ extern "C"{ return(result); } - +#endif + REFRESH_BUFFER_SIG(external_refresh_buffer){ int result; *buffer = external_get_buffer(app, buffer->buffer_id); @@ -2522,7 +2508,6 @@ internal void view_caller(Coroutine *coroutine){ View *view = (View*)coroutine->in; View_Persistent *persistent = &view->persistent; - 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 = external_get_buffer; - app_links->get_active_buffer = external_get_active_buffer; app_links->get_parameter_buffer = external_get_parameter_buffer; app_links->get_buffer_by_name = external_get_buffer_by_name; app_links->refresh_buffer = external_refresh_buffer; + +#if 0 app_links->buffer_seek_delimiter = external_buffer_seek_delimiter; app_links->buffer_seek_string = external_buffer_seek_string; app_links->buffer_seek_string_insensitive = external_buffer_seek_string_insensitive; +#endif + app_links->buffer_read_range = external_buffer_read_range; app_links->buffer_replace_range = external_buffer_replace_range; diff --git a/4ed_file.cpp b/4ed_file.cpp index 51db66c0..0d03d2bc 100644 --- a/4ed_file.cpp +++ b/4ed_file.cpp @@ -582,6 +582,7 @@ filename_match(String query, Absolutes *absolutes, String filename, b32 case_sen return result; } +#if 0 internal Hot_Directory_Match hot_directory_first_match(Hot_Directory *hot_directory, String str, @@ -605,7 +606,7 @@ hot_directory_first_match(Hot_Directory *hot_directory, if (match(filename, str)) is_match = 1; } else{ - if (match_unsensitive(filename, str)) is_match = 1; + if (match_insensitive(filename, str)) is_match = 1; } } else{ @@ -621,6 +622,7 @@ hot_directory_first_match(Hot_Directory *hot_directory, return result; } +#endif inline File_Sync_State buffer_get_sync(Editing_File *file){ diff --git a/4ed_metagen.cpp b/4ed_metagen.cpp index 3f790884..d052ce25 100644 --- a/4ed_metagen.cpp +++ b/4ed_metagen.cpp @@ -476,6 +476,24 @@ generate_custom_headers(){ ); 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); return(filename); diff --git a/4tech_table.cpp b/4tech_table.cpp index 7c4144e5..77ba5a3e 100644 --- a/4tech_table.cpp +++ b/4tech_table.cpp @@ -88,12 +88,13 @@ table_add(Table *table, void *item, void *arg, Hash_Function *hash_func, Compare internal b32 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; - i32 i; + i32 i, start; Assert((table->count - 1) * 8 < table->max * 7); hash = (hash_func(search_key, arg) | TableHashMin); i = hash % table->max; + start = i; inspect = table->hash_array + i; while (*inspect != TableHashEmpty){ diff --git a/TODO.txt b/TODO.txt index 1f78229b..083fa665 100644 --- a/TODO.txt +++ b/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] tab character wrong width ; [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] key presses that should be consumed in the GUI are now passed to the file! ; [] indication on failure to save ; [] 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 diff --git a/custom_api_spec.txt b/custom_api_spec.txt index 853b2bab..fd11836f 100644 --- a/custom_api_spec.txt +++ b/custom_api_spec.txt @@ -18,14 +18,12 @@ Buffer_Summary Get_Buffer_First(Application_Links *app) void Get_Buffer_Next(Application_Links *app, Buffer_Summary *buffer) 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_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_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_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_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 Buffer_Read_Range(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *out) diff --git a/power/4coder_experiments.cpp b/power/4coder_experiments.cpp index e8ffa4ed..06b77398 100644 --- a/power/4coder_experiments.cpp +++ b/power/4coder_experiments.cpp @@ -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 // if the API exposed access to the tokens in a code file. CUSTOM_COMMAND_SIG(mark_matching_brace){ @@ -146,7 +50,8 @@ CUSTOM_COMMAND_SIG(mark_matching_brace){ int nesting_counter = 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 // so that indexing it with "i" will put it with the chunk that is actually loaded.