From 67c15443e097e1d1f39bb06e68a9d6fb33b0eddb Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Mon, 26 Oct 2015 22:10:33 -0400 Subject: [PATCH] updown seeks --- 4ed.cpp | 66 ++---- 4ed_file_view.cpp | 2 +- buffer/4coder_buffer_abstract.cpp | 375 +++++++++++++++++++++++++++--- buffer/4coder_gap_buffer.cpp | 74 ++---- buffer/4coder_golden_array.cpp | 48 +--- buffer/4coder_shared.cpp | 162 ++++--------- win32_4ed.cpp | 2 +- 7 files changed, 420 insertions(+), 309 deletions(-) diff --git a/4ed.cpp b/4ed.cpp index fb00c2f0..de9dd2dc 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -234,36 +234,22 @@ COMMAND_DECL(seek_whitespace_left){ } COMMAND_DECL(seek_whitespace_up){ -#if BUFFER_EXPERIMENT_SCALPEL ProfileMomentFunction(); REQ_FILE_VIEW(view); REQ_FILE(file, view); - char* data = file->buffer.data; - u32 pos = view->cursor.pos; - while (pos > 0 && char_is_whitespace(data[pos])){ - --pos; - } - - bool32 no_hard_character = 0; - while (pos > 0){ - if (starts_new_line(data[pos])){ - if (no_hard_character) break; - else no_hard_character = 1; - } - else if (!char_is_whitespace(data[pos])){ - no_hard_character = 0; - } - --pos; - } - - if (pos != 0) ++pos; - + i32 pos = buffer_seek_whitespace_up(&file->buffer, view->cursor.pos); view_cursor_move(view, pos); -#endif } COMMAND_DECL(seek_whitespace_down){ + ProfileMomentFunction(); + REQ_FILE_VIEW(view); + REQ_FILE(file, view); + + i32 pos = buffer_seek_whitespace_down(&file->buffer, view->cursor.pos); + view_cursor_move(view, pos); + #if BUFFER_EXPERIMENT_SCALPEL ProfileMomentFunction(); REQ_FILE_VIEW(view); @@ -382,40 +368,13 @@ COMMAND_DECL(seek_white_or_token_left){ #endif } -internal i32 -seek_alphanumeric_right(u8 *data, i32 size, i32 pos){ - while (pos < size && !char_is_alpha_numeric_true(data[pos])){ - ++pos; - } - while (pos < size && char_is_alpha_numeric_true(data[pos])){ - ++pos; - } - return pos; -} - -internal i32 -seek_alphanumeric_left(u8 *data, i32 pos){ - --pos; - while (pos > 0 && !char_is_alpha_numeric_true(data[pos])){ - --pos; - } - while (pos >= 0 && char_is_alpha_numeric_true(data[pos])){ - --pos; - } - ++pos; - return pos; -} - COMMAND_DECL(seek_alphanumeric_right){ -#if BUFFER_EXPERIMENT_SCALPEL ProfileMomentFunction(); REQ_FILE_VIEW(view); REQ_FILE(file, view); - i32 pos = seek_alphanumeric_right( - (u8*)file->buffer.data, file->buffer.size, view->cursor.pos); + i32 pos = buffer_seek_alphanumeric_right(&file->buffer, view->cursor.pos); view_cursor_move(view, pos); -#endif } COMMAND_DECL(seek_alphanumeric_left){ @@ -423,8 +382,7 @@ COMMAND_DECL(seek_alphanumeric_left){ REQ_FILE_VIEW(view); REQ_FILE(file, view); - i32 pos = seek_alphanumeric_left( - (u8*)file->buffer.data, view->cursor.pos); + i32 pos = buffer_seek_alphanumeric_left(&file->buffer, view->cursor.pos); view_cursor_move(view, pos); } @@ -455,6 +413,7 @@ COMMAND_DECL(seek_alphanumeric_or_camel_right){ } COMMAND_DECL(seek_alphanumeric_or_camel_left){ +#if BUFFER_EXPERIMENT_SCALPEL ProfileMomentFunction(); REQ_FILE_VIEW(view); REQ_FILE(file, view); @@ -462,7 +421,7 @@ COMMAND_DECL(seek_alphanumeric_or_camel_left){ u8 *data = (u8*)file->buffer.data; i32 an_pos, camel_pos; - an_pos = seek_alphanumeric_left( + an_pos = buffer_seek_alphanumeric_left( data, view->cursor.pos); char curr_char; @@ -476,6 +435,7 @@ COMMAND_DECL(seek_alphanumeric_or_camel_left){ } view_cursor_move(view, camel_pos); +#endif } COMMAND_DECL(search){ diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index d865b61d..ea641fd4 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -1347,7 +1347,7 @@ file_create_from_string(General_Memory *general, Editing_File *file, u8 *filenam *file = {}; file->buffer.data = (char*)data; file->buffer.max = request_size; - gap_buffer_initialize(&file->buffer, val.str, val.size); + buffer_initialize(&file->buffer, val.str, val.size); file_synchronize_times(file, filename); file_init_strings(file); diff --git a/buffer/4coder_buffer_abstract.cpp b/buffer/4coder_buffer_abstract.cpp index 4a931067..dba70194 100644 --- a/buffer/4coder_buffer_abstract.cpp +++ b/buffer/4coder_buffer_abstract.cpp @@ -13,11 +13,8 @@ // TOP -#define CAT_(a,b) a##b -#define CAT(a,b) CAT_(a,b) - -#define Buffer_Stringify_Type CAT(Buffer_Type, _Stringify_Loop) -#define Buffer_Backify_Type CAT(Buffer_Type, _Backify_Loop) +#define Buffer_Stringify_Type cat_4tech(Buffer_Type, _Stringify_Loop) +#define Buffer_Backify_Type cat_4tech(Buffer_Type, _Backify_Loop) internal_4tech int buffer_count_newlines(Buffer_Type *buffer, int start, int end){ @@ -42,6 +39,98 @@ buffer_count_newlines(Buffer_Type *buffer, int start, int end){ return(count); } +internal_4tech int +buffer_seek_whitespace_down(Buffer_Type *buffer, int pos){ + Buffer_Stringify_Type loop; + char *data; + int end; + int size; + int no_hard; + int prev_endline; + + size = buffer_size(buffer); + loop = buffer_stringify_loop(buffer, pos, size, size); + + for (;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 (!is_whitespace(data[pos])) goto buffer_seek_whitespace_down_mid; + } + } + +buffer_seek_whitespace_down_mid: + no_hard = 0; + prev_endline = -1; + for (;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] == '\n'){ + if (no_hard) goto buffer_seek_whitespace_down_end; + else{ + no_hard = 1; + prev_endline = pos; + } + } + else if (!is_whitespace(data[pos])){ + no_hard = 0; + } + } + } + +buffer_seek_whitespace_down_end: + if (prev_endline == -1 || prev_endline+1 >= size) pos = size; + else pos = prev_endline+1; + + return pos; +} + +internal_4tech int +buffer_seek_whitespace_up(Buffer_Type *buffer, int pos){ + Buffer_Backify_Type loop; + char *data; + int end; + int size; + int no_hard; + + size = buffer_size(buffer); + loop = buffer_backify_loop(buffer, pos, 0, size); + + for (;buffer_backify_good(&loop); + buffer_backify_next(&loop)){ + end = loop.absolute_pos; + data = loop.data - loop.absolute_pos; + for (;pos > end; --pos){ + if (!is_whitespace(data[pos])) goto buffer_seek_whitespace_up_mid; + } + } + +buffer_seek_whitespace_up_mid: + no_hard = 0; + for (;buffer_backify_good(&loop); + buffer_backify_next(&loop)){ + end = loop.absolute_pos; + data = loop.data - loop.absolute_pos; + for (; pos > end; --pos){ + if (data[pos] == '\n'){ + if (no_hard) goto buffer_seek_whitespace_up_end; + else no_hard = 1; + } + else if (!is_whitespace(data[pos])){ + no_hard = 0; + } + } + } + +buffer_seek_whitespace_up_end: + if (pos != 0) ++pos; + + return pos; +} + internal_4tech int buffer_seek_whitespace_right(Buffer_Type *buffer, int pos){ Buffer_Stringify_Type loop; @@ -77,24 +166,90 @@ buffer_seek_whitespace_left(Buffer_Type *buffer, int pos){ char *data; int end; int size; - + size = buffer_size(buffer); loop = buffer_backify_loop(buffer, pos, 0, size); for (;buffer_backify_good(&loop); buffer_backify_next(&loop)){ end = loop.absolute_pos; - data = loop.data - end; - for (; pos > end && is_whitespace(data[pos]); --pos); + data = loop.data - loop.absolute_pos; + for (; pos >= end && is_whitespace(data[pos]); --pos); if (!is_whitespace(data[pos])) break; } for (;buffer_backify_good(&loop); buffer_backify_next(&loop)){ end = loop.absolute_pos; - data = loop.data - end; - for (; pos > end && !is_whitespace(data[pos]); --pos); - if (is_whitespace(data[pos])) break; + data = loop.data - loop.absolute_pos; + for (; pos >= end && is_whitespace(data[pos]); --pos); + if (!is_whitespace(data[pos])) break; + } + + return(pos); +} + +internal_4tech int +buffer_seek_alphanumeric_right(Buffer_Type *buffer, int pos){ + Buffer_Stringify_Type loop; + char *data; + int end; + int size; + + size = buffer_size(buffer); + loop = buffer_stringify_loop(buffer, pos, size, size); + + for (;buffer_stringify_good(&loop); + buffer_stringify_next(&loop)){ + end = loop.size + loop.absolute_pos; + data = loop.data - loop.absolute_pos; + for (; pos < end && is_alphanumeric_true(data[pos]); ++pos); + if (!is_alphanumeric_true(data[pos])) break; + } + + for (;buffer_stringify_good(&loop); + buffer_stringify_next(&loop)){ + end = loop.size + loop.absolute_pos; + data = loop.data - loop.absolute_pos; + for (; pos < end && !is_alphanumeric_true(data[pos]); ++pos); + if (is_alphanumeric_true(data[pos])) break; + } + + return(pos); +} + +internal_4tech int +buffer_seek_alphanumeric_left(Buffer_Type *buffer, int pos){ + Buffer_Backify_Type loop; + char *data; + int end; + int size; + + --pos; + if (pos >= 0){ + size = buffer_size(buffer); + loop = buffer_backify_loop(buffer, pos, 0, size); + + for (;buffer_backify_good(&loop); + buffer_backify_next(&loop)){ + end = loop.absolute_pos; + data = loop.data - end; + for (; pos >= end && !is_alphanumeric_true(data[pos]); --pos); + if (is_alphanumeric_true(data[pos])) break; + } + + for (;buffer_backify_good(&loop); + buffer_backify_next(&loop)){ + end = loop.absolute_pos; + data = loop.data - end; + for (; pos >= end && is_alphanumeric_true(data[pos]); --pos); + if (!is_alphanumeric_true(data[pos])) break; + } + + ++pos; + } + else{ + pos = 0; } return(pos); @@ -329,7 +484,7 @@ buffer_get_line_index(Buffer_Type *buffer, int pos, int l_bound, int u_bound){ return(start); } -#ifndef NON_ABSTRACT_PORTION_4TECH +#ifndef NON_ABSTRACT_4TECH internal_4tech int buffer_get_line_index_from_wrapped_y(float *wraps, float y, float font_height, int l_bound, int u_bound){ int start, end, i, result; @@ -352,6 +507,159 @@ buffer_get_line_index_from_wrapped_y(float *wraps, float y, float font_height, i } #endif +#ifndef NON_ABSTRACT_4TECH + +typedef struct{ + Full_Cursor cursor, prev_cursor; +} Seek_State; + +internal_4tech int +cursor_seek_step(Seek_State *state, Buffer_Seek seek, int xy_seek, float max_width, float font_height, + char *advances, int stride, int size, char ch){ + Full_Cursor cursor, prev_cursor; + float ch_width; + int result; + float x, px, y; + + cursor = state->cursor; + prev_cursor = state->prev_cursor; + + result = 1; + prev_cursor = cursor; + switch (ch){ + case '\n': + ++cursor.line; + cursor.unwrapped_y += font_height; + cursor.wrapped_y += font_height; + cursor.character = 1; + cursor.unwrapped_x = 0; + cursor.wrapped_x = 0; + break; + + default: + ++cursor.character; + if (ch == '\r') ch_width = *(float*)(advances + stride * '\\') + *(float*)(advances + stride * 'r'); + else ch_width = *(float*)(advances + stride * ch); + + if (cursor.wrapped_x + ch_width >= max_width){ + cursor.wrapped_y += font_height; + cursor.wrapped_x = 0; + prev_cursor = cursor; + } + + cursor.unwrapped_x += ch_width; + cursor.wrapped_x += ch_width; + + break; + } + + ++cursor.pos; + + if (cursor.pos > size){ + cursor = prev_cursor; + result = 0; + goto cursor_seek_step_end; + } + + x = y = px = 0; + + switch (seek.type){ + case buffer_seek_pos: + if (cursor.pos > seek.pos){ + cursor = prev_cursor; + result = 0; + goto cursor_seek_step_end; + }break; + + case buffer_seek_wrapped_xy: + x = cursor.wrapped_x; px = prev_cursor.wrapped_x; + y = cursor.wrapped_y; break; + + case buffer_seek_unwrapped_xy: + x = cursor.unwrapped_x; px = prev_cursor.unwrapped_x; + y = cursor.unwrapped_y; break; + + case buffer_seek_line_char: + if (cursor.line == seek.line && cursor.character >= seek.character){ + result = 0; + goto cursor_seek_step_end; + } + else if (cursor.line > seek.line){ + cursor = prev_cursor; + result = 0; + goto cursor_seek_step_end; + }break; + } + + if (xy_seek){ + if (y > seek.y){ + cursor = prev_cursor; + result = 0; + goto cursor_seek_step_end; + } + + if (y > seek.y - font_height && x >= seek.x){ + if (!seek.round_down){ + if (ch != '\n' && (seek.x - px) < (x - seek.x)) cursor = prev_cursor; + result = 0; + goto cursor_seek_step_end; + } + + if (x > seek.x){ + cursor = prev_cursor; + result = 0; + goto cursor_seek_step_end; + } + } + } + +cursor_seek_step_end: + state->cursor = cursor; + state->prev_cursor = prev_cursor; + + return(result); +} +#endif + +internal_4tech Full_Cursor +buffer_cursor_seek(Buffer_Type *buffer, Buffer_Seek seek, float max_width, float font_height, + void *advance_data, int stride, Full_Cursor cursor){ + Buffer_Stringify_Type loop; + char *data; + int size, end; + int i; + int result; + + Seek_State state; + char *advances; + int xy_seek; + + size = buffer_size(buffer); + advances = (char*)advance_data; + xy_seek = (seek.type == buffer_seek_wrapped_xy || seek.type == buffer_seek_unwrapped_xy); + state.cursor = cursor; + + result = 1; + i = cursor.pos; + for (loop = buffer_stringify_loop(buffer, i, size, size); + buffer_stringify_good(&loop); + buffer_stringify_next(&loop)){ + end = loop.size + loop.absolute_pos; + data = loop.data - loop.absolute_pos; + for (; i < end && result; ++i){ + result = cursor_seek_step(&state, seek, xy_seek, max_width, font_height, + advances, stride, size, data[i]); + } + } + if (result){ + result = cursor_seek_step(&state, seek, xy_seek, max_width, font_height, + advances, stride, size, 0); + assert_4tech(result == 0); + } + + return(state.cursor); +} + internal_4tech Full_Cursor buffer_cursor_from_pos(Buffer_Type *buffer, int pos, float *wraps, float max_width, float font_height, void *advance_data, int stride){ @@ -399,9 +707,10 @@ buffer_cursor_from_wrapped_xy(Buffer_Type *buffer, float x, float y, int round_d internal_4tech void buffer_get_render_data(Buffer_Type *buffer, float *wraps, Buffer_Render_Item *items, int max, int *count, - float port_x, float port_y, float scroll_x, float scroll_y, Full_Cursor start_cursor, int wrapped, + float port_x, float port_y, float scroll_x, float scroll_y, int wrapped, float width, float height, void *advance_data, int stride, float font_height){ Buffer_Stringify_Type loop; + Full_Cursor start_cursor; Buffer_Render_Item *item; char *data; int size, end; @@ -410,14 +719,22 @@ buffer_get_render_data(Buffer_Type *buffer, float *wraps, Buffer_Render_Item *it int i, item_i; float ch_width, ch_width_sub; char ch; - + size = buffer_size(buffer); - + shift_x = port_x - scroll_x; shift_y = port_y - scroll_y; - if (wrapped) shift_y += start_cursor.wrapped_y; - else shift_y += start_cursor.unwrapped_y; - + if (wrapped){ + start_cursor = buffer_cursor_from_wrapped_xy(buffer, 0, scroll_y, 0, wraps, + width, font_height, advance_data, stride); + shift_y += start_cursor.wrapped_y; + } + else{ + start_cursor = buffer_cursor_from_unwrapped_xy(buffer, 0, scroll_y, 0, wraps, + width, font_height, advance_data, stride); + shift_y += start_cursor.unwrapped_y; + } + x = shift_x; y = shift_y; item_i = 0; @@ -502,26 +819,8 @@ buffer_get_render_data_end: *count = item_i; } -internal_4tech void -buffer_get_render_data(Buffer_Type *buffer, float *wraps, Buffer_Render_Item *items, int max, int *count, - float port_x, float port_y, float scroll_x, float scroll_y, int wrapped, - float width, float height, void *advance_data, int stride, float font_height){ - Full_Cursor start_cursor; - if (wrapped){ - start_cursor = buffer_cursor_from_wrapped_xy(buffer, 0, scroll_y, 0, wraps, - width, font_height, advance_data, stride); - } - else{ - start_cursor = buffer_cursor_from_unwrapped_xy(buffer, 0, scroll_y, 0, wraps, - width, font_height, advance_data, stride); - } - buffer_get_render_data(buffer, wraps, items, max, count, - port_x, port_y, scroll_x, scroll_y, start_cursor, wrapped, - width, height, advance_data, stride, font_height); -} - -#ifndef NON_ABSTRACT_PORTION_4TECH -#define NON_ABSTRACT_PORTION_4TECH 1 +#ifndef NON_ABSTRACT_4TECH +#define NON_ABSTRACT_4TECH 1 #endif // BOTTOM diff --git a/buffer/4coder_gap_buffer.cpp b/buffer/4coder_gap_buffer.cpp index 3e115320..b357e146 100644 --- a/buffer/4coder_gap_buffer.cpp +++ b/buffer/4coder_gap_buffer.cpp @@ -25,25 +25,26 @@ typedef struct{ } Gap_Buffer; inline_4tech void -gap_buffer_initialize(Gap_Buffer *buffer, char *data, int size){ - int size1, size2, gap_size; +buffer_initialize(Gap_Buffer *buffer, char *data, int size){ + int osize1, size1, size2; assert_4tech(buffer->max >= size); - size1 = size >> 1; - size2 = size - size1; - gap_size = buffer->max - size1 - size2; + size2 = size >> 1; + size1 = osize1 = size - size2; + + if (size1 > 0){ + size1 = eol_convert_in(buffer->data, data, size1); + + if (size2 > 0){ + size2 = eol_convert_in(buffer->data + size1, data + osize1, size2); + } + } + buffer->size1 = size1; buffer->size2 = size2; - buffer->gap_size = gap_size; - - if (buffer->size1 > 0){ - memcpy_4tech(buffer->data, data, size1); - } - - if (buffer->size2 > 0){ - memcpy_4tech(buffer->data + size1 + gap_size, data + size1, size2); - } + buffer->gap_size = buffer->max - size1 - size2; + memmove_4tech(buffer->data + size1 + buffer->gap_size, buffer->data + size1, size2); } inline_4tech int @@ -246,50 +247,5 @@ buffer_stringify(Gap_Buffer *buffer, int start, int end, char *out){ } } -internal_4tech Full_Cursor -buffer_cursor_seek(Gap_Buffer *buffer, Buffer_Seek seek, float max_width, float font_height, - void *advance_data, int stride, Full_Cursor cursor){ - char *data; - int size1, size2, gap_size; - int total_size, end, i; - int step; - int result; - - Seek_State state; - char *advances; - int xy_seek; - char ch; - - data = buffer->data; - size1 = buffer->size1; - gap_size = buffer->gap_size; - size2 = buffer->size2; - total_size = size1 + gap_size + size2; - - advances = (char*)advance_data; - xy_seek = (seek.type == buffer_seek_wrapped_xy || seek.type == buffer_seek_unwrapped_xy); - state.cursor = cursor; - - result = 1; - i = cursor.pos; - end = size1; - for (step = 0; step < 2; ++step){ - for (; i < end && result; ++i){ - ch = data[i]; - result = cursor_seek_step(&state, seek, xy_seek, max_width, font_height, - advances, stride, size1 + size2, ch); - } - end = total_size; - i += gap_size; - } - if (result){ - result = cursor_seek_step(&state, seek, xy_seek, max_width, font_height, - advances, stride, size1 + size2, 0); - assert_4tech(result == 0); - } - - return(state.cursor); -} - // BOTTOM diff --git a/buffer/4coder_golden_array.cpp b/buffer/4coder_golden_array.cpp index 68f0cd4b..aeb71516 100644 --- a/buffer/4coder_golden_array.cpp +++ b/buffer/4coder_golden_array.cpp @@ -24,6 +24,12 @@ typedef struct{ int widths_max; } Buffer; +internal_4tech void +buffer_initialize(Buffer *buffer, char *data, int size){ + assert_4tech(size <= buffer->max); + buffer->size = eol_convert_in(buffer->data, data, size); +} + inline_4tech int buffer_size(Buffer *buffer){ return buffer->size; @@ -150,36 +156,6 @@ buffer_replace_range(Buffer *buffer, int start, int end, char *str, int len, int return(result); } -internal_4tech Full_Cursor -buffer_cursor_seek(Buffer *buffer, Buffer_Seek seek, float max_width, float font_height, - void *advance_data, int stride, Full_Cursor cursor){ - char *data; - int size; - - Seek_State state; - char *advances; - char ch; - int xy_seek; - int result; - - data = buffer->data; - size = buffer->size; - assert_4tech(size < buffer->max); - data[size] = 0; - - advances = (char*)advance_data; - xy_seek = (seek.type == buffer_seek_wrapped_xy || seek.type == buffer_seek_unwrapped_xy); - state.cursor = cursor; - - do{ - ch = data[state.cursor.pos]; - result = cursor_seek_step(&state, seek, xy_seek, max_width, font_height, - advances, stride, size, ch); - }while(result); - - return(state.cursor); -} - internal_4tech void buffer_invert_edit_shift(Buffer *buffer, Buffer_Edit edit, Buffer_Edit *inverse, char *strings, int *str_pos, int max, int shift_amount){ int pos; @@ -313,18 +289,6 @@ buffer_find_hard_start(Buffer *buffer, int line_start, int *all_whitespace, int return(result); } -internal_4tech void -buffer_eol_convert_in(Buffer *buffer){ - buffer->size = eol_convert_in(buffer->data, buffer->size); -} - -inline_4tech int -buffer_eol_convert_out_size(Buffer *buffer){ - int size; - size = buffer->size + buffer->line_count; - return(size); -} - internal_4tech void buffer_eol_convert_out(Buffer *buffer){ int size; diff --git a/buffer/4coder_shared.cpp b/buffer/4coder_shared.cpp index 941d7c81..493bd4c8 100644 --- a/buffer/4coder_shared.cpp +++ b/buffer/4coder_shared.cpp @@ -23,6 +23,9 @@ #define assert_4tech assert #define ceil_4tech CEIL32 + +#define cat_4tech_(a,b) a##b +#define cat_4tech(a,b) cat_4tech_(a,b) #endif inline_4tech float @@ -147,117 +150,6 @@ make_cursor_hint(int line_index, int *starts, float *wrap_ys, float font_height) return(hint); } -typedef struct{ - Full_Cursor cursor, prev_cursor; -} Seek_State; - -internal_4tech int -cursor_seek_step(Seek_State *state, Buffer_Seek seek, int xy_seek, float max_width, float font_height, - char *advances, int stride, int size, char ch){ - Full_Cursor cursor, prev_cursor; - float ch_width; - int result; - float x, px, y; - - cursor = state->cursor; - prev_cursor = state->prev_cursor; - - result = 1; - prev_cursor = cursor; - switch (ch){ - case '\n': - ++cursor.line; - cursor.unwrapped_y += font_height; - cursor.wrapped_y += font_height; - cursor.character = 1; - cursor.unwrapped_x = 0; - cursor.wrapped_x = 0; - break; - - default: - ++cursor.character; - if (ch == '\r') ch_width = *(float*)(advances + stride * '\\') + *(float*)(advances + stride * 'r'); - else ch_width = *(float*)(advances + stride * ch); - - if (cursor.wrapped_x + ch_width >= max_width){ - cursor.wrapped_y += font_height; - cursor.wrapped_x = 0; - prev_cursor = cursor; - } - - cursor.unwrapped_x += ch_width; - cursor.wrapped_x += ch_width; - - break; - } - - ++cursor.pos; - - if (cursor.pos > size){ - cursor = prev_cursor; - result = 0; - goto cursor_seek_step_end; - } - - x = y = px = 0; - - switch (seek.type){ - case buffer_seek_pos: - if (cursor.pos > seek.pos){ - cursor = prev_cursor; - result = 0; - goto cursor_seek_step_end; - }break; - - case buffer_seek_wrapped_xy: - x = cursor.wrapped_x; px = prev_cursor.wrapped_x; - y = cursor.wrapped_y; break; - - case buffer_seek_unwrapped_xy: - x = cursor.unwrapped_x; px = prev_cursor.unwrapped_x; - y = cursor.unwrapped_y; break; - - case buffer_seek_line_char: - if (cursor.line == seek.line && cursor.character >= seek.character){ - result = 0; - goto cursor_seek_step_end; - } - else if (cursor.line > seek.line){ - cursor = prev_cursor; - result = 0; - goto cursor_seek_step_end; - }break; - } - - if (xy_seek){ - if (y > seek.y){ - cursor = prev_cursor; - result = 0; - goto cursor_seek_step_end; - } - - if (y > seek.y - font_height && x >= seek.x){ - if (!seek.round_down){ - if (ch != '\n' && (seek.x - px) < (x - seek.x)) cursor = prev_cursor; - result = 0; - goto cursor_seek_step_end; - } - - if (x > seek.x){ - cursor = prev_cursor; - result = 0; - goto cursor_seek_step_end; - } - } - } - -cursor_seek_step_end: - state->cursor = cursor; - state->prev_cursor = prev_cursor; - - return(result); -} - typedef struct{ int pos, index; } Cursor_With_Index; @@ -409,11 +301,23 @@ buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, int count, } internal_4tech int -eol_convert_in(char *data, int size){ +eol_convert_in(char *dest, char *src, int size){ + int i, j; + + for (i = 0, j = 0; i < size; ++i, ++j){ + if (src[i] == '\r' && i+1 < size && src[i+1] == '\n') ++i; + dest[j] = src[i]; + } + + return(j); +} + +internal_4tech int +eol_in_place_convert_in(char *data, int size){ int i; for (i = 0; i < size; ++i){ - if (data[i] == '\r' && data[i+1] == '\n'){ + if (data[i] == '\r' && i+1 < size && data[i+1] == '\n'){ memmove_4tech(data + i, data + i + 1, size - i); size -= 1; } @@ -423,11 +327,34 @@ eol_convert_in(char *data, int size){ } internal_4tech int -eol_convert_out(char *data, int size, int max, int *size_out){ +eol_convert_out(char *dest, int max, char *src, int size, int *size_out){ + int result; + int i, j; + + // TODO(allen): iterative memory check? + result = 1; + i = 0; + j = 0; + + for (; i < size; ++i, ++j){ + if (src[i] == '\n'){ + dest[j] = '\r'; + ++j; + dest[j] = '\n'; + } + else dest[j] = src[i]; + } + + *size_out = j; + return(result); +} + +internal_4tech int +eol_in_place_convert_out(char *data, int size, int max, int *size_out){ int result; int i; - // TODO(allen): iterative memory check + // TODO(allen): iterative memory check? result = 1; i = 0; @@ -451,5 +378,10 @@ is_whitespace(char c){ return(result); } +inline_4tech int +is_alphanumeric_true(char c){ + return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9'); +} + // BOTTOM diff --git a/win32_4ed.cpp b/win32_4ed.cpp index 0357ce68..4417e0ab 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -54,7 +54,7 @@ #define FPS 30 #define FRAME_TIME (1000000 / FPS) -#define BUFFER_EXPERIMENT_SCALPEL 1 +#define BUFFER_EXPERIMENT_SCALPEL 0 #include "4ed_meta.h"