From e37cce743ad2d6e33df0b46a08cd9579c6c22bd7 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Fri, 6 Jan 2017 21:59:55 -0500 Subject: [PATCH] lots of organization to files, figured out a good way to solve the build.cpp string problem and set it up --- 4coder_custom.h | 2 +- 4coder_default_include.cpp | 419 +++++----- 4coder_search.cpp | 34 +- 4coder_types.h | 36 +- 4cpp_lexer.h | 62 +- 4ed_app_target.cpp | 9 +- 4ed_file_view.cpp | 56 +- 4ed_math.h | 97 +-- 4ed_site.ctm | Bin 0 -> 340 bytes buffer/4coder_gap_buffer.cpp | 275 ------- buffer/4coder_shared.cpp | 389 --------- build.bat | 4 +- build.sh | 2 +- build_all.bat | 48 -- build_exp.bat | 14 - 4ed_defines.h => common/4coder_defines.h | 75 +- 4coder_version.h => common/4coder_version.h | 2 +- .../4coder_buffer.cpp | 741 +++++++++++++++--- file/4coder_file.cpp | 59 +- file/4coder_file_tests.cpp | 5 +- file/4coder_undo.cpp | 70 ++ filetrack/4tech_file_track_win32.c | 1 - linux_4ed.cpp | 10 +- 4ed_metagen.cpp => meta/4ed_metagen.cpp | 71 +- build.cpp => meta/build.cpp | 304 +++---- .../fsm_table_generator.cpp | 4 +- {site => meta}/meta_parser.cpp | 4 +- {site => meta}/out_context.cpp | 0 readme_generator.c => meta/readme_generator.c | 0 package.sh | 2 +- project.4coder | 3 +- site/abstract_document.cpp | 213 +++-- site/build.bat | 2 +- site/build.sh | 2 +- site/sitegen.cpp | 45 +- test/dll_reader.cpp | 206 ----- test/dll_test.cpp | 37 - test/experiment.cpp | 523 ------------ win32_4ed.cpp | 27 +- 39 files changed, 1361 insertions(+), 2492 deletions(-) create mode 100644 4ed_site.ctm delete mode 100644 buffer/4coder_gap_buffer.cpp delete mode 100644 buffer/4coder_shared.cpp delete mode 100644 build_all.bat delete mode 100644 build_exp.bat rename 4ed_defines.h => common/4coder_defines.h (75%) rename 4coder_version.h => common/4coder_version.h (95%) rename buffer/4coder_buffer_abstract.cpp => file/4coder_buffer.cpp (69%) create mode 100644 file/4coder_undo.cpp rename 4ed_metagen.cpp => meta/4ed_metagen.cpp (93%) rename build.cpp => meta/build.cpp (73%) rename fsm_table_generator.cpp => meta/fsm_table_generator.cpp (99%) rename {site => meta}/meta_parser.cpp (99%) rename {site => meta}/out_context.cpp (100%) rename readme_generator.c => meta/readme_generator.c (100%) delete mode 100644 test/dll_reader.cpp delete mode 100644 test/dll_test.cpp delete mode 100644 test/experiment.cpp diff --git a/4coder_custom.h b/4coder_custom.h index 4d36083b..e7dec44e 100644 --- a/4coder_custom.h +++ b/4coder_custom.h @@ -7,7 +7,7 @@ #include -#include "4coder_version.h" +#include "common/4coder_version.h" #include "4coder_keycodes.h" #include "4coder_style.h" #include "4coder_rect.h" diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index 57cfbb56..bdf5b1d5 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -435,13 +435,14 @@ static void buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t end, char *str, int32_t size, int32_t *result){ char read_buffer[512]; - if (size <= 0){ - *result = pos; - } - else if (size > sizeof(read_buffer)){ - *result = pos; + if (buffer->size > end){ + *result = buffer->size; } else{ + *result = end; + } + + if (size > 0 && size <= sizeof(read_buffer)){ if (buffer->exists){ String read_str = make_fixed_width_string(read_buffer); String needle_str = make_string(str, size); @@ -488,13 +489,9 @@ buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, int32 static void buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t min, char *str, int32_t size, int32_t *result){ char read_buffer[512]; - if (size <= 0){ - *result = min-1; - } - else if (size > sizeof(read_buffer)){ - *result = min-1; - } - else{ + + *result = min-1; + if (size > 0 && size <= sizeof(read_buffer)){ if (buffer->exists){ String read_str = make_fixed_width_string(read_buffer); String needle_str = make_string(str, size); @@ -524,8 +521,6 @@ buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, int3 } } - *result = min-1; - finished:; } } @@ -541,13 +536,14 @@ buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *b Stream_Chunk stream = {0}; stream.max_end = end; - if (size <= 0){ - *result = buffer->size; - } - else if (size > sizeof(read_buffer)){ + if (buffer->size > end){ *result = buffer->size; } else{ + *result = end; + } + + if (size > 0 && size <= sizeof(read_buffer)){ if (buffer->exists){ String read_str = make_fixed_width_string(read_buffer); String needle_str = make_string(str, size); @@ -573,8 +569,6 @@ buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *b } } - *result = buffer->size; - finished:; } } @@ -590,13 +584,8 @@ buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary * Stream_Chunk stream = {0}; stream.min_start = min; - if (size <= 0){ - *result = -1; - } - else if (size > sizeof(read_buffer)){ - *result = -1; - } - else{ + *result = min-1; + if (size > 0 && size <= sizeof(read_buffer)){ if (buffer->exists){ String read_str = make_fixed_width_string(read_buffer); String needle_str = make_string(str, size); @@ -622,8 +611,6 @@ buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary * } } - *result = -1; - finished:; } } @@ -3388,65 +3375,65 @@ read_config_line(Cpp_Token_Array array, int32_t *i_ptr){ } if (subscript_success){ - if (token.type == CPP_TOKEN_EQ){ - config_line.eq_token = read_config_token(array, &i); - ++i; - if (i < array.count){ - Cpp_Token val_token = read_config_token(array, &i); - - bool32 array_success = 1; - if (val_token.type == CPP_TOKEN_BRACE_OPEN){ - array_success = 0; - ++i; - if (i < array.count){ - config_line.val_array_start = i; - - bool32 expecting_array_item = 1; - for (; i < array.count; ++i){ - Cpp_Token array_token = read_config_token(array, &i); - if (array_token.size == 0){ - break; - } - if (array_token.type == CPP_TOKEN_BRACE_CLOSE){ - config_line.val_array_end = i; - array_success = 1; - break; - } - else{ - if (array_token.type == CPP_TOKEN_COMMA){ - if (!expecting_array_item){ - expecting_array_item = 1; - } - else{ - break; - } + if (token.type == CPP_TOKEN_EQ){ + config_line.eq_token = read_config_token(array, &i); + ++i; + if (i < array.count){ + Cpp_Token val_token = read_config_token(array, &i); + + bool32 array_success = 1; + if (val_token.type == CPP_TOKEN_BRACE_OPEN){ + array_success = 0; + ++i; + if (i < array.count){ + config_line.val_array_start = i; + + bool32 expecting_array_item = 1; + for (; i < array.count; ++i){ + Cpp_Token array_token = read_config_token(array, &i); + if (array_token.size == 0){ + break; + } + if (array_token.type == CPP_TOKEN_BRACE_CLOSE){ + config_line.val_array_end = i; + array_success = 1; + break; } else{ - if (expecting_array_item){ - expecting_array_item = 0; - ++config_line.val_array_count; + if (array_token.type == CPP_TOKEN_COMMA){ + if (!expecting_array_item){ + expecting_array_item = 1; + } + else{ + break; + } + } + else{ + if (expecting_array_item){ + expecting_array_item = 0; + ++config_line.val_array_count; + } } } } } } - } - - if (array_success){ - config_line.val_token = val_token; - ++i; - if (i < array.count){ - Cpp_Token semicolon_token = read_config_token(array, &i); - if (semicolon_token.type == CPP_TOKEN_SEMICOLON){ - config_line.read_success = 1; + + if (array_success){ + config_line.val_token = val_token; + ++i; + if (i < array.count){ + Cpp_Token semicolon_token = read_config_token(array, &i); + if (semicolon_token.type == CPP_TOKEN_SEMICOLON){ + config_line.read_success = 1; + } + } } } } - } } } } -} if (!config_line.read_success){ for (; i < array.count; ++i){ @@ -3469,7 +3456,7 @@ get_config_item(Config_Line line, char *mem, Cpp_Token_Array array){ item.array = array; item.mem = mem; if (line.id_token.size != 0){ - item.id = make_string(mem + line.id_token.start, line.id_token.size); + item.id = make_string(mem + line.id_token.start, line.id_token.size); } if (line.subscript_token.size != 0){ @@ -3488,48 +3475,48 @@ config_var(Config_Item item, char *var_name, int32_t *subscript, uint32_t token_ if (item.line.val_token.type == token_type){ if ((var_name == 0 && item.id.size == 0) || match(item.id, var_name)){ if (subscript){ - if (item.has_subscript){ - *subscript = item.subscript_index; - } - else{ - subscript_succes = 0; - } - } - - if (subscript_succes){ - if (var_out){ - switch (token_type){ - case CPP_TOKEN_BOOLEAN_CONSTANT: - { - *(bool32*)var_out = (item.mem[item.line.val_token.start] == 't'); - }break; - - case CPP_TOKEN_INTEGER_CONSTANT: - { - String val = make_string(item.mem + item.line.val_token.start, item.line.val_token.size); - *(int32_t*)var_out = str_to_int(val); - }break; - - case CPP_TOKEN_STRING_CONSTANT: - { - *(String*)var_out = make_string(item.mem + item.line.val_token.start + 1,item.line.val_token.size - 2); - }break; - - case CPP_TOKEN_BRACE_OPEN: - { - Config_Array_Reader *array_reader = (Config_Array_Reader*)var_out; - array_reader->array = item.array; - array_reader->mem = item.mem; - array_reader->i = item.line.val_array_start; - array_reader->val_array_end = item.line.val_array_end; - array_reader->good = 1; - }break; + if (item.has_subscript){ + *subscript = item.subscript_index; + } + else{ + subscript_succes = 0; } } - result = 1; + + if (subscript_succes){ + if (var_out){ + switch (token_type){ + case CPP_TOKEN_BOOLEAN_CONSTANT: + { + *(bool32*)var_out = (item.mem[item.line.val_token.start] == 't'); + }break; + + case CPP_TOKEN_INTEGER_CONSTANT: + { + String val = make_string(item.mem + item.line.val_token.start, item.line.val_token.size); + *(int32_t*)var_out = str_to_int(val); + }break; + + case CPP_TOKEN_STRING_CONSTANT: + { + *(String*)var_out = make_string(item.mem + item.line.val_token.start + 1,item.line.val_token.size - 2); + }break; + + case CPP_TOKEN_BRACE_OPEN: + { + Config_Array_Reader *array_reader = (Config_Array_Reader*)var_out; + array_reader->array = item.array; + array_reader->mem = item.mem; + array_reader->i = item.line.val_array_start; + array_reader->val_array_end = item.line.val_array_end; + array_reader->good = 1; + }break; + } + } + result = 1; + } } } -} return(result); } @@ -3585,9 +3572,9 @@ config_array_next_item(Config_Array_Reader *array_reader, Config_Item *item){ ++array_reader->i; goto doublebreak; }break; - } } - doublebreak:; + } + doublebreak:; array_reader->good = result; return(result); @@ -3689,16 +3676,16 @@ process_config_file(Application_Links *app){ config_bool_var(item, "enable_code_wrapping", 0, &enable_code_wrapping); config_bool_var(item, "automatically_adjust_wrapping", 0, &automatically_adjust_wrapping); config_bool_var(item, "automatically_indent_text_on_save", 0, &automatically_indent_text_on_save); - + config_int_var(item, "default_wrap_width", 0, &new_wrap_width); config_int_var(item, "default_min_base_width", 0, &new_min_base_width); - + config_string_var(item, "default_theme_name", 0, &default_theme_name); config_string_var(item, "default_font_name", 0, &default_font_name); - } - } - adjust_all_buffer_wrap_widths(app, new_wrap_width, new_min_base_width); - } + } + } + adjust_all_buffer_wrap_widths(app, new_wrap_width, new_min_base_width); + } } end_temp_memory(temp); @@ -3748,7 +3735,7 @@ set_project_extensions(Project *project, String src){ int32_t j = 0, k = 0; for (int32_t i = 0; i < src.size; ++i){ switch (mode){ - case 0: + case 0: { if (src.str[i] == '.'){ mode = 1; @@ -3766,7 +3753,7 @@ set_project_extensions(Project *project, String src){ project->extension_space[j++] = src.str[i]; } }break; - } + } } project->extension_space[j++] = 0; project->extension_count = k; @@ -3778,28 +3765,28 @@ interpret_escaped_string(char *dst, String src){ int32_t mode = 0; int32_t j = 0; for (int32_t i = 0; i < src.size; ++i){ - switch (mode){ + switch (mode){ case 0: { - if (src.str[i] == '\\'){ - mode = 1; + if (src.str[i] == '\\'){ + mode = 1; + } + else{ + dst[j++] = src.str[i]; + } + }break; + + case 1: + { + switch (src.str[i]){ + case '\\':{dst[j++] = '\\'; mode = 0;}break; + case 'n': {dst[j++] = '\n'; mode = 0;}break; + case 't': {dst[j++] = '\t'; mode = 0;}break; + case '"': {dst[j++] = '"'; mode = 0;}break; + case '0': {dst[j++] = '\0'; mode = 0;}break; + } + }break; } - else{ - dst[j++] = src.str[i]; - } - }break; - - case 1: - { - switch (src.str[i]){ - case '\\':{dst[j++] = '\\'; mode = 0;}break; - case 'n': {dst[j++] = '\n'; mode = 0;}break; - case 't': {dst[j++] = '\t'; mode = 0;}break; - case '"': {dst[j++] = '"'; mode = 0;}break; - case '0': {dst[j++] = '\0'; mode = 0;}break; - } - }break; -} } dst[j] = 0; } @@ -3817,37 +3804,37 @@ close_all_files_with_extension(Application_Links *app, Partition *scratch_part, buffers_to_close_count = 0; do_repeat = 0; - uint32_t access = AccessAll; - Buffer_Summary buffer = {0}; - for (buffer = get_buffer_first(app, access); - buffer.exists; - get_buffer_next(app, &buffer, access)){ - - bool32 is_match = 1; - if (extension_count > 0){ - String extension = file_extension(make_string(buffer.file_name, buffer.file_name_len)); - is_match = 0; - for (int32_t i = 0; i < extension_count; ++i){ - if (match(extension, extension_list[i])){ - is_match = 1; - break; + uint32_t access = AccessAll; + Buffer_Summary buffer = {0}; + for (buffer = get_buffer_first(app, access); + buffer.exists; + get_buffer_next(app, &buffer, access)){ + + bool32 is_match = 1; + if (extension_count > 0){ + String extension = file_extension(make_string(buffer.file_name, buffer.file_name_len)); + is_match = 0; + for (int32_t i = 0; i < extension_count; ++i){ + if (match(extension, extension_list[i])){ + is_match = 1; + break; + } } } + + if (is_match){ + if (buffers_to_close_count >= buffers_to_close_max){ + do_repeat = 1; + break; + } + buffers_to_close[buffers_to_close_count++] = buffer.buffer_id; + } } - if (is_match){ - if (buffers_to_close_count >= buffers_to_close_max){ - do_repeat = 1; - break; - } - buffers_to_close[buffers_to_close_count++] = buffer.buffer_id; + for (int32_t i = 0; i < buffers_to_close_count; ++i){ + kill_buffer(app, buffer_identifier(buffers_to_close[i]), true, 0); } } - - for (int32_t i = 0; i < buffers_to_close_count; ++i){ - kill_buffer(app, buffer_identifier(buffers_to_close[i]), true, 0); - } -} while(do_repeat); end_temp_memory(temp); @@ -3876,31 +3863,31 @@ open_all_files_with_extension(Application_Links *app, Partition *scratch_part, c if (extension_count > 0){ is_match = 0; - String extension = make_string_cap(info->filename, info->filename_len, info->filename_len+1); - extension = file_extension(extension); + String extension = make_string_cap(info->filename, info->filename_len, info->filename_len+1); + extension = file_extension(extension); for (int32_t j = 0; j < extension_count; ++j){ if (match(extension, extension_list[j])){ is_match = 1; break; } - } - - if (is_match){ - // NOTE(allen): There's no way in the 4coder API to use relative - // paths at the moment, so everything should be full paths. Which is - // managable. Here simply set the dir string size back to where it - // was originally, so that new appends overwrite old ones. - dir.size = dir_size; - append_sc(&dir, info->filename); - create_buffer(app, dir.str, dir.size, 0); + } + + if (is_match){ + // NOTE(allen): There's no way in the 4coder API to use relative + // paths at the moment, so everything should be full paths. Which is + // managable. Here simply set the dir string size back to where it + // was originally, so that new appends overwrite old ones. + dir.size = dir_size; + append_sc(&dir, info->filename); + create_buffer(app, dir.str, dir.size, 0); + } + } } } - } -} free_file_list(app, list); - -end_temp_memory(temp); + + end_temp_memory(temp); } static char** @@ -3968,10 +3955,10 @@ CUSTOM_COMMAND_SIG(load_project){ if (result == LexResult_Finished){ // Clear out current project - if (current_project.close_all_code_when_this_project_closes){ - exec_command(app, close_all_code); - } - current_project = null_project; + if (current_project.close_all_code_when_this_project_closes){ + exec_command(app, close_all_code); + } + current_project = null_project; // Set new project directory { @@ -3992,9 +3979,9 @@ CUSTOM_COMMAND_SIG(load_project){ String str = {0}; if (config_string_var(item, "extensions", 0, &str)){ if (str.size < sizeof(current_project.extension_space)){ - set_project_extensions(¤t_project, str); - print_message(app, str.str, str.size); - print_message(app, "\n", 1); + set_project_extensions(¤t_project, str); + print_message(app, str.str, str.size); + print_message(app, "\n", 1); } else{ print_message(app, literal("STRING TOO LONG!\n")); @@ -4067,35 +4054,35 @@ CUSTOM_COMMAND_SIG(load_project){ } if (read_string){ - if (config_int_var(array_item, 0, 0, 0)){ - append(&msg, "NULL, "); - dest_str[0] = 0; + if (config_int_var(array_item, 0, 0, 0)){ + append(&msg, "NULL, "); + dest_str[0] = 0; + } + + String str = {0}; + if (config_string_var(array_item, 0, 0, &str)){ + if (str.size < dest_str_size){ + interpret_escaped_string(dest_str, str); + append(&msg, dest_str); + append(&msg, ", "); + } + else{ + append(&msg, "STRING TOO LONG!, "); + } + } } - String str = {0}; - if (config_string_var(array_item, 0, 0, &str)){ - if (str.size < dest_str_size){ - interpret_escaped_string(dest_str, str); - append(&msg, dest_str); - append(&msg, ", "); - } - else{ - append(&msg, "STRING TOO LONG!, "); + if (read_bool){ + if (config_bool_var(array_item, 0, 0, dest_bool)){ + if (dest_bool){ + append(&msg, "true, "); + } + else{ + append(&msg, "false, "); + } } } - } - if (read_bool){ - if (config_bool_var(array_item, 0, 0, dest_bool)){ - if (dest_bool){ - append(&msg, "true, "); - } - else{ - append(&msg, "false, "); - } - } - } - item_index++; } @@ -4106,7 +4093,7 @@ CUSTOM_COMMAND_SIG(load_project){ } } } - + if (current_project.close_all_files_when_project_opens){ close_all_files_with_extension(app, &global_part, 0, 0); } diff --git a/4coder_search.cpp b/4coder_search.cpp index 861af0e8..37126728 100644 --- a/4coder_search.cpp +++ b/4coder_search.cpp @@ -264,11 +264,7 @@ match_check(Application_Links *app, Search_Range *range, int32_t *pos, Search_Ma } static int32_t -search_front_to_back_step(Application_Links *app, - Search_Range *range, - String word, - int32_t *pos, - Search_Match *result_ptr){ +search_front_to_back_step(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){ int32_t found_match = FindResult_None; Search_Match result = *result_ptr; @@ -284,16 +280,10 @@ search_front_to_back_step(Application_Links *app, result.buffer = get_buffer(app, range->buffer, AccessAll); if (case_insensitive){ - buffer_seek_string_insensitive_forward(app, &result.buffer, - start_pos, end_pos, - word.str, word.size, - &result.start); + buffer_seek_string_insensitive_forward(app, &result.buffer, start_pos, end_pos, word.str, word.size, &result.start); } else{ - buffer_seek_string_forward(app, &result.buffer, - start_pos, end_pos, - word.str, word.size, - &result.start); + buffer_seek_string_forward(app, &result.buffer, start_pos, end_pos, word.str, word.size, &result.start); } if (result.start < end_pos){ @@ -319,11 +309,7 @@ search_front_to_back_step(Application_Links *app, } static int32_t -search_front_to_back(Application_Links *app, - Search_Range *range, - String word, - int32_t *pos, - Search_Match *result_ptr){ +search_front_to_back(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){ int32_t found_match = FindResult_None; for (;found_match == FindResult_None;){ found_match = search_front_to_back_step(app, range, word, pos, result_ptr); @@ -332,11 +318,7 @@ search_front_to_back(Application_Links *app, } static int32_t -search_back_to_front_step(Application_Links *app, - Search_Range *range, - String word, - int32_t *pos, - Search_Match *result_ptr){ +search_back_to_front_step(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){ int32_t found_match = FindResult_None; Search_Match result = *result_ptr; @@ -372,11 +354,7 @@ search_back_to_front_step(Application_Links *app, } static int32_t -search_back_to_front(Application_Links *app, - Search_Range *range, - String word, - int32_t *pos, - Search_Match *result_ptr){ +search_back_to_front(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){ int32_t found_match = FindResult_None; for (;found_match == FindResult_None;){ found_match = search_back_to_front_step(app, range, word, pos, result_ptr); diff --git a/4coder_types.h b/4coder_types.h index 641d9d2d..2597a021 100644 --- a/4coder_types.h +++ b/4coder_types.h @@ -39,14 +39,14 @@ TYPEDEF int32_t View_ID; /* DOC(A Key_Modifier acts as an index for specifying modifiers in arrays.) */ ENUM(int32_t, Key_Modifier){ - MDFR_SHIFT_INDEX, - MDFR_CONTROL_INDEX, - MDFR_ALT_INDEX, + MDFR_SHIFT_INDEX, + MDFR_CONTROL_INDEX, + MDFR_ALT_INDEX, MDFR_CAPS_INDEX, MDFR_HOLD_INDEX, /* DOC(MDFR_INDEX_COUNT is used to specify the number of modifiers supported.) */ - MDFR_INDEX_COUNT + MDFR_INDEX_COUNT }; /* DOC(A Key_Modifier_Flag field is used to specify a specific state of modifiers. @@ -231,7 +231,7 @@ ENUM(uint32_t, Buffer_Create_Flag){ /* DOC(Buffer_Creation_Data is a struct used as a local handle for the creation of a buffer. ) HIDE_MEMBERS() */ - STRUCT Buffer_Creation_Data{ +STRUCT Buffer_Creation_Data{ Buffer_Create_Flag flags; char fname_space [256]; int32_t fname_len; @@ -343,7 +343,7 @@ ENUM(int32_t, Mouse_Cursor_Show_Type){ MouseCursorShow_Never, /* DOC(The MouseCursorShow_Never mode always shows the cursor.) */ MouseCursorShow_Always, -// MouseCursorShow_WhenActive,// TODO(allen): coming soon + // MouseCursorShow_WhenActive,// TODO(allen): coming soon }; /* DOC(A View_Split_Position specifies where a new view should be placed as a result of a view split operation.) */ @@ -359,7 +359,7 @@ ENUM(int32_t, View_Split_Position){ }; /* DOC(Generic_Command acts as a name for a command, and can name an internal command or a custom command.) */ - UNION Generic_Command{ +UNION Generic_Command{ /*DOC(If this Generic_Command represents an internal command the cmdid field will have a value less than cmdid_count, and this field is the command id for the command.)*/ Command_ID cmdid; /*DOC(If this Generic_Command does not represent an internal command the command @@ -370,23 +370,23 @@ ENUM(int32_t, View_Split_Position){ /* DOC(Key_Event_Data describes a key event, including the translation to a character, the translation to a character ignoring the state of caps lock, and an array of all the modifiers that were pressed at the time of the event.) */ STRUCT Key_Event_Data{ /* DOC(This field is the raw keycode which is always non-zero in valid key events.) */ - Key_Code keycode; + Key_Code keycode; /* DOC(This field is the keycode after translation to a character, this is 0 if there is no translation.) */ - Key_Code character; + Key_Code character; /* DOC(This field is like the field character, except that the state of caps lock is ignored in the translation.) */ - Key_Code character_no_caps_lock; + Key_Code character_no_caps_lock; /* DOC(This field is an array indicating the state of modifiers at the time of the key press. The array is indexed using the values of Key_Modifier. A 1 indicates that the corresponding modifier was held, and a 0 indicates that it was not held.) DOC_SEE(Key_Modifier) */ - char modifiers[MDFR_INDEX_COUNT]; + char modifiers[MDFR_INDEX_COUNT]; }; /* DOC(Mouse_State describes an entire mouse state complete with the position, left and right button states, the wheel state, and whether or not the mouse if in the window.) */ - STRUCT Mouse_State{ +STRUCT Mouse_State{ /* DOC(This field indicates that the left button is held.) */ char l; /* DOC(This field indicates that the right button is held.) */ @@ -402,9 +402,9 @@ STRUCT Key_Event_Data{ /* DOC( This field is 0 when the wheel has not moved, it is 1 for a downward motion and -1 for an upward motion. ) */ - char wheel; + char wheel; /* DOC(This field indicates that the mouse is outside of the window.) */ - char out_of_window; + char out_of_window; /* DOC(This field contains the x position of the mouse relative to the window where the left side is 0.) */ int32_t x; /* DOC(This field contains the y position of the mouse relative to the window where the top side is 0.) */ @@ -456,7 +456,7 @@ STRUCT File_List{ }; /* DOC(Buffer_Identifier acts as a loosely typed description of a buffer that can either be a name or an id.) */ - STRUCT Buffer_Identifier{ +STRUCT Buffer_Identifier{ /* DOC(This field is the name of the buffer; it need not be null terminated. If id is specified this pointer should be NULL.) */ char *name; @@ -464,7 +464,7 @@ STRUCT File_List{ int32_t name_len; /* DOC(This field is the id of the buffer. If name is specified this should be 0.) */ - Buffer_ID id; + Buffer_ID id; }; /* DOC(This struct is a part of an incomplete feature.) */ @@ -684,7 +684,7 @@ DOC(User_Input describes a user input event which can be either a key press or m DOC_SEE(User_Input_Type_ID) DOC_SEE(Generic_Command) */ - STRUCT User_Input{ +STRUCT User_Input{ /* DOC(This field specifies whether the event was a key press or mouse event.) */ User_Input_Type_ID type; /* DOC(This field indicates that an abort event has occurred and the command needs to shut down.) */ @@ -701,7 +701,7 @@ DOC_SEE(Generic_Command) /* DOC(Query_Bar is a struct used to store information in the user's control that will be displayed as a drop down bar durring an interactive command.) */ - STRUCT Query_Bar{ +STRUCT Query_Bar{ /* DOC(This specifies the prompt portion of the drop down bar.) */ String prompt; /* DOC(This specifies the main string portion of the drop down bar.) */ diff --git a/4cpp_lexer.h b/4cpp_lexer.h index e61a3817..c14abf43 100644 --- a/4cpp_lexer.h +++ b/4cpp_lexer.h @@ -149,6 +149,10 @@ static String_And_Flag keywords[] = { {make_lit_string("register") , CPP_TOKEN_KEY_OTHER}, {make_lit_string("this") , CPP_TOKEN_KEY_OTHER}, {make_lit_string("thread_local") , CPP_TOKEN_KEY_OTHER}, + +#if defined(FCPP_LEXER_EXTRA_KEYWORDS) + FCPP_LEXER_EXTRA_KEYWORDS +#endif }; @@ -171,7 +175,7 @@ DOC_SEE(Cpp_Get_Token_Result) Cpp_Get_Token_Result result = {}; Cpp_Token *token_array = array.tokens; Cpp_Token *token = 0; - int32_t first = 0; + int32_t first = 0; int32_t count = array.count; int32_t last = count; int32_t this_start = 0, next_start = 0; @@ -218,7 +222,7 @@ DOC_SEE(Cpp_Get_Token_Result) result.token_index = -1; result.in_whitespace = 1; } - + if (result.token_index >= 0 && result.token_index < count){ token = array.tokens + result.token_index; result.token_start = token->start; @@ -939,7 +943,7 @@ cpp_lex_nonalloc_no_null_out_limit(Cpp_Lex_Data *S_ptr, char *chunk, int32_t siz } Cpp_Lex_Result result = cpp_lex_nonalloc_no_null_no_limit(S_ptr, chunk, size, full_size, - &temp_stack); + &temp_stack); token_array_out->count = temp_stack.count; @@ -996,23 +1000,23 @@ to make sure it returns LexResult_Finished to you: CODE_EXAMPLE( Cpp_Token_Array lex_file(char *file_name){ - File_Data file = read_whole_file(file_name); - - char *temp = (char*)malloc(4096); // hopefully big enough - Cpp_Lex_Data lex_state = cpp_lex_data_init(temp); - - Cpp_Token_Array array = {0}; - array.tokens = (Cpp_Token*)malloc(1 << 20); // hopefully big enough - array.max_count = (1 << 20)/sizeof(Cpp_Token); - - Cpp_Lex_Result result = - cpp_lex_step(&lex_state, file.data, file.size, file.size, - &array, NO_OUT_LIMIT); - Assert(result == LexResult_Finished); - - free(temp); - - return(array); +File_Data file = read_whole_file(file_name); + +char *temp = (char*)malloc(4096); // hopefully big enough +Cpp_Lex_Data lex_state = cpp_lex_data_init(temp); + +Cpp_Token_Array array = {0}; +array.tokens = (Cpp_Token*)malloc(1 << 20); // hopefully big enough +array.max_count = (1 << 20)/sizeof(Cpp_Token); + +Cpp_Lex_Result result = +cpp_lex_step(&lex_state, file.data, file.size, file.size, +&array, NO_OUT_LIMIT); +Assert(result == LexResult_Finished); + +free(temp); + +return(array); }) ) @@ -1538,15 +1542,15 @@ it is quick and convenient to lex files. CODE_EXAMPLE( Cpp_Token_Array lex_file(char *file_name){ - File_Data file = read_whole_file(file_name); - - // This array will be automatically grown if it runs - // out of memory. - Cpp_Token_Array array = cpp_make_token_array(100); - - cpp_lex_file(file.data, file.size, &array); - - return(array); +File_Data file = read_whole_file(file_name); + +// This array will be automatically grown if it runs +// out of memory. +Cpp_Token_Array array = cpp_make_token_array(100); + +cpp_lex_file(file.data, file.size, &array); + +return(array); }) ) diff --git a/4ed_app_target.cpp b/4ed_app_target.cpp index 3571ff36..ad377423 100644 --- a/4ed_app_target.cpp +++ b/4ed_app_target.cpp @@ -11,7 +11,7 @@ // TODO(allen): can I get away from this one? #include -#include "4ed_defines.h" +#include "common/4coder_defines.h" #define FSTRING_IMPLEMENTATION #define FSTRING_C @@ -41,11 +41,8 @@ #include "4ed_style.cpp" #include "4ed_command.cpp" -#include "buffer/4coder_shared.cpp" -#include "buffer/4coder_gap_buffer.cpp" -#define Buffer_Type Gap_Buffer -#include "buffer/4coder_buffer_abstract.cpp" - +#include "file/4coder_buffer.cpp" +#include "file/4coder_undo.cpp" #include "file/4coder_file.cpp" #include "file/4coder_working_set.cpp" #include "file/4coder_hot_directory.cpp" diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index 84547ba6..fe00ec06 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -440,7 +440,7 @@ view_compute_cursor(View *view, Buffer_Seek seek, b32 return_hint){ first_wrap_determination = 0; } else{ - assert_4tech(stop.pos == wrap_unit_end); + assert(stop.pos == wrap_unit_end); do_wrap = 1; ++wrap_array_index; wrap_unit_end = file->state.wrap_positions[wrap_array_index]; @@ -484,7 +484,7 @@ internal i32 file_compute_lowest_line(Editing_File *file, f32 font_height){ i32 lowest_line = 0; - Buffer_Type *buffer = &file->state.buffer; + Gap_Buffer *buffer = &file->state.buffer; if (file->settings.unwrapped_lines){ lowest_line = buffer->line_count; } @@ -755,7 +755,7 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file, i32 max = 0, size = 0; b32 dos_write_mode = file->settings.dos_write_mode; char *data = 0; - Buffer_Type *buffer = &file->state.buffer; + Gap_Buffer *buffer = &file->state.buffer; if (dos_write_mode){ max = buffer_size(buffer) + buffer->line_count + 1; @@ -847,14 +847,14 @@ enum{ }; internal i32 -file_grow_starts_as_needed(System_Functions *system, General_Memory *general, Buffer_Type *buffer, i32 additional_lines){ +file_grow_starts_as_needed(System_Functions *system, General_Memory *general, Gap_Buffer *buffer, i32 additional_lines){ b32 result = GROW_NOT_NEEDED; i32 max = buffer->line_max; i32 count = buffer->line_count; i32 target_lines = count + additional_lines; if (target_lines > max || max == 0){ - max = LargeRoundUp(target_lines + max, Kbytes(1)); + max = l_round_up_i32(target_lines + max, Kbytes(1)); i32 *new_lines = (i32*)general_memory_reallocate(system, general, buffer->line_starts, sizeof(i32)*count, sizeof(f32)*max); @@ -894,7 +894,7 @@ file_update_cursor_positions(Models *models, Editing_File *file){ // internal void -file_measure_starts(System_Functions *system, General_Memory *general, Buffer_Type *buffer){ +file_measure_starts(System_Functions *system, General_Memory *general, Gap_Buffer *buffer){ if (!buffer->line_starts){ i32 max = buffer->line_max = Kbytes(1); buffer->line_starts = (i32*)general_memory_allocate(system, general, max*sizeof(i32)); @@ -922,7 +922,7 @@ file_measure_starts(System_Functions *system, General_Memory *general, Buffer_Ty // NOTE(allen): These calls assumes that the buffer's line starts are already correct, // and that the buffer's line_count is correct. internal void -file_allocate_metadata_as_needed(System_Functions *system, General_Memory *general, Buffer_Type *buffer, void **mem, i32 *mem_max_count, i32 count, i32 item_size){ +file_allocate_metadata_as_needed(System_Functions *system, General_Memory *general, Gap_Buffer *buffer, void **mem, i32 *mem_max_count, i32 count, i32 item_size){ if (*mem == 0){ i32 max = ((count+1)*2); max = (max+(0x3FF))&(~(0x3FF)); @@ -996,7 +996,7 @@ struct Code_Wrap_State{ f32 x; b32 consume_newline; - Buffer_Stream_Type stream; + Gap_Buffer_Stream stream; i32 i; f32 *adv; @@ -1012,7 +1012,7 @@ wrap_state_init(Code_Wrap_State *state, Editing_File *file, f32 *adv){ state->line_starts = file->state.buffer.line_starts; state->next_line_start = state->line_starts[1]; - Buffer_Type *buffer = &file->state.buffer; + Gap_Buffer *buffer = &file->state.buffer; i32 size = buffer_size(buffer); buffer_stringify_loop(&state->stream, buffer, 0, size); @@ -1262,9 +1262,11 @@ stickieness_guess(Cpp_Token_Type type, Cpp_Token_Type other_type, u16 flags, u16 guess = 1000; } } + else if (type == CPP_TOKEN_COMMA){ + guess = 20; + } else if (type == CPP_TOKEN_COLON || type == CPP_TOKEN_PARENTHESE_CLOSE || - type == CPP_TOKEN_COMMA || type == CPP_TOKEN_BRACKET_OPEN || type == CPP_TOKEN_BRACKET_CLOSE){ if (on_left){ @@ -1490,7 +1492,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, } } else{ - Buffer_Stream_Type stream = {0}; + Gap_Buffer_Stream stream = {0}; i32 word_stage = 0; i32 i = stop.pos; @@ -1603,7 +1605,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, step.start_x = x; step.this_token = wrap_state.token_ptr; - Buffer_Stream_Type stream = {0}; + Gap_Buffer_Stream stream = {0}; Potential_Wrap_Indent_Pair potential_wrap = {0}; potential_wrap.wrap_position = i; @@ -1737,6 +1739,10 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file, general_stickieness = next_stickieness; } + if (wrap_state.wrap_x.paren_top != 0 && this_type == CPP_TOKEN_COMMA){ + general_stickieness = 0; + } + wrappable_score = 64*50; wrappable_score += 101 - general_stickieness - wrap_state.wrap_x.paren_safe_top*80; @@ -1893,14 +1899,14 @@ file_create_from_string(System_Functions *system, Models *models, Font_Set *font_set = models->font_set; General_Memory *general = &models->mem.general; Partition *part = &models->mem.part; - Buffer_Init_Type init; + Gap_Buffer_Init init; file->state = null_editing_file_state; init = buffer_begin_init(&file->state.buffer, val.str, val.size); for (; buffer_init_need_more(&init); ){ i32 page_size = buffer_init_page_size(&init); - page_size = LargeRoundUp(page_size, Kbytes(4)); + page_size = l_round_up_i32(page_size, Kbytes(4)); if (page_size < Kbytes(4)) page_size = Kbytes(4); void *data = general_memory_allocate(system, general, page_size); buffer_init_provide_page(&init, data, page_size); @@ -1977,7 +1983,7 @@ file_close(System_Functions *system, General_Memory *general, Editing_File *file general_memory_free(system, general, file->state.token_array.tokens); } - Buffer_Type *buffer = &file->state.buffer; + Gap_Buffer *buffer = &file->state.buffer; if (buffer->data){ general_memory_free(system, general, buffer->data); general_memory_free(system, general, buffer->line_starts); @@ -2012,7 +2018,7 @@ Job_Callback_Sig(job_full_lex){ Editing_File *file = (Editing_File*)data[0]; General_Memory *general = (General_Memory*)data[1]; - Buffer_Type *buffer = &file->state.buffer; + Gap_Buffer *buffer = &file->state.buffer; i32 text_size = buffer_size(buffer); i32 aligned_buffer_size = (text_size + 3)&(~3); @@ -2074,7 +2080,7 @@ Job_Callback_Sig(job_full_lex){ } } while (still_lexing); - i32 new_max = LargeRoundUp(tokens.count+1, Kbytes(1)); + i32 new_max = l_round_up_i32(tokens.count+1, Kbytes(1)); system->acquire_lock(FRAME_LOCK); { @@ -2158,7 +2164,7 @@ file_first_lex_serial(System_Functions *system, Mem_Options *mem, Editing_File * { Temp_Memory temp = begin_temp_memory(part); - Buffer_Type *buffer = &file->state.buffer; + Gap_Buffer *buffer = &file->state.buffer; i32 text_size = buffer_size(buffer); i32 mem_size = partition_remaining(part); @@ -2201,7 +2207,7 @@ file_first_lex_serial(System_Functions *system, Mem_Options *mem, Editing_File * } } while (still_lexing); - i32 new_max = LargeRoundUp(tokens.count+1, Kbytes(1)); + i32 new_max = l_round_up_i32(tokens.count+1, Kbytes(1)); { Assert(file->state.swap_array.tokens == 0); @@ -2250,7 +2256,7 @@ file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *fi b32 result = 1; b32 inline_lex = !file->state.still_lexing; if (inline_lex){ - Buffer_Type *buffer = &file->state.buffer; + Gap_Buffer *buffer = &file->state.buffer; i32 extra_tolerance = 100; Cpp_Token_Array *array = &file->state.token_array; @@ -2315,7 +2321,7 @@ file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *fi if (inline_lex){ i32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array); if (new_count > array->max_count){ - i32 new_max = LargeRoundUp(new_count, Kbytes(1)); + i32 new_max = l_round_up_i32(new_count, Kbytes(1)); array->tokens = (Cpp_Token*) general_memory_reallocate(system, general, array->tokens, array->count*sizeof(Cpp_Token), new_max*sizeof(Cpp_Token)); array->max_count = new_max; @@ -2376,7 +2382,7 @@ file_relex_serial(System_Functions *system, Mem_Options *mem, Editing_File *file Assert(!file->state.still_lexing); - Buffer_Type *buffer = &file->state.buffer; + Gap_Buffer *buffer = &file->state.buffer; Cpp_Token_Array *array = &file->state.token_array; Temp_Memory temp = begin_temp_memory(part); @@ -2430,7 +2436,7 @@ file_relex_serial(System_Functions *system, Mem_Options *mem, Editing_File *file i32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array); if (new_count > array->max_count){ - i32 new_max = LargeRoundUp(new_count, Kbytes(1)); + i32 new_max = l_round_up_i32(new_count, Kbytes(1)); array->tokens = (Cpp_Token*) general_memory_reallocate(system, general, array->tokens, array->count*sizeof(Cpp_Token), new_max*sizeof(Cpp_Token)); array->max_count = new_max; @@ -3137,7 +3143,7 @@ file_do_single_edit(System_Functions *system, Models *models, Editing_File *file } // NOTE(allen): meta data - Buffer_Type *buffer = &file->state.buffer; + Gap_Buffer *buffer = &file->state.buffer; i32 line_start = buffer_get_line_index(&file->state.buffer, start); i32 line_end = buffer_get_line_index(&file->state.buffer, end); i32 replaced_line_count = line_end - line_start; @@ -5989,7 +5995,7 @@ draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target first_wrap_determination = 0; } else{ - assert_4tech(stop.pos == wrap_unit_end); + assert(stop.pos == wrap_unit_end); do_wrap = 1; ++wrap_array_index; wrap_unit_end = file->state.wrap_positions[wrap_array_index]; diff --git a/4ed_math.h b/4ed_math.h index ce0a11a8..d610c66a 100644 --- a/4ed_math.h +++ b/4ed_math.h @@ -53,43 +53,6 @@ COS(f32 x_degrees){ } #endif -/* - * Rounding - */ - -inline i32 -TRUNC32(real32 x) { return (i32)x; } - -inline i32 -FLOOR32(real32 x) { return (i32)(x)-((x!=(i32)(x) && x<0)?1:0); } - -inline i32 -CEIL32(real32 x) { return (i32)(x)+((x!=(i32)(x) && x>0)?1:0); } - -inline i32 -ROUND32(real32 x) { return FLOOR32(x + .5f); } - -inline i32 -DIVCEIL32(i32 n, i32 d) { - i32 q = (n/d); - return q + (q*d < n); -} - -inline real32 -FRACPART32(real32 x) { return x - (i32)x; } - -inline u32 -ROUNDPOT32(u32 v){ - v--; - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - v++; - return v; -} - /* * Vectors */ @@ -413,10 +376,10 @@ perp(Vec2 v){ inline Vec2 polar_to_cartesian(real32 theta_degrees, real32 length){ - Vec2 result; - result.x = COS(theta_degrees)*length; - result.y = SIN(theta_degrees)*length; - return result; + Vec2 result; + result.x = COS(theta_degrees)*length; + result.y = SIN(theta_degrees)*length; + return result; } inline Vec2 @@ -463,8 +426,8 @@ inline f32 unlerp(f32 a, f32 x, f32 b){ f32 r = x; if (b > a){ - r = (x - a) / (b - a); - } + r = (x - a) / (b - a); + } return(r); } @@ -517,7 +480,7 @@ color_blend(u32 a, real32 t, u32 b){ u8 byte[4]; u32 comp; } A, B, R; - + A.comp = a; B.comp = b; @@ -589,23 +552,23 @@ rgba_to_hsla(Vec4 rgba){ } else{ switch (maxc){ - case 0: - { - hsla.x = (rgba.g - rgba.b) / delta; - hsla.x += (rgba.g < rgba.b) * 6.f; - }break; - - case 1: - { - hsla.x = (rgba.b - rgba.r) / delta; - hsla.x += 2.f; - }break; - - case 2: - { - hsla.x = (rgba.r - rgba.g) / delta; - hsla.x += 4.f; - }break; + case 0: + { + hsla.x = (rgba.g - rgba.b) / delta; + hsla.x += (rgba.g < rgba.b) * 6.f; + }break; + + case 1: + { + hsla.x = (rgba.b - rgba.r) / delta; + hsla.x += 2.f; + }break; + + case 2: + { + hsla.x = (rgba.r - rgba.g) / delta; + hsla.x += 4.f; + }break; } hsla.x *= (1/6.f); // * 60 / 360 hsla.y = delta / (1.f - ABS(2.f*hsla.z - 1.f)); @@ -626,27 +589,27 @@ hsla_to_rgba(Vec4 hsla){ m = hsla.z - C*.5f; H = FLOOR32(hsla.x * 6.f); switch (H){ - case 0: + case 0: rgba.r = C; rgba.g = X; rgba.b = 0; break; - case 1: + case 1: rgba.r = X; rgba.g = C; rgba.b = 0; break; - case 2: + case 2: rgba.r = 0; rgba.g = C; rgba.b = X; break; - case 3: + case 3: rgba.r = 0; rgba.g = X; rgba.b = C; break; - case 4: + case 4: rgba.r = X; rgba.g = 0; rgba.b = C; break; - case 5: + case 5: rgba.r = C; rgba.g = 0; rgba.b = X; break; } diff --git a/4ed_site.ctm b/4ed_site.ctm new file mode 100644 index 0000000000000000000000000000000000000000..f13ce96e1c8a50efe71108e1e39efa84a6ced204 GIT binary patch literal 340 zcmcC7j62o(Cvtmt#wA8Z1_p-NTnr4QM%Gthd@Z1$(X1ZM9;iGQkbmM@oDPh?8>r`4 ziIgFX4^qz-{data != 0); - return(good); -} - -inline_4tech i32 -buffer_size(Gap_Buffer *buffer){ - i32 size = buffer->size1 + buffer->size2; - return(size); -} - -typedef struct Gap_Buffer_Init{ - Gap_Buffer *buffer; - char *data; - i32 size; -} Gap_Buffer_Init; - -internal_4tech Gap_Buffer_Init -buffer_begin_init(Gap_Buffer *buffer, char *data, i32 size){ - Gap_Buffer_Init init; - init.buffer = buffer; - init.data = data; - init.size = size; - return(init); -} - -internal_4tech i32 -buffer_init_need_more(Gap_Buffer_Init *init){ - i32 result = 1; - if (init->buffer->data) result = 0; - return(result); -} - -internal_4tech i32 -buffer_init_page_size(Gap_Buffer_Init *init){ - i32 result = init->size * 2; - return(result); -} - -internal_4tech void -buffer_init_provide_page(Gap_Buffer_Init *init, void *page, i32 page_size){ - Gap_Buffer *buffer = init->buffer; - buffer->data = (char*)page; - buffer->max = page_size; -} - -internal_4tech i32 -buffer_end_init(Gap_Buffer_Init *init, void *scratch, i32 scratch_size){ - Gap_Buffer *buffer = init->buffer; - i32 osize1 = 0, size1 = 0, size2 = 0, size = init->size; - i32 result = 0; - - if (buffer->data){ - if (buffer->max >= init->size){ - size2 = size >> 1; - size1 = osize1 = size - size2; - - if (size1 > 0){ - size1 = eol_convert_in(buffer->data, init->data, size1); - if (size2 > 0){ - size2 = eol_convert_in(buffer->data + size1, init->data + osize1, size2); - } - } - - buffer->size1 = size1; - buffer->size2 = size2; - buffer->gap_size = buffer->max - size1 - size2; - memmove_4tech(buffer->data + size1 + buffer->gap_size, buffer->data + size1, size2); - - result = 1; - } - } - - return(result); -} - -typedef struct Gap_Buffer_Stream{ - Gap_Buffer *buffer; - char *data; - i32 end; - i32 separated; - i32 absolute_end; - - b32 use_termination_character; - char terminator; -} Gap_Buffer_Stream; -static Gap_Buffer_Stream null_buffer_stream = {0}; - -internal_4tech b32 -buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, i32 start, i32 end){ - b32 result = 0; - - if (0 <= start && start < end && end <= buffer->size1 + buffer->size2){ - stream->buffer = buffer; - stream->absolute_end = end; - - if (start < buffer->size1){ - if (buffer->size1 < end){ - stream->separated = 1; - } - else{ - stream->separated = 0; - } - stream->data = buffer->data; - } - else{ - stream->separated = 0; - stream->data = buffer->data + buffer->gap_size; - } - - if (stream->separated){ - stream->end = buffer->size1; - } - else{ - stream->end = end; - } - - if (stream->end > stream->absolute_end){ - stream->end = stream->absolute_end; - } - - result = 1; - } - - if (result == 0){ - if (stream->use_termination_character){ - stream->buffer = buffer; - stream->absolute_end = end; - stream->use_termination_character = 0; - stream->data = (&stream->terminator) - buffer->size1 - buffer->size2; - stream->end = stream->absolute_end + 1; - result = 1; - } - } - - return(result); -} - -internal_4tech b32 -buffer_stringify_next(Gap_Buffer_Stream *stream){ - b32 result = 0; - Gap_Buffer *buffer = stream->buffer; - if (stream->separated){ - stream->data = buffer->data + buffer->gap_size; - stream->end = stream->absolute_end; - stream->separated = 0; - result = 1; - } - - if (result == 0){ - if (stream->use_termination_character){ - stream->use_termination_character = 0; - stream->data = (&stream->terminator) - buffer->size1 - buffer->size2; - stream->end = stream->absolute_end + 1; - result = 1; - } - } - - return(result); -} - -internal_4tech i32 -buffer_replace_range(Gap_Buffer *buffer, i32 start, i32 end, char *str, i32 len, i32 *shift_amount, - void *scratch, i32 scratch_memory, i32 *request_amount){ - char *data = buffer->data; - i32 size = buffer_size(buffer); - i32 result = 0; - i32 move_size = 0; - - assert_4tech(0 <= start); - assert_4tech(start <= end); - assert_4tech(end <= size); - - *shift_amount = (len - (end - start)); - if (*shift_amount + size <= buffer->max){ - if (end < buffer->size1){ - move_size = buffer->size1 - end; - memmove_4tech(data + buffer->size1 + buffer->gap_size - move_size, data + end, move_size); - buffer->size1 -= move_size; - buffer->size2 += move_size; - } - if (start > buffer->size1){ - move_size = start - buffer->size1; - memmove_4tech(data + buffer->size1, data + buffer->size1 + buffer->gap_size, move_size); - buffer->size1 += move_size; - buffer->size2 -= move_size; - } - - memcpy_4tech(data + start, str, len); - buffer->size2 = size - end; - buffer->size1 = start + len; - buffer->gap_size -= *shift_amount; - - assert_4tech(buffer->size1 + buffer->size2 == size + *shift_amount); - assert_4tech(buffer->size1 + buffer->gap_size + buffer->size2 == buffer->max); - } - else{ - *request_amount = round_up_4tech(2*(*shift_amount + size), 4 << 10); - result = 1; - } - - return(result); -} - -// TODO(allen): Now that we are just using Gap_Buffer we could afford to improve -// this for the Gap_Buffer's behavior. -internal_4tech i32 -buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edit *sorted_edits, - char *strings, i32 edit_count, void *scratch, i32 scratch_size, - i32 *request_amount){ - Buffer_Edit *edit = 0; - i32 i = state->i; - i32 shift_total = state->shift_total; - i32 shift_amount = 0; - i32 result = 0; - - edit = sorted_edits + i; - for (; i < edit_count; ++i, ++edit){ - result = buffer_replace_range(buffer, edit->start + shift_total, edit->end + shift_total, - strings + edit->str_start, edit->len, &shift_amount, - scratch, scratch_size, request_amount); - if (result) break; - shift_total += shift_amount; - } - - state->shift_total = shift_total; - state->i = i; - - return(result); -} - -internal_4tech void* -buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, i32 new_max){ - void *result = buffer->data; - i32 size = buffer_size(buffer); - i32 new_gap_size = new_max - size; - - assert_4tech(new_max >= size); - - memcpy_4tech(new_data, buffer->data, buffer->size1); - memcpy_4tech((char*)new_data + buffer->size1 + new_gap_size, buffer->data + buffer->size1 + buffer->gap_size, buffer->size2); - - buffer->data = (char*)new_data; - buffer->gap_size = new_gap_size; - buffer->max = new_max; - - return(result); -} - -// BOTTOM - diff --git a/buffer/4coder_shared.cpp b/buffer/4coder_shared.cpp deleted file mode 100644 index c80c3f94..00000000 --- a/buffer/4coder_shared.cpp +++ /dev/null @@ -1,389 +0,0 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 23.10.2015 - * - * Items shared by gap buffer types - * - */ - -// TOP - -// TODO(allen): eliminate the extra defs and the extra include. - -#include "../4coder_seek_types.h" - -#ifndef inline_4tech -#define inline_4tech inline -#endif - -#ifndef internal_4tech -#define internal_4tech static -#endif - -#ifndef memset_4tech -#define memset_4tech memset -#endif - -#ifndef memzero_4tech -#define memzero_4tech(x) do{ \ - char *p = (char*)&x; char *e = p + sizeof(x); \ - for (;p 0); - buffer_quick_sort_cursors(positions, 0, count-1); -} - -inline_4tech void -buffer_unsort_cursors(Cursor_With_Index *positions, i32 count){ - assert_4tech(count > 0); - buffer_quick_unsort_cursors(positions, 0, count-1); -} - -internal_4tech void -buffer_update_cursors(Cursor_With_Index *sorted_positions, i32 count, i32 start, i32 end, i32 len){ - i32 shift_amount = (len - (end - start)); - 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 >= start; --position) position->pos = start; -} - -internal_4tech i32 -buffer_batch_debug_sort_check(Buffer_Edit *sorted_edits, i32 edit_count){ - Buffer_Edit *edit = sorted_edits; - i32 i = 0, start_point = 0; - i32 result = 1; - - for (i = 0; i < edit_count; ++i, ++edit){ - if (start_point > edit->start){ - result = 0; break; - } - start_point = (edit->end < edit->start + 1)?(edit->start + 1):(edit->end); - } - - return(result); -} - -internal_4tech i32 -buffer_batch_edit_max_shift(Buffer_Edit *sorted_edits, i32 edit_count){ - Buffer_Edit *edit; - i32 i, result; - i32 shift_total, shift_max; - - result = 0; - shift_total = 0; - shift_max = 0; - - edit = sorted_edits; - for (i = 0; i < edit_count; ++i, ++edit){ - shift_total += (edit->len - (edit->end - edit->start)); - if (shift_total > shift_max) shift_max = shift_total; - } - - return(shift_max); -} - -internal_4tech i32 -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; - Buffer_Edit *edit, *end_edit; - i32 start, end; - i32 shift_amount; - - position = sorted_positions; - end_position = sorted_positions + count; - - edit = sorted_edits; - end_edit = sorted_edits + edit_count; - - shift_amount = 0; - - for (; edit < end_edit && position < end_position; ++edit){ - start = edit->start; - end = edit->end; - - for (; position->pos < start && position < end_position; ++position){ - position->pos += shift_amount; - } - - for (; position->pos <= end && position < end_position; ++position){ - position->pos = start + shift_amount; - } - - shift_amount += (edit->len - (end - start)); - } - - for (; position < end_position; ++position){ - position->pos += shift_amount; - } - - for (; edit < end_edit; ++edit){ - shift_amount += (edit->len - (edit->end - edit->start)); - } - - return(shift_amount); -} - -internal_4tech i32 -eol_convert_in(char *dest, char *src, i32 size){ - i32 i, j, k; - - i = 0; - k = 0; - j = 0; - - for (; j < size && src[j] != '\r'; ++j); - memcpy_4tech(dest, src, j); - - if (j < size){ - k = 1; - ++j; - for (i = j; i < size; ++i){ - if (src[i] == '\r'){ - memcpy_4tech(dest + j - k, src + j, i - j); - ++k; - j = i+1; - } - } - memcpy_4tech(dest + j - k, src + j, i - j); - j = i - k; - } - - return(j); -} - -internal_4tech i32 -eol_in_place_convert_in(char *data, i32 size){ - i32 i, j, k; - - i = 0; - k = 0; - j = 0; - - for (; j < size && data[j] != '\r'; ++j); - - if (j < size){ - k = 1; - ++j; - for (i = j; i < size; ++i){ - if (data[i] == '\r'){ - memmove_4tech(data + j - k, data + j, i - j); - ++k; - j = i+1; - } - } - memmove_4tech(data + j - k, data + j, i - j); - j = i - k; - } - - return(j); -} - -internal_4tech i32 -eol_convert_out(char *dest, i32 max, char *src, i32 size, i32 *size_out){ - i32 result; - i32 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 i32 -eol_in_place_convert_out(char *data, i32 size, i32 max, i32 *size_out){ - i32 result; - i32 i; - - // TODO(allen): iterative memory check? - result = 1; - i = 0; - - for (; i < size; ++i){ - if (data[i] == '\n'){ - memmove_4tech(data + i + 1, data + i, size - i); - data[i] = '\r'; - ++i; - ++size; - } - } - - *size_out = size; - return(result); -} - -inline_4tech i32 -is_whitespace(char c){ - i32 result; - result = (c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '\f' || c == '\v'); - return(result); -} - -inline_4tech i32 -is_alphanumeric_true(char c){ - return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9'); -} - -inline_4tech i32 -is_alphanumeric(char c){ - return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '_'); -} - -inline_4tech i32 -is_upper(char c){ - return (c >= 'A' && c <= 'Z'); -} - -inline_4tech i32 -is_lower(char c){ - return (c >= 'a' && c <= 'z'); -} - -inline_4tech char -to_upper(char c){ - if (is_lower(c)){ - c += 'A' - 'a'; - } - return(c); -} - -internal_4tech i32 -is_match(char *a, char *b, i32 len){ - i32 result; - - result = 1; - for (;len > 0; --len, ++a, ++b) - if (*a != *b) { result = 0; break; } - - return(result); -} - -internal_4tech i32 -is_match_insensitive(char *a, char *b, i32 len){ - i32 result; - - result = 1; - for (;len > 0; --len, ++a, ++b) - if (to_upper(*a) != to_upper(*b)) { result = 0; break; } - - return(result); -} - -// BOTTOM - diff --git a/build.bat b/build.bat index fc882613..013c3706 100644 --- a/build.bat +++ b/build.bat @@ -11,8 +11,9 @@ SET BUILD_MODE=%1 if "%BUILD_MODE%" == "" (SET BUILD_MODE="/DDEV_BUILD") pushd ..\build -cl %OPTS% ..\code\build.cpp /Zi /Febuild %BUILD_MODE% +cl %OPTS% ..\code\meta\build.cpp /Zi /Febuild %BUILD_MODE% if %ERRORLEVEL% neq 0 (set FirstError=1) +if %ERRORLEVEL% neq 0 (goto END) popd ..\build\build @@ -24,4 +25,5 @@ call "print_size.bat" 4ed_app.dll call "print_size.bat" 4ed.exe popd +::END call "ctime" -end 4ed_data.ctm %FirstError% diff --git a/build.sh b/build.sh index f7880837..eb0adaa7 100755 --- a/build.sh +++ b/build.sh @@ -3,7 +3,7 @@ WARNINGS="-Wno-write-strings" FLAGS="-D_GNU_SOURCE -fPIC -fpermissive -DDEV_BUILD" -g++ $WARNINGS $FLAGS build.cpp -g -o ../build/build +g++ $WARNINGS $FLAGS meta/build.cpp -g -o ../build/build ../build/build diff --git a/build_all.bat b/build_all.bat deleted file mode 100644 index 59203d7b..00000000 --- a/build_all.bat +++ /dev/null @@ -1,48 +0,0 @@ -@echo off - -call "ctime" -begin 4ed_data.ctm - -set OPTS=/W4 /wd4310 /wd4100 /wd4201 /wd4505 /wd4996 /wd4127 /wd4510 /wd4512 /wd4610 /wd4390 /WX -set OPTS=%OPTS% /GR- /EHa- /nologo /FC -set INCLUDES=/I..\foreign /I..\foreign\freetype2 -set LIBS=user32.lib winmm.lib gdi32.lib opengl32.lib -set LIBS=%LIBS% ..\foreign\freetype.lib -set ICON=..\res\icon.res -set DEFINES= -set FirstError=0 - -pushd ..\meta -REM cl %OPTS% ..\code\4ed_metagen.cpp %* /Femetagen -if %ERRORLEVEL% neq 0 (set FirstError=1) -popd - -pushd ..\code -REM "..\meta\metagen" -if %ERRORLEVEL% neq 0 (set FirstError=1) - -set CODE_DIR=%CD% -popd - -pushd ..\build - -REM call "%CODE_DIR%\buildsuper.bat" ..\code\4coder_default_bindings.cpp -REM call "%CODE_DIR%\buildsuper.bat" ..\code\internal_4coder_tests.cpp -REM call "%CODE_DIR%\buildsuper.bat" ..\code\power\4coder_casey.cpp -REM call "%CODE_DIR%\buildsuper.bat" ..\4vim\4coder_chronal.cpp -if %ERRORLEVEL% neq 0 (set FirstError=1) - -set EXPORTS=/EXPORT:app_get_functions -cl %OPTS% %INCLUDES% %DEFINES% %CODE_DIR%\4ed_app_target.cpp %* /Fe4ed_app /LD /link /DEBUG /INCREMENTAL:NO /OPT:REF %EXPORTS% -if %ERRORLEVEL% neq 0 (set FirstError=1) - -cl %OPTS% %INCLUDES% %DEFINES% %CODE_DIR%\win32_4ed.cpp %LIBS% %ICON% %* /Fe4ed /link /DEBUG /NODEFAULTLIB:library -if %ERRORLEVEL% neq 0 (set FirstError=1) - -call "print_size.bat" 4ed_app.dll -call "print_size.bat" 4ed.exe - -popd - -call "ctime" -end 4ed_data.ctm %FirstError% - - diff --git a/build_exp.bat b/build_exp.bat deleted file mode 100644 index 634a0228..00000000 --- a/build_exp.bat +++ /dev/null @@ -1,14 +0,0 @@ -@echo off - -set WARNINGOPS=/W4 /wd4310 /wd4100 /wd4201 /wd4505 /wd4996 /wd4127 /wd4510 /wd4512 /wd4610 /wd4390 /WX -set WARNINGOPS=%WARNINGOPS% /GR- /EHa- /nologo /FC - -pushd ..\build -cl %WARNINGOPS% ..\code\test\fsm_table_generator.cpp /Fefsm_gen %* - -pushd ..\code\test -..\..\build\fsm_gen -popd - -cl %WARNINGOPS% ..\code\test\experiment.cpp /Fexperiment %* -popd diff --git a/4ed_defines.h b/common/4coder_defines.h similarity index 75% rename from 4ed_defines.h rename to common/4coder_defines.h index b7341682..a55408ed 100644 --- a/4ed_defines.h +++ b/common/4coder_defines.h @@ -7,10 +7,10 @@ * */ -#ifndef FRED_DEFINES_H -#define FRED_DEFINES_H +// TOP -#include +#if !defined(FRED_DEFINES_H) +#define FRED_DEFINES_H #if !defined (FRED_TYPES) #include @@ -58,13 +58,14 @@ typedef double f64; #define TentativeAssert(c) Assert(c) #define NotImplemented Assert(!"This is not implemented yet!") #define InvalidCodePath Assert(!"Invalid code path!") +#define InvalidPath InvalidCodePath #define AllowLocal(name) (void)name #ifndef ArrayCount # define ArrayCount(array) (sizeof(array)/sizeof(array[0])) #endif + #define OffsetOfStruct(S,c) ((i64)(& ((S*)0)->c )) -#define OffsetOfPtr(s,c) ((i64)((char*)(&(s)->c) - (char*)(s))) #define Swap(T,a,b) do{ T t = a; a = b; b = t; } while(0) @@ -97,17 +98,6 @@ TMin(i32, -2147483647-1); TMin(i64, -9223372036854775807-1); #undef TMin -internal i32 -LargeRoundUp(i32 x, i32 granularity){ - i32 original_x = x; - x /= granularity; - x *= granularity; - if (x < original_x){ - x += granularity; - } - return x; -} - #define Bit_0 (1 << 0) #define Bit_1 (1 << 1) #define Bit_2 (1 << 2) @@ -150,4 +140,57 @@ LargeRoundUp(i32 x, i32 granularity){ #define Gbytes(n) (((u64)n) << 30) #define Tbytes(n) (((u64)n) << 40) -#endif \ No newline at end of file +// +// Rounding +// + +internal u32 +l_round_up_u32(u32 x, u32 granularity){ + u32 new_x = x + granularity - 1; + new_x = new_x - (new_x % granularity); + return(new_x); +} + +internal i32 +l_round_up_i32(i32 x, i32 granularity){ + i32 new_x = (i32)l_round_up_u32((u32)x, (u32)granularity); + return(new_x); +} + +inline i32 +TRUNC32(real32 x) { return (i32)x; } + +inline i32 +FLOOR32(real32 x) { return (i32)(x)-((x!=(i32)(x) && x<0)?1:0); } + +inline i32 +CEIL32(real32 x) { return (i32)(x)+((x!=(i32)(x) && x>0)?1:0); } + +inline i32 +ROUND32(real32 x) { return FLOOR32(x + .5f); } + +inline i32 +DIVCEIL32(i32 n, i32 d) { + i32 q = (n/d); + return q + (q*d < n); +} + +inline real32 +FRACPART32(real32 x) { return x - (i32)x; } + +inline u32 +ROUNDPOT32(u32 v){ + v--; + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + v++; + return v; +} + +#endif + +// BOTTOM + diff --git a/4coder_version.h b/common/4coder_version.h similarity index 95% rename from 4coder_version.h rename to common/4coder_version.h index 9f2ed8b3..674d8113 100644 --- a/4coder_version.h +++ b/common/4coder_version.h @@ -1,6 +1,6 @@ #define MAJOR 4 #define MINOR 0 -#define PATCH 14 +#define PATCH 15 #define VN__(a,b,c) #a"."#b"."#c #define VN_(a,b,c) VN__(a,b,c) diff --git a/buffer/4coder_buffer_abstract.cpp b/file/4coder_buffer.cpp similarity index 69% rename from buffer/4coder_buffer_abstract.cpp rename to file/4coder_buffer.cpp index 38cca6d6..d0898246 100644 --- a/buffer/4coder_buffer_abstract.cpp +++ b/file/4coder_buffer.cpp @@ -1,28 +1,580 @@ /* * Mr. 4th Dimention - Allen Webster * - * 24.10.2015 + * 06.01.2017 * - * Buffer features based on the stringify loop, - * and other abstract buffer features. + * The 4coder base buffer data structure. * */ // TOP -#define Buffer_Init_Type cat_4tech(Buffer_Type, _Init) -#define Buffer_Stream_Type cat_4tech(Buffer_Type, _Stream) +// +// Buffer low level operations +// -inline_4tech void -buffer_stringify(Buffer_Type *buffer, i32 start, i32 end, char *out){ - Buffer_Stream_Type stream = {0}; +// TODO(allen): Put 4coder_seek_types into the file directory. +// Setup a meta system for putting together a file in the custom +// code directory from the export structs and helpers. + +#include "../4coder_seek_types.h" + +typedef struct Cursor_With_Index{ + i32 pos; + i32 index; +} Cursor_With_Index; + +inline void +write_cursor_with_index(Cursor_With_Index *positions, i32 *count, i32 pos){ + positions[(*count)].index = *count; + positions[(*count)].pos = pos; + ++(*count); +} + +#define CursorSwap__(a,b) { Cursor_With_Index t = a; a = b; b = t; } + +internal void +buffer_quick_sort_cursors(Cursor_With_Index *positions, i32 start, i32 pivot){ + i32 mid = start; + i32 pivot_pos = positions[pivot].pos; + for (i32 i = mid; i < pivot; ++i){ + if (positions[i].pos < pivot_pos){ + CursorSwap__(positions[mid], positions[i]); + ++mid; + } + } + CursorSwap__(positions[mid], positions[pivot]); + + if (start < mid - 1) buffer_quick_sort_cursors(positions, start, mid - 1); + if (mid + 1 < pivot) buffer_quick_sort_cursors(positions, mid + 1, pivot); +} + +// TODO(allen): Rewrite this without being a dumbass. +internal void +buffer_quick_unsort_cursors(Cursor_With_Index *positions, i32 start, i32 pivot){ + i32 mid = start; + i32 pivot_index = positions[pivot].index; + for (i32 i = mid; i < pivot; ++i){ + if (positions[i].index < pivot_index){ + CursorSwap__(positions[mid], positions[i]); + ++mid; + } + } + CursorSwap__(positions[mid], positions[pivot]); + + if (start < mid - 1) buffer_quick_unsort_cursors(positions, start, mid - 1); + if (mid + 1 < pivot) buffer_quick_unsort_cursors(positions, mid + 1, pivot); +} + +#undef CursorSwap__ + +inline void +buffer_sort_cursors(Cursor_With_Index *positions, i32 count){ + assert(count > 0); + buffer_quick_sort_cursors(positions, 0, count-1); +} + +inline void +buffer_unsort_cursors(Cursor_With_Index *positions, i32 count){ + assert(count > 0); + buffer_quick_unsort_cursors(positions, 0, count-1); +} + +internal void +buffer_update_cursors(Cursor_With_Index *sorted_positions, i32 count, i32 start, i32 end, i32 len){ + i32 shift_amount = (len - (end - start)); + 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 >= start; --position) position->pos = start; +} + +internal i32 +buffer_batch_debug_sort_check(Buffer_Edit *sorted_edits, i32 edit_count){ + Buffer_Edit *edit = sorted_edits; + i32 i = 0, start_point = 0; + i32 result = 1; + + for (i = 0; i < edit_count; ++i, ++edit){ + if (start_point > edit->start){ + result = 0; break; + } + start_point = (edit->end < edit->start + 1)?(edit->start + 1):(edit->end); + } + + return(result); +} + +internal i32 +buffer_batch_edit_max_shift(Buffer_Edit *sorted_edits, i32 edit_count){ + i32 i = 0; + i32 shift_total = 0, shift_max = 0; + + Buffer_Edit *edit = sorted_edits; + for (i = 0; i < edit_count; ++i, ++edit){ + shift_total += (edit->len - (edit->end - edit->start)); + if (shift_total > shift_max) shift_max = shift_total; + } + + return(shift_max); +} + +internal i32 +buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, i32 count, Buffer_Edit *sorted_edits, i32 edit_count){ + Cursor_With_Index *position = sorted_positions; + Cursor_With_Index *end_position = sorted_positions + count; + Buffer_Edit *edit = sorted_edits; + Buffer_Edit *end_edit = sorted_edits + edit_count; + i32 shift_amount = 0; + i32 start = 0, end = 0; + + for (; edit < end_edit && position < end_position; ++edit){ + start = edit->start; + end = edit->end; + + for (; position->pos < start && position < end_position; ++position){ + position->pos += shift_amount; + } + + for (; position->pos <= end && position < end_position; ++position){ + position->pos = start + shift_amount; + } + + shift_amount += (edit->len - (end - start)); + } + + for (; position < end_position; ++position){ + position->pos += shift_amount; + } + + for (; edit < end_edit; ++edit){ + shift_amount += (edit->len - (edit->end - edit->start)); + } + + return(shift_amount); +} + +internal i32 +eol_convert_in(char *dest, char *src, i32 size){ + i32 i = 0, j = 0, k = 0; + + for (; j < size && src[j] != '\r'; ++j); + memcpy(dest, src, j); + + if (j < size){ + k = 1; + ++j; + for (i = j; i < size; ++i){ + if (src[i] == '\r'){ + memcpy(dest + j - k, src + j, i - j); + ++k; + j = i+1; + } + } + memcpy(dest + j - k, src + j, i - j); + j = i - k; + } + + return(j); +} + +internal i32 +eol_in_place_convert_in(char *data, i32 size){ + i32 i = 0, j = 0, k = 0; + + for (; j < size && data[j] != '\r'; ++j); + + if (j < size){ + k = 1; + ++j; + for (i = j; i < size; ++i){ + if (data[i] == '\r'){ + memmove(data + j - k, data + j, i - j); + ++k; + j = i+1; + } + } + memmove(data + j - k, data + j, i - j); + j = i - k; + } + + return(j); +} + +// TODO(allen): iterative memory check? +internal i32 +eol_convert_out(char *dest, i32 max, char *src, i32 size, i32 *size_out){ + i32 result = 1; + i32 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); +} + +// TODO(allen): iterative memory check? +internal i32 +eol_in_place_convert_out(char *data, i32 size, i32 max, i32 *size_out){ + i32 result = 1; + i32 i = 0; + + for (; i < size; ++i){ + if (data[i] == '\n'){ + memmove(data + i + 1, data + i, size - i); + data[i] = '\r'; + ++i; + ++size; + } + } + + *size_out = size; + return(result); +} + +inline i32 +is_whitespace(char c){ + i32 result; + result = (c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '\f' || c == '\v'); + return(result); +} + +inline i32 +is_alphanumeric_true(char c){ + return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9'); +} + +inline i32 +is_alphanumeric(char c){ + return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '_'); +} + +inline i32 +is_upper(char c){ + return (c >= 'A' && c <= 'Z'); +} + +inline i32 +is_lower(char c){ + return (c >= 'a' && c <= 'z'); +} + +inline char +to_upper(char c){ + if (is_lower(c)){ + c += 'A' - 'a'; + } + return(c); +} + +internal i32 +is_match(char *a, char *b, i32 len){ + i32 result = 1; + for (;len > 0; --len, ++a, ++b) + if (*a != *b) { result = 0; break; } + + return(result); +} + +internal i32 +is_match_insensitive(char *a, char *b, i32 len){ + i32 result = 1; + for (;len > 0; --len, ++a, ++b) + if (to_upper(*a) != to_upper(*b)) { result = 0; break; } + + return(result); +} + +// +// Implementation of the gap buffer +// + +typedef struct Gap_Buffer{ + char *data; + i32 size1; + i32 gap_size; + i32 size2; + i32 max; + + i32 *line_starts; + i32 line_count; + i32 line_max; +} Gap_Buffer; + +inline i32 +buffer_good(Gap_Buffer *buffer){ + i32 good = (buffer->data != 0); + return(good); +} + +inline i32 +buffer_size(Gap_Buffer *buffer){ + i32 size = buffer->size1 + buffer->size2; + return(size); +} + +typedef struct Gap_Buffer_Init{ + Gap_Buffer *buffer; + char *data; + i32 size; +} Gap_Buffer_Init; + +internal Gap_Buffer_Init +buffer_begin_init(Gap_Buffer *buffer, char *data, i32 size){ + Gap_Buffer_Init init; + init.buffer = buffer; + init.data = data; + init.size = size; + return(init); +} + +internal i32 +buffer_init_need_more(Gap_Buffer_Init *init){ + i32 result = 1; + if (init->buffer->data) result = 0; + return(result); +} + +internal i32 +buffer_init_page_size(Gap_Buffer_Init *init){ + i32 result = init->size * 2; + return(result); +} + +internal void +buffer_init_provide_page(Gap_Buffer_Init *init, void *page, i32 page_size){ + Gap_Buffer *buffer = init->buffer; + buffer->data = (char*)page; + buffer->max = page_size; +} + +internal i32 +buffer_end_init(Gap_Buffer_Init *init, void *scratch, i32 scratch_size){ + Gap_Buffer *buffer = init->buffer; + i32 osize1 = 0, size1 = 0, size2 = 0, size = init->size; + i32 result = 0; + + if (buffer->data){ + if (buffer->max >= init->size){ + size2 = size >> 1; + size1 = osize1 = size - size2; + + if (size1 > 0){ + size1 = eol_convert_in(buffer->data, init->data, size1); + if (size2 > 0){ + size2 = eol_convert_in(buffer->data + size1, init->data + osize1, size2); + } + } + + buffer->size1 = size1; + buffer->size2 = size2; + buffer->gap_size = buffer->max - size1 - size2; + memmove(buffer->data + size1 + buffer->gap_size, buffer->data + size1, size2); + + result = 1; + } + } + + return(result); +} + +typedef struct Gap_Buffer_Stream{ + Gap_Buffer *buffer; + char *data; + i32 end; + i32 separated; + i32 absolute_end; + + b32 use_termination_character; + char terminator; +} Gap_Buffer_Stream; +static Gap_Buffer_Stream null_buffer_stream = {0}; + +internal b32 +buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, i32 start, i32 end){ + b32 result = 0; + + if (0 <= start && start < end && end <= buffer->size1 + buffer->size2){ + stream->buffer = buffer; + stream->absolute_end = end; + + if (start < buffer->size1){ + if (buffer->size1 < end){ + stream->separated = 1; + } + else{ + stream->separated = 0; + } + stream->data = buffer->data; + } + else{ + stream->separated = 0; + stream->data = buffer->data + buffer->gap_size; + } + + if (stream->separated){ + stream->end = buffer->size1; + } + else{ + stream->end = end; + } + + if (stream->end > stream->absolute_end){ + stream->end = stream->absolute_end; + } + + result = 1; + } + + if (result == 0){ + if (stream->use_termination_character){ + stream->buffer = buffer; + stream->absolute_end = end; + stream->use_termination_character = 0; + stream->data = (&stream->terminator) - buffer->size1 - buffer->size2; + stream->end = stream->absolute_end + 1; + result = 1; + } + } + + return(result); +} + +internal b32 +buffer_stringify_next(Gap_Buffer_Stream *stream){ + b32 result = 0; + Gap_Buffer *buffer = stream->buffer; + if (stream->separated){ + stream->data = buffer->data + buffer->gap_size; + stream->end = stream->absolute_end; + stream->separated = 0; + result = 1; + } + + if (result == 0){ + if (stream->use_termination_character){ + stream->use_termination_character = 0; + stream->data = (&stream->terminator) - buffer->size1 - buffer->size2; + stream->end = stream->absolute_end + 1; + result = 1; + } + } + + return(result); +} + +internal i32 +buffer_replace_range(Gap_Buffer *buffer, i32 start, i32 end, char *str, i32 len, i32 *shift_amount, + void *scratch, i32 scratch_memory, i32 *request_amount){ + char *data = buffer->data; + i32 size = buffer_size(buffer); + i32 result = 0; + i32 move_size = 0; + + assert(0 <= start); + assert(start <= end); + assert(end <= size); + + *shift_amount = (len - (end - start)); + if (*shift_amount + size <= buffer->max){ + if (end < buffer->size1){ + move_size = buffer->size1 - end; + memmove(data + buffer->size1 + buffer->gap_size - move_size, data + end, move_size); + buffer->size1 -= move_size; + buffer->size2 += move_size; + } + if (start > buffer->size1){ + move_size = start - buffer->size1; + memmove(data + buffer->size1, data + buffer->size1 + buffer->gap_size, move_size); + buffer->size1 += move_size; + buffer->size2 -= move_size; + } + + memcpy(data + start, str, len); + buffer->size2 = size - end; + buffer->size1 = start + len; + buffer->gap_size -= *shift_amount; + + assert(buffer->size1 + buffer->size2 == size + *shift_amount); + assert(buffer->size1 + buffer->gap_size + buffer->size2 == buffer->max); + } + else{ + *request_amount = l_round_up_u32(2*(*shift_amount + size), 4 << 10); + result = 1; + } + + return(result); +} + +typedef struct Buffer_Batch_State{ + i32 i; + i32 shift_total; +} Buffer_Batch_State; + +// TODO(allen): Now that we are just using Gap_Buffer we could afford to improve +// this for the Gap_Buffer's behavior. +internal i32 +buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edit *sorted_edits, char *strings, i32 edit_count, void *scratch, i32 scratch_size, i32 *request_amount){ + Buffer_Edit *edit = 0; + i32 i = state->i; + i32 shift_total = state->shift_total; + i32 shift_amount = 0; + i32 result = 0; + + edit = sorted_edits + i; + for (; i < edit_count; ++i, ++edit){ + result = buffer_replace_range(buffer, edit->start + shift_total, edit->end + shift_total, + strings + edit->str_start, edit->len, &shift_amount, + scratch, scratch_size, request_amount); + if (result) break; + shift_total += shift_amount; + } + + state->shift_total = shift_total; + state->i = i; + + return(result); +} + +internal void* +buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, i32 new_max){ + void *result = buffer->data; + i32 size = buffer_size(buffer); + i32 new_gap_size = new_max - size; + + assert(new_max >= size); + + memcpy(new_data, buffer->data, buffer->size1); + memcpy((char*)new_data + buffer->size1 + new_gap_size, buffer->data + buffer->size1 + buffer->gap_size, buffer->size2); + + buffer->data = (char*)new_data; + buffer->gap_size = new_gap_size; + buffer->max = new_max; + + return(result); +} + +// +// High level buffer operations +// + +inline void +buffer_stringify(Gap_Buffer *buffer, i32 start, i32 end, char *out){ + Gap_Buffer_Stream stream = {0}; i32 i = start; if (buffer_stringify_loop(&stream, buffer, i, end)){ b32 still_looping = 0; do{ i32 size = stream.end - i; - memcpy_4tech(out, stream.data + i, size); + memcpy(out, stream.data + i, size); i = stream.end; out += size; still_looping = buffer_stringify_next(&stream); @@ -30,12 +582,12 @@ buffer_stringify(Buffer_Type *buffer, i32 start, i32 end, char *out){ } } -internal_4tech i32 -buffer_convert_out(Buffer_Type *buffer, char *dest, i32 max){ - Buffer_Stream_Type stream = {0}; +internal i32 +buffer_convert_out(Gap_Buffer *buffer, char *dest, i32 max){ + Gap_Buffer_Stream stream = {0}; i32 i = 0; i32 size = buffer_size(buffer); - assert_4tech(size + buffer->line_count <= max); + assert(size + buffer->line_count <= max); i32 pos = 0; if (buffer_stringify_loop(&stream, buffer, 0, size)){ @@ -44,7 +596,7 @@ buffer_convert_out(Buffer_Type *buffer, char *dest, i32 max){ i32 size = stream.end - i; i32 out_size = 0; i32 result = eol_convert_out(dest + pos, max - pos, stream.data + i, size, &out_size); - assert_4tech(result); + assert(result); i = stream.end; pos += out_size; still_looping = buffer_stringify_next(&stream); @@ -54,15 +606,15 @@ buffer_convert_out(Buffer_Type *buffer, char *dest, i32 max){ return(pos); } -internal_4tech i32 -buffer_count_newlines(Buffer_Type *buffer, i32 start, i32 end){ - Buffer_Stream_Type stream = {0}; +internal i32 +buffer_count_newlines(Gap_Buffer *buffer, i32 start, i32 end){ + Gap_Buffer_Stream stream = {0}; i32 i = start; i32 count = 0; - assert_4tech(0 <= start); - assert_4tech(start <= end); - assert_4tech(end <= buffer_size(buffer)); + assert(0 <= start); + assert(start <= end); + assert(end <= buffer_size(buffer)); if (buffer_stringify_loop(&stream, buffer, i, end)){ b32 still_looping = 0; @@ -86,9 +638,9 @@ typedef struct Buffer_Measure_Starts{ // TODO(allen): Rewrite this with a duff routine // Also make it so that the array goes one past the end // and stores the size in the extra spot. -internal_4tech i32 -buffer_measure_starts(Buffer_Measure_Starts *state, Buffer_Type *buffer){ - Buffer_Stream_Type stream = {0}; +internal i32 +buffer_measure_starts(Buffer_Measure_Starts *state, Gap_Buffer *buffer){ + Gap_Buffer_Stream stream = {0}; i32 size = buffer_size(buffer); i32 start = state->start, i = state->i; i32 *start_ptr = buffer->line_starts + state->count; @@ -113,7 +665,7 @@ buffer_measure_starts(Buffer_Measure_Starts *state, Buffer_Type *buffer){ }while(still_looping); } - assert_4tech(i == size); + assert(i == size); if (start_ptr == start_end){ goto buffer_measure_starts_widths_end; @@ -133,11 +685,11 @@ buffer_measure_starts(Buffer_Measure_Starts *state, Buffer_Type *buffer){ return(result); } -internal_4tech void -buffer_measure_character_starts(Buffer_Type *buffer, i32 *character_starts, i32 mode, i32 virtual_white){ - assert_4tech(mode == 0); +internal void +buffer_measure_character_starts(Gap_Buffer *buffer, i32 *character_starts, i32 mode, i32 virtual_white){ + assert(mode == 0); - Buffer_Stream_Type stream = {0}; + Gap_Buffer_Stream stream = {0}; i32 i = 0; i32 size = buffer_size(buffer); @@ -180,7 +732,7 @@ buffer_measure_character_starts(Buffer_Type *buffer, i32 *character_starts, i32 }while(still_looping); } - assert_4tech(line_index-1 == buffer->line_count); + assert(line_index-1 == buffer->line_count); } enum{ @@ -200,14 +752,14 @@ struct Buffer_Layout_Stop{ }; struct Buffer_Measure_Wrap_Params{ - Buffer_Type *buffer; + Gap_Buffer *buffer; i32 *wrap_line_index; f32 *adv; b32 virtual_white; }; struct Buffer_Measure_Wrap_State{ - Buffer_Stream_Type stream; + Gap_Buffer_Stream stream; i32 i; i32 size; b32 still_looping; @@ -233,7 +785,7 @@ struct Buffer_Measure_Wrap_State{ #define DrYield(PC, n) { *S_ptr = S; S_ptr->__pc__ = PC; return(n); resumespot_##PC:; } #define DrReturn(n) { *S_ptr = S; S_ptr->__pc__ = -1; return(n); } -internal_4tech Buffer_Layout_Stop +internal Buffer_Layout_Stop buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Params params, f32 line_shift, b32 do_wrap, i32 wrap_unit_end){ Buffer_Measure_Wrap_State S = *S_ptr; Buffer_Layout_Stop S_stop; @@ -337,7 +889,7 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para ++S.current_wrap_index; params.wrap_line_index[S.line_index++] = S.current_wrap_index; - assert_4tech(S.line_index-1 == params.buffer->line_count); + assert(S.line_index-1 == params.buffer->line_count); S_stop.status = BLStatus_Finished; DrReturn(S_stop); @@ -347,15 +899,15 @@ buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Para #undef DrYield #undef DrReturn -internal_4tech void -buffer_remeasure_starts(Buffer_Type *buffer, i32 line_start, i32 line_end, i32 line_shift, i32 text_shift){ +internal void +buffer_remeasure_starts(Gap_Buffer *buffer, i32 line_start, i32 line_end, i32 line_shift, i32 text_shift){ i32 *starts = buffer->line_starts; i32 line_count = buffer->line_count; - assert_4tech(0 <= line_start); - assert_4tech(line_start <= line_end); - assert_4tech(line_end < line_count); - assert_4tech(line_count + line_shift <= buffer->line_max); + assert(0 <= line_start); + assert(line_start <= line_end); + assert(line_end < line_count); + assert(line_count + line_shift <= buffer->line_max); ++line_end; @@ -376,12 +928,12 @@ buffer_remeasure_starts(Buffer_Type *buffer, i32 line_start, i32 line_end, i32 l new_line_count += line_shift; new_line_end += line_shift; - memmove_4tech(starts + line_end + line_shift, starts + line_end, - sizeof(i32)*(line_count - line_end)); + memmove(starts + line_end + line_shift, starts + line_end, + sizeof(i32)*(line_count - line_end)); } // Iteration data (yikes! Need better loop system) - Buffer_Stream_Type stream = {0}; + Gap_Buffer_Stream stream = {0}; i32 size = buffer_size(buffer); i32 char_i = starts[line_start]; i32 line_i = line_start; @@ -417,20 +969,20 @@ buffer_remeasure_starts(Buffer_Type *buffer, i32 line_start, i32 line_end, i32 l } buffer_remeasure_starts_end:; - assert_4tech(line_count >= 1); + assert(line_count >= 1); buffer->line_count = new_line_count; } -internal_4tech void -buffer_remeasure_character_starts(Buffer_Type *buffer, i32 line_start, i32 line_end, i32 line_shift, +internal void +buffer_remeasure_character_starts(Gap_Buffer *buffer, i32 line_start, i32 line_end, i32 line_shift, i32 *character_starts, i32 mode, i32 virtual_whitespace){ - assert_4tech(mode == 0); + assert(mode == 0); i32 new_line_count = buffer->line_count; - assert_4tech(0 <= line_start); - assert_4tech(line_start <= line_end); - assert_4tech(line_end < new_line_count - line_shift); + assert(0 <= line_start); + assert(line_start <= line_end); + assert(line_end < new_line_count - line_shift); ++line_end; @@ -441,12 +993,12 @@ buffer_remeasure_character_starts(Buffer_Type *buffer, i32 line_start, i32 line_ line_count -= line_shift; new_line_end += line_shift; - memmove_4tech(character_starts + line_end + line_shift, character_starts + line_end, - sizeof(i32)*(line_count - line_end + 1)); + memmove(character_starts + line_end + line_shift, character_starts + line_end, + sizeof(i32)*(line_count - line_end + 1)); } // Iteration data (yikes! Need better loop system) - Buffer_Stream_Type stream = {0}; + Gap_Buffer_Stream stream = {0}; i32 size = buffer_size(buffer); i32 char_i = buffer->line_starts[line_start]; i32 line_i = line_start; @@ -494,7 +1046,7 @@ buffer_remeasure_character_starts(Buffer_Type *buffer, i32 line_start, i32 line_ }while(still_looping); } - assert_4tech(line_i >= new_line_end); + assert(line_i >= new_line_end); buffer_remeasure_character_starts_end:; @@ -511,14 +1063,14 @@ buffer_remeasure_character_starts(Buffer_Type *buffer, i32 line_start, i32 line_ } } -internal_4tech void -buffer_remeasure_wrap_y(Buffer_Type *buffer, i32 line_start, i32 line_end, i32 line_shift, +internal void +buffer_remeasure_wrap_y(Gap_Buffer *buffer, i32 line_start, i32 line_end, i32 line_shift, f32 *wraps, f32 font_height, f32 *adv, f32 max_width){ i32 new_line_count = buffer->line_count; - assert_4tech(0 <= line_start); - assert_4tech(line_start <= line_end); - assert_4tech(line_end < new_line_count - line_shift); + assert(0 <= line_start); + assert(line_start <= line_end); + assert(line_end < new_line_count - line_shift); ++line_end; @@ -529,12 +1081,11 @@ buffer_remeasure_wrap_y(Buffer_Type *buffer, i32 line_start, i32 line_end, i32 l line_count -= line_shift; new_line_end += line_shift; - memmove_4tech(wraps + line_end + line_shift, wraps + line_end, - sizeof(i32)*(line_count - line_end + 1)); + memmove(wraps + line_end + line_shift, wraps + line_end, sizeof(i32)*(line_count - line_end + 1)); } // Iteration data (yikes! Need better loop system) - Buffer_Stream_Type stream = {0}; + Gap_Buffer_Stream stream = {0}; i32 size = buffer_size(buffer); i32 char_i = buffer->line_starts[line_start]; i32 line_i = line_start; @@ -594,7 +1145,7 @@ buffer_remeasure_wrap_y(Buffer_Type *buffer, i32 line_start, i32 line_end, i32 l } } -internal_4tech i32 +internal i32 binary_search(i32 *array, i32 value, i32 l_bound, i32 u_bound){ i32 start = l_bound, end = u_bound; i32 i = 0; @@ -614,7 +1165,7 @@ binary_search(i32 *array, i32 value, i32 l_bound, i32 u_bound){ else{ break; } - assert_4tech(start < end); + assert(start < end); if (start == end - 1){ i = start; break; @@ -624,39 +1175,39 @@ binary_search(i32 *array, i32 value, i32 l_bound, i32 u_bound){ return(i); } -inline_4tech i32 -buffer_get_line_index_range(Buffer_Type *buffer, i32 pos, i32 l_bound, i32 u_bound){ - assert_4tech(0 <= l_bound); - assert_4tech(l_bound <= u_bound); - assert_4tech(u_bound <= buffer->line_count); +inline i32 +buffer_get_line_index_range(Gap_Buffer *buffer, i32 pos, i32 l_bound, i32 u_bound){ + assert(0 <= l_bound); + assert(l_bound <= u_bound); + assert(u_bound <= buffer->line_count); - assert_4tech(buffer->line_starts != 0); + assert(buffer->line_starts != 0); i32 i = binary_search(buffer->line_starts, pos, l_bound, u_bound); return(i); } -inline_4tech i32 -buffer_get_line_index(Buffer_Type *buffer, i32 pos){ +inline i32 +buffer_get_line_index(Gap_Buffer *buffer, i32 pos){ i32 result = buffer_get_line_index_range(buffer, pos, 0, buffer->line_count); return(result); } -inline_4tech i32 +inline i32 buffer_get_line_index_from_character_pos(i32 *character_starts, i32 pos, i32 l_bound, i32 u_bound){ i32 i = binary_search(character_starts, pos, l_bound, u_bound); return(i); } -inline_4tech i32 +inline i32 buffer_get_line_index_from_wrapped_y(i32 *wrap_line_index, f32 y, f32 line_height, i32 l_bound, i32 u_bound){ i32 wrap_index = FLOOR32(y/line_height); i32 i = binary_search(wrap_line_index, wrap_index, l_bound, u_bound); return(i); } -internal_4tech Partial_Cursor -buffer_partial_from_pos(Buffer_Type *buffer, i32 pos){ +internal Partial_Cursor +buffer_partial_from_pos(Gap_Buffer *buffer, i32 pos){ Partial_Cursor result = {0}; int32_t size = buffer_size(buffer); @@ -675,8 +1226,8 @@ buffer_partial_from_pos(Buffer_Type *buffer, i32 pos){ return(result); } -internal_4tech Partial_Cursor -buffer_partial_from_line_character(Buffer_Type *buffer, i32 line, i32 character){ +internal Partial_Cursor +buffer_partial_from_line_character(Gap_Buffer *buffer, i32 line, i32 character){ Partial_Cursor result = {0}; i32 line_index = line - 1; @@ -710,7 +1261,7 @@ buffer_partial_from_line_character(Buffer_Type *buffer, i32 line, i32 character) } struct Buffer_Cursor_Seek_Params{ - Buffer_Type *buffer; + Gap_Buffer *buffer; Buffer_Seek seek; f32 font_height; f32 *adv; @@ -726,7 +1277,7 @@ struct Buffer_Cursor_Seek_State{ Full_Cursor this_cursor; Full_Cursor prev_cursor; - Buffer_Stream_Type stream; + Gap_Buffer_Stream stream; b32 still_looping; i32 i; i32 size; @@ -745,7 +1296,7 @@ struct Buffer_Cursor_Seek_State{ #define DrYield(PC, n) { *S_ptr = S; S_ptr->__pc__ = PC; return(n); resumespot_##PC:; } #define DrReturn(n) { *S_ptr = S; S_ptr->__pc__ = -1; return(n); } -internal_4tech Buffer_Layout_Stop +internal Buffer_Layout_Stop buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params params, f32 line_shift, b32 do_wrap, i32 wrap_unit_end){ Buffer_Cursor_Seek_State S = *S_ptr; Buffer_Layout_Stop S_stop; @@ -1074,13 +1625,13 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa #undef DrYield #undef DrReturn -internal_4tech void -buffer_invert_edit_shift(Buffer_Type *buffer, Buffer_Edit edit, Buffer_Edit *inverse, char *strings, +internal void +buffer_invert_edit_shift(Gap_Buffer *buffer, Buffer_Edit edit, Buffer_Edit *inverse, char *strings, i32 *str_pos, i32 max, i32 shift_amount){ i32 pos = *str_pos; i32 len = edit.end - edit.start; - assert_4tech(pos >= 0); - assert_4tech(pos + len <= max); + assert(pos >= 0); + assert(pos + len <= max); *str_pos = pos + len; inverse->str_start = pos; @@ -1090,8 +1641,8 @@ buffer_invert_edit_shift(Buffer_Type *buffer, Buffer_Edit edit, Buffer_Edit *inv buffer_stringify(buffer, edit.start, edit.end, strings + pos); } -inline_4tech void -buffer_invert_edit(Buffer_Type *buffer, Buffer_Edit edit, Buffer_Edit *inverse, char *strings, +inline void +buffer_invert_edit(Gap_Buffer *buffer, Buffer_Edit edit, Buffer_Edit *inverse, char *strings, i32 *str_pos, i32 max){ buffer_invert_edit_shift(buffer, edit, inverse, strings, str_pos, max, 0); } @@ -1102,8 +1653,8 @@ typedef struct Buffer_Invert_Batch{ i32 len; } Buffer_Invert_Batch; -internal_4tech i32 -buffer_invert_batch(Buffer_Invert_Batch *state, Buffer_Type *buffer, Buffer_Edit *edits, i32 count, +internal i32 +buffer_invert_batch(Buffer_Invert_Batch *state, Gap_Buffer *buffer, Buffer_Edit *edits, i32 count, Buffer_Edit *inverse, char *strings, i32 *str_pos, i32 max){ i32 shift_amount = state->shift_amount; i32 i = state->i; @@ -1130,7 +1681,7 @@ buffer_invert_batch(Buffer_Invert_Batch *state, Buffer_Type *buffer, Buffer_Edit enum Buffer_Render_Flag{ BRFlag_Special_Character = (1 << 0), - BRFlag_Ghost_Character = (1 << 1) + BRFlag_Ghost_Character = (1 << 1) }; typedef struct Buffer_Render_Item{ @@ -1150,7 +1701,7 @@ typedef struct Render_Item_Write{ f32 x_max; } Render_Item_Write; -inline_4tech Render_Item_Write +inline Render_Item_Write write_render_item(Render_Item_Write write, i32 index, u16 glyphid, u16 flags){ f32 ch_width = write.adv[(u8)glyphid]; @@ -1173,7 +1724,7 @@ write_render_item(Render_Item_Write write, i32 index, u16 glyphid, u16 flags){ // TODO(allen): Reduce the number of parameters. struct Buffer_Render_Params{ - Buffer_Type *buffer; + Gap_Buffer *buffer; Buffer_Render_Item *items; i32 max; i32 *count; @@ -1193,7 +1744,7 @@ struct Buffer_Render_Params{ }; struct Buffer_Render_State{ - Buffer_Stream_Type stream; + Gap_Buffer_Stream stream; b32 still_looping; i32 i; @@ -1216,7 +1767,7 @@ struct Buffer_Render_State{ #define DrYield(PC, n) { *S_ptr = S; S_ptr->__pc__ = PC; return(n); resumespot_##PC:; } #define DrReturn(n) { *S_ptr = S; S_ptr->__pc__ = -1; return(n); } -internal_4tech Buffer_Layout_Stop +internal Buffer_Layout_Stop buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 line_shift, b32 do_wrap, i32 wrap_unit_end){ Buffer_Render_State S = *S_ptr; Buffer_Layout_Stop S_stop; @@ -1295,7 +1846,7 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 switch (params.wrap_slashes){ case WrapIndicator_Show_After_Line: { - S.write = write_render_item(S.write, S.i-1, '\\', BRFlag_Ghost_Character); + S.write = write_render_item(S.write, S.i-1, '\\', BRFlag_Ghost_Character); }break; case WrapIndicator_Show_At_Wrap_Edge: @@ -1410,7 +1961,7 @@ buffer_render_data(Buffer_Render_State *S_ptr, Buffer_Render_Params params, f32 } *params.count = (i32)(S.write.item - params.items); - assert_4tech(*params.count <= params.max); + assert(*params.count <= params.max); S_stop.status = BLStatus_Finished; DrReturn(S_stop); diff --git a/file/4coder_file.cpp b/file/4coder_file.cpp index 0f73fc5b..6ccb01b5 100644 --- a/file/4coder_file.cpp +++ b/file/4coder_file.cpp @@ -47,63 +47,6 @@ edit_pos_set_scroll(File_Edit_Positions *edit_pos, GUI_Scroll_Vars scroll){ edit_pos->last_set_type = EditPos_ScrollSet; } -// -// Undo Basics -// - -enum Edit_Type{ - ED_NORMAL, - ED_REVERSE_NORMAL, - ED_UNDO, - ED_REDO, -}; - -struct Edit_Step{ - Edit_Type type; - union{ - struct{ - b32 can_merge; - Buffer_Edit edit; - i32 next_block; - i32 prev_block; - }; - struct{ - i32 first_child; - i32 inverse_first_child; - i32 inverse_child_count; - i32 special_type; - }; - }; - i32 child_count; -}; - -struct Edit_Stack{ - u8 *strings; - i32 size, max; - - Edit_Step *edits; - i32 edit_count, edit_max; -}; - -struct Small_Edit_Stack{ - u8 *strings; - i32 size, max; - - Buffer_Edit *edits; - i32 edit_count, edit_max; -}; - -struct Undo_Data{ - Edit_Stack undo; - Edit_Stack redo; - Edit_Stack history; - Small_Edit_Stack children; - - i32 history_block_count, history_head_block; - i32 edit_history_cursor; - b32 current_block_normal; -}; - // // Highlighting Information @@ -138,7 +81,7 @@ struct Editing_File_Settings{ static Editing_File_Settings null_editing_file_settings = {0}; struct Editing_File_State{ - Buffer_Type buffer; + Gap_Buffer buffer; i32 *wrap_line_index; i32 wrap_max; diff --git a/file/4coder_file_tests.cpp b/file/4coder_file_tests.cpp index af1677c2..552b5ead 100644 --- a/file/4coder_file_tests.cpp +++ b/file/4coder_file_tests.cpp @@ -9,7 +9,10 @@ // TOP -#include "4coder_file.cpp" +#include "../common/4ed_defines.h" + +#include "4coder_buffer.cpp" +#include "4coder_undo.cpp" int main(){ return(0); diff --git a/file/4coder_undo.cpp b/file/4coder_undo.cpp new file mode 100644 index 00000000..f0e416b1 --- /dev/null +++ b/file/4coder_undo.cpp @@ -0,0 +1,70 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 06.01.2017 + * + * Undo subsystem for 4coder + * + */ + +// TOP + +// +// Undo Basics +// + +enum Edit_Type{ + ED_NORMAL, + ED_REVERSE_NORMAL, + ED_UNDO, + ED_REDO, +}; + +struct Edit_Step{ + Edit_Type type; + union{ + struct{ + b32 can_merge; + Buffer_Edit edit; + i32 next_block; + i32 prev_block; + }; + struct{ + i32 first_child; + i32 inverse_first_child; + i32 inverse_child_count; + i32 special_type; + }; + }; + i32 child_count; +}; + +struct Edit_Stack{ + u8 *strings; + i32 size, max; + + Edit_Step *edits; + i32 edit_count, edit_max; +}; + +struct Small_Edit_Stack{ + u8 *strings; + i32 size, max; + + Buffer_Edit *edits; + i32 edit_count, edit_max; +}; + +struct Undo_Data{ + Edit_Stack undo; + Edit_Stack redo; + Edit_Stack history; + Small_Edit_Stack children; + + i32 history_block_count, history_head_block; + i32 edit_history_cursor; + b32 current_block_normal; +}; + +// BOTTOM + diff --git a/filetrack/4tech_file_track_win32.c b/filetrack/4tech_file_track_win32.c index 43323c8e..952eb5f5 100644 --- a/filetrack/4tech_file_track_win32.c +++ b/filetrack/4tech_file_track_win32.c @@ -430,7 +430,6 @@ shut_down_track_system(File_Track_System *system){ File_Track_Result result = FileTrack_Good; Win32_File_Track_Vars *vars = to_vars(system); - DWORD win32_result = 0; // NOTE(allen): Close all the handles stored in the table. diff --git a/linux_4ed.cpp b/linux_4ed.cpp index 958010a3..8d84567d 100644 --- a/linux_4ed.cpp +++ b/linux_4ed.cpp @@ -4,14 +4,16 @@ * * 14.11.2015 * - * Linux layer for project codename "4ed" + * Linux layer for 4coder * */ // TOP -# include -# include "4ed_defines.h" +#include +#include +#include "common/4coder_defines.h" +#include "common/4coder_version.h" #if FRED_SUPER @@ -19,7 +21,6 @@ # define FSTRING_C # include "4coder_string.h" -#include "4coder_version.h" # include "4coder_keycodes.h" # include "4coder_style.h" # include "4coder_rect.h" @@ -48,7 +49,6 @@ typedef void Custom_Command_Function; struct Application_Links; # include "4ed_os_custom_api.h" -//# include "4coder_custom.h" #else # include "4coder_default_bindings.cpp" diff --git a/4ed_metagen.cpp b/meta/4ed_metagen.cpp similarity index 93% rename from 4ed_metagen.cpp rename to meta/4ed_metagen.cpp index e585b9dd..a9539ca1 100644 --- a/4ed_metagen.cpp +++ b/meta/4ed_metagen.cpp @@ -9,81 +9,24 @@ // TOP -#include "4coder_version.h" +#include "../common/4coder_defines.h" +#include "../common/4coder_version.h" #if !defined(FSTRING_GUARD) -#include "internal_4coder_string.cpp" +#include "../internal_4coder_string.cpp" #endif -#include "4cpp_lexer.h" +#include "../4cpp_lexer.h" #include #include #include #include -#include "4coder_mem.h" +#include "../4coder_mem.h" -// TODO(allen): In the end the metaprogramming base should be one sub-project, the site should be one sub-project, and this code generator should be one sub-project. -#include "site/meta_parser.cpp" - -#define InvalidPath Assert(!"Invalid path of execution") - -typedef struct Out_Context{ - char out_directory_space[256]; - String out_directory; - FILE *file; - String *str; -} Out_Context; - -static void -set_context_directory(Out_Context *context, char *dst_directory){ - context->out_directory = make_fixed_width_string(context->out_directory_space); - copy_sc(&context->out_directory, dst_directory); -} - -static int32_t -begin_file_out(Out_Context *out_context, char *filename, String *out){ - char str_space[512]; - String name = make_fixed_width_string(str_space); - if (out_context->out_directory.size > 0){ - append_ss(&name, out_context->out_directory); - append_sc(&name, "\\"); - } - append_sc(&name, filename); - terminate_with_null(&name); - - int32_t r = 0; - out_context->file = fopen(name.str, "wb"); - out_context->str = out; - out->size = 0; - if (out_context->file){ - r = 1; - } - - return(r); -} - -static void -dump_file_out(Out_Context out_context){ - fwrite(out_context.str->str, 1, out_context.str->size, out_context.file); - out_context.str->size = 0; -} - -static void -end_file_out(Out_Context out_context){ - dump_file_out(out_context); - fclose(out_context.file); -} - -static String -make_out_string(int32_t x){ - String str; - str.size = 0; - str.memory_size = x; - str.str = (char*)malloc(x); - return(str); -} +#include "meta_parser.cpp" +#include "out_context.cpp" ////////////////////////////////////////////////////////////////////////////////////////////////// char *keys_that_need_codes[] = { diff --git a/build.cpp b/meta/build.cpp similarity index 73% rename from build.cpp rename to meta/build.cpp index 197514e1..5cd7e772 100644 --- a/build.cpp +++ b/meta/build.cpp @@ -10,10 +10,10 @@ #include #include -#include "4coder_version.h" +#include "../common/4coder_version.h" #define FSTRING_INLINE static -#include "internal_4coder_string.cpp" +#include "../internal_4coder_string.cpp" // // reusable @@ -21,7 +21,7 @@ #define IS_64BIT -// NOTE(allen): Compiler OS cracking. +// NOTE(allen): Compiler/OS cracking. #if defined(_MSC_VER) # define IS_CL @@ -75,7 +75,7 @@ static int32_t prev_error = 0; static void init_time_system(); static uint64_t get_time(); static int32_t get_current_directory(char *buffer, int32_t max); -static void execute(char *dir, char *str, char *args); +static void execute_in_dir(char *dir, char *str, char *args); static void make_folder_if_missing(char *dir, char *folder); static void clear_folder(char *folder); @@ -169,7 +169,7 @@ get_current_directory(char *buffer, int32_t max){ } static void -execute(char *dir, char *str, char *args){ +execute_in_dir(char *dir, char *str, char *args){ if (dir){ Temp_Dir temp = pushdir(dir); if (args){ @@ -201,8 +201,6 @@ slash_fix(char *path){ static void make_folder_if_missing(char *dir, char *folder){ - slash_fix(dir); - char space[1024]; String path = make_fixed_width_string(space); append_sc(&path, dir); @@ -225,7 +223,6 @@ make_folder_if_missing(char *dir, char *folder){ static void clear_folder(char *folder){ - slash_fix(folder); systemf("del /S /Q /F %s\\* & rmdir /S /Q %s & mkdir %s", folder, folder, folder); } @@ -256,16 +253,11 @@ copy_file(char *path, char *file, char *folder1, char *folder2, char *newname){ } terminate_with_null(&b); - slash_fix(src); - slash_fix(dst); - CopyFileA(src, dst, 0); } static void copy_all(char *source, char *tag, char *folder){ - slash_fix(source); - slash_fix(folder); if (source){ systemf("copy %s\\%s %s\\*", source, tag, folder); } @@ -279,9 +271,6 @@ zip(char *parent, char *folder, char *dest){ char cdir[512]; get_current_directory(cdir, sizeof(cdir)); - slash_fix(parent); - slash_fix(dest); - Temp_Dir temp = pushdir(parent); systemf("%s\\zip %s\\4tech_gobble.zip", cdir, cdir); popdir(temp); @@ -337,7 +326,7 @@ get_current_directory(char *buffer, int32_t max){ } static void -execute(char *dir, char *str, char *args){ +execute_in_dir(char *dir, char *str, char *args){ if (dir){ if (args){ Temp_Dir temp = pushdir(dir); @@ -543,10 +532,6 @@ init_build_line(Build_Line *line){ static void build_cl(uint32_t flags, char *code_path, char *code_file, char *out_path, char *out_file, char *exports){ - slash_fix(out_path); - slash_fix(code_path); - slash_fix(code_file); - Build_Line line; init_build_line(&line); @@ -706,10 +691,6 @@ buildsuper(char *code_path, char *out_path, char *filename){ Temp_Dir temp = pushdir(out_path); #if defined(IS_CL) - slash_fix(filename); - slash_fix(out_path); - slash_fix(code_path); - systemf("call \"%s\\buildsuper.bat\" %s", code_path, filename); #elif defined(IS_GCC) @@ -723,119 +704,21 @@ buildsuper(char *code_path, char *out_path, char *filename){ popdir(temp); } -#define D_META_DIR "../meta" -#define D_META_FSM_DIR "../meta/fsmgen" -#define D_META_GEN_DIR "../meta/metagen" -#define D_BUILD_DIR "../build" -#define D_BUILD_SITE_DIR "../build/site" -#define D_SITE_GEN_DIR "../build/site/sitegen" +#define META_DIR "../meta" +#define BUILD_DIR "../build" -#define D_SITE_DIR "../site" -#define D_PACK_DIR "../distributions" -#define D_PACK_DATA_DIR "../data/dist_files" -#define D_DATA_DIR "../data/test" +#define SITE_DIR "../site" +#define PACK_DIR "../distributions" +#define PACK_DATA_DIR "../data/dist_files" +#define DATA_DIR "../data/test" -#define D_PACK_ALPHA_PAR_DIR "../current_dist" -#define D_PACK_SUPER_PAR_DIR "../current_dist_super" -#define D_PACK_POWER_PAR_DIR "../current_dist_power" +#define PACK_ALPHA_PAR_DIR "../current_dist" +#define PACK_SUPER_PAR_DIR "../current_dist_super" +#define PACK_POWER_PAR_DIR "../current_dist_power" -#define D_PACK_ALPHA_DIR D_PACK_ALPHA_PAR_DIR"/4coder" -#define D_PACK_SUPER_DIR D_PACK_SUPER_PAR_DIR"/4coder" -#define D_PACK_POWER_DIR D_PACK_POWER_PAR_DIR"/power" - -static char *META_DIR = 0; -static char *META_FSM_DIR = 0; -static char *META_GEN_DIR = 0; -static char *BUILD_DIR = 0; -static char *BUILD_SITE_DIR = 0; -static char *SITE_GEN_DIR = 0; -static char *SITE_DIR = 0; -static char *PACK_DIR = 0; -static char *PACK_DATA_DIR = 0; -static char *DATA_DIR = 0; -static char *PACK_ALPHA_PAR_DIR = 0; -static char *PACK_SUPER_PAR_DIR = 0; -static char *PACK_POWER_PAR_DIR = 0; -static char *PACK_ALPHA_DIR = 0; -static char *PACK_SUPER_DIR = 0; -static char *PACK_POWER_DIR = 0; - -static char* -get_head(String builder){ - return(builder.str + builder.size); -} - -static void -init_global_strings(){ - int32_t size = (1 << 12); - char *base = (char*)malloc(size); - String builder = make_string_cap(base, 0, size); - String term = make_string((void*)"\0", 1); - - META_DIR = get_head(builder); - append_sc(&builder, D_META_DIR); - append_ss(&builder, term); - - META_FSM_DIR = get_head(builder); - append_sc(&builder, D_META_FSM_DIR); - append_ss(&builder, term); - - META_GEN_DIR = get_head(builder); - append_sc(&builder, D_META_GEN_DIR); - append_ss(&builder, term); - - BUILD_DIR = get_head(builder); - append_sc(&builder, D_BUILD_DIR); - append_ss(&builder, term); - - BUILD_SITE_DIR = get_head(builder); - append_sc(&builder, D_BUILD_SITE_DIR); - append_ss(&builder, term); - - SITE_GEN_DIR = get_head(builder); - append_sc(&builder, D_SITE_GEN_DIR); - append_ss(&builder, term); - - SITE_DIR = get_head(builder); - append_sc(&builder, D_SITE_DIR); - append_ss(&builder, term); - - PACK_DIR = get_head(builder); - append_sc(&builder, D_PACK_DIR); - append_ss(&builder, term); - - PACK_DATA_DIR = get_head(builder); - append_sc(&builder, D_PACK_DATA_DIR); - append_ss(&builder, term); - - DATA_DIR = get_head(builder); - append_sc(&builder, D_DATA_DIR); - append_ss(&builder, term); - - PACK_ALPHA_PAR_DIR = get_head(builder); - append_sc(&builder, D_PACK_ALPHA_PAR_DIR); - append_ss(&builder, term); - - PACK_SUPER_PAR_DIR = get_head(builder); - append_sc(&builder, D_PACK_SUPER_PAR_DIR); - append_ss(&builder, term); - - PACK_POWER_PAR_DIR = get_head(builder); - append_sc(&builder, D_PACK_POWER_PAR_DIR); - append_ss(&builder, term); - - PACK_ALPHA_DIR = get_head(builder); - append_sc(&builder, D_PACK_ALPHA_DIR); - append_ss(&builder, term); - - PACK_SUPER_DIR = get_head(builder); - append_sc(&builder, D_PACK_SUPER_DIR); - append_ss(&builder, term); - - PACK_POWER_DIR = get_head(builder); - append_sc(&builder, D_PACK_POWER_DIR); - append_ss(&builder, term); -} +#define PACK_ALPHA_DIR PACK_ALPHA_PAR_DIR"/4coder" +#define PACK_SUPER_DIR PACK_SUPER_PAR_DIR"/4coder" +#define PACK_POWER_DIR PACK_POWER_PAR_DIR"/power" #if defined(IS_WINDOWS) #define PLAT_LAYER "win32_4ed.cpp" @@ -845,18 +728,23 @@ init_global_strings(){ #error No platform layer defined for this OS. #endif +#define DECL_STR(n,s) char n[] = s; slash_fix(n) + static void fsm_generator(char *cdir){ { + DECL_STR(file, "meta/fsm_table_generator.cpp"); + DECL_STR(dir, META_DIR); + BEGIN_TIME_SECTION(); - build(OPTS | DEBUG_INFO, cdir, "fsm_table_generator.cpp", - META_DIR, "fsmgen", 0); + build(OPTS | DEBUG_INFO, cdir, file, dir, "fsmgen", 0); END_TIME_SECTION("build fsm generator"); } if (prev_error == 0){ + DECL_STR(cmd, META_DIR"/fsmgen"); BEGIN_TIME_SECTION(); - execute(cdir, META_FSM_DIR, 0); + execute_in_dir(cdir, cmd, 0); END_TIME_SECTION("run fsm generator"); } } @@ -864,14 +752,18 @@ fsm_generator(char *cdir){ static void metagen(char *cdir){ { + DECL_STR(file, "meta/4ed_metagen.cpp"); + DECL_STR(dir, META_DIR); + BEGIN_TIME_SECTION(); - build(OPTS | INCLUDES | DEBUG_INFO, cdir, "4ed_metagen.cpp", META_DIR, "metagen", 0); + build(OPTS | INCLUDES | DEBUG_INFO, cdir, file, dir, "metagen", 0); END_TIME_SECTION("build metagen"); } if (prev_error == 0){ + DECL_STR(cmd, META_DIR"/metagen"); BEGIN_TIME_SECTION(); - execute(cdir, META_GEN_DIR, 0); + execute_in_dir(cdir, cmd, 0); END_TIME_SECTION("run metagen"); } } @@ -881,7 +773,7 @@ enum{ Custom_Experiments, Custom_Casey, Custom_ChronalVim, - CUSTOM_COUNT + Custom_COUNT }; static void @@ -895,52 +787,49 @@ do_buildsuper(char *cdir, int32_t custom_option){ case Custom_Default: { copy_sc(&str, "../code/4coder_default_bindings.cpp"); - terminate_with_null(&str); - buildsuper(cdir, BUILD_DIR, str.str); }break; case Custom_Experiments: { #if defined(IS_WINDOWS) copy_sc(&str, "../code/internal_4coder_tests.cpp"); - terminate_with_null(&str); - buildsuper(cdir, BUILD_DIR, str.str); #else copy_sc(&str, "../code/power/4coder_experiments.cpp"); - terminate_with_null(&str); - buildsuper(cdir, BUILD_DIR, str.str); #endif }break; case Custom_Casey: { copy_sc(&str, "../code/power/4coder_casey.cpp"); - terminate_with_null(&str); - buildsuper(cdir, BUILD_DIR, str.str); }break; case Custom_ChronalVim: { copy_sc(&str, "../4vim/4coder_chronal.cpp"); - terminate_with_null(&str); - buildsuper(cdir, BUILD_DIR, str.str); }break; } + terminate_with_null(&str); + + DECL_STR(dir, BUILD_DIR); + buildsuper(cdir, dir, str.str); + END_TIME_SECTION("build custom"); } static void build_main(char *cdir, uint32_t flags){ + DECL_STR(dir, BUILD_DIR); { + DECL_STR(file, "4ed_app_target.cpp"); BEGIN_TIME_SECTION(); - build(OPTS | INCLUDES | SHARED_CODE | flags, cdir, "4ed_app_target.cpp", BUILD_DIR, "4ed_app"DLL, "/EXPORT:app_get_functions"); + build(OPTS | INCLUDES | SHARED_CODE | flags, cdir, file, dir, "4ed_app"DLL, "/EXPORT:app_get_functions"); END_TIME_SECTION("build 4ed_app"); } { BEGIN_TIME_SECTION(); - build(OPTS | INCLUDES | LIBS | ICON | flags, cdir, PLAT_LAYER, BUILD_DIR, "4ed", 0); + build(OPTS | INCLUDES | LIBS | ICON | flags, cdir, PLAT_LAYER, dir, "4ed", 0); END_TIME_SECTION("build 4ed"); } } @@ -957,24 +846,18 @@ standard_build(char *cdir, uint32_t flags){ static void site_build(char *cdir, uint32_t flags){ { + DECL_STR(file, "site/sitegen.cpp"); + DECL_STR(dir, BUILD_DIR"/site"); BEGIN_TIME_SECTION(); - // TODO(allen): Figure out how to do these strings the right way... fuck. -#if defined(IS_WINDOWS) - build(OPTS | SITE_INCLUDES | flags, cdir, "site\\sitegen.cpp", BUILD_SITE_DIR, "sitegen", 0); -#else - build(OPTS | SITE_INCLUDES | flags, cdir, "site/sitegen.cpp", BUILD_SITE_DIR, "sitegen", 0); -#endif + build(OPTS | SITE_INCLUDES | flags, cdir, file, dir, "sitegen", 0); END_TIME_SECTION("build sitegen"); } { BEGIN_TIME_SECTION(); -#if defined(IS_WINDOWS) - systemf("..\\build\\site\\sitegen . ..\\foreign\\site-resources site\\source_material ..\\site"); -#else - systemf("../build/site/sitegen . ../foreign/site-resources site/source_material ../site"); -#endif + DECL_STR(cmd, "../build/site/sitegen . ../site_resources site/source_material ../site"); + systemf(cmd); END_TIME_SECTION("run sitegen"); } @@ -984,8 +867,7 @@ static void get_4coder_dist_name(String *zip_file, int32_t OS_specific, char *tier, char *ext){ zip_file->size = 0; - append_sc(zip_file, PACK_DIR); - append_sc(zip_file, "/"); + append_sc(zip_file, PACK_DIR"/"); append_sc(zip_file, tier); append_sc(zip_file, "/4coder-"); @@ -1027,69 +909,82 @@ package(char *cdir){ // NOTE(allen): alpha build_main(cdir, OPTIMIZATION | KEEP_ASSERT | DEBUG_INFO); - clear_folder(PACK_ALPHA_PAR_DIR); - make_folder_if_missing(PACK_ALPHA_DIR, "3rdparty"); - make_folder_if_missing(PACK_DIR, "alpha"); - copy_file(BUILD_DIR, "4ed"EXE, PACK_ALPHA_DIR, 0, 0); - ONLY_WINDOWS(copy_file(BUILD_DIR, "4ed"PDB, PACK_ALPHA_DIR, 0, 0)); - copy_file(BUILD_DIR, "4ed_app"DLL, PACK_ALPHA_DIR, 0, 0); - ONLY_WINDOWS(copy_file(BUILD_DIR, "4ed_app"PDB, PACK_ALPHA_DIR, 0, 0)); - copy_all (PACK_DATA_DIR, "*", PACK_ALPHA_DIR); - copy_file(0, "README.txt", PACK_ALPHA_DIR, 0, 0); - copy_file(0, "TODO.txt", PACK_ALPHA_DIR, 0, 0); - copy_file(DATA_DIR, "release-config.4coder", PACK_ALPHA_DIR, 0, "config.4coder"); + DECL_STR(build_dir, BUILD_DIR); + DECL_STR(site_dir, SITE_DIR); + DECL_STR(pack_dir, PACK_DIR); + DECL_STR(pack_data_dir, PACK_DATA_DIR); + DECL_STR(data_dir, DATA_DIR); + + DECL_STR(pack_alpha_par_dir, PACK_ALPHA_PAR_DIR); + DECL_STR(pack_super_par_dir, PACK_SUPER_PAR_DIR); + DECL_STR(pack_power_par_dir, PACK_POWER_PAR_DIR); + + DECL_STR(pack_alpha_dir, PACK_ALPHA_DIR); + DECL_STR(pack_super_dir, PACK_SUPER_DIR); + DECL_STR(pack_power_dir, PACK_POWER_DIR); + + clear_folder(pack_alpha_par_dir); + make_folder_if_missing(pack_alpha_dir, "3rdparty"); + make_folder_if_missing(pack_dir, "alpha"); + copy_file(build_dir, "4ed"EXE, pack_alpha_dir, 0, 0); + ONLY_WINDOWS(copy_file(build_dir, "4ed"PDB, pack_alpha_dir, 0, 0)); + copy_file(build_dir, "4ed_app"DLL, pack_alpha_dir, 0, 0); + ONLY_WINDOWS(copy_file(build_dir, "4ed_app"PDB, pack_alpha_dir, 0, 0)); + copy_all (pack_data_dir, "*", pack_alpha_dir); + copy_file(0, "README.txt", pack_alpha_dir, 0, 0); + copy_file(0, "TODO.txt", pack_alpha_dir, 0, 0); + copy_file(DATA_DIR, "release-config.4coder", pack_alpha_dir, 0, "config.4coder"); get_4coder_dist_name(&str, 1, "alpha", "zip"); - zip(PACK_ALPHA_PAR_DIR, "4coder", str.str); + zip(pack_alpha_par_dir, "4coder", str.str); // NOTE(allen): super build_main(cdir, OPTIMIZATION | KEEP_ASSERT | DEBUG_INFO | SUPER); do_buildsuper(cdir, Custom_Default); - clear_folder(PACK_SUPER_PAR_DIR); - make_folder_if_missing(PACK_SUPER_DIR, "3rdparty"); - make_folder_if_missing(PACK_DIR, "super"); - make_folder_if_missing(PACK_DIR, "super-docs"); + clear_folder(pack_super_par_dir); + make_folder_if_missing(pack_super_dir, "3rdparty"); + make_folder_if_missing(pack_dir, "super"); + make_folder_if_missing(pack_dir, "super-docs"); - copy_file(BUILD_DIR, "4ed"EXE, PACK_SUPER_DIR, 0, 0); - ONLY_WINDOWS(copy_file(BUILD_DIR, "4ed"PDB, PACK_SUPER_DIR, 0, 0)); - copy_file(BUILD_DIR, "4ed_app"DLL, PACK_SUPER_DIR, 0, 0); - ONLY_WINDOWS(copy_file(BUILD_DIR, "4ed_app"PDB, PACK_SUPER_DIR, 0, 0)); - copy_file(BUILD_DIR, "4coder_custom"DLL, PACK_SUPER_DIR, 0, 0); + copy_file(build_dir, "4ed"EXE, pack_super_dir, 0, 0); + ONLY_WINDOWS(copy_file(build_dir, "4ed"PDB, pack_super_dir, 0, 0)); + copy_file(build_dir, "4ed_app"DLL, pack_super_dir, 0, 0); + ONLY_WINDOWS(copy_file(build_dir, "4ed_app"PDB, pack_super_dir, 0, 0)); + copy_file(build_dir, "4coder_custom"DLL, pack_super_dir, 0, 0); - copy_all (PACK_DATA_DIR, "*", PACK_SUPER_DIR); - copy_file(0, "README.txt", PACK_SUPER_DIR, 0, 0); - copy_file(0, "TODO.txt", PACK_SUPER_DIR, 0, 0); - copy_file(DATA_DIR, "release-config.4coder", PACK_SUPER_DIR, 0, "config.4coder"); + copy_all (pack_data_dir, "*", pack_super_dir); + copy_file(0, "README.txt", pack_super_dir, 0, 0); + copy_file(0, "TODO.txt", pack_super_dir, 0, 0); + copy_file(data_dir, "release-config.4coder", pack_super_dir, 0, "config.4coder"); - copy_all (0, "4coder_*.h", PACK_SUPER_DIR); - copy_all (0, "4coder_*.cpp", PACK_SUPER_DIR); - copy_all (0, "4cpp_*.h", PACK_SUPER_DIR); - copy_all (0, "4cpp_*.c", PACK_SUPER_DIR); - copy_file(0, "buildsuper"BAT, PACK_SUPER_DIR, 0, 0); + copy_all (0, "4coder_*.h", pack_super_dir); + copy_all (0, "4coder_*.cpp", pack_super_dir); + copy_all (0, "4cpp_*.h", pack_super_dir); + copy_all (0, "4cpp_*.c", pack_super_dir); + copy_file(0, "buildsuper"BAT, pack_super_dir, 0, 0); get_4coder_dist_name(&str, 0, "API", "html"); str2 = front_of_directory(str); - copy_file(SITE_DIR, "custom_docs.html", PACK_DIR, "super-docs", str2.str); + copy_file(site_dir, "custom_docs.html", pack_dir, "super-docs", str2.str); get_4coder_dist_name(&str, 1, "super", "zip"); - zip(PACK_SUPER_PAR_DIR, "4coder", str.str); + zip(pack_super_par_dir, "4coder", str.str); // NOTE(allen): power - clear_folder(PACK_POWER_PAR_DIR); - make_folder_if_missing(PACK_POWER_DIR, 0); - make_folder_if_missing(PACK_DIR, "power"); - copy_all("power", "*", PACK_POWER_DIR); + clear_folder(pack_power_par_dir); + make_folder_if_missing(pack_power_dir, 0); + make_folder_if_missing(pack_dir, "power"); + copy_all("power", "*", pack_power_dir); get_4coder_dist_name(&str, 0, "power", "zip"); - zip(PACK_POWER_PAR_DIR, "power", str.str); + zip(pack_power_par_dir, "power", str.str); } #if defined(DEV_BUILD) int main(int argc, char **argv){ init_time_system(); - init_global_strings(); char cdir[256]; @@ -1125,7 +1020,6 @@ int main(int argc, char **argv){ int main(int argc, char **argv){ init_time_system(); - init_global_strings(); char cdir[256]; diff --git a/fsm_table_generator.cpp b/meta/fsm_table_generator.cpp similarity index 99% rename from fsm_table_generator.cpp rename to meta/fsm_table_generator.cpp index d7bcf0ee..05bf6219 100644 --- a/fsm_table_generator.cpp +++ b/meta/fsm_table_generator.cpp @@ -14,8 +14,8 @@ #define Assert(n) do{ if (!(n)) { *(int*)0 = 0xA11E; } }while(0) #define ArrayCount(a) (sizeof(a)/sizeof(*a)) -#include "4cpp_lexer_types.h" -#include "4ed_mem_ansi.c" +#include "../4cpp_lexer_types.h" +#include "../4ed_mem_ansi.c" typedef struct Whitespace_FSM{ unsigned char pp_state; diff --git a/site/meta_parser.cpp b/meta/meta_parser.cpp similarity index 99% rename from site/meta_parser.cpp rename to meta/meta_parser.cpp index 1e21591d..5fe55e8b 100644 --- a/site/meta_parser.cpp +++ b/meta/meta_parser.cpp @@ -16,14 +16,14 @@ #include "internal_4coder_string.cpp" #endif -#include "4cpp_lexer.h" +#include "../4cpp_lexer.h" #include #include #include #include -#include "4coder_mem.h" +#include "../4coder_mem.h" typedef struct Parse_Context{ Cpp_Token *token_s; diff --git a/site/out_context.cpp b/meta/out_context.cpp similarity index 100% rename from site/out_context.cpp rename to meta/out_context.cpp diff --git a/readme_generator.c b/meta/readme_generator.c similarity index 100% rename from readme_generator.c rename to meta/readme_generator.c diff --git a/package.sh b/package.sh index 3b6f65f7..ca2ce96e 100644 --- a/package.sh +++ b/package.sh @@ -3,5 +3,5 @@ WARNINGS="-Wno-write-strings" FLAGS="-D_GNU_SOURCE -fPIC -fpermissive -DPACKAGE" -g++ $WARNINGS $FLAGS build.cpp -g -o ../build/build +g++ $WARNINGS $FLAGS meta/build.cpp -g -o ../build/build ../build/build diff --git a/project.4coder b/project.4coder index 5cc61b75..0be2f5ed 100644 --- a/project.4coder +++ b/project.4coder @@ -1,10 +1,9 @@ extensions=".c.cpp.h.hpp.bat.sh"; -// NOTE(allen): There is some kind of bug where hitting f12 causes a crash. It looks like there is a special meaning placed on some fkeys by windows, which I have not found how to disable yet. fkey_command_win[1] = {"build.bat", "*compilation*", true}; fkey_command_win[2] = {"..\\misc\\run.bat", "*run*"}; fkey_command_win[3] = {"site\\build.bat", "*compilation*", true}; -fkey_command_win[4] = {"file\\run_tests.bat", "*tests*"}; +fkey_command_win[4] = {"file\\run_tests.bat", "*tests*", true}; fkey_command_win[5] = {0, 0}; fkey_command_win[6] = {0, 0}; fkey_command_win[7] = {0, 0}; diff --git a/site/abstract_document.cpp b/site/abstract_document.cpp index d6ee1883..77056780 100644 --- a/site/abstract_document.cpp +++ b/site/abstract_document.cpp @@ -9,11 +9,6 @@ // TOP -#if !defined(ABSTRACT_DOCUMENT_H) -#define ABSTRACT_DOCUMENT_H - -#define NotImplemented Assert(!"Not Implemented!") - // Enriched Text struct Enriched_Text{ @@ -65,20 +60,20 @@ enum{ struct Document_Item{ Document_Item *next; Document_Item *parent; - int32_t type; + i32 type; union{ struct{ Document_Item *first_child; Document_Item *last_child; String name; String id; - int32_t show_title; + i32 show_title; } section; struct{ Meta_Unit *unit; Alternate_Names_Array *alt_names; - int32_t alt_name_type; + i32 alt_name_type; } unit_elements; struct{ @@ -108,7 +103,7 @@ struct Basic_List{ }; struct Abstract_Item{ - int32_t item_type; + i32 item_type; char *name; // Document value members @@ -118,7 +113,7 @@ struct Abstract_Item{ // Document building members Partition *part; Document_Item *section_stack[16]; - int32_t section_top; + i32 section_top; // Image value members char *source_file; @@ -130,7 +125,7 @@ struct Abstract_Item{ static Abstract_Item null_abstract_item = {0}; struct Image_Instantiation{ - int32_t w, h; + i32 w, h; }; struct Document_System{ @@ -148,8 +143,8 @@ create_document_system(Partition *part){ } static void* -push_item_on_list(Partition *part, Basic_List *list, int32_t item_size){ - int32_t mem_size = item_size + sizeof(Basic_Node); +push_item_on_list(Partition *part, Basic_List *list, i32 item_size){ + i32 mem_size = item_size + sizeof(Basic_Node); void *mem = push_block(part, mem_size); assert(mem != 0); memset(mem, 0, mem_size); @@ -203,7 +198,7 @@ get_item_by_name(Basic_List list, char *name){ } static Image_Instantiation* -get_image_instantiation(Basic_List list, int32_t w, int32_t h){ +get_image_instantiation(Basic_List list, i32 w, i32 h){ Image_Instantiation *result = 0; for (Basic_Node *node = list.head; @@ -232,15 +227,15 @@ create_item(Partition *part, Basic_List *list, char *name){ } static void -add_image_instantiation(Partition *part, Basic_List *list, int32_t w, int32_t h){ +add_image_instantiation(Partition *part, Basic_List *list, i32 w, i32 h){ Image_Instantiation *instantiation = (Image_Instantiation*)push_item_on_list(part, list, sizeof(Image_Instantiation)); instantiation->w = w; instantiation->h = h; } static void -set_section_name(Partition *part, Document_Item *item, char *name, int32_t show_title){ - int32_t name_len = str_size(name); +set_section_name(Partition *part, Document_Item *item, char *name, i32 show_title){ + i32 name_len = str_size(name); item->section.name = make_string_cap(push_array(part, char, name_len+1), 0, name_len+1); partition_align(part, 8); append_sc(&item->section.name, name); @@ -249,14 +244,14 @@ set_section_name(Partition *part, Document_Item *item, char *name, int32_t show_ static void set_section_id(Partition *part, Document_Item *item, char *id){ - int32_t id_len = str_size(id); + i32 id_len = str_size(id); item->section.id = make_string_cap(push_array(part, char, id_len+1), 0, id_len+1); partition_align(part, 8); append_sc(&item->section.id, id); } static void -begin_document_description(Abstract_Item *doc, Partition *part, char *title, int32_t show_title){ +begin_document_description(Abstract_Item *doc, Partition *part, char *title, i32 show_title){ *doc = null_abstract_item; doc->item_type = ItemType_Document; doc->part = part; @@ -290,23 +285,23 @@ add_image_description(Document_System *system, char *source_file, char *extensio item->source_file = source_file; item->name = name; - int32_t w = 0, h = 0, comp = 0; - int32_t stbi_r = stbi_info(source_file, &w, &h, &comp); + i32 w = 0, h = 0, comp = 0; + i32 stbi_r = stbi_info(source_file, &w, &h, &comp); if (!stbi_r){ fprintf(stderr, "Did not find file %s\n", source_file); item->w_h_ratio = 1.f; item->h_w_ratio = 1.f; } else{ - item->w_h_ratio = ((float)w/(float)h); - item->h_w_ratio = ((float)h/(float)w); + item->w_h_ratio = ((float)w/(float)h); + item->h_w_ratio = ((float)h/(float)w); } } return(item); } static Abstract_Item* -begin_document_description(Document_System *system, char *title, char *name, int32_t show_title){ +begin_document_description(Document_System *system, char *title, char *name, i32 show_title){ Abstract_Item *item = create_item(system->part, &system->doc_list, name); if (item){ begin_document_description(item, system->part, title, show_title); @@ -380,7 +375,7 @@ add_element_list(Abstract_Item *doc, Meta_Unit *unit){ } static void -add_element_list(Abstract_Item *doc, Meta_Unit *unit, Alternate_Names_Array *alt_names, int32_t alt_name_type){ +add_element_list(Abstract_Item *doc, Meta_Unit *unit, Alternate_Names_Array *alt_names, i32 alt_name_type){ Document_Item *parent = doc->section_stack[doc->section_top]; Document_Item *item = push_struct(doc->part, Document_Item); *item = null_document_item; @@ -404,7 +399,7 @@ add_full_elements(Abstract_Item *doc, Meta_Unit *unit){ } static void -add_full_elements(Abstract_Item *doc, Meta_Unit *unit, Alternate_Names_Array *alt_names, int32_t alt_name_type){ +add_full_elements(Abstract_Item *doc, Meta_Unit *unit, Alternate_Names_Array *alt_names, i32 alt_name_type){ Document_Item *parent = doc->section_stack[doc->section_top]; Document_Item *item = push_struct(doc->part, Document_Item); *item = null_document_item; @@ -479,21 +474,21 @@ add_enriched_text(Abstract_Item *doc, Enriched_Text *text){ #define HTML_EXAMPLE_CODE_CLOSE "" struct Section_Counter{ - int32_t counter[16]; - int32_t nest_level; + i32 counter[16]; + i32 nest_level; }; -static int32_t -doc_get_link_string(Abstract_Item *doc, char *space, int32_t capacity){ +static i32 +doc_get_link_string(Abstract_Item *doc, char *space, i32 capacity){ String str = make_string_cap(space, 0, capacity); append_sc(&str, doc->name); append_sc(&str, ".html"); - int32_t result = terminate_with_null(&str); + i32 result = terminate_with_null(&str); return(result); } -static int32_t -img_get_link_string(Abstract_Item *img, char *space, int32_t capacity, int32_t w, int32_t h){ +static i32 +img_get_link_string(Abstract_Item *img, char *space, i32 capacity, i32 w, i32 h){ String str = make_string_cap(space, 0, capacity); append_sc(&str, img->name); @@ -504,14 +499,14 @@ img_get_link_string(Abstract_Item *img, char *space, int32_t capacity, int32_t w append_sc(&str, "."); append_sc(&str, img->extension); - int32_t result = terminate_with_null(&str); + i32 result = terminate_with_null(&str); return(result); } static void -append_section_number_reduced(String *out, Section_Counter *section_counter, int32_t reduce){ - int32_t level = section_counter->nest_level-reduce; - for (int32_t i = 1; i <= level; ++i){ +append_section_number_reduced(String *out, Section_Counter *section_counter, i32 reduce){ + i32 level = section_counter->nest_level-reduce; + for (i32 i = 1; i <= level; ++i){ append_int_to_str(out, section_counter->counter[i]); if (i != level){ append_sc(out, "."); @@ -524,11 +519,11 @@ append_section_number(String *out, Section_Counter *section_counter){ append_section_number_reduced(out, section_counter, 0); } -static int32_t -extract_command_body(String *out, String l, int32_t *i_in_out, int32_t *body_start_out, int32_t *body_end_out, String command_name, int32_t require_body){ - int32_t result = 0; +static i32 +extract_command_body(String *out, String l, i32 *i_in_out, i32 *body_start_out, i32 *body_end_out, String command_name, i32 require_body){ + i32 result = 0; - int32_t i = *i_in_out; + i32 i = *i_in_out; for (; i < l.size; ++i){ if (!char_is_whitespace(l.str[i])){ @@ -536,8 +531,8 @@ extract_command_body(String *out, String l, int32_t *i_in_out, int32_t *body_sta } } - int32_t found_command_body = 0; - int32_t body_start = 0, body_end = 0; + i32 found_command_body = 0; + i32 body_start = 0, body_end = 0; if (l.str[i] == '{'){ body_start = i+1; @@ -558,12 +553,12 @@ extract_command_body(String *out, String l, int32_t *i_in_out, int32_t *body_sta if (require_body){ #define STR_START "! Doc generator error: missing body for " #define STR_SLOW " !" - append_sc(out, STR_START); - append_ss(out, command_name); - append_sc(out, STR_SLOW); + append_sc(out, STR_START); + append_ss(out, command_name); + append_sc(out, STR_SLOW); #undef STR - - fprintf(stderr, "error: missing body for %.*s\n", command_name.size, command_name.str); + + fprintf(stderr, "error: missing body for %.*s\n", command_name.size, command_name.str); } } @@ -614,7 +609,7 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu append_sc(out, "
"); - int32_t item_counter = 0; + i32 item_counter = 0; for (String line = get_first_double_line(source); line.str; @@ -623,13 +618,13 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu append_sc(out, "

"); //append_ss(out, l); - int32_t start = 0, i = 0; + i32 start = 0, i = 0; for (; i < l.size; ++i){ if (l.str[i] == '\\'){ append_ss(out, substr(l, start, i-start)); - int32_t command_start = i+1; - int32_t command_end = command_start; + i32 command_start = i+1; + i32 command_end = command_start; for (; command_end < l.size; ++command_end){ if (!char_is_alpha_numeric(l.str[command_end])){ break; @@ -684,7 +679,7 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu i = command_end; - int32_t match_index = 0; + i32 match_index = 0; if (string_set_match(enriched_commands, ArrayCount(enriched_commands), command_string, &match_index)){ switch (match_index){ case Cmd_BackSlash: append_sc(out, "\\"); break; @@ -692,8 +687,8 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu case Cmd_BeginStyle: { - int32_t body_start = 0, body_end = 0; - int32_t has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1); + i32 body_start = 0, body_end = 0; + i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1); if (has_body){ String body_text = substr(l, body_start, body_end - body_start); body_text = skip_chop_whitespace(body_text); @@ -711,8 +706,8 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu // TODO(allen): upgrade this bs case Cmd_DocLink: { - int32_t body_start = 0, body_end = 0; - int32_t has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1); + i32 body_start = 0, body_end = 0; + i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1); if (has_body){ String body_text = substr(l, body_start, body_end - body_start); body_text = skip_chop_whitespace(body_text); @@ -754,8 +749,8 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu case Cmd_Section: { // TODO(allen): undo the duplication of this body extraction code. - int32_t body_start = 0, body_end = 0; - int32_t has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1); + i32 body_start = 0, body_end = 0; + i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1); if (has_body){ String body_text = substr(l, body_start, body_end - body_start); body_text = skip_chop_whitespace(body_text); @@ -768,8 +763,8 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu case Cmd_BeginLink: { - int32_t body_start = 0, body_end = 0; - int32_t has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1); + i32 body_start = 0, body_end = 0; + i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1); if (has_body){ String body_text = substr(l, body_start, body_end - body_start); body_text = skip_chop_whitespace(body_text); @@ -809,15 +804,15 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu case Cmd_Image: { // TODO(allen): generalize this - int32_t body_start = 0, body_end = 0; - int32_t has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1); + i32 body_start = 0, body_end = 0; + i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1); if (has_body){ String body_text = substr(l, body_start, body_end - body_start); body_text = skip_chop_whitespace(body_text); - int32_t pixel_height = 10; - int32_t pixel_width = HTML_WIDTH; + i32 pixel_height = 10; + i32 pixel_width = HTML_WIDTH; body_start = 0, body_end = 0; has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 0); @@ -862,11 +857,11 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu case Cmd_Video: { // TODO(allen): generalize this - int32_t body_start = 0, body_end = 0; - int32_t has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1); + i32 body_start = 0, body_end = 0; + i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1); - int32_t pixel_width = HTML_WIDTH; - int32_t pixel_height = (int32_t)(pixel_width * 0.5625); + i32 pixel_width = HTML_WIDTH; + i32 pixel_height = (i32)(pixel_width * 0.5625); if (has_body){ String body_text = substr(l, body_start, body_end - body_start); @@ -879,7 +874,7 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu append_int_to_str(out, pixel_width); append_sc(out, "' height='"); append_int_to_str(out, pixel_height); - append_sc(out, "' src='"); + append_sc(out, "' src='"); append_ss(out, youtube_str); append_sc(out, "' allowfullscreen> "); } @@ -917,16 +912,16 @@ print_item_in_list(String *out, String name, char *id_postfix){ } static void -init_used_links(Partition *part, Used_Links *used, int32_t count){ +init_used_links(Partition *part, Used_Links *used, i32 count){ used->strs = push_array(part, String, count); used->count = 0; used->max = count; } -static int32_t +static i32 try_to_use(Used_Links *used, String str){ - int32_t result = 1; - int32_t index = 0; + i32 result = 1; + i32 index = 0; if (string_set_match(used->strs, used->count, str, &index)){ result = 0; @@ -939,7 +934,7 @@ try_to_use(Used_Links *used, String str){ } static void -print_struct_html(String *out, Item_Node *member, int32_t hide_children){ +print_struct_html(String *out, Item_Node *member, i32 hide_children){ String name = member->name; String type = member->type; String type_postfix = member->type_postfix; @@ -991,7 +986,7 @@ print_function_html(String *out, Used_Links *used, String cpp_name, String ret, else{ append_sc(out, "(

"); - for (int32_t j = 0; j < breakdown.count; ++j){ + for (i32 j = 0; j < breakdown.count; ++j){ append_ss(out, breakdown.args[j].param_string); if (j < breakdown.count - 1){ append_s_char(out, ','); @@ -1020,7 +1015,7 @@ print_macro_html(String *out, String name, Argument_Breakdown breakdown){ else{ append_sc (out, "(
"); - for (int32_t j = 0; j < breakdown.count; ++j){ + for (i32 j = 0; j < breakdown.count; ++j){ append_ss(out, breakdown.args[j].param_string); if (j < breakdown.count - 1){ append_s_char(out, ','); @@ -1048,11 +1043,11 @@ static String get_next_doc_chunk(String source, String prev_chunk, Doc_Chunk_Type *type){ String chunk = {0}; String word = {0}; - int32_t pos = source.size; - int32_t word_index = 0; + i32 pos = source.size; + i32 word_index = 0; Doc_Chunk_Type t = DocChunk_PlainText; - int32_t start_pos = (int32_t)(prev_chunk.str - source.str) + prev_chunk.size; + i32 start_pos = (i32)(prev_chunk.str - source.str) + prev_chunk.size; String source_tail = substr_tail(source, start_pos); Assert(DocChunk_Count == ArrayCount(doc_chunk_headers)); @@ -1061,9 +1056,9 @@ get_next_doc_chunk(String source, String prev_chunk, Doc_Chunk_Type *type){ word.str; word = get_next_word(source_tail, word), ++word_index){ - for (int32_t i = 1; i < DocChunk_Count; ++i){ + for (i32 i = 1; i < DocChunk_Count; ++i){ if (match_ss(word, doc_chunk_headers[i])){ - pos = (int32_t)(word.str - source.str); + pos = (i32)(word.str - source.str); t = (Doc_Chunk_Type)i; goto doublebreak; } @@ -1075,8 +1070,8 @@ get_next_doc_chunk(String source, String prev_chunk, Doc_Chunk_Type *type){ if (word_index == 0){ *type = t; - int32_t nest_level = 1; - int32_t i = find_s_char(source, pos, '('); + i32 nest_level = 1; + i32 i = find_s_char(source, pos, '('); for (++i; i < source.size; ++i){ if (source.str[i] == '('){ ++nest_level; @@ -1094,8 +1089,8 @@ get_next_doc_chunk(String source, String prev_chunk, Doc_Chunk_Type *type){ chunk = substr(source, start_pos, pos - start_pos); - int32_t is_all_white = 1; - for (int32_t i = 0; i < chunk.size; ++i){ + i32 is_all_white = 1; + for (i32 i = 0; i < chunk.size; ++i){ if (!char_is_whitespace(chunk.str[i])){ is_all_white = 0; break; @@ -1137,8 +1132,8 @@ print_doc_description(String *out, Partition *part, String src){ case DocChunk_CodeExample: { - int32_t start = 0; - int32_t end = chunk.size-1; + i32 start = 0; + i32 end = chunk.size-1; while (start < end && chunk.str[start] != '(') ++start; start += 1; while (end > start && chunk.str[end] != ')') --end; @@ -1148,14 +1143,14 @@ print_doc_description(String *out, Partition *part, String src){ if (start < end){ String code_example = substr(chunk, start, end - start); - int32_t first_line = 1; + i32 first_line = 1; for (String line = get_first_line(code_example); line.str; line = get_next_line(code_example, line)){ if (!(first_line && line.size == 0)){ - int32_t space_i = 0; + i32 space_i = 0; for (; space_i < line.size; ++space_i){ if (line.str[space_i] == ' '){ append_sc(out, " "); @@ -1210,11 +1205,11 @@ print_struct_docs(String *out, Partition *part, Item_Node *member){ static void print_see_also(String *out, Documentation *doc){ - int32_t doc_see_count = doc->see_also_count; + i32 doc_see_count = doc->see_also_count; if (doc_see_count > 0){ append_sc(out, HTML_DOC_HEAD_OPEN"See Also"HTML_DOC_HEAD_CLOSE); - for (int32_t j = 0; j < doc_see_count; ++j){ + for (i32 j = 0; j < doc_see_count; ++j){ String see_also = doc->see_also[j]; append_sc(out, HTML_DOC_ITEM_OPEN""); - int32_t has_cpp_name = 0; + i32 has_cpp_name = 0; if (item->cpp_name.str != 0){ if (try_to_use(used, item->cpp_name)){ append_sc(out, "