fixed bug with the parallel lexing routine not using the gap buffer

This commit is contained in:
Allen Webster 2016-09-19 10:41:11 -04:00
parent 6d2589d149
commit 1a987c6781
6 changed files with 301 additions and 286 deletions

View File

@ -1151,7 +1151,8 @@ cpp_get_relex_range(Cpp_Token_Array *array, int32_t start_pos, int32_t end_pos){
} }
FCPP_LINK Cpp_Relex_Data FCPP_LINK Cpp_Relex_Data
cpp_relex_init(Cpp_Token_Array *array, int32_t start_pos, int32_t end_pos, int32_t character_shift_amount, char *spare){ cpp_relex_init(Cpp_Token_Array *array, int32_t start_pos, int32_t end_pos, int32_t character_shift_amount, char *spare)
{
Cpp_Relex_Data state = {0}; Cpp_Relex_Data state = {0};
Cpp_Relex_Range range = cpp_get_relex_range(array, start_pos, end_pos); Cpp_Relex_Range range = cpp_get_relex_range(array, start_pos, end_pos);

View File

@ -1122,8 +1122,8 @@ Job_Callback_Sig(job_full_lex){
Editing_File *file = (Editing_File*)data[0]; Editing_File *file = (Editing_File*)data[0];
General_Memory *general = (General_Memory*)data[1]; General_Memory *general = (General_Memory*)data[1];
char *text_data = file->state.buffer.data; Buffer_Type *buffer = &file->state.buffer;
i32 text_size = buffer_size(&file->state.buffer); i32 text_size = buffer_size(buffer);
i32 buffer_size = (text_size + 3)&(~3); i32 buffer_size = (text_size + 3)&(~3);
@ -1142,12 +1142,32 @@ Job_Callback_Sig(job_full_lex){
Cpp_Lex_Data lex = cpp_lex_data_init(tb); Cpp_Lex_Data lex = cpp_lex_data_init(tb);
// TODO(allen): deduplicate this against relex
char *chunks[3];
i32 chunk_sizes[3];
chunks[0] = buffer->data;
chunk_sizes[0] = buffer->size1;
chunks[1] = buffer->data + buffer->size1 + buffer->gap_size;
chunk_sizes[1] = buffer->size2;
chunks[2] = 0;
chunk_sizes[2] = 0;
i32 chunk_index = 0;
do{ do{
char *chunk = chunks[chunk_index];
i32 chunk_size = chunk_sizes[chunk_index];
i32 result = i32 result =
cpp_lex_step(&lex, text_data, text_size, text_size, &tokens, 2048); cpp_lex_step(&lex, chunk, chunk_size, text_size, &tokens, 2048);
switch (result){ switch (result){
case LexResult_NeedChunk: Assert(!"Invalid Path"); break; case LexResult_NeedChunk:
++chunk_index;
break;
case LexResult_NeedTokenMemory: case LexResult_NeedTokenMemory:
if (system->check_cancel(thread)){ if (system->check_cancel(thread)){
@ -1290,10 +1310,10 @@ file_relex_parallel(System_Functions *system,
chunks[2] = 0; chunks[2] = 0;
chunk_sizes[2] = 0; chunk_sizes[2] = 0;
int32_t chunk_index = 0; i32 chunk_index = 0;
char *chunk = chunks[chunk_index]; char *chunk = chunks[chunk_index];
int32_t chunk_size = chunk_sizes[chunk_index]; i32 chunk_size = chunk_sizes[chunk_index];
while (!cpp_relex_is_start_chunk(&state, chunk, chunk_size)){ while (!cpp_relex_is_start_chunk(&state, chunk, chunk_size)){
++chunk_index; ++chunk_index;

View File

@ -152,9 +152,9 @@
; [] option to not open *messages* every startup ; [] option to not open *messages* every startup
; ;
; [] query buffer font info ; [] query buffer font info
; [] break buffer name ties by adding parent directories instead of <#> ; [] option to break buffer name ties by adding parent directories instead of <#>
; [] undo groups ; [] undo groups
; [] cursor/scroll grouping ; [] cursor/scroll groups
; [] allow for arbitrary wrap positions independent of view width ; [] allow for arbitrary wrap positions independent of view width
; [] word level wrapping ~ temporary measure really want to have totally formatted code presentation ; [] word level wrapping ~ temporary measure really want to have totally formatted code presentation
; [] double binding warnings ; [] double binding warnings
@ -171,8 +171,8 @@
; buffer behavior cleanup ; buffer behavior cleanup
; [X] show all characters as \# if they can't be rendered ; [X] show all characters as \# if they can't be rendered
; [] binary buffer mode
; [] get the navigation working correctly around multi-glyph characters ; [] get the navigation working correctly around multi-glyph characters
; [] binary buffer mode
; [] support full length unicode file names ; [] support full length unicode file names
; meta programming system ; meta programming system

View File

@ -1,11 +1,11 @@
/* /*
* Mr. 4th Dimention - Allen Webster * Mr. 4th Dimention - Allen Webster
* Four Tech
*
* public domain -- no warranty is offered or implied; use this code at your own risk
* *
* 24.10.2015 * 24.10.2015
* *
* Buffer features based on the stringify loop,
* and other abstract buffer features.
*
*/ */
// TOP // TOP
@ -15,7 +15,7 @@
#define Buffer_Backify_Type cat_4tech(Buffer_Type, _Backify_Loop) #define Buffer_Backify_Type cat_4tech(Buffer_Type, _Backify_Loop)
inline_4tech void inline_4tech void
buffer_stringify(Buffer_Type *buffer, int start, int end, char *out){ buffer_stringify(Buffer_Type *buffer, i32 start, i32 end, char *out){
for (Buffer_Stringify_Type loop = buffer_stringify_loop(buffer, start, end); for (Buffer_Stringify_Type loop = buffer_stringify_loop(buffer, start, end);
buffer_stringify_good(&loop); buffer_stringify_good(&loop);
buffer_stringify_next(&loop)){ buffer_stringify_next(&loop)){
@ -24,10 +24,10 @@ buffer_stringify(Buffer_Type *buffer, int start, int end, char *out){
} }
} }
internal_4tech int internal_4tech i32
buffer_convert_out(Buffer_Type *buffer, char *dest, int max){ buffer_convert_out(Buffer_Type *buffer, char *dest, i32 max){
Buffer_Stringify_Type loop; Buffer_Stringify_Type loop;
int size, out_size, pos, result; i32 size, out_size, pos, result;
size = buffer_size(buffer); size = buffer_size(buffer);
assert_4tech(size + buffer->line_count < max); assert_4tech(size + buffer->line_count < max);
@ -44,11 +44,11 @@ buffer_convert_out(Buffer_Type *buffer, char *dest, int max){
return(pos); return(pos);
} }
internal_4tech int internal_4tech i32
buffer_count_newlines(Buffer_Type *buffer, int start, int end){ buffer_count_newlines(Buffer_Type *buffer, i32 start, i32 end){
Buffer_Stringify_Type loop; Buffer_Stringify_Type loop;
int i; i32 i;
int count; i32 count;
assert_4tech(0 <= start); assert_4tech(0 <= start);
assert_4tech(start <= end); assert_4tech(start <= end);
@ -69,25 +69,25 @@ buffer_count_newlines(Buffer_Type *buffer, int start, int end){
#ifndef NON_ABSTRACT_4TECH #ifndef NON_ABSTRACT_4TECH
typedef struct Buffer_Measure_Starts{ typedef struct Buffer_Measure_Starts{
int i; i32 i;
int count; i32 count;
int start; i32 start;
float width; f32 width;
} Buffer_Measure_Starts; } Buffer_Measure_Starts;
#endif #endif
internal_4tech int internal_4tech i32
buffer_measure_starts_widths_(Buffer_Measure_Starts *state, Buffer_Type *buffer, float *advance_data){ buffer_measure_starts_widths_(Buffer_Measure_Starts *state, Buffer_Type *buffer, f32 *advance_data){
Buffer_Stringify_Type loop; Buffer_Stringify_Type loop;
int *start_ptr, *start_end; i32 *start_ptr, *start_end;
float *width_ptr; f32 *width_ptr;
debug_4tech(int widths_max); debug_4tech(i32 widths_max);
debug_4tech(int max); debug_4tech(i32 max);
char *data; char *data;
int size, end; i32 size, end;
float width; f32 width;
int start, i; i32 start, i;
int result; i32 result;
char ch; char ch;
size = buffer_size(buffer); size = buffer_size(buffer);
@ -136,24 +136,24 @@ buffer_measure_starts_widths_(Buffer_Measure_Starts *state, Buffer_Type *buffer,
buffer_measure_starts_widths_end: buffer_measure_starts_widths_end:
state->i = i; state->i = i;
state->count = (int)(start_ptr - buffer->line_starts); state->count = (i32)(start_ptr - buffer->line_starts);
state->start = start; state->start = start;
state->width = width; state->width = width;
return(result); return(result);
} }
internal_4tech int internal_4tech i32
buffer_measure_starts_zero_widths_(Buffer_Measure_Starts *state, Buffer_Type *buffer){ buffer_measure_starts_zero_widths_(Buffer_Measure_Starts *state, Buffer_Type *buffer){
Buffer_Stringify_Type loop; Buffer_Stringify_Type loop;
int *start_ptr, *start_end; i32 *start_ptr, *start_end;
float *width_ptr; f32 *width_ptr;
debug_4tech(int widths_max); debug_4tech(i32 widths_max);
debug_4tech(int max); debug_4tech(i32 max);
char *data; char *data;
int size, end; i32 size, end;
int start, i; i32 start, i;
int result; i32 result;
char ch; char ch;
size = buffer_size(buffer); size = buffer_size(buffer);
@ -197,15 +197,15 @@ buffer_measure_starts_zero_widths_(Buffer_Measure_Starts *state, Buffer_Type *bu
buffer_measure_starts_zero_widths_end: buffer_measure_starts_zero_widths_end:
state->i = i; state->i = i;
state->count = (int)(start_ptr - buffer->line_starts); state->count = (i32)(start_ptr - buffer->line_starts);
state->start = start; state->start = start;
return(result); return(result);
} }
internal_4tech int internal_4tech i32
buffer_measure_starts_widths(Buffer_Measure_Starts *state, Buffer_Type *buffer, float *advance_data){ buffer_measure_starts_widths(Buffer_Measure_Starts *state, Buffer_Type *buffer, f32 *advance_data){
int result = 0; i32 result = 0;
if (advance_data){ if (advance_data){
result = buffer_measure_starts_widths_(state, buffer, advance_data); result = buffer_measure_starts_widths_(state, buffer, advance_data);
@ -218,13 +218,13 @@ buffer_measure_starts_widths(Buffer_Measure_Starts *state, Buffer_Type *buffer,
} }
internal_4tech void internal_4tech void
buffer_remeasure_starts(Buffer_Type *buffer, int line_start, int line_end, int line_shift, int text_shift){ buffer_remeasure_starts(Buffer_Type *buffer, i32 line_start, i32 line_end, i32 line_shift, i32 text_shift){
Buffer_Stringify_Type loop; Buffer_Stringify_Type loop;
int *starts = buffer->line_starts; i32 *starts = buffer->line_starts;
int line_count = buffer->line_count; i32 line_count = buffer->line_count;
char *data = 0; char *data = 0;
int size = 0, end = 0; i32 size = 0, end = 0;
int line_i = 0, char_i = 0, start = 0; i32 line_i = 0, char_i = 0, start = 0;
assert_4tech(0 <= line_start); assert_4tech(0 <= line_start);
assert_4tech(line_start <= line_end); assert_4tech(line_start <= line_end);
@ -243,7 +243,7 @@ buffer_remeasure_starts(Buffer_Type *buffer, int line_start, int line_end, int l
if (line_shift != 0){ if (line_shift != 0){
memmove_4tech(starts + line_end + line_shift, starts + line_end, memmove_4tech(starts + line_end + line_shift, starts + line_end,
sizeof(int)*(line_count - line_end)); sizeof(i32)*(line_count - line_end));
line_count += line_shift; line_count += line_shift;
} }
@ -277,17 +277,17 @@ buffer_remeasure_starts(Buffer_Type *buffer, int line_start, int line_end, int l
} }
internal_4tech void internal_4tech void
buffer_remeasure_widths(Buffer_Type *buffer, float *advance_data, buffer_remeasure_widths(Buffer_Type *buffer, f32 *advance_data,
int line_start, int line_end, int line_shift){ i32 line_start, i32 line_end, i32 line_shift){
Buffer_Stringify_Type loop; Buffer_Stringify_Type loop;
int *starts = buffer->line_starts; i32 *starts = buffer->line_starts;
float *widths = buffer->line_widths; f32 *widths = buffer->line_widths;
int line_count = buffer->line_count; i32 line_count = buffer->line_count;
int widths_count = buffer->widths_count; i32 widths_count = buffer->widths_count;
char *data = 0; char *data = 0;
int size = 0, end = 0; i32 size = 0, end = 0;
int i = 0, j = 0; i32 i = 0, j = 0;
float width = 0; f32 width = 0;
char ch = 0; char ch = 0;
assert_4tech(0 <= line_start); assert_4tech(0 <= line_start);
@ -297,7 +297,7 @@ buffer_remeasure_widths(Buffer_Type *buffer, float *advance_data,
++line_end; ++line_end;
if (line_shift != 0){ if (line_shift != 0){
memmove_4tech(widths + line_end + line_shift, widths + line_end, memmove_4tech(widths + line_end + line_shift, widths + line_end,
sizeof(float)*(widths_count - line_end)); sizeof(f32)*(widths_count - line_end));
} }
buffer->widths_count = line_count; buffer->widths_count = line_count;
@ -345,11 +345,11 @@ buffer_measure_widths(Buffer_Type *buffer, void *advance_data){
#endif #endif
internal_4tech void internal_4tech void
buffer_measure_wrap_y(Buffer_Type *buffer, float *wraps, buffer_measure_wrap_y(Buffer_Type *buffer, f32 *wraps,
float font_height, float max_width){ f32 font_height, f32 max_width){
float *widths; f32 *widths;
float y_pos; f32 y_pos;
int i, line_count; i32 i, line_count;
line_count = buffer->line_count; line_count = buffer->line_count;
widths = buffer->line_widths; widths = buffer->line_widths;
@ -362,11 +362,11 @@ buffer_measure_wrap_y(Buffer_Type *buffer, float *wraps,
} }
} }
internal_4tech int internal_4tech i32
buffer_get_line_index_range(Buffer_Type *buffer, int pos, int l_bound, int u_bound){ buffer_get_line_index_range(Buffer_Type *buffer, i32 pos, i32 l_bound, i32 u_bound){
int *lines; i32 *lines;
int start, end; i32 start, end;
int i; i32 i;
assert_4tech(0 <= l_bound); assert_4tech(0 <= l_bound);
assert_4tech(l_bound <= u_bound); assert_4tech(l_bound <= u_bound);
@ -393,16 +393,16 @@ buffer_get_line_index_range(Buffer_Type *buffer, int pos, int l_bound, int u_bou
return(start); return(start);
} }
inline_4tech int inline_4tech i32
buffer_get_line_index(Buffer_Type *buffer, int pos){ buffer_get_line_index(Buffer_Type *buffer, i32 pos){
int result = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count); i32 result = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count);
return(result); return(result);
} }
#ifndef NON_ABSTRACT_4TECH #ifndef NON_ABSTRACT_4TECH
internal_4tech int internal_4tech i32
buffer_get_line_index_from_wrapped_y(float *wraps, float y, float font_height, int l_bound, int u_bound){ buffer_get_line_index_from_wrapped_y(f32 *wraps, f32 y, f32 font_height, i32 l_bound, i32 u_bound){
int start, end, i, result; i32 start, end, i, result;
start = l_bound; start = l_bound;
end = u_bound; end = u_bound;
for (;;){ for (;;){
@ -428,13 +428,13 @@ typedef struct Seek_State{
Full_Cursor prev_cursor; Full_Cursor prev_cursor;
} Seek_State; } Seek_State;
internal_4tech int internal_4tech i32
cursor_seek_step(Seek_State *state, Buffer_Seek seek, int xy_seek, float max_width, cursor_seek_step(Seek_State *state, Buffer_Seek seek, i32 xy_seek, f32 max_width,
float font_height, float *advances, int size, char ch){ f32 font_height, f32 *advances, i32 size, char ch){
Full_Cursor cursor, prev_cursor; Full_Cursor cursor, prev_cursor;
float ch_width; f32 ch_width;
int result; i32 result;
float x, px, y; f32 x, px, y;
cursor = state->cursor; cursor = state->cursor;
prev_cursor = state->prev_cursor; prev_cursor = state->prev_cursor;
@ -453,8 +453,8 @@ cursor_seek_step(Seek_State *state, Buffer_Seek seek, int xy_seek, float max_wid
default: default:
++cursor.character; ++cursor.character;
if (ch == '\r') ch_width = *(float*)(advances + '\\') + *(float*)(advances + 'r'); if (ch == '\r') ch_width = *(f32*)(advances + '\\') + *(f32*)(advances + 'r');
else ch_width = *(float*)(advances + ch); else ch_width = *(f32*)(advances + ch);
if (cursor.wrapped_x + ch_width >= max_width){ if (cursor.wrapped_x + ch_width >= max_width){
cursor.wrapped_y += font_height; cursor.wrapped_y += font_height;
@ -536,16 +536,16 @@ cursor_seek_step(Seek_State *state, Buffer_Seek seek, int xy_seek, float max_wid
#endif #endif
internal_4tech Full_Cursor internal_4tech Full_Cursor
buffer_cursor_seek(Buffer_Type *buffer, Buffer_Seek seek, float max_width, buffer_cursor_seek(Buffer_Type *buffer, Buffer_Seek seek, f32 max_width,
float font_height, float *advance_data, Full_Cursor cursor){ f32 font_height, f32 *advance_data, Full_Cursor cursor){
Buffer_Stringify_Type loop; Buffer_Stringify_Type loop;
char *data; char *data;
int size, end; i32 size, end;
int i; i32 i;
int result; i32 result;
Seek_State state; Seek_State state;
int xy_seek; i32 xy_seek;
state.cursor = cursor; state.cursor = cursor;
@ -596,7 +596,7 @@ buffer_cursor_seek(Buffer_Type *buffer, Buffer_Seek seek, float max_width,
} }
internal_4tech Partial_Cursor internal_4tech Partial_Cursor
buffer_partial_from_pos(Buffer_Type *buffer, int pos){ buffer_partial_from_pos(Buffer_Type *buffer, i32 pos){
Partial_Cursor result = {0}; Partial_Cursor result = {0};
int32_t size = buffer_size(buffer); int32_t size = buffer_size(buffer);
@ -607,7 +607,7 @@ buffer_partial_from_pos(Buffer_Type *buffer, int pos){
pos = 0; pos = 0;
} }
int line_index = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count); i32 line_index = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count);
result.pos = pos; result.pos = pos;
result.line = line_index+1; result.line = line_index+1;
result.character = pos - buffer->line_starts[line_index] + 1; result.character = pos - buffer->line_starts[line_index] + 1;
@ -616,10 +616,10 @@ buffer_partial_from_pos(Buffer_Type *buffer, int pos){
} }
internal_4tech Full_Cursor internal_4tech Full_Cursor
buffer_cursor_from_pos(Buffer_Type *buffer, int pos, float *wraps, buffer_cursor_from_pos(Buffer_Type *buffer, i32 pos, f32 *wraps,
float max_width, float font_height, float *advance_data){ f32 max_width, f32 font_height, f32 *advance_data){
Full_Cursor result; Full_Cursor result;
int line_index; i32 line_index;
int32_t size = buffer_size(buffer); int32_t size = buffer_size(buffer);
if (pos > size){ if (pos > size){
@ -638,18 +638,18 @@ buffer_cursor_from_pos(Buffer_Type *buffer, int pos, float *wraps,
} }
internal_4tech Partial_Cursor internal_4tech Partial_Cursor
buffer_partial_from_line_character(Buffer_Type *buffer, int line, int character){ buffer_partial_from_line_character(Buffer_Type *buffer, i32 line, i32 character){
Partial_Cursor result = {0}; Partial_Cursor result = {0};
int line_index = line - 1; i32 line_index = line - 1;
if (line_index >= buffer->line_count) line_index = buffer->line_count - 1; if (line_index >= buffer->line_count) line_index = buffer->line_count - 1;
if (line_index < 0) line_index = 0; if (line_index < 0) line_index = 0;
int32_t size = buffer_size(buffer); int32_t size = buffer_size(buffer);
int this_start = buffer->line_starts[line_index]; i32 this_start = buffer->line_starts[line_index];
int max_character = (size-this_start) + 1; i32 max_character = (size-this_start) + 1;
if (line_index+1 < buffer->line_count){ if (line_index+1 < buffer->line_count){
int next_start = buffer->line_starts[line_index+1]; i32 next_start = buffer->line_starts[line_index+1];
max_character = (next_start-this_start); max_character = (next_start-this_start);
} }
@ -664,11 +664,11 @@ buffer_partial_from_line_character(Buffer_Type *buffer, int line, int character)
} }
internal_4tech Full_Cursor internal_4tech Full_Cursor
buffer_cursor_from_line_character(Buffer_Type *buffer, int line, int character, float *wraps, buffer_cursor_from_line_character(Buffer_Type *buffer, i32 line, i32 character, f32 *wraps,
float max_width, float font_height, float *advance_data){ f32 max_width, f32 font_height, f32 *advance_data){
Full_Cursor result = {0}; Full_Cursor result = {0};
int line_index = line - 1; i32 line_index = line - 1;
if (line_index >= buffer->line_count) line_index = buffer->line_count - 1; if (line_index >= buffer->line_count) line_index = buffer->line_count - 1;
if (line_index < 0) line_index = 0; if (line_index < 0) line_index = 0;
@ -680,12 +680,12 @@ buffer_cursor_from_line_character(Buffer_Type *buffer, int line, int character,
} }
internal_4tech Full_Cursor internal_4tech Full_Cursor
buffer_cursor_from_unwrapped_xy(Buffer_Type *buffer, float x, float y, int round_down, float *wraps, buffer_cursor_from_unwrapped_xy(Buffer_Type *buffer, f32 x, f32 y, i32 round_down, f32 *wraps,
float max_width, float font_height, float *advance_data){ f32 max_width, f32 font_height, f32 *advance_data){
Full_Cursor result; Full_Cursor result;
int line_index; i32 line_index;
line_index = (int)(y / font_height); line_index = (i32)(y / font_height);
if (line_index >= buffer->line_count) line_index = buffer->line_count - 1; if (line_index >= buffer->line_count) line_index = buffer->line_count - 1;
if (line_index < 0) line_index = 0; if (line_index < 0) line_index = 0;
@ -697,10 +697,10 @@ buffer_cursor_from_unwrapped_xy(Buffer_Type *buffer, float x, float y, int round
} }
internal_4tech Full_Cursor internal_4tech Full_Cursor
buffer_cursor_from_wrapped_xy(Buffer_Type *buffer, float x, float y, int round_down, float *wraps, buffer_cursor_from_wrapped_xy(Buffer_Type *buffer, f32 x, f32 y, i32 round_down, f32 *wraps,
float max_width, float font_height, float *advance_data){ f32 max_width, f32 font_height, f32 *advance_data){
Full_Cursor result; Full_Cursor result;
int line_index; i32 line_index;
line_index = buffer_get_line_index_from_wrapped_y(wraps, y, font_height, 0, buffer->line_count); line_index = buffer_get_line_index_from_wrapped_y(wraps, y, font_height, 0, buffer->line_count);
result = make_cursor_hint(line_index, buffer->line_starts, wraps, font_height); result = make_cursor_hint(line_index, buffer->line_starts, wraps, font_height);
@ -712,9 +712,9 @@ buffer_cursor_from_wrapped_xy(Buffer_Type *buffer, float x, float y, int round_d
internal_4tech void internal_4tech void
buffer_invert_edit_shift(Buffer_Type *buffer, Buffer_Edit edit, Buffer_Edit *inverse, char *strings, buffer_invert_edit_shift(Buffer_Type *buffer, Buffer_Edit edit, Buffer_Edit *inverse, char *strings,
int *str_pos, int max, int shift_amount){ i32 *str_pos, i32 max, i32 shift_amount){
int pos = *str_pos; i32 pos = *str_pos;
int len = edit.end - edit.start; i32 len = edit.end - edit.start;
assert_4tech(pos >= 0); assert_4tech(pos >= 0);
assert_4tech(pos + len <= max); assert_4tech(pos + len <= max);
*str_pos = pos + len; *str_pos = pos + len;
@ -728,25 +728,25 @@ buffer_invert_edit_shift(Buffer_Type *buffer, Buffer_Edit edit, Buffer_Edit *inv
inline_4tech void inline_4tech void
buffer_invert_edit(Buffer_Type *buffer, Buffer_Edit edit, Buffer_Edit *inverse, char *strings, buffer_invert_edit(Buffer_Type *buffer, Buffer_Edit edit, Buffer_Edit *inverse, char *strings,
int *str_pos, int max){ i32 *str_pos, i32 max){
buffer_invert_edit_shift(buffer, edit, inverse, strings, str_pos, max, 0); buffer_invert_edit_shift(buffer, edit, inverse, strings, str_pos, max, 0);
} }
#ifndef NON_ABSTRACT_4TECH #ifndef NON_ABSTRACT_4TECH
typedef struct Buffer_Invert_Batch{ typedef struct Buffer_Invert_Batch{
int i; i32 i;
int shift_amount; i32 shift_amount;
int len; i32 len;
} Buffer_Invert_Batch; } Buffer_Invert_Batch;
#endif #endif
internal_4tech int internal_4tech i32
buffer_invert_batch(Buffer_Invert_Batch *state, Buffer_Type *buffer, Buffer_Edit *edits, int count, buffer_invert_batch(Buffer_Invert_Batch *state, Buffer_Type *buffer, Buffer_Edit *edits, i32 count,
Buffer_Edit *inverse, char *strings, int *str_pos, int max){ Buffer_Edit *inverse, char *strings, i32 *str_pos, i32 max){
Buffer_Edit *edit, *inv_edit; Buffer_Edit *edit, *inv_edit;
int shift_amount; i32 shift_amount;
int result; i32 result;
int i; i32 i;
result = 0; result = 0;
i = state->i; i = state->i;
@ -777,8 +777,8 @@ struct Buffer_Render_Options{
}; };
internal_4tech Full_Cursor internal_4tech Full_Cursor
buffer_get_start_cursor(Buffer_Type *buffer, float *wraps, float scroll_y, buffer_get_start_cursor(Buffer_Type *buffer, f32 *wraps, f32 scroll_y,
int wrapped, float width, float *advance_data, float font_height){ i32 wrapped, f32 width, f32 *advance_data, f32 font_height){
Full_Cursor result; Full_Cursor result;
if (wrapped){ if (wrapped){
@ -796,19 +796,19 @@ buffer_get_start_cursor(Buffer_Type *buffer, float *wraps, float scroll_y,
#define BRFlag_Special_Character (1 << 0) #define BRFlag_Special_Character (1 << 0)
typedef struct Buffer_Render_Item{ typedef struct Buffer_Render_Item{
int index; i32 index;
unsigned short glyphid; unsigned short glyphid;
unsigned short flags; unsigned short flags;
float x0, y0; f32 x0, y0;
float x1, y1; f32 x1, y1;
} Buffer_Render_Item; } Buffer_Render_Item;
inline_4tech void inline_4tech void
write_render_item(Buffer_Render_Item *item, write_render_item(Buffer_Render_Item *item,
int index, i32 index,
unsigned short glyphid, unsigned short glyphid,
float x, float y, f32 x, f32 y,
float w, float h){ f32 w, f32 h){
item->index = index; item->index = index;
item->glyphid = glyphid; item->glyphid = glyphid;
item->x0 = x; item->x0 = x;
@ -817,36 +817,36 @@ write_render_item(Buffer_Render_Item *item,
item->y1 = y + h; item->y1 = y + h;
} }
inline_4tech float inline_4tech f32
write_render_item_inline(Buffer_Render_Item *item, write_render_item_inline(Buffer_Render_Item *item,
int index, i32 index,
unsigned short glyphid, unsigned short glyphid,
float x, float y, f32 x, f32 y,
float *advance_data, float h){ f32 *advance_data, f32 h){
float ch_width; f32 ch_width;
ch_width = measure_character(advance_data, (char)glyphid); ch_width = measure_character(advance_data, (char)glyphid);
write_render_item(item, index, glyphid, x, y, ch_width, h); write_render_item(item, index, glyphid, x, y, ch_width, h);
return(ch_width); return(ch_width);
} }
internal_4tech void internal_4tech void
buffer_get_render_data(Buffer_Type *buffer, Buffer_Render_Item *items, int max, int *count, buffer_get_render_data(Buffer_Type *buffer, Buffer_Render_Item *items, i32 max, i32 *count,
float port_x, float port_y, f32 port_x, f32 port_y,
float scroll_x, float scroll_y, Full_Cursor start_cursor, f32 scroll_x, f32 scroll_y, Full_Cursor start_cursor,
int wrapped, i32 wrapped,
float width, float height, f32 width, f32 height,
float *advance_data, float font_height, f32 *advance_data, f32 font_height,
Buffer_Render_Options opts){ Buffer_Render_Options opts){
Buffer_Stringify_Type loop; Buffer_Stringify_Type loop;
Buffer_Render_Item *item; Buffer_Render_Item *item;
Buffer_Render_Item *item_end; Buffer_Render_Item *item_end;
char *data; char *data;
int size, end; i32 size, end;
float shift_x, shift_y; f32 shift_x, shift_y;
float x, y; f32 x, y;
int i, item_i; i32 i, item_i;
float ch_width, ch_width_sub; f32 ch_width, ch_width_sub;
uint8_t ch; uint8_t ch;
size = buffer_size(buffer); size = buffer_size(buffer);

View File

@ -1,13 +1,9 @@
/* /*
* Mr. 4th Dimention - Allen Webster * Mr. 4th Dimention - Allen Webster
* Four Tech
*
* public domain -- no warranty is offered or implied; use this code at your own risk
* *
* 23.10.2015 * 23.10.2015
* *
* Buffer data object * An implementation of a gap buffer.
* type - Gap Buffer
* *
*/ */
@ -15,39 +11,39 @@
typedef struct Gap_Buffer{ typedef struct Gap_Buffer{
char *data; char *data;
int size1; i32 size1;
int gap_size; i32 gap_size;
int size2; i32 size2;
int max; i32 max;
float *line_widths; f32 *line_widths;
int *line_starts; i32 *line_starts;
int line_count; i32 line_count;
int widths_count; i32 widths_count;
int line_max; i32 line_max;
int widths_max; i32 widths_max;
} Gap_Buffer; } Gap_Buffer;
inline_4tech int inline_4tech i32
buffer_good(Gap_Buffer *buffer){ buffer_good(Gap_Buffer *buffer){
int good = (buffer->data != 0); i32 good = (buffer->data != 0);
return(good); return(good);
} }
inline_4tech int inline_4tech i32
buffer_size(Gap_Buffer *buffer){ buffer_size(Gap_Buffer *buffer){
int size = buffer->size1 + buffer->size2; i32 size = buffer->size1 + buffer->size2;
return(size); return(size);
} }
typedef struct Gap_Buffer_Init{ typedef struct Gap_Buffer_Init{
Gap_Buffer *buffer; Gap_Buffer *buffer;
char *data; char *data;
int size; i32 size;
} Gap_Buffer_Init; } Gap_Buffer_Init;
internal_4tech Gap_Buffer_Init internal_4tech Gap_Buffer_Init
buffer_begin_init(Gap_Buffer *buffer, char *data, int size){ buffer_begin_init(Gap_Buffer *buffer, char *data, i32 size){
Gap_Buffer_Init init; Gap_Buffer_Init init;
init.buffer = buffer; init.buffer = buffer;
init.data = data; init.data = data;
@ -55,31 +51,31 @@ buffer_begin_init(Gap_Buffer *buffer, char *data, int size){
return(init); return(init);
} }
internal_4tech int internal_4tech i32
buffer_init_need_more(Gap_Buffer_Init *init){ buffer_init_need_more(Gap_Buffer_Init *init){
int result = 1; i32 result = 1;
if (init->buffer->data) result = 0; if (init->buffer->data) result = 0;
return(result); return(result);
} }
internal_4tech int internal_4tech i32
buffer_init_page_size(Gap_Buffer_Init *init){ buffer_init_page_size(Gap_Buffer_Init *init){
int result = init->size * 2; i32 result = init->size * 2;
return(result); return(result);
} }
internal_4tech void internal_4tech void
buffer_init_provide_page(Gap_Buffer_Init *init, void *page, int page_size){ buffer_init_provide_page(Gap_Buffer_Init *init, void *page, i32 page_size){
Gap_Buffer *buffer = init->buffer; Gap_Buffer *buffer = init->buffer;
buffer->data = (char*)page; buffer->data = (char*)page;
buffer->max = page_size; buffer->max = page_size;
} }
internal_4tech int internal_4tech i32
buffer_end_init(Gap_Buffer_Init *init, void *scratch, int scratch_size){ buffer_end_init(Gap_Buffer_Init *init, void *scratch, i32 scratch_size){
Gap_Buffer *buffer = init->buffer; Gap_Buffer *buffer = init->buffer;
int osize1 = 0, size1 = 0, size2 = 0, size = init->size; i32 osize1 = 0, size1 = 0, size2 = 0, size = init->size;
int result = 0; i32 result = 0;
if (buffer->data){ if (buffer->data){
if (buffer->max >= init->size){ if (buffer->max >= init->size){
@ -108,14 +104,14 @@ buffer_end_init(Gap_Buffer_Init *init, void *scratch, int scratch_size){
typedef struct Gap_Buffer_Stringify_Loop{ typedef struct Gap_Buffer_Stringify_Loop{
Gap_Buffer *buffer; Gap_Buffer *buffer;
char *data, *base; char *data, *base;
int absolute_pos; i32 absolute_pos;
int pos, end; i32 pos, end;
int size; i32 size;
int separated; i32 separated;
} Gap_Buffer_Stringify_Loop; } Gap_Buffer_Stringify_Loop;
internal_4tech Gap_Buffer_Stringify_Loop internal_4tech Gap_Buffer_Stringify_Loop
buffer_stringify_loop(Gap_Buffer *buffer, int start, int end){ buffer_stringify_loop(Gap_Buffer *buffer, i32 start, i32 end){
Gap_Buffer_Stringify_Loop result = {0}; Gap_Buffer_Stringify_Loop result = {0};
if (0 <= start && start < end && end <= buffer->size1 + buffer->size2){ if (0 <= start && start < end && end <= buffer->size1 + buffer->size2){
@ -157,15 +153,15 @@ buffer_stringify_loop(Gap_Buffer *buffer, int start, int end){
return(result); return(result);
} }
inline_4tech int inline_4tech i32
buffer_stringify_good(Gap_Buffer_Stringify_Loop *loop){ buffer_stringify_good(Gap_Buffer_Stringify_Loop *loop){
int result = (loop->buffer != 0); i32 result = (loop->buffer != 0);
return(result); return(result);
} }
internal_4tech void internal_4tech void
buffer_stringify_next(Gap_Buffer_Stringify_Loop *loop){ buffer_stringify_next(Gap_Buffer_Stringify_Loop *loop){
int size1 = 0, temp_end = 0; i32 size1 = 0, temp_end = 0;
if (loop->separated){ if (loop->separated){
loop->separated = 0; loop->separated = 0;
size1 = loop->buffer->size1; size1 = loop->buffer->size1;
@ -184,14 +180,14 @@ buffer_stringify_next(Gap_Buffer_Stringify_Loop *loop){
typedef struct Gap_Buffer_Backify_Loop{ typedef struct Gap_Buffer_Backify_Loop{
Gap_Buffer *buffer; Gap_Buffer *buffer;
char *data, *base; char *data, *base;
int pos, end; i32 pos, end;
int size; i32 size;
int absolute_pos; i32 absolute_pos;
int separated; i32 separated;
} Gap_Buffer_Backify_Loop; } Gap_Buffer_Backify_Loop;
internal_4tech Gap_Buffer_Backify_Loop internal_4tech Gap_Buffer_Backify_Loop
buffer_backify_loop(Gap_Buffer *buffer, int start, int end){ buffer_backify_loop(Gap_Buffer *buffer, i32 start, i32 end){
Gap_Buffer_Backify_Loop result = {0}; Gap_Buffer_Backify_Loop result = {0};
++start; ++start;
@ -235,16 +231,16 @@ buffer_backify_loop(Gap_Buffer *buffer, int start, int end){
return(result); return(result);
} }
inline_4tech int inline_4tech i32
buffer_backify_good(Gap_Buffer_Backify_Loop *loop){ buffer_backify_good(Gap_Buffer_Backify_Loop *loop){
int result = (loop->buffer != 0); i32 result = (loop->buffer != 0);
return(result); return(result);
} }
internal_4tech void internal_4tech void
buffer_backify_next(Gap_Buffer_Backify_Loop *loop){ buffer_backify_next(Gap_Buffer_Backify_Loop *loop){
Gap_Buffer *buffer = loop->buffer; Gap_Buffer *buffer = loop->buffer;
int temp_end = 0; i32 temp_end = 0;
if (loop->separated){ if (loop->separated){
loop->separated = 0; loop->separated = 0;
@ -265,13 +261,13 @@ buffer_backify_next(Gap_Buffer_Backify_Loop *loop){
loop->data = loop->base + loop->pos; loop->data = loop->base + loop->pos;
} }
internal_4tech int internal_4tech i32
buffer_replace_range(Gap_Buffer *buffer, int start, int end, char *str, int len, int *shift_amount, buffer_replace_range(Gap_Buffer *buffer, i32 start, i32 end, char *str, i32 len, i32 *shift_amount,
void *scratch, int scratch_memory, int *request_amount){ void *scratch, i32 scratch_memory, i32 *request_amount){
char *data = buffer->data; char *data = buffer->data;
int size = buffer_size(buffer); i32 size = buffer_size(buffer);
int result = 0; i32 result = 0;
int move_size = 0; i32 move_size = 0;
assert_4tech(0 <= start); assert_4tech(0 <= start);
assert_4tech(start <= end); assert_4tech(start <= end);
@ -309,14 +305,14 @@ buffer_replace_range(Gap_Buffer *buffer, int start, int end, char *str, int len,
} }
// NOTE(allen): This could should be optimized for Gap_Buffer // NOTE(allen): This could should be optimized for Gap_Buffer
internal_4tech int internal_4tech i32
buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edit *sorted_edits, buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edit *sorted_edits,
char *strings, int edit_count, void *scratch, int scratch_size, int *request_amount){ char *strings, i32 edit_count, void *scratch, i32 scratch_size, i32 *request_amount){
Buffer_Edit *edit = 0; Buffer_Edit *edit = 0;
int i = state->i; i32 i = state->i;
int shift_total = state->shift_total; i32 shift_total = state->shift_total;
int shift_amount = 0; i32 shift_amount = 0;
int result = 0; i32 result = 0;
edit = sorted_edits + i; edit = sorted_edits + i;
for (; i < edit_count; ++i, ++edit){ for (; i < edit_count; ++i, ++edit){
@ -334,10 +330,10 @@ buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edi
} }
internal_4tech void* internal_4tech void*
buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, int new_max){ buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, i32 new_max){
void *result = buffer->data; void *result = buffer->data;
int size = buffer_size(buffer); i32 size = buffer_size(buffer);
int new_gap_size = new_max - size; i32 new_gap_size = new_max - size;
assert_4tech(new_max >= size); assert_4tech(new_max >= size);

View File

@ -1,8 +1,5 @@
/* /*
* Mr. 4th Dimention - Allen Webster * Mr. 4th Dimention - Allen Webster
* Four Tech
*
* public domain -- no warranty is offered or implied; use this code at your own risk
* *
* 23.10.2015 * 23.10.2015
* *
@ -12,6 +9,8 @@
// TOP // TOP
// TODO(allen): eliminate the extra defs and the extra include.
#include "../4coder_seek_types.h" #include "../4coder_seek_types.h"
#ifndef inline_4tech #ifndef inline_4tech
@ -27,7 +26,9 @@
#endif #endif
#ifndef memzero_4tech #ifndef memzero_4tech
#define memzero_4tech(x) ((x) = {}) #define memzero_4tech(x) do{ \
char *p = (char*)&x; char *e = p + sizeof(x); \
for (;p<e; ++p) {*p=0;} }while(0)
#endif #endif
#ifndef memcpy_4tech #ifndef memcpy_4tech
@ -60,9 +61,9 @@
#endif #endif
#ifndef round_up_4tech #ifndef round_up_4tech
internal_4tech int internal_4tech i32
lroundup_(int x, int granularity){ lroundup_(i32 x, i32 granularity){
int original_x; i32 original_x;
original_x = x; original_x = x;
x /= granularity; x /= granularity;
x *= granularity; x *= granularity;
@ -79,17 +80,17 @@ lroundup_(int x, int granularity){
#define measure_character(a,c) ((a)[c]) #define measure_character(a,c) ((a)[c])
typedef struct Buffer_Batch_State{ typedef struct Buffer_Batch_State{
int i; i32 i;
int shift_total; i32 shift_total;
} Buffer_Batch_State; } Buffer_Batch_State;
inline_4tech Full_Cursor inline_4tech Full_Cursor
make_cursor_hint(int line_index, int *starts, float *wrap_ys, float font_height){ make_cursor_hint(i32 line_index, i32 *starts, f32 *wrap_ys, f32 font_height){
Full_Cursor hint; Full_Cursor hint;
hint.pos = starts[line_index]; hint.pos = starts[line_index];
hint.line = line_index + 1; hint.line = line_index + 1;
hint.character = 1; hint.character = 1;
hint.unwrapped_y = (float)(line_index * font_height); hint.unwrapped_y = (f32)(line_index * font_height);
hint.unwrapped_x = 0; hint.unwrapped_x = 0;
hint.wrapped_y = wrap_ys[line_index]; hint.wrapped_y = wrap_ys[line_index];
hint.wrapped_x = 0; hint.wrapped_x = 0;
@ -97,11 +98,11 @@ make_cursor_hint(int line_index, int *starts, float *wrap_ys, float font_height)
} }
typedef struct Cursor_With_Index{ typedef struct Cursor_With_Index{
int pos, index; i32 pos, index;
} Cursor_With_Index; } Cursor_With_Index;
inline_4tech void inline_4tech void
write_cursor_with_index(Cursor_With_Index *positions, int *count, int pos){ write_cursor_with_index(Cursor_With_Index *positions, i32 *count, i32 pos){
positions[*count].index = *count; positions[*count].index = *count;
positions[*count].pos = pos; positions[*count].pos = pos;
++*count; ++*count;
@ -110,9 +111,9 @@ write_cursor_with_index(Cursor_With_Index *positions, int *count, int pos){
#define CursorSwap__(a,b) { Cursor_With_Index t = a; a = b; b = t; } #define CursorSwap__(a,b) { Cursor_With_Index t = a; a = b; b = t; }
internal_4tech void internal_4tech void
buffer_quick_sort_cursors(Cursor_With_Index *positions, int start, int pivot){ buffer_quick_sort_cursors(Cursor_With_Index *positions, i32 start, i32 pivot){
int i, mid; i32 i, mid;
int pivot_pos; i32 pivot_pos;
mid = start; mid = start;
pivot_pos = positions[pivot].pos; pivot_pos = positions[pivot].pos;
@ -129,9 +130,9 @@ buffer_quick_sort_cursors(Cursor_With_Index *positions, int start, int pivot){
} }
internal_4tech void internal_4tech void
buffer_quick_unsort_cursors(Cursor_With_Index *positions, int start, int pivot){ buffer_quick_unsort_cursors(Cursor_With_Index *positions, i32 start, i32 pivot){
int i, mid; i32 i, mid;
int pivot_index; i32 pivot_index;
mid = start; mid = start;
pivot_index = positions[pivot].index; pivot_index = positions[pivot].index;
@ -150,50 +151,47 @@ buffer_quick_unsort_cursors(Cursor_With_Index *positions, int start, int pivot){
#undef CursorSwap__ #undef CursorSwap__
inline_4tech void inline_4tech void
buffer_sort_cursors(Cursor_With_Index *positions, int count){ buffer_sort_cursors(Cursor_With_Index *positions, i32 count){
assert_4tech(count > 0); assert_4tech(count > 0);
buffer_quick_sort_cursors(positions, 0, count-1); buffer_quick_sort_cursors(positions, 0, count-1);
} }
inline_4tech void inline_4tech void
buffer_unsort_cursors(Cursor_With_Index *positions, int count){ buffer_unsort_cursors(Cursor_With_Index *positions, i32 count){
assert_4tech(count > 0); assert_4tech(count > 0);
buffer_quick_unsort_cursors(positions, 0, count-1); buffer_quick_unsort_cursors(positions, 0, count-1);
} }
internal_4tech void internal_4tech void
buffer_update_cursors(Cursor_With_Index *sorted_positions, int count, int start, int end, int len){ buffer_update_cursors(Cursor_With_Index *sorted_positions, i32 count, i32 start, i32 end, i32 len){
int shift_amount = (len - (end - start)); i32 shift_amount = (len - (end - start));
Cursor_With_Index *position = sorted_positions + count - 1; Cursor_With_Index *position = sorted_positions + count - 1;
for (; position >= sorted_positions && position->pos > end; --position) position->pos += shift_amount; for (; position >= sorted_positions && position->pos > end; --position) position->pos += shift_amount;
for (; position >= sorted_positions && position->pos >= start; --position) position->pos = start; for (; position >= sorted_positions && position->pos >= start; --position) position->pos = start;
} }
internal_4tech int internal_4tech i32
buffer_batch_debug_sort_check(Buffer_Edit *sorted_edits, int edit_count){ buffer_batch_debug_sort_check(Buffer_Edit *sorted_edits, i32 edit_count){
Buffer_Edit *edit; Buffer_Edit *edit = sorted_edits;
int i, result, start_point; i32 i = 0, start_point = 0;
i32 result = 1;
result = 1;
start_point = 0;
edit = sorted_edits;
for (i = 0; i < edit_count; ++i, ++edit){ for (i = 0; i < edit_count; ++i, ++edit){
if (start_point > edit->start){ if (start_point > edit->start){
result = 0; break; result = 0; break;
} }
start_point = (edit->end < edit->start + 1)?edit->start + 1:edit->end; start_point = (edit->end < edit->start + 1)?(edit->start + 1):(edit->end);
} }
return(result); return(result);
} }
internal_4tech int internal_4tech i32
buffer_batch_edit_max_shift(Buffer_Edit *sorted_edits, int edit_count){ buffer_batch_edit_max_shift(Buffer_Edit *sorted_edits, i32 edit_count){
Buffer_Edit *edit; Buffer_Edit *edit;
int i, result; i32 i, result;
int shift_total, shift_max; i32 shift_total, shift_max;
result = 0; result = 0;
shift_total = 0; shift_total = 0;
@ -208,12 +206,12 @@ buffer_batch_edit_max_shift(Buffer_Edit *sorted_edits, int edit_count){
return(shift_max); return(shift_max);
} }
internal_4tech int internal_4tech i32
buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, int count, Buffer_Edit *sorted_edits, int edit_count){ buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, i32 count, Buffer_Edit *sorted_edits, i32 edit_count){
Cursor_With_Index *position, *end_position; Cursor_With_Index *position, *end_position;
Buffer_Edit *edit, *end_edit; Buffer_Edit *edit, *end_edit;
int start, end; i32 start, end;
int shift_amount; i32 shift_amount;
position = sorted_positions; position = sorted_positions;
end_position = sorted_positions + count; end_position = sorted_positions + count;
@ -249,9 +247,9 @@ buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, int count,
return(shift_amount); return(shift_amount);
} }
internal_4tech int internal_4tech i32
eol_convert_in(char *dest, char *src, int size){ eol_convert_in(char *dest, char *src, i32 size){
int i, j, k; i32 i, j, k;
i = 0; i = 0;
k = 0; k = 0;
@ -277,9 +275,9 @@ eol_convert_in(char *dest, char *src, int size){
return(j); return(j);
} }
internal_4tech int internal_4tech i32
eol_in_place_convert_in(char *data, int size){ eol_in_place_convert_in(char *data, i32 size){
int i, j, k; i32 i, j, k;
i = 0; i = 0;
k = 0; k = 0;
@ -304,10 +302,10 @@ eol_in_place_convert_in(char *data, int size){
return(j); return(j);
} }
internal_4tech int internal_4tech i32
eol_convert_out(char *dest, int max, char *src, int size, int *size_out){ eol_convert_out(char *dest, i32 max, char *src, i32 size, i32 *size_out){
int result; i32 result;
int i, j; i32 i, j;
// TODO(allen): iterative memory check? // TODO(allen): iterative memory check?
result = 1; result = 1;
@ -327,10 +325,10 @@ eol_convert_out(char *dest, int max, char *src, int size, int *size_out){
return(result); return(result);
} }
internal_4tech int internal_4tech i32
eol_in_place_convert_out(char *data, int size, int max, int *size_out){ eol_in_place_convert_out(char *data, i32 size, i32 max, i32 *size_out){
int result; i32 result;
int i; i32 i;
// TODO(allen): iterative memory check? // TODO(allen): iterative memory check?
result = 1; result = 1;
@ -349,29 +347,29 @@ eol_in_place_convert_out(char *data, int size, int max, int *size_out){
return(result); return(result);
} }
inline_4tech int inline_4tech i32
is_whitespace(char c){ is_whitespace(char c){
int result; i32 result;
result = (c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '\f' || c == '\v'); result = (c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '\f' || c == '\v');
return(result); return(result);
} }
inline_4tech int inline_4tech i32
is_alphanumeric_true(char c){ is_alphanumeric_true(char c){
return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9'); return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9');
} }
inline_4tech int inline_4tech i32
is_alphanumeric(char c){ is_alphanumeric(char c){
return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '_'); return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '_');
} }
inline_4tech int inline_4tech i32
is_upper(char c){ is_upper(char c){
return (c >= 'A' && c <= 'Z'); return (c >= 'A' && c <= 'Z');
} }
inline_4tech int inline_4tech i32
is_lower(char c){ is_lower(char c){
return (c >= 'a' && c <= 'z'); return (c >= 'a' && c <= 'z');
} }
@ -384,9 +382,9 @@ to_upper(char c){
return(c); return(c);
} }
internal_4tech int internal_4tech i32
is_match(char *a, char *b, int len){ is_match(char *a, char *b, i32 len){
int result; i32 result;
result = 1; result = 1;
for (;len > 0; --len, ++a, ++b) for (;len > 0; --len, ++a, ++b)
@ -395,9 +393,9 @@ is_match(char *a, char *b, int len){
return(result); return(result);
} }
internal_4tech int internal_4tech i32
is_match_insensitive(char *a, char *b, int len){ is_match_insensitive(char *a, char *b, i32 len){
int result; i32 result;
result = 1; result = 1;
for (;len > 0; --len, ++a, ++b) for (;len > 0; --len, ++a, ++b)